Bug 980472 - Make SurfaceToPackedBGRA take a DataSourceSurface to avoid unnecessary surface conversion. r=Bas
authorJonathan Watt <jwatt@jwatt.org>
Thu, 06 Mar 2014 23:31:33 +0000
changeset 189576 2ac59d28974c553c93eb814b4a9af8c1eb61c255
parent 189575 4efacf2f947bbabbf26be8f9e37142b7f22614da
child 189577 5de7483b01d20b3239aaf6b848c0872437a77cc4
push id3503
push userraliiev@mozilla.com
push dateMon, 28 Apr 2014 18:51:11 +0000
treeherdermozilla-beta@c95ac01e332e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersBas
bugs980472
milestone30.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 980472 - Make SurfaceToPackedBGRA take a DataSourceSurface to avoid unnecessary surface conversion. r=Bas
gfx/2d/DataSurfaceHelpers.h
--- a/gfx/2d/DataSurfaceHelpers.h
+++ b/gfx/2d/DataSurfaceHelpers.h
@@ -22,43 +22,38 @@ ConvertBGRXToBGRA(uint8_t* aData, const 
 #else
       pixel[column] |= 0xFF000000;
 #endif
     }
     pixel += (aStride/4);
   }
 }
 
-/*
+/**
  * Convert aSurface to a packed buffer in BGRA format. The pixel data is
  * returned in a buffer allocated with new uint8_t[].
  */
 inline uint8_t *
-SurfaceToPackedBGRA(SourceSurface *aSurface)
+SurfaceToPackedBGRA(DataSourceSurface *aSurface)
 {
-  RefPtr<DataSourceSurface> data = aSurface->GetDataSurface();
-  if (!data) {
-    return nullptr;
-  }
-
-  SurfaceFormat format = data->GetFormat();
+  SurfaceFormat format = aSurface->GetFormat();
   if (format != SurfaceFormat::B8G8R8A8 && format != SurfaceFormat::B8G8R8X8) {
     return nullptr;
   }
 
-  IntSize size = data->GetSize();
+  IntSize size = aSurface->GetSize();
 
   uint8_t* imageBuffer = new (std::nothrow) uint8_t[size.width * size.height * sizeof(uint32_t)];
   if (!imageBuffer) {
     return nullptr;
   }
 
-  size_t stride = data->Stride();
+  size_t stride = aSurface->Stride();
 
-  uint32_t* src = reinterpret_cast<uint32_t*>(data->GetData());
+  uint32_t* src = reinterpret_cast<uint32_t*>(aSurface->GetData());
   uint32_t* dst = reinterpret_cast<uint32_t*>(imageBuffer);
 
   if (stride == size.width * sizeof(uint32_t)) {
     // DataSourceSurface is already packed. We can use memcpy.
     memcpy(dst, src, size.width * size.height * sizeof(uint32_t));
   } else {
     for (int row = 0; row < size.height; ++row) {
       for (int column = 0; column < size.width; ++column) {