Bug 1035168 - Use Map api to check if DataSourceSurfaces have data available in DrawTargetCairo. r=Bas, a=lmandel
authorMatt Woodrow <mwoodrow@mozilla.com>
Wed, 09 Jul 2014 13:53:48 +1200
changeset 208172 dd517186b945
parent 208171 d8e7408cb510
child 208173 2bc7c49698cc
push id3753
push userryanvm@gmail.com
push date2014-07-28 14:29 +0000
treeherdermozilla-beta@ecfc5bee1685 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersBas, lmandel
bugs1035168
milestone32.0
Bug 1035168 - Use Map api to check if DataSourceSurfaces have data available in DrawTargetCairo. r=Bas, a=lmandel
gfx/2d/DrawTargetCairo.cpp
--- a/gfx/2d/DrawTargetCairo.cpp
+++ b/gfx/2d/DrawTargetCairo.cpp
@@ -125,17 +125,19 @@ PatternIsCompatible(const Pattern& aPatt
   }
 }
 
 static cairo_user_data_key_t surfaceDataKey;
 
 void
 ReleaseData(void* aData)
 {
-  static_cast<DataSourceSurface*>(aData)->Release();
+  DataSourceSurface *data = static_cast<DataSourceSurface*>(aData);
+  data->Unmap();
+  data->Release();
 }
 
 cairo_surface_t*
 CopyToImageSurface(unsigned char *aData,
                    const IntSize &aSize,
                    int32_t aStride,
                    SurfaceFormat aFormat)
 {
@@ -190,45 +192,54 @@ GetCairoSurfaceForSourceSurface(SourceSu
     return nullptr;
   }
 
   RefPtr<DataSourceSurface> data = aSurface->GetDataSurface();
   if (!data) {
     return nullptr;
   }
 
+  DataSourceSurface::MappedSurface map;
+  if (!data->Map(DataSourceSurface::READ, &map)) {
+    return nullptr;
+  }
+
   cairo_surface_t* surf =
-    cairo_image_surface_create_for_data(data->GetData(),
+    cairo_image_surface_create_for_data(map.mData,
                                         GfxFormatToCairoFormat(data->GetFormat()),
                                         data->GetSize().width,
                                         data->GetSize().height,
-                                        data->Stride());
+                                        map.mStride);
 
   // In certain scenarios, requesting larger than 8k image fails.  Bug 803568
   // covers the details of how to run into it, but the full detailed
   // investigation hasn't been done to determine the underlying cause.  We
   // will just handle the failure to allocate the surface to avoid a crash.
   if (cairo_surface_status(surf)) {
     if (cairo_surface_status(surf) == CAIRO_STATUS_INVALID_STRIDE) {
       // If we failed because of an invalid stride then copy into
       // a new surface with a stride that cairo chooses. No need to
       // set user data since we're not dependent on the original
       // data.
-      return CopyToImageSurface(data->GetData(),
-                                data->GetSize(),
-                                data->Stride(),
-                                data->GetFormat());
+      cairo_surface_t* result =
+        CopyToImageSurface(map.mData,
+                           data->GetSize(),
+                           map.mStride,
+                           data->GetFormat());
+      data->Unmap();
+      return result;
     }
+    data->Unmap();
     return nullptr;
   }
 
   cairo_surface_set_user_data(surf,
- 				                      &surfaceDataKey,
- 				                      data.forget().drop(),
- 				                      ReleaseData);
+                              &surfaceDataKey,
+                              data.forget().drop(),
+                              ReleaseData);
   return surf;
 }
 
 // An RAII class to temporarily clear any device offset set
 // on a surface. Note that this does not take a reference to the
 // surface.
 class AutoClearDeviceOffset
 {