Bug 656185 - Part 4 - Fix for D3D9. r=Bas

This commit is contained in:
Matt Woodrow 2011-06-27 14:32:42 +12:00
Родитель 63f8b0a243
Коммит efa3bcd4b7
2 изменённых файлов: 25 добавлений и 75 удалений

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

@ -287,6 +287,15 @@ 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);
/*
@ -334,6 +343,9 @@ 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());
@ -386,75 +398,8 @@ PlanarYCbCrImageD3D9::PlanarYCbCrImageD3D9()
void
PlanarYCbCrImageD3D9::SetData(const PlanarYCbCrImage::Data &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;
PRUint32 dummy;
mBuffer = CopyData(mData, mSize, dummy, aData);
mHasData = PR_TRUE;
}
@ -587,20 +532,26 @@ 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(),
0,
0,
mSize.width,
mSize.height,
mData.mPicX,
mData.mPicY,
mData.mPicSize.width,
mData.mPicSize.height,
mData.mYStride,
mData.mCbCrStride,
imageSurface->Stride(),
mType);
type);
return imageSurface.forget().get();
}

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

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