#ifndef LayerRenderer_h
#define LayerRenderer_h
#if USE(ACCELERATED_COMPOSITING)
#include "IntRect.h"
#include "LayerData.h"
#include "TransformationMatrix.h"
#include <BlackBerryPlatformGLES2Context.h>
#include <BlackBerryPlatformIntRectRegion.h>
#include <wtf/HashSet.h>
#include <wtf/Noncopyable.h>
#include <wtf/PassOwnPtr.h>
#include <wtf/Vector.h>
namespace WebCore {
class LayerCompositingThread;
class LayerRendererSurface;
class LayerRenderingResults {
public:
LayerRenderingResults() : wasEmpty(true), needsAnimationFrame(false) { }
void addHolePunchRect(const IntRect&);
IntRect holePunchRect(size_t index) const;
size_t holePunchRectSize() { return m_holePunchRects.size(); }
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:
Vector<IntRect> m_holePunchRects; IntRect m_dirtyRects[NumberOfDirtyRects];
};
class LayerRenderer {
WTF_MAKE_NONCOPYABLE(LayerRenderer);
public:
static PassOwnPtr<LayerRenderer> create(BlackBerry::Platform::Graphics::GLES2Context*);
LayerRenderer(BlackBerry::Platform::Graphics::GLES2Context*);
~LayerRenderer();
void releaseLayerResources();
void drawLayers(const FloatRect& visibleRect, const IntRect& layoutRect, const IntSize& contentsSize, const IntRect& dstRect);
void setRootLayer(LayerCompositingThread*);
LayerCompositingThread* rootLayer() { return m_rootLayer.get(); }
void addLayer(LayerCompositingThread*);
bool removeLayer(LayerCompositingThread*);
void addLayerToReleaseTextureResourcesList(LayerCompositingThread*);
bool hardwareCompositing() const { return m_hardwareCompositing; }
void setClearSurfaceOnDrawLayers(bool clear) { m_clearSurfaceOnDrawLayers = clear; }
bool clearSurfaceOnDrawLayers() const { return m_clearSurfaceOnDrawLayers; }
BlackBerry::Platform::Graphics::GLES2Context* context() const { return m_context; }
const LayerRenderingResults& lastRenderingResults() const { return m_lastRenderingResults; }
void setNeedsCommit() { m_needsCommit = true; }
IntRect toWebKitDocumentCoordinates(const FloatRect&) const;
bool layerAlreadyOnSurface(LayerCompositingThread*) const;
private:
void updateLayersRecursive(LayerCompositingThread*, const TransformationMatrix& parentMatrix, Vector<RefPtr<LayerCompositingThread> >& surfaceLayers, float opacity, FloatRect clipRect, double currentTime);
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;
IntRect toWebKitWindowCoordinates(const FloatRect&) const;
void bindCommonAttribLocation(int location, const char* attribName);
bool makeContextCurrent();
bool initializeSharedGLObjects();
unsigned m_layerProgramObject[LayerData::NumberOfLayerProgramShaders];
unsigned m_layerMaskProgramObject[LayerData::NumberOfLayerProgramShaders];
unsigned m_colorProgramObject;
unsigned m_checkerProgramObject;
const int m_positionLocation;
const int m_texCoordLocation;
int m_samplerLocation[LayerData::NumberOfLayerProgramShaders];
int m_alphaLocation[LayerData::NumberOfLayerProgramShaders];
int m_maskSamplerLocation[LayerData::NumberOfLayerProgramShaders];
int m_maskSamplerLocationMask[LayerData::NumberOfLayerProgramShaders];
int m_maskAlphaLocation[LayerData::NumberOfLayerProgramShaders];
int m_colorColorLocation;
int m_checkerScaleLocation;
int m_checkerOriginLocation;
int m_checkerSurfaceHeightLocation;
FloatRect m_visibleRect;
IntRect m_layoutRect;
IntSize m_contentsSize;
IntRect m_viewport;
IntRect m_scissorRect;
RefPtr<LayerCompositingThread> m_rootLayer;
unsigned m_fbo;
LayerRendererSurface* m_currentLayerRendererSurface;
bool m_hardwareCompositing;
bool m_clearSurfaceOnDrawLayers;
typedef HashSet<LayerCompositingThread*> LayerSet;
LayerSet m_layers;
LayerSet m_layersLockingTextureResources;
BlackBerry::Platform::Graphics::GLES2Context* m_context;
LayerRenderingResults m_lastRenderingResults;
bool m_needsCommit;
};
}
#endif // USE(ACCELERATED_COMPOSITING)
#endif