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 "base/callback.h"
10 #include "base/containers/scoped_ptr_hash_map.h"
11 #include "cc/base/cc_export.h"
12 #include "cc/base/scoped_ptr_deque.h"
13 #include "cc/output/overlay_processor.h"
14 #include "cc/output/renderer.h"
15 #include "cc/resources/resource_provider.h"
16 #include "cc/resources/scoped_resource.h"
17 #include "cc/resources/task_graph_runner.h"
18 #include "ui/gfx/geometry/quad_f.h"
23 class ResourceProvider
;
25 // This is the base class for code shared between the GL and software
26 // renderer implementations. "Direct" refers to the fact that it does not
27 // delegate rendering to another compositor.
28 class CC_EXPORT DirectRenderer
: public Renderer
{
30 ~DirectRenderer() override
;
32 void DecideRenderPassAllocationsForFrame(
33 const RenderPassList
& render_passes_in_draw_order
) override
;
34 bool HasAllocatedResourcesForTesting(RenderPassId id
) const override
;
35 void DrawFrame(RenderPassList
* render_passes_in_draw_order
,
36 float device_scale_factor
,
37 const gfx::Rect
& device_viewport_rect
,
38 const gfx::Rect
& device_clip_rect
,
39 bool disable_picture_quad_image_filtering
) override
;
41 struct CC_EXPORT DrawingFrame
{
45 const RenderPassList
* render_passes_in_draw_order
;
46 const RenderPass
* root_render_pass
;
47 const RenderPass
* current_render_pass
;
48 const ScopedResource
* current_texture
;
50 gfx::Rect root_damage_rect
;
51 gfx::Rect device_viewport_rect
;
52 gfx::Rect device_clip_rect
;
54 gfx::Transform projection_matrix
;
55 gfx::Transform window_matrix
;
57 bool disable_picture_quad_image_filtering
;
59 OverlayCandidateList overlay_list
;
62 void SetEnlargePassTextureAmountForTesting(const gfx::Vector2d
& amount
);
63 void DoDrawPolygon(const DrawPolygon
& poly
,
65 const gfx::Rect
& render_pass_scissor
,
66 bool use_render_pass_scissor
);
69 enum SurfaceInitializationMode
{
70 SURFACE_INITIALIZATION_MODE_PRESERVE
,
71 SURFACE_INITIALIZATION_MODE_SCISSORED_CLEAR
,
72 SURFACE_INITIALIZATION_MODE_FULL_SURFACE_CLEAR
,
75 DirectRenderer(RendererClient
* client
,
76 const RendererSettings
* settings
,
77 OutputSurface
* output_surface
,
78 ResourceProvider
* resource_provider
);
80 static gfx::RectF
QuadVertexRect();
81 static void QuadRectTransform(gfx::Transform
* quad_rect_transform
,
82 const gfx::Transform
& quad_transform
,
83 const gfx::RectF
& quad_rect
);
84 void InitializeViewport(DrawingFrame
* frame
,
85 const gfx::Rect
& draw_rect
,
86 const gfx::Rect
& viewport_rect
,
87 const gfx::Size
& surface_size
);
88 gfx::Rect
MoveFromDrawToWindowSpace(const DrawingFrame
* frame
,
89 const gfx::Rect
& draw_rect
) const;
91 bool NeedDeviceClip(const DrawingFrame
* frame
) const;
92 gfx::Rect
DeviceClipRectInDrawSpace(const DrawingFrame
* frame
) const;
93 gfx::Rect
DeviceViewportRectInDrawSpace(const DrawingFrame
* frame
) const;
94 gfx::Rect
OutputSurfaceRectInDrawSpace(const DrawingFrame
* frame
) const;
95 static gfx::Rect
ComputeScissorRectForRenderPass(const DrawingFrame
* frame
);
96 void SetScissorStateForQuad(const DrawingFrame
* frame
,
98 const gfx::Rect
& render_pass_scissor
,
99 bool use_render_pass_scissor
);
100 bool ShouldSkipQuad(const DrawQuad
& quad
,
101 const gfx::Rect
& render_pass_scissor
);
102 void SetScissorTestRectInDrawSpace(const DrawingFrame
* frame
,
103 const gfx::Rect
& draw_space_rect
);
105 static gfx::Size
RenderPassTextureSize(const RenderPass
* render_pass
);
107 void FlushPolygons(ScopedPtrDeque
<DrawPolygon
>* poly_list
,
109 const gfx::Rect
& render_pass_scissor
,
110 bool use_render_pass_scissor
);
111 void DrawRenderPass(DrawingFrame
* frame
, const RenderPass
* render_pass
);
112 bool UseRenderPass(DrawingFrame
* frame
, const RenderPass
* render_pass
);
114 virtual void BindFramebufferToOutputSurface(DrawingFrame
* frame
) = 0;
115 virtual bool BindFramebufferToTexture(DrawingFrame
* frame
,
116 const ScopedResource
* resource
,
117 const gfx::Rect
& target_rect
) = 0;
118 virtual void SetScissorTestRect(const gfx::Rect
& scissor_rect
) = 0;
119 virtual void PrepareSurfaceForPass(
121 SurfaceInitializationMode initialization_mode
,
122 const gfx::Rect
& render_pass_scissor
) = 0;
123 // clip_region is a (possibly null) pointer to a quad in the same
124 // space as the quad. When non-null only the area of the quad that overlaps
125 // with clip_region will be drawn.
126 virtual void DoDrawQuad(DrawingFrame
* frame
,
127 const DrawQuad
* quad
,
128 const gfx::QuadF
* clip_region
) = 0;
129 virtual void BeginDrawingFrame(DrawingFrame
* frame
) = 0;
130 virtual void FinishDrawingFrame(DrawingFrame
* frame
) = 0;
131 virtual void FinishDrawingQuadList();
132 virtual bool FlippedFramebuffer(const DrawingFrame
* frame
) const = 0;
133 virtual void EnsureScissorTestEnabled() = 0;
134 virtual void EnsureScissorTestDisabled() = 0;
135 virtual void DiscardBackbuffer() {}
136 virtual void EnsureBackbuffer() {}
138 virtual void CopyCurrentRenderPassToBitmap(
140 scoped_ptr
<CopyOutputRequest
> request
) = 0;
142 base::ScopedPtrHashMap
<RenderPassId
, ScopedResource
> render_pass_textures_
;
143 OutputSurface
* output_surface_
;
144 ResourceProvider
* resource_provider_
;
145 scoped_ptr
<OverlayProcessor
> overlay_processor_
;
147 // For use in coordinate conversion, this stores the output rect, viewport
148 // rect (= unflipped version of glViewport rect), the size of target
149 // framebuffer, and the current window space viewport. During a draw, this
150 // stores the values for the current render pass; in between draws, they
151 // retain the values for the root render pass of the last draw.
152 gfx::Rect current_draw_rect_
;
153 gfx::Rect current_viewport_rect_
;
154 gfx::Size current_surface_size_
;
155 gfx::Rect current_window_space_viewport_
;
158 gfx::Vector2d enlarge_pass_texture_amount_
;
160 DISALLOW_COPY_AND_ASSIGN(DirectRenderer
);
165 #endif // CC_OUTPUT_DIRECT_RENDERER_H_