OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #ifndef CC_DIRECT_RENDERER_H_ | |
6 #define CC_DIRECT_RENDERER_H_ | |
7 | |
8 #include "base/basictypes.h" | |
9 #include "cc/base/cc_export.h" | |
10 #include "cc/renderer.h" | |
11 #include "cc/resource_provider.h" | |
12 #include "cc/scoped_resource.h" | |
13 | |
14 namespace cc { | |
15 | |
16 class ResourceProvider; | |
17 | |
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 { | |
22 public: | |
23 virtual ~DirectRenderer(); | |
24 | |
25 ResourceProvider* resource_provider() const { return resource_provider_; } | |
26 | |
27 virtual void DecideRenderPassAllocationsForFrame( | |
28 const RenderPassList& render_passes_in_draw_order) OVERRIDE; | |
29 virtual bool HaveCachedResourcesForRenderPassId(RenderPass::Id id) const | |
30 OVERRIDE; | |
31 virtual void DrawFrame(RenderPassList& render_passes_in_draw_order) OVERRIDE; | |
32 | |
33 struct CC_EXPORT DrawingFrame { | |
34 DrawingFrame(); | |
35 ~DrawingFrame(); | |
36 | |
37 const RenderPass* root_render_pass; | |
38 const RenderPass* current_render_pass; | |
39 const ScopedResource* current_texture; | |
40 | |
41 gfx::RectF root_damage_rect; | |
42 | |
43 gfx::Transform projection_matrix; | |
44 gfx::Transform window_matrix; | |
45 bool flipped_y; | |
46 }; | |
47 | |
48 void SetEnlargePassTextureAmountForTesting(gfx::Vector2d amount); | |
49 | |
50 protected: | |
51 DirectRenderer(RendererClient* client, ResourceProvider* resource_provider); | |
52 | |
53 class CachedResource : public ScopedResource { | |
54 public: | |
55 static scoped_ptr<CachedResource> Create( | |
56 ResourceProvider* resource_provider) { | |
57 return make_scoped_ptr(new CachedResource(resource_provider)); | |
58 } | |
59 virtual ~CachedResource() {} | |
60 | |
61 bool is_complete() const { return is_complete_; } | |
62 void set_is_complete(bool is_complete) { is_complete_ = is_complete; } | |
63 | |
64 protected: | |
65 explicit CachedResource(ResourceProvider* resource_provider) | |
66 : ScopedResource(resource_provider), | |
67 is_complete_(false) {} | |
68 | |
69 private: | |
70 bool is_complete_; | |
71 | |
72 DISALLOW_COPY_AND_ASSIGN(CachedResource); | |
73 }; | |
74 | |
75 static gfx::RectF QuadVertexRect(); | |
76 static void QuadRectTransform(gfx::Transform* quad_rect_transform, | |
77 const gfx::Transform& quad_transform, | |
78 const gfx::RectF& quad_rect); | |
79 static void InitializeMatrices(DrawingFrame& frame, | |
80 gfx::Rect draw_rect, | |
81 bool flip_y); | |
82 static gfx::Rect MoveScissorToWindowSpace(const DrawingFrame& frame, | |
83 const gfx::RectF& scissor_rect); | |
84 static gfx::RectF ComputeScissorRectForRenderPass(const DrawingFrame& frame); | |
85 void SetScissorStateForQuad(const DrawingFrame& frame, const DrawQuad& quad); | |
86 void SetScissorStateForQuadWithRenderPassScissor( | |
87 const DrawingFrame& frame, | |
88 const DrawQuad& quad, | |
89 const gfx::RectF& render_pass_scissor, | |
90 bool* should_skip_quad); | |
91 | |
92 static gfx::Size RenderPassTextureSize(const RenderPass* render_pass); | |
93 static GLenum RenderPassTextureFormat(const RenderPass* render_pass); | |
94 | |
95 void DrawRenderPass(DrawingFrame& frame, const RenderPass* render_pass); | |
96 bool UseRenderPass(DrawingFrame& frame, const RenderPass* render_pass); | |
97 | |
98 virtual void BindFramebufferToOutputSurface(DrawingFrame& frame) = 0; | |
99 virtual bool BindFramebufferToTexture(DrawingFrame& frame, | |
100 const ScopedResource* resource, | |
101 gfx::Rect framebuffer_rect) = 0; | |
102 virtual void SetDrawViewportSize(gfx::Size viewport_size) = 0; | |
103 virtual void SetScissorTestRect(gfx::Rect scissor_rect) = 0; | |
104 virtual void ClearFramebuffer(DrawingFrame& frame) = 0; | |
105 virtual void DoDrawQuad(DrawingFrame& frame, const DrawQuad* quad) = 0; | |
106 virtual void BeginDrawingFrame(DrawingFrame& frame) = 0; | |
107 virtual void FinishDrawingFrame(DrawingFrame& frame) = 0; | |
108 virtual void FinishDrawingQuadList(); | |
109 virtual bool FlippedFramebuffer() const = 0; | |
110 virtual void EnsureScissorTestEnabled() = 0; | |
111 virtual void EnsureScissorTestDisabled() = 0; | |
112 | |
113 ScopedPtrHashMap<RenderPass::Id, CachedResource> render_pass_textures_; | |
114 ResourceProvider* resource_provider_; | |
115 | |
116 private: | |
117 gfx::Vector2d enlarge_pass_texture_amount_; | |
118 | |
119 DISALLOW_COPY_AND_ASSIGN(DirectRenderer); | |
120 }; | |
121 | |
122 } // namespace cc | |
123 | |
124 #endif // CC_DIRECT_RENDERER_H_ | |
OLD | NEW |