Bug 1255961 - Avoid zeroing out shmems (r=dvander)
☠☠ backed out by 3b74da083e58 ☠ ☠
authorBill McCloskey <billm@mozilla.com>
Fri, 11 Mar 2016 20:24:21 -0800
changeset 291085 08a097c4ea862f80c537d784de3635e1dcbf0f70
parent 291084 25ff944d5dc9454055426d021889fb700b8ff55a
child 291086 0f2e90feea3b779e6b8cc8ca572c6313e1d0995e
push id19656
push usergwagner@mozilla.com
push dateMon, 04 Apr 2016 13:43:23 +0000
treeherderb2g-inbound@e99061fde28a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdvander
bugs1255961
milestone48.0a1
Bug 1255961 - Avoid zeroing out shmems (r=dvander)
gfx/layers/BufferTexture.cpp
--- a/gfx/layers/BufferTexture.cpp
+++ b/gfx/layers/BufferTexture.cpp
@@ -395,30 +395,33 @@ MemoryTextureData::Serialize(SurfaceDesc
   }
 
   uintptr_t ptr = reinterpret_cast<uintptr_t>(mBuffer);
   aOutDescriptor = SurfaceDescriptorBuffer(mDescriptor, MemoryOrShmem(ptr));
 
   return true;
 }
 
-static bool InitBuffer(uint8_t* buf, size_t bufSize, gfx::SurfaceFormat aFormat, TextureAllocationFlags aAllocFlags)
+static bool
+InitBuffer(uint8_t* buf, size_t bufSize,
+           gfx::SurfaceFormat aFormat, TextureAllocationFlags aAllocFlags,
+           bool aAlreadyZero)
 {
   if (!buf) {
     gfxDebug() << "BufferTextureData: Failed to allocate " << bufSize << " bytes";
     return false;
   }
 
   if ((aAllocFlags & ALLOC_CLEAR_BUFFER) ||
       (aAllocFlags & ALLOC_CLEAR_BUFFER_BLACK)) {
     if (aFormat == gfx::SurfaceFormat::B8G8R8X8) {
       // Even though BGRX was requested, XRGB_UINT32 is what is meant,
       // so use 0xFF000000 to put alpha in the right place.
       std::fill_n(reinterpret_cast<uint32_t*>(buf), bufSize / sizeof(uint32_t), 0xFF000000);
-    } else {
+    } else if (!aAlreadyZero) {
       memset(buf, 0, bufSize);
     }
   }
 
   if (aAllocFlags & ALLOC_CLEAR_BUFFER_WHITE) {
     memset(buf, 0xFF, bufSize);
   }
 
@@ -440,17 +443,17 @@ MemoryTextureData::Create(gfx::IntSize a
   }
 
   uint32_t bufSize = ImageDataSerializer::ComputeRGBBufferSize(aSize, aFormat);
   if (!bufSize) {
     return nullptr;
   }
 
   uint8_t* buf = new (fallible) uint8_t[bufSize];
-  if (!InitBuffer(buf, bufSize, aFormat, aAllocFlags)) {
+  if (!InitBuffer(buf, bufSize, aFormat, aAllocFlags, false)) {
     return nullptr;
   }
 
   auto fwd = aAllocator ? aAllocator->AsCompositableForwarder() : nullptr;
   bool hasIntermediateBuffer = fwd ? ComputeHasIntermediateBuffer(aFormat,
                                               fwd->GetCompositorBackendType())
                                    : true;
 
@@ -517,17 +520,17 @@ ShmemTextureData::Create(gfx::IntSize aS
   }
 
   mozilla::ipc::Shmem shm;
   if (!aAllocator->AsShmemAllocator()->AllocUnsafeShmem(bufSize, OptimalShmemType(), &shm)) {
     return nullptr;
   }
 
   uint8_t* buf = shm.get<uint8_t>();
-  if (!InitBuffer(buf, bufSize, aFormat, aAllocFlags)) {
+  if (!InitBuffer(buf, bufSize, aFormat, aAllocFlags, true)) {
     return nullptr;
   }
 
   auto fwd = aAllocator->AsCompositableForwarder();
   bool hasIntermediateBuffer = fwd ? ComputeHasIntermediateBuffer(aFormat,
                                               fwd->GetCompositorBackendType())
                                    : true;