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/output/renderer.h"
13 #include "cc/resources/resource_provider.h"
14 #include "cc/resources/scoped_resource.h"
15 #include "cc/resources/task_graph_runner.h"
19 class ResourceProvider
;
21 // This is the base class for code shared between the GL and software
22 // renderer implementations. "Direct" refers to the fact that it does not
23 // delegate rendering to another compositor.
24 class CC_EXPORT DirectRenderer
: public Renderer
{
26 virtual ~DirectRenderer();
28 ResourceProvider
* resource_provider() const { return resource_provider_
; }
30 virtual bool CanReadPixels() const OVERRIDE
;
31 virtual void DecideRenderPassAllocationsForFrame(
32 const RenderPassList
& render_passes_in_draw_order
) OVERRIDE
;
33 virtual bool HasAllocatedResourcesForTesting(RenderPass::Id id
) const
35 virtual void DrawFrame(RenderPassList
* render_passes_in_draw_order
,
36 ContextProvider
* offscreen_context_provider
,
37 float device_scale_factor
,
38 const gfx::Rect
& device_viewport_rect
,
39 const gfx::Rect
& device_clip_rect
,
40 bool allow_partial_swap
,
41 bool disable_picture_quad_image_filtering
) OVERRIDE
;
43 struct CC_EXPORT DrawingFrame
{
47 const RenderPass
* root_render_pass
;
48 const RenderPass
* current_render_pass
;
49 const ScopedResource
* current_texture
;
51 gfx::RectF root_damage_rect
;
52 gfx::Rect device_viewport_rect
;
53 gfx::Rect device_clip_rect
;
55 gfx::Transform projection_matrix
;
56 gfx::Transform window_matrix
;
58 ContextProvider
* offscreen_context_provider
;
60 bool disable_picture_quad_image_filtering
;
63 void SetEnlargePassTextureAmountForTesting(const gfx::Vector2d
& amount
);
66 DirectRenderer(RendererClient
* client
,
67 const LayerTreeSettings
* settings
,
68 OutputSurface
* output_surface
,
69 ResourceProvider
* resource_provider
);
71 static gfx::RectF
QuadVertexRect();
72 static void QuadRectTransform(gfx::Transform
* quad_rect_transform
,
73 const gfx::Transform
& quad_transform
,
74 const gfx::RectF
& quad_rect
);
75 void InitializeViewport(DrawingFrame
* frame
,
76 const gfx::Rect
& draw_rect
,
77 const gfx::Rect
& viewport_rect
,
78 const gfx::Size
& surface_size
);
79 gfx::Rect
MoveFromDrawToWindowSpace(const gfx::RectF
& draw_rect
) const;
81 bool NeedDeviceClip(const DrawingFrame
* frame
) const;
82 gfx::Rect
DeviceClipRectInWindowSpace(const DrawingFrame
* frame
) const;
83 static gfx::RectF
ComputeScissorRectForRenderPass(const DrawingFrame
* frame
);
84 void SetScissorStateForQuad(const DrawingFrame
* frame
, const DrawQuad
& quad
);
85 void SetScissorStateForQuadWithRenderPassScissor(
86 const DrawingFrame
* frame
,
88 const gfx::RectF
& render_pass_scissor
,
89 bool* should_skip_quad
);
90 void SetScissorTestRectInDrawSpace(const DrawingFrame
* frame
,
91 const gfx::RectF
& draw_space_rect
);
93 static gfx::Size
RenderPassTextureSize(const RenderPass
* render_pass
);
95 void DrawRenderPass(DrawingFrame
* frame
,
96 const RenderPass
* render_pass
,
97 bool allow_partial_swap
);
98 bool UseRenderPass(DrawingFrame
* frame
, const RenderPass
* render_pass
);
100 void RunOnDemandRasterTask(internal::Task
* on_demand_raster_task
);
102 virtual void BindFramebufferToOutputSurface(DrawingFrame
* frame
) = 0;
103 virtual bool BindFramebufferToTexture(DrawingFrame
* frame
,
104 const ScopedResource
* resource
,
105 const gfx::Rect
& target_rect
) = 0;
106 virtual void SetDrawViewport(const gfx::Rect
& window_space_viewport
) = 0;
107 virtual void SetScissorTestRect(const gfx::Rect
& scissor_rect
) = 0;
108 virtual void DiscardPixels(bool has_external_stencil_test
,
109 bool draw_rect_covers_full_surface
) = 0;
110 virtual void ClearFramebuffer(DrawingFrame
* frame
,
111 bool has_external_stencil_test
) = 0;
112 virtual void DoDrawQuad(DrawingFrame
* frame
, const DrawQuad
* quad
) = 0;
113 virtual void BeginDrawingFrame(DrawingFrame
* frame
) = 0;
114 virtual void FinishDrawingFrame(DrawingFrame
* frame
) = 0;
115 virtual void FinishDrawingQuadList();
116 virtual bool FlippedFramebuffer() const = 0;
117 virtual void EnsureScissorTestEnabled() = 0;
118 virtual void EnsureScissorTestDisabled() = 0;
119 virtual void DiscardBackbuffer() {}
120 virtual void EnsureBackbuffer() {}
122 virtual void CopyCurrentRenderPassToBitmap(
124 scoped_ptr
<CopyOutputRequest
> request
) = 0;
126 base::ScopedPtrHashMap
<RenderPass::Id
, ScopedResource
> render_pass_textures_
;
127 OutputSurface
* output_surface_
;
128 ResourceProvider
* resource_provider_
;
130 // For use in coordinate conversion, this stores the output rect, viewport
131 // rect (= unflipped version of glViewport rect), and the size of target
132 // framebuffer. During a draw, this stores the values for the current render
133 // pass; in between draws, they retain the values for the root render pass of
135 gfx::Rect current_draw_rect_
;
136 gfx::Rect current_viewport_rect_
;
137 gfx::Size current_surface_size_
;
140 gfx::Vector2d enlarge_pass_texture_amount_
;
142 internal::NamespaceToken on_demand_task_namespace_
;
144 DISALLOW_COPY_AND_ASSIGN(DirectRenderer
);
149 #endif // CC_OUTPUT_DIRECT_RENDERER_H_