Bug 1534170 - Fix scope of TextureClientAutoLock in MediaEngineTabVideoSource r=mattwoodrow
authorsotaro <sotaro.ikeda.g@gmail.com>
Mon, 11 Mar 2019 08:00:10 +0000
changeset 521321 9294eb30e6da
parent 521306 2883b91c8f6f
child 521322 b9a333944346
push id10866
push usernerli@mozilla.com
push dateTue, 12 Mar 2019 18:59:09 +0000
treeherdermozilla-beta@445c24a51727 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmattwoodrow
bugs1534170, 1440038
milestone67.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 1534170 - Fix scope of TextureClientAutoLock in MediaEngineTabVideoSource r=mattwoodrow TextureClientAutoLock was added by Bug 1440038. Its scope is not good. It should be existed before "MutexAutoLock lock(mMutex)". Differential Revision: https://phabricator.services.mozilla.com/D22877
dom/media/webrtc/MediaEngineTabVideoSource.cpp
--- a/dom/media/webrtc/MediaEngineTabVideoSource.cpp
+++ b/dom/media/webrtc/MediaEngineTabVideoSource.cpp
@@ -340,49 +340,51 @@ void MediaEngineTabVideoSource::Draw() {
 
   RefPtr<layers::TextureClient> texture =
       rgbImage->GetTextureClient(/* aForwarder */ nullptr);
   if (!texture) {
     NS_WARNING("Failed to allocate TextureClient");
     return;
   }
 
-  layers::TextureClientAutoLock autoLock(texture,
-                                         layers::OpenMode::OPEN_WRITE_ONLY);
-  if (!autoLock.Succeeded()) {
-    NS_WARNING("Failed to lock TextureClient");
-    return;
-  }
+  {
+    layers::TextureClientAutoLock autoLock(texture,
+                                           layers::OpenMode::OPEN_WRITE_ONLY);
+    if (!autoLock.Succeeded()) {
+      NS_WARNING("Failed to lock TextureClient");
+      return;
+    }
 
-  RefPtr<gfx::DrawTarget> dt = texture->BorrowDrawTarget();
-  if (!dt || !dt->IsValid()) {
-    NS_WARNING("Failed to borrow DrawTarget");
-    return;
-  }
+    RefPtr<gfx::DrawTarget> dt = texture->BorrowDrawTarget();
+    if (!dt || !dt->IsValid()) {
+      NS_WARNING("Failed to borrow DrawTarget");
+      return;
+    }
 
-  if (mWindow) {
-    RefPtr<gfxContext> context = gfxContext::CreateOrNull(dt);
-    MOZ_ASSERT(context);  // already checked the draw target above
-    context->SetMatrix(context->CurrentMatrix().PreScale(
-        (((float)size.width) / mViewportWidth),
-        (((float)size.height) / mViewportHeight)));
+    if (mWindow) {
+      RefPtr<gfxContext> context = gfxContext::CreateOrNull(dt);
+      MOZ_ASSERT(context);  // already checked the draw target above
+      context->SetMatrix(context->CurrentMatrix().PreScale(
+          (((float)size.width) / mViewportWidth),
+          (((float)size.height) / mViewportHeight)));
 
-    nscolor bgColor = NS_RGB(255, 255, 255);
-    uint32_t renderDocFlags =
-        mScrollWithPage ? 0
-                        : (nsIPresShell::RENDER_IGNORE_VIEWPORT_SCROLLING |
-                           nsIPresShell::RENDER_DOCUMENT_RELATIVE);
-    nsRect r(nsPresContext::CSSPixelsToAppUnits((float)mViewportOffsetX),
-             nsPresContext::CSSPixelsToAppUnits((float)mViewportOffsetY),
-             nsPresContext::CSSPixelsToAppUnits((float)mViewportWidth),
-             nsPresContext::CSSPixelsToAppUnits((float)mViewportHeight));
-    NS_ENSURE_SUCCESS_VOID(
-        presShell->RenderDocument(r, renderDocFlags, bgColor, context));
-  } else {
-    dt->ClearRect(Rect(0, 0, size.width, size.height));
+      nscolor bgColor = NS_RGB(255, 255, 255);
+      uint32_t renderDocFlags =
+          mScrollWithPage ? 0
+                          : (nsIPresShell::RENDER_IGNORE_VIEWPORT_SCROLLING |
+                             nsIPresShell::RENDER_DOCUMENT_RELATIVE);
+      nsRect r(nsPresContext::CSSPixelsToAppUnits((float)mViewportOffsetX),
+               nsPresContext::CSSPixelsToAppUnits((float)mViewportOffsetY),
+               nsPresContext::CSSPixelsToAppUnits((float)mViewportWidth),
+               nsPresContext::CSSPixelsToAppUnits((float)mViewportHeight));
+      NS_ENSURE_SUCCESS_VOID(
+          presShell->RenderDocument(r, renderDocFlags, bgColor, context));
+    } else {
+      dt->ClearRect(Rect(0, 0, size.width, size.height));
+    }
   }
 
   MutexAutoLock lock(mMutex);
   mImage = rgbImage;
 }
 
 nsresult MediaEngineTabVideoSource::FocusOnSelectedSource(
     const RefPtr<const AllocationHandle>& aHandle) {