Bug 649417 - Part 2 - Add a YUV option to SharedImage and use it to share YUV data across processes. r=cjones,joe

This commit is contained in:
Matt Woodrow
2011-04-21 16:38:39 +12:00
parent fc21b7078a
commit 9f9df90122
11 changed files with 369 additions and 66 deletions

View File

@@ -2234,6 +2234,9 @@ ImageContainer* nsHTMLMediaElement::GetImageContainer()
return nsnull;
mImageContainer = manager->CreateImageContainer();
if (manager->IsCompositingCheap()) {
mImageContainer->SetDelayedConversion(PR_TRUE);
}
return mImageContainer;
}

View File

@@ -162,6 +162,12 @@ public:
*/
virtual void SetCurrentImage(Image* aImage) = 0;
/**
* Ask any PlanarYCbCr images created by this container to delay
* YUV -> RGB conversion until draw time. See PlanarYCbCrImage::SetDelayedConversion.
*/
virtual void SetDelayedConversion(PRBool aDelayed) {}
/**
* Get the current Image.
* This has to add a reference since otherwise there are race conditions
@@ -415,6 +421,18 @@ public:
*/
virtual void SetData(const Data& aData) = 0;
/**
* Ask this Image to not convert YUV to RGB during SetData, and make
* the original data available through GetData. This is optional,
* and not all PlanarYCbCrImages will support it.
*/
virtual void SetDelayedConversion(PRBool aDelayed) { }
/**
* Grab the original YUV data. This is optional.
*/
virtual const Data* GetData() { return nsnull; }
protected:
PlanarYCbCrImage(void* aImplData) : Image(aImplData, PLANAR_YCBCR) {}
};

View File

