Bug 1075077 - Update buffer's addresses r=nical
authorSotaro Ikeda <sikeda@mozilla.com>
Fri, 10 Oct 2014 06:21:43 -0700
changeset 233070 e0662f559c632a79ce1021e0eada0953590d14ce
parent 233069 311c125897e53e66c7c74fb9a935b88562771008
child 233071 0402daa909e416b596ddac2980e916907ed27205
push id1
push usersledru@mozilla.com
push dateThu, 04 Dec 2014 17:57:20 +0000
reviewersnical
bugs1075077
milestone35.0a1
Bug 1075077 - Update buffer's addresses r=nical
gfx/layers/GrallocImages.cpp
--- a/gfx/layers/GrallocImages.cpp
+++ b/gfx/layers/GrallocImages.cpp
@@ -129,16 +129,23 @@ GrallocImage::SetData(const Data& aData)
              mData.mCbChannel + i * mData.mCbCrStride,
              uvSize.width);
       memcpy(vChannel + i * uvStride,
              mData.mCrChannel + i * mData.mCbCrStride,
              uvSize.width);
     }
   }
   graphicBuffer->unlock();
+  // Initialze the channels' addresses.
+  // Do not cache the addresses when gralloc buffer is not locked.
+  // gralloc hal could map gralloc buffer only when the buffer is locked,
+  // though some gralloc hals implementation maps it when it is allocated.
+  mData.mYChannel     = nullptr;
+  mData.mCrChannel    = nullptr;
+  mData.mCbChannel    = nullptr;
 }
 
 void GrallocImage::SetData(const GrallocData& aData)
 {
   mTextureClient = static_cast<GrallocTextureClientOGL*>(aData.mGraphicBuffer.get());
   mSize = aData.mPicSize;
 }
 
@@ -330,16 +337,22 @@ ConvertOmxYUVFormatToRGB565(android::sp<
       ycbcrData.mCbSkip       = 0;
       ycbcrData.mCbCrSize     = aSurface->GetSize() / 2;
       ycbcrData.mPicSize      = aSurface->GetSize();
       ycbcrData.mCrChannel    = buffer + ycbcrData.mYStride * aBuffer->getHeight();
       ycbcrData.mCrSkip       = 0;
       // Align to 16 bytes boundary
       ycbcrData.mCbCrStride   = ALIGN(ycbcrData.mYStride / 2, 16);
       ycbcrData.mCbChannel    = ycbcrData.mCrChannel + (ycbcrData.mCbCrStride * aBuffer->getHeight() / 2);
+    } else {
+      // Update channels' address.
+      // Gralloc buffer could map gralloc buffer only when the buffer is locked.
+      ycbcrData.mYChannel     = buffer;
+      ycbcrData.mCrChannel    = buffer + ycbcrData.mYStride * aBuffer->getHeight();
+      ycbcrData.mCbChannel    = ycbcrData.mCrChannel + (ycbcrData.mCbCrStride * aBuffer->getHeight() / 2);
     }
     gfx::ConvertYCbCrToRGB(ycbcrData,
                            aSurface->GetFormat(),
                            aSurface->GetSize(),
                            aMappedSurface->mData,
                            aMappedSurface->mStride);
     return OK;
   }