Bug 1232334 - [1.2] Only set context on successful attach. r=snorp
authorEugen Sawin <esawin@mozilla.com>
Wed, 02 Mar 2016 17:29:10 +0100
changeset 324933 1931aaadbec47be48ed412c7115c59b3452775bb
parent 324932 e88c874e1f766b0602038d0d3dc14039e6e3e3d8
child 324934 570ffd0108950e6076f4b3ced57a9cc3b51066a2
push id1128
push userjlund@mozilla.com
push dateWed, 01 Jun 2016 01:31:59 +0000
treeherdermozilla-release@fe0d30de989d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssnorp
bugs1232334
milestone47.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1232334 - [1.2] Only set context on successful attach. r=snorp
gfx/gl/AndroidSurfaceTexture.cpp
gfx/gl/AndroidSurfaceTexture.h
--- a/gfx/gl/AndroidSurfaceTexture.cpp
+++ b/gfx/gl/AndroidSurfaceTexture.cpp
@@ -124,23 +124,25 @@ AndroidSurfaceTexture::Attach(GLContext*
     // Wait until it's detached (or we time out)
     if (NS_FAILED(lock.Wait(aTimeout))) {
       return NS_ERROR_NOT_AVAILABLE;
     }
   }
 
   MOZ_ASSERT(aContext->IsOwningThreadCurrent(), "Trying to attach GLContext from different thread");
 
-  mAttachedContext = aContext;
-  mAttachedContext->MakeCurrent();
   aContext->fGenTextures(1, &mTexture);
 
-  UpdateCanDetach();
+  if (NS_FAILED(mSurfaceTexture->AttachToGLContext(mTexture))) {
+    return NS_ERROR_NOT_AVAILABLE;
+  }
+  mAttachedContext = aContext;
+  mAttachedContext->MakeCurrent();
 
-  return mSurfaceTexture->AttachToGLContext(mTexture);
+  return NS_OK;
 }
 
 nsresult
 AndroidSurfaceTexture::Detach()
 {
   MonitorAutoLock lock(mMonitor);
 
   if (!CanDetach() ||
@@ -155,34 +157,31 @@ AndroidSurfaceTexture::Detach()
   mSurfaceTexture->DetachFromGLContext();
 
   mTexture = 0;
   mAttachedContext = nullptr;
   lock.NotifyAll();
   return NS_OK;
 }
 
-void
-AndroidSurfaceTexture::UpdateCanDetach()
+bool
+AndroidSurfaceTexture::CanDetach() const
 {
   // The API for attach/detach only exists on 16+, and PowerVR has some sort of
-  // fencing issue. Additionally, attach/detach seems to be busted on at least some
-  // Mali adapters (400MP2 for sure, bug 1131793)
-  bool canDetach = gfxPrefs::SurfaceTextureDetachEnabled();
-
-  mCanDetach = AndroidBridge::Bridge()->GetAPIVersion() >= 16 &&
+  // fencing issue. Additionally, attach/detach seems to be busted on at least
+  // some Mali adapters (400MP2 for sure, bug 1131793)
+  return AndroidBridge::Bridge()->GetAPIVersion() >= 16 &&
     (!mAttachedContext || mAttachedContext->Vendor() != GLVendor::Imagination) &&
     (!mAttachedContext || mAttachedContext->Vendor() != GLVendor::ARM /* Mali */) &&
-    canDetach;
+    gfxPrefs::SurfaceTextureDetachEnabled();
 }
 
 bool
 AndroidSurfaceTexture::Init(GLContext* aContext, GLuint aTexture)
 {
-  UpdateCanDetach();
 
   if (!aTexture && !CanDetach()) {
     // We have no texture and cannot initialize detached, bail out
     return false;
   }
 
   if (NS_WARN_IF(NS_FAILED(
       SurfaceTexture::New(aTexture, ReturnTo(&mSurfaceTexture))))) {
@@ -209,17 +208,16 @@ AndroidSurfaceTexture::Init(GLContext* a
   return true;
 }
 
 AndroidSurfaceTexture::AndroidSurfaceTexture()
   : mTexture(0)
   , mSurfaceTexture()
   , mSurface()
   , mAttachedContext(nullptr)
-  , mCanDetach(false)
   , mMonitor("AndroidSurfaceTexture::mContextMonitor")
 {
 }
 
 AndroidSurfaceTexture::~AndroidSurfaceTexture()
 {
   sInstances.Remove(mID);
 
--- a/gfx/gl/AndroidSurfaceTexture.h
+++ b/gfx/gl/AndroidSurfaceTexture.h
@@ -51,19 +51,19 @@ public:
   // attach while you are consuming in order to allow this.
   //
   // Only one GLContext may be attached at any given time. If another is already
   // attached, we try to wait for it to become detached.
   nsresult Attach(GLContext* aContext, PRIntervalTime aTiemout = PR_INTERVAL_NO_TIMEOUT);
 
   nsresult Detach();
 
-  // Ability to detach is based on API version (16+), and we also block PowerVR since it has some type
-  // of fencing problem. Bug 1100126.
-  bool CanDetach() const { return mCanDetach; }
+  // Ability to detach is based on API version (16+), and we also block PowerVR
+  // since it has some type of fencing problem. Bug 1100126.
+  bool CanDetach() const;
 
   GLContext* AttachedContext() const { return mAttachedContext; }
 
   AndroidNativeWindow* NativeWindow() const {
     return mNativeWindow;
   }
 
   // This attaches the updated data to the TEXTURE_EXTERNAL target
@@ -85,24 +85,22 @@ public:
   GLuint Texture() const { return mTexture; }
   const widget::sdk::Surface::Ref& JavaSurface() const { return mSurface; }
 
 private:
   AndroidSurfaceTexture();
   ~AndroidSurfaceTexture();
 
   bool Init(GLContext* aContext, GLuint aTexture);
-  void UpdateCanDetach();
 
   GLuint mTexture;
   widget::sdk::SurfaceTexture::GlobalRef mSurfaceTexture;
   widget::sdk::Surface::GlobalRef mSurface;
 
   GLContext* mAttachedContext;
-  bool mCanDetach;
 
   RefPtr<AndroidNativeWindow> mNativeWindow;
   int mID;
   nsCOMPtr<nsIRunnable> mFrameAvailableCallback;
 
   mutable Monitor mMonitor;
 };