2010-05-17 21:04:22 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
2012-05-21 04:12:37 -07:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2010-03-29 21:48:52 -07:00
|
|
|
|
|
|
|
#ifndef GFX_LAYERMANAGEROGL_H
|
|
|
|
#define GFX_LAYERMANAGEROGL_H
|
|
|
|
|
2012-03-18 13:07:25 -07:00
|
|
|
#include "LayerManagerOGLProgram.h"
|
2010-03-29 21:48:52 -07:00
|
|
|
|
2010-10-13 15:55:45 -07:00
|
|
|
#include "mozilla/layers/ShadowLayers.h"
|
2011-05-10 18:45:42 -07:00
|
|
|
#include "mozilla/TimeStamp.h"
|
2013-01-10 02:51:43 -08:00
|
|
|
#include "nsPoint.h"
|
2011-05-10 18:45:42 -07:00
|
|
|
|
2010-03-29 21:48:52 -07:00
|
|
|
#ifdef XP_WIN
|
|
|
|
#include <windows.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define BUFFER_OFFSET(i) ((char *)NULL + (i))
|
|
|
|
|
|
|
|
#include "gfxContext.h"
|
2010-05-24 23:35:35 -07:00
|
|
|
#include "gfx3DMatrix.h"
|
2010-03-29 21:48:52 -07:00
|
|
|
#include "nsIWidget.h"
|
2012-11-26 14:23:27 -08:00
|
|
|
#include "GLContextTypes.h"
|
2010-03-29 21:48:52 -07:00
|
|
|
|
|
|
|
namespace mozilla {
|
2012-11-26 14:23:27 -08:00
|
|
|
namespace gl {
|
|
|
|
class GLContext;
|
|
|
|
}
|
2010-03-29 21:48:52 -07:00
|
|
|
namespace layers {
|
|
|
|
|
2012-11-19 09:58:38 -08:00
|
|
|
class Composer2D;
|
2010-03-29 21:48:52 -07:00
|
|
|
class LayerOGL;
|
2010-10-13 16:36:44 -07:00
|
|
|
class ShadowThebesLayer;
|
|
|
|
class ShadowContainerLayer;
|
|
|
|
class ShadowImageLayer;
|
|
|
|
class ShadowCanvasLayer;
|
|
|
|
class ShadowColorLayer;
|
2012-09-04 22:17:13 -07:00
|
|
|
struct FPSState;
|
2010-03-29 21:48:52 -07:00
|
|
|
|
|
|
|
/**
|
2012-03-17 09:44:45 -07:00
|
|
|
* This is the LayerManager used for OpenGL 2.1 and OpenGL ES 2.0.
|
|
|
|
* This can be used either on the main thread or the compositor.
|
2010-03-29 21:48:52 -07:00
|
|
|
*/
|
2010-10-13 15:55:45 -07:00
|
|
|
class THEBES_API LayerManagerOGL :
|
|
|
|
public ShadowLayerManager
|
|
|
|
{
|
2010-06-25 17:52:37 -07:00
|
|
|
typedef mozilla::gl::GLContext GLContext;
|
2010-12-16 23:23:07 -08:00
|
|
|
typedef mozilla::gl::ShaderProgramType ProgramType;
|
2010-06-25 17:52:37 -07:00
|
|
|
|
2010-03-29 21:48:52 -07:00
|
|
|
public:
|
2012-04-20 08:46:30 -07:00
|
|
|
LayerManagerOGL(nsIWidget *aWidget, int aSurfaceWidth = -1, int aSurfaceHeight = -1,
|
|
|
|
bool aIsRenderingToEGLSurface = false);
|
2010-03-29 21:48:52 -07:00
|
|
|
virtual ~LayerManagerOGL();
|
2010-07-18 22:01:14 -07:00
|
|
|
|
2010-08-06 22:09:18 -07:00
|
|
|
void Destroy();
|
|
|
|
|
2011-01-18 12:11:18 -08:00
|
|
|
|
2010-03-29 21:48:52 -07:00
|
|
|
/**
|
2011-01-18 12:11:18 -08:00
|
|
|
* Initializes the layer manager with a given GLContext. If aContext is null
|
|
|
|
* then the layer manager will try to create one for the associated widget.
|
2010-03-29 21:48:52 -07:00
|
|
|
*
|
2011-01-18 12:11:18 -08:00
|
|
|
* \param aContext an existing GL context to use. Can be created with CreateContext()
|
2010-06-25 17:52:37 -07:00
|
|
|
*
|
2010-03-29 21:48:52 -07:00
|
|
|
* \return True is initialization was succesful, false when it was not.
|
|
|
|
*/
|
2012-11-26 14:23:27 -08:00
|
|
|
bool Initialize(bool force = false);
|
2011-01-18 12:11:18 -08:00
|
|
|
|
2012-02-27 13:33:19 -08:00
|
|
|
bool Initialize(nsRefPtr<GLContext> aContext, bool force = false);
|
2010-03-29 21:48:52 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the clipping region for this layer manager. This is important on
|
|
|
|
* windows because using OGL we no longer have GDI's native clipping. Therefor
|
|
|
|
* widget must tell us what part of the screen is being invalidated,
|
|
|
|
* and we should clip to this.
|
|
|
|
*
|
|
|
|
* \param aClippingRegion Region to clip to. Setting an empty region
|
|
|
|
* will disable clipping.
|
|
|
|
*/
|
|
|
|
void SetClippingRegion(const nsIntRegion& aClippingRegion);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* LayerManager implementation.
|
|
|
|
*/
|
2011-08-09 12:38:26 -07:00
|
|
|
virtual ShadowLayerManager* AsShadowManager()
|
|
|
|
{
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2010-03-29 21:48:52 -07:00
|
|
|
void BeginTransaction();
|
|
|
|
|
|
|
|
void BeginTransactionWithTarget(gfxContext* aTarget);
|
|
|
|
|
|
|
|
void EndConstruction();
|
|
|
|
|
2012-08-13 03:10:10 -07:00
|
|
|
virtual bool EndEmptyTransaction(EndTransactionFlags aFlags = END_DEFAULT);
|
2012-08-06 19:41:29 -07:00
|
|
|
virtual void NotifyShadowTreeTransaction();
|
2010-12-13 16:14:07 -08:00
|
|
|
virtual void EndTransaction(DrawThebesLayerCallback aCallback,
|
2011-09-26 06:20:42 -07:00
|
|
|
void* aCallbackData,
|
|
|
|
EndTransactionFlags aFlags = END_DEFAULT);
|
2010-03-29 21:48:52 -07:00
|
|
|
|
2010-06-23 11:59:07 -07:00
|
|
|
virtual void SetRoot(Layer* aLayer) { mRoot = aLayer; }
|
|
|
|
|
2012-11-26 14:23:27 -08:00
|
|
|
virtual bool CanUseCanvasLayerForSize(const gfxIntSize &aSize) {
|
|
|
|
if (!mGLContext)
|
|
|
|
return false;
|
|
|
|
int32_t maxSize = GetMaxTextureSize();
|
|
|
|
return aSize <= gfxIntSize(maxSize, maxSize);
|
2011-07-08 03:42:21 -07:00
|
|
|
}
|
|
|
|
|
2012-11-26 14:23:27 -08:00
|
|
|
virtual int32_t GetMaxTextureSize() const;
|
2012-05-22 16:15:16 -07:00
|
|
|
|
2010-03-29 21:48:52 -07:00
|
|
|
virtual already_AddRefed<ThebesLayer> CreateThebesLayer();
|
|
|
|
|
|
|
|
virtual already_AddRefed<ContainerLayer> CreateContainerLayer();
|
|
|
|
|
|
|
|
virtual already_AddRefed<ImageLayer> CreateImageLayer();
|
|
|
|
|
2010-05-12 17:56:11 -07:00
|
|
|
virtual already_AddRefed<ColorLayer> CreateColorLayer();
|
|
|
|
|
2010-05-17 21:04:22 -07:00
|
|
|
virtual already_AddRefed<CanvasLayer> CreateCanvasLayer();
|
|
|
|
|
2010-10-13 15:55:45 -07:00
|
|
|
virtual already_AddRefed<ShadowThebesLayer> CreateShadowThebesLayer();
|
|
|
|
virtual already_AddRefed<ShadowContainerLayer> CreateShadowContainerLayer();
|
|
|
|
virtual already_AddRefed<ShadowImageLayer> CreateShadowImageLayer();
|
|
|
|
virtual already_AddRefed<ShadowColorLayer> CreateShadowColorLayer();
|
|
|
|
virtual already_AddRefed<ShadowCanvasLayer> CreateShadowCanvasLayer();
|
2012-07-17 16:59:45 -07:00
|
|
|
virtual already_AddRefed<ShadowRefLayer> CreateShadowRefLayer();
|
2010-10-13 15:55:45 -07:00
|
|
|
|
2010-03-30 11:58:37 -07:00
|
|
|
virtual LayersBackend GetBackendType() { return LAYERS_OPENGL; }
|
2010-09-03 11:01:05 -07:00
|
|
|
virtual void GetBackendName(nsAString& name) { name.AssignLiteral("OpenGL"); }
|
2010-03-30 11:58:37 -07:00
|
|
|
|
2012-06-25 19:43:31 -07:00
|
|
|
virtual already_AddRefed<gfxASurface>
|
|
|
|
CreateOptimalMaskSurface(const gfxIntSize &aSize);
|
|
|
|
|
2012-11-07 19:51:55 -08:00
|
|
|
virtual void ClearCachedResources(Layer* aSubtree = nullptr) MOZ_OVERRIDE;
|
|
|
|
|
2010-03-29 21:48:52 -07:00
|
|
|
/**
|
|
|
|
* Helper methods.
|
|
|
|
*/
|
2012-11-26 14:23:27 -08:00
|
|
|
void MakeCurrent(bool aForce = false);
|
2010-03-29 21:48:52 -07:00
|
|
|
|
2012-03-18 13:07:25 -07:00
|
|
|
ShaderProgramOGL* GetBasicLayerProgram(bool aOpaque, bool aIsRGB,
|
|
|
|
MaskType aMask = MaskNone)
|
2010-09-07 17:37:34 -07:00
|
|
|
{
|
2012-03-18 13:07:25 -07:00
|
|
|
gl::ShaderProgramType format = gl::BGRALayerProgramType;
|
2010-09-07 17:37:34 -07:00
|
|
|
if (aIsRGB) {
|
2012-03-18 13:07:25 -07:00
|
|
|
if (aOpaque) {
|
|
|
|
format = gl::RGBXLayerProgramType;
|
|
|
|
} else {
|
|
|
|
format = gl::RGBALayerProgramType;
|
|
|
|
}
|
2010-09-07 17:37:34 -07:00
|
|
|
} else {
|
2012-03-18 13:07:25 -07:00
|
|
|
if (aOpaque) {
|
|
|
|
format = gl::BGRXLayerProgramType;
|
|
|
|
}
|
2010-09-07 17:37:34 -07:00
|
|
|
}
|
2012-03-18 13:07:25 -07:00
|
|
|
return GetProgram(format, aMask);
|
2010-09-07 17:37:34 -07:00
|
|
|
}
|
|
|
|
|
2012-03-18 13:07:25 -07:00
|
|
|
ShaderProgramOGL* GetProgram(gl::ShaderProgramType aType,
|
|
|
|
Layer* aMaskLayer) {
|
|
|
|
if (aMaskLayer)
|
|
|
|
return GetProgram(aType, Mask2d);
|
|
|
|
return GetProgram(aType, MaskNone);
|
|
|
|
}
|
|
|
|
|
|
|
|
ShaderProgramOGL* GetProgram(gl::ShaderProgramType aType,
|
|
|
|
MaskType aMask = MaskNone) {
|
|
|
|
NS_ASSERTION(ProgramProfileOGL::ProgramExists(aType, aMask),
|
2012-03-18 13:07:25 -07:00
|
|
|
"Invalid program type.");
|
2012-03-18 13:07:25 -07:00
|
|
|
return mPrograms[aType].mVariations[aMask];
|
2010-05-24 23:35:35 -07:00
|
|
|
}
|
|
|
|
|
2012-03-18 13:07:25 -07:00
|
|
|
ShaderProgramOGL* GetFBOLayerProgram(MaskType aMask = MaskNone) {
|
|
|
|
return GetProgram(GetFBOLayerProgramType(), aMask);
|
2012-03-05 10:09:05 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
gl::ShaderProgramType GetFBOLayerProgramType() {
|
2010-05-24 23:35:35 -07:00
|
|
|
if (mFBOTextureTarget == LOCAL_GL_TEXTURE_RECTANGLE_ARB)
|
2012-03-05 10:09:05 -08:00
|
|
|
return gl::RGBARectLayerProgramType;
|
|
|
|
return gl::RGBALayerProgramType;
|
2010-05-24 23:35:35 -07:00
|
|
|
}
|
2010-03-29 21:48:52 -07:00
|
|
|
|
2012-03-18 13:07:25 -07:00
|
|
|
GLContext* gl() const { return mGLContext; }
|
2010-04-26 19:09:47 -07:00
|
|
|
|
2012-11-26 14:23:27 -08:00
|
|
|
// |NSOpenGLContext*|:
|
|
|
|
void* GetNSOpenGLContext() const;
|
|
|
|
|
2010-07-22 13:29:37 -07:00
|
|
|
DrawThebesLayerCallback GetThebesLayerCallback() const
|
|
|
|
{ return mThebesLayerCallback; }
|
|
|
|
|
|
|
|
void* GetThebesLayerCallbackData() const
|
|
|
|
{ return mThebesLayerCallbackData; }
|
|
|
|
|
2010-05-24 23:35:35 -07:00
|
|
|
/*
|
|
|
|
* Helper functions for our layers
|
|
|
|
*/
|
|
|
|
void CallThebesLayerDrawCallback(ThebesLayer* aLayer,
|
|
|
|
gfxContext* aContext,
|
|
|
|
const nsIntRegion& aRegionToDraw)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(mThebesLayerCallback,
|
|
|
|
"CallThebesLayerDrawCallback without callback!");
|
|
|
|
mThebesLayerCallback(aLayer, aContext,
|
2010-03-03 13:37:04 -08:00
|
|
|
aRegionToDraw, nsIntRegion(),
|
|
|
|
mThebesLayerCallbackData);
|
2010-05-24 23:35:35 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
GLenum FBOTextureTarget() { return mFBOTextureTarget; }
|
|
|
|
|
2011-01-17 23:22:25 -08:00
|
|
|
/**
|
|
|
|
* Controls how to initialize the texture / FBO created by
|
|
|
|
* CreateFBOWithTexture.
|
|
|
|
* - InitModeNone: No initialization, contents are undefined.
|
|
|
|
* - InitModeClear: Clears the FBO.
|
|
|
|
* - InitModeCopy: Copies the contents of the current glReadBuffer into the
|
|
|
|
* texture.
|
|
|
|
*/
|
|
|
|
enum InitMode {
|
|
|
|
InitModeNone,
|
|
|
|
InitModeClear,
|
|
|
|
InitModeCopy
|
|
|
|
};
|
|
|
|
|
2010-05-24 23:35:35 -07:00
|
|
|
/* Create a FBO backed by a texture; will leave the FBO
|
|
|
|
* bound. Note that the texture target type will be
|
|
|
|
* of the type returned by FBOTextureTarget; different
|
|
|
|
* shaders are required to sample from the different
|
|
|
|
* texture types.
|
|
|
|
*/
|
2011-01-17 23:22:25 -08:00
|
|
|
void CreateFBOWithTexture(const nsIntRect& aRect, InitMode aInit,
|
2012-01-25 18:05:34 -08:00
|
|
|
GLuint aCurrentFrameBuffer,
|
2010-05-24 23:35:35 -07:00
|
|
|
GLuint *aFBO, GLuint *aTexture);
|
|
|
|
|
|
|
|
GLuint QuadVBO() { return mQuadVBO; }
|
|
|
|
GLintptr QuadVBOVertexOffset() { return 0; }
|
|
|
|
GLintptr QuadVBOTexCoordOffset() { return sizeof(float)*4*2; }
|
|
|
|
GLintptr QuadVBOFlippedTexCoordOffset() { return sizeof(float)*8*2; }
|
|
|
|
|
2012-11-26 14:23:27 -08:00
|
|
|
void BindQuadVBO();
|
|
|
|
void QuadVBOVerticesAttrib(GLuint aAttribIndex);
|
|
|
|
void QuadVBOTexCoordsAttrib(GLuint aAttribIndex);
|
|
|
|
void QuadVBOFlippedTexCoordsAttrib(GLuint aAttribIndex);
|
2010-05-24 23:35:35 -07:00
|
|
|
|
|
|
|
// Super common
|
|
|
|
void BindAndDrawQuad(GLuint aVertAttribIndex,
|
|
|
|
GLuint aTexCoordAttribIndex,
|
2012-11-26 14:23:27 -08:00
|
|
|
bool aFlipped = false);
|
2010-05-24 23:35:35 -07:00
|
|
|
|
2012-03-18 13:07:25 -07:00
|
|
|
void BindAndDrawQuad(ShaderProgramOGL *aProg,
|
2010-05-24 23:35:35 -07:00
|
|
|
bool aFlipped = false)
|
|
|
|
{
|
2012-05-01 19:54:40 -07:00
|
|
|
NS_ASSERTION(aProg->HasInitialized(), "Shader program not correctly initialized");
|
2012-03-18 13:07:25 -07:00
|
|
|
BindAndDrawQuad(aProg->AttribLocation(ShaderProgramOGL::VertexCoordAttrib),
|
|
|
|
aProg->AttribLocation(ShaderProgramOGL::TexCoordAttrib),
|
2010-05-24 23:35:35 -07:00
|
|
|
aFlipped);
|
|
|
|
}
|
|
|
|
|
2012-03-18 13:07:25 -07:00
|
|
|
void BindAndDrawQuadWithTextureRect(ShaderProgramOGL *aProg,
|
2011-07-04 19:50:38 -07:00
|
|
|
const nsIntRect& aTexCoordRect,
|
|
|
|
const nsIntSize& aTexSize,
|
2012-02-29 14:15:12 -08:00
|
|
|
GLenum aWrapMode = LOCAL_GL_REPEAT,
|
|
|
|
bool aFlipped = false);
|
|
|
|
|
2010-09-02 20:50:29 -07:00
|
|
|
#ifdef MOZ_LAYERS_HAVE_LOG
|
2010-09-29 11:36:32 -07:00
|
|
|
virtual const char* Name() const { return "OGL"; }
|
2010-09-02 20:50:29 -07:00
|
|
|
#endif // MOZ_LAYERS_HAVE_LOG
|
|
|
|
|
2012-03-17 05:07:02 -07:00
|
|
|
const nsIntSize& GetWidgetSize() {
|
2010-09-29 11:36:32 -07:00
|
|
|
return mWidgetSize;
|
|
|
|
}
|
2010-12-16 23:23:07 -08:00
|
|
|
|
2011-02-04 11:47:06 -08:00
|
|
|
enum WorldTransforPolicy {
|
|
|
|
ApplyWorldTransform,
|
|
|
|
DontApplyWorldTransform
|
|
|
|
};
|
|
|
|
|
2010-09-29 11:36:32 -07:00
|
|
|
/**
|
|
|
|
* Setup the viewport and projection matrix for rendering
|
|
|
|
* to a window of the given dimensions.
|
|
|
|
*/
|
2011-02-04 11:47:06 -08:00
|
|
|
void SetupPipeline(int aWidth, int aHeight, WorldTransforPolicy aTransformPolicy);
|
2012-02-02 19:28:22 -08:00
|
|
|
|
2011-02-04 11:47:06 -08:00
|
|
|
/**
|
|
|
|
* Setup World transform matrix.
|
|
|
|
* Transform will be ignored if it is not PreservesAxisAlignedRectangles
|
|
|
|
* or has non integer scale
|
|
|
|
*/
|
|
|
|
void SetWorldTransform(const gfxMatrix& aMatrix);
|
|
|
|
gfxMatrix& GetWorldTransform(void);
|
|
|
|
void WorldTransformRect(nsIntRect& aRect);
|
2010-09-21 12:41:24 -07:00
|
|
|
|
2012-11-21 18:40:57 -08:00
|
|
|
void UpdateRenderBounds(const nsIntRect& aRect);
|
|
|
|
|
2012-04-20 08:46:30 -07:00
|
|
|
/**
|
|
|
|
* Set the size of the surface we're rendering to.
|
|
|
|
*/
|
|
|
|
void SetSurfaceSize(int width, int height);
|
|
|
|
|
2012-08-13 03:10:10 -07:00
|
|
|
bool CompositingDisabled() { return mCompositingDisabled; }
|
|
|
|
void SetCompositingDisabled(bool aCompositingDisabled) { mCompositingDisabled = aCompositingDisabled; }
|
|
|
|
|
2012-07-31 15:48:40 -07:00
|
|
|
/**
|
|
|
|
* Creates a DrawTarget which is optimized for inter-operating with this
|
|
|
|
* layermanager.
|
|
|
|
*/
|
|
|
|
virtual TemporaryRef<mozilla::gfx::DrawTarget>
|
|
|
|
CreateDrawTarget(const mozilla::gfx::IntSize &aSize,
|
|
|
|
mozilla::gfx::SurfaceFormat aFormat);
|
|
|
|
|
2012-10-25 09:23:42 -07:00
|
|
|
/**
|
|
|
|
* Calculates the 'completeness' of the rendering that intersected with the
|
|
|
|
* screen on the last render. This is only useful when progressive tile
|
|
|
|
* drawing is enabled, otherwise this will always return 1.0.
|
|
|
|
* This function's expense scales with the size of the layer tree and the
|
|
|
|
* complexity of individual layers' valid regions.
|
|
|
|
*/
|
|
|
|
float ComputeRenderIntegrity();
|
|
|
|
|
2010-03-29 21:48:52 -07:00
|
|
|
private:
|
|
|
|
/** Widget associated with this layer manager */
|
|
|
|
nsIWidget *mWidget;
|
2010-09-09 13:40:29 -07:00
|
|
|
nsIntSize mWidgetSize;
|
|
|
|
|
2012-04-20 08:46:30 -07:00
|
|
|
/** The size of the surface we are rendering to */
|
|
|
|
nsIntSize mSurfaceSize;
|
|
|
|
|
2010-03-29 21:48:52 -07:00
|
|
|
/**
|
|
|
|
* Context target, NULL when drawing directly to our swap chain.
|
|
|
|
*/
|
|
|
|
nsRefPtr<gfxContext> mTarget;
|
|
|
|
|
2010-04-26 19:09:47 -07:00
|
|
|
nsRefPtr<GLContext> mGLContext;
|
2010-03-29 21:48:52 -07:00
|
|
|
|
2012-11-19 09:58:38 -08:00
|
|
|
/** Our more efficient but less powerful alter ego, if one is available. */
|
|
|
|
nsRefPtr<Composer2D> mComposer2D;
|
|
|
|
|
2011-01-18 12:11:18 -08:00
|
|
|
already_AddRefed<mozilla::gl::GLContext> CreateContext();
|
|
|
|
|
2010-05-24 23:35:35 -07:00
|
|
|
/** Backbuffer */
|
|
|
|
GLuint mBackBufferFBO;
|
|
|
|
GLuint mBackBufferTexture;
|
|
|
|
nsIntSize mBackBufferSize;
|
|
|
|
|
|
|
|
/** Shader Programs */
|
2012-03-18 13:07:25 -07:00
|
|
|
struct ShaderProgramVariations {
|
|
|
|
ShaderProgramOGL* mVariations[NumMaskTypes];
|
|
|
|
};
|
|
|
|
nsTArray<ShaderProgramVariations> mPrograms;
|
2010-05-24 23:35:35 -07:00
|
|
|
|
2010-05-12 09:21:31 -07:00
|
|
|
/** Texture target to use for FBOs */
|
|
|
|
GLenum mFBOTextureTarget;
|
2010-03-29 21:48:52 -07:00
|
|
|
|
2010-05-24 23:35:35 -07:00
|
|
|
/** VBO that has some basics in it for a textured quad,
|
|
|
|
* including vertex coords and texcoords for both
|
|
|
|
* flipped and unflipped textures */
|
|
|
|
GLuint mQuadVBO;
|
|
|
|
|
|
|
|
/** Region we're clipping our current drawing to. */
|
2010-03-29 21:48:52 -07:00
|
|
|
nsIntRegion mClippingRegion;
|
2010-05-24 23:35:35 -07:00
|
|
|
|
|
|
|
/** Misc */
|
2011-09-28 23:19:26 -07:00
|
|
|
bool mHasBGRA;
|
2012-08-13 03:10:10 -07:00
|
|
|
bool mCompositingDisabled;
|
2010-05-24 23:35:35 -07:00
|
|
|
|
2012-04-20 08:46:30 -07:00
|
|
|
/**
|
|
|
|
* When rendering to an EGL surface (e.g. on Android), we rely on being told
|
|
|
|
* about size changes (via SetSurfaceSize) rather than pulling this information
|
|
|
|
* from the widget, since the widget's information can lag behind.
|
|
|
|
*/
|
|
|
|
bool mIsRenderingToEGLSurface;
|
|
|
|
|
2010-06-23 11:59:07 -07:00
|
|
|
/** Current root layer. */
|
|
|
|
LayerOGL *RootLayer() const;
|
|
|
|
|
2010-03-29 21:48:52 -07:00
|
|
|
/**
|
|
|
|
* Render the current layer tree to the active target.
|
|
|
|
*/
|
2010-05-24 23:35:35 -07:00
|
|
|
void Render();
|
2010-09-29 11:36:32 -07:00
|
|
|
|
2010-03-29 21:48:52 -07:00
|
|
|
/**
|
2010-05-24 23:35:35 -07:00
|
|
|
* Setup a backbuffer of the given dimensions.
|
2010-03-29 21:48:52 -07:00
|
|
|
*/
|
2010-05-24 23:35:35 -07:00
|
|
|
void SetupBackBuffer(int aWidth, int aHeight);
|
2010-09-29 11:36:32 -07:00
|
|
|
|
2010-03-29 21:48:52 -07:00
|
|
|
/**
|
|
|
|
* Copies the content of our backbuffer to the set transaction target.
|
|
|
|
*/
|
2012-03-05 10:09:05 -08:00
|
|
|
void CopyToTarget(gfxContext *aTarget);
|
2010-05-24 23:35:35 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Updates all layer programs with a new projection matrix.
|
|
|
|
*/
|
|
|
|
void SetLayerProgramProjectionMatrix(const gfx3DMatrix& aMatrix);
|
|
|
|
|
2012-03-18 13:07:25 -07:00
|
|
|
/**
|
2012-05-01 19:54:40 -07:00
|
|
|
* Helper method for Initialize, creates all valid variations of a program
|
|
|
|
* and adds them to mPrograms
|
2012-03-18 13:07:25 -07:00
|
|
|
*/
|
2012-05-01 19:54:40 -07:00
|
|
|
void AddPrograms(gl::ShaderProgramType aType);
|
2012-03-18 13:07:25 -07:00
|
|
|
|
2012-10-25 09:23:42 -07:00
|
|
|
/**
|
|
|
|
* Recursive helper method for use by ComputeRenderIntegrity. Subtracts
|
2012-11-29 04:03:27 -08:00
|
|
|
* any incomplete rendering on aLayer from aScreenRegion. Any low-precision
|
|
|
|
* rendering is included in aLowPrecisionScreenRegion. aTransform is the
|
2012-10-25 09:23:42 -07:00
|
|
|
* accumulated transform of intermediate surfaces beneath aLayer.
|
|
|
|
*/
|
|
|
|
static void ComputeRenderIntegrityInternal(Layer* aLayer,
|
|
|
|
nsIntRegion& aScreenRegion,
|
2012-11-29 04:03:27 -08:00
|
|
|
nsIntRegion& aLowPrecisionScreenRegion,
|
2012-10-25 09:23:42 -07:00
|
|
|
const gfx3DMatrix& aTransform);
|
|
|
|
|
2010-05-24 23:35:35 -07:00
|
|
|
/* Thebes layer callbacks; valid at the end of a transaciton,
|
|
|
|
* while rendering */
|
|
|
|
DrawThebesLayerCallback mThebesLayerCallback;
|
|
|
|
void *mThebesLayerCallbackData;
|
2011-02-04 11:47:06 -08:00
|
|
|
gfxMatrix mWorldMatrix;
|
2012-09-04 22:17:13 -07:00
|
|
|
nsAutoPtr<FPSState> mFPS;
|
2012-11-21 18:40:57 -08:00
|
|
|
nsIntRect mRenderBounds;
|
2012-11-07 19:51:55 -08:00
|
|
|
#ifdef DEBUG
|
|
|
|
// NB: only interesting when this is a purely compositing layer
|
|
|
|
// manager. True after possibly onscreen layers have had their
|
|
|
|
// cached resources cleared outside of a transaction, and before the
|
|
|
|
// next forwarded transaction that re-validates their buffers.
|
|
|
|
bool mMaybeInvalidTree;
|
|
|
|
#endif
|
2011-05-10 18:45:42 -07:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool sDrawFPS;
|
2012-09-05 13:24:54 -07:00
|
|
|
static bool sFrameCounter;
|
2010-03-29 21:48:52 -07:00
|
|
|
};
|
|
|
|
|
2012-11-19 09:58:38 -08:00
|
|
|
enum LayerRenderStateFlags {
|
|
|
|
LAYER_RENDER_STATE_Y_FLIPPED = 1 << 0,
|
|
|
|
LAYER_RENDER_STATE_BUFFER_ROTATION = 1 << 1
|
|
|
|
};
|
|
|
|
|
|
|
|
struct LayerRenderState {
|
2013-01-10 02:51:43 -08:00
|
|
|
LayerRenderState() : mSurface(nullptr), mFlags(0), mHasOwnOffset(false)
|
2012-11-19 09:58:38 -08:00
|
|
|
{}
|
|
|
|
|
|
|
|
LayerRenderState(SurfaceDescriptor* aSurface, uint32_t aFlags = 0)
|
|
|
|
: mSurface(aSurface)
|
|
|
|
, mFlags(aFlags)
|
2013-01-10 02:51:43 -08:00
|
|
|
, mHasOwnOffset(false)
|
|
|
|
{}
|
|
|
|
|
|
|
|
LayerRenderState(SurfaceDescriptor* aSurface, nsIntPoint aOffset, uint32_t aFlags = 0)
|
|
|
|
: mSurface(aSurface)
|
|
|
|
, mFlags(aFlags)
|
|
|
|
, mOffset(aOffset)
|
|
|
|
, mHasOwnOffset(true)
|
2012-11-19 09:58:38 -08:00
|
|
|
{}
|
|
|
|
|
|
|
|
bool YFlipped() const
|
|
|
|
{ return mFlags & LAYER_RENDER_STATE_Y_FLIPPED; }
|
|
|
|
|
|
|
|
bool BufferRotated() const
|
|
|
|
{ return mFlags & LAYER_RENDER_STATE_BUFFER_ROTATION; }
|
|
|
|
|
|
|
|
SurfaceDescriptor* mSurface;
|
|
|
|
uint32_t mFlags;
|
2013-01-10 02:51:43 -08:00
|
|
|
nsIntPoint mOffset;
|
|
|
|
bool mHasOwnOffset;
|
2012-11-19 09:58:38 -08:00
|
|
|
};
|
|
|
|
|
2010-03-29 21:48:52 -07:00
|
|
|
/**
|
|
|
|
* General information and tree management for OGL layers.
|
|
|
|
*/
|
|
|
|
class LayerOGL
|
|
|
|
{
|
|
|
|
public:
|
2010-05-24 23:35:35 -07:00
|
|
|
LayerOGL(LayerManagerOGL *aManager)
|
2011-10-17 07:59:28 -07:00
|
|
|
: mOGLManager(aManager), mDestroyed(false)
|
2010-05-24 23:35:35 -07:00
|
|
|
{ }
|
2010-03-29 21:48:52 -07:00
|
|
|
|
2010-08-06 22:09:18 -07:00
|
|
|
virtual ~LayerOGL() { }
|
|
|
|
|
2010-05-24 23:35:35 -07:00
|
|
|
virtual LayerOGL *GetFirstChildOGL() {
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2010-05-24 23:35:35 -07:00
|
|
|
}
|
2010-03-29 21:48:52 -07:00
|
|
|
|
2010-08-06 22:09:18 -07:00
|
|
|
/* Do NOT call this from the generic LayerOGL destructor. Only from the
|
|
|
|
* concrete class destructor
|
|
|
|
*/
|
|
|
|
virtual void Destroy() = 0;
|
|
|
|
|
2010-03-29 21:48:52 -07:00
|
|
|
virtual Layer* GetLayer() = 0;
|
|
|
|
|
2012-11-19 09:58:38 -08:00
|
|
|
virtual LayerRenderState GetRenderState() { return LayerRenderState(); }
|
|
|
|
|
2010-05-24 23:35:35 -07:00
|
|
|
virtual void RenderLayer(int aPreviousFrameBuffer,
|
|
|
|
const nsIntPoint& aOffset) = 0;
|
2010-03-29 21:48:52 -07:00
|
|
|
|
2010-04-26 19:09:47 -07:00
|
|
|
typedef mozilla::gl::GLContext GLContext;
|
|
|
|
|
2010-10-13 15:55:45 -07:00
|
|
|
LayerManagerOGL* OGLManager() const { return mOGLManager; }
|
2010-04-26 19:09:47 -07:00
|
|
|
GLContext *gl() const { return mOGLManager->gl(); }
|
2012-01-15 21:41:55 -08:00
|
|
|
virtual void CleanupResources() = 0;
|
2010-09-21 09:32:17 -07:00
|
|
|
|
2012-03-18 13:08:49 -07:00
|
|
|
/*
|
|
|
|
* Loads the result of rendering the layer as an OpenGL texture in aTextureUnit.
|
|
|
|
* Will try to use an existing texture if possible, or a temporary
|
|
|
|
* one if not. It is the callee's responsibility to release the texture.
|
|
|
|
* Will return true if a texture could be constructed and loaded, false otherwise.
|
|
|
|
* The texture will not be transformed, i.e., it will be in the same coord
|
|
|
|
* space as this.
|
|
|
|
* Any layer that can be used as a mask layer should override this method.
|
|
|
|
* aSize will contain the size of the image.
|
|
|
|
*/
|
|
|
|
virtual bool LoadAsTexture(GLuint aTextureUnit, gfxIntSize* aSize)
|
|
|
|
{
|
|
|
|
NS_WARNING("LoadAsTexture called without being overriden");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-03-29 21:48:52 -07:00
|
|
|
protected:
|
2010-04-26 19:09:47 -07:00
|
|
|
LayerManagerOGL *mOGLManager;
|
2011-09-28 23:19:26 -07:00
|
|
|
bool mDestroyed;
|
2010-03-29 21:48:52 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
} /* layers */
|
|
|
|
} /* mozilla */
|
|
|
|
|
|
|
|
#endif /* GFX_LAYERMANAGEROGL_H */
|