Bug 565875. Part 1: Refactor PlanarYCbCrImageOGL to make ownership of its temporary buffer more explicit. r=bas

This commit is contained in:
Robert O'Callahan 2010-05-17 11:07:13 +12:00
Родитель 4791be9e87
Коммит 1efab30a6d
2 изменённых файлов: 28 добавлений и 32 удалений

Просмотреть файл

@ -207,25 +207,16 @@ ImageLayerOGL::RenderLayer(int)
PlanarYCbCrImageOGL::PlanarYCbCrImageOGL(mozilla::layers::LayerManagerOGL* aManager) PlanarYCbCrImageOGL::PlanarYCbCrImageOGL(mozilla::layers::LayerManagerOGL* aManager)
: PlanarYCbCrImage(NULL) : PlanarYCbCrImage(NULL)
, mLoaded(PR_FALSE)
, mHasData(PR_FALSE)
, mManager(aManager) , mManager(aManager)
, mHasData(PR_FALSE)
{ {
memset(mTextures, 0, sizeof(GLuint) * 3); memset(mTextures, 0, sizeof(GLuint) * 3);
} }
PlanarYCbCrImageOGL::~PlanarYCbCrImageOGL()
{
if (mHasData) {
delete [] mData.mYChannel;
delete [] mData.mCbChannel;
delete [] mData.mCrChannel;
}
}
void void
PlanarYCbCrImageOGL::SetData(const PlanarYCbCrImage::Data &aData) PlanarYCbCrImageOGL::SetData(const PlanarYCbCrImage::Data &aData)
{ {
// For now, we copy the data
int width_shift = 0; int width_shift = 0;
int height_shift = 0; int height_shift = 0;
if (aData.mYSize.width == aData.mCbCrSize.width && 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.mCbCrSize.height = aData.mPicSize.height >> height_shift;
mData.mYSize = aData.mPicSize; mData.mYSize = aData.mPicSize;
mData.mYStride = mData.mYSize.width; mData.mYStride = mData.mYSize.width;
mData.mCbChannel = new PRUint8[mData.mCbCrStride * mData.mCbCrSize.height]; mBuffer = new PRUint8[mData.mCbCrStride * mData.mCbCrSize.height * 2 +
mData.mCrChannel = new PRUint8[mData.mCbCrStride * mData.mCbCrSize.height]; mData.mYStride * mData.mYSize.height];
mData.mYChannel = new PRUint8[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_x = aData.mPicX >> width_shift;
int cbcr_y = aData.mPicY >> height_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++) { for (int i = 0; i < mData.mYSize.height; i++) {
memcpy(mData.mYChannel + i * mData.mYStride, memcpy(mData.mYChannel + i * mData.mYStride,
aData.mYChannel + ((aData.mPicY + i) * aData.mYStride) + aData.mPicX, aData.mYChannel + ((aData.mPicY + i) * aData.mYStride) + aData.mPicX,
mData.mYStride); 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; mSize = aData.mPicSize;
mHasData = PR_TRUE; mHasData = PR_TRUE;

Просмотреть файл

@ -93,7 +93,6 @@ class THEBES_API PlanarYCbCrImageOGL : public PlanarYCbCrImage
{ {
public: public:
PlanarYCbCrImageOGL(LayerManagerOGL *aManager); PlanarYCbCrImageOGL(LayerManagerOGL *aManager);
virtual ~PlanarYCbCrImageOGL();
virtual void SetData(const Data &aData); 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 * 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. * make sure the textures are created and filled on the main thread.
*/ */
virtual void AllocateTextures(); void AllocateTextures();
/** /**
* XXX * XXX
* Free the textures, we call this from the main thread when we're done * 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 * be destroyed off the main-thread and might not be able to properly clean
* up its textures * up its textures
*/ */
virtual void FreeTextures(); void FreeTextures();
virtual PRBool HasData() { return mHasData; } PRBool HasData() { return mHasData; }
Data mData; nsAutoArrayPtr<PRUint8> mBuffer;
PRBool mLoaded;
PRBool mHasData;
GLuint mTextures[3];
gfxIntSize mSize;
LayerManagerOGL *mManager; LayerManagerOGL *mManager;
Data mData;
gfxIntSize mSize;
GLuint mTextures[3];
PRPackedBool mHasData;
}; };