Bug 928806 - Allow SharedPlanarYCbCrImage images to optionally have padding. r=nical
☠☠ backed out by f8fea5ea69a1 ☠ ☠
authorAlessandro Decina <alessandro.d@gmail.com>
Sun, 15 Dec 2013 14:06:14 -0500
changeset 160543 e9ca04f323d0106f095ce2c0dd77f634ceea0652
parent 160542 139cdac4f380c74344d6d93b9395fad12bab6519
child 160544 37c7fbeb787aff066fc5a836955119f4a0ab1b79
push idunknown
push userunknown
push dateunknown
reviewersnical
bugs928806
milestone29.0a1
Bug 928806 - Allow SharedPlanarYCbCrImage images to optionally have padding. r=nical Overload YCbCrImageDataSerializer.InitializeBufferInfo to take explicit plane offsets. Make SharedPlanarYCbCrImage::SetDataNoCopy set the offsets based on the Y, Cb and Cr plane pointers passed by the caller.
gfx/layers/YCbCrImageDataSerializer.cpp
gfx/layers/YCbCrImageDataSerializer.h
gfx/layers/ipc/SharedPlanarYCbCrImage.cpp
--- a/gfx/layers/YCbCrImageDataSerializer.cpp
+++ b/gfx/layers/YCbCrImageDataSerializer.cpp
@@ -148,35 +148,47 @@ static size_t ComputeOffset(uint32_t aSi
 // Minimum required shmem size in bytes
 size_t
 YCbCrImageDataSerializer::ComputeMinBufferSize(uint32_t aSize)
 {
   return ComputeOffset(aSize) + MOZ_ALIGN_WORD(sizeof(YCbCrBufferInfo));
 }
 
 void
-YCbCrImageDataSerializer::InitializeBufferInfo(const gfx::IntSize& aYSize,
+YCbCrImageDataSerializer::InitializeBufferInfo(uint32_t aYOffset,
+                                               uint32_t aCbOffset,
+                                               uint32_t aCrOffset,
+                                               const gfx::IntSize& aYSize,
                                                const gfx::IntSize& aCbCrSize,
                                                StereoMode aStereoMode)
 {
   YCbCrBufferInfo* info = GetYCbCrBufferInfo(mData);
-  info->mYOffset = MOZ_ALIGN_WORD(sizeof(YCbCrBufferInfo));
-  info->mCbOffset = info->mYOffset
-                  + MOZ_ALIGN_WORD(aYSize.width * aYSize.height);
-  info->mCrOffset = info->mCbOffset
-                  + MOZ_ALIGN_WORD(aCbCrSize.width * aCbCrSize.height);
-
+  uint32_t info_size = MOZ_ALIGN_WORD(sizeof(YCbCrBufferInfo));
+  info->mYOffset = info_size + aYOffset;
+  info->mCbOffset = info_size + aCbOffset;
+  info->mCrOffset = info_size + aCrOffset;
   info->mYWidth = aYSize.width;
   info->mYHeight = aYSize.height;
   info->mCbCrWidth = aCbCrSize.width;
   info->mCbCrHeight = aCbCrSize.height;
   info->mStereoMode = aStereoMode;
 }
 
 void
+YCbCrImageDataSerializer::InitializeBufferInfo(const gfx::IntSize& aYSize,
+                                               const gfx::IntSize& aCbCrSize,
+                                               StereoMode aStereoMode)
+{
+  uint32_t yOffset = MOZ_ALIGN_WORD(sizeof(YCbCrBufferInfo));
+  uint32_t cbOffset = yOffset + MOZ_ALIGN_WORD(aYSize.width * aYSize.height);
+  uint32_t crOffset = cbOffset + MOZ_ALIGN_WORD(aCbCrSize.width * aCbCrSize.height);
+  return InitializeBufferInfo(yOffset, cbOffset, crOffset, aYSize, aCbCrSize, aStereoMode);
+}
+
+void
 YCbCrImageDataSerializer::InitializeBufferInfo(const gfxIntSize& aYSize,
                                                const gfxIntSize& aCbCrSize,
                                                StereoMode aStereoMode)
 {
   InitializeBufferInfo(gfx::IntSize(aYSize.width, aYSize.height),
                        gfx::IntSize(aCbCrSize.width, aCbCrSize.height),
                        aStereoMode);
 }
--- a/gfx/layers/YCbCrImageDataSerializer.h
+++ b/gfx/layers/YCbCrImageDataSerializer.h
@@ -109,16 +109,22 @@ public:
                                      const gfxIntSize& aCbCrSize);
   static size_t ComputeMinBufferSize(uint32_t aSize);
 
   /**
    * Write the image informations in the buffer for given dimensions.
    * The provided pointer should point to the beginning of the (chunk of)
    * buffer on which we want to store the image.
    */
+  void InitializeBufferInfo(uint32_t aYOffset,
+                            uint32_t aCbOffset,
+                            uint32_t aCrOffset,
+                            const gfx::IntSize& aYSize,
+                            const gfx::IntSize& aCbCrSize,
+                            StereoMode aStereoMode);
   void InitializeBufferInfo(const gfx::IntSize& aYSize,
                             const gfx::IntSize& aCbCrSize,
                             StereoMode aStereoMode);
   void InitializeBufferInfo(const gfxIntSize& aYSize,
                             const gfxIntSize& aCbCrSize,
                             StereoMode aStereoMode);
 
   bool CopyData(const uint8_t* aYData,
--- a/gfx/layers/ipc/SharedPlanarYCbCrImage.cpp
+++ b/gfx/layers/ipc/SharedPlanarYCbCrImage.cpp
@@ -138,18 +138,31 @@ SharedPlanarYCbCrImage::AllocateAndGetNe
   return serializer.GetData();
 }
 
 void
 SharedPlanarYCbCrImage::SetDataNoCopy(const Data &aData)
 {
   mData = aData;
   mSize = aData.mPicSize;
+  /* SetDataNoCopy is used to update YUV plane offsets without (re)allocating
+   * memory previously allocated with AllocateAndGetNewBuffer().
+   * serializer.GetData() returns the address of the memory previously allocated
+   * with AllocateAndGetNewBuffer(), that we subtract from the Y, Cb, Cr
+   * channels to compute 0-based offsets to pass to InitializeBufferInfo.
+   */
   YCbCrImageDataSerializer serializer(mTextureClient->GetBuffer());
-  serializer.InitializeBufferInfo(aData.mYSize,
+  uint8_t *base = serializer.GetData();
+  uint32_t yOffset = aData.mYChannel - base;
+  uint32_t cbOffset = aData.mCbChannel - base;
+  uint32_t crOffset = aData.mCrChannel - base;
+  serializer.InitializeBufferInfo(yOffset,
+                                  cbOffset,
+                                  crOffset,
+                                  aData.mYSize,
                                   aData.mCbCrSize,
                                   aData.mStereoMode);
 }
 
 uint8_t*
 SharedPlanarYCbCrImage::AllocateBuffer(uint32_t aSize)
 {
   NS_ABORT_IF_FALSE(!mTextureClient->IsAllocated(),