Back out c8f7bace9cf9, 17ec4e01c126 (bug 767480) r=bustage
authorKan-Ru Chen (陳侃如) <kanru@kanru.info>
Tue, 21 Aug 2012 17:55:02 +0800
changeset 108390 7bf66490dfadc559934a7f73d8a528e9caf62668
parent 108389 c8f7bace9cf901c983648de962a21a46975f683e
child 108391 e1ec49e3076f2f3d42bc0b6a4aaccc3ea369ba90
push idunknown
push userunknown
push dateunknown
reviewersbustage
bugs767480
milestone17.0a1
backs outc8f7bace9cf901c983648de962a21a46975f683e
Back out c8f7bace9cf9, 17ec4e01c126 (bug 767480) r=bustage
content/media/nsBuiltinDecoderReader.cpp
gfx/layers/GrallocImages.cpp
gfx/layers/GrallocImages.h
gfx/layers/ImageContainer.cpp
gfx/layers/ImageContainer.h
gfx/layers/ImageTypes.h
gfx/layers/Makefile.in
gfx/layers/d3d10/ImageLayerD3D10.cpp
gfx/layers/d3d9/ImageLayerD3D9.cpp
gfx/layers/ipc/ImageContainerChild.cpp
gfx/layers/opengl/ImageLayerOGL.cpp
--- a/content/media/nsBuiltinDecoderReader.cpp
+++ b/content/media/nsBuiltinDecoderReader.cpp
@@ -58,30 +58,16 @@ static bool
 ValidatePlane(const VideoData::YCbCrBuffer::Plane& aPlane)
 {
   return aPlane.mWidth <= PlanarYCbCrImage::MAX_DIMENSION &&
          aPlane.mHeight <= PlanarYCbCrImage::MAX_DIMENSION &&
          aPlane.mWidth * aPlane.mHeight < MAX_VIDEO_WIDTH * MAX_VIDEO_HEIGHT &&
          aPlane.mStride > 0;
 }
 
