Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1031)

Side by Side Diff: cc/output/direct_renderer.h

Issue 2680203005: cc: Use DrawingFrame as state, not function argument (Closed)
Patch Set: Add reset Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « cc/output/bsp_walk_action.cc ('k') | cc/output/direct_renderer.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CC_OUTPUT_DIRECT_RENDERER_H_ 5 #ifndef CC_OUTPUT_DIRECT_RENDERER_H_
6 #define CC_OUTPUT_DIRECT_RENDERER_H_ 6 #define CC_OUTPUT_DIRECT_RENDERER_H_
7 7
8 #include <memory> 8 #include <memory>
9 #include <unordered_map> 9 #include <unordered_map>
10 #include <vector> 10 #include <vector>
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 // Allow tests to enlarge the texture size of non-root render passes to 67 // Allow tests to enlarge the texture size of non-root render passes to
68 // verify cases where the texture doesn't match the render pass size. 68 // verify cases where the texture doesn't match the render pass size.
69 void SetEnlargePassTextureAmountForTesting(const gfx::Size& amount) { 69 void SetEnlargePassTextureAmountForTesting(const gfx::Size& amount) {
70 enlarge_pass_texture_amount_ = amount; 70 enlarge_pass_texture_amount_ = amount;
71 } 71 }
72 72
73 // Public for tests that poke at internals. 73 // Public for tests that poke at internals.
74 struct CC_EXPORT DrawingFrame { 74 struct CC_EXPORT DrawingFrame {
75 DrawingFrame(); 75 DrawingFrame();
76 ~DrawingFrame(); 76 ~DrawingFrame();
77 gfx::Rect ComputeScissorRectForRenderPass() const;
77 78
78 const RenderPassList* render_passes_in_draw_order = nullptr; 79 const RenderPassList* render_passes_in_draw_order = nullptr;
79 const RenderPass* root_render_pass = nullptr; 80 const RenderPass* root_render_pass = nullptr;
80 const RenderPass* current_render_pass = nullptr; 81 const RenderPass* current_render_pass = nullptr;
81 const ScopedResource* current_texture = nullptr; 82 const ScopedResource* current_texture = nullptr;
82 83
83 gfx::Rect root_damage_rect; 84 gfx::Rect root_damage_rect;
84 gfx::Size device_viewport_size; 85 gfx::Size device_viewport_size;
85 gfx::ColorSpace device_color_space; 86 gfx::ColorSpace device_color_space;
86 87
(...skipping 10 matching lines...) Expand all
97 enum SurfaceInitializationMode { 98 enum SurfaceInitializationMode {
98 SURFACE_INITIALIZATION_MODE_PRESERVE, 99 SURFACE_INITIALIZATION_MODE_PRESERVE,
99 SURFACE_INITIALIZATION_MODE_SCISSORED_CLEAR, 100 SURFACE_INITIALIZATION_MODE_SCISSORED_CLEAR,
100 SURFACE_INITIALIZATION_MODE_FULL_SURFACE_CLEAR, 101 SURFACE_INITIALIZATION_MODE_FULL_SURFACE_CLEAR,
101 }; 102 };
102 103
103 static gfx::RectF QuadVertexRect(); 104 static gfx::RectF QuadVertexRect();
104 static void QuadRectTransform(gfx::Transform* quad_rect_transform, 105 static void QuadRectTransform(gfx::Transform* quad_rect_transform,
105 const gfx::Transform& quad_transform, 106 const gfx::Transform& quad_transform,
106 const gfx::RectF& quad_rect); 107 const gfx::RectF& quad_rect);
108 // This function takes DrawingFrame as an argument because RenderPass drawing
109 // code uses its computations for buffer sizing.
107 void InitializeViewport(DrawingFrame* frame, 110 void InitializeViewport(DrawingFrame* frame,
108 const gfx::Rect& draw_rect, 111 const gfx::Rect& draw_rect,
109 const gfx::Rect& viewport_rect, 112 const gfx::Rect& viewport_rect,
110 const gfx::Size& surface_size); 113 const gfx::Size& surface_size);
111 gfx::Rect MoveFromDrawToWindowSpace(const DrawingFrame* frame, 114 gfx::Rect MoveFromDrawToWindowSpace(const gfx::Rect& draw_rect) const;
112 const gfx::Rect& draw_rect) const;
113 115
114 gfx::Rect DeviceViewportRectInDrawSpace(const DrawingFrame* frame) const; 116 gfx::Rect DeviceViewportRectInDrawSpace() const;
115 gfx::Rect OutputSurfaceRectInDrawSpace(const DrawingFrame* frame) const; 117 gfx::Rect OutputSurfaceRectInDrawSpace() const;
116 static gfx::Rect ComputeScissorRectForRenderPass(const DrawingFrame* frame); 118 void SetScissorStateForQuad(const DrawQuad& quad,
117 void SetScissorStateForQuad(const DrawingFrame* frame,
118 const DrawQuad& quad,
119 const gfx::Rect& render_pass_scissor, 119 const gfx::Rect& render_pass_scissor,
120 bool use_render_pass_scissor); 120 bool use_render_pass_scissor);
121 bool ShouldSkipQuad(const DrawQuad& quad, 121 bool ShouldSkipQuad(const DrawQuad& quad,
122 const gfx::Rect& render_pass_scissor); 122 const gfx::Rect& render_pass_scissor);
123 void SetScissorTestRectInDrawSpace(const DrawingFrame* frame, 123 void SetScissorTestRectInDrawSpace(const gfx::Rect& draw_space_rect);
124 const gfx::Rect& draw_space_rect);
125 124
126 static gfx::Size RenderPassTextureSize(const RenderPass* render_pass); 125 static gfx::Size RenderPassTextureSize(const RenderPass* render_pass);
127 126
128 void FlushPolygons(std::deque<std::unique_ptr<DrawPolygon>>* poly_list, 127 void FlushPolygons(std::deque<std::unique_ptr<DrawPolygon>>* poly_list,
129 DrawingFrame* frame,
130 const gfx::Rect& render_pass_scissor, 128 const gfx::Rect& render_pass_scissor,
131 bool use_render_pass_scissor); 129 bool use_render_pass_scissor);
132 void DrawRenderPassAndExecuteCopyRequests(DrawingFrame* frame, 130 void DrawRenderPassAndExecuteCopyRequests(RenderPass* render_pass);
133 RenderPass* render_pass); 131 void DrawRenderPass(const RenderPass* render_pass);
134 void DrawRenderPass(DrawingFrame* frame, const RenderPass* render_pass); 132 bool UseRenderPass(const RenderPass* render_pass);
135 bool UseRenderPass(DrawingFrame* frame, const RenderPass* render_pass);
136 133
137 void DoDrawPolygon(const DrawPolygon& poly, 134 void DoDrawPolygon(const DrawPolygon& poly,
138 DrawingFrame* frame,
139 const gfx::Rect& render_pass_scissor, 135 const gfx::Rect& render_pass_scissor,
140 bool use_render_pass_scissor); 136 bool use_render_pass_scissor);
141 137
142 const FilterOperations* FiltersForPass(int render_pass_id) const; 138 const FilterOperations* FiltersForPass(int render_pass_id) const;
143 const FilterOperations* BackgroundFiltersForPass(int render_pass_id) const; 139 const FilterOperations* BackgroundFiltersForPass(int render_pass_id) const;
144 140
145 // Private interface implemented by subclasses for use by DirectRenderer. 141 // Private interface implemented by subclasses for use by DirectRenderer.
146 virtual bool CanPartialSwap() = 0; 142 virtual bool CanPartialSwap() = 0;
147 virtual ResourceFormat BackbufferFormat() const = 0; 143 virtual ResourceFormat BackbufferFormat() const = 0;
148 virtual void BindFramebufferToOutputSurface(DrawingFrame* frame) = 0; 144 virtual void BindFramebufferToOutputSurface() = 0;
149 virtual bool BindFramebufferToTexture(DrawingFrame* frame, 145 virtual bool BindFramebufferToTexture(const ScopedResource* resource) = 0;
150 const ScopedResource* resource) = 0;
151 virtual void SetScissorTestRect(const gfx::Rect& scissor_rect) = 0; 146 virtual void SetScissorTestRect(const gfx::Rect& scissor_rect) = 0;
152 virtual void PrepareSurfaceForPass( 147 virtual void PrepareSurfaceForPass(
153 DrawingFrame* frame,
154 SurfaceInitializationMode initialization_mode, 148 SurfaceInitializationMode initialization_mode,
155 const gfx::Rect& render_pass_scissor) = 0; 149 const gfx::Rect& render_pass_scissor) = 0;
156 // |clip_region| is a (possibly null) pointer to a quad in the same 150 // |clip_region| is a (possibly null) pointer to a quad in the same
157 // space as the quad. When non-null only the area of the quad that overlaps 151 // space as the quad. When non-null only the area of the quad that overlaps
158 // with clip_region will be drawn. 152 // with clip_region will be drawn.
159 virtual void DoDrawQuad(DrawingFrame* frame, 153 virtual void DoDrawQuad(const DrawQuad* quad,
160 const DrawQuad* quad,
161 const gfx::QuadF* clip_region) = 0; 154 const gfx::QuadF* clip_region) = 0;
162 virtual void BeginDrawingFrame(DrawingFrame* frame) = 0; 155 virtual void BeginDrawingFrame() = 0;
163 virtual void FinishDrawingFrame(DrawingFrame* frame) = 0; 156 virtual void FinishDrawingFrame() = 0;
164 // If a pass contains a single tile draw quad and can be drawn without 157 // If a pass contains a single tile draw quad and can be drawn without
165 // a render pass (e.g. applying a filter directly to the tile quad) 158 // a render pass (e.g. applying a filter directly to the tile quad)
166 // return that quad, otherwise return null. 159 // return that quad, otherwise return null.
167 virtual const TileDrawQuad* CanPassBeDrawnDirectly(const RenderPass* pass); 160 virtual const TileDrawQuad* CanPassBeDrawnDirectly(const RenderPass* pass);
168 virtual void FinishDrawingQuadList() {} 161 virtual void FinishDrawingQuadList() {}
169 virtual bool FlippedFramebuffer(const DrawingFrame* frame) const = 0; 162 virtual bool FlippedFramebuffer() const = 0;
170 virtual void EnsureScissorTestEnabled() = 0; 163 virtual void EnsureScissorTestEnabled() = 0;
171 virtual void EnsureScissorTestDisabled() = 0; 164 virtual void EnsureScissorTestDisabled() = 0;
172 virtual void DidChangeVisibility() = 0; 165 virtual void DidChangeVisibility() = 0;
173 virtual void CopyCurrentRenderPassToBitmap( 166 virtual void CopyCurrentRenderPassToBitmap(
174 DrawingFrame* frame,
175 std::unique_ptr<CopyOutputRequest> request) = 0; 167 std::unique_ptr<CopyOutputRequest> request) = 0;
176 168
177 gfx::Size surface_size_for_swap_buffers() const { 169 gfx::Size surface_size_for_swap_buffers() const {
178 return reshape_surface_size_; 170 return reshape_surface_size_;
179 } 171 }
180 172
181 const RendererSettings* const settings_; 173 const RendererSettings* const settings_;
182 OutputSurface* const output_surface_; 174 OutputSurface* const output_surface_;
183 ResourceProvider* const resource_provider_; 175 ResourceProvider* const resource_provider_;
184 // This can be replaced by test implementations. 176 // This can be replaced by test implementations.
(...skipping 20 matching lines...) Expand all
205 // For use in coordinate conversion, this stores the output rect, viewport 197 // For use in coordinate conversion, this stores the output rect, viewport
206 // rect (= unflipped version of glViewport rect), the size of target 198 // rect (= unflipped version of glViewport rect), the size of target
207 // framebuffer, and the current window space viewport. During a draw, this 199 // framebuffer, and the current window space viewport. During a draw, this
208 // stores the values for the current render pass; in between draws, they 200 // stores the values for the current render pass; in between draws, they
209 // retain the values for the root render pass of the last draw. 201 // retain the values for the root render pass of the last draw.
210 gfx::Rect current_draw_rect_; 202 gfx::Rect current_draw_rect_;
211 gfx::Rect current_viewport_rect_; 203 gfx::Rect current_viewport_rect_;
212 gfx::Size current_surface_size_; 204 gfx::Size current_surface_size_;
213 gfx::Rect current_window_space_viewport_; 205 gfx::Rect current_window_space_viewport_;
214 206
207 DrawingFrame* current_frame() {
208 DCHECK(current_frame_valid_);
209 return &current_frame_;
210 }
211 const DrawingFrame* current_frame() const {
212 DCHECK(current_frame_valid_);
213 return &current_frame_;
214 }
215
216 void SetCurrentFrameForTesting(const DrawingFrame& frame);
217
215 private: 218 private:
216 bool initialized_ = false; 219 bool initialized_ = false;
217 #if DCHECK_IS_ON() 220 #if DCHECK_IS_ON()
218 bool overdraw_feedback_support_missing_logged_once_ = false; 221 bool overdraw_feedback_support_missing_logged_once_ = false;
219 #endif 222 #endif
220 gfx::Size enlarge_pass_texture_amount_; 223 gfx::Size enlarge_pass_texture_amount_;
221 224
225 // The current drawing frame is valid only during the duration of the
226 // DrawFrame function. Use the accessor current_frame() to ensure that use
227 // is valid;
228 DrawingFrame current_frame_;
229 bool current_frame_valid_ = false;
230
222 // Cached values given to Reshape(). 231 // Cached values given to Reshape().
223 gfx::Size reshape_surface_size_; 232 gfx::Size reshape_surface_size_;
224 float reshape_device_scale_factor_ = 0.f; 233 float reshape_device_scale_factor_ = 0.f;
225 gfx::ColorSpace reshape_device_color_space_; 234 gfx::ColorSpace reshape_device_color_space_;
226 bool reshape_has_alpha_ = false; 235 bool reshape_has_alpha_ = false;
227 bool reshape_use_stencil_ = false; 236 bool reshape_use_stencil_ = false;
228 237
229 DISALLOW_COPY_AND_ASSIGN(DirectRenderer); 238 DISALLOW_COPY_AND_ASSIGN(DirectRenderer);
230 }; 239 };
231 240
232 } // namespace cc 241 } // namespace cc
233 242
234 #endif // CC_OUTPUT_DIRECT_RENDERER_H_ 243 #endif // CC_OUTPUT_DIRECT_RENDERER_H_
OLDNEW
« no previous file with comments | « cc/output/bsp_walk_action.cc ('k') | cc/output/direct_renderer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698