Back out bug 656185 due to windows compile failures

This commit is contained in:
Matt Woodrow
2011-06-27 15:21:22 +12:00
parent 9d9105e74d
commit da5429fd82
20 changed files with 438 additions and 358 deletions

View File

@@ -407,12 +407,6 @@ public:
PRUint32 mPicY;
gfxIntSize mPicSize;
StereoMode mStereoMode;
nsIntRect GetPictureRect() const {
return nsIntRect(mPicX, mPicY,
mPicSize.width,
mPicSize.height);
}
};
enum {
@@ -439,20 +433,6 @@ public:
*/
virtual const Data* GetData() { return nsnull; }
/**
* Make a copy of the YCbCr data.
*
* @param aDest Data object to store the plane data in.
* @param aDestSize Size of the Y plane that was copied.
* @param aDestBufferSize Number of bytes allocated for storage.
* @param aData Input image data.
* @return Raw data pointer for the planes or nsnull on failure.
*/
PRUint8 *CopyData(Data& aDest, gfxIntSize& aDestSize,
PRUint32& aDestBufferSize, const Data& aData);
virtual PRUint8* AllocateBuffer(PRUint32 aSize) { return new (mozilla::fallible_t()) PRUint8[aSize]; };
protected:
PlanarYCbCrImage(void* aImplData) : Image(aImplData, PLANAR_YCBCR) {}
};

View File

@@ -481,49 +481,6 @@ ContainerLayer::DidInsertChild(Layer* aLayer)
}
}
PRUint8*
PlanarYCbCrImage::CopyData(Data& aDest, gfxIntSize& aDestSize,
PRUint32& aDestBufferSize, const Data& aData)
{
aDest = aData;
/* We always have a multiple of 16 width so we can force the stride */
aDest.mYStride = aDest.mYSize.width;
aDest.mCbCrStride = aDest.mCbCrSize.width;
// update buffer size
aDestBufferSize = aDest.mCbCrStride * aDest.mCbCrSize.height * 2 +
aDest.mYStride * aDest.mYSize.height;
// get new buffer
PRUint8* buffer = AllocateBuffer(aDestBufferSize);
if (!buffer)
return nsnull;
aDest.mYChannel = buffer;
aDest.mCbChannel = aDest.mYChannel + aDest.mYStride * aDest.mYSize.height;
aDest.mCrChannel = aDest.mCbChannel + aDest.mCbCrStride * aDest.mCbCrSize.height;
for (int i = 0; i < aDest.mYSize.height; i++) {
memcpy(aDest.mYChannel + i * aDest.mYStride,
aData.mYChannel + i * aData.mYStride,
aDest.mYStride);
}
for (int i = 0; i < aDest.mCbCrSize.height; i++) {
memcpy(aDest.mCbChannel + i * aDest.mCbCrStride,
aData.mCbChannel + i * aData.mCbCrStride,
aDest.mCbCrStride);
memcpy(aDest.mCrChannel + i * aDest.mCbCrStride,
aData.mCrChannel + i * aData.mCbCrStride,
aDest.mCbCrStride);
}
aDestSize = aData.mPicSize;
return buffer;
}
#ifdef MOZ_LAYERS_HAVE_LOG
static nsACString& PrintInfo(nsACString& aTo, ShadowLayer* aShadowLayer);

View File

@@ -149,16 +149,78 @@ BasicPlanarYCbCrImage::SetData(const Data& aData)
return;
}
gfx::YUVType type = gfx::YV12;
int width_shift = 0;
int height_shift = 0;
if (aData.mYSize.width == aData.mCbCrSize.width &&
aData.mYSize.height == aData.mCbCrSize.height) {
type = gfx::YV24;
width_shift = 0;
height_shift = 0;
}
else if (aData.mYSize.width / 2 == aData.mCbCrSize.width &&
aData.mYSize.height == aData.mCbCrSize.height) {
type = gfx::YV16;
width_shift = 1;
height_shift = 0;
}
else if (aData.mYSize.width / 2 == aData.mCbCrSize.width &&
aData.mYSize.height / 2 == aData.mCbCrSize.height ) {
type = gfx::YV12;
width_shift = 1;
height_shift = 1;
}
else {
NS_ERROR("YCbCr format not supported");
}
if (mDelayedConversion) {
mBuffer = CopyData(mData, mSize, mBufferSize, aData);
mData = aData;
mData.mCbCrStride = mData.mCbCrSize.width = aData.mPicSize.width >> width_shift;
// Round up the values for width and height to make sure we sample enough data
// for the last pixel - See bug 590735
if (width_shift && (aData.mPicSize.width & 1)) {
mData.mCbCrStride++;
mData.mCbCrSize.width++;
}
mData.mCbCrSize.height = aData.mPicSize.height >> height_shift;
if (height_shift && (aData.mPicSize.height & 1)) {
mData.mCbCrSize.height++;
}
mData.mYSize = aData.mPicSize;
mData.mYStride = mData.mYSize.width;
mBufferSize = mData.mCbCrStride * mData.mCbCrSize.height * 2 +
mData.mYStride * mData.mYSize.height;
mBuffer = new PRUint8[mBufferSize];
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.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;
return;
}
gfx::YUVType type =
gfx::TypeFromSize(aData.mYSize.width,
aData.mYSize.height,
aData.mCbCrSize.width,
aData.mCbCrSize.height);
gfxASurface::gfxImageFormat format = GetOffscreenFormat();