-static bool
-IsYV12Format(const VideoData::YCbCrBuffer::Plane& aYPlane,
-             const VideoData::YCbCrBuffer::Plane& aCbPlane,
-             const VideoData::YCbCrBuffer::Plane& aCrPlane)
-{
-  return
-    aYPlane.mWidth % 2 == 0 &&
-    aYPlane.mHeight % 2 == 0 &&
-    aYPlane.mWidth / 2 == aCbPlane.mWidth &&
-    aYPlane.mHeight / 2 == aCbPlane.mHeight &&
-    aCbPlane.mWidth == aCrPlane.mWidth &&
-    aCbPlane.mHeight == aCrPlane.mHeight;
-}
-
 bool
 nsVideoInfo::ValidateVideoRegion(const nsIntSize& aFrame,
                                  const nsIntRect& aPicture,
                                  const nsIntSize& aDisplay)
 {
   return
     aFrame.width <= PlanarYCbCrImage::MAX_DIMENSION &&
     aFrame.height <= PlanarYCbCrImage::MAX_DIMENSION &&
@@ -192,56 +178,48 @@ VideoData* VideoData::Create(nsVideoInfo
   }
 
   nsAutoPtr<VideoData> v(new VideoData(aOffset,
                                        aTime,
                                        aEndTime,
                                        aKeyframe,
                                        aTimecode,
                                        aInfo.mDisplay));
+  // Currently our decoder only knows how to output to PLANAR_YCBCR
+  // format.
+  ImageFormat format = PLANAR_YCBCR;
+  v->mImage = aContainer->CreateImage(&format, 1);
+  if (!v->mImage) {
+    return nullptr;
+  }
+  NS_ASSERTION(v->mImage->GetFormat() == PLANAR_YCBCR,
+               "Wrong format?");
+  PlanarYCbCrImage* videoImage = static_cast<PlanarYCbCrImage*>(v->mImage.get());
+
+  PlanarYCbCrImage::Data data;
   const YCbCrBuffer::Plane &Y = aBuffer.mPlanes[0];
   const YCbCrBuffer::Plane &Cb = aBuffer.mPlanes[1];
   const YCbCrBuffer::Plane &Cr = aBuffer.mPlanes[2];
 
-  // Currently our decoder only knows how to output to PLANAR_YCBCR
-  // format.
-  ImageFormat format[2] = {PLANAR_YCBCR, GRALLOC_PLANAR_YCBCR};
-  if (IsYV12Format(Y, Cb, Cr)) {
-    v->mImage = aContainer->CreateImage(format, 2);
-  } else {
-    v->mImage = aContainer->CreateImage(format, 1);
-  }
-  if (!v->mImage) {
-    return nullptr;
-  }
-  NS_ASSERTION(v->mImage->GetFormat() == PLANAR_YCBCR ||
-               v->mImage->GetFormat() == GRALLOC_PLANAR_YCBCR,
-               "Wrong format?");
-  PlanarYCbCrImage* videoImage = static_cast<PlanarYCbCrImage*>(v->mImage.get());
-
-  PlanarYCbCrImage::Data data;
   data.mYChannel = Y.mData;
   data.mYSize = gfxIntSize(Y.mWidth, Y.mHeight);
   data.mYStride = Y.mStride;
-  data.mYOffset = Y.mOffset;
-  data.mYSkip = Y.mSkip;
   data.mCbChannel = Cb.mData;
   data.mCrChannel = Cr.mData;
   data.mCbCrSize = gfxIntSize(Cb.mWidth, Cb.mHeight);
   data.mCbCrStride = Cb.mStride;
-  data.mCbOffset = Cb.mOffset;
-  data.mCbSkip = Cb.mSkip;
-  data.mCrOffset = Cr.mOffset;
-  data.mCrSkip = Cr.mSkip;
   data.mPicX = aPicture.x;
   data.mPicY = aPicture.y;
   data.mPicSize = gfxIntSize(aPicture.width, aPicture.height);
   data.mStereoMode = aInfo.mStereoMode;
 
-  videoImage->CopyData(data);
+  videoImage->CopyData(data,
+                       Y.mOffset, Y.mSkip,
+                       Cb.mOffset, Cb.mSkip,
+                       Cr.mOffset, Cr.mSkip);
   return v.forget();
 }
 
 void* nsBuiltinDecoderReader::VideoQueueMemoryFunctor::operator()(void* anObject) {
   const VideoData* v = static_cast<const VideoData*>(anObject);
   if (!v->mImage) {
     return nullptr;
   }
deleted file mode 100644
--- a/gfx/layers/GrallocImages.cpp
+++ /dev/null
@@ -1,108 +0,0 @@
-/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* vim: set ts=2 et sw=2 tw=80: */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this file,
- * You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#include "mozilla/layers/ImageBridgeChild.h"
-
-#include "nsDebug.h"
-#include "ImageContainer.h"
-#include "GrallocImages.h"
-
-using namespace mozilla::ipc;
-using namespace android;
-
-namespace mozilla {
-namespace layers {
-
-GrallocPlanarYCbCrImage::GrallocPlanarYCbCrImage()
-  : PlanarYCbCrImage(nullptr)
-{
-  mFormat = GRALLOC_PLANAR_YCBCR;
-}
-
-GrallocPlanarYCbCrImage::~GrallocPlanarYCbCrImage()
-{
-  ImageBridgeChild *ibc = ImageBridgeChild::GetSingleton();
-  ibc->DeallocSurfaceDescriptorGralloc(mSurfaceDescriptor);
-}
-
-void
-GrallocPlanarYCbCrImage::SetData(const Data& aData)
-{
-  NS_PRECONDITION(aData.mYSize.width % 2 == 0, "Image should have even width");
-  NS_PRECONDITION(aData.mYSize.height % 2 == 0, "Image should have even height");
-  NS_PRECONDITION(aData.mYStride % 16 == 0, "Image should have stride of multiple of 16 pixels");
-
-  mData = aData;
-  mSize = aData.mPicSize;
-
-  if (mSurfaceDescriptor.type() == SurfaceDescriptor::T__None) {
-    ImageBridgeChild *ibc = ImageBridgeChild::GetSingleton();
-    ibc->AllocSurfaceDescriptorGralloc(aData.mYSize,
-                                       HAL_PIXEL_FORMAT_YV12,
-                                       GraphicBuffer::USAGE_SW_READ_OFTEN |
-                                       GraphicBuffer::USAGE_SW_WRITE_OFTEN |
-                                       GraphicBuffer::USAGE_HW_TEXTURE,
-                                       &mSurfaceDescriptor);
-  }
-  sp<GraphicBuffer> graphicBuffer =
-    GrallocBufferActor::GetFrom(mSurfaceDescriptor.get_SurfaceDescriptorGralloc());
-  if (!graphicBuffer.get()) {
-    return;
-  }
-
-  if (graphicBuffer->initCheck() != NO_ERROR) {
-    return;
-  }
-
-  void* vaddr;
-  if (graphicBuffer->lock(GraphicBuffer::USAGE_SW_WRITE_OFTEN,
-                          &vaddr) != OK) {
-    return;
-  }
-
-  PRUint8* yChannel = static_cast<PRUint8*>(vaddr);
-  gfxIntSize ySize = gfxIntSize(aData.mYSize.width,
-                                aData.mYSize.height);
-  PRInt32 yStride = graphicBuffer->getStride();
-
-  PRUint8* vChannel = yChannel + (yStride * ySize.height);
-  gfxIntSize uvSize = gfxIntSize(ySize.width / 2,
-                                 ySize.height / 2);
-  // Align to 16 bytes boundary
-  PRInt32 uvStride = ((yStride / 2) + 15) & ~0x0F;
-  PRUint8* uChannel = vChannel + (uvStride * uvSize.height);
-
-  // Memory outside of the image width may not writable. If the stride
-  // equals to the image width then we can use only one copy.
-  if (yStride == mData.mYStride &&
-      yStride == ySize.width) {
-    memcpy(yChannel, mData.mYChannel, yStride * ySize.width);
-  } else {
-    for (int i = 0; i < ySize.height; i++) {
-      memcpy(yChannel + i * yStride,
-             mData.mYChannel + i * mData.mYStride,
-             ySize.width);
-    }
-  }
-  if (uvStride == mData.mCbCrStride &&
-      uvStride == uvSize.width) {
-    memcpy(uChannel, mData.mCbChannel, uvStride * uvSize.width);
-    memcpy(vChannel, mData.mCrChannel, uvStride * uvSize.width);
-  } else {
-    for (int i = 0; i < uvSize.height; i++) {
-      memcpy(uChannel + i * uvStride,
-             mData.mCbChannel + i * mData.mCbCrStride,
-             uvSize.width);
-      memcpy(vChannel + i * uvStride,
-             mData.mCrChannel + i * mData.mCbCrStride,
-             uvSize.width);
-    }
-  }
-  graphicBuffer->unlock();
-}
-
-} // namespace layers
-} // namespace mozilla
deleted file mode 100644
--- a/gfx/layers/GrallocImages.h
+++ /dev/null
@@ -1,70 +0,0 @@
-/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#ifndef GRALLOCIMAGES_H
-#define GRALLOCIMAGES_H
-
-#ifdef MOZ_WIDGET_GONK
-
-#include "mozilla/layers/LayersSurfaces.h"
-#include "ImageLayers.h"
-
-#include <ui/GraphicBuffer.h>
-
-namespace mozilla {
-namespace layers {
-
-/**
- * The YUV format supported by Android HAL
- *
- * 4:2:0 - CbCr width and height is half that of Y.
- *
- * This format assumes
- * - an even width
- * - an even height
- * - a horizontal stride multiple of 16 pixels
- * - a vertical stride equal to the height
- *
- * y_size = stride * height
- * c_size = ALIGN(stride/2, 16) * height/2
- * size = y_size + c_size * 2
- * cr_offset = y_size
- * cb_offset = y_size + c_size
- *
- * The Image that is rendered is the picture region defined by
- * mPicX, mPicY and mPicSize. The size of the rendered image is
- * mPicSize, not mYSize or mCbCrSize.
- */
-class THEBES_API GrallocPlanarYCbCrImage : public PlanarYCbCrImage {
-  typedef PlanarYCbCrImage::Data Data;
-
-public:
-  GrallocPlanarYCbCrImage();
-
-  virtual ~GrallocPlanarYCbCrImage();
-
-  /**
-   * This makes a copy of the data buffers, in order to support functioning
-   * in all different layer managers.
-   */
-  virtual void SetData(const Data& aData);
-
-  virtual PRUint32 GetDataSize() { return 0; }
-
-  virtual bool IsValid() { return mSurfaceDescriptor.type() != SurfaceDescriptor::T__None; }
-
-  SurfaceDescriptor GetSurfaceDescriptor() {
-    return mSurfaceDescriptor;
-  }
-
-private:
-  SurfaceDescriptor mSurfaceDescriptor;
-};
-
-} // namespace layers
-} // namespace mozilla
-#endif
-
-#endif /* GRALLOCIMAGES_H */
--- a/gfx/layers/ImageContainer.cpp
+++ b/gfx/layers/ImageContainer.cpp
@@ -4,17 +4,16 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 
 #include "mozilla/layers/ImageBridgeChild.h"
 #include "mozilla/layers/ImageContainerChild.h"
 
 #include "ImageContainer.h"
 #include "GonkIOSurfaceImage.h"
-#include "GrallocImages.h"
 #include "mozilla/ipc/Shmem.h"
 #include "mozilla/ipc/CrossProcessMutex.h"
 #include "SharedTextureImage.h"
 #include "gfxImageSurface.h"
 #include "gfxSharedImageSurface.h"
 #include "yuv_convert.h"
 #include "gfxUtils.h"
 
@@ -26,17 +25,16 @@
 #include "gfxD2DSurface.h"
 #include "gfxWindowsPlatform.h"
 #include <d3d10_1.h>
 
 #include "d3d10/ImageLayerD3D10.h"
 #endif
 
 using namespace mozilla::ipc;
-using namespace android;
 using mozilla::gfx::DataSourceSurface;
 using mozilla::gfx::SourceSurface;
 
 
 namespace mozilla {
 namespace layers {
 
 already_AddRefed<Image>
@@ -44,47 +42,32 @@ ImageFactory::CreateImage(const ImageFor
                           PRUint32 aNumFormats,
                           const gfxIntSize &,
                           BufferRecycleBin *aRecycleBin)
 {
   if (!aNumFormats) {
     return nullptr;
   }
   nsRefPtr<Image> img;
-#ifdef MOZ_WIDGET_GONK
-  if (FormatInList(aFormats, aNumFormats, GRALLOC_PLANAR_YCBCR)) {
-    img = new GrallocPlanarYCbCrImage();
-    return img.forget();
-  }
-#endif
   if (FormatInList(aFormats, aNumFormats, PLANAR_YCBCR)) {
     img = new PlanarYCbCrImage(aRecycleBin);
-    return img.forget();
-  }
-  if (FormatInList(aFormats, aNumFormats, CAIRO_SURFACE)) {
+  } else if (FormatInList(aFormats, aNumFormats, CAIRO_SURFACE)) {
     img = new CairoImage();
-    return img.forget();
-  }
-  if (FormatInList(aFormats, aNumFormats, SHARED_TEXTURE)) {
+  } else if (FormatInList(aFormats, aNumFormats, SHARED_TEXTURE)) {
     img = new SharedTextureImage();
-    return img.forget();
-  }
 #ifdef XP_MACOSX
-  if (FormatInList(aFormats, aNumFormats, MAC_IO_SURFACE)) {
+  } else if (FormatInList(aFormats, aNumFormats, MAC_IO_SURFACE)) {
     img = new MacIOSurfaceImage();
-    return img.forget();
-  }
 #endif
 #ifdef MOZ_WIDGET_GONK
-  if (FormatInList(aFormats, aNumFormats, GONK_IO_SURFACE)) {
+  } else if (FormatInList(aFormats, aNumFormats, GONK_IO_SURFACE)) {
     img = new GonkIOSurfaceImage();
-    return img.forget();
+#endif
   }
-#endif
-  return nullptr;
+  return img.forget();
 }
 
 BufferRecycleBin::BufferRecycleBin()
   : mLock("mozilla.layers.BufferRecycleBin.mLock")
 {
 }
 
 void
@@ -435,17 +418,20 @@ CopyPlane(PRUint8 *aDst, PRUint8 *aSrc,
       }
       aSrc += aStride;
       aDst += aStride;
     }
   }
 }
 
 void
