1 // Copyright 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CCDirectRenderer_h
6 #define CCDirectRenderer_h
8 #include "base/basictypes.h"
9 #include "CCRenderer.h"
10 #include "CCResourceProvider.h"
11 #include "CCScopedTexture.h"
15 class CCResourceProvider
;
17 // This is the base class for code shared between the GL and software
18 // renderer implementations. "Direct" refers to the fact that it does not
19 // delegate rendering to another compositor.
20 class CCDirectRenderer
: public CCRenderer
{
22 virtual ~CCDirectRenderer();
24 CCResourceProvider
* resourceProvider() const { return m_resourceProvider
; }
26 virtual void decideRenderPassAllocationsForFrame(const CCRenderPassList
& renderPassesInDrawOrder
) OVERRIDE
;
27 virtual bool haveCachedResourcesForRenderPassId(CCRenderPass::Id
) const OVERRIDE
;
28 virtual void drawFrame(const CCRenderPassList
& renderPassesInDrawOrder
, const CCRenderPassIdHashMap
& renderPassesById
) OVERRIDE
;
31 CCDirectRenderer(CCRendererClient
* client
, CCResourceProvider
* resourceProvider
);
37 const CCRenderPassIdHashMap
* renderPassesById
;
38 const CCRenderPass
* rootRenderPass
;
39 const CCRenderPass
* currentRenderPass
;
40 const CCScopedTexture
* currentTexture
;
42 FloatRect rootDamageRect
;
44 WebKit::WebTransformationMatrix projectionMatrix
;
45 WebKit::WebTransformationMatrix windowMatrix
;
47 FloatRect scissorRectInRenderPassSpace
;
50 class CachedTexture
: public CCScopedTexture
{
52 static scoped_ptr
<CachedTexture
> create(CCResourceProvider
* resourceProvider
) {
53 return make_scoped_ptr(new CachedTexture(resourceProvider
));
55 virtual ~CachedTexture() {}
57 bool isComplete() const { return m_isComplete
; }
58 void setIsComplete(bool isComplete
) { m_isComplete
= isComplete
; }
61 explicit CachedTexture(CCResourceProvider
* resourceProvider
)
62 : CCScopedTexture(resourceProvider
)
70 DISALLOW_COPY_AND_ASSIGN(CachedTexture
);
73 static FloatRect
quadVertexRect();
74 static void quadRectTransform(WebKit::WebTransformationMatrix
* quadRectTransform
, const WebKit::WebTransformationMatrix
& quadTransform
, const FloatRect
& quadRect
);
75 static void initializeMatrices(DrawingFrame
&, const IntRect
& drawRect
, bool flipY
);
76 static IntRect
moveScissorToWindowSpace(const DrawingFrame
&, FloatRect scissorRect
);
78 bool haveCachedResources(CCRenderPass::Id
) const;
79 static IntSize
renderPassTextureSize(const CCRenderPass
*);
80 static GC3Denum
renderPassTextureFormat(const CCRenderPass
*);
82 void drawRenderPass(DrawingFrame
&, const CCRenderPass
*);
83 bool useRenderPass(DrawingFrame
&, const CCRenderPass
*);
85 virtual void bindFramebufferToOutputSurface(DrawingFrame
&) = 0;
86 virtual bool bindFramebufferToTexture(DrawingFrame
&, const CCScopedTexture
*, const IntRect
& framebufferRect
) = 0;
87 virtual void setDrawViewportSize(const IntSize
&) = 0;
88 virtual void enableScissorTestRect(const IntRect
& scissorRect
) = 0;
89 virtual void disableScissorTest() = 0;
90 virtual void clearFramebuffer(DrawingFrame
&) = 0;
91 virtual void drawQuad(DrawingFrame
&, const CCDrawQuad
*) = 0;
92 virtual void beginDrawingFrame(DrawingFrame
&) = 0;
93 virtual void finishDrawingFrame(DrawingFrame
&) = 0;
94 virtual bool flippedFramebuffer() const = 0;
96 ScopedPtrHashMap
<CCRenderPass::Id
, CachedTexture
> m_renderPassTextures
;
97 CCResourceProvider
* m_resourceProvider
;
100 DISALLOW_COPY_AND_ASSIGN(CCDirectRenderer
);
105 #endif // CCDirectRenderer_h