Bug 1365099 - Convert NS_GetCurrentThread uses in gfx (r=dvander)
authorBill McCloskey <billm@mozilla.com>
Thu, 01 Jun 2017 13:43:00 -0700
changeset 412324 d4c07cb66853
parent 412323 351a4d47496e
child 412325 43fcf7ddd6ba
push id7566
push usermtabara@mozilla.com
push dateWed, 02 Aug 2017 08:25:16 +0000
treeherdermozilla-beta@86913f512c3c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdvander
bugs1365099
milestone56.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 1365099 - Convert NS_GetCurrentThread uses in gfx (r=dvander) MozReview-Commit-ID: 9I4eXsBl2s8
dom/canvas/OffscreenCanvas.cpp
dom/html/HTMLCanvasElement.cpp
gfx/gl/SharedSurface.cpp
gfx/gl/SharedSurface.h
gfx/layers/AsyncCanvasRenderer.cpp
gfx/layers/AsyncCanvasRenderer.h
gfx/layers/ImageContainer.h
gfx/layers/LayerScope.cpp
gfx/layers/ipc/UiCompositorControllerChild.cpp
--- a/dom/canvas/OffscreenCanvas.cpp
+++ b/dom/canvas/OffscreenCanvas.cpp
@@ -81,25 +81,25 @@ OffscreenCanvas::Constructor(const Globa
 
 void
 OffscreenCanvas::ClearResources()
 {
   if (mCanvasClient) {
     mCanvasClient->Clear();
 
     if (mCanvasRenderer) {
-      nsCOMPtr<nsISerialEventTarget> activeTarget = mCanvasRenderer->GetActiveThread();
+      nsCOMPtr<nsISerialEventTarget> activeTarget = mCanvasRenderer->GetActiveEventTarget();
       MOZ_RELEASE_ASSERT(activeTarget, "GFX: failed to get active event target.");
       bool current;
       activeTarget->IsOnCurrentThread(&current);
       MOZ_RELEASE_ASSERT(current, "GFX: active thread is not current thread.");
       mCanvasRenderer->SetCanvasClient(nullptr);
       mCanvasRenderer->mContext = nullptr;
       mCanvasRenderer->mGLContext = nullptr;
-      mCanvasRenderer->ResetActiveThread();
+      mCanvasRenderer->ResetActiveEventTarget();
     }
 
     mCanvasClient = nullptr;
   }
 }
 
 already_AddRefed<nsISupports>
 OffscreenCanvas::GetContext(JSContext* aCx,
@@ -138,17 +138,17 @@ OffscreenCanvas::GetContext(JSContext* a
   }
 
   if (mCanvasRenderer) {
     if (contextType == CanvasContextType::WebGL1 ||
         contextType == CanvasContextType::WebGL2) {
       WebGLContext* webGL = static_cast<WebGLContext*>(mCurrentContext.get());
       gl::GLContext* gl = webGL->GL();
       mCanvasRenderer->mContext = mCurrentContext;
-      mCanvasRenderer->SetActiveThread();
+      mCanvasRenderer->SetActiveEventTarget();
       mCanvasRenderer->mGLContext = gl;
       mCanvasRenderer->SetIsAlphaPremultiplied(webGL->IsPremultAlpha() || !gl->Caps().alpha);
 
       if (RefPtr<ImageBridgeChild> imageBridge = ImageBridgeChild::GetSingleton()) {
         TextureFlags flags = TextureFlags::ORIGIN_BOTTOM_LEFT;
         mCanvasClient = imageBridge->CreateCanvasClient(CanvasClient::CanvasClientTypeShSurf, flags);
         mCanvasRenderer->SetCanvasClient(mCanvasClient);
 
--- a/dom/html/HTMLCanvasElement.cpp
+++ b/dom/html/HTMLCanvasElement.cpp
@@ -1370,17 +1370,17 @@ HTMLCanvasElement::OnVisibilityChange()
         mRenderer = nullptr;
       }
 
     private:
       RefPtr<AsyncCanvasRenderer> mRenderer;
     };
 
     RefPtr<nsIRunnable> runnable = new Runnable(mAsyncCanvasRenderer);
-    nsCOMPtr<nsIEventTarget> activeTarget = mAsyncCanvasRenderer->GetActiveThread();
+    nsCOMPtr<nsIEventTarget> activeTarget = mAsyncCanvasRenderer->GetActiveEventTarget();
     if (activeTarget) {
       activeTarget->Dispatch(runnable, nsIThread::DISPATCH_NORMAL);
     }
     return;
   }
 
   if (mCurrentContext) {
     mCurrentContext->OnVisibilityChange();
@@ -1412,17 +1412,17 @@ HTMLCanvasElement::OnMemoryPressure()
         mRenderer = nullptr;
       }
 
     private:
       RefPtr<AsyncCanvasRenderer> mRenderer;
     };
 
     RefPtr<nsIRunnable> runnable = new Runnable(mAsyncCanvasRenderer);
-    nsCOMPtr<nsIEventTarget> activeTarget = mAsyncCanvasRenderer->GetActiveThread();
+    nsCOMPtr<nsIEventTarget> activeTarget = mAsyncCanvasRenderer->GetActiveEventTarget();
     if (activeTarget) {
       activeTarget->Dispatch(runnable, nsIThread::DISPATCH_NORMAL);
     }
     return;
   }
 
   if (mCurrentContext) {
     mCurrentContext->OnMemoryPressure();
--- a/gfx/gl/SharedSurface.cpp
+++ b/gfx/gl/SharedSurface.cpp
@@ -211,19 +211,16 @@ SharedSurface::SharedSurface(SharedSurfa
     : mType(type)
     , mAttachType(attachType)
     , mGL(gl)
     , mSize(size)
     , mHasAlpha(hasAlpha)
     , mCanRecycle(canRecycle)
     , mIsLocked(false)
     , mIsProducerAcquired(false)
-#ifdef DEBUG
-    , mOwningThread(NS_GetCurrentThread())
-#endif
 { }
 
 layers::TextureFlags
 SharedSurface::GetTextureFlags() const
 {
     return layers::TextureFlags::NO_FLAGS;
 }
 
--- a/gfx/gl/SharedSurface.h
+++ b/gfx/gl/SharedSurface.h
@@ -62,19 +62,16 @@ public:
     const AttachmentType mAttachType;
     const WeakPtr<GLContext> mGL;
     const gfx::IntSize mSize;
     const bool mHasAlpha;
     const bool mCanRecycle;
 protected:
     bool mIsLocked;
     bool mIsProducerAcquired;
-#ifdef DEBUG
-    nsIThread* const mOwningThread;
-#endif
 
     SharedSurface(SharedSurfaceType type,
                   AttachmentType attachType,
                   GLContext* gl,
                   const gfx::IntSize& size,
                   bool hasAlpha,
                   bool canRecycle);
 
--- a/gfx/layers/AsyncCanvasRenderer.cpp
+++ b/gfx/layers/AsyncCanvasRenderer.cpp
@@ -117,34 +117,34 @@ AsyncCanvasRenderer::SetCanvasClient(Can
   if (aClient) {
     mCanvasClientAsyncHandle = aClient->GetAsyncHandle();
   } else {
     mCanvasClientAsyncHandle = CompositableHandle();
   }
 }
 
 void
-AsyncCanvasRenderer::SetActiveThread()
+AsyncCanvasRenderer::SetActiveEventTarget()
 {
   MutexAutoLock lock(mMutex);
-  mActiveThread = NS_GetCurrentThread();
+  mActiveEventTarget = GetCurrentThreadSerialEventTarget();
 }
 
 void
-AsyncCanvasRenderer::ResetActiveThread()
+AsyncCanvasRenderer::ResetActiveEventTarget()
 {
   MutexAutoLock lock(mMutex);
-  mActiveThread = nullptr;
+  mActiveEventTarget = nullptr;
 }
 
-already_AddRefed<nsIThread>
-AsyncCanvasRenderer::GetActiveThread()
+already_AddRefed<nsISerialEventTarget>
+AsyncCanvasRenderer::GetActiveEventTarget()
 {
   MutexAutoLock lock(mMutex);
-  nsCOMPtr<nsIThread> result = mActiveThread;
+  nsCOMPtr<nsISerialEventTarget> result = mActiveEventTarget;
   return result.forget();
 }
 
 void
 AsyncCanvasRenderer::CopyFromTextureClient(TextureClient* aTextureClient)
 {
   MutexAutoLock lock(mMutex);
 
--- a/gfx/layers/AsyncCanvasRenderer.h
+++ b/gfx/layers/AsyncCanvasRenderer.h
@@ -9,17 +9,17 @@
 
 #include "LayersTypes.h"
 #include "mozilla/gfx/Point.h"          // for IntSize
 #include "mozilla/Mutex.h"
 #include "nsCOMPtr.h"                   // for nsCOMPtr
 
 class nsICanvasRenderingContextInternal;
 class nsIInputStream;
-class nsIThread;
+class nsISerialEventTarget;
 
 namespace mozilla {
 
 namespace gfx {
 class DataSourceSurface;
 }
 
 namespace gl {
@@ -74,18 +74,18 @@ public:
   }
 
   void SetIsAlphaPremultiplied(bool aIsAlphaPremultiplied)
   {
     mIsAlphaPremultiplied = aIsAlphaPremultiplied;
   }
 
   // Active thread means the thread which spawns GLContext.
-  void SetActiveThread();
-  void ResetActiveThread();
+  void SetActiveEventTarget();
+  void ResetActiveEventTarget();
 
   // This will readback surface and return the surface
   // in the DataSourceSurface.
   // Can be called in main thread only.
   already_AddRefed<gfx::DataSourceSurface> GetSurface();
 
   // For SharedSurface_Basic case, before the frame sending to the compositor,
   // we readback it to a texture client because SharedSurface_Basic cannot shared.
@@ -111,17 +111,17 @@ public:
     return mCanvasClientAsyncHandle;
   }
 
   CanvasClient* GetCanvasClient() const
   {
     return mCanvasClient;
   }
 
-  already_AddRefed<nsIThread> GetActiveThread();
+  already_AddRefed<nsISerialEventTarget> GetActiveEventTarget();
 
   // The lifetime is controllered by HTMLCanvasElement.
   // Only accessed in main thread.
   dom::HTMLCanvasElement* mHTMLCanvasElement;
 
   // Only accessed in active thread.
   nsICanvasRenderingContextInternal* mContext;
 
@@ -154,15 +154,15 @@ private:
   // we copy from this TextureClient to this mSurfaceForBasic directly
   // by calling CopyFromTextureClient().
   RefPtr<gfx::DataSourceSurface> mSurfaceForBasic;
 
   // Protect non thread-safe objects.
   Mutex mMutex;
 
   // Can be accessed in any thread, need protect by mutex.
-  nsCOMPtr<nsIThread> mActiveThread;
+  nsCOMPtr<nsISerialEventTarget> mActiveEventTarget;
 };
 
 } // namespace layers
 } // namespace mozilla
 
 #endif // MOZILLA_LAYERS_ASYNCCANVASRENDERER_H_
