Skip to content

Commit

Permalink
Bug 539356 - Part 8a - Add END_NO_COMPOSITE to EndTransactionFlags an…
Browse files Browse the repository at this point in the history
…d implement in for all LayerManagers. r=roc
  • Loading branch information
mattwoodrow committed Jun 30, 2012
1 parent 05df417 commit 503c89e
Show file tree
Hide file tree
Showing 19 changed files with 174 additions and 74 deletions.
3 changes: 2 additions & 1 deletion gfx/layers/Layers.h
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,8 @@ class THEBES_API LayerManager {

enum EndTransactionFlags {
END_DEFAULT = 0,
END_NO_IMMEDIATE_REDRAW = 1 << 0 // Do not perform the drawing phase
END_NO_IMMEDIATE_REDRAW = 1 << 0, // Do not perform the drawing phase
END_NO_COMPOSITE = 1 << 1 // Do not composite after drawing thebes layer contents.
};

/**
Expand Down
22 changes: 19 additions & 3 deletions gfx/layers/basic/BasicLayerManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,12 @@ BasicLayerManager::EndTransactionInternal(DrawThebesLayerCallback aCallback,

mTransactionIncomplete = false;

if (aFlags & END_NO_COMPOSITE) {
// TODO: We should really just set mTarget to null and make sure we can handle that further down the call chain
nsRefPtr<gfxASurface> surf = gfxPlatform::GetPlatform()->CreateOffscreenSurface(gfxIntSize(1, 1), gfxASurface::CONTENT_COLOR);
mTarget = new gfxContext(surf);
}

if (mTarget && mRoot && !(aFlags & END_NO_IMMEDIATE_REDRAW)) {
nsIntRect clipRect;
if (HasShadowManager()) {
Expand Down Expand Up @@ -425,9 +431,19 @@ BasicLayerManager::EndTransactionInternal(DrawThebesLayerCallback aCallback,
}
}

PaintLayer(mTarget, mRoot, aCallback, aCallbackData, nsnull);
if (mWidget) {
FlashWidgetUpdateArea(mTarget);
if (aFlags & END_NO_COMPOSITE) {
if (IsRetained()) {
// Clip the destination out so that we don't draw to it, and
// only end up validating ThebesLayers.
mTarget->Clip(gfxRect(0, 0, 0, 0));
PaintLayer(mTarget, mRoot, aCallback, aCallbackData, nsnull);
}
// If we're not retained, then don't composite means do nothing at all.
} else {
PaintLayer(mTarget, mRoot, aCallback, aCallbackData, nsnull);
if (mWidget) {
FlashWidgetUpdateArea(mTarget);
}
}

if (!mTransactionIncomplete) {
Expand Down
8 changes: 6 additions & 2 deletions gfx/layers/d3d10/LayerManagerD3D10.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ LayerManagerD3D10::EndTransaction(DrawThebesLayerCallback aCallback,
Log();
#endif

Render();
Render(aFlags);
mCurrentCallbackInfo.Callback = nsnull;
mCurrentCallbackInfo.CallbackData = nsnull;
}
Expand Down Expand Up @@ -657,10 +657,14 @@ LayerManagerD3D10::EnsureReadbackManager()
}

void
LayerManagerD3D10::Render()
LayerManagerD3D10::Render(EndTransactionFlags aFlags)
{
static_cast<LayerD3D10*>(mRoot->ImplData())->Validate();

if (aFlags & END_NO_COMPOSITE) {
return;
}

SetupPipeline();

float black[] = { 0, 0, 0, 0 };
Expand Down
2 changes: 1 addition & 1 deletion gfx/layers/d3d10/LayerManagerD3D10.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ class THEBES_API LayerManagerD3D10 : public ShadowLayerManager,
void VerifyBufferSize();
void EnsureReadbackManager();

void Render();
void Render(EndTransactionFlags aFlags);

nsRefPtr<ID3D10Device1> mDevice;

Expand Down
5 changes: 4 additions & 1 deletion gfx/layers/d3d9/CanvasLayerD3D9.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,9 @@ void
CanvasLayerD3D9::RenderLayer()
{
UpdateSurface();
if (mD3DManager->CompositingDisabled()) {
return;
}
FireDidTransactionCallback();

if (!mTexture)
Expand Down Expand Up @@ -361,7 +364,7 @@ ShadowCanvasLayerD3D9::GetLayer()
void
ShadowCanvasLayerD3D9::RenderLayer()
{
if (!mBuffer) {
if (!mBuffer || mD3DManager->CompositingDisabled()) {
return;
}

Expand Down
3 changes: 3 additions & 0 deletions gfx/layers/d3d9/ColorLayerD3D9.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ RenderColorLayerD3D9(ColorLayer* aLayer, LayerManagerD3D9 *aManager)
{
// XXX we might be able to improve performance by using
// IDirect3DDevice9::Clear
if (aManager->CompositingDisabled()) {
return;
}

nsIntRect visibleRect = aLayer->GetEffectiveVisibleRegion().GetBounds();

Expand Down
39 changes: 22 additions & 17 deletions gfx/layers/d3d9/ContainerLayerD3D9.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,20 +147,23 @@ ContainerRender(Container* aContainer,

aContainer->mSupportsComponentAlphaChildren = false;
if (useIntermediate) {
aManager->device()->GetRenderTarget(0, getter_AddRefs(previousRenderTarget));
HRESULT hr = aManager->device()->CreateTexture(visibleRect.width, visibleRect.height, 1,
D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8,
D3DPOOL_DEFAULT, getter_AddRefs(renderTexture),
NULL);
if (FAILED(hr)) {
aManager->ReportFailure(NS_LITERAL_CSTRING("ContainerLayerD3D9::ContainerRender(): Failed to create texture"),
hr);
return;
}

nsRefPtr<IDirect3DSurface9> renderSurface;
renderTexture->GetSurfaceLevel(0, getter_AddRefs(renderSurface));
aManager->device()->SetRenderTarget(0, renderSurface);
if (!aManager->CompositingDisabled()) {
aManager->device()->GetRenderTarget(0, getter_AddRefs(previousRenderTarget));
HRESULT hr = aManager->device()->CreateTexture(visibleRect.width, visibleRect.height, 1,
D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8,
D3DPOOL_DEFAULT, getter_AddRefs(renderTexture),
NULL);
if (FAILED(hr)) {
aManager->ReportFailure(NS_LITERAL_CSTRING("ContainerLayerD3D9::ContainerRender(): Failed to create texture"),
hr);
return;
}

nsRefPtr<IDirect3DSurface9> renderSurface;
renderTexture->GetSurfaceLevel(0, getter_AddRefs(renderSurface));
aManager->device()->SetRenderTarget(0, renderSurface);
}

if (aContainer->mVisibleRegion.GetNumRects() == 1 &&
(aContainer->GetContentFlags() & aContainer->CONTENT_OPAQUE)) {
Expand All @@ -182,12 +185,14 @@ ContainerRender(Container* aContainer,
::OffsetRect(&src,
visibleRect.x + PRInt32(transform.x0),
visibleRect.y + PRInt32(transform.y0));
hr = aManager->device()->
StretchRect(previousRenderTarget, &src, renderSurface, &dest, D3DTEXF_NONE);
if (!aManager->CompositingDisabled()) {
hr = aManager->device()->
StretchRect(previousRenderTarget, &src, renderSurface, &dest, D3DTEXF_NONE);
}
}
if (hr == S_OK) {
aContainer->mSupportsComponentAlphaChildren = true;
} else {
} else if (!aManager->CompositingDisabled()) {
aManager->device()->
Clear(0, 0, D3DCLEAR_TARGET, D3DCOLOR_RGBA(0, 0, 0, 0), 0, 0);
}
Expand Down Expand Up @@ -256,7 +261,7 @@ ContainerRender(Container* aContainer,

aManager->device()->SetScissorRect(&containerD3D9ClipRect);

if (useIntermediate) {
if (useIntermediate && !aManager->CompositingDisabled()) {
aManager->device()->SetRenderTarget(0, previousRenderTarget);
aManager->device()->SetVertexShaderConstantF(CBvRenderTargetOffset, previousRenderTargetOffset, 1);
aManager->device()->SetVertexShaderConstantF(CBmProjection, &oldViewMatrix[0][0], 4);
Expand Down
6 changes: 5 additions & 1 deletion gfx/layers/d3d9/ImageLayerD3D9.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ void
ImageLayerD3D9::RenderLayer()
{
ImageContainer *container = GetContainer();
if (!container) {
if (!container || mD3DManager->CompositingDisabled()) {
return;
}

Expand Down Expand Up @@ -610,6 +610,10 @@ ShadowImageLayerD3D9::GetLayer()
void
ShadowImageLayerD3D9::RenderLayer()
{
if (mD3DManager->CompositingDisabled()) {
return;
}

if (mBuffer) {
mBuffer->RenderTo(mD3DManager, GetEffectiveVisibleRegion());
} else if (mYCbCrImage) {
Expand Down
7 changes: 7 additions & 0 deletions gfx/layers/d3d9/LayerManagerD3D9.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ LayerManagerD3D9::EndTransaction(DrawThebesLayerCallback aCallback,
// so we don't need to pass any global transform here.
mRoot->ComputeEffectiveTransforms(gfx3DMatrix());

SetCompositingDisabled(aFlags & END_NO_COMPOSITE);
Render();
/* Clean this out for sanity */
mCurrentCallbackInfo.Callback = NULL;
Expand Down Expand Up @@ -284,6 +285,12 @@ LayerManagerD3D9::Render()
deviceManager()->SetupRenderState();

SetupPipeline();

if (CompositingDisabled()) {
static_cast<LayerD3D9*>(mRoot->ImplData())->RenderLayer();
return;
}

nsIntRect rect;
mWidget->GetClientBounds(rect);

Expand Down
9 changes: 9 additions & 0 deletions gfx/layers/d3d9/LayerManagerD3D9.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,9 @@ class THEBES_API LayerManagerD3D9 : public ShadowLayerManager {

void ReportFailure(const nsACString &aMsg, HRESULT aCode);

bool CompositingDisabled() { return mCompositingDisabled; }
void SetCompositingDisabled(bool aCompositingDisabled) { mCompositingDisabled = aCompositingDisabled; }

private:
/* Default device manager instance */
static DeviceManagerD3D9 *mDefaultDeviceManager;
Expand Down Expand Up @@ -208,6 +211,12 @@ class THEBES_API LayerManagerD3D9 : public ShadowLayerManager {
*/
PRUint32 mDeviceResetCount;

/*
* True if we should only be drawing layer contents, not
* compositing them to the target.
*/
bool mCompositingDisabled;

/*
* Render the current layer tree to the active target.
*/
Expand Down
6 changes: 5 additions & 1 deletion gfx/layers/d3d9/ThebesLayerD3D9.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,10 @@ ThebesLayerD3D9::RenderThebesLayer(ReadbackProcessor* aReadback)
mValidRegion = neededRegion;
}

if (mD3DManager->CompositingDisabled()) {
return;
}

SetShaderTransformAndOpacity();

if (mode == SURFACE_COMPONENT_ALPHA) {
Expand Down Expand Up @@ -654,7 +658,7 @@ ShadowThebesLayerD3D9::IsEmpty()
void
ShadowThebesLayerD3D9::RenderThebesLayer()
{
if (!mBuffer) {
if (!mBuffer || mD3DManager->CompositingDisabled()) {
return;
}
NS_ABORT_IF_FALSE(mBuffer, "should have a buffer here");
Expand Down
6 changes: 6 additions & 0 deletions gfx/layers/opengl/CanvasLayerOGL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,9 @@ CanvasLayerOGL::RenderLayer(int aPreviousDestination,
const nsIntPoint& aOffset)
{
UpdateSurface();
if (mOGLManager->CompositingDisabled()) {
return;
}
FireDidTransactionCallback();

mOGLManager->MakeCurrent();
Expand Down Expand Up @@ -365,6 +368,9 @@ void
ShadowCanvasLayerOGL::RenderLayer(int aPreviousFrameBuffer,
const nsIntPoint& aOffset)
{
if (mOGLManager->CompositingDisabled()) {
return;
}
mOGLManager->MakeCurrent();

ShaderProgramOGL *program =
Expand Down
4 changes: 4 additions & 0 deletions gfx/layers/opengl/ColorLayerOGL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ static void
RenderColorLayer(ColorLayer* aLayer, LayerManagerOGL *aManager,
const nsIntPoint& aOffset)
{
if (aManager->CompositingDisabled()) {
return;
}

aManager->MakeCurrent();

// XXX we might be able to improve performance by using glClear
Expand Down
80 changes: 42 additions & 38 deletions gfx/layers/opengl/ContainerLayerOGL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,12 +179,14 @@ ContainerRender(Container* aContainer,
}

aContainer->gl()->PushViewportRect();
framebufferRect -= childOffset;
aManager->CreateFBOWithTexture(framebufferRect,
mode,
aPreviousFrameBuffer,
&frameBuffer,
&containerSurface);
framebufferRect -= childOffset;
if (!aManager->CompositingDisabled()) {
aManager->CreateFBOWithTexture(framebufferRect,
mode,
aPreviousFrameBuffer,
&frameBuffer,
&containerSurface);
}
childOffset.x = visibleRect.x;
childOffset.y = visibleRect.y;
} else {
Expand Down Expand Up @@ -239,45 +241,47 @@ ContainerRender(Container* aContainer,
aManager->SetupPipeline(viewport.width, viewport.height,
LayerManagerOGL::ApplyWorldTransform);
aContainer->gl()->PopScissorRect();

aContainer->gl()->fBindFramebuffer(LOCAL_GL_FRAMEBUFFER, aPreviousFrameBuffer);
aContainer->gl()->fDeleteFramebuffers(1, &frameBuffer);

aContainer->gl()->fActiveTexture(LOCAL_GL_TEXTURE0);
if (!aManager->CompositingDisabled()) {
aContainer->gl()->fDeleteFramebuffers(1, &frameBuffer);

aContainer->gl()->fBindTexture(aManager->FBOTextureTarget(), containerSurface);
aContainer->gl()->fActiveTexture(LOCAL_GL_TEXTURE0);

MaskType maskType = MaskNone;
if (aContainer->GetMaskLayer()) {
if (!aContainer->GetTransform().CanDraw2D()) {
maskType = Mask3d;
} else {
maskType = Mask2d;
aContainer->gl()->fBindTexture(aManager->FBOTextureTarget(), containerSurface);

MaskType maskType = MaskNone;
if (aContainer->GetMaskLayer()) {
if (!aContainer->GetTransform().CanDraw2D()) {
maskType = Mask3d;
} else {
maskType = Mask2d;
}
}
ShaderProgramOGL *rgb =
aManager->GetFBOLayerProgram(maskType);

rgb->Activate();
rgb->SetLayerQuadRect(visibleRect);
rgb->SetLayerTransform(transform);
rgb->SetLayerOpacity(opacity);
rgb->SetRenderOffset(aOffset);
rgb->SetTextureUnit(0);
rgb->LoadMask(aContainer->GetMaskLayer());

if (rgb->GetTexCoordMultiplierUniformLocation() != -1) {
// 2DRect case, get the multiplier right for a sampler2DRect
rgb->SetTexCoordMultiplier(visibleRect.width, visibleRect.height);
}
}
ShaderProgramOGL *rgb =
aManager->GetFBOLayerProgram(maskType);

rgb->Activate();
rgb->SetLayerQuadRect(visibleRect);
rgb->SetLayerTransform(transform);
rgb->SetLayerOpacity(opacity);
rgb->SetRenderOffset(aOffset);
rgb->SetTextureUnit(0);
rgb->LoadMask(aContainer->GetMaskLayer());

if (rgb->GetTexCoordMultiplierUniformLocation() != -1) {
// 2DRect case, get the multiplier right for a sampler2DRect
rgb->SetTexCoordMultiplier(visibleRect.width, visibleRect.height);
}

// Drawing is always flipped, but when copying between surfaces we want to avoid
// this. Pass true for the flip parameter to introduce a second flip
// that cancels the other one out.
aManager->BindAndDrawQuad(rgb, true);
// Drawing is always flipped, but when copying between surfaces we want to avoid
// this. Pass true for the flip parameter to introduce a second flip
// that cancels the other one out.
aManager->BindAndDrawQuad(rgb, true);

// Clean up resources. This also unbinds the texture.
aContainer->gl()->fDeleteTextures(1, &containerSurface);
// Clean up resources. This also unbinds the texture.
aContainer->gl()->fDeleteTextures(1, &containerSurface);
}
} else {
aContainer->gl()->PopScissorRect();
}
Expand Down
Loading

0 comments on commit 503c89e

Please sign in to comment.