Fix race condition when mapping a D2D surface while its DrawTarget mutates. (bug 1418348, r=bas) a=gchang
authorDavid Anderson <danderson@mozilla.com>
Tue, 12 Dec 2017 14:52:54 -0600
changeset 445348 c843f2f3085e6439335e0fd5ad89eeb7f90ea7d5
parent 445347 5b840d6589db2600932fccb36c04a2ac4f37e7bd
child 445349 3b4d18da6b103eb83fffc14e0115434d2951c15e
push id1618
push userCallek@gmail.com
push dateThu, 11 Jan 2018 17:45:48 +0000
treeherdermozilla-release@882ca853e05a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbas, gchang
bugs1418348
milestone58.0
Fix race condition when mapping a D2D surface while its DrawTarget mutates. (bug 1418348, r=bas) a=gchang
gfx/2d/SourceSurfaceD2D1.cpp
--- a/gfx/2d/SourceSurfaceD2D1.cpp
+++ b/gfx/2d/SourceSurfaceD2D1.cpp
@@ -36,23 +36,28 @@ bool
 SourceSurfaceD2D1::IsValid() const
 {
   return mDevice == Factory::GetD2D1Device();
 }
 
 already_AddRefed<DataSourceSurface>
 SourceSurfaceD2D1::GetDataSurface()
 {
-  HRESULT hr;
+  Maybe<MutexAutoLock> lock;
+  if (mSnapshotLock) {
+    lock.emplace(*mSnapshotLock);
+  }
 
   if (!EnsureRealizedBitmap()) {
     gfxCriticalError() << "Failed to realize a bitmap, device " << hexa(mDevice);
     return nullptr;
   }
 
+  HRESULT hr;
+
   RefPtr<ID2D1Bitmap1> softwareBitmap;
   D2D1_BITMAP_PROPERTIES1 props;
   props.dpiX = 96;
   props.dpiY = 96;
   props.pixelFormat = D2DPixelFormat(mFormat);
   props.colorContext = nullptr;
   props.bitmapOptions = D2D1_BITMAP_OPTIONS_CANNOT_DRAW |
                         D2D1_BITMAP_OPTIONS_CPU_READ;