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 CC_DIRECT_RENDERER_H_
6 #define CC_DIRECT_RENDERER_H_
8 #include "base/basictypes.h"
9 #include "cc/cc_export.h"
10 #include "cc/renderer.h"
11 #include "cc/resource_provider.h"
12 #include "cc/scoped_resource.h"
16 class ResourceProvider
;
18 // This is the base class for code shared between the GL and software
19 // renderer implementations. "Direct" refers to the fact that it does not
20 // delegate rendering to another compositor.
21 class CC_EXPORT DirectRenderer
: public Renderer
{
23 virtual ~DirectRenderer();
25 ResourceProvider
* resourceProvider() const { return m_resourceProvider
; }
27 virtual void decideRenderPassAllocationsForFrame(const RenderPassList
& renderPassesInDrawOrder
) OVERRIDE
;
28 virtual bool haveCachedResourcesForRenderPassId(RenderPass::Id
) const OVERRIDE
;
29 virtual void drawFrame(RenderPassList
& renderPassesInDrawOrder
, RenderPassIdHashMap
& renderPassesById
) OVERRIDE
;
31 struct CC_EXPORT DrawingFrame
{
35 const RenderPassIdHashMap
* renderPassesById
;
36 const RenderPass
* rootRenderPass
;
37 const RenderPass
* currentRenderPass
;
38 const ScopedResource
* currentTexture
;
40 gfx::RectF rootDamageRect
;
42 gfx::Transform projectionMatrix
;
43 gfx::Transform windowMatrix
;
48 DirectRenderer(RendererClient
* client
, ResourceProvider
* resourceProvider
);
50 class CachedResource
: public ScopedResource
{
52 static scoped_ptr
<CachedResource
> create(ResourceProvider
* resourceProvider
) {
53 return make_scoped_ptr(new CachedResource(resourceProvider
));
55 virtual ~CachedResource() {}
57 bool isComplete() const { return m_isComplete
; }
58 void setIsComplete(bool isComplete
) { m_isComplete
= isComplete
; }
61 explicit CachedResource(ResourceProvider
* resourceProvider
)
62 : ScopedResource(resourceProvider
)
70 DISALLOW_COPY_AND_ASSIGN(CachedResource
);
73 static gfx::RectF
quadVertexRect();
74 static void quadRectTransform(gfx::Transform
* quadRectTransform
, const gfx::Transform
& quadTransform
, const gfx::RectF
& quadRect
);
75 static void initializeMatrices(DrawingFrame
&, const gfx::Rect
& drawRect
, bool flipY
);
76 static gfx::Rect
moveScissorToWindowSpace(const DrawingFrame
&, gfx::RectF scissorRect
);
77 static gfx::RectF
computeScissorRectForRenderPass(const DrawingFrame
& frame
);
78 void setScissorStateForQuad(const DrawingFrame
& frame
, const DrawQuad
& quad
);
79 void setScissorStateForQuadWithRenderPassScissor(const DrawingFrame
& frame
, const DrawQuad
& quad
, const gfx::RectF
& renderPassScissor
, bool* shouldSkipQuad
);
81 bool haveCachedResources(RenderPass::Id
) const;
82 static gfx::Size
renderPassTextureSize(const RenderPass
*);
83 static GLenum
renderPassTextureFormat(const RenderPass
*);
85 void drawRenderPass(DrawingFrame
&, const RenderPass
*);
86 bool useRenderPass(DrawingFrame
&, const RenderPass
*);
88 virtual void bindFramebufferToOutputSurface(DrawingFrame
&) = 0;
89 virtual bool bindFramebufferToTexture(DrawingFrame
&, const ScopedResource
*, const gfx::Rect
& framebufferRect
) = 0;
90 virtual void setDrawViewportSize(const gfx::Size
&) = 0;
91 virtual void setScissorTestRect(const gfx::Rect
& scissorRect
) = 0;
92 virtual void clearFramebuffer(DrawingFrame
&) = 0;
93 virtual void drawQuad(DrawingFrame
&, const DrawQuad
*) = 0;
94 virtual void beginDrawingFrame(DrawingFrame
&) = 0;
95 virtual void finishDrawingFrame(DrawingFrame
&) = 0;
96 virtual void finishDrawingQuadList();
97 virtual bool flippedFramebuffer() const = 0;
98 virtual void ensureScissorTestEnabled() = 0;
99 virtual void ensureScissorTestDisabled() = 0;
101 ScopedPtrHashMap
<RenderPass::Id
, CachedResource
> m_renderPassTextures
;
102 ResourceProvider
* m_resourceProvider
;
105 DISALLOW_COPY_AND_ASSIGN(DirectRenderer
);
110 #endif // CC_DIRECT_RENDERER_H_