-PlanarYCbCrImage::CopyData(const Data& aData)
+PlanarYCbCrImage::CopyData(const Data& aData,
+                           PRInt32 aYOffset, PRInt32 aYSkip,
+                           PRInt32 aCbOffset, PRInt32 aCbSkip,
+                           PRInt32 aCrOffset, PRInt32 aCrSkip)
 {
   mData = aData;
 
   // update buffer size
   mBufferSize = mData.mCbCrStride * mData.mCbCrSize.height * 2 +
                 mData.mYStride * mData.mYSize.height;
 
   // get new buffer
@@ -454,23 +440,23 @@ PlanarYCbCrImage::CopyData(const Data& a
     return;
 
   mData.mYChannel = mBuffer;
   mData.mCbChannel = mData.mYChannel + mData.mYStride * mData.mYSize.height;
   mData.mCrChannel = mData.mCbChannel + mData.mCbCrStride * mData.mCbCrSize.height;
 
   CopyPlane(mData.mYChannel, aData.mYChannel,
             mData.mYSize, mData.mYStride,
-            mData.mYOffset, mData.mYSkip);
+            aYOffset, aYSkip);
   CopyPlane(mData.mCbChannel, aData.mCbChannel,
             mData.mCbCrSize, mData.mCbCrStride,
-            mData.mCbOffset, mData.mCbSkip);
+            aCbOffset, aCbSkip);
   CopyPlane(mData.mCrChannel, aData.mCrChannel,
             mData.mCbCrSize, mData.mCbCrStride,
-            mData.mCrOffset, mData.mCrSkip);
+            aCrOffset, aCrSkip);
 
   mSize = aData.mPicSize;
 }
 
 void
 PlanarYCbCrImage::SetData(const Data &aData)
 {
   CopyData(aData);
--- a/gfx/layers/ImageContainer.h
+++ b/gfx/layers/ImageContainer.h
@@ -598,40 +598,29 @@ private:
  * 4:2:0 - CbCr width and height is half that of Y.
  *
  * The color format is detected based on the height/width ratios
  * defined above.
  * 
  * The Image that is rendered is the picture region defined by
  * mPicX, mPicY and mPicSize. The size of the rendered image is
  * mPicSize, not mYSize or mCbCrSize.
- *
- * mYOffset, mYSkip, mCbOffset, mCbSkip, mCrOffset, mCrSkip are added
- * to support various output formats from hardware decoder. m*Offset
- * are the extra left stride and m*Skip are per-pixel skips in the
- * source image.
  */
 class THEBES_API PlanarYCbCrImage : public Image {
 public:
   struct Data {
     // Luminance buffer
     PRUint8* mYChannel;
     PRInt32 mYStride;
     gfxIntSize mYSize;
-    PRInt32 mYOffset;
-    PRInt32 mYSkip;
     // Chroma buffers
     PRUint8* mCbChannel;
     PRUint8* mCrChannel;
     PRInt32 mCbCrStride;
     gfxIntSize mCbCrSize;
-    PRInt32 mCbOffset;
-    PRInt32 mCbSkip;
-    PRInt32 mCrOffset;
-    PRInt32 mCrSkip;
     // Picture region
     PRUint32 mPicX;
     PRUint32 mPicY;
     gfxIntSize mPicSize;
     StereoMode mStereoMode;
 
     nsIntRect GetPictureRect() const {
       return nsIntRect(mPicX, mPicY,
@@ -639,17 +628,17 @@ public:
                        mPicSize.height);
     }
   };
 
   enum {
     MAX_DIMENSION = 16384
   };
 
-  virtual ~PlanarYCbCrImage();
+  ~PlanarYCbCrImage();
 
   /**
    * This makes a copy of the data buffers, in order to support functioning
    * in all different layer managers.
    */
   virtual void SetData(const Data& aData);
 
   /**
@@ -660,53 +649,60 @@ public:
   virtual void SetDelayedConversion(bool aDelayed) { }
 
   /**
    * Grab the original YUV data. This is optional.
    */
   virtual const Data* GetData() { return &mData; }
 
   /**
-   * Return the number of bytes of heap memory used to store this image.
-   */
-  virtual PRUint32 GetDataSize() { return mBufferSize; }
-
-  virtual bool IsValid() { return !!mBufferSize; }
-
-  virtual gfxIntSize GetSize() { return mSize; }
-
-  PlanarYCbCrImage(BufferRecycleBin *aRecycleBin);
-
-protected:
-  /**
    * Make a copy of the YCbCr data into local storage.
    *
    * @param aData           Input image data.
+   * @param aYOffset        Pixels to skip between lines in the Y plane.
+   * @param aYSkip          Pixels to skip between pixels in the Y plane.
+   * @param aCbOffset       Pixels to skip between lines in the Cb plane.
+   * @param aCbSkip         Pixels to skip between pixels in the Cb plane.
+   * @param aCrOffset       Pixels to skip between lines in the Cr plane.
+   * @param aCrSkip         Pixels to skip between pixels in the Cr plane.
    */
-  void CopyData(const Data& aData);
+  void CopyData(const Data& aData,
+                PRInt32 aYOffset = 0, PRInt32 aYSkip = 0,
+                PRInt32 aCbOffset = 0, PRInt32 aCbSkip = 0,
+                PRInt32 aCrOffset = 0, PRInt32 aCrSkip = 0);
 
   /**
    * Return a buffer to store image data in.
    * The default implementation returns memory that can
    * be freed wit delete[]
    */
   virtual PRUint8* AllocateBuffer(PRUint32 aSize);
 
+  /**
+   * Return the number of bytes of heap memory used to store this image.
+   */
+  virtual PRUint32 GetDataSize() { return mBufferSize; }
+
   already_AddRefed<gfxASurface> GetAsSurface();
 
+  virtual gfxIntSize GetSize() { return mSize; }
+
   void SetOffscreenFormat(gfxASurface::gfxImageFormat aFormat) { mOffscreenFormat = aFormat; }
   gfxASurface::gfxImageFormat GetOffscreenFormat() { return mOffscreenFormat; }
 
+  // XXX - not easy to protect these sadly.
   nsAutoArrayPtr<PRUint8> mBuffer;
   PRUint32 mBufferSize;
   Data mData;
   gfxIntSize mSize;
   gfxASurface::gfxImageFormat mOffscreenFormat;
   nsCountedRef<nsMainThreadSurfaceRef> mSurface;
   nsRefPtr<BufferRecycleBin> mRecycleBin;
+
+  PlanarYCbCrImage(BufferRecycleBin *aRecycleBin);
 };
 
 /**
  * Currently, the data in a CairoImage surface is treated as being in the
  * device output color space. This class is very simple as all backends
  * have to know about how to deal with drawing a cairo image.
  */
 class THEBES_API CairoImage : public Image {
@@ -826,9 +822,9 @@ public:
   gfxIntSize mSize;
   RemoteImageData::Format mFormat;
 };
 
 
 } //namespace
 } //namespace
 
