Add signalSyncPoint to the WebGraphicsContext3D command buffer impls.
[chromium-blink-merge.git] / cc / output / direct_renderer.h
blob41537507068bb94f6b8f743acd54b7d0860906f6
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_OUTPUT_DIRECT_RENDERER_H_
6 #define CC_OUTPUT_DIRECT_RENDERER_H_
8 #include "base/basictypes.h"
9 #include "cc/base/cc_export.h"
10 #include "cc/output/renderer.h"
11 #include "cc/resources/resource_provider.h"
12 #include "cc/resources/scoped_resource.h"
14 namespace cc {
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 {
22 public:
23 virtual ~DirectRenderer();
25 ResourceProvider* resource_provider() const { return resource_provider_; }
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;
33 struct CC_EXPORT DrawingFrame {
34 DrawingFrame();
35 ~DrawingFrame();
37 const RenderPass* root_render_pass;
38 const RenderPass* current_render_pass;
39 const ScopedResource* current_texture;
41 gfx::RectF root_damage_rect;
43 gfx::Transform projection_matrix;
44 gfx::Transform window_matrix;
45 bool flipped_y;
48 void SetEnlargePassTextureAmountForTesting(gfx::Vector2d amount);
50 protected:
51 DirectRenderer(RendererClient* client, ResourceProvider* resource_provider);
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));
59 virtual ~CachedResource() {}
61 bool is_complete() const { return is_complete_; }
62 void set_is_complete(bool is_complete) { is_complete_ = is_complete; }
64 protected:
65 explicit CachedResource(ResourceProvider* resource_provider)
66 : ScopedResource(resource_provider),
67 is_complete_(false) {}
69 private:
70 bool is_complete_;
72 DISALLOW_COPY_AND_ASSIGN(CachedResource);
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);
92 static gfx::Size RenderPassTextureSize(const RenderPass* render_pass);
93 static GLenum RenderPassTextureFormat(const RenderPass* render_pass);
95 void DrawRenderPass(DrawingFrame* frame, const RenderPass* render_pass);
96 bool UseRenderPass(DrawingFrame* frame, const RenderPass* render_pass);
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 virtual void CopyCurrentRenderPassToBitmap(DrawingFrame* frame,
113 SkBitmap* bitmap) = 0;
115 ScopedPtrHashMap<RenderPass::Id, CachedResource> render_pass_textures_;
116 ResourceProvider* resource_provider_;
118 private:
119 gfx::Vector2d enlarge_pass_texture_amount_;
121 DISALLOW_COPY_AND_ASSIGN(DirectRenderer);
124 } // namespace cc
126 #endif // CC_OUTPUT_DIRECT_RENDERER_H_