--- a/gfx/layers/ImageContainer.h
+++ b/gfx/layers/ImageContainer.h
@@ -102,35 +102,33 @@ public:
       return NS_OK;
     }
     RawRef mRef;
   };
 
   static RawRef Void() { return nullptr; }
   void Release(RawRef aRawRef)
   {
-    MOZ_ASSERT(mOwningThread);
-    bool current;
-    mOwningThread->IsOnCurrentThread(&current);
-    if (current) {
+    MOZ_ASSERT(mOwningEventTarget);
+    if (mOwningEventTarget->IsOnCurrentThread()) {
       aRawRef->Release();
       return;
     }
     nsCOMPtr<nsIRunnable> runnable = new SurfaceReleaser(aRawRef);
-    mOwningThread->Dispatch(runnable, nsIThread::DISPATCH_NORMAL);
+    mOwningEventTarget->Dispatch(runnable, nsIThread::DISPATCH_NORMAL);
   }
   void AddRef(RawRef aRawRef)
   {
-    MOZ_ASSERT(!mOwningThread);
-    NS_GetCurrentThread(getter_AddRefs(mOwningThread));
+    MOZ_ASSERT(!mOwningEventTarget);
+    mOwningEventTarget = mozilla::GetCurrentThreadSerialEventTarget();
     aRawRef->AddRef();
   }
 
 private:
-  nsCOMPtr<nsIThread> mOwningThread;
+  nsCOMPtr<nsISerialEventTarget> mOwningEventTarget;
 };
 
 #endif
 
 #ifdef XP_WIN
 struct ID3D10Texture2D;
 struct ID3D10Device;
 struct ID3D10ShaderResourceView;