@@ -115,13 +115,17 @@ public:
BasicPlanarYCbCrImage(const gfxIntSize& aScaleHint) :
PlanarYCbCrImage(static_cast<BasicImageImplData*>(this)),
mScaleHint(aScaleHint),
mOffscreenFormat(gfxASurface::ImageFormatUnknown)
mOffscreenFormat(gfxASurface::ImageFormatUnknown),
mDelayedConversion(PR_FALSE)
{}
virtual void SetData(const Data& aData);
virtual void SetDelayedConversion(PRBool aDelayed) { mDelayedConversion = aDelayed; }
virtual already_AddRefed<gfxASurface> GetAsSurface();
const Data* GetData() { return &mData; }
void SetOffscreenFormat(gfxImageFormat aFormat) { mOffscreenFormat = aFormat; }
gfxImageFormat GetOffscreenFormat() { return mOffscreenFormat; }
@@ -131,6 +135,9 @@ protected:
gfxIntSize mScaleHint;
PRInt32 mStride;
gfxImageFormat mOffscreenFormat;
Data mData;
PRUint32 mBufferSize;
PRPackedBool mDelayedConversion;
};
void
@@ -141,26 +148,82 @@ BasicPlanarYCbCrImage::SetData(const Data& aData)
NS_ERROR("Illegal width or height");
return;
}
gfxASurface::gfxImageFormat format = GetOffscreenFormat();
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) {
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;
}
gfxASurface::gfxImageFormat format = GetOffscreenFormat();
// 'prescale' is true if the scaling is to be done as part of the
// YCbCr to RGB conversion rather than on the RGB data when rendered.
PRBool prescale = mScaleHint.width > 0 && mScaleHint.height > 0 &&
@@ -296,7 +359,9 @@ BasicPlanarYCbCrImage::GetAsSurface()
return result.forget();
}
if (!mBuffer) {
// XXX: If we forced delayed conversion, are we ever going to hit this?
// We may need to implement the conversion here.
if (!mBuffer || mDelayedConversion) {
return nsnull;
}
@@ -336,10 +401,12 @@ public:
BasicImageContainer() :
ImageContainer(nsnull),
mScaleHint(-1, -1),
mOffscreenFormat(gfxASurface::ImageFormatUnknown)
mOffscreenFormat(gfxASurface::ImageFormatUnknown),
mDelayed(PR_FALSE)
{}
virtual already_AddRefed<Image> CreateImage(const Image::Format* aFormats,
PRUint32 aNumFormats);
virtual void SetDelayedConversion(PRBool aDelayed) { mDelayed = aDelayed; }
virtual void SetCurrentImage(Image* aImage);
virtual already_AddRefed<Image> GetCurrentImage();
virtual already_AddRefed<gfxASurface> GetCurrentAsSurface(gfxIntSize* aSize);
@@ -353,6 +420,7 @@ protected:
nsRefPtr<Image> mImage;
gfxIntSize mScaleHint;
gfxImageFormat mOffscreenFormat;
PRPackedBool mDelayed;
};
/**
@@ -382,6 +450,7 @@ BasicImageContainer::CreateImage(const Image::Format* aFormats,
ReentrantMonitorAutoEnter mon(mReentrantMonitor);
image = new BasicPlanarYCbCrImage(mScaleHint);
static_cast<BasicPlanarYCbCrImage*>(image.get())->SetOffscreenFormat(mOffscreenFormat);
static_cast<BasicPlanarYCbCrImage*>(image.get())->SetDelayedConversion(mDelayed);
}
return image.forget();
}

View File

@@ -1631,6 +1631,13 @@ public:
{
NS_RUNTIMEABORT("if this default impl is called, |aBuffer| leaks");
}
virtual void SetBackBufferYUVImage(gfxSharedImageSurface* aYBuffer,
gfxSharedImageSurface* aUBuffer,
gfxSharedImageSurface* aVBuffer)
{
NS_RUNTIMEABORT("if this default impl is called, |aBuffer| leaks");
}
virtual void Disconnect()
{
@@ -1965,6 +1972,15 @@ public:
mBackBuffer = aBuffer;
}
virtual void SetBackBufferYUVImage(gfxSharedImageSurface* aYBuffer,
gfxSharedImageSurface* aUBuffer,
gfxSharedImageSurface* aVBuffer)
{
mBackBufferY = aYBuffer;
mBackBufferU = aUBuffer;
mBackBufferV = aVBuffer;
}
virtual void Disconnect()
{
mBackBuffer = SurfaceDescriptor();
@@ -1977,12 +1993,88 @@ private:
return static_cast<BasicShadowLayerManager*>(mManager);
}
// For YUV Images these are the 3 planes (Y, Cb and Cr),
// for RGB images only mBackSurface is used.
SurfaceDescriptor mBackBuffer;
nsRefPtr<gfxSharedImageSurface> mBackBufferY;
nsRefPtr<gfxSharedImageSurface> mBackBufferU;
nsRefPtr<gfxSharedImageSurface> mBackBufferV;
gfxIntSize mCbCrSize;
};
void
BasicShadowableImageLayer::Paint(gfxContext* aContext)
{
nsRefPtr<Image> image = mContainer->GetCurrentImage();
if (image->GetFormat() == Image::PLANAR_YCBCR && BasicManager()->IsCompositingCheap()) {
PlanarYCbCrImage *YCbCrImage = static_cast<PlanarYCbCrImage*>(image.get());
const PlanarYCbCrImage::Data *data = YCbCrImage->GetData();
NS_ASSERTION(data, "Must be able to retrieve yuv data from image!");
if (mSize != data->mYSize || mCbCrSize != data->mCbCrSize) {
if (mBackBufferY) {
BasicManager()->ShadowLayerForwarder::DestroySharedSurface(mBackBufferY);
BasicManager()->ShadowLayerForwarder::DestroySharedSurface(mBackBufferU);
BasicManager()->ShadowLayerForwarder::DestroySharedSurface(mBackBufferV);
BasicManager()->DestroyedImageBuffer(BasicManager()->Hold(this));
}
mSize = data->mYSize;
mCbCrSize = data->mCbCrSize;
nsRefPtr<gfxSharedImageSurface> tmpYSurface;
nsRefPtr<gfxSharedImageSurface> tmpUSurface;
nsRefPtr<gfxSharedImageSurface> tmpVSurface;
if (!BasicManager()->AllocDoubleBuffer(
mSize,
gfxASurface::CONTENT_ALPHA,
getter_AddRefs(tmpYSurface), getter_AddRefs(mBackBufferY)))
NS_RUNTIMEABORT("creating ImageLayer 'front buffer' failed!");
if (!BasicManager()->AllocDoubleBuffer(
mCbCrSize,
gfxASurface::CONTENT_ALPHA,
getter_AddRefs(tmpUSurface), getter_AddRefs(mBackBufferU)))
NS_RUNTIMEABORT("creating ImageLayer 'front buffer' failed!");
if (!BasicManager()->AllocDoubleBuffer(
mCbCrSize,
gfxASurface::CONTENT_ALPHA,
getter_AddRefs(tmpVSurface), getter_AddRefs(mBackBufferV)))
NS_RUNTIMEABORT("creating ImageLayer 'front buffer' failed!");
YUVImage yuv(tmpYSurface->GetShmem(),
tmpUSurface->GetShmem(),
tmpVSurface->GetShmem());
BasicManager()->CreatedImageBuffer(BasicManager()->Hold(this),
nsIntSize(mSize.width, mSize.height),
yuv);
}
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());
BasicManager()->PaintedImage(BasicManager()->Hold(this),
yuv);
return;
}
gfxIntSize oldSize = mSize;
nsRefPtr<gfxPattern> pat = GetAndPaintCurrentImage(aContext, GetEffectiveOpacity());
if (!pat || !HasShadow())
@@ -2825,6 +2917,26 @@ BasicShadowLayerManager::ForwardTransaction()
break;
}
case EditReply::TOpImageSwap: {
MOZ_LAYERS_LOG(("[LayersForwarder] YUVBufferSwap"));
const OpImageSwap& ois = reply.get_OpImageSwap();
BasicShadowableLayer* layer = GetBasicShadowable(ois);
const SharedImage& newBack = ois.newBackImage();
if (newBack.type() == SharedImage::TSurfaceDescriptor) {
layer->SetBackBuffer(newBack.get_SurfaceDescriptor());
} else {
const YUVImage& yuv = newBack.get_YUVImage();
nsRefPtr<gfxSharedImageSurface> YSurf = gfxSharedImageSurface::Open(yuv.Ydata());
nsRefPtr<gfxSharedImageSurface> USurf = gfxSharedImageSurface::Open(yuv.Udata());
nsRefPtr<gfxSharedImageSurface> VSurf = gfxSharedImageSurface::Open(yuv.Vdata());
layer->SetBackBufferYUVImage(YSurf, USurf, VSurf);
}
break;
}
default:
NS_RUNTIMEABORT("not reached");
}

View File

@@ -83,8 +83,15 @@ union SurfaceDescriptor {
SurfaceDescriptorX11;
};
struct YUVImage {
Shmem Ydata;
Shmem Udata;
Shmem Vdata;
};
union SharedImage {
SurfaceDescriptor;
YUVImage;
};
struct ThebesBuffer {
@@ -216,6 +223,8 @@ union Edit {
// Replies to operations
struct OpBufferSwap { PLayer layer; SurfaceDescriptor newBackBuffer; };
struct OpImageSwap { PLayer layer; SharedImage newBackImage; };
struct OpThebesBufferSwap {
PLayer layer;
ThebesBuffer newBackBuffer;
@@ -237,6 +246,7 @@ struct OpThebesBufferSwap {
union EditReply {
OpBufferSwap;
OpThebesBufferSwap;
OpImageSwap;
};

View File

@@ -207,11 +207,11 @@ ShadowLayerForwarder::CreatedThebesBuffer(ShadowableLayer* aThebes,
void
ShadowLayerForwarder::CreatedImageBuffer(ShadowableLayer* aImage,
nsIntSize aSize,
const SurfaceDescriptor& aTempFrontSurface)
const SharedImage& aTempFrontImage)
{
mTxn->AddEdit(OpCreateImageBuffer(NULL, Shadow(aImage),
aSize,
aTempFrontSurface));
aTempFrontImage));
}
void
@@ -291,10 +291,10 @@ ShadowLayerForwarder::PaintedThebesBuffer(ShadowableLayer* aThebes,
}
void
ShadowLayerForwarder::PaintedImage(ShadowableLayer* aImage,
const SurfaceDescriptor& aNewFrontSurface)
const SharedImage& aNewFrontImage)
{
mTxn->AddPaint(OpPaintImage(NULL, Shadow(aImage),
aNewFrontSurface));
aNewFrontImage));
}
void
ShadowLayerForwarder::PaintedCanvas(ShadowableLayer* aCanvas,

View File

@@ -166,7 +166,7 @@ public:
*/
void CreatedImageBuffer(ShadowableLayer* aImage,
nsIntSize aSize,
const SurfaceDescriptor& aInitialFrontSurface);
const SharedImage& aInitialFrontImage);
void CreatedCanvasBuffer(ShadowableLayer* aCanvas,
nsIntSize aSize,
const SurfaceDescriptor& aInitialFrontSurface);
@@ -226,7 +226,7 @@ public:
* ImageLayers. This is slow, and will be optimized.
*/
void PaintedImage(ShadowableLayer* aImage,
const SurfaceDescriptor& aNewFrontSurface);
const SharedImage& aNewFrontImage);
void PaintedCanvas(ShadowableLayer* aCanvas,
const SurfaceDescriptor& aNewFrontSurface);

