2010-05-24 23:35:35 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
2010-03-29 21:48:52 -07:00
|
|
|
* 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>
|
2010-05-24 23:35:35 -07:00
|
|
|
* Vladimir Vukicevic <vladimir@pobox.com>
|
2010-03-29 21:48:52 -07:00
|
|
|
*
|
|
|
|
* 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 ***** */
|
|
|
|
|
2011-04-02 19:14:00 -07:00
|
|
|
#include "mozilla/layers/PLayers.h"
|
2011-10-10 22:50:08 -07:00
|
|
|
|
|
|
|
/* This must occur *after* layers/PLayers.h to avoid typedefs conflicts. */
|
|
|
|
#include "mozilla/Util.h"
|
|
|
|
|
2011-04-02 19:14:00 -07:00
|
|
|
#include "mozilla/layers/ShadowLayers.h"
|
2010-10-13 15:55:45 -07:00
|
|
|
|
2010-07-22 13:29:37 -07:00
|
|
|
#include "ThebesLayerBuffer.h"
|
2010-03-29 21:48:52 -07:00
|
|
|
#include "ThebesLayerOGL.h"
|
2011-01-17 23:22:25 -08:00
|
|
|
#include "gfxUtils.h"
|
|
|
|
#include "gfxTeeSurface.h"
|
2010-03-29 21:48:52 -07:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace layers {
|
|
|
|
|
2010-07-22 13:29:37 -07:00
|
|
|
using gl::GLContext;
|
2010-07-22 13:29:37 -07:00
|
|
|
using gl::TextureImage;
|
|
|
|
|
2011-03-31 14:33:46 -07:00
|
|
|
static const int ALLOW_REPEAT = ThebesLayerBuffer::ALLOW_REPEAT;
|
|
|
|
|
2010-11-12 12:02:20 -08:00
|
|
|
// BindAndDrawQuadWithTextureRect can work with either GL_REPEAT (preferred)
|
2011-03-31 14:33:46 -07:00
|
|
|
// or GL_CLAMP_TO_EDGE textures. If ALLOW_REPEAT is set in aFlags, we
|
|
|
|
// select based on whether REPEAT is valid for non-power-of-two textures --
|
|
|
|
// if we have NPOT support we use it, otherwise we stick with CLAMP_TO_EDGE and
|
|
|
|
// decompose.
|
|
|
|
// If ALLOW_REPEAT is not set, we always use GL_CLAMP_TO_EDGE.
|
2010-11-12 12:02:20 -08:00
|
|
|
static already_AddRefed<TextureImage>
|
|
|
|
CreateClampOrRepeatTextureImage(GLContext *aGl,
|
|
|
|
const nsIntSize& aSize,
|
2011-03-31 14:33:46 -07:00
|
|
|
TextureImage::ContentType aContentType,
|
|
|
|
PRUint32 aFlags)
|
2010-11-12 12:02:20 -08:00
|
|
|
{
|
|
|
|
GLenum wrapMode = LOCAL_GL_CLAMP_TO_EDGE;
|
2011-03-31 14:33:46 -07:00
|
|
|
if ((aFlags & ALLOW_REPEAT) &&
|
|
|
|
(aGl->IsExtensionSupported(GLContext::ARB_texture_non_power_of_two) ||
|
|
|
|
aGl->IsExtensionSupported(GLContext::OES_texture_npot)))
|
2010-11-12 12:02:20 -08:00
|
|
|
{
|
|
|
|
wrapMode = LOCAL_GL_REPEAT;
|
|
|
|
}
|
|
|
|
|
|
|
|
return aGl->CreateTextureImage(aSize, aContentType, wrapMode);
|
|
|
|
}
|
|
|
|
|
2011-02-26 04:40:47 -08:00
|
|
|
static void
|
|
|
|
SetAntialiasingFlags(Layer* aLayer, gfxContext* aTarget)
|
|
|
|
{
|
|
|
|
nsRefPtr<gfxASurface> surface = aTarget->CurrentSurface();
|
|
|
|
if (surface->GetContentType() != gfxASurface::CONTENT_COLOR_ALPHA) {
|
|
|
|
// Destination doesn't have alpha channel; no need to set any special flags
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
surface->SetSubpixelAntialiasingEnabled(
|
|
|
|
!(aLayer->GetContentFlags() & Layer::CONTENT_COMPONENT_ALPHA));
|
|
|
|
}
|
2010-07-22 13:29:37 -07:00
|
|
|
|
2010-07-22 13:29:37 -07:00
|
|
|
class ThebesLayerBufferOGL
|
|
|
|
{
|
|
|
|
NS_INLINE_DECL_REFCOUNTING(ThebesLayerBufferOGL)
|
|
|
|
public:
|
|
|
|
typedef TextureImage::ContentType ContentType;
|
|
|
|
typedef ThebesLayerBuffer::PaintState PaintState;
|
|
|
|
|
2010-10-13 15:55:45 -07:00
|
|
|
ThebesLayerBufferOGL(ThebesLayer* aLayer, LayerOGL* aOGLLayer)
|
2010-07-22 13:29:37 -07:00
|
|
|
: mLayer(aLayer)
|
2010-10-13 15:55:45 -07:00
|
|
|
, mOGLLayer(aOGLLayer)
|
2010-07-22 13:29:37 -07:00
|
|
|
{}
|
|
|
|
virtual ~ThebesLayerBufferOGL() {}
|
|
|
|
|
2011-03-31 14:33:46 -07:00
|
|
|
enum { PAINT_WILL_RESAMPLE = ThebesLayerBuffer::PAINT_WILL_RESAMPLE };
|
2011-02-08 12:37:47 -08:00
|
|
|
virtual PaintState BeginPaint(ContentType aContentType,
|
2011-03-31 14:33:46 -07:00
|
|
|
PRUint32 aFlags) = 0;
|
2010-07-22 13:29:37 -07:00
|
|
|
|
2011-03-31 14:33:46 -07:00
|
|
|
void RenderTo(const nsIntPoint& aOffset, LayerManagerOGL* aManager,
|
|
|
|
PRUint32 aFlags);
|
2010-07-22 13:29:37 -07:00
|
|
|
|
2010-09-21 12:41:24 -07:00
|
|
|
nsIntSize GetSize() {
|
|
|
|
if (mTexImage)
|
|
|
|
return mTexImage->GetSize();
|
|
|
|
return nsIntSize(0, 0);
|
|
|
|
}
|
|
|
|
|
2010-07-22 13:29:37 -07:00
|
|
|
protected:
|
2010-09-21 12:41:24 -07:00
|
|
|
virtual nsIntPoint GetOriginOffset() = 0;
|
2010-07-22 13:29:37 -07:00
|
|
|
|
2010-10-13 15:55:45 -07:00
|
|
|
GLContext* gl() const { return mOGLLayer->gl(); }
|
2010-07-22 13:29:37 -07:00
|
|
|
|
2010-10-13 15:55:45 -07:00
|
|
|
ThebesLayer* mLayer;
|
|
|
|
LayerOGL* mOGLLayer;
|
2010-07-22 13:29:37 -07:00
|
|
|
nsRefPtr<TextureImage> mTexImage;
|
2011-01-17 23:22:25 -08:00
|
|
|
nsRefPtr<TextureImage> mTexImageOnWhite;
|
2010-07-22 13:29:37 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
void
|
|
|
|
ThebesLayerBufferOGL::RenderTo(const nsIntPoint& aOffset,
|
2011-03-31 14:33:46 -07:00
|
|
|
LayerManagerOGL* aManager,
|
|
|
|
PRUint32 aFlags)
|
2010-07-22 13:29:37 -07:00
|
|
|
{
|
2010-09-21 12:41:24 -07:00
|
|
|
if (!mTexImage)
|
|
|
|
return;
|
|
|
|
|
2011-01-17 23:22:25 -08:00
|
|
|
if (mTexImage->InUpdate()) {
|
|
|
|
mTexImage->EndUpdate();
|
|
|
|
}
|
2010-09-09 16:41:02 -07:00
|
|
|
|
2011-01-17 23:22:25 -08:00
|
|
|
if (mTexImageOnWhite && mTexImageOnWhite->InUpdate()) {
|
|
|
|
mTexImageOnWhite->EndUpdate();
|
2010-07-22 13:29:37 -07:00
|
|
|
}
|
|
|
|
|
2011-01-17 23:22:25 -08:00
|
|
|
PRInt32 passes = mTexImageOnWhite ? 2 : 1;
|
|
|
|
for (PRInt32 pass = 1; pass <= passes; ++pass) {
|
|
|
|
LayerProgram *program;
|
|
|
|
|
|
|
|
if (passes == 2) {
|
|
|
|
ComponentAlphaTextureLayerProgram *alphaProgram;
|
|
|
|
if (pass == 1) {
|
|
|
|
alphaProgram = aManager->GetComponentAlphaPass1LayerProgram();
|
|
|
|
gl()->fBlendFuncSeparate(LOCAL_GL_ZERO, LOCAL_GL_ONE_MINUS_SRC_COLOR,
|
|
|
|
LOCAL_GL_ONE, LOCAL_GL_ONE);
|
|
|
|
} else {
|
|
|
|
alphaProgram = aManager->GetComponentAlphaPass2LayerProgram();
|
|
|
|
gl()->fBlendFuncSeparate(LOCAL_GL_ONE, LOCAL_GL_ONE,
|
|
|
|
LOCAL_GL_ONE, LOCAL_GL_ONE);
|
|
|
|
}
|
2010-10-13 15:55:45 -07:00
|
|
|
|
2011-01-17 23:22:25 -08:00
|
|
|
alphaProgram->Activate();
|
|
|
|
alphaProgram->SetBlackTextureUnit(0);
|
|
|
|
alphaProgram->SetWhiteTextureUnit(1);
|
|
|
|
program = alphaProgram;
|
|
|
|
} else {
|
|
|
|
// Note BGR: Cairo's image surfaces are always in what
|
|
|
|
// OpenGL and our shaders consider BGR format.
|
|
|
|
ColorTextureLayerProgram *basicProgram =
|
2011-04-07 16:58:08 -07:00
|
|
|
aManager->GetColorTextureLayerProgram(mTexImage->GetShaderProgramType());
|
2011-01-17 23:22:25 -08:00
|
|
|
|
|
|
|
basicProgram->Activate();
|
|
|
|
basicProgram->SetTextureUnit(0);
|
|
|
|
program = basicProgram;
|
|
|
|
}
|
2010-10-13 15:55:45 -07:00
|
|
|
|
2011-01-17 23:22:25 -08:00
|
|
|
program->SetLayerOpacity(mLayer->GetEffectiveOpacity());
|
|
|
|
program->SetLayerTransform(mLayer->GetEffectiveTransform());
|
|
|
|
program->SetRenderOffset(aOffset);
|
|
|
|
|
2011-03-31 14:33:46 -07:00
|
|
|
const nsIntRegion& visibleRegion = mLayer->GetEffectiveVisibleRegion();
|
|
|
|
nsIntRegion tmpRegion;
|
|
|
|
const nsIntRegion* renderRegion;
|
|
|
|
if (aFlags & PAINT_WILL_RESAMPLE) {
|
|
|
|
// If we're resampling, then the texture image will contain exactly the
|
|
|
|
// entire visible region's bounds, and we should draw it all in one quad
|
|
|
|
// to avoid unexpected aliasing.
|
|
|
|
tmpRegion = visibleRegion.GetBounds();
|
|
|
|
renderRegion = &tmpRegion;
|
|
|
|
} else {
|
|
|
|
renderRegion = &visibleRegion;
|
|
|
|
}
|
2011-01-17 23:22:25 -08:00
|
|
|
|
2011-08-24 07:09:59 -07:00
|
|
|
nsIntRegion region(*renderRegion);
|
|
|
|
nsIntPoint origin = GetOriginOffset();
|
|
|
|
region.MoveBy(-origin); // translate into TexImage space, buffer origin might not be at texture (0,0)
|
|
|
|
|
|
|
|
// Figure out the intersecting draw region
|
|
|
|
nsIntSize texSize = mTexImage->GetSize();
|
|
|
|
nsIntRect textureRect = nsIntRect(0, 0, texSize.width, texSize.height);
|
|
|
|
textureRect.MoveBy(region.GetBounds().TopLeft());
|
|
|
|
nsIntRegion subregion;
|
|
|
|
subregion.And(region, textureRect);
|
|
|
|
if (subregion.IsEmpty()) // Region is empty, nothing to draw
|
|
|
|
return;
|
|
|
|
|
|
|
|
nsIntRegion screenRects;
|
|
|
|
nsIntRegion regionRects;
|
|
|
|
|
|
|
|
// Collect texture/screen coordinates for drawing
|
|
|
|
nsIntRegionRectIterator iter(subregion);
|
|
|
|
while (const nsIntRect* iterRect = iter.Next()) {
|
|
|
|
nsIntRect regionRect = *iterRect;
|
|
|
|
nsIntRect screenRect = regionRect;
|
|
|
|
screenRect.MoveBy(origin);
|
|
|
|
|
|
|
|
screenRects.Or(screenRects, screenRect);
|
|
|
|
regionRects.Or(regionRects, regionRect);
|
|
|
|
}
|
|
|
|
|
2011-07-06 11:00:47 -07:00
|
|
|
mTexImage->BeginTileIteration();
|
|
|
|
if (mTexImageOnWhite) {
|
2011-08-24 07:09:59 -07:00
|
|
|
NS_ASSERTION(mTexImage->GetTileCount() == mTexImageOnWhite->GetTileCount(),
|
|
|
|
"Tile count mismatch on component alpha texture");
|
2011-07-06 11:00:47 -07:00
|
|
|
mTexImageOnWhite->BeginTileIteration();
|
2011-01-17 23:22:25 -08:00
|
|
|
}
|
2011-07-06 11:00:47 -07:00
|
|
|
|
2011-08-24 07:09:59 -07:00
|
|
|
bool usingTiles = (mTexImage->GetTileCount() > 1);
|
2011-07-06 11:00:47 -07:00
|
|
|
do {
|
2011-08-24 07:09:59 -07:00
|
|
|
if (mTexImageOnWhite) {
|
|
|
|
NS_ASSERTION(mTexImageOnWhite->GetTileRect() == mTexImage->GetTileRect(), "component alpha textures should be the same size.");
|
2011-07-06 11:00:47 -07:00
|
|
|
}
|
2011-08-24 07:09:59 -07:00
|
|
|
|
|
|
|
nsIntRect tileRect = mTexImage->GetTileRect();
|
|
|
|
|
2011-07-06 11:00:47 -07:00
|
|
|
// Bind textures.
|
|
|
|
TextureImage::ScopedBindTexture texBind(mTexImage, LOCAL_GL_TEXTURE0);
|
|
|
|
TextureImage::ScopedBindTexture texOnWhiteBind(mTexImageOnWhite, LOCAL_GL_TEXTURE1);
|
|
|
|
|
2011-08-24 07:09:59 -07:00
|
|
|
// Draw texture. If we're using tiles, we do repeating manually, as texture
|
|
|
|
// repeat would cause each individual tile to repeat instead of the
|
|
|
|
// compound texture as a whole. This involves drawing at most 4 sections,
|
|
|
|
// 2 for each axis that has texture repeat.
|
|
|
|
for (int y = 0; y < (usingTiles ? 2 : 1); y++) {
|
|
|
|
for (int x = 0; x < (usingTiles ? 2 : 1); x++) {
|
|
|
|
nsIntRect currentTileRect(tileRect);
|
|
|
|
currentTileRect.MoveBy(x * texSize.width, y * texSize.height);
|
|
|
|
|
|
|
|
nsIntRegionRectIterator screenIter(screenRects);
|
|
|
|
nsIntRegionRectIterator regionIter(regionRects);
|
|
|
|
|
|
|
|
const nsIntRect* screenRect;
|
|
|
|
const nsIntRect* regionRect;
|
|
|
|
while ((screenRect = screenIter.Next()) &&
|
|
|
|
(regionRect = regionIter.Next())) {
|
|
|
|
nsIntRect tileScreenRect(*screenRect);
|
|
|
|
nsIntRect tileRegionRect(*regionRect);
|
|
|
|
|
|
|
|
// When we're using tiles, find the intersection between the tile
|
|
|
|
// rect and this region rect. Tiling is then handled by the
|
|
|
|
// outer for-loops and modifying the tile rect.
|
|
|
|
if (usingTiles) {
|
|
|
|
tileScreenRect.MoveBy(-origin);
|
|
|
|
tileScreenRect = tileScreenRect.Intersect(currentTileRect);
|
|
|
|
tileScreenRect.MoveBy(origin);
|
|
|
|
|
|
|
|
if (tileScreenRect.IsEmpty())
|
|
|
|
continue;
|
|
|
|
|
|
|
|
tileRegionRect = regionRect->Intersect(currentTileRect);
|
|
|
|
tileRegionRect.MoveBy(-currentTileRect.TopLeft());
|
|
|
|
}
|
|
|
|
|
2011-10-14 13:16:19 -07:00
|
|
|
#ifdef ANDROID
|
|
|
|
// Bug 691354
|
|
|
|
// Using the LINEAR filter we get unexplained artifacts.
|
|
|
|
// Use NEAREST when no scaling is required.
|
|
|
|
gfxMatrix matrix;
|
|
|
|
bool is2D = mLayer->GetEffectiveTransform().Is2D(&matrix);
|
|
|
|
if (is2D && !matrix.HasNonTranslationOrFlip()) {
|
|
|
|
gl()->ApplyFilterToBoundTexture(gfxPattern::FILTER_NEAREST);
|
|
|
|
} else {
|
|
|
|
mTexImage->ApplyFilter();
|
|
|
|
}
|
|
|
|
#endif
|
2011-08-24 07:09:59 -07:00
|
|
|
program->SetLayerQuadRect(tileScreenRect);
|
|
|
|
aManager->BindAndDrawQuadWithTextureRect(program, tileRegionRect,
|
|
|
|
tileRect.Size(),
|
|
|
|
mTexImage->GetWrapMode());
|
|
|
|
}
|
|
|
|
}
|
2011-08-23 14:12:15 -07:00
|
|
|
}
|
2011-08-24 07:09:59 -07:00
|
|
|
|
|
|
|
if (mTexImageOnWhite)
|
|
|
|
mTexImageOnWhite->NextTile();
|
2011-07-06 11:00:47 -07:00
|
|
|
} while (mTexImage->NextTile());
|
2010-09-22 11:17:01 -07:00
|
|
|
}
|
2011-01-17 23:22:25 -08:00
|
|
|
|
|
|
|
if (mTexImageOnWhite) {
|
|
|
|
// Restore defaults
|
|
|
|
gl()->fBlendFuncSeparate(LOCAL_GL_ONE, LOCAL_GL_ONE_MINUS_SRC_ALPHA,
|
|
|
|
LOCAL_GL_ONE, LOCAL_GL_ONE);
|
2011-04-07 16:58:08 -07:00
|
|
|
}
|
2010-07-22 13:29:37 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// This implementation is the fast-path for when our TextureImage is
|
|
|
|
// permanently backed with a server-side ASurface. We can simply
|
|
|
|
// reuse the ThebesLayerBuffer logic in its entirety and profit.
|
|
|
|
class SurfaceBufferOGL : public ThebesLayerBufferOGL, private ThebesLayerBuffer
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
typedef ThebesLayerBufferOGL::ContentType ContentType;
|
|
|
|
typedef ThebesLayerBufferOGL::PaintState PaintState;
|
|
|
|
|
2010-09-21 12:41:24 -07:00
|
|
|
SurfaceBufferOGL(ThebesLayerOGL* aLayer)
|
2010-10-13 15:55:45 -07:00
|
|
|
: ThebesLayerBufferOGL(aLayer, aLayer)
|
2010-07-22 13:29:37 -07:00
|
|
|
, ThebesLayerBuffer(SizedToVisibleBounds)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
virtual ~SurfaceBufferOGL() {}
|
|
|
|
|
|
|
|
// ThebesLayerBufferOGL interface
|
2011-02-08 12:37:47 -08:00
|
|
|
virtual PaintState BeginPaint(ContentType aContentType,
|
2011-03-31 14:33:46 -07:00
|
|
|
PRUint32 aFlags)
|
2010-07-22 13:29:37 -07:00
|
|
|
{
|
|
|
|
// Let ThebesLayerBuffer do all the hard work for us! :D
|
2011-02-08 12:37:47 -08:00
|
|
|
return ThebesLayerBuffer::BeginPaint(mLayer,
|
|
|
|
aContentType,
|
2011-03-31 14:33:46 -07:00
|
|
|
aFlags);
|
2010-07-22 13:29:37 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// ThebesLayerBuffer interface
|
|
|
|
virtual already_AddRefed<gfxASurface>
|
2011-03-31 14:33:46 -07:00
|
|
|
CreateBuffer(ContentType aType, const nsIntSize& aSize, PRUint32 aFlags)
|
2010-07-22 13:29:37 -07:00
|
|
|
{
|
|
|
|
NS_ASSERTION(gfxASurface::CONTENT_ALPHA != aType,"ThebesBuffer has color");
|
|
|
|
|
2011-03-31 14:33:46 -07:00
|
|
|
mTexImage = CreateClampOrRepeatTextureImage(gl(), aSize, aType, aFlags);
|
2010-07-22 13:29:37 -07:00
|
|
|
return mTexImage ? mTexImage->GetBackingSurface() : nsnull;
|
|
|
|
}
|
|
|
|
|
2010-07-22 13:29:37 -07:00
|
|
|
protected:
|
2010-09-21 12:41:24 -07:00
|
|
|
virtual nsIntPoint GetOriginOffset() {
|
|
|
|
return BufferRect().TopLeft() - BufferRotation();
|
2010-07-22 13:29:37 -07:00
|
|
|
}
|
2010-07-22 13:29:37 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// This implementation is (currently) the slow-path for when we can't
|
|
|
|
// implement pixel retaining using thebes. This implementation and
|
|
|
|
// the above could be unified by abstracting buffer-copy operations
|
|
|
|
// and implementing them here using GL hacketry.
|
|
|
|
class BasicBufferOGL : public ThebesLayerBufferOGL
|
|
|
|
{
|
|
|
|
public:
|
2010-09-21 12:41:24 -07:00
|
|
|
BasicBufferOGL(ThebesLayerOGL* aLayer)
|
2010-10-13 15:55:45 -07:00
|
|
|
: ThebesLayerBufferOGL(aLayer, aLayer)
|
2010-09-21 12:41:24 -07:00
|
|
|
, mBufferRect(0,0,0,0)
|
|
|
|
, mBufferRotation(0,0)
|
2010-07-22 13:29:37 -07:00
|
|
|
{}
|
|
|
|
virtual ~BasicBufferOGL() {}
|
|
|
|
|
2011-02-08 12:37:47 -08:00
|
|
|
virtual PaintState BeginPaint(ContentType aContentType,
|
2011-03-31 14:33:46 -07:00
|
|
|
PRUint32 aFlags);
|
2010-07-22 13:29:37 -07:00
|
|
|
|
2010-07-22 13:29:37 -07:00
|
|
|
protected:
|
2010-09-21 12:41:24 -07:00
|
|
|
enum XSide {
|
|
|
|
LEFT, RIGHT
|
|
|
|
};
|
|
|
|
enum YSide {
|
|
|
|
TOP, BOTTOM
|
|
|
|
};
|
|
|
|
nsIntRect GetQuadrantRectangle(XSide aXSide, YSide aYSide);
|
|
|
|
|
|
|
|
virtual nsIntPoint GetOriginOffset() {
|
|
|
|
return mBufferRect.TopLeft() - mBufferRotation;
|
2010-07-22 13:29:37 -07:00
|
|
|
}
|
|
|
|
|
2010-07-22 13:29:37 -07:00
|
|
|
private:
|
|
|
|
nsIntRect mBufferRect;
|
2010-09-21 12:41:24 -07:00
|
|
|
nsIntPoint mBufferRotation;
|
2010-07-22 13:29:37 -07:00
|
|
|
};
|
|
|
|
|
2010-09-21 12:41:24 -07:00
|
|
|
static void
|
|
|
|
WrapRotationAxis(PRInt32* aRotationPoint, PRInt32 aSize)
|
|
|
|
{
|
|
|
|
if (*aRotationPoint < 0) {
|
|
|
|
*aRotationPoint += aSize;
|
|
|
|
} else if (*aRotationPoint >= aSize) {
|
|
|
|
*aRotationPoint -= aSize;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIntRect
|
|
|
|
BasicBufferOGL::GetQuadrantRectangle(XSide aXSide, YSide aYSide)
|
|
|
|
{
|
|
|
|
// quadrantTranslation is the amount we translate the top-left
|
|
|
|
// of the quadrant by to get coordinates relative to the layer
|
|
|
|
nsIntPoint quadrantTranslation = -mBufferRotation;
|
|
|
|
quadrantTranslation.x += aXSide == LEFT ? mBufferRect.width : 0;
|
|
|
|
quadrantTranslation.y += aYSide == TOP ? mBufferRect.height : 0;
|
|
|
|
return mBufferRect + quadrantTranslation;
|
|
|
|
}
|
|
|
|
|
2011-01-17 23:22:25 -08:00
|
|
|
static void
|
|
|
|
FillSurface(gfxASurface* aSurface, const nsIntRegion& aRegion,
|
2011-02-17 14:47:04 -08:00
|
|
|
const nsIntPoint& aOffset, const gfxRGBA& aColor)
|
2011-01-17 23:22:25 -08:00
|
|
|
{
|
|
|
|
nsRefPtr<gfxContext> ctx = new gfxContext(aSurface);
|
|
|
|
ctx->Translate(-gfxPoint(aOffset.x, aOffset.y));
|
|
|
|
gfxUtils::ClipToRegion(ctx, aRegion);
|
|
|
|
ctx->SetColor(aColor);
|
|
|
|
ctx->Paint();
|
|
|
|
}
|
|
|
|
|
2010-07-22 13:29:37 -07:00
|
|
|
BasicBufferOGL::PaintState
|
2011-02-08 12:37:47 -08:00
|
|
|
BasicBufferOGL::BeginPaint(ContentType aContentType,
|
2011-03-31 14:33:46 -07:00
|
|
|
PRUint32 aFlags)
|
2010-07-22 13:29:37 -07:00
|
|
|
{
|
2010-09-21 12:41:24 -07:00
|
|
|
PaintState result;
|
2011-06-22 05:11:28 -07:00
|
|
|
// We need to disable rotation if we're going to be resampled when
|
2011-03-31 14:33:46 -07:00
|
|
|
// drawing, because we might sample across the rotation boundary.
|
2011-09-28 23:19:26 -07:00
|
|
|
bool canHaveRotation = !(aFlags & PAINT_WILL_RESAMPLE);
|
2011-03-31 14:33:46 -07:00
|
|
|
|
|
|
|
nsIntRegion validRegion = mLayer->GetValidRegion();
|
|
|
|
|
|
|
|
Layer::SurfaceMode mode;
|
|
|
|
ContentType contentType;
|
|
|
|
nsIntRegion neededRegion;
|
2011-09-28 23:19:26 -07:00
|
|
|
bool canReuseBuffer;
|
2011-03-31 14:33:46 -07:00
|
|
|
nsIntRect destBufferRect;
|
2011-01-17 23:22:25 -08:00
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
while (true) {
|
2011-03-31 14:33:46 -07:00
|
|
|
mode = mLayer->GetSurfaceMode();
|
|
|
|
contentType = aContentType;
|
|
|
|
neededRegion = mLayer->GetVisibleRegion();
|
|
|
|
// If we're going to resample, we need a buffer that's in clamp mode.
|
|
|
|
canReuseBuffer = neededRegion.GetBounds().Size() <= mBufferRect.Size() &&
|
|
|
|
mTexImage &&
|
|
|
|
(!(aFlags & PAINT_WILL_RESAMPLE) ||
|
|
|
|
mTexImage->GetWrapMode() == LOCAL_GL_CLAMP_TO_EDGE);
|
|
|
|
|
|
|
|
if (canReuseBuffer) {
|
|
|
|
if (mBufferRect.Contains(neededRegion.GetBounds())) {
|
|
|
|
// We don't need to adjust mBufferRect.
|
|
|
|
destBufferRect = mBufferRect;
|
|
|
|
} else {
|
|
|
|
// The buffer's big enough but doesn't contain everything that's
|
|
|
|
// going to be visible. We'll move it.
|
|
|
|
destBufferRect = nsIntRect(neededRegion.GetBounds().TopLeft(), mBufferRect.Size());
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
destBufferRect = neededRegion.GetBounds();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mode == Layer::SURFACE_COMPONENT_ALPHA) {
|
2011-01-17 23:22:25 -08:00
|
|
|
#ifdef MOZ_GFX_OPTIMIZE_MOBILE
|
|
|
|
mode = Layer::SURFACE_SINGLE_CHANNEL_ALPHA;
|
2011-03-31 14:33:46 -07:00
|
|
|
#else
|
|
|
|
if (!mLayer->GetParent() || !mLayer->GetParent()->SupportsComponentAlphaChildren()) {
|
|
|
|
mode = Layer::SURFACE_SINGLE_CHANNEL_ALPHA;
|
|
|
|
} else {
|
|
|
|
contentType = gfxASurface::CONTENT_COLOR;
|
|
|
|
}
|
|
|
|
#endif
|
2011-01-17 23:22:25 -08:00
|
|
|
}
|
2011-03-31 14:33:46 -07:00
|
|
|
|
|
|
|
if ((aFlags & PAINT_WILL_RESAMPLE) &&
|
2011-04-18 20:07:23 -07:00
|
|
|
(!neededRegion.GetBounds().IsEqualInterior(destBufferRect) ||
|
2011-03-31 14:33:46 -07:00
|
|
|
neededRegion.GetNumRects() > 1)) {
|
|
|
|
// The area we add to neededRegion might not be painted opaquely
|
|
|
|
if (mode == Layer::SURFACE_OPAQUE) {
|
|
|
|
contentType = gfxASurface::CONTENT_COLOR_ALPHA;
|
|
|
|
mode = Layer::SURFACE_SINGLE_CHANNEL_ALPHA;
|
|
|
|
}
|
|
|
|
// For component alpha layers, we leave contentType as CONTENT_COLOR.
|
2011-01-17 23:22:25 -08:00
|
|
|
|
2011-03-31 14:33:46 -07:00
|
|
|
// We need to validate the entire buffer, to make sure that only valid
|
|
|
|
// pixels are sampled
|
|
|
|
neededRegion = destBufferRect;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mTexImage &&
|
|
|
|
(mTexImage->GetContentType() != contentType ||
|
|
|
|
(mode == Layer::SURFACE_COMPONENT_ALPHA) != (mTexImageOnWhite != nsnull))) {
|
|
|
|
// We're effectively clearing the valid region, so we need to draw
|
|
|
|
// the entire needed region now.
|
|
|
|
result.mRegionToInvalidate = mLayer->GetValidRegion();
|
|
|
|
validRegion.SetEmpty();
|
|
|
|
mTexImage = nsnull;
|
|
|
|
mTexImageOnWhite = nsnull;
|
|
|
|
mBufferRect.SetRect(0, 0, 0, 0);
|
|
|
|
mBufferRotation.MoveTo(0, 0);
|
|
|
|
// Restart decision process with the cleared buffer. We can only go
|
|
|
|
// around the loop one more iteration, since mTexImage is null now.
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
2010-09-21 12:41:24 -07:00
|
|
|
}
|
2010-07-22 13:29:37 -07:00
|
|
|
|
2011-03-31 14:33:46 -07:00
|
|
|
result.mRegionToDraw.Sub(neededRegion, validRegion);
|
2010-09-21 12:41:24 -07:00
|
|
|
if (result.mRegionToDraw.IsEmpty())
|
|
|
|
return result;
|
|
|
|
|
2011-10-26 14:36:18 -07:00
|
|
|
if (destBufferRect.width > gl()->GetMaxTextureImageSize() ||
|
|
|
|
destBufferRect.height > gl()->GetMaxTextureImageSize()) {
|
2011-02-17 14:47:04 -08:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2011-03-31 14:33:46 -07:00
|
|
|
nsIntRect drawBounds = result.mRegionToDraw.GetBounds();
|
2010-09-21 12:41:24 -07:00
|
|
|
nsRefPtr<TextureImage> destBuffer;
|
2011-01-17 23:22:25 -08:00
|
|
|
nsRefPtr<TextureImage> destBufferOnWhite;
|
2010-09-21 12:41:24 -07:00
|
|
|
|
2011-03-31 14:33:46 -07:00
|
|
|
PRUint32 bufferFlags = canHaveRotation ? ALLOW_REPEAT : 0;
|
|
|
|
if (canReuseBuffer) {
|
2010-09-21 12:41:24 -07:00
|
|
|
nsIntRect keepArea;
|
|
|
|
if (keepArea.IntersectRect(destBufferRect, mBufferRect)) {
|
|
|
|
// Set mBufferRotation so that the pixels currently in mBuffer
|
|
|
|
// will still be rendered in the right place when mBufferRect
|
|
|
|
// changes to destBufferRect.
|
|
|
|
nsIntPoint newRotation = mBufferRotation +
|
|
|
|
(destBufferRect.TopLeft() - mBufferRect.TopLeft());
|
|
|
|
WrapRotationAxis(&newRotation.x, mBufferRect.width);
|
|
|
|
WrapRotationAxis(&newRotation.y, mBufferRect.height);
|
|
|
|
NS_ASSERTION(nsIntRect(nsIntPoint(0,0), mBufferRect.Size()).Contains(newRotation),
|
|
|
|
"newRotation out of bounds");
|
|
|
|
PRInt32 xBoundary = destBufferRect.XMost() - newRotation.x;
|
|
|
|
PRInt32 yBoundary = destBufferRect.YMost() - newRotation.y;
|
|
|
|
if ((drawBounds.x < xBoundary && xBoundary < drawBounds.XMost()) ||
|
2011-03-31 14:33:46 -07:00
|
|
|
(drawBounds.y < yBoundary && yBoundary < drawBounds.YMost()) ||
|
|
|
|
(newRotation != nsIntPoint(0,0) && !canHaveRotation)) {
|
2010-09-21 12:41:24 -07:00
|
|
|
// The stuff we need to redraw will wrap around an edge of the
|
|
|
|
// buffer, so we will need to do a self-copy
|
|
|
|
// If mBufferRotation == nsIntPoint(0,0) we could do a real
|
|
|
|
// self-copy but we're not going to do that in GL yet.
|
|
|
|
// We can't do a real self-copy because the buffer is rotated.
|
|
|
|
// So allocate a new buffer for the destination.
|
2011-04-06 16:38:01 -07:00
|
|
|
destBufferRect = neededRegion.GetBounds();
|
2011-06-22 05:11:28 -07:00
|
|
|
destBuffer = CreateClampOrRepeatTextureImage(gl(), destBufferRect.Size(), contentType, bufferFlags);
|
2010-09-21 12:41:24 -07:00
|
|
|
if (!destBuffer)
|
|
|
|
return result;
|
2011-01-17 23:22:25 -08:00
|
|
|
if (mode == Layer::SURFACE_COMPONENT_ALPHA) {
|
2011-02-08 12:37:47 -08:00
|
|
|
destBufferOnWhite =
|
2011-06-22 05:11:28 -07:00
|
|
|
CreateClampOrRepeatTextureImage(gl(), destBufferRect.Size(), contentType, bufferFlags);
|
2011-01-17 23:22:25 -08:00
|
|
|
if (!destBufferOnWhite)
|
|
|
|
return result;
|
|
|
|
}
|
2010-09-21 12:41:24 -07:00
|
|
|
} else {
|
|
|
|
mBufferRect = destBufferRect;
|
|
|
|
mBufferRotation = newRotation;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// No pixels are going to be kept. The whole visible region
|
|
|
|
// will be redrawn, so we don't need to copy anything, so we don't
|
|
|
|
// set destBuffer.
|
|
|
|
mBufferRect = destBufferRect;
|
|
|
|
mBufferRotation = nsIntPoint(0,0);
|
2010-07-22 13:29:37 -07:00
|
|
|
}
|
|
|
|
} else {
|
2010-09-21 12:41:24 -07:00
|
|
|
// The buffer's not big enough, so allocate a new one
|
2011-06-22 05:11:28 -07:00
|
|
|
destBuffer = CreateClampOrRepeatTextureImage(gl(), destBufferRect.Size(), contentType, bufferFlags);
|
2010-09-21 12:41:24 -07:00
|
|
|
if (!destBuffer)
|
|
|
|
return result;
|
2011-01-17 23:22:25 -08:00
|
|
|
|
|
|
|
if (mode == Layer::SURFACE_COMPONENT_ALPHA) {
|
|
|
|
destBufferOnWhite =
|
2011-06-22 05:11:28 -07:00
|
|
|
CreateClampOrRepeatTextureImage(gl(), destBufferRect.Size(), contentType, bufferFlags);
|
2011-01-17 23:22:25 -08:00
|
|
|
if (!destBufferOnWhite)
|
|
|
|
return result;
|
|
|
|
}
|
2010-07-22 13:29:37 -07:00
|
|
|
}
|
2011-03-31 14:33:46 -07:00
|
|
|
NS_ASSERTION(!(aFlags & PAINT_WILL_RESAMPLE) || destBufferRect == neededRegion.GetBounds(),
|
|
|
|
"If we're resampling, we need to validate the entire buffer");
|
2010-09-21 12:41:24 -07:00
|
|
|
|
|
|
|
if (!destBuffer && !mTexImage) {
|
|
|
|
return result;
|
2010-07-22 13:29:37 -07:00
|
|
|
}
|
|
|
|
|
2010-09-21 12:41:24 -07:00
|
|
|
if (destBuffer) {
|
2011-01-17 23:22:25 -08:00
|
|
|
if (mTexImage && (mode != Layer::SURFACE_COMPONENT_ALPHA || mTexImageOnWhite)) {
|
2010-10-01 20:56:56 -07:00
|
|
|
// BlitTextureImage depends on the FBO texture target being
|
|
|
|
// TEXTURE_2D. This isn't the case on some older X1600-era Radeons.
|
2010-10-13 15:55:45 -07:00
|
|
|
if (mOGLLayer->OGLManager()->FBOTextureTarget() == LOCAL_GL_TEXTURE_2D) {
|
2010-10-01 20:56:56 -07:00
|
|
|
nsIntRect overlap;
|
|
|
|
overlap.IntersectRect(mBufferRect, destBufferRect);
|
2010-09-21 12:41:24 -07:00
|
|
|
|
2010-10-01 20:56:56 -07:00
|
|
|
nsIntRect srcRect(overlap), dstRect(overlap);
|
|
|
|
srcRect.MoveBy(- mBufferRect.TopLeft() + mBufferRotation);
|
|
|
|
dstRect.MoveBy(- destBufferRect.TopLeft());
|
2010-07-22 13:29:37 -07:00
|
|
|
|
2011-06-22 05:11:28 -07:00
|
|
|
destBuffer->Resize(destBufferRect.Size());
|
2010-09-21 12:41:24 -07:00
|
|
|
|
2010-10-01 20:56:56 -07:00
|
|
|
gl()->BlitTextureImage(mTexImage, srcRect,
|
|
|
|
destBuffer, dstRect);
|
2011-01-17 23:22:25 -08:00
|
|
|
if (mode == Layer::SURFACE_COMPONENT_ALPHA) {
|
2011-06-22 05:11:28 -07:00
|
|
|
destBufferOnWhite->Resize(destBufferRect.Size());
|
2011-01-17 23:22:25 -08:00
|
|
|
gl()->BlitTextureImage(mTexImageOnWhite, srcRect,
|
|
|
|
destBufferOnWhite, dstRect);
|
|
|
|
}
|
2010-10-01 20:56:56 -07:00
|
|
|
} else {
|
|
|
|
// can't blit, just draw everything
|
2011-06-22 05:11:28 -07:00
|
|
|
destBuffer = CreateClampOrRepeatTextureImage(gl(), destBufferRect.Size(), contentType, bufferFlags);
|
2011-01-17 23:22:25 -08:00
|
|
|
if (mode == Layer::SURFACE_COMPONENT_ALPHA) {
|
|
|
|
destBufferOnWhite =
|
2011-06-22 05:11:28 -07:00
|
|
|
CreateClampOrRepeatTextureImage(gl(), destBufferRect.Size(), contentType, bufferFlags);
|
2011-01-17 23:22:25 -08:00
|
|
|
}
|
2010-10-01 20:56:56 -07:00
|
|
|
}
|
2010-09-21 12:41:24 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
mTexImage = destBuffer.forget();
|
2011-01-17 23:22:25 -08:00
|
|
|
if (mode == Layer::SURFACE_COMPONENT_ALPHA) {
|
|
|
|
mTexImageOnWhite = destBufferOnWhite.forget();
|
|
|
|
}
|
2010-09-21 12:41:24 -07:00
|
|
|
mBufferRect = destBufferRect;
|
|
|
|
mBufferRotation = nsIntPoint(0,0);
|
|
|
|
}
|
2011-03-31 14:33:46 -07:00
|
|
|
NS_ASSERTION(canHaveRotation || mBufferRotation == nsIntPoint(0,0),
|
|
|
|
"Rotation disabled, but we have nonzero rotation?");
|
2010-09-21 12:41:24 -07:00
|
|
|
|
|
|
|
nsIntRegion invalidate;
|
|
|
|
invalidate.Sub(mLayer->GetValidRegion(), destBufferRect);
|
|
|
|
result.mRegionToInvalidate.Or(result.mRegionToInvalidate, invalidate);
|
|
|
|
|
|
|
|
// Figure out which quadrant to draw in
|
|
|
|
PRInt32 xBoundary = mBufferRect.XMost() - mBufferRotation.x;
|
|
|
|
PRInt32 yBoundary = mBufferRect.YMost() - mBufferRotation.y;
|
|
|
|
XSide sideX = drawBounds.XMost() <= xBoundary ? RIGHT : LEFT;
|
|
|
|
YSide sideY = drawBounds.YMost() <= yBoundary ? BOTTOM : TOP;
|
|
|
|
nsIntRect quadrantRect = GetQuadrantRectangle(sideX, sideY);
|
|
|
|
NS_ASSERTION(quadrantRect.Contains(drawBounds), "Messed up quadrants");
|
|
|
|
|
|
|
|
nsIntPoint offset = -nsIntPoint(quadrantRect.x, quadrantRect.y);
|
2011-02-08 12:37:47 -08:00
|
|
|
|
2010-09-21 12:41:24 -07:00
|
|
|
// Make the region to draw relative to the buffer, before
|
|
|
|
// passing to BeginUpdate.
|
|
|
|
result.mRegionToDraw.MoveBy(offset);
|
2010-07-22 13:29:37 -07:00
|
|
|
// BeginUpdate is allowed to modify the given region,
|
|
|
|
// if it wants more to be repainted than we request.
|
2011-01-17 23:22:25 -08:00
|
|
|
if (mode == Layer::SURFACE_COMPONENT_ALPHA) {
|
|
|
|
nsIntRegion drawRegionCopy = result.mRegionToDraw;
|
|
|
|
gfxASurface *onBlack = mTexImage->BeginUpdate(drawRegionCopy);
|
|
|
|
gfxASurface *onWhite = mTexImageOnWhite->BeginUpdate(result.mRegionToDraw);
|
|
|
|
NS_ASSERTION(result.mRegionToDraw == drawRegionCopy,
|
|
|
|
"BeginUpdate should always modify the draw region in the same way!");
|
2011-02-17 14:47:04 -08:00
|
|
|
FillSurface(onBlack, result.mRegionToDraw, nsIntPoint(0,0), gfxRGBA(0.0, 0.0, 0.0, 1.0));
|
|
|
|
FillSurface(onWhite, result.mRegionToDraw, nsIntPoint(0,0), gfxRGBA(1.0, 1.0, 1.0, 1.0));
|
2011-01-17 23:22:25 -08:00
|
|
|
gfxASurface* surfaces[2] = { onBlack, onWhite };
|
2011-10-10 22:50:08 -07:00
|
|
|
nsRefPtr<gfxTeeSurface> surf = new gfxTeeSurface(surfaces, ArrayLength(surfaces));
|
2011-01-17 23:22:25 -08:00
|
|
|
|
|
|
|
// XXX If the device offset is set on the individual surfaces instead of on
|
|
|
|
// the tee surface, we render in the wrong place. Why?
|
|
|
|
gfxPoint deviceOffset = onBlack->GetDeviceOffset();
|
|
|
|
onBlack->SetDeviceOffset(gfxPoint(0, 0));
|
|
|
|
onWhite->SetDeviceOffset(gfxPoint(0, 0));
|
|
|
|
surf->SetDeviceOffset(deviceOffset);
|
|
|
|
|
|
|
|
// Using this surface as a source will likely go horribly wrong, since
|
|
|
|
// only the onBlack surface will really be used, so alpha information will
|
|
|
|
// be incorrect.
|
2011-10-17 07:59:28 -07:00
|
|
|
surf->SetAllowUseAsSource(false);
|
2011-01-17 23:22:25 -08:00
|
|
|
result.mContext = new gfxContext(surf);
|
|
|
|
} else {
|
|
|
|
result.mContext = new gfxContext(mTexImage->BeginUpdate(result.mRegionToDraw));
|
2011-01-24 11:31:35 -08:00
|
|
|
if (mTexImage->GetContentType() == gfxASurface::CONTENT_COLOR_ALPHA) {
|
|
|
|
gfxUtils::ClipToRegion(result.mContext, result.mRegionToDraw);
|
|
|
|
result.mContext->SetOperator(gfxContext::OPERATOR_CLEAR);
|
2011-03-31 14:33:46 -07:00
|
|
|
result.mContext->Paint();
|
2011-01-24 11:31:35 -08:00
|
|
|
result.mContext->SetOperator(gfxContext::OPERATOR_OVER);
|
|
|
|
}
|
2011-01-17 23:22:25 -08:00
|
|
|
}
|
2010-09-21 12:41:24 -07:00
|
|
|
if (!result.mContext) {
|
2010-07-22 13:29:37 -07:00
|
|
|
NS_WARNING("unable to get context for update");
|
2010-09-21 12:41:24 -07:00
|
|
|
return result;
|
2010-07-22 13:29:37 -07:00
|
|
|
}
|
2011-01-17 13:47:18 -08:00
|
|
|
result.mContext->Translate(-gfxPoint(quadrantRect.x, quadrantRect.y));
|
2010-07-22 13:29:37 -07:00
|
|
|
// Move rgnToPaint back into position so that the thebes callback
|
|
|
|
// gets the right coordintes.
|
2010-09-21 12:41:24 -07:00
|
|
|
result.mRegionToDraw.MoveBy(-offset);
|
2011-08-09 08:38:05 -07:00
|
|
|
|
|
|
|
// If we do partial updates, we have to clip drawing to the regionToDraw.
|
|
|
|
// If we don't clip, background images will be fillrect'd to the region correctly,
|
|
|
|
// while text or lines will paint outside of the regionToDraw. This becomes apparent
|
|
|
|
// with concave regions. Right now the scrollbars invalidate a narrow strip of the awesomebar
|
|
|
|
// although they never cover it. This leads to two draw rects, the narow strip and the actually
|
|
|
|
// newly exposed area. It would be wise to fix this glitch in any way to have simpler
|
|
|
|
// clip and draw regions.
|
|
|
|
gfxUtils::ClipToRegion(result.mContext, result.mRegionToDraw);
|
|
|
|
|
2010-09-21 12:41:24 -07:00
|
|
|
return result;
|
2010-07-22 13:29:37 -07:00
|
|
|
}
|
|
|
|
|
2010-04-26 19:09:47 -07:00
|
|
|
ThebesLayerOGL::ThebesLayerOGL(LayerManagerOGL *aManager)
|
2010-07-01 09:30:38 -07:00
|
|
|
: ThebesLayer(aManager, nsnull)
|
2010-04-26 19:09:47 -07:00
|
|
|
, LayerOGL(aManager)
|
2010-07-22 13:29:37 -07:00
|
|
|
, mBuffer(nsnull)
|
2010-03-29 21:48:52 -07:00
|
|
|
{
|
|
|
|
mImplData = static_cast<LayerOGL*>(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
ThebesLayerOGL::~ThebesLayerOGL()
|
|
|
|
{
|
2010-08-06 22:09:18 -07:00
|
|
|
Destroy();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ThebesLayerOGL::Destroy()
|
|
|
|
{
|
|
|
|
if (!mDestroyed) {
|
|
|
|
mBuffer = nsnull;
|
2011-10-17 07:59:28 -07:00
|
|
|
mDestroyed = true;
|
2010-08-06 22:09:18 -07:00
|
|
|
}
|
2010-03-29 21:48:52 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2010-07-22 13:29:37 -07:00
|
|
|
ThebesLayerOGL::CreateSurface()
|
2010-03-29 21:48:52 -07:00
|
|
|
{
|
2010-07-22 13:29:37 -07:00
|
|
|
NS_ASSERTION(!mBuffer, "buffer already created?");
|
|
|
|
|
|
|
|
if (mVisibleRegion.IsEmpty()) {
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2010-07-22 13:29:37 -07:00
|
|
|
}
|
|
|
|
|
2010-09-21 12:41:24 -07:00
|
|
|
if (gl()->TextureImageSupportsGetBackingSurface()) {
|
2010-07-22 13:29:37 -07:00
|
|
|
// use the ThebesLayerBuffer fast-path
|
2010-09-21 12:41:24 -07:00
|
|
|
mBuffer = new SurfaceBufferOGL(this);
|
2010-07-22 13:29:37 -07:00
|
|
|
} else {
|
2010-09-21 12:41:24 -07:00
|
|
|
mBuffer = new BasicBufferOGL(this);
|
2010-07-01 09:30:38 -07:00
|
|
|
}
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2010-06-23 07:01:29 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ThebesLayerOGL::SetVisibleRegion(const nsIntRegion &aRegion)
|
|
|
|
{
|
|
|
|
if (aRegion.IsEqual(mVisibleRegion))
|
|
|
|
return;
|
|
|
|
ThebesLayer::SetVisibleRegion(aRegion);
|
2010-03-29 21:48:52 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ThebesLayerOGL::InvalidateRegion(const nsIntRegion &aRegion)
|
|
|
|
{
|
2010-07-01 09:30:38 -07:00
|
|
|
mValidRegion.Sub(mValidRegion, aRegion);
|
2010-03-29 21:48:52 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-08-20 12:07:06 -07:00
|
|
|
ThebesLayerOGL::RenderLayer(int aPreviousFrameBuffer,
|
|
|
|
const nsIntPoint& aOffset)
|
2010-03-29 21:48:52 -07:00
|
|
|
{
|
2010-07-22 13:29:37 -07:00
|
|
|
if (!mBuffer && !CreateSurface()) {
|
2010-06-23 07:01:29 -07:00
|
|
|
return;
|
2010-07-22 13:29:37 -07:00
|
|
|
}
|
|
|
|
NS_ABORT_IF_FALSE(mBuffer, "should have a buffer here");
|
2010-06-23 07:01:29 -07:00
|
|
|
|
2011-08-20 12:07:06 -07:00
|
|
|
mOGLManager->MakeCurrent();
|
|
|
|
gl()->fActiveTexture(LOCAL_GL_TEXTURE0);
|
|
|
|
|
2010-07-22 13:29:37 -07:00
|
|
|
TextureImage::ContentType contentType =
|
2010-07-29 12:15:13 -07:00
|
|
|
CanUseOpaqueSurface() ? gfxASurface::CONTENT_COLOR :
|
2010-07-22 13:29:37 -07:00
|
|
|
gfxASurface::CONTENT_COLOR_ALPHA;
|
2011-02-08 12:37:47 -08:00
|
|
|
|
2011-03-31 14:33:46 -07:00
|
|
|
PRUint32 flags = 0;
|
2011-08-29 10:56:50 -07:00
|
|
|
#ifndef MOZ_GFX_OPTIMIZE_MOBILE
|
|
|
|
gfxMatrix transform2d;
|
2011-08-20 12:07:06 -07:00
|
|
|
if (GetEffectiveTransform().Is2D(&transform2d)) {
|
|
|
|
if (transform2d.HasNonIntegerTranslation()) {
|
|
|
|
flags |= ThebesLayerBufferOGL::PAINT_WILL_RESAMPLE;
|
|
|
|
}
|
|
|
|
} else {
|
2011-03-31 14:33:46 -07:00
|
|
|
flags |= ThebesLayerBufferOGL::PAINT_WILL_RESAMPLE;
|
2011-02-08 12:37:47 -08:00
|
|
|
}
|
2011-08-29 10:56:50 -07:00
|
|
|
#endif
|
2011-02-08 12:37:47 -08:00
|
|
|
|
2011-06-22 05:11:28 -07:00
|
|
|
Buffer::PaintState state = mBuffer->BeginPaint(contentType, flags);
|
2010-07-22 13:29:37 -07:00
|
|
|
mValidRegion.Sub(mValidRegion, state.mRegionToInvalidate);
|
2010-05-20 20:20:48 -07:00
|
|
|
|
2010-07-22 13:29:37 -07:00
|
|
|
if (state.mContext) {
|
|
|
|
state.mRegionToInvalidate.And(state.mRegionToInvalidate, mVisibleRegion);
|
2010-05-24 23:35:35 -07:00
|
|
|
|
2010-07-22 13:29:37 -07:00
|
|
|
LayerManager::DrawThebesLayerCallback callback =
|
|
|
|
mOGLManager->GetThebesLayerCallback();
|
2011-01-25 00:45:17 -08:00
|
|
|
if (!callback) {
|
|
|
|
NS_ERROR("GL should never need to update ThebesLayers in an empty transaction");
|
|
|
|
} else {
|
|
|
|
void* callbackData = mOGLManager->GetThebesLayerCallbackData();
|
2011-02-26 04:40:47 -08:00
|
|
|
SetAntialiasingFlags(this, state.mContext);
|
2011-01-25 00:45:17 -08:00
|
|
|
callback(this, state.mContext, state.mRegionToDraw,
|
|
|
|
state.mRegionToInvalidate, callbackData);
|
2011-03-01 12:30:16 -08:00
|
|
|
// Everything that's visible has been validated. Do this instead of just
|
2011-01-25 00:45:17 -08:00
|
|
|
// OR-ing with aRegionToDraw, since that can lead to a very complex region
|
|
|
|
// here (OR doesn't automatically simplify to the simplest possible
|
|
|
|
// representation of a region.)
|
2011-03-01 12:30:16 -08:00
|
|
|
nsIntRegion tmp;
|
|
|
|
tmp.Or(mVisibleRegion, state.mRegionToDraw);
|
|
|
|
mValidRegion.Or(mValidRegion, tmp);
|
2011-01-25 00:45:17 -08:00
|
|
|
}
|
2010-05-20 20:20:48 -07:00
|
|
|
}
|
|
|
|
|
2011-08-20 12:07:06 -07:00
|
|
|
// Drawing thebes layers can change the current context, reset it.
|
2011-02-23 12:31:49 -08:00
|
|
|
gl()->MakeCurrent();
|
|
|
|
|
2010-09-21 12:41:24 -07:00
|
|
|
gl()->fBindFramebuffer(LOCAL_GL_FRAMEBUFFER, aPreviousFrameBuffer);
|
2011-03-31 14:33:46 -07:00
|
|
|
mBuffer->RenderTo(aOffset, mOGLManager, flags);
|
2010-03-29 21:48:52 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
Layer*
|
|
|
|
ThebesLayerOGL::GetLayer()
|
|
|
|
{
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2010-03-29 21:48:52 -07:00
|
|
|
ThebesLayerOGL::IsEmpty()
|
|
|
|
{
|
2010-07-22 13:29:37 -07:00
|
|
|
return !mBuffer;
|
2010-03-29 21:48:52 -07:00
|
|
|
}
|
|
|
|
|
2012-01-15 21:41:55 -08:00
|
|
|
void
|
|
|
|
ThebesLayerOGL::CleanupResources()
|
|
|
|
{
|
|
|
|
mBuffer = nsnull;
|
|
|
|
}
|
2010-10-13 15:55:45 -07:00
|
|
|
|
|
|
|
class ShadowBufferOGL : public ThebesLayerBufferOGL
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
ShadowBufferOGL(ShadowThebesLayerOGL* aLayer)
|
|
|
|
: ThebesLayerBufferOGL(aLayer, aLayer)
|
|
|
|
{}
|
|
|
|
|
2011-06-22 05:11:28 -07:00
|
|
|
virtual PaintState BeginPaint(ContentType aContentType, PRUint32) {
|
2010-10-13 15:55:45 -07:00
|
|
|
NS_RUNTIMEABORT("can't BeginPaint for a shadow layer");
|
|
|
|
return PaintState();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Upload(gfxASurface* aUpdate, const nsIntRegion& aUpdated,
|
|
|
|
const nsIntRect& aRect, const nsIntPoint& aRotation);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual nsIntPoint GetOriginOffset() {
|
|
|
|
return mBufferRect.TopLeft() - mBufferRotation;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
nsIntRect mBufferRect;
|
|
|
|
nsIntPoint mBufferRotation;
|
|
|
|
};
|
|
|
|
|
|
|
|
void
|
|
|
|
ShadowBufferOGL::Upload(gfxASurface* aUpdate, const nsIntRegion& aUpdated,
|
|
|
|
const nsIntRect& aRect, const nsIntPoint& aRotation)
|
|
|
|
{
|
2010-12-30 23:40:31 -08:00
|
|
|
gfxIntSize size = aUpdate->GetSize();
|
2011-10-15 13:07:10 -07:00
|
|
|
if (!mTexImage ||
|
|
|
|
GetSize() != nsIntSize(size.width, size.height) ||
|
|
|
|
mTexImage->GetContentType() != aUpdate->GetContentType()) {
|
2011-03-31 14:33:46 -07:00
|
|
|
// XXX we should do something here to decide whether to use REPEAT or not,
|
|
|
|
// but I'm not sure what
|
|
|
|
mTexImage = CreateClampOrRepeatTextureImage(gl(),
|
|
|
|
nsIntSize(size.width, size.height), aUpdate->GetContentType(), ALLOW_REPEAT);
|
2010-12-30 23:40:31 -08:00
|
|
|
}
|
|
|
|
|
2010-10-13 15:55:45 -07:00
|
|
|
nsIntRegion destRegion(aUpdated);
|
|
|
|
// aUpdated is in screen coordinates. Move it so that the layer's
|
|
|
|
// top-left is 0,0
|
|
|
|
nsIntPoint visTopLeft = mLayer->GetVisibleRegion().GetBounds().TopLeft();
|
|
|
|
destRegion.MoveBy(-visTopLeft);
|
2010-12-09 14:26:13 -08:00
|
|
|
|
2011-08-24 07:10:03 -07:00
|
|
|
// Correct for rotation
|
|
|
|
destRegion.MoveBy(aRotation);
|
|
|
|
nsIntRect destBounds = destRegion.GetBounds();
|
|
|
|
destRegion.MoveBy((destBounds.x >= size.width) ? -size.width : 0,
|
|
|
|
(destBounds.y >= size.height) ? -size.height : 0);
|
|
|
|
|
|
|
|
// There's code to make sure that updated regions don't cross rotation
|
|
|
|
// boundaries, so assert here that this is the case
|
|
|
|
NS_ASSERTION(((destBounds.x % size.width) + destBounds.width <= size.width) &&
|
|
|
|
((destBounds.y % size.height) + destBounds.height <= size.height),
|
|
|
|
"Updated region lies across rotation boundaries!");
|
|
|
|
|
2010-10-13 15:55:45 -07:00
|
|
|
// NB: this gfxContext must not escape EndUpdate() below
|
2011-06-22 05:11:28 -07:00
|
|
|
mTexImage->DirectUpdate(aUpdate, destRegion);
|
2010-10-13 15:55:45 -07:00
|
|
|
|
|
|
|
mBufferRect = aRect;
|
|
|
|
mBufferRotation = aRotation;
|
|
|
|
}
|
|
|
|
|
|
|
|
ShadowThebesLayerOGL::ShadowThebesLayerOGL(LayerManagerOGL *aManager)
|
|
|
|
: ShadowThebesLayer(aManager, nsnull)
|
|
|
|
, LayerOGL(aManager)
|
|
|
|
{
|
|
|
|
mImplData = static_cast<LayerOGL*>(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
ShadowThebesLayerOGL::~ShadowThebesLayerOGL()
|
|
|
|
{}
|
|
|
|
|
|
|
|
void
|
|
|
|
ShadowThebesLayerOGL::Swap(const ThebesBuffer& aNewFront,
|
|
|
|
const nsIntRegion& aUpdatedRegion,
|
2011-10-02 14:19:32 -07:00
|
|
|
OptionalThebesBuffer* aNewBack,
|
2010-10-13 15:55:45 -07:00
|
|
|
nsIntRegion* aNewBackValidRegion,
|
2010-11-05 00:17:07 -07:00
|
|
|
OptionalThebesBuffer* aReadOnlyFront,
|
|
|
|
nsIntRegion* aFrontUpdatedRegion)
|
2010-10-13 15:55:45 -07:00
|
|
|
{
|
2011-10-02 14:19:32 -07:00
|
|
|
if (!mDestroyed) {
|
|
|
|
if (!mBuffer) {
|
|
|
|
mBuffer = new ShadowBufferOGL(this);
|
|
|
|
}
|
2010-10-13 15:55:45 -07:00
|
|
|
nsRefPtr<gfxASurface> surf = ShadowLayerForwarder::OpenDescriptor(aNewFront.buffer());
|
|
|
|
mBuffer->Upload(surf, aUpdatedRegion, aNewFront.rect(), aNewFront.rotation());
|
|
|
|
}
|
|
|
|
|
|
|
|
*aNewBack = aNewFront;
|
|
|
|
*aNewBackValidRegion = mValidRegion;
|
2010-11-05 00:17:07 -07:00
|
|
|
*aReadOnlyFront = null_t();
|
|
|
|
aFrontUpdatedRegion->SetEmpty();
|
2010-10-13 15:55:45 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ShadowThebesLayerOGL::DestroyFrontBuffer()
|
|
|
|
{
|
|
|
|
mBuffer = nsnull;
|
|
|
|
}
|
|
|
|
|
2011-01-05 20:54:47 -08:00
|
|
|
void
|
|
|
|
ShadowThebesLayerOGL::Disconnect()
|
|
|
|
{
|
|
|
|
Destroy();
|
|
|
|
}
|
|
|
|
|
2010-10-13 15:55:45 -07:00
|
|
|
void
|
|
|
|
ShadowThebesLayerOGL::Destroy()
|
|
|
|
{
|
|
|
|
if (!mDestroyed) {
|
2011-10-17 07:59:28 -07:00
|
|
|
mDestroyed = true;
|
2010-10-13 15:55:45 -07:00
|
|
|
mBuffer = nsnull;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Layer*
|
|
|
|
ShadowThebesLayerOGL::GetLayer()
|
|
|
|
{
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2010-10-13 15:55:45 -07:00
|
|
|
ShadowThebesLayerOGL::IsEmpty()
|
|
|
|
{
|
|
|
|
return !mBuffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ShadowThebesLayerOGL::RenderLayer(int aPreviousFrameBuffer,
|
2010-11-08 01:06:15 -08:00
|
|
|
const nsIntPoint& aOffset)
|
2010-10-13 15:55:45 -07:00
|
|
|
{
|
|
|
|
if (!mBuffer) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
NS_ABORT_IF_FALSE(mBuffer, "should have a buffer here");
|
|
|
|
|
|
|
|
mOGLManager->MakeCurrent();
|
|
|
|
gl()->fActiveTexture(LOCAL_GL_TEXTURE0);
|
|
|
|
|
|
|
|
gl()->fBindFramebuffer(LOCAL_GL_FRAMEBUFFER, aPreviousFrameBuffer);
|
2011-03-31 14:33:46 -07:00
|
|
|
mBuffer->RenderTo(aOffset, mOGLManager, 0);
|
2010-10-13 15:55:45 -07:00
|
|
|
}
|
|
|
|
|
2012-01-15 21:41:55 -08:00
|
|
|
void
|
|
|
|
ShadowThebesLayerOGL::CleanupResources()
|
|
|
|
{
|
|
|
|
DestroyFrontBuffer();
|
|
|
|
}
|
|
|
|
|
2010-03-29 21:48:52 -07:00
|
|
|
} /* layers */
|
|
|
|
} /* mozilla */
|