--- a/gfx/layers/LayerScope.cpp
+++ b/gfx/layers/LayerScope.cpp
@@ -782,17 +782,17 @@ public:
 
     void Send() {
         mThread->Dispatch(new SendTask(this), NS_DISPATCH_NORMAL);
     }
 
 protected:
     virtual ~DebugDataSender() {}
     void RemoveData() {
-        MOZ_ASSERT(NS_GetCurrentThread() == mThread);
+        MOZ_ASSERT(mThread->SerialEventTarget()->IsOnCurrentThread());
         if (mList.isEmpty())
             return;
 
         DebugGLData *d;
         while ((d = mList.popFirst()) != nullptr)
             delete d;
     }
 
@@ -1154,17 +1154,17 @@ LayerScopeWebSocketManager::SocketHandle
                                  getter_AddRefs(mOutputStream));
 
     nsCOMPtr<nsIInputStream> debugInputStream;
     mTransport->OpenInputStream(0,
                                 0,
                                 0,
                                 getter_AddRefs(debugInputStream));
     mInputStream = do_QueryInterface(debugInputStream);
-    mInputStream->AsyncWait(this, 0, 0, NS_GetCurrentThread());
+    mInputStream->AsyncWait(this, 0, 0, GetCurrentThreadEventTarget());
 }
 
 bool
 LayerScopeWebSocketManager::SocketHandler::WriteToStream(void *aPtr,
                                           uint32_t aSize)
 {
     if (mState == NoHandshake) {
         // Not yet handshake, just return true in case of
@@ -1229,17 +1229,17 @@ LayerScopeWebSocketManager::SocketHandle
 
     if (!mConnected) {
         nsTArray<nsCString> protocolString;
         ReadInputStreamData(protocolString);
 
         if (WebSocketHandshake(protocolString)) {
             mState = HandshakeSuccess;
             mConnected = true;
-            mInputStream->AsyncWait(this, 0, 0, NS_GetCurrentThread());
+            mInputStream->AsyncWait(this, 0, 0, GetCurrentThreadEventTarget());
         } else {
             mState = HandshakeFailed;
         }
         return NS_OK;
     } else {
         return HandleSocketMessage(aStream);
     }
 }
@@ -1359,17 +1359,17 @@ LayerScopeWebSocketManager::SocketHandle
     nsresult rv = NS_OK;
 
     do {
         rv = mInputStream->Read((char *)buffer, cPacketSize, &count);
 
         // TODO: combine packets if we have to read more than once
 
         if (rv == NS_BASE_STREAM_WOULD_BLOCK) {
-            mInputStream->AsyncWait(this, 0, 0, NS_GetCurrentThread());
+            mInputStream->AsyncWait(this, 0, 0, GetCurrentThreadEventTarget());
             return NS_OK;
         }
 
         if (NS_FAILED(rv)) {
             break;
         }
 
         if (count == 0) {
--- a/gfx/layers/ipc/UiCompositorControllerChild.cpp
+++ b/gfx/layers/ipc/UiCompositorControllerChild.cpp
@@ -30,17 +30,17 @@ GetUiThread()
   MOZ_CRASH("Platform does not support UiCompositorController");
   return nullptr;
 }
 #endif // defined(MOZ_WIDGET_ANDROID)
 
 static bool
 IsOnUiThread()
 {
-  return NS_GetCurrentThread() == GetUiThread();
+  return GetUiThread()->SerialEventTarget()->IsOnCurrentThread();
 }
 
 namespace mozilla {
 namespace layers {
 
 
 // public:
 /* static */ RefPtr<UiCompositorControllerChild>