Bug 1256572 - use SourceSurfaceRawData with custom deallocator in imgFrame. r=bas
authorJerryShih <hshih@mozilla.com>
Thu, 05 May 2016 07:30:00 +0200
changeset 338093 c6b24d98429c6f07e168a80626d301359f6118d8
parent 338092 6a6f96dd901b750dafae2731d50ec92fe7dcea1c
child 338094 4e78d7772c3e61431e3e4b0e9d9647863ab0a84e
push id1183
push userraliiev@mozilla.com
push dateMon, 05 Sep 2016 20:01:49 +0000
treeherdermozilla-release@3148731bed45 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbas
bugs1256572
milestone49.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 1256572 - use SourceSurfaceRawData with custom deallocator in imgFrame. r=bas We can prevent the memory copy in GuaranteePersistance() during painting.
image/imgFrame.cpp
--- a/image/imgFrame.cpp
+++ b/image/imgFrame.cpp
@@ -28,18 +28,16 @@ static bool gDisableOptimize = false;
 
 
 namespace mozilla {
 
 using namespace gfx;
 
 namespace image {
 
-static UserDataKey kVolatileBuffer;
-
 static void
 VolatileBufferRelease(void* vbuf)
 {
   delete static_cast<VolatileBufferPtr<unsigned char>*>(vbuf);
 }
 
 static int32_t
 VolatileSurfaceStride(const IntSize& size, SurfaceFormat format)
@@ -53,24 +51,27 @@ CreateLockedSurface(VolatileBuffer* vbuf
                     const IntSize& size,
                     SurfaceFormat format)
 {
   VolatileBufferPtr<unsigned char>* vbufptr =
     new VolatileBufferPtr<unsigned char>(vbuf);
   MOZ_ASSERT(!vbufptr->WasBufferPurged(), "Expected image data!");
 
   int32_t stride = VolatileSurfaceStride(size, format);
+
+  // The VolatileBufferPtr is held by this DataSourceSurface.
   RefPtr<DataSourceSurface> surf =
-    Factory::CreateWrappingDataSourceSurface(*vbufptr, stride, size, format);
+    Factory::CreateWrappingDataSourceSurface(*vbufptr, stride, size, format,
+                                             &VolatileBufferRelease,
+                                             static_cast<void*>(vbufptr));
   if (!surf) {
     delete vbufptr;
     return nullptr;
   }
 
-  surf->AddUserData(&kVolatileBuffer, vbufptr, VolatileBufferRelease);
   return surf.forget();
 }
 
 static already_AddRefed<VolatileBuffer>
 AllocateBufferForImage(const IntSize& size, SurfaceFormat format)
 {
   int32_t stride = VolatileSurfaceStride(size, format);
   RefPtr<VolatileBuffer> buf = new VolatileBuffer();