View File

@@ -2223,8 +2223,7 @@ BasicShadowableImageLayer::Paint(gfxContext* aContext)
YUVImage yuv(tmpYSurface->GetShmem(),
tmpUSurface->GetShmem(),
tmpVSurface->GetShmem(),
data->GetPictureRect());
tmpVSurface->GetShmem());
BasicManager()->CreatedImageBuffer(BasicManager()->Hold(this),
nsIntSize(mSize.width, mSize.height),
@@ -2232,24 +2231,19 @@ BasicShadowableImageLayer::Paint(gfxContext* aContext)
}
for (int i = 0; i < data->mYSize.height; i++) {
memcpy(mBackBufferY->Data() + i * mBackBufferY->Stride(),
data->mYChannel + i * data->mYStride,
data->mYSize.width);
}
for (int i = 0; i < data->mCbCrSize.height; i++) {
memcpy(mBackBufferU->Data() + i * mBackBufferU->Stride(),
data->mCbChannel + i * data->mCbCrStride,
data->mCbCrSize.width);
memcpy(mBackBufferV->Data() + i * mBackBufferV->Stride(),
data->mCrChannel + i * data->mCbCrStride,
data->mCbCrSize.width);
}
memcpy(mBackBufferY->Data(),
data->mYChannel,
data->mYStride * mSize.height);
memcpy(mBackBufferU->Data(),
data->mCbChannel,
data->mCbCrStride * mCbCrSize.height);
memcpy(mBackBufferV->Data(),
data->mCrChannel,
data->mCbCrStride * mCbCrSize.height);
YUVImage yuv(mBackBufferY->GetShmem(),
mBackBufferU->GetShmem(),
mBackBufferV->GetShmem(),
data->GetPictureRect());
mBackBufferV->GetShmem());
BasicManager()->PaintedImage(BasicManager()->Hold(this),
yuv);

View File

@@ -348,24 +348,11 @@ ImageLayerD3D10::RenderLayer()
(float)yuvImage->mSize.width,
(float)yuvImage->mSize.height)
);
effect()->GetVariableByName("vTextureCoords")->AsVector()->SetFloatVector(
ShaderConstantRectD3D10(
(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)
);
}
technique->GetPassByIndex(0)->Apply(0);
device()->Draw(4, 0);
if (image->GetFormat() == Image::PLANAR_YCBCR) {
effect()->GetVariableByName("vTextureCoords")->AsVector()->
SetFloatVector(ShaderConstantRectD3D10(0, 0, 1.0f, 1.0f));
}
GetContainer()->NotifyPaintedImage(image);
}
@@ -379,8 +366,75 @@ PlanarYCbCrImageD3D10::PlanarYCbCrImageD3D10(ID3D10Device1 *aDevice)
void
PlanarYCbCrImageD3D10::SetData(const PlanarYCbCrImage::Data &aData)
{
PRUint32 dummy;
mBuffer = CopyData(mData, mSize, dummy, aData);
// XXX - For D3D10Ex we really should just copy to systemmem surfaces here.
// For now, we copy the data
int width_shift = 0;
int height_shift = 0;
if (aData.mYSize.width == aData.mCbCrSize.width &&
aData.mYSize.height == aData.mCbCrSize.height) {
// YV24 format
width_shift = 0;
height_shift = 0;
mType = gfx::YV24;
} else if (aData.mYSize.width / 2 == aData.mCbCrSize.width &&
aData.mYSize.height == aData.mCbCrSize.height) {
// YV16 format
width_shift = 1;
height_shift = 0;
mType = gfx::YV16;
} else if (aData.mYSize.width / 2 == aData.mCbCrSize.width &&
aData.mYSize.height / 2 == aData.mCbCrSize.height ) {
// YV12 format
width_shift = 1;
height_shift = 1;
mType = gfx::YV12;
} else {
NS_ERROR("YCbCr format not supported");
}
mData = aData;
mData.mCbCrStride = mData.mCbCrSize.width = aData.mPicSize.width >> width_shift;
// Round up the values for width and height to make sure we sample enough data
// for the last pixel - See bug 590735
if (width_shift && (aData.mPicSize.width & 1)) {
mData.mCbCrStride++;
mData.mCbCrSize.width++;
}
mData.mCbCrSize.height = aData.mPicSize.height >> height_shift;
if (height_shift && (aData.mPicSize.height & 1)) {
mData.mCbCrSize.height++;
}
mData.mYSize = aData.mPicSize;
mData.mYStride = mData.mYSize.width;
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.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;
AllocateTextures();
@@ -422,26 +476,20 @@ PlanarYCbCrImageD3D10::GetAsSurface()
{
nsRefPtr<gfxImageSurface> imageSurface =
new gfxImageSurface(mSize, gfxASurface::ImageFormatRGB24);
gfx::YUVType type =
gfx::TypeFromSize(mData.mYSize.width,
mData.mYSize.height,
mData.mCbCrSize.width,
mData.mCbCrSize.height);
// Convert from YCbCr to RGB now
gfx::ConvertYCbCrToRGB32(mData.mYChannel,
mData.mCbChannel,
mData.mCrChannel,
imageSurface->Data(),
mData.mPicX,
mData.mPicY,
mData.mPicSize.width,
mData.mPicSize.height,
0,
0,
mSize.width,
mSize.height,
mData.mYStride,
mData.mCbCrStride,
imageSurface->Stride(),
type);
mType);
return imageSurface.forget().get();
}

