Bug 1035168 - Avoid calling GetData/Stride on a surface that we will later Map. r=Bas, a=lmandel
authorMatt Woodrow <mwoodrow@mozilla.com>
Fri, 11 Jul 2014 15:23:56 +1200
changeset 208173 2bc7c49698cc
parent 208172 dd517186b945
child 208174 a8dd4b54e15b
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 - Avoid calling GetData/Stride on a surface that we will later Map. r=Bas, a=lmandel
gfx/2d/FilterNodeSoftware.cpp
--- a/gfx/2d/FilterNodeSoftware.cpp
+++ b/gfx/2d/FilterNodeSoftware.cpp
@@ -826,23 +826,36 @@ FilterNodeSoftware::GetInputDataSourceSu
     IntRect srcRect = aTransparencyPaddedSourceRect->Intersect(aRect);
     surface = GetDataSurfaceInRect(surface, surfaceRect, srcRect, EDGE_MODE_NONE);
     surfaceRect = srcRect;
   }
 
   RefPtr<DataSourceSurface> result =
     GetDataSurfaceInRect(surface, surfaceRect, aRect, aEdgeMode);
 
-  if (result &&
-      (result->Stride() != GetAlignedStride<16>(result->Stride()) ||
-       reinterpret_cast<uintptr_t>(result->GetData()) % 16 != 0)) {
-    // Align unaligned surface.
-    result = CloneAligned(result);
+  if (result) {
+    // TODO: This isn't safe since we don't have a guarantee
+    // that future Maps will have the same stride
+    DataSourceSurface::MappedSurface map;
+    if (result->Map(DataSourceSurface::READ, &map)) {
+       // Unmap immediately since CloneAligned hasn't been updated
+       // to use the Map API yet. We can still read the stride/data
+       // values as long as we don't try to dereference them.
+      result->Unmap();
+      if (map.mStride != GetAlignedStride<16>(map.mStride) ||
+          reinterpret_cast<uintptr_t>(map.mData) % 16 != 0) {
+        // Align unaligned surface.
+        result = CloneAligned(result);
+      }
+    } else {
+      result = nullptr;
+    }
   }
 
+
   if (!result) {
 #ifdef DEBUG_DUMP_SURFACES
     printf(" -- no input --</section>\n\n");
 #endif
     return nullptr;
   }
 
   SurfaceFormat currentFormat = result->GetFormat();