#ifndef LayerRenderer_h
#define LayerRenderer_h
#if USE(ACCELERATED_COMPOSITING)
#include "Extensions3DOpenGLES.h"
#include "IntRect.h"
#include "LayerData.h"
#include "LayerFilterRenderer.h"
#include "TransformationMatrix.h"
#include <BlackBerryPlatformGLES2Context.h>
#include <BlackBerryPlatformGLES2Program.h>
#include <BlackBerryPlatformIntRectRegion.h>
#include <wtf/HashSet.h>
#include <wtf/Noncopyable.h>
#include <wtf/PassOwnPtr.h>
#include <wtf/Vector.h>
namespace WebCore {
class Color;
class LayerCompositingThread;
class LayerRendererClient;
class LayerRendererSurface;
class LayerRenderingResults {
public:
LayerRenderingResults() : wasEmpty(true), needsAnimationFrame(false) { }
static const int NumberOfDirtyRects = 3;
const IntRect& dirtyRect(int i) const { return m_dirtyRects[i]; }
void addDirtyRect(const IntRect& dirtyRect);
bool isEmpty() const;
bool wasEmpty;
BlackBerry::Platform::IntRectRegion dirtyRegion;
bool needsAnimationFrame;
private:
IntRect m_dirtyRects[NumberOfDirtyRects];
};
class LayerRenderer {
WTF_MAKE_NONCOPYABLE(LayerRenderer);
public:
static TransformationMatrix orthoMatrix(float left, float right, float bottom, float top, float nearZ, float farZ);
static PassOwnPtr<LayerRenderer> create(LayerRendererClient*);
LayerRenderer(LayerRendererClient*);
~LayerRenderer();
LayerRendererClient* client() const { return m_client; }
void releaseLayerResources();
void prepareFrame(double animationTime, LayerCompositingThread* rootLayer);
void setViewport(const IntRect& viewport, const IntRect& clipRect, const FloatRect& visibleRect, const IntRect& layoutRect, const IntSize& contentsSize);
void compositeLayers(const TransformationMatrix&, LayerCompositingThread* rootLayer);
void compositeBuffer(const TransformationMatrix&, const FloatRect& contents, BlackBerry::Platform::Graphics::Buffer*, bool contentsOpaque, float opacity);
void drawColor(const TransformationMatrix&, const FloatRect& contents, const Color&);
void addLayer(LayerCompositingThread*);
bool removeLayer(LayerCompositingThread*);
void addLayerToReleaseTextureResourcesList(LayerCompositingThread*);
bool hardwareCompositing() const { return m_hardwareCompositing; }
BlackBerry::Platform::Graphics::GLES2Context* context() const;
const LayerRenderingResults& lastRenderingResults() const { return m_lastRenderingResults; }
void setNeedsCommit() { m_needsCommit = true; }
IntRect toWindowCoordinates(const FloatRect&) const;
IntRect toPixelViewportCoordinates(const FloatRect&) const;
IntRect toDocumentViewportCoordinates(const FloatRect&) const;
bool layerAlreadyOnSurface(LayerCompositingThread*) const;
void drawDebugBorder(const Vector<FloatPoint>&, const Color&, float borderWidth);
static GLuint loadShader(GLenum type, const char* shaderSource);
static GLuint loadShaderProgram(const char* vertexShaderSource, const char* fragmentShaderSource);
private:
void prepareFrameRecursive(LayerCompositingThread*, double animationTime, bool isContextCurrent);
void updateLayersRecursive(LayerCompositingThread*, const TransformationMatrix& parentMatrix, const TransformationMatrix& projectionMatrix, Vector<RefPtr<LayerCompositingThread> >& surfaceLayers, float opacity, FloatRect clipRect);
void compositeLayersRecursive(LayerCompositingThread*, int stencilValue, FloatRect clipRect);
void updateScissorIfNeeded(const FloatRect& clipRect);
bool useSurface(LayerRendererSurface*);
void drawLayersOnSurfaces(const Vector<RefPtr<LayerCompositingThread> >& surfaceLayers);
void drawDebugBorder(LayerCompositingThread*);
void drawHolePunchRect(LayerCompositingThread*);
IntRect toOpenGLWindowCoordinates(const FloatRect&) const;
bool makeContextCurrent();
enum ProgramIndex {
LayerProgramRGBA = LayerData::LayerProgramRGBA,
LayerProgramBGRA = LayerData::LayerProgramBGRA,
MaskPrograms,
LayerMaskProgramRGBA = MaskPrograms + LayerData::LayerProgramRGBA,
LayerMaskProgramBGRA = MaskPrograms + LayerData::LayerProgramBGRA,
InternalPrograms,
ColorProgram = InternalPrograms,
NumberOfPrograms
};
bool createProgram(ProgramIndex);
const BlackBerry::Platform::Graphics::GLES2Program& useProgram(ProgramIndex);
const BlackBerry::Platform::Graphics::GLES2Program& useLayerProgram(LayerData::LayerProgram, bool isMask = false);
LayerRendererClient* m_client;
BlackBerry::Platform::Graphics::GLES2Program m_programs[NumberOfPrograms];
#if ENABLE(CSS_FILTERS)
OwnPtr<LayerFilterRenderer> m_filterRenderer;
#endif
int m_colorColorLocation;
double m_scale;
double m_animationTime;
FloatRect m_visibleRect;
IntRect m_layoutRect;
IntSize m_contentsSize;
IntRect m_viewport; IntRect m_scissorRect; FloatRect m_clipRect;
unsigned m_fbo;
LayerRendererSurface* m_currentLayerRendererSurface;
bool m_hardwareCompositing;
typedef HashSet<LayerCompositingThread*> LayerSet;
LayerSet m_layers;
LayerSet m_layersLockingTextureResources;
bool m_isRobustnessSupported;
PFNGLGETGRAPHICSRESETSTATUSEXTPROC m_glGetGraphicsResetStatusEXT;
LayerRenderingResults m_lastRenderingResults;
bool m_needsCommit;
bool m_stencilCleared;
};
}
#endif // USE(ACCELERATED_COMPOSITING)
#endif