View File

@@ -127,6 +127,7 @@ public:
nsRefPtr<ID3D10ShaderResourceView> mCbView;
nsRefPtr<ID3D10ShaderResourceView> mCrView;
PRPackedBool mHasData;
gfx::YUVType mType;
};

View File

@@ -287,15 +287,6 @@ ImageLayerD3D9::RenderLayer()
yuvImage->mSize.height),
1);
device()->SetVertexShaderConstantF(CBvTextureCoords,
ShaderConstantRect(
(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);
/*
@@ -343,9 +334,6 @@ ImageLayerD3D9::RenderLayer()
device()->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2);
device()->SetVertexShaderConstantF(CBvTextureCoords,
ShaderConstantRect(0, 0, 1.0f, 1.0f), 1);
} else if (image->GetFormat() == Image::CAIRO_SURFACE) {
CairoImageD3D9 *cairoImage =
static_cast<CairoImageD3D9*>(image.get());
@@ -398,8 +386,75 @@ PlanarYCbCrImageD3D9::PlanarYCbCrImageD3D9()
void
PlanarYCbCrImageD3D9::SetData(const PlanarYCbCrImage::Data &aData)
{
PRUint32 dummy;
mBuffer = CopyData(mData, mSize, dummy, aData);
// XXX - For D3D9Ex we really should just copy to systemmem surfaces here.
// For now, we copy the data
int width_shift = 0;
int height_shift = 0;
if (aData.mYSize.width == aData.mCbCrSize.width &&
aData.mYSize.height == aData.mCbCrSize.height) {
// YV24 format
width_shift = 0;
height_shift = 0;
mType = gfx::YV24;
} else if (aData.mYSize.width / 2 == aData.mCbCrSize.width &&
aData.mYSize.height == aData.mCbCrSize.height) {
// YV16 format
width_shift = 1;
height_shift = 0;
mType = gfx::YV16;
} else if (aData.mYSize.width / 2 == aData.mCbCrSize.width &&
aData.mYSize.height / 2 == aData.mCbCrSize.height ) {
// YV12 format
width_shift = 1;
height_shift = 1;
mType = gfx::YV12;
} else {
NS_ERROR("YCbCr format not supported");
}
mData = aData;
mData.mCbCrStride = mData.mCbCrSize.width = aData.mPicSize.width >> width_shift;
// Round up the values for width and height to make sure we sample enough data
// for the last pixel - See bug 590735
if (width_shift && (aData.mPicSize.width & 1)) {
mData.mCbCrStride++;
mData.mCbCrSize.width++;
}
mData.mCbCrSize.height = aData.mPicSize.height >> height_shift;
if (height_shift && (aData.mPicSize.height & 1)) {
mData.mCbCrSize.height++;
}
mData.mYSize = aData.mPicSize;
mData.mYStride = mData.mYSize.width;
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.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;
}
@@ -532,26 +587,20 @@ PlanarYCbCrImageD3D9::GetAsSurface()
{
nsRefPtr<gfxImageSurface> imageSurface =
new gfxImageSurface(mSize, gfxASurface::ImageFormatRGB24);
gfx::YUVType type =
gfx::TypeFromSize(mData.mYSize.width,
mData.mYSize.height,
mData.mCbCrSize.width,
mData.mCbCrSize.height);
// Convert from YCbCr to RGB now
gfx::ConvertYCbCrToRGB32(mData.mYChannel,
mData.mCbChannel,
mData.mCrChannel,
imageSurface->Data(),
mData.mPicX,
mData.mPicY,
mData.mPicSize.width,
mData.mPicSize.height,
0,
0,
mSize.width,
mSize.height,
mData.mYStride,
mData.mCbCrStride,
imageSurface->Stride(),
type);
mType);
return imageSurface.forget().get();
}

View File

@@ -132,6 +132,7 @@ public:
nsRefPtr<IDirect3DTexture9> mCrTexture;
nsRefPtr<IDirect3DTexture9> mCbTexture;
PRPackedBool mHasData;
gfx::YUVType mType;
};

View File

@@ -87,7 +87,6 @@ struct YUVImage {
Shmem Ydata;
Shmem Udata;
Shmem Vdata;
nsIntRect picture;
};
union SharedImage {

View File

@@ -276,29 +276,23 @@ ImageContainerOGL::GetCurrentAsSurface(gfxIntSize *aSize)
return nsnull;
}
size = yuvImage->mData.mPicSize;
size = yuvImage->mSize;
nsRefPtr<gfxImageSurface> imageSurface =
new gfxImageSurface(size, gfxASurface::ImageFormatRGB24);
gfx::YUVType type =
gfx::TypeFromSize(yuvImage->mData.mYSize.width,
yuvImage->mData.mYSize.height,
yuvImage->mData.mCbCrSize.width,
yuvImage->mData.mCbCrSize.height);
gfx::ConvertYCbCrToRGB32(yuvImage->mData.mYChannel,
yuvImage->mData.mCbChannel,
yuvImage->mData.mCrChannel,
imageSurface->Data(),
yuvImage->mData.mPicX,
yuvImage->mData.mPicY,
0,
0,
size.width,
size.height,
yuvImage->mData.mYStride,
yuvImage->mData.mCbCrStride,
imageSurface->Stride(),
type);
yuvImage->mType);
*aSize = size;
return imageSurface.forget().get();
@@ -438,10 +432,7 @@ ImageLayerOGL::RenderLayer(int,
program->SetRenderOffset(aOffset);
program->SetYCbCrTextureUnits(0, 1, 2);
mOGLManager->BindAndDrawQuadWithTextureRect(program,
yuvImage->mData.GetPictureRect(),
nsIntSize(yuvImage->mData.mYSize.width,
yuvImage->mData.mYSize.height));
mOGLManager->BindAndDrawQuad(program);
// We shouldn't need to do this, but do it anyway just in case
// someone else forgets.
@@ -671,11 +662,84 @@ PlanarYCbCrImageOGL::~PlanarYCbCrImageOGL()
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 &&
aData.mYSize.height == aData.mCbCrSize.height) {
// YV24 format
width_shift = 0;
height_shift = 0;
mType = gfx::YV24;
} else if (aData.mYSize.width / 2 == aData.mCbCrSize.width &&
aData.mYSize.height == aData.mCbCrSize.height) {
// YV16 format
width_shift = 1;
height_shift = 0;
mType = gfx::YV16;
} else if (aData.mYSize.width / 2 == aData.mCbCrSize.width &&
aData.mYSize.height / 2 == aData.mCbCrSize.height ) {
// YV12 format
width_shift = 1;
height_shift = 1;
mType = gfx::YV12;
} else {
NS_ERROR("YCbCr format not supported");
}
mData = aData;
mData.mCbCrStride = mData.mCbCrSize.width = aData.mPicSize.width >> width_shift;
// Round up the values for width and height to make sure we sample enough data
// for the last pixel - See bug 590735
if (width_shift && (aData.mPicSize.width & 1)) {
mData.mCbCrStride++;
mData.mCbCrSize.width++;
}
mData.mCbCrSize.height = aData.mPicSize.height >> height_shift;
if (height_shift && (aData.mPicSize.height & 1)) {
mData.mCbCrSize.height++;
}
mData.mYSize = aData.mPicSize;
mData.mYStride = mData.mYSize.width;
// Recycle the previous image main-memory buffer now that we're about to get a new buffer
if (mBuffer)
mRecycleBin->RecycleBuffer(mBuffer.forget(), mBufferSize);
mBuffer = CopyData(mData, mSize, mBufferSize, aData);
// update buffer size
mBufferSize = mData.mCbCrStride * mData.mCbCrSize.height * 2 +
mData.mYStride * mData.mYSize.height;
// get new buffer
mBuffer = mRecycleBin->GetBuffer(mBufferSize);
if (!mBuffer)
return;
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.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;
}
@@ -701,28 +765,60 @@ UploadYUVToTexture(GLContext* gl, const PlanarYCbCrImage::Data& aData,
GLTexture* aUTexture,
GLTexture* aVTexture)
{
nsIntRect size(0, 0, aData.mYSize.width, aData.mYSize.height);
GLuint texture = aYTexture->GetTextureID();
nsRefPtr<gfxASurface> surf = new gfxImageSurface(aData.mYChannel,
aData.mYSize,
aData.mYStride,
gfxASurface::ImageFormatA8);
gl->UploadSurfaceToTexture(surf, size, texture, true);
size = nsIntRect(0, 0, aData.mCbCrSize.width, aData.mCbCrSize.height);
texture = aUTexture->GetTextureID();
surf = new gfxImageSurface(aData.mCbChannel,
aData.mCbCrSize,
aData.mCbCrStride,
gfxASurface::ImageFormatA8);
gl->UploadSurfaceToTexture(surf, size, texture, true);
GLint alignment;
texture = aVTexture->GetTextureID();
surf = new gfxImageSurface(aData.mCrChannel,
aData.mCbCrSize,
aData.mCbCrStride,
gfxASurface::ImageFormatA8);
gl->UploadSurfaceToTexture(surf, size, texture, true);
if (!((ptrdiff_t)aData.mYStride & 0x7) && !((ptrdiff_t)aData.mYChannel & 0x7)) {
alignment = 8;
} else if (!((ptrdiff_t)aData.mYStride & 0x3)) {
alignment = 4;
} else if (!((ptrdiff_t)aData.mYStride & 0x1)) {
alignment = 2;
} else {
alignment = 1;
}
// Set texture alignment for Y plane.
gl->fPixelStorei(LOCAL_GL_UNPACK_ALIGNMENT, alignment);
gl->fBindTexture(LOCAL_GL_TEXTURE_2D, aYTexture->GetTextureID());
gl->fTexSubImage2D(LOCAL_GL_TEXTURE_2D, 0,
0, 0, aData.mYSize.width, aData.mYSize.height,
LOCAL_GL_LUMINANCE,
LOCAL_GL_UNSIGNED_BYTE,
aData.mYChannel);
if (!((ptrdiff_t)aData.mCbCrStride & 0x7) &&
!((ptrdiff_t)aData.mCbChannel & 0x7) &&
!((ptrdiff_t)aData.mCrChannel & 0x7))
{
alignment = 8;
} else if (!((ptrdiff_t)aData.mCbCrStride & 0x3)) {
alignment = 4;
} else if (!((ptrdiff_t)aData.mCbCrStride & 0x1)) {
alignment = 2;
} else {
alignment = 1;
}
// Set texture alignment for Cb/Cr plane
gl->fPixelStorei(LOCAL_GL_UNPACK_ALIGNMENT, alignment);
gl->fBindTexture(LOCAL_GL_TEXTURE_2D, aUTexture->GetTextureID());
gl->fTexSubImage2D(LOCAL_GL_TEXTURE_2D, 0,
0, 0, aData.mCbCrSize.width, aData.mCbCrSize.height,
LOCAL_GL_LUMINANCE,
LOCAL_GL_UNSIGNED_BYTE,
aData.mCbChannel);
gl->fBindTexture(LOCAL_GL_TEXTURE_2D, aVTexture->GetTextureID());
gl->fTexSubImage2D(LOCAL_GL_TEXTURE_2D, 0,
0, 0, aData.mCbCrSize.width, aData.mCbCrSize.height,
LOCAL_GL_LUMINANCE,
LOCAL_GL_UNSIGNED_BYTE,
aData.mCrChannel);
// Reset alignment to default
gl->fPixelStorei(LOCAL_GL_UNPACK_ALIGNMENT, 4);
}
void
@@ -881,9 +977,6 @@ ShadowImageLayerOGL::Swap(const SharedImage& aNewFront, SharedImage* aNewBack)
gfxSharedImageSurface::Open(yuv.Udata());
nsRefPtr<gfxSharedImageSurface> surfV =
gfxSharedImageSurface::Open(yuv.Vdata());
mPictureRect = yuv.picture();
mSize = surfY->GetSize();
PlanarYCbCrImage::Data data;
data.mYChannel = surfY->Data();
@@ -963,20 +1056,11 @@ ShadowImageLayerOGL::RenderLayer(int aPreviousFrameBuffer,
yuvProgram->Activate();
yuvProgram->SetLayerQuadRect(nsIntRect(0, 0,
mPictureRect.width,
mPictureRect.height));
mSize.width,
mSize.height));
yuvProgram->SetYCbCrTextureUnits(0, 1, 2);
program = yuvProgram;
program->SetLayerTransform(GetEffectiveTransform());
program->SetLayerOpacity(GetEffectiveOpacity());
program->SetRenderOffset(aOffset);
mOGLManager->BindAndDrawQuadWithTextureRect(program,
mPictureRect,
nsIntSize(mSize.width, mSize.height));
return;
}
program->SetLayerTransform(GetEffectiveTransform());

View File

@@ -207,10 +207,6 @@ public:
mTextures[2].IsAllocated();
}
PRUint8* AllocateBuffer(PRUint32 aSize) {
return mRecycleBin->GetBuffer(aSize);
}
nsAutoArrayPtr<PRUint8> mBuffer;
PRUint32 mBufferSize;
nsRefPtr<RecycleBin> mRecycleBin;
@@ -218,6 +214,7 @@ public:
Data mData;
gfxIntSize mSize;
PRPackedBool mHasData;
gfx::YUVType mType;
};
@@ -271,7 +268,6 @@ private:
nsRefPtr<TextureImage> mTexImage;
GLTexture mYUVTexture[3];
gfxIntSize mSize;
nsIntRect mPictureRect;
};
} /* layers */

View File

@@ -670,73 +670,6 @@ LayerManagerOGL::FPSState::DrawFPS(GLContext* context, CopyProgram* copyprog)
context->fDrawArrays(LOCAL_GL_TRIANGLE_STRIP, 0, 12);
}
// |aTexCoordRect| is the rectangle from the texture that we want to
// draw using the given program. The program already has a necessary
// offset and scale, so the geometry that needs to be drawn is a unit
// square from 0,0 to 1,1.
//
// |aTexSize| is the actual size of the texture, as it can be larger
// than the rectangle given by |aTexCoordRect|.
void
LayerManagerOGL::BindAndDrawQuadWithTextureRect(LayerProgram *aProg,
const nsIntRect& aTexCoordRect,
const nsIntSize& aTexSize,
GLenum aWrapMode)
{
GLuint vertAttribIndex =
aProg->AttribLocation(LayerProgram::VertexAttrib);
GLuint texCoordAttribIndex =
aProg->AttribLocation(LayerProgram::TexCoordAttrib);
NS_ASSERTION(texCoordAttribIndex != GLuint(-1), "no texture coords?");
// clear any bound VBO so that glVertexAttribPointer() goes back to
// "pointer mode"
mGLContext->fBindBuffer(LOCAL_GL_ARRAY_BUFFER, 0);
// Given what we know about these textures and coordinates, we can
// compute fmod(t, 1.0f) to get the same texture coordinate out. If
// the texCoordRect dimension is < 0 or > width/height, then we have
// wraparound that we need to deal with by drawing multiple quads,
// because we can't rely on full non-power-of-two texture support
// (which is required for the REPEAT wrap mode).
GLContext::RectTriangles rects;
if (aWrapMode == LOCAL_GL_REPEAT) {
rects.addRect(/* dest rectangle */
0.0f, 0.0f, 1.0f, 1.0f,
/* tex coords */
aTexCoordRect.x / GLfloat(aTexSize.width),
aTexCoordRect.y / GLfloat(aTexSize.height),
aTexCoordRect.XMost() / GLfloat(aTexSize.width),
aTexCoordRect.YMost() / GLfloat(aTexSize.height));
} else {
GLContext::DecomposeIntoNoRepeatTriangles(aTexCoordRect, aTexSize, rects);
}
// vertex position buffer is 2 floats, not normalized, 0 stride.
mGLContext->fVertexAttribPointer(vertAttribIndex, 2,
LOCAL_GL_FLOAT, LOCAL_GL_FALSE, 0,
rects.vertexPointer());
// texture coord buffer is 2 floats, not normalized, 0 stride.
mGLContext->fVertexAttribPointer(texCoordAttribIndex, 2,
LOCAL_GL_FLOAT, LOCAL_GL_FALSE, 0,
rects.texCoordPointer());
{
mGLContext->fEnableVertexAttribArray(texCoordAttribIndex);
{
mGLContext->fEnableVertexAttribArray(vertAttribIndex);
mGLContext->fDrawArrays(LOCAL_GL_TRIANGLES, 0, rects.elements());
mGLContext->fDisableVertexAttribArray(vertAttribIndex);
}
mGLContext->fDisableVertexAttribArray(texCoordAttribIndex);
}
}
void
LayerManagerOGL::Render()
{

View File

@@ -360,12 +360,6 @@ public:
aFlipped);
}
void BindAndDrawQuadWithTextureRect(LayerProgram *aProg,
const nsIntRect& aTexCoordRect,
const nsIntSize& aTexSize,
GLenum aWrapMode = LOCAL_GL_REPEAT);
#ifdef MOZ_LAYERS_HAVE_LOG
virtual const char* Name() const { return "OGL"; }
#endif // MOZ_LAYERS_HAVE_LOG

