Bug 556584: Allow opaque containers to draw their contents directly to their parent layer. r=joedrew

This commit is contained in:
Bas Schouten 2010-04-01 23:17:15 +02:00
parent e06c8ff57c
commit 0291fc7a4f

View file

@ -132,54 +132,57 @@ ContainerLayerOGL::RenderLayer(int aPreviousFrameBuffer)
* Setup our temporary texture for rendering the contents of this container.
*/
GLuint containerSurface;
sglWrapper.GenTextures(1, &containerSurface);
sglWrapper.BindTexture(LOCAL_GL_TEXTURE_2D, containerSurface);
sglWrapper.TexImage2D(LOCAL_GL_TEXTURE_2D,
0,
LOCAL_GL_RGBA,
mVisibleRect.width,
mVisibleRect.height,
0,
LOCAL_GL_BGRA,
LOCAL_GL_UNSIGNED_BYTE,
NULL);
sglWrapper.TexParameteri(LOCAL_GL_TEXTURE_2D, LOCAL_GL_TEXTURE_MIN_FILTER, LOCAL_GL_LINEAR);
sglWrapper.TexParameteri(LOCAL_GL_TEXTURE_2D, LOCAL_GL_TEXTURE_MAG_FILTER, LOCAL_GL_LINEAR);
/**
* Create the framebuffer and bind it to make our content render into our
* framebuffer.
*/
GLuint frameBuffer;
sglWrapper.GenFramebuffersEXT(1, &frameBuffer);
sglWrapper.BindFramebufferEXT(LOCAL_GL_FRAMEBUFFER_EXT, frameBuffer);
sglWrapper.FramebufferTexture2DEXT(LOCAL_GL_FRAMEBUFFER_EXT,
LOCAL_GL_COLOR_ATTACHMENT0_EXT,
LOCAL_GL_TEXTURE_2D,
containerSurface,
0);
NS_ASSERTION(
sglWrapper.CheckFramebufferStatusEXT(LOCAL_GL_FRAMEBUFFER_EXT) ==
LOCAL_GL_FRAMEBUFFER_COMPLETE, "Error setting up framebuffer.");
RGBLayerProgram *rgbProgram =
static_cast<LayerManagerOGL*>(mManager)->GetRGBLayerProgram();
YCbCrLayerProgram *yCbCrProgram =
static_cast<LayerManagerOGL*>(mManager)->GetYCbCrLayerProgram();
/**
* Store old shader program variables and set the ones used for rendering
* this container's content.
*/
rgbProgram->Activate();
rgbProgram->PushRenderTargetOffset((GLfloat)GetVisibleRect().x,
(GLfloat)GetVisibleRect().y);
yCbCrProgram->Activate();
yCbCrProgram->PushRenderTargetOffset((GLfloat)GetVisibleRect().x,
(GLfloat)GetVisibleRect().y);
if (GetOpacity() != 1.0) {
sglWrapper.GenTextures(1, &containerSurface);
sglWrapper.BindTexture(LOCAL_GL_TEXTURE_2D, containerSurface);
sglWrapper.TexImage2D(LOCAL_GL_TEXTURE_2D,
0,
LOCAL_GL_RGBA,
mVisibleRect.width,
mVisibleRect.height,
0,
LOCAL_GL_BGRA,
LOCAL_GL_UNSIGNED_BYTE,
NULL);
sglWrapper.TexParameteri(LOCAL_GL_TEXTURE_2D, LOCAL_GL_TEXTURE_MIN_FILTER, LOCAL_GL_LINEAR);
sglWrapper.TexParameteri(LOCAL_GL_TEXTURE_2D, LOCAL_GL_TEXTURE_MAG_FILTER, LOCAL_GL_LINEAR);
/**
* Create the framebuffer and bind it to make our content render into our
* framebuffer.
*/
sglWrapper.GenFramebuffersEXT(1, &frameBuffer);
sglWrapper.BindFramebufferEXT(LOCAL_GL_FRAMEBUFFER_EXT, frameBuffer);
sglWrapper.FramebufferTexture2DEXT(LOCAL_GL_FRAMEBUFFER_EXT,
LOCAL_GL_COLOR_ATTACHMENT0_EXT,
LOCAL_GL_TEXTURE_2D,
containerSurface,
0);
NS_ASSERTION(
sglWrapper.CheckFramebufferStatusEXT(LOCAL_GL_FRAMEBUFFER_EXT) ==
LOCAL_GL_FRAMEBUFFER_COMPLETE, "Error setting up framebuffer.");
/**
* Store old shader program variables and set the ones used for rendering
* this container's content.
*/
rgbProgram->Activate();
rgbProgram->PushRenderTargetOffset((GLfloat)GetVisibleRect().x,
(GLfloat)GetVisibleRect().y);
yCbCrProgram->Activate();
yCbCrProgram->PushRenderTargetOffset((GLfloat)GetVisibleRect().x,
(GLfloat)GetVisibleRect().y);
} else {
frameBuffer = aPreviousFrameBuffer;
}
/**
* Render this container's contents.
@ -200,45 +203,47 @@ ContainerLayerOGL::RenderLayer(int aPreviousFrameBuffer)
layerToRender = layerToRender->GetNextSibling();
}
// Unbind the current framebuffer and rebind the previous one.
sglWrapper.BindFramebufferEXT(LOCAL_GL_FRAMEBUFFER_EXT, aPreviousFrameBuffer);
sglWrapper.DeleteFramebuffersEXT(1, &frameBuffer);
if (GetOpacity() != 1.0) {
// Unbind the current framebuffer and rebind the previous one.
sglWrapper.BindFramebufferEXT(LOCAL_GL_FRAMEBUFFER_EXT, aPreviousFrameBuffer);
sglWrapper.DeleteFramebuffersEXT(1, &frameBuffer);
// Restore old shader program variables.
yCbCrProgram->Activate();
yCbCrProgram->PopRenderTargetOffset();
// Restore old shader program variables.
yCbCrProgram->Activate();
yCbCrProgram->PopRenderTargetOffset();
rgbProgram->Activate();
rgbProgram->PopRenderTargetOffset();
rgbProgram->Activate();
rgbProgram->PopRenderTargetOffset();
/**
* Render the contents of this container to our destination.
*/
float quadTransform[4][4];
/*
* Matrix to transform the <0.0,0.0>, <1.0,1.0> quad to the correct position
* and size.
*/
memset(&quadTransform, 0, sizeof(quadTransform));
quadTransform[0][0] = (float)GetVisibleRect().width;
quadTransform[1][1] = (float)GetVisibleRect().height;
quadTransform[2][2] = 1.0f;
quadTransform[3][0] = (float)GetVisibleRect().x;
quadTransform[3][1] = (float)GetVisibleRect().y;
quadTransform[3][3] = 1.0f;
/**
* Render the contents of this container to our destination.
*/
float quadTransform[4][4];
/*
* Matrix to transform the <0.0,0.0>, <1.0,1.0> quad to the correct position
* and size.
*/
memset(&quadTransform, 0, sizeof(quadTransform));
quadTransform[0][0] = (float)GetVisibleRect().width;
quadTransform[1][1] = (float)GetVisibleRect().height;
quadTransform[2][2] = 1.0f;
quadTransform[3][0] = (float)GetVisibleRect().x;
quadTransform[3][1] = (float)GetVisibleRect().y;
quadTransform[3][3] = 1.0f;
rgbProgram->SetLayerQuadTransform(&quadTransform[0][0]);
rgbProgram->SetLayerQuadTransform(&quadTransform[0][0]);
sglWrapper.BindTexture(LOCAL_GL_TEXTURE_2D, containerSurface);
sglWrapper.BindTexture(LOCAL_GL_TEXTURE_2D, containerSurface);
rgbProgram->SetLayerOpacity(GetOpacity());
rgbProgram->SetLayerTransform(&mTransform._11);
rgbProgram->Apply();
rgbProgram->SetLayerOpacity(GetOpacity());
rgbProgram->SetLayerTransform(&mTransform._11);
rgbProgram->Apply();
sglWrapper.DrawArrays(LOCAL_GL_TRIANGLE_STRIP, 0, 4);
sglWrapper.DrawArrays(LOCAL_GL_TRIANGLE_STRIP, 0, 4);
// Clean up resources.
sglWrapper.DeleteTextures(1, &containerSurface);
// Clean up resources.
sglWrapper.DeleteTextures(1, &containerSurface);
}
}
} /* layers */