-#endif
+#endif
\ No newline at end of file
--- a/gfx/layers/ImageTypes.h
+++ b/gfx/layers/ImageTypes.h
@@ -12,23 +12,16 @@ enum ImageFormat {
   /**
    * The PLANAR_YCBCR format creates a PlanarYCbCrImage. All backends should
    * support this format, because the Ogg video decoder depends on it.
    * The maximum image width and height is 16384.
    */
   PLANAR_YCBCR,
 
   /**
-   * The GRALLOC_PLANAR_YCBCR format creates a GrallocPlanarYCbCrImage, a
-   * subtype of PlanarYCbCrImage. It takes a PlanarYCbCrImage data and can be
-   * used as a texture by Gonk backend directly.
-   */
-  GRALLOC_PLANAR_YCBCR,
-
-  /**
    * The CAIRO_SURFACE format creates a CairoImage. All backends should
    * support this format, because video rendering sometimes requires it.
    * 
    * This format is useful even though a ThebesLayer could be used.
    * It makes it easy to render a cairo surface when another Image format
    * could be used. It can also avoid copying the surface data in some
    * cases.
    * 
@@ -75,9 +68,9 @@ enum StereoMode {
   STEREO_MODE_RIGHT_LEFT,
   STEREO_MODE_BOTTOM_TOP,
   STEREO_MODE_TOP_BOTTOM
 };
 
 
 } // namespace
 
-#endif
+#endif
\ No newline at end of file
--- a/gfx/layers/Makefile.in
+++ b/gfx/layers/Makefile.in
@@ -167,20 +167,17 @@ EXPORTS_mozilla/layers += ShadowLayerUti
 DEFINES	+= -DMOZ_ENABLE_D3D10_LAYER
 endif
 
 # NB: Gralloc is available on other platforms that use the android GL
 # libraries, but only Gonk is able to use it reliably because Gecko
 # has full system permissions there.
 ifeq ($(MOZ_WIDGET_TOOLKIT),gonk)
 EXPORTS_mozilla/layers += ShadowLayerUtilsGralloc.h
-CPPSRCS += \
-        ShadowLayerUtilsGralloc.cpp \
-        GrallocImages.cpp \
-        $(NULL)
+CPPSRCS += ShadowLayerUtilsGralloc.cpp
 endif
 
 include $(topsrcdir)/config/rules.mk
 
 include $(topsrcdir)/ipc/chromium/chromium-config.mk
 
 LOCAL_INCLUDES += \
         -I$(topsrcdir)/content/events/src \
--- a/gfx/layers/d3d10/ImageLayerD3D10.cpp
+++ b/gfx/layers/d3d10/ImageLayerD3D10.cpp
@@ -219,17 +219,17 @@ ImageLayerD3D10::RenderLayer()
         (float)0,
         (float)size.width,
         (float)size.height)
       );
   } else if (image->GetFormat() == ImageFormat::PLANAR_YCBCR) {
     PlanarYCbCrImage *yuvImage =
       static_cast<PlanarYCbCrImage*>(image);
 
-    if (!yuvImage->IsValid()) {
+    if (!yuvImage->mBufferSize) {
       return;
     }
 
     if (!yuvImage->GetBackendData(mozilla::layers::LAYERS_D3D10)) {
       AllocateTexturesYCbCr(yuvImage);
     }
 
     PlanarYCbCrD3D10BackendData *data =
@@ -256,17 +256,17 @@ ImageLayerD3D10::RenderLayer()
     effect()->GetVariableByName("tCb")->AsShaderResource()->SetResource(data->mCbView);
     effect()->GetVariableByName("tCr")->AsShaderResource()->SetResource(data->mCrView);
 
     /*
      * Send 3d control data and metadata to NV3DVUtils
      */
     if (GetNv3DVUtils()) {
       Nv_Stereo_Mode mode;
-      switch (yuvImage->GetData()->mStereoMode) {
+      switch (yuvImage->mData.mStereoMode) {
       case STEREO_MODE_LEFT_RIGHT:
         mode = NV_STEREO_MODE_LEFT_RIGHT;
         break;
       case STEREO_MODE_RIGHT_LEFT:
         mode = NV_STEREO_MODE_RIGHT_LEFT;
         break;
       case STEREO_MODE_BOTTOM_TOP:
         mode = NV_STEREO_MODE_BOTTOM_TOP;
@@ -277,37 +277,37 @@ ImageLayerD3D10::RenderLayer()
       case STEREO_MODE_MONO:
         mode = NV_STEREO_MODE_MONO;
         break;
       }
       
       // Send control data even in mono case so driver knows to leave stereo mode.
       GetNv3DVUtils()->SendNv3DVControl(mode, true, FIREFOX_3DV_APP_HANDLE);
 
-      if (yuvImage->GetData()->mStereoMode != STEREO_MODE_MONO) {
+      if (yuvImage->mData.mStereoMode != STEREO_MODE_MONO) {
         // Dst resource is optional
-        GetNv3DVUtils()->SendNv3DVMetaData((unsigned int)yuvImage->GetData()->mYSize.width,
-                                           (unsigned int)yuvImage->GetData()->mYSize.height, (HANDLE)(data->mYTexture), (HANDLE)(NULL));
+        GetNv3DVUtils()->SendNv3DVMetaData((unsigned int)yuvImage->mData.mYSize.width, 
+                                           (unsigned int)yuvImage->mData.mYSize.height, (HANDLE)(data->mYTexture), (HANDLE)(NULL));
       }
     }
 
     effect()->GetVariableByName("vLayerQuad")->AsVector()->SetFloatVector(
       ShaderConstantRectD3D10(
         (float)0,
         (float)0,
         (float)size.width,
         (float)size.height)
       );
 
     effect()->GetVariableByName("vTextureCoords")->AsVector()->SetFloatVector(
       ShaderConstantRectD3D10(
-        (float)yuvImage->GetData()->mPicX / yuvImage->GetData()->mYSize.width,
-        (float)yuvImage->GetData()->mPicY / yuvImage->GetData()->mYSize.height,
-        (float)yuvImage->GetData()->mPicSize.width / yuvImage->GetData()->mYSize.width,
-        (float)yuvImage->GetData()->mPicSize.height / yuvImage->GetData()->mYSize.height)
+        (float)yuvImage->mData.mPicX / yuvImage->mData.mYSize.width,
+        (float)yuvImage->mData.mPicY / yuvImage->mData.mYSize.height,
+        (float)yuvImage->mData.mPicSize.width / yuvImage->mData.mYSize.width,
+        (float)yuvImage->mData.mPicSize.height / yuvImage->mData.mYSize.height)
        );
   }
   
   bool resetTexCoords = image->GetFormat() == ImageFormat::PLANAR_YCBCR;
   image = nullptr;
   autoLock.Unlock();
 
   technique->GetPassByIndex(0)->Apply(0);
@@ -325,36 +325,36 @@ ImageLayerD3D10::RenderLayer()
   GetContainer()->NotifyPaintedImage(image);
 }
 
 void ImageLayerD3D10::AllocateTexturesYCbCr(PlanarYCbCrImage *aImage)
 {
   nsAutoPtr<PlanarYCbCrD3D10BackendData> backendData(
     new PlanarYCbCrD3D10BackendData);
 
-  const PlanarYCbCrImage::Data *data = aImage->GetData();
+  PlanarYCbCrImage::Data &data = aImage->mData;
 
   D3D10_SUBRESOURCE_DATA dataY;
   D3D10_SUBRESOURCE_DATA dataCb;
   D3D10_SUBRESOURCE_DATA dataCr;
   CD3D10_TEXTURE2D_DESC descY(DXGI_FORMAT_R8_UNORM,
-                              data->mYSize.width,
-                              data->mYSize.height, 1, 1);
+                              data.mYSize.width,
+                              data.mYSize.height, 1, 1);
   CD3D10_TEXTURE2D_DESC descCbCr(DXGI_FORMAT_R8_UNORM,
-                                 data->mCbCrSize.width,
-                                 data->mCbCrSize.height, 1, 1);
+                                 data.mCbCrSize.width,
+                                 data.mCbCrSize.height, 1, 1);
 
   descY.Usage = descCbCr.Usage = D3D10_USAGE_IMMUTABLE;
 