View File

@@ -438,8 +438,8 @@ ShadowLayersParent::RecvUpdate(const InfallibleTArray<Edit>& cset,
newFront = SurfaceDescriptor();
}
replyv.push_back(OpBufferSwap(shadow, NULL,
newBack));
replyv.push_back(OpImageSwap(shadow, NULL,
newBack));
break;
}

View File

@@ -420,7 +420,7 @@ ImageLayerOGL::RenderLayer(int,
gl()->fActiveTexture(LOCAL_GL_TEXTURE2);
gl()->fBindTexture(LOCAL_GL_TEXTURE_2D, yuvImage->mTextures[2].GetTextureID());
ApplyFilter(mFilter);
YCbCrTextureLayerProgram *program = mOGLManager->GetYCbCrLayerProgram();
program->Activate();
@@ -669,19 +669,19 @@ PlanarYCbCrImageOGL::AllocateTextures(mozilla::gl::GLContext *gl)
InitTexture(gl, mTextures[2].GetTextureID(), LOCAL_GL_LUMINANCE, mData.mCbCrSize);
}
void
PlanarYCbCrImageOGL::UpdateTextures(GLContext *gl)
static void
UploadYUVToTexture(GLContext* gl, const PlanarYCbCrImage::Data& aData,
GLTexture* aYTexture,
GLTexture* aUTexture,
GLTexture* aVTexture)
{
if (!mBuffer || !mHasData)
return;
GLint alignment;
if (!((ptrdiff_t)mData.mYStride & 0x7) && !((ptrdiff_t)mData.mYChannel & 0x7)) {
if (!((ptrdiff_t)aData.mYStride & 0x7) && !((ptrdiff_t)aData.mYChannel & 0x7)) {
alignment = 8;
} else if (!((ptrdiff_t)mData.mYStride & 0x3)) {
} else if (!((ptrdiff_t)aData.mYStride & 0x3)) {
alignment = 4;
} else if (!((ptrdiff_t)mData.mYStride & 0x1)) {
} else if (!((ptrdiff_t)aData.mYStride & 0x1)) {
alignment = 2;
} else {
alignment = 1;
@@ -690,21 +690,21 @@ PlanarYCbCrImageOGL::UpdateTextures(GLContext *gl)
// Set texture alignment for Y plane.
gl->fPixelStorei(LOCAL_GL_UNPACK_ALIGNMENT, alignment);
gl->fBindTexture(LOCAL_GL_TEXTURE_2D, mTextures[0].GetTextureID());
gl->fBindTexture(LOCAL_GL_TEXTURE_2D, aYTexture->GetTextureID());
gl->fTexSubImage2D(LOCAL_GL_TEXTURE_2D, 0,
0, 0, mData.mYSize.width, mData.mYSize.height,
0, 0, aData.mYSize.width, aData.mYSize.height,
LOCAL_GL_LUMINANCE,
LOCAL_GL_UNSIGNED_BYTE,
mData.mYChannel);
aData.mYChannel);
if (!((ptrdiff_t)mData.mCbCrStride & 0x7) &&
!((ptrdiff_t)mData.mCbChannel & 0x7) &&
!((ptrdiff_t)mData.mCrChannel & 0x7))
if (!((ptrdiff_t)aData.mCbCrStride & 0x7) &&
!((ptrdiff_t)aData.mCbChannel & 0x7) &&
!((ptrdiff_t)aData.mCrChannel & 0x7))
{
alignment = 8;
} else if (!((ptrdiff_t)mData.mCbCrStride & 0x3)) {
} else if (!((ptrdiff_t)aData.mCbCrStride & 0x3)) {
alignment = 4;
} else if (!((ptrdiff_t)mData.mCbCrStride & 0x1)) {
} else if (!((ptrdiff_t)aData.mCbCrStride & 0x1)) {
alignment = 2;
} else {
alignment = 1;
@@ -713,24 +713,33 @@ PlanarYCbCrImageOGL::UpdateTextures(GLContext *gl)
// Set texture alignment for Cb/Cr plane
gl->fPixelStorei(LOCAL_GL_UNPACK_ALIGNMENT, alignment);
gl->fBindTexture(LOCAL_GL_TEXTURE_2D, mTextures[1].GetTextureID());
gl->fBindTexture(LOCAL_GL_TEXTURE_2D, aUTexture->GetTextureID());
gl->fTexSubImage2D(LOCAL_GL_TEXTURE_2D, 0,
0, 0, mData.mCbCrSize.width, mData.mCbCrSize.height,
0, 0, aData.mCbCrSize.width, aData.mCbCrSize.height,
LOCAL_GL_LUMINANCE,
LOCAL_GL_UNSIGNED_BYTE,
mData.mCbChannel);
aData.mCbChannel);
gl->fBindTexture(LOCAL_GL_TEXTURE_2D, mTextures[2].GetTextureID());
gl->fBindTexture(LOCAL_GL_TEXTURE_2D, aVTexture->GetTextureID());
gl->fTexSubImage2D(LOCAL_GL_TEXTURE_2D, 0,
0, 0, mData.mCbCrSize.width, mData.mCbCrSize.height,
0, 0, aData.mCbCrSize.width, aData.mCbCrSize.height,
LOCAL_GL_LUMINANCE,
LOCAL_GL_UNSIGNED_BYTE,
mData.mCrChannel);
aData.mCrChannel);
// Reset alignment to default
gl->fPixelStorei(LOCAL_GL_UNPACK_ALIGNMENT, 4);
}
void
PlanarYCbCrImageOGL::UpdateTextures(GLContext *gl)
{
if (!mBuffer || !mHasData)
return;
UploadYUVToTexture(gl, mData, &mTextures[0], &mTextures[1], &mTextures[2]);
}
CairoImageOGL::CairoImageOGL(LayerManagerOGL *aManager)
: CairoImage(nsnull), mSize(0, 0)
{
@@ -793,26 +802,84 @@ PRBool
ShadowImageLayerOGL::Init(const SharedImage& aFront,
const nsIntSize& aSize)
{
mDeadweight = aFront;
nsRefPtr<gfxASurface> surf =
ShadowLayerForwarder::OpenDescriptor(aFront.get_SurfaceDescriptor());
gfxSize sz = surf->GetSize();
mTexImage = gl()->CreateTextureImage(nsIntSize(sz.width, sz.height),
surf->GetContentType(),
LOCAL_GL_CLAMP_TO_EDGE);
return PR_TRUE;
if (aFront.type() == SharedImage::TSurfaceDescriptor) {
SurfaceDescriptor desc = aFront.get_SurfaceDescriptor();
nsRefPtr<gfxASurface> surf =
ShadowLayerForwarder::OpenDescriptor(desc);
gfxSize sz = surf->GetSize();
mTexImage = gl()->CreateTextureImage(nsIntSize(sz.width, sz.height),
surf->GetContentType(),
LOCAL_GL_CLAMP_TO_EDGE);
mOGLManager->DestroySharedSurface(&desc, mAllocator);
return PR_TRUE;
} else {
YUVImage yuv = aFront.get_YUVImage();
nsRefPtr<gfxSharedImageSurface> surfY =
gfxSharedImageSurface::Open(yuv.Ydata());
nsRefPtr<gfxSharedImageSurface> surfU =
gfxSharedImageSurface::Open(yuv.Udata());
nsRefPtr<gfxSharedImageSurface> surfV =
gfxSharedImageSurface::Open(yuv.Vdata());
mSize = gfxIntSize(surfY->GetSize().width, surfY->GetSize().height);
gfxIntSize CbCrSize = gfxIntSize(surfU->GetSize().width, surfU->GetSize().height);
if (!mYUVTexture[0].IsAllocated()) {
mYUVTexture[0].Allocate(mOGLManager->glForResources());
mYUVTexture[1].Allocate(mOGLManager->glForResources());
mYUVTexture[2].Allocate(mOGLManager->glForResources());
}
NS_ASSERTION(mYUVTexture[0].IsAllocated() &&
mYUVTexture[1].IsAllocated() &&
mYUVTexture[2].IsAllocated(),
"Texture allocation failed!");
gl()->MakeCurrent();
InitTexture(gl(), mYUVTexture[0].GetTextureID(), LOCAL_GL_LUMINANCE, mSize);
InitTexture(gl(), mYUVTexture[1].GetTextureID(), LOCAL_GL_LUMINANCE, CbCrSize);
InitTexture(gl(), mYUVTexture[2].GetTextureID(), LOCAL_GL_LUMINANCE, CbCrSize);
mOGLManager->DestroySharedSurface(surfY, mAllocator);
mOGLManager->DestroySharedSurface(surfU, mAllocator);
mOGLManager->DestroySharedSurface(surfV, mAllocator);
return PR_TRUE;
}
}
void
ShadowImageLayerOGL::Swap(const SharedImage& aNewFront, SharedImage* aNewBack)
{
if (!mDestroyed && mTexImage) {
nsRefPtr<gfxASurface> surf =
ShadowLayerForwarder::OpenDescriptor(aNewFront.get_SurfaceDescriptor());
// XXX this is always just ridiculously slow
gfxSize sz = surf->GetSize();
nsIntRegion updateRegion(nsIntRect(0, 0, sz.width, sz.height));
mTexImage->DirectUpdate(surf, updateRegion);
if (!mDestroyed) {
if (aNewFront.type() == SharedImage::TSurfaceDescriptor) {
nsRefPtr<gfxASurface> surf =
ShadowLayerForwarder::OpenDescriptor(aNewFront.get_SurfaceDescriptor());
// XXX this is always just ridiculously slow
gfxSize sz = surf->GetSize();
nsIntRegion updateRegion(nsIntRect(0, 0, sz.width, sz.height));
mTexImage->DirectUpdate(surf, updateRegion);
} else {
const YUVImage& yuv = aNewFront.get_YUVImage();
nsRefPtr<gfxSharedImageSurface> surfY =
gfxSharedImageSurface::Open(yuv.Ydata());
nsRefPtr<gfxSharedImageSurface> surfU =
gfxSharedImageSurface::Open(yuv.Udata());
nsRefPtr<gfxSharedImageSurface> surfV =
gfxSharedImageSurface::Open(yuv.Vdata());
PlanarYCbCrImage::Data data;
data.mYChannel = surfY->Data();
data.mYStride = surfY->Stride();
data.mYSize = surfY->GetSize();
data.mCbChannel = surfU->Data();
data.mCrChannel = surfV->Data();
data.mCbCrStride = surfU->Stride();
data.mCbCrSize = surfU->GetSize();
UploadYUVToTexture(gl(), data, &mYUVTexture[0], &mYUVTexture[1], &mYUVTexture[2]);
}
}
*aNewBack = aNewFront;
@@ -822,9 +889,6 @@ void
ShadowImageLayerOGL::DestroyFrontBuffer()
{
mTexImage = nsnull;
if (IsSurfaceDescriptorValid(mDeadweight)) {
mOGLManager->DestroySharedSurface(&mDeadweight, mAllocator);
}
}
void
@@ -854,19 +918,45 @@ ShadowImageLayerOGL::RenderLayer(int aPreviousFrameBuffer,
{
mOGLManager->MakeCurrent();
gl()->fActiveTexture(LOCAL_GL_TEXTURE0);
gl()->fBindTexture(LOCAL_GL_TEXTURE_2D, mTexImage->Texture());
ColorTextureLayerProgram *program =
mOGLManager->GetColorTextureLayerProgram(mTexImage->GetShaderProgramType());
LayerProgram* program;
ApplyFilter(mFilter);
if (mTexImage) {
gl()->fActiveTexture(LOCAL_GL_TEXTURE0);
gl()->fBindTexture(LOCAL_GL_TEXTURE_2D, mTexImage->Texture());
ColorTextureLayerProgram *colorProgram =
mOGLManager->GetColorTextureLayerProgram(mTexImage->GetShaderProgramType());
ApplyFilter(mFilter);
colorProgram->Activate();
colorProgram->SetTextureUnit(0);
colorProgram->SetLayerQuadRect(nsIntRect(nsIntPoint(0, 0), mTexImage->GetSize()));
program = colorProgram;
} else {
gl()->fActiveTexture(LOCAL_GL_TEXTURE0);
gl()->fBindTexture(LOCAL_GL_TEXTURE_2D, mYUVTexture[0].GetTextureID());
ApplyFilter(mFilter);
gl()->fActiveTexture(LOCAL_GL_TEXTURE1);
gl()->fBindTexture(LOCAL_GL_TEXTURE_2D, mYUVTexture[1].GetTextureID());
ApplyFilter(mFilter);
gl()->fActiveTexture(LOCAL_GL_TEXTURE2);
gl()->fBindTexture(LOCAL_GL_TEXTURE_2D, mYUVTexture[2].GetTextureID());
ApplyFilter(mFilter);
YCbCrTextureLayerProgram *yuvProgram = mOGLManager->GetYCbCrLayerProgram();
yuvProgram->Activate();
yuvProgram->SetLayerQuadRect(nsIntRect(0, 0,
mSize.width,
mSize.height));
yuvProgram->SetYCbCrTextureUnits(0, 1, 2);
program = yuvProgram;
}
program->Activate();
program->SetLayerQuadRect(nsIntRect(nsIntPoint(0, 0), mTexImage->GetSize()));
program->SetLayerTransform(GetEffectiveTransform());
program->SetLayerOpacity(GetEffectiveOpacity());
program->SetRenderOffset(aOffset);
program->SetTextureUnit(0);
mOGLManager->BindAndDrawQuad(program);
}

View File

@@ -263,8 +263,8 @@ public:
private:
nsRefPtr<TextureImage> mTexImage;
SurfaceDescriptor mDeadweight;
GLTexture mYUVTexture[3];
gfxIntSize mSize;
};
} /* layers */

View File

@@ -1088,7 +1088,8 @@ LayerManagerOGL::CreateFBOWithTexture(const nsIntRect& aRect, InitMode aInit,
*aTexture = tex;
}
void LayerOGL::ApplyFilter(gfxPattern::GraphicsFilter aFilter)
void
LayerOGL::ApplyFilter(gfxPattern::GraphicsFilter aFilter)
{
if (aFilter == gfxPattern::FILTER_NEAREST) {
gl()->fTexParameteri(LOCAL_GL_TEXTURE_2D, LOCAL_GL_TEXTURE_MIN_FILTER, LOCAL_GL_NEAREST);