2010-05-24 23:35:35 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
2010-03-29 21:48:52 -07:00
|
|
|
* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is Mozilla Corporation code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is Mozilla Foundation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2009
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* Bas Schouten <bschouten@mozilla.org>
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
|
|
|
#include "ContainerLayerOGL.h"
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace layers {
|
|
|
|
|
2010-04-26 19:09:47 -07:00
|
|
|
ContainerLayerOGL::ContainerLayerOGL(LayerManagerOGL *aManager)
|
2010-03-29 21:48:52 -07:00
|
|
|
: ContainerLayer(aManager, NULL)
|
2010-04-26 19:09:47 -07:00
|
|
|
, LayerOGL(aManager)
|
2010-03-29 21:48:52 -07:00
|
|
|
{
|
|
|
|
mImplData = static_cast<LayerOGL*>(this);
|
|
|
|
}
|
|
|
|
|
2010-05-20 20:20:48 -07:00
|
|
|
ContainerLayerOGL::~ContainerLayerOGL()
|
|
|
|
{
|
2010-08-06 22:09:18 -07:00
|
|
|
Destroy();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ContainerLayerOGL::Destroy()
|
|
|
|
{
|
|
|
|
if (!mDestroyed) {
|
|
|
|
while (mFirstChild) {
|
|
|
|
GetFirstChildOGL()->Destroy();
|
|
|
|
RemoveChild(mFirstChild);
|
|
|
|
}
|
|
|
|
mDestroyed = PR_TRUE;
|
2010-05-20 20:20:48 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-29 21:48:52 -07:00
|
|
|
void
|
|
|
|
ContainerLayerOGL::InsertAfter(Layer* aChild, Layer* aAfter)
|
|
|
|
{
|
|
|
|
aChild->SetParent(this);
|
|
|
|
if (!aAfter) {
|
2010-05-25 21:06:34 -07:00
|
|
|
Layer *oldFirstChild = GetFirstChild();
|
|
|
|
mFirstChild = aChild;
|
|
|
|
aChild->SetNextSibling(oldFirstChild);
|
|
|
|
aChild->SetPrevSibling(nsnull);
|
|
|
|
if (oldFirstChild) {
|
|
|
|
oldFirstChild->SetPrevSibling(aChild);
|
|
|
|
}
|
2010-05-23 19:25:58 -07:00
|
|
|
NS_ADDREF(aChild);
|
2010-03-29 21:48:52 -07:00
|
|
|
return;
|
|
|
|
}
|
2010-05-25 21:06:34 -07:00
|
|
|
for (Layer *child = GetFirstChild();
|
|
|
|
child; child = child->GetNextSibling()) {
|
|
|
|
if (aAfter == child) {
|
|
|
|
Layer *oldNextSibling = child->GetNextSibling();
|
|
|
|
child->SetNextSibling(aChild);
|
|
|
|
aChild->SetNextSibling(oldNextSibling);
|
|
|
|
if (oldNextSibling) {
|
|
|
|
oldNextSibling->SetPrevSibling(aChild);
|
|
|
|
}
|
|
|
|
aChild->SetPrevSibling(child);
|
2010-05-23 19:25:58 -07:00
|
|
|
NS_ADDREF(aChild);
|
2010-03-29 21:48:52 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
NS_WARNING("Failed to find aAfter layer!");
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ContainerLayerOGL::RemoveChild(Layer *aChild)
|
|
|
|
{
|
|
|
|
if (GetFirstChild() == aChild) {
|
2010-05-25 21:06:34 -07:00
|
|
|
mFirstChild = GetFirstChild()->GetNextSibling();
|
|
|
|
if (mFirstChild) {
|
|
|
|
mFirstChild->SetPrevSibling(nsnull);
|
|
|
|
}
|
|
|
|
aChild->SetNextSibling(nsnull);
|
|
|
|
aChild->SetPrevSibling(nsnull);
|
|
|
|
aChild->SetParent(nsnull);
|
2010-05-20 20:20:48 -07:00
|
|
|
NS_RELEASE(aChild);
|
2010-03-29 21:48:52 -07:00
|
|
|
return;
|
|
|
|
}
|
2010-05-25 21:06:34 -07:00
|
|
|
Layer *lastChild = nsnull;
|
|
|
|
for (Layer *child = GetFirstChild(); child;
|
|
|
|
child = child->GetNextSibling()) {
|
|
|
|
if (child == aChild) {
|
2010-03-29 21:48:52 -07:00
|
|
|
// We're sure this is not our first child. So lastChild != NULL.
|
|
|
|
lastChild->SetNextSibling(child->GetNextSibling());
|
2010-05-25 21:06:34 -07:00
|
|
|
if (child->GetNextSibling()) {
|
|
|
|
child->GetNextSibling()->SetPrevSibling(lastChild);
|
|
|
|
}
|
|
|
|
child->SetNextSibling(nsnull);
|
|
|
|
child->SetPrevSibling(nsnull);
|
|
|
|
child->SetParent(nsnull);
|
2010-05-20 20:20:48 -07:00
|
|
|
NS_RELEASE(aChild);
|
2010-03-29 21:48:52 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
lastChild = child;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Layer*
|
|
|
|
ContainerLayerOGL::GetLayer()
|
|
|
|
{
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
LayerOGL*
|
|
|
|
ContainerLayerOGL::GetFirstChildOGL()
|
|
|
|
{
|
|
|
|
if (!mFirstChild) {
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
return static_cast<LayerOGL*>(mFirstChild->ImplData());
|
|
|
|
}
|
|
|
|
|
2010-09-16 09:45:08 -07:00
|
|
|
static inline GLint GetYCoordOfRectStartingFromBottom(GLint y, GLint height, GLint viewportHeight)
|
|
|
|
{
|
2010-09-18 08:59:06 -07:00
|
|
|
#ifdef XP_MACOSX
|
2010-09-16 09:45:08 -07:00
|
|
|
(void) height;
|
|
|
|
(void) viewportHeight;
|
|
|
|
return y;
|
|
|
|
#else
|
|
|
|
return viewportHeight - height - y;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2010-03-29 21:48:52 -07:00
|
|
|
void
|
2010-05-20 20:20:48 -07:00
|
|
|
ContainerLayerOGL::RenderLayer(int aPreviousFrameBuffer,
|
2010-05-24 23:35:35 -07:00
|
|
|
const nsIntPoint& aOffset)
|
2010-03-29 21:48:52 -07:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Setup our temporary texture for rendering the contents of this container.
|
|
|
|
*/
|
|
|
|
GLuint containerSurface;
|
|
|
|
GLuint frameBuffer;
|
2010-05-24 23:35:35 -07:00
|
|
|
|
|
|
|
nsIntPoint childOffset(aOffset);
|
2010-05-31 16:29:37 -07:00
|
|
|
nsIntRect visibleRect = mVisibleRegion.GetBounds();
|
2010-03-29 21:48:52 -07:00
|
|
|
|
2010-09-13 21:30:00 -07:00
|
|
|
GLint savedScissor[4];
|
|
|
|
gl()->fGetIntegerv(LOCAL_GL_SCISSOR_BOX, savedScissor);
|
|
|
|
|
2010-05-23 15:34:58 -07:00
|
|
|
float opacity = GetOpacity();
|
2010-09-09 13:40:15 -07:00
|
|
|
bool needsFramebuffer = (opacity != 1.0) || !mTransform.IsIdentity();
|
|
|
|
if (needsFramebuffer) {
|
2010-05-31 16:29:37 -07:00
|
|
|
mOGLManager->CreateFBOWithTexture(visibleRect.width,
|
|
|
|
visibleRect.height,
|
2010-05-24 23:35:35 -07:00
|
|
|
&frameBuffer,
|
|
|
|
&containerSurface);
|
2010-05-31 16:29:37 -07:00
|
|
|
childOffset.x = visibleRect.x;
|
|
|
|
childOffset.y = visibleRect.y;
|
2010-09-13 21:30:00 -07:00
|
|
|
mOGLManager->gl()->fScissor(0, 0, visibleRect.width, visibleRect.height);
|
2010-09-09 13:40:15 -07:00
|
|
|
mOGLManager->gl()->fClearColor(0.0, 0.0, 0.0, 0.0);
|
2010-09-07 17:35:50 -07:00
|
|
|
mOGLManager->gl()->fClear(LOCAL_GL_COLOR_BUFFER_BIT);
|
2010-04-01 14:17:15 -07:00
|
|
|
} else {
|
|
|
|
frameBuffer = aPreviousFrameBuffer;
|
|
|
|
}
|
2010-05-24 23:35:35 -07:00
|
|
|
|
2010-09-16 09:45:08 -07:00
|
|
|
GLint viewport[4];
|
|
|
|
gl()->fGetIntegerv(LOCAL_GL_VIEWPORT, viewport);
|
|
|
|
|
2010-03-29 21:48:52 -07:00
|
|
|
/**
|
|
|
|
* Render this container's contents.
|
|
|
|
*/
|
|
|
|
LayerOGL *layerToRender = GetFirstChildOGL();
|
|
|
|
while (layerToRender) {
|
|
|
|
const nsIntRect *clipRect = layerToRender->GetLayer()->GetClipRect();
|
|
|
|
if (clipRect) {
|
2010-09-09 13:40:15 -07:00
|
|
|
if (needsFramebuffer) {
|
|
|
|
gl()->fScissor(clipRect->x - visibleRect.x,
|
2010-09-16 09:45:08 -07:00
|
|
|
GetYCoordOfRectStartingFromBottom(clipRect->y - visibleRect.y, clipRect->height, viewport[3]),
|
2010-09-09 13:40:15 -07:00
|
|
|
clipRect->width,
|
|
|
|
clipRect->height);
|
|
|
|
} else {
|
|
|
|
gl()->fScissor(clipRect->x,
|
2010-09-16 09:45:08 -07:00
|
|
|
GetYCoordOfRectStartingFromBottom(clipRect->y, clipRect->height, viewport[3]),
|
2010-09-09 13:40:15 -07:00
|
|
|
clipRect->width,
|
|
|
|
clipRect->height);
|
|
|
|
}
|
2010-03-29 21:48:52 -07:00
|
|
|
} else {
|
2010-09-09 13:40:15 -07:00
|
|
|
if (needsFramebuffer) {
|
|
|
|
gl()->fScissor(0, 0, visibleRect.width, visibleRect.height);
|
|
|
|
} else {
|
2010-09-16 09:45:08 -07:00
|
|
|
gl()->fScissor(visibleRect.x,
|
|
|
|
GetYCoordOfRectStartingFromBottom(visibleRect.y, visibleRect.height, viewport[3]),
|
|
|
|
visibleRect.width,
|
|
|
|
visibleRect.height);
|
2010-09-09 13:40:15 -07:00
|
|
|
}
|
2010-03-29 21:48:52 -07:00
|
|
|
}
|
|
|
|
|
2010-05-24 23:35:35 -07:00
|
|
|
layerToRender->RenderLayer(frameBuffer, childOffset);
|
|
|
|
|
2010-05-25 21:06:34 -07:00
|
|
|
Layer *nextSibling = layerToRender->GetLayer()->GetNextSibling();
|
|
|
|
layerToRender = nextSibling ? static_cast<LayerOGL*>(nextSibling->
|
|
|
|
ImplData())
|
|
|
|
: nsnull;
|
2010-03-29 21:48:52 -07:00
|
|
|
}
|
|
|
|
|
2010-09-09 13:40:15 -07:00
|
|
|
gl()->fScissor(savedScissor[0], savedScissor[1], savedScissor[2], savedScissor[3]);
|
|
|
|
|
|
|
|
if (needsFramebuffer) {
|
2010-04-01 14:17:15 -07:00
|
|
|
// Unbind the current framebuffer and rebind the previous one.
|
2010-04-26 19:09:47 -07:00
|
|
|
gl()->fBindFramebuffer(LOCAL_GL_FRAMEBUFFER, aPreviousFrameBuffer);
|
|
|
|
gl()->fDeleteFramebuffers(1, &frameBuffer);
|
2010-04-01 14:17:15 -07:00
|
|
|
|
2010-05-24 23:35:35 -07:00
|
|
|
gl()->fActiveTexture(LOCAL_GL_TEXTURE0);
|
2010-04-01 14:17:15 -07:00
|
|
|
|
2010-05-24 23:35:35 -07:00
|
|
|
gl()->fBindTexture(mOGLManager->FBOTextureTarget(), containerSurface);
|
2010-05-12 17:56:11 -07:00
|
|
|
|
2010-05-24 23:35:35 -07:00
|
|
|
ColorTextureLayerProgram *rgb = mOGLManager->GetFBOLayerProgram();
|
2010-04-01 14:17:15 -07:00
|
|
|
|
2010-05-24 23:35:35 -07:00
|
|
|
rgb->Activate();
|
2010-05-31 16:29:37 -07:00
|
|
|
rgb->SetLayerQuadRect(visibleRect);
|
2010-05-24 23:35:35 -07:00
|
|
|
rgb->SetLayerTransform(mTransform);
|
|
|
|
rgb->SetLayerOpacity(opacity);
|
|
|
|
rgb->SetRenderOffset(aOffset);
|
|
|
|
rgb->SetTextureUnit(0);
|
2010-04-01 14:17:15 -07:00
|
|
|
|
2010-05-24 23:35:35 -07:00
|
|
|
if (rgb->GetTexCoordMultiplierUniformLocation() != -1) {
|
|
|
|
// 2DRect case, get the multiplier right for a sampler2DRect
|
2010-05-31 16:29:37 -07:00
|
|
|
float f[] = { float(visibleRect.width), float(visibleRect.height) };
|
2010-05-24 23:35:35 -07:00
|
|
|
rgb->SetUniform(rgb->GetTexCoordMultiplierUniformLocation(),
|
|
|
|
2, f);
|
|
|
|
}
|
2010-04-01 14:17:15 -07:00
|
|
|
|
2010-05-24 23:35:35 -07:00
|
|
|
DEBUG_GL_ERROR_CHECK(gl());
|
2010-04-01 14:17:15 -07:00
|
|
|
|
2010-05-24 23:35:35 -07:00
|
|
|
mOGLManager->BindAndDrawQuad(rgb);
|
2010-04-01 14:17:15 -07:00
|
|
|
|
2010-05-24 23:35:35 -07:00
|
|
|
DEBUG_GL_ERROR_CHECK(gl());
|
2010-04-01 14:17:15 -07:00
|
|
|
|
2010-05-24 23:35:35 -07:00
|
|
|
// Clean up resources. This also unbinds the texture.
|
2010-04-26 19:09:47 -07:00
|
|
|
gl()->fDeleteTextures(1, &containerSurface);
|
2010-05-24 23:35:35 -07:00
|
|
|
|
|
|
|
DEBUG_GL_ERROR_CHECK(gl());
|
2010-04-01 14:17:15 -07:00
|
|
|
}
|
2010-03-29 21:48:52 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
} /* layers */
|
|
|
|
} /* mozilla */
|