-  dataY.pSysMem = data->mYChannel;
-  dataY.SysMemPitch = data->mYStride;
-  dataCb.pSysMem = data->mCbChannel;
-  dataCb.SysMemPitch = data->mCbCrStride;
-  dataCr.pSysMem = data->mCrChannel;
-  dataCr.SysMemPitch = data->mCbCrStride;
+  dataY.pSysMem = data.mYChannel;
+  dataY.SysMemPitch = data.mYStride;
+  dataCb.pSysMem = data.mCbChannel;
+  dataCb.SysMemPitch = data.mCbCrStride;
+  dataCr.pSysMem = data.mCrChannel;
+  dataCr.SysMemPitch = data.mCbCrStride;
 
   HRESULT hr = device()->CreateTexture2D(&descY, &dataY, getter_AddRefs(backendData->mYTexture));
   if (!FAILED(hr)) {
       hr = device()->CreateTexture2D(&descCbCr, &dataCb, getter_AddRefs(backendData->mCbTexture));
   }
   if (!FAILED(hr)) {
       hr = device()->CreateTexture2D(&descCbCr, &dataCr, getter_AddRefs(backendData->mCrTexture));
   }
--- a/gfx/layers/d3d9/ImageLayerD3D9.cpp
+++ b/gfx/layers/d3d9/ImageLayerD3D9.cpp
@@ -128,17 +128,17 @@ SurfaceToTexture(IDirect3DDevice9 *aDevi
 
 static void AllocateTexturesYCbCr(PlanarYCbCrImage *aImage,
                                   IDirect3DDevice9 *aDevice,
                                   LayerManagerD3D9 *aManager)
 {
   nsAutoPtr<PlanarYCbCrD3D9BackendData> backendData(
     new PlanarYCbCrD3D9BackendData);
 
-  const PlanarYCbCrImage::Data *data = aImage->GetData();
+  PlanarYCbCrImage::Data &data = aImage->mData;
 
   D3DLOCKED_RECT lockrectY;
   D3DLOCKED_RECT lockrectCb;
   D3DLOCKED_RECT lockrectCr;
   PRUint8* src;
   PRUint8* dest;
 
   nsRefPtr<IDirect3DSurface9> tmpSurfaceY;
@@ -155,41 +155,41 @@ static void AllocateTexturesYCbCr(Planar
     nsRefPtr<IDirect3DTexture9> tmpYTexture;
     nsRefPtr<IDirect3DTexture9> tmpCbTexture;
     nsRefPtr<IDirect3DTexture9> tmpCrTexture;
     // D3D9Ex does not support the managed pool, could use dynamic textures
     // here. But since an Image is immutable static textures are probably a
     // better idea.
 
     HRESULT hr;
-    hr = aDevice->CreateTexture(data->mYSize.width, data->mYSize.height,
+    hr = aDevice->CreateTexture(data.mYSize.width, data.mYSize.height,
                                 1, 0, D3DFMT_L8, D3DPOOL_DEFAULT,
                                 getter_AddRefs(backendData->mYTexture), NULL);
     if (!FAILED(hr)) {
-      hr = aDevice->CreateTexture(data->mCbCrSize.width, data->mCbCrSize.height,
+      hr = aDevice->CreateTexture(data.mCbCrSize.width, data.mCbCrSize.height,
                                   1, 0, D3DFMT_L8, D3DPOOL_DEFAULT,
                                   getter_AddRefs(backendData->mCbTexture), NULL);
     }
     if (!FAILED(hr)) {
-      hr = aDevice->CreateTexture(data->mCbCrSize.width, data->mCbCrSize.height,
+      hr = aDevice->CreateTexture(data.mCbCrSize.width, data.mCbCrSize.height,
                                   1, 0, D3DFMT_L8, D3DPOOL_DEFAULT,
                                   getter_AddRefs(backendData->mCrTexture), NULL);
     }
     if (!FAILED(hr)) {
-      hr = aDevice->CreateTexture(data->mYSize.width, data->mYSize.height,
+      hr = aDevice->CreateTexture(data.mYSize.width, data.mYSize.height,
                                   1, 0, D3DFMT_L8, D3DPOOL_SYSTEMMEM,
                                   getter_AddRefs(tmpYTexture), NULL);
     }
     if (!FAILED(hr)) {
-      hr = aDevice->CreateTexture(data->mCbCrSize.width, data->mCbCrSize.height,
+      hr = aDevice->CreateTexture(data.mCbCrSize.width, data.mCbCrSize.height,
                                   1, 0, D3DFMT_L8, D3DPOOL_SYSTEMMEM,
                                   getter_AddRefs(tmpCbTexture), NULL);
     }
     if (!FAILED(hr)) {
-      hr = aDevice->CreateTexture(data->mCbCrSize.width, data->mCbCrSize.height,
+      hr = aDevice->CreateTexture(data.mCbCrSize.width, data.mCbCrSize.height,
                                   1, 0, D3DFMT_L8, D3DPOOL_SYSTEMMEM,
                                   getter_AddRefs(tmpCrTexture), NULL);
     }
 
     if (FAILED(hr)) {
       aManager->ReportFailure(NS_LITERAL_CSTRING("PlanarYCbCrImageD3D9::AllocateTextures(): Failed to create texture (isD3D9Ex)"),
                               hr);
       return;
@@ -198,73 +198,73 @@ static void AllocateTexturesYCbCr(Planar
     tmpYTexture->GetSurfaceLevel(0, getter_AddRefs(tmpSurfaceY));
     tmpCbTexture->GetSurfaceLevel(0, getter_AddRefs(tmpSurfaceCb));
     tmpCrTexture->GetSurfaceLevel(0, getter_AddRefs(tmpSurfaceCr));
     tmpSurfaceY->LockRect(&lockrectY, NULL, 0);
     tmpSurfaceCb->LockRect(&lockrectCb, NULL, 0);
     tmpSurfaceCr->LockRect(&lockrectCr, NULL, 0);
   } else {
     HRESULT hr;
-    hr = aDevice->CreateTexture(data->mYSize.width, data->mYSize.height,
+    hr = aDevice->CreateTexture(data.mYSize.width, data.mYSize.height,
                                 1, 0, D3DFMT_L8, D3DPOOL_MANAGED,
                                 getter_AddRefs(backendData->mYTexture), NULL);
     if (!FAILED(hr)) {
-      aDevice->CreateTexture(data->mCbCrSize.width, data->mCbCrSize.height,
+      aDevice->CreateTexture(data.mCbCrSize.width, data.mCbCrSize.height,
                              1, 0, D3DFMT_L8, D3DPOOL_MANAGED,
                              getter_AddRefs(backendData->mCbTexture), NULL);
     }
     if (!FAILED(hr)) {
-      aDevice->CreateTexture(data->mCbCrSize.width, data->mCbCrSize.height,
+      aDevice->CreateTexture(data.mCbCrSize.width, data.mCbCrSize.height,
                              1, 0, D3DFMT_L8, D3DPOOL_MANAGED,
                              getter_AddRefs(backendData->mCrTexture), NULL);
     }
 
     if (FAILED(hr)) {
       aManager->ReportFailure(NS_LITERAL_CSTRING("PlanarYCbCrImageD3D9::AllocateTextures(): Failed to create texture (!isD3D9Ex)"),
                               hr);
       return;
     }
 
     /* lock the entire texture */
     backendData->mYTexture->LockRect(0, &lockrectY, NULL, 0);
     backendData->mCbTexture->LockRect(0, &lockrectCb, NULL, 0);
     backendData->mCrTexture->LockRect(0, &lockrectCr, NULL, 0);
   }
 
-  src  = data->mYChannel;
+  src  = data.mYChannel;
   //FIX cast
   dest = (PRUint8*)lockrectY.pBits;
 
   // copy over data
-  for (int h=0; h<data->mYSize.height; h++) {
-    memcpy(dest, src, data->mYSize.width);
+  for (int h=0; h<data.mYSize.height; h++) {
+    memcpy(dest, src, data.mYSize.width);
     dest += lockrectY.Pitch;
-    src += data->mYStride;
+    src += data.mYStride;
   }
 
-  src  = data->mCbChannel;
+  src  = data.mCbChannel;
   //FIX cast
   dest = (PRUint8*)lockrectCb.pBits;
 
   // copy over data
-  for (int h=0; h<data->mCbCrSize.height; h++) {
-    memcpy(dest, src, data->mCbCrSize.width);
+  for (int h=0; h<data.mCbCrSize.height; h++) {
+    memcpy(dest, src, data.mCbCrSize.width);
     dest += lockrectCb.Pitch;
-    src += data->mCbCrStride;
+    src += data.mCbCrStride;
   }
 
-  src  = data->mCrChannel;
+  src  = data.mCrChannel;
   //FIX cast
   dest = (PRUint8*)lockrectCr.pBits;
 
   // copy over data
-  for (int h=0; h<data->mCbCrSize.height; h++) {
-    memcpy(dest, src, data->mCbCrSize.width);
+  for (int h=0; h<data.mCbCrSize.height; h++) {
+    memcpy(dest, src, data.mCbCrSize.width);
     dest += lockrectCr.Pitch;
-    src += data->mCbCrStride;
+    src += data.mCbCrStride;
   }
 
   if (isD3D9Ex) {
     tmpSurfaceY->UnlockRect();
     tmpSurfaceCb->UnlockRect();
     tmpSurfaceCr->UnlockRect();
     nsRefPtr<IDirect3DSurface9> dstSurface;
     backendData->mYTexture->GetSurfaceLevel(0, getter_AddRefs(dstSurface));
@@ -295,30 +295,30 @@ ImageLayerD3D9::GetLayer()
   * If successful, aHasAlpha will be set to true if the texture has an
   * alpha component, false otherwise.
   */
 IDirect3DTexture9*
 ImageLayerD3D9::GetTexture(Image *aImage, bool& aHasAlpha)
 {
   NS_ASSERTION(aImage, "Null image.");
 
-  if (aImage->GetFormat() == REMOTE_IMAGE_BITMAP) {
+  if (aImage->GetFormat() == ImageFormat::REMOTE_IMAGE_BITMAP) {
     RemoteBitmapImage *remoteImage =
       static_cast<RemoteBitmapImage*>(aImage);
       
     if (!aImage->GetBackendData(mozilla::layers::LAYERS_D3D9)) {
       nsAutoPtr<TextureD3D9BackendData> dat(new TextureD3D9BackendData());
       dat->mTexture = DataToTexture(device(), remoteImage->mData, remoteImage->mStride, remoteImage->mSize, D3DFMT_A8R8G8B8);
       if (dat->mTexture) {
         aImage->SetBackendData(mozilla::layers::LAYERS_D3D9, dat.forget());
       }
     }
 
     aHasAlpha = remoteImage->mFormat == RemoteImageData::BGRA32;
-  } else if (aImage->GetFormat() == CAIRO_SURFACE) {
+  } else if (aImage->GetFormat() == ImageFormat::CAIRO_SURFACE) {
     CairoImage *cairoImage =
       static_cast<CairoImage*>(aImage);
 
     if (!cairoImage->mSurface) {
       return nullptr;
     }
 
     if (!aImage->GetBackendData(mozilla::layers::LAYERS_D3D9)) {
@@ -365,20 +365,20 @@ ImageLayerD3D9::RenderLayer()
   if (!image) {
     return;
   }
 
   SetShaderTransformAndOpacity();
 
   gfxIntSize size = mScaleMode == SCALE_NONE ? image->GetSize() : mScaleToSize;
 
-  if (image->GetFormat() == CAIRO_SURFACE ||
-      image->GetFormat() == REMOTE_IMAGE_BITMAP)
+  if (image->GetFormat() == ImageFormat::CAIRO_SURFACE ||
+      image->GetFormat() == ImageFormat::REMOTE_IMAGE_BITMAP)
   {
-    NS_ASSERTION(image->GetFormat() != CAIRO_SURFACE ||
+    NS_ASSERTION(image->GetFormat() != ImageFormat::CAIRO_SURFACE ||
                  !static_cast<CairoImage*>(image)->mSurface ||
                  static_cast<CairoImage*>(image)->mSurface->GetContentType() != gfxASurface::CONTENT_ALPHA,
                  "Image layer has alpha image");
 
     bool hasAlpha = false;
     nsRefPtr<IDirect3DTexture9> texture = GetTexture(image, hasAlpha);
 
     device()->SetVertexShaderConstantF(CBvLayerQuad,
@@ -407,17 +407,17 @@ ImageLayerD3D9::RenderLayer()
     if (mFilter == gfxPattern::FILTER_NEAREST) {
       device()->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);
       device()->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);
     }
   } else {
     PlanarYCbCrImage *yuvImage =
       static_cast<PlanarYCbCrImage*>(image);
 
-    if (!yuvImage->IsValid()) {
+    if (!yuvImage->mBufferSize) {
       return;
     }
 
     if (!yuvImage->GetBackendData(mozilla::layers::LAYERS_D3D9)) {
       AllocateTexturesYCbCr(yuvImage, device(), mD3DManager);
     }
 
     PlanarYCbCrD3D9BackendData *data =
@@ -437,31 +437,31 @@ ImageLayerD3D9::RenderLayer()
                                        ShaderConstantRect(0,
                                                           0,
                                                           size.width,
                                                           size.height),
                                        1);
 
     device()->SetVertexShaderConstantF(CBvTextureCoords,
       ShaderConstantRect(
-        (float)yuvImage->GetData()->mPicX / yuvImage->GetData()->mYSize.width,
-        (float)yuvImage->GetData()->mPicY / yuvImage->GetData()->mYSize.height,
-        (float)yuvImage->GetData()->mPicSize.width / yuvImage->GetData()->mYSize.width,
-        (float)yuvImage->GetData()->mPicSize.height / yuvImage->GetData()->mYSize.height
+        (float)yuvImage->mData.mPicX / yuvImage->mData.mYSize.width,
+        (float)yuvImage->mData.mPicY / yuvImage->mData.mYSize.height,
+        (float)yuvImage->mData.mPicSize.width / yuvImage->mData.mYSize.width,
+        (float)yuvImage->mData.mPicSize.height / yuvImage->mData.mYSize.height
       ),
       1);
 
     mD3DManager->SetShaderMode(DeviceManagerD3D9::YCBCRLAYER, GetMaskLayer());
 
     /*
      * Send 3d control data and metadata
      */
     if (mD3DManager->GetNv3DVUtils()) {
       Nv_Stereo_Mode mode;
-      switch (yuvImage->GetData()->mStereoMode) {
+      switch (yuvImage->mData.mStereoMode) {
       case STEREO_MODE_LEFT_RIGHT:
         mode = NV_STEREO_MODE_LEFT_RIGHT;
         break;
       case STEREO_MODE_RIGHT_LEFT:
         mode = NV_STEREO_MODE_RIGHT_LEFT;
         break;
       case STEREO_MODE_BOTTOM_TOP:
         mode = NV_STEREO_MODE_BOTTOM_TOP;
@@ -472,23 +472,23 @@ ImageLayerD3D9::RenderLayer()
       case STEREO_MODE_MONO:
         mode = NV_STEREO_MODE_MONO;
         break;
       }
 
       // Send control data even in mono case so driver knows to leave stereo mode.
       mD3DManager->GetNv3DVUtils()->SendNv3DVControl(mode, true, FIREFOX_3DV_APP_HANDLE);
 
-      if (yuvImage->GetData()->mStereoMode != STEREO_MODE_MONO) {
+      if (yuvImage->mData.mStereoMode != STEREO_MODE_MONO) {
         mD3DManager->GetNv3DVUtils()->SendNv3DVControl(mode, true, FIREFOX_3DV_APP_HANDLE);
 
         nsRefPtr<IDirect3DSurface9> renderTarget;
         device()->GetRenderTarget(0, getter_AddRefs(renderTarget));
-        mD3DManager->GetNv3DVUtils()->SendNv3DVMetaData((unsigned int)yuvImage->GetSize().width,
-                                                        (unsigned int)yuvImage->GetSize().height, (HANDLE)(data->mYTexture), (HANDLE)(renderTarget));
+        mD3DManager->GetNv3DVUtils()->SendNv3DVMetaData((unsigned int)yuvImage->mSize.width,
+                                                        (unsigned int)yuvImage->mSize.height, (HANDLE)(data->mYTexture), (HANDLE)(renderTarget));
       }
     }
 
     // Linear scaling is default here, adhering to mFilter is difficult since
     // presumably even with point filtering we'll still want chroma upsampling
     // to be linear. In the current approach we can't.
     device()->SetTexture(0, data->mYTexture);
     device()->SetTexture(1, data->mCbTexture);
@@ -517,18 +517,18 @@ ImageLayerD3D9::GetAsTexture(gfxIntSize*
   AutoLockImage autoLock(GetContainer());
 
   Image *image = autoLock.GetImage();
 
   if (!image) {
     return nullptr;
   }
 
-  if (image->GetFormat() != CAIRO_SURFACE &&
-      image->GetFormat() != REMOTE_IMAGE_BITMAP) {
+  if (image->GetFormat() != ImageFormat::CAIRO_SURFACE &&
+      image->GetFormat() != ImageFormat::REMOTE_IMAGE_BITMAP) {
     return nullptr;
   }
   
   bool dontCare;
   *aSize = image->GetSize();
   nsRefPtr<IDirect3DTexture9> result = GetTexture(image, dontCare);
   return result.forget();
 }
@@ -611,42 +611,42 @@ ShadowImageLayerD3D9::RenderLayer()
 {
   if (mD3DManager->CompositingDisabled()) {
     return;
   }
 
   if (mBuffer) {
     mBuffer->RenderTo(mD3DManager, GetEffectiveVisibleRegion());
   } else if (mYCbCrImage) {
-    if (!mYCbCrImage->IsValid()) {
+    if (!mYCbCrImage->mBufferSize) {
       return;
     }
 
     if (!mYCbCrImage->GetBackendData(mozilla::layers::LAYERS_D3D9)) {
       AllocateTexturesYCbCr(mYCbCrImage, device(), mD3DManager);
     }
 
     PlanarYCbCrD3D9BackendData *data =
       static_cast<PlanarYCbCrD3D9BackendData*>(mYCbCrImage->GetBackendData(mozilla::layers::LAYERS_D3D9));
 
     if (!data) {
       return;
     }
 
-    if (!mYCbCrImage->IsValid()) {
+    if (!mYCbCrImage->mBufferSize) {
       return;
     }
 
     SetShaderTransformAndOpacity();
 
     device()->SetVertexShaderConstantF(CBvLayerQuad,
                                        ShaderConstantRect(0,
                                                           0,
-                                                          mYCbCrImage->GetSize().width,
-                                                          mYCbCrImage->GetSize().height),
+                                                          mYCbCrImage->mSize.width,
+                                                          mYCbCrImage->mSize.height),
                                        1);
 
     mD3DManager->SetShaderMode(DeviceManagerD3D9::YCBCRLAYER, GetMaskLayer());
 
     /*
      * Send 3d control data and metadata
      */
     if (mD3DManager->GetNv3DVUtils()) {
--- a/gfx/layers/ipc/ImageContainerChild.cpp
+++ b/gfx/layers/ipc/ImageContainerChild.cpp
@@ -6,17 +6,16 @@
 
 #include "ImageContainerChild.h"
 #include "gfxSharedImageSurface.h"
 #include "ShadowLayers.h"
 #include "mozilla/layers/PLayers.h"
 #include "mozilla/layers/SharedImageUtils.h"
 #include "ImageContainer.h"
 #include "GonkIOSurfaceImage.h"
-#include "GrallocImages.h"
 
 namespace mozilla {
 namespace layers {
 
 /*
  * - POOL_MAX_SHARED_IMAGES is the maximum number number of shared images to
  * store in the ImageContainerChild's pool.
  *
@@ -202,20 +201,16 @@ SharedImage* ImageContainerChild::Create
     NS_ABORT_IF_FALSE(result->type() == SharedImage::TYUVImage,
                       "SharedImage type not set correctly");
     return result;
 #ifdef MOZ_WIDGET_GONK
   } else if (image->GetFormat() == GONK_IO_SURFACE) {
     GonkIOSurfaceImage* gonkImage = static_cast<GonkIOSurfaceImage*>(image);
     SharedImage* result = new SharedImage(gonkImage->GetSurfaceDescriptor());
     return result;
-  } else if (image->GetFormat() == GRALLOC_PLANAR_YCBCR) {
-    GrallocPlanarYCbCrImage* GrallocImage = static_cast<GrallocPlanarYCbCrImage*>(image);
-    SharedImage* result = new SharedImage(GrallocImage->GetSurfaceDescriptor());
-    return result;
 #endif
   } else {
     NS_RUNTIMEABORT("TODO: Only YUVImage is supported here right now.");
   }
   return nullptr;
 }
 
 bool ImageContainerChild::AddSharedImageToPool(SharedImage* img)
--- a/gfx/layers/opengl/ImageLayerOGL.cpp
+++ b/gfx/layers/opengl/ImageLayerOGL.cpp
@@ -248,17 +248,17 @@ ImageLayerOGL::RenderLayer(int,
     "Remote images aren't handled yet in OGL layers!");
   NS_ASSERTION(mScaleMode == SCALE_NONE,
     "Scale modes other than none not handled yet in OGL layers!");
 
   if (image->GetFormat() == PLANAR_YCBCR) {
     PlanarYCbCrImage *yuvImage =
       static_cast<PlanarYCbCrImage*>(image);
 
-    if (!yuvImage->IsValid()) {
+    if (!yuvImage->mBufferSize) {
       return;
     }
 
     PlanarYCbCrOGLBackendData *data =
       static_cast<PlanarYCbCrOGLBackendData*>(yuvImage->GetBackendData(LAYERS_OPENGL));
 
     if (data && data->mTextures->GetGLContext() != gl()) {
       // If these textures were allocated by another layer manager,
@@ -288,28 +288,28 @@ ImageLayerOGL::RenderLayer(int,
     gl()->fBindTexture(LOCAL_GL_TEXTURE_2D, data->mTextures[0].GetTextureID());
     gl()->ApplyFilterToBoundTexture(mFilter);
     
     ShaderProgramOGL *program = mOGLManager->GetProgram(YCbCrLayerProgramType,
                                                         GetMaskLayer());
 
     program->Activate();
     program->SetLayerQuadRect(nsIntRect(0, 0,
-                                        yuvImage->GetSize().width,
-                                        yuvImage->GetSize().height));
+                                        yuvImage->mSize.width,
+                                        yuvImage->mSize.height));
     program->SetLayerTransform(GetEffectiveTransform());
     program->SetLayerOpacity(GetEffectiveOpacity());
     program->SetRenderOffset(aOffset);
     program->SetYCbCrTextureUnits(0, 1, 2);
     program->LoadMask(GetMaskLayer());
 
     mOGLManager->BindAndDrawQuadWithTextureRect(program,
-                                                yuvImage->GetData()->GetPictureRect(),
-                                                nsIntSize(yuvImage->GetData()->mYSize.width,
-                                                          yuvImage->GetData()->mYSize.height));
+                                                yuvImage->mData.GetPictureRect(),
+                                                nsIntSize(yuvImage->mData.mYSize.width,
+                                                          yuvImage->mData.mYSize.height));
 
     // We shouldn't need to do this, but do it anyway just in case
     // someone else forgets.
     gl()->fActiveTexture(LOCAL_GL_TEXTURE0);
   } else if (image->GetFormat() == CAIRO_SURFACE) {
     CairoImage *cairoImage =
       static_cast<CairoImage*>(image);
 
@@ -527,42 +527,42 @@ ImageLayerOGL::ImageLayerOGL(LayerManage
   , mTextureRecycleBin(new TextureRecycleBin())
 { 
   mImplData = static_cast<LayerOGL*>(this);
 }
 
 void
 ImageLayerOGL::AllocateTexturesYCbCr(PlanarYCbCrImage *aImage)
 {
-  if (!aImage->IsValid())
+  if (!aImage->mBufferSize)
     return;
 
   nsAutoPtr<PlanarYCbCrOGLBackendData> backendData(
     new PlanarYCbCrOGLBackendData);
 
-  const PlanarYCbCrImage::Data *data = aImage->GetData();
+  PlanarYCbCrImage::Data &data = aImage->mData;
 
   gl()->MakeCurrent();
 
-  mTextureRecycleBin->GetTexture(TextureRecycleBin::TEXTURE_Y, data->mYSize, gl(), &backendData->mTextures[0]);
+  mTextureRecycleBin->GetTexture(TextureRecycleBin::TEXTURE_Y, data.mYSize, gl(), &backendData->mTextures[0]);
   SetClamping(gl(), backendData->mTextures[0].GetTextureID());
 
-  mTextureRecycleBin->GetTexture(TextureRecycleBin::TEXTURE_C, data->mCbCrSize, gl(), &backendData->mTextures[1]);
+  mTextureRecycleBin->GetTexture(TextureRecycleBin::TEXTURE_C, data.mCbCrSize, gl(), &backendData->mTextures[1]);
   SetClamping(gl(), backendData->mTextures[1].GetTextureID());
 
-  mTextureRecycleBin->GetTexture(TextureRecycleBin::TEXTURE_C, data->mCbCrSize, gl(), &backendData->mTextures[2]);
+  mTextureRecycleBin->GetTexture(TextureRecycleBin::TEXTURE_C, data.mCbCrSize, gl(), &backendData->mTextures[2]);
   SetClamping(gl(), backendData->mTextures[2].GetTextureID());
 
-  UploadYUVToTexture(gl(), *data,
+  UploadYUVToTexture(gl(), aImage->mData,
                      &backendData->mTextures[0],
                      &backendData->mTextures[1],
                      &backendData->mTextures[2]);
 
-  backendData->mYSize = data->mYSize;
-  backendData->mCbCrSize = data->mCbCrSize;
+  backendData->mYSize = aImage->mData.mYSize;
+  backendData->mCbCrSize = aImage->mData.mCbCrSize;
   backendData->mTextureRecycleBin = mTextureRecycleBin;
 
   aImage->SetBackendData(LAYERS_OPENGL, backendData.forget());
 }
 
 void
 ImageLayerOGL::AllocateTexturesCairo(CairoImage *aImage)
 {