diff --git a/gfx/layers/opengl/ImageLayerOGL.cpp b/gfx/layers/opengl/ImageLayerOGL.cpp index 88dc390e788..fd48bf5d307 100644 --- a/gfx/layers/opengl/ImageLayerOGL.cpp +++ b/gfx/layers/opengl/ImageLayerOGL.cpp @@ -207,25 +207,16 @@ ImageLayerOGL::RenderLayer(int) PlanarYCbCrImageOGL::PlanarYCbCrImageOGL(mozilla::layers::LayerManagerOGL* aManager) : PlanarYCbCrImage(NULL) - , mLoaded(PR_FALSE) - , mHasData(PR_FALSE) , mManager(aManager) + , mHasData(PR_FALSE) { memset(mTextures, 0, sizeof(GLuint) * 3); } -PlanarYCbCrImageOGL::~PlanarYCbCrImageOGL() -{ - if (mHasData) { - delete [] mData.mYChannel; - delete [] mData.mCbChannel; - delete [] mData.mCrChannel; - } -} - void PlanarYCbCrImageOGL::SetData(const PlanarYCbCrImage::Data &aData) { + // For now, we copy the data int width_shift = 0; int height_shift = 0; if (aData.mYSize.width == aData.mCbCrSize.width && @@ -252,26 +243,32 @@ PlanarYCbCrImageOGL::SetData(const PlanarYCbCrImage::Data &aData) mData.mCbCrSize.height = aData.mPicSize.height >> height_shift; mData.mYSize = aData.mPicSize; mData.mYStride = mData.mYSize.width; - mData.mCbChannel = new PRUint8[mData.mCbCrStride * mData.mCbCrSize.height]; - mData.mCrChannel = new PRUint8[mData.mCbCrStride * mData.mCbCrSize.height]; - mData.mYChannel = new PRUint8[mData.mYStride * mData.mYSize.height]; + mBuffer = new PRUint8[mData.mCbCrStride * mData.mCbCrSize.height * 2 + + mData.mYStride * mData.mYSize.height]; + mData.mYChannel = mBuffer; + mData.mCbChannel = mData.mYChannel + mData.mYStride * mData.mYSize.height; + mData.mCrChannel = mData.mCbChannel + mData.mCbCrStride * mData.mCbCrSize.height; int cbcr_x = aData.mPicX >> width_shift; int cbcr_y = aData.mPicY >> height_shift; - for (int i = 0; i < mData.mCbCrSize.height; i++) { - memcpy(mData.mCbChannel + i * mData.mCbCrStride, - aData.mCbChannel + ((cbcr_y + i) * aData.mCbCrStride) + cbcr_x, - mData.mCbCrStride); - memcpy(mData.mCrChannel + i * mData.mCbCrStride, - aData.mCrChannel + ((cbcr_y + i) * aData.mCbCrStride) + cbcr_x, - mData.mCbCrStride); - } for (int i = 0; i < mData.mYSize.height; i++) { memcpy(mData.mYChannel + i * mData.mYStride, aData.mYChannel + ((aData.mPicY + i) * aData.mYStride) + aData.mPicX, mData.mYStride); } - + for (int i = 0; i < mData.mCbCrSize.height; i++) { + memcpy(mData.mCbChannel + i * mData.mCbCrStride, + aData.mCbChannel + ((cbcr_y + i) * aData.mCbCrStride) + cbcr_x, + mData.mCbCrStride); + } + for (int i = 0; i < mData.mCbCrSize.height; i++) { + memcpy(mData.mCrChannel + i * mData.mCbCrStride, + aData.mCrChannel + ((cbcr_y + i) * aData.mCbCrStride) + cbcr_x, + mData.mCbCrStride); + } + + // Fix picture rect to be correct + mData.mPicX = mData.mPicY = 0; mSize = aData.mPicSize; mHasData = PR_TRUE; diff --git a/gfx/layers/opengl/ImageLayerOGL.h b/gfx/layers/opengl/ImageLayerOGL.h index 09dab61d7f9..13b6bfe3c3a 100644 --- a/gfx/layers/opengl/ImageLayerOGL.h +++ b/gfx/layers/opengl/ImageLayerOGL.h @@ -93,7 +93,6 @@ class THEBES_API PlanarYCbCrImageOGL : public PlanarYCbCrImage { public: PlanarYCbCrImageOGL(LayerManagerOGL *aManager); - virtual ~PlanarYCbCrImageOGL(); virtual void SetData(const Data &aData); @@ -101,7 +100,7 @@ public: * Upload the data from out mData into our textures. For now we use this to * make sure the textures are created and filled on the main thread. */ - virtual void AllocateTextures(); + void AllocateTextures(); /** * XXX * Free the textures, we call this from the main thread when we're done @@ -109,15 +108,15 @@ public: * be destroyed off the main-thread and might not be able to properly clean * up its textures */ - virtual void FreeTextures(); - virtual PRBool HasData() { return mHasData; } + void FreeTextures(); + PRBool HasData() { return mHasData; } - Data mData; - PRBool mLoaded; - PRBool mHasData; - GLuint mTextures[3]; - gfxIntSize mSize; + nsAutoArrayPtr mBuffer; LayerManagerOGL *mManager; + Data mData; + gfxIntSize mSize; + GLuint mTextures[3]; + PRPackedBool mHasData; };