2010-05-17 21:04:22 -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>
|
2010-05-24 23:35:35 -07:00
|
|
|
* Frederic Plourde <frederic.plourde@collabora.co.uk>
|
|
|
|
* 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 ***** */
|
|
|
|
|
|
|
|
#ifndef GFX_LAYERMANAGEROGL_H
|
|
|
|
#define GFX_LAYERMANAGEROGL_H
|
|
|
|
|
|
|
|
#include "Layers.h"
|
|
|
|
|
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"
|
|
|
|
|
2010-03-29 21:48:52 -07:00
|
|
|
#ifdef XP_WIN
|
|
|
|
#include <windows.h>
|
|
|
|
#endif
|
|
|
|
|
2010-04-26 19:37:14 -07:00
|
|
|
/**
|
|
|
|
* We don't include GLDefs.h here since we don't want to drag in all defines
|
|
|
|
* in for all our users.
|
|
|
|
*/
|
|
|
|
typedef unsigned int GLenum;
|
|
|
|
typedef unsigned int GLbitfield;
|
2010-03-29 21:48:52 -07:00
|
|
|
typedef unsigned int GLuint;
|
|
|
|
typedef int GLint;
|
2010-04-26 19:37:14 -07:00
|
|
|
typedef int GLsizei;
|
2010-03-29 21:48:52 -07:00
|
|
|
|
|
|
|
#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"
|
2010-04-26 19:09:47 -07:00
|
|
|
#include "GLContext.h"
|
2010-03-29 21:48:52 -07:00
|
|
|
|
2010-05-24 23:35:35 -07:00
|
|
|
#include "LayerManagerOGLProgram.h"
|
|
|
|
|
2010-03-29 21:48:52 -07:00
|
|
|
namespace mozilla {
|
|
|
|
namespace layers {
|
|
|
|
|
|
|
|
class LayerOGL;
|
2010-10-13 16:36:44 -07:00
|
|
|
class ShadowThebesLayer;
|
|
|
|
class ShadowContainerLayer;
|
|
|
|
class ShadowImageLayer;
|
|
|
|
class ShadowCanvasLayer;
|
|
|
|
class ShadowColorLayer;
|
2010-03-29 21:48:52 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This is the LayerManager used for OpenGL 2.1. For now this will render on
|
|
|
|
* the main thread.
|
|
|
|
*/
|
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:
|
|
|
|
LayerManagerOGL(nsIWidget *aWidget);
|
|
|
|
virtual ~LayerManagerOGL();
|
2010-07-18 22:01:14 -07:00
|
|
|
|
|
|
|
void CleanupResources();
|
|
|
|
|
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-02-27 13:33:19 -08:00
|
|
|
bool Initialize(bool force = false) {
|
|
|
|
return Initialize(CreateContext(), force);
|
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();
|
|
|
|
|
2011-01-25 00:45:17 -08:00
|
|
|
virtual bool EndEmptyTransaction();
|
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; }
|
|
|
|
|
2011-07-08 03:42:21 -07:00
|
|
|
virtual bool CanUseCanvasLayerForSize(const gfxIntSize &aSize)
|
|
|
|
{
|
|
|
|
if (!mGLContext)
|
|
|
|
return false;
|
|
|
|
PRInt32 maxSize = mGLContext->GetMaxTextureSize();
|
|
|
|
return aSize <= gfxIntSize(maxSize, maxSize);
|
|
|
|
}
|
|
|
|
|
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();
|
|
|
|
|
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
|
|
|
|
2010-03-29 21:48:52 -07:00
|
|
|
/**
|
|
|
|
* Helper methods.
|
|
|
|
*/
|
2011-09-28 23:19:26 -07:00
|
|
|
void MakeCurrent(bool aForce = false) {
|
2010-09-09 13:40:29 -07:00
|
|
|
if (mDestroyed) {
|
|
|
|
NS_WARNING("Call on destroyed layer manager");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
mGLContext->MakeCurrent(aForce);
|
|
|
|
}
|
2010-03-29 21:48:52 -07:00
|
|
|
|
2010-12-16 23:23:07 -08:00
|
|
|
ColorTextureLayerProgram *GetColorTextureLayerProgram(ProgramType type){
|
|
|
|
return static_cast<ColorTextureLayerProgram*>(mPrograms[type]);
|
|
|
|
}
|
|
|
|
|
2010-05-24 23:35:35 -07:00
|
|
|
ColorTextureLayerProgram *GetRGBALayerProgram() {
|
2010-12-16 23:23:07 -08:00
|
|
|
return static_cast<ColorTextureLayerProgram*>(mPrograms[gl::RGBALayerProgramType]);
|
2010-05-24 23:35:35 -07:00
|
|
|
}
|
|
|
|
ColorTextureLayerProgram *GetBGRALayerProgram() {
|
2010-12-16 23:23:07 -08:00
|
|
|
return static_cast<ColorTextureLayerProgram*>(mPrograms[gl::BGRALayerProgramType]);
|
2010-05-24 23:35:35 -07:00
|
|
|
}
|
|
|
|
ColorTextureLayerProgram *GetRGBXLayerProgram() {
|
2010-12-16 23:23:07 -08:00
|
|
|
return static_cast<ColorTextureLayerProgram*>(mPrograms[gl::RGBXLayerProgramType]);
|
2010-05-24 23:35:35 -07:00
|
|
|
}
|
|
|
|
ColorTextureLayerProgram *GetBGRXLayerProgram() {
|
2010-12-16 23:23:07 -08:00
|
|
|
return static_cast<ColorTextureLayerProgram*>(mPrograms[gl::BGRXLayerProgramType]);
|
2010-05-24 23:35:35 -07:00
|
|
|
}
|
2011-09-28 23:19:26 -07:00
|
|
|
ColorTextureLayerProgram *GetBasicLayerProgram(bool aOpaque, bool aIsRGB)
|
2010-09-07 17:37:34 -07:00
|
|
|
{
|
|
|
|
if (aIsRGB) {
|
|
|
|
return aOpaque
|
|
|
|
? GetRGBXLayerProgram()
|
|
|
|
: GetRGBALayerProgram();
|
|
|
|
} else {
|
|
|
|
return aOpaque
|
|
|
|
? GetBGRXLayerProgram()
|
|
|
|
: GetBGRALayerProgram();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-24 23:35:35 -07:00
|
|
|
ColorTextureLayerProgram *GetRGBARectLayerProgram() {
|
2010-12-16 23:23:07 -08:00
|
|
|
return static_cast<ColorTextureLayerProgram*>(mPrograms[gl::RGBARectLayerProgramType]);
|
2010-05-24 23:35:35 -07:00
|
|
|
}
|
|
|
|
SolidColorLayerProgram *GetColorLayerProgram() {
|
2010-12-16 23:23:07 -08:00
|
|
|
return static_cast<SolidColorLayerProgram*>(mPrograms[gl::ColorLayerProgramType]);
|
2010-05-24 23:35:35 -07:00
|
|
|
}
|
|
|
|
YCbCrTextureLayerProgram *GetYCbCrLayerProgram() {
|
2010-12-16 23:23:07 -08:00
|
|
|
return static_cast<YCbCrTextureLayerProgram*>(mPrograms[gl::YCbCrLayerProgramType]);
|
2010-05-24 23:35:35 -07:00
|
|
|
}
|
2011-01-17 23:22:25 -08:00
|
|
|
ComponentAlphaTextureLayerProgram *GetComponentAlphaPass1LayerProgram() {
|
|
|
|
return static_cast<ComponentAlphaTextureLayerProgram*>
|
|
|
|
(mPrograms[gl::ComponentAlphaPass1ProgramType]);
|
|
|
|
}
|
|
|
|
ComponentAlphaTextureLayerProgram *GetComponentAlphaPass2LayerProgram() {
|
|
|
|
return static_cast<ComponentAlphaTextureLayerProgram*>
|
|
|
|
(mPrograms[gl::ComponentAlphaPass2ProgramType]);
|
|
|
|
}
|
2010-05-24 23:35:35 -07:00
|
|
|
CopyProgram *GetCopy2DProgram() {
|
2010-12-16 23:23:07 -08:00
|
|
|
return static_cast<CopyProgram*>(mPrograms[gl::Copy2DProgramType]);
|
2010-05-24 23:35:35 -07:00
|
|
|
}
|
|
|
|
CopyProgram *GetCopy2DRectProgram() {
|
2010-12-16 23:23:07 -08:00
|
|
|
return static_cast<CopyProgram*>(mPrograms[gl::Copy2DRectProgramType]);
|
2010-05-24 23:35:35 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
ColorTextureLayerProgram *GetFBOLayerProgram() {
|
2012-03-01 00:26:09 -08:00
|
|
|
return static_cast<ColorTextureLayerProgram*>(mPrograms[GetFBOLayerProgramType()]);
|
|
|
|
}
|
|
|
|
|
|
|
|
gl::ShaderProgramType GetFBOLayerProgramType() {
|
2010-05-24 23:35:35 -07:00
|
|
|
if (mFBOTextureTarget == LOCAL_GL_TEXTURE_RECTANGLE_ARB)
|
2012-03-01 00:26:09 -08:00
|
|
|
return gl::RGBARectLayerProgramType;
|
|
|
|
return gl::RGBALayerProgramType;
|
2010-05-24 23:35:35 -07:00
|
|
|
}
|
2010-03-29 21:48:52 -07:00
|
|
|
|
2010-04-26 19:09:47 -07:00
|
|
|
GLContext *gl() const { return mGLContext; }
|
|
|
|
|
2010-07-22 13:29:37 -07:00
|
|
|
DrawThebesLayerCallback GetThebesLayerCallback() const
|
|
|
|
{ return mThebesLayerCallback; }
|
|
|
|
|
|
|
|
void* GetThebesLayerCallbackData() const
|
|
|
|
{ return mThebesLayerCallbackData; }
|
|
|
|
|
2010-08-06 22:09:18 -07:00
|
|
|
// This is a GLContext that can be used for resource
|
|
|
|
// management (creation, destruction). It is guaranteed
|
|
|
|
// to be either the same as the gl() context, or a context
|
|
|
|
// that is in the same share pool.
|
|
|
|
GLContext *glForResources() const {
|
|
|
|
if (mGLContext->GetSharedContext())
|
|
|
|
return mGLContext->GetSharedContext();
|
|
|
|
return mGLContext;
|
|
|
|
}
|
|
|
|
|
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; }
|
|
|
|
|
|
|
|
void BindQuadVBO() {
|
|
|
|
mGLContext->fBindBuffer(LOCAL_GL_ARRAY_BUFFER, mQuadVBO);
|
|
|
|
}
|
|
|
|
|
|
|
|
void QuadVBOVerticesAttrib(GLuint aAttribIndex) {
|
|
|
|
mGLContext->fVertexAttribPointer(aAttribIndex, 2,
|
|
|
|
LOCAL_GL_FLOAT, LOCAL_GL_FALSE, 0,
|
|
|
|
(GLvoid*) QuadVBOVertexOffset());
|
|
|
|
}
|
|
|
|
|
|
|
|
void QuadVBOTexCoordsAttrib(GLuint aAttribIndex) {
|
|
|
|
mGLContext->fVertexAttribPointer(aAttribIndex, 2,
|
|
|
|
LOCAL_GL_FLOAT, LOCAL_GL_FALSE, 0,
|
|
|
|
(GLvoid*) QuadVBOTexCoordOffset());
|
|
|
|
}
|
|
|
|
|
|
|
|
void QuadVBOFlippedTexCoordsAttrib(GLuint aAttribIndex) {
|
|
|
|
mGLContext->fVertexAttribPointer(aAttribIndex, 2,
|
|
|
|
LOCAL_GL_FLOAT, LOCAL_GL_FALSE, 0,
|
|
|
|
(GLvoid*) QuadVBOFlippedTexCoordOffset());
|
|
|
|
}
|
|
|
|
|
|
|
|
// Super common
|
|
|
|
|
|
|
|
void BindAndDrawQuad(GLuint aVertAttribIndex,
|
|
|
|
GLuint aTexCoordAttribIndex,
|
|
|
|
bool aFlipped = false)
|
|
|
|
{
|
|
|
|
BindQuadVBO();
|
|
|
|
QuadVBOVerticesAttrib(aVertAttribIndex);
|
|
|
|
|
2010-05-31 16:29:37 -07:00
|
|
|
if (aTexCoordAttribIndex != GLuint(-1)) {
|
2010-05-24 23:35:35 -07:00
|
|
|
if (aFlipped)
|
|
|
|
QuadVBOFlippedTexCoordsAttrib(aTexCoordAttribIndex);
|
|
|
|
else
|
|
|
|
QuadVBOTexCoordsAttrib(aTexCoordAttribIndex);
|
|
|
|
|
|
|
|
mGLContext->fEnableVertexAttribArray(aTexCoordAttribIndex);
|
|
|
|
}
|
|
|
|
|
|
|
|
mGLContext->fEnableVertexAttribArray(aVertAttribIndex);
|
|
|
|
|
|
|
|
mGLContext->fDrawArrays(LOCAL_GL_TRIANGLE_STRIP, 0, 4);
|
|
|
|
|
|
|
|
mGLContext->fDisableVertexAttribArray(aVertAttribIndex);
|
|
|
|
|
2010-05-31 16:29:37 -07:00
|
|
|
if (aTexCoordAttribIndex != GLuint(-1)) {
|
2010-05-24 23:35:35 -07:00
|
|
|
mGLContext->fDisableVertexAttribArray(aTexCoordAttribIndex);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void BindAndDrawQuad(LayerProgram *aProg,
|
|
|
|
bool aFlipped = false)
|
|
|
|
{
|
|
|
|
BindAndDrawQuad(aProg->AttribLocation(LayerProgram::VertexAttrib),
|
|
|
|
aProg->AttribLocation(LayerProgram::TexCoordAttrib),
|
|
|
|
aFlipped);
|
|
|
|
}
|
|
|
|
|
2011-07-04 19:50:38 -07:00
|
|
|
void BindAndDrawQuadWithTextureRect(LayerProgram *aProg,
|
|
|
|
const nsIntRect& aTexCoordRect,
|
|
|
|
const nsIntSize& aTexSize,
|
|
|
|
GLenum aWrapMode = LOCAL_GL_REPEAT);
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
2010-09-29 11:36:32 -07:00
|
|
|
const nsIntSize& GetWigetSize() {
|
|
|
|
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);
|
2011-02-24 23:44:18 -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
|
|
|
|
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;
|
|
|
|
|
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
|
|
|
|
2011-01-18 12:11:18 -08:00
|
|
|
already_AddRefed<mozilla::gl::GLContext> CreateContext();
|
|
|
|
|
2010-05-24 23:35:35 -07:00
|
|
|
static ProgramType sLayerProgramTypes[];
|
|
|
|
|
|
|
|
/** Backbuffer */
|
|
|
|
GLuint mBackBufferFBO;
|
|
|
|
GLuint mBackBufferTexture;
|
|
|
|
nsIntSize mBackBufferSize;
|
|
|
|
|
|
|
|
/** Shader Programs */
|
|
|
|
nsTArray<LayerManagerOGLProgram*> mPrograms;
|
|
|
|
|
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;
|
2010-05-24 23:35:35 -07:00
|
|
|
|
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-01 00:26:09 -08:00
|
|
|
void CopyToTarget(gfxContext *aTarget);
|
2010-05-24 23:35:35 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Updates all layer programs with a new projection matrix.
|
|
|
|
*
|
|
|
|
* XXX we need a way to be able to delay setting this until
|
|
|
|
* the program is actually used. Maybe a DelayedSetUniform
|
|
|
|
* on Program, that will delay the set until the next Activate?
|
|
|
|
*
|
|
|
|
* XXX this is only called once per frame, so it's not awful.
|
|
|
|
* If we have any more similar updates, then we should delay.
|
|
|
|
*/
|
|
|
|
void SetLayerProgramProjectionMatrix(const gfx3DMatrix& aMatrix);
|
|
|
|
|
|
|
|
/* 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;
|
2011-05-10 18:45:42 -07:00
|
|
|
|
|
|
|
struct FPSState
|
|
|
|
{
|
|
|
|
GLuint texture;
|
|
|
|
int fps;
|
|
|
|
bool initialized;
|
|
|
|
int fcount;
|
|
|
|
TimeStamp last;
|
|
|
|
|
|
|
|
FPSState()
|
|
|
|
: texture(0)
|
|
|
|
, fps(0)
|
|
|
|
, initialized(false)
|
|
|
|
, fcount(0)
|
2011-09-21 21:16:12 -07:00
|
|
|
{
|
|
|
|
last = TimeStamp::Now();
|
|
|
|
}
|
2011-05-10 18:45:42 -07:00
|
|
|
void DrawFPS(GLContext*, CopyProgram*);
|
|
|
|
} mFPS;
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool sDrawFPS;
|
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() {
|
|
|
|
return nsnull;
|
|
|
|
}
|
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;
|
|
|
|
|
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
|
|
|
|
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 */
|