View File

@@ -75,6 +75,74 @@ CreateClampOrRepeatTextureImage(GLContext *aGl,
return aGl->CreateTextureImage(aSize, aContentType, wrapMode);
}
// |aTexCoordRect| is the rectangle from the texture that we want to
// draw using the given program. The program already has a necessary
// offset and scale, so the geometry that needs to be drawn is a unit
// square from 0,0 to 1,1.
//
// |aTexSize| is the actual size of the texture, as it can be larger
// than the rectangle given by |aTexCoordRect|.
static void
BindAndDrawQuadWithTextureRect(GLContext* aGl,
LayerProgram *aProg,
const nsIntRect& aTexCoordRect,
const nsIntSize& aTexSize,
GLenum aWrapMode)
{
GLuint vertAttribIndex =
aProg->AttribLocation(LayerProgram::VertexAttrib);
GLuint texCoordAttribIndex =
aProg->AttribLocation(LayerProgram::TexCoordAttrib);
NS_ASSERTION(texCoordAttribIndex != GLuint(-1), "no texture coords?");
// clear any bound VBO so that glVertexAttribPointer() goes back to
// "pointer mode"
aGl->fBindBuffer(LOCAL_GL_ARRAY_BUFFER, 0);
// Given what we know about these textures and coordinates, we can
// compute fmod(t, 1.0f) to get the same texture coordinate out. If
// the texCoordRect dimension is < 0 or > width/height, then we have
// wraparound that we need to deal with by drawing multiple quads,
// because we can't rely on full non-power-of-two texture support
// (which is required for the REPEAT wrap mode).
GLContext::RectTriangles rects;
if (aWrapMode == LOCAL_GL_REPEAT) {
rects.addRect(/* dest rectangle */
0.0f, 0.0f, 1.0f, 1.0f,
/* tex coords */
aTexCoordRect.x / GLfloat(aTexSize.width),
aTexCoordRect.y / GLfloat(aTexSize.height),
aTexCoordRect.XMost() / GLfloat(aTexSize.width),
aTexCoordRect.YMost() / GLfloat(aTexSize.height));
} else {
GLContext::DecomposeIntoNoRepeatTriangles(aTexCoordRect, aTexSize, rects);
}
// vertex position buffer is 2 floats, not normalized, 0 stride.
aGl->fVertexAttribPointer(vertAttribIndex, 2,
LOCAL_GL_FLOAT, LOCAL_GL_FALSE, 0,
rects.vertexPointer());
// texture coord buffer is 2 floats, not normalized, 0 stride.
aGl->fVertexAttribPointer(texCoordAttribIndex, 2,
LOCAL_GL_FLOAT, LOCAL_GL_FALSE, 0,
rects.texCoordPointer());
{
aGl->fEnableVertexAttribArray(texCoordAttribIndex);
{
aGl->fEnableVertexAttribArray(vertAttribIndex);
aGl->fDrawArrays(LOCAL_GL_TRIANGLES, 0, rects.elements());
aGl->fDisableVertexAttribArray(vertAttribIndex);
}
aGl->fDisableVertexAttribArray(texCoordAttribIndex);
}
}
static void
SetAntialiasingFlags(Layer* aLayer, gfxContext* aTarget)
{
@@ -201,9 +269,9 @@ ThebesLayerBufferOGL::RenderTo(const nsIntPoint& aOffset,
quadRect.MoveBy(-GetOriginOffset());
aManager->BindAndDrawQuadWithTextureRect(program, quadRect,
mTexImage->GetSize(),
mTexImage->GetWrapMode());
BindAndDrawQuadWithTextureRect(gl(), program, quadRect,
mTexImage->GetSize(),
mTexImage->GetWrapMode());
}
}

View File

@@ -1382,8 +1382,7 @@ GLContext::UploadSurfaceToTexture(gfxASurface *aSurface,
if (!imageSurface ||
(imageSurface->Format() != gfxASurface::ImageFormatARGB32 &&
imageSurface->Format() != gfxASurface::ImageFormatRGB24 &&
imageSurface->Format() != gfxASurface::ImageFormatRGB16_565 &&
imageSurface->Format() != gfxASurface::ImageFormatA8)) {
imageSurface->Format() != gfxASurface::ImageFormatRGB16_565)) {
// We can't get suitable pixel data for the surface, make a copy
nsIntRect bounds = aDstRegion.GetBounds();
imageSurface =
@@ -1431,12 +1430,6 @@ GLContext::UploadSurfaceToTexture(gfxASurface *aSurface,
type = LOCAL_GL_UNSIGNED_SHORT_5_6_5;
shader = RGBALayerProgramType;
break;
case gfxASurface::ImageFormatA8:
format = LOCAL_GL_LUMINANCE;
type = LOCAL_GL_UNSIGNED_BYTE;
// We don't have a specific luminance shader
shader = ShaderProgramType(0);
break;
default:
NS_ASSERTION(false, "Unhandled image surface format!");
format = 0;

View File

@@ -23,5 +23,3 @@ convert.patch contains the following changes:
be properly guarded with cpuid() calls.
win64.patch: SSE2 optimization for Microsoft Visual C++ x64 version
TypeFromSize.patch: Bug 656185 - Add a method to detect YUVType from plane sizes.

View File

@@ -1,58 +0,0 @@
diff --git a/gfx/ycbcr/yuv_convert.cpp b/gfx/ycbcr/yuv_convert.cpp
--- a/gfx/ycbcr/yuv_convert.cpp
+++ b/gfx/ycbcr/yuv_convert.cpp
@@ -26,16 +26,32 @@ namespace mozilla {
namespace gfx {
// 16.16 fixed point arithmetic
const int kFractionBits = 16;
const int kFractionMax = 1 << kFractionBits;
const int kFractionMask = ((1 << kFractionBits) - 1);
+NS_GFX_(YUVType) TypeFromSize(int ywidth,
+ int yheight,
+ int cbcrwidth,
+ int cbcrheight)
+{
+ if (ywidth == cbcrwidth && yheight == cbcrheight) {
+ return YV24;
+ }
+ else if (ywidth / 2 == cbcrwidth && yheight == cbcrheight) {
+ return YV16;
+ }
+ else {
+ return YV12;
+ }
+}
+
// Convert a frame of YUV to 32 bit ARGB.
NS_GFX_(void) ConvertYCbCrToRGB32(const uint8* y_buf,
const uint8* u_buf,
const uint8* v_buf,
uint8* rgb_buf,
int pic_x,
int pic_y,
int pic_width,
diff --git a/gfx/ycbcr/yuv_convert.h b/gfx/ycbcr/yuv_convert.h
--- a/gfx/ycbcr/yuv_convert.h
+++ b/gfx/ycbcr/yuv_convert.h
@@ -36,16 +36,18 @@ enum Rotate {
// Filter affects how scaling looks.
enum ScaleFilter {
FILTER_NONE = 0, // No filter (point sampled).
FILTER_BILINEAR_H = 1, // Bilinear horizontal filter.
FILTER_BILINEAR_V = 2, // Bilinear vertical filter.
FILTER_BILINEAR = 3 // Bilinear filter.
};
+NS_GFX_(YUVType) TypeFromSize(int ywidth, int yheight, int cbcrwidth, int cbcrheight);
+
// Convert a frame of YUV to 32 bit ARGB.
// Pass in YV16/YV12 depending on source format
NS_GFX_(void) ConvertYCbCrToRGB32(const uint8* yplane,
const uint8* uplane,
const uint8* vplane,
uint8* rgbframe,
int pic_x,
int pic_y,

View File

@@ -8,4 +8,3 @@ cp $1/media/base/yuv_row_win.cc yuv_row_win.cpp
cp $1/media/base/yuv_row_posix.cc yuv_row_c.cpp
patch -p3 <convert.patch
patch -p3 <win64.patch
patch -p3 <TypeFromSize.patch

View File

@@ -31,22 +31,6 @@ const int kFractionBits = 16;
const int kFractionMax = 1 << kFractionBits;
const int kFractionMask = ((1 << kFractionBits) - 1);
NS_GFX_(YUVType) TypeFromSize(int ywidth,
int yheight,
int cbcrwidth,
int cbcrheight)
{
if (ywidth == cbcrwidth && yheight == cbcrheight) {
return YV24;
}
else if (ywidth / 2 == cbcrwidth && yheight == cbcrheight) {
return YV16;
}
else {
return YV12;
}
}
// Convert a frame of YUV to 32 bit ARGB.
NS_GFX_(void) ConvertYCbCrToRGB32(const uint8* y_buf,
const uint8* u_buf,

View File

@@ -41,8 +41,6 @@ enum ScaleFilter {
FILTER_BILINEAR = 3 // Bilinear filter.
};
NS_GFX_(YUVType) TypeFromSize(int ywidth, int yheight, int cbcrwidth, int cbcrheight);
// Convert a frame of YUV to 32 bit ARGB.
// Pass in YV16/YV12 depending on source format
NS_GFX_(void) ConvertYCbCrToRGB32(const uint8* yplane,