OLD | NEW |
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 #include "cc/output/direct_renderer.h" | 5 #include "cc/output/direct_renderer.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/debug/trace_event.h" | 9 #include "base/debug/trace_event.h" |
10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 void DirectRenderer::QuadRectTransform(gfx::Transform* quad_rect_transform, | 70 void DirectRenderer::QuadRectTransform(gfx::Transform* quad_rect_transform, |
71 const gfx::Transform& quad_transform, | 71 const gfx::Transform& quad_transform, |
72 const gfx::RectF& quad_rect) { | 72 const gfx::RectF& quad_rect) { |
73 *quad_rect_transform = quad_transform; | 73 *quad_rect_transform = quad_transform; |
74 quad_rect_transform->Translate(0.5 * quad_rect.width() + quad_rect.x(), | 74 quad_rect_transform->Translate(0.5 * quad_rect.width() + quad_rect.x(), |
75 0.5 * quad_rect.height() + quad_rect.y()); | 75 0.5 * quad_rect.height() + quad_rect.y()); |
76 quad_rect_transform->Scale(quad_rect.width(), quad_rect.height()); | 76 quad_rect_transform->Scale(quad_rect.width(), quad_rect.height()); |
77 } | 77 } |
78 | 78 |
79 // static | 79 // static |
80 void DirectRenderer::InitializeMatrices(DrawingFrame& frame, | 80 void DirectRenderer::InitializeMatrices(DrawingFrame* frame, |
81 gfx::Rect draw_rect, | 81 gfx::Rect draw_rect, |
82 bool flip_y) { | 82 bool flip_y) { |
83 if (flip_y) { | 83 if (flip_y) { |
84 frame.projection_matrix = OrthoProjectionMatrix(draw_rect.x(), | 84 frame->projection_matrix = OrthoProjectionMatrix(draw_rect.x(), |
85 draw_rect.right(), | 85 draw_rect.right(), |
86 draw_rect.bottom(), | 86 draw_rect.bottom(), |
87 draw_rect.y()); | 87 draw_rect.y()); |
88 } else { | 88 } else { |
89 frame.projection_matrix = OrthoProjectionMatrix(draw_rect.x(), | 89 frame->projection_matrix = OrthoProjectionMatrix(draw_rect.x(), |
90 draw_rect.right(), | 90 draw_rect.right(), |
91 draw_rect.y(), | 91 draw_rect.y(), |
92 draw_rect.bottom()); | 92 draw_rect.bottom()); |
93 } | 93 } |
94 frame.window_matrix = | 94 frame->window_matrix = |
95 window_matrix(0, 0, draw_rect.width(), draw_rect.height()); | 95 window_matrix(0, 0, draw_rect.width(), draw_rect.height()); |
96 frame.flipped_y = flip_y; | 96 frame->flipped_y = flip_y; |
97 } | 97 } |
98 | 98 |
99 // static | 99 // static |
100 gfx::Rect DirectRenderer::MoveScissorToWindowSpace( | 100 gfx::Rect DirectRenderer::MoveScissorToWindowSpace( |
101 const DrawingFrame& frame, const gfx::RectF& scissor_rect) { | 101 const DrawingFrame* frame, const gfx::RectF& scissor_rect) { |
102 gfx::Rect scissor_rect_in_canvas_space = gfx::ToEnclosingRect(scissor_rect); | 102 gfx::Rect scissor_rect_in_canvas_space = gfx::ToEnclosingRect(scissor_rect); |
103 // The scissor coordinates must be supplied in viewport space so we need to | 103 // The scissor coordinates must be supplied in viewport space so we need to |
104 // offset by the relative position of the top left corner of the current | 104 // offset by the relative position of the top left corner of the current |
105 // render pass. | 105 // render pass. |
106 gfx::Rect framebuffer_output_rect = frame.current_render_pass->output_rect; | 106 gfx::Rect framebuffer_output_rect = frame->current_render_pass->output_rect; |
107 scissor_rect_in_canvas_space.set_x( | 107 scissor_rect_in_canvas_space.set_x( |
108 scissor_rect_in_canvas_space.x() - framebuffer_output_rect.x()); | 108 scissor_rect_in_canvas_space.x() - framebuffer_output_rect.x()); |
109 if (frame.flipped_y && !frame.current_texture) { | 109 if (frame->flipped_y && !frame->current_texture) { |
110 scissor_rect_in_canvas_space.set_y( | 110 scissor_rect_in_canvas_space.set_y( |
111 framebuffer_output_rect.height() - | 111 framebuffer_output_rect.height() - |
112 (scissor_rect_in_canvas_space.bottom() - framebuffer_output_rect.y())); | 112 (scissor_rect_in_canvas_space.bottom() - framebuffer_output_rect.y())); |
113 } else { | 113 } else { |
114 scissor_rect_in_canvas_space.set_y( | 114 scissor_rect_in_canvas_space.set_y( |
115 scissor_rect_in_canvas_space.y() - framebuffer_output_rect.y()); | 115 scissor_rect_in_canvas_space.y() - framebuffer_output_rect.y()); |
116 } | 116 } |
117 return scissor_rect_in_canvas_space; | 117 return scissor_rect_in_canvas_space; |
118 } | 118 } |
119 | 119 |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 for (size_t i = 0; i < render_passes_in_draw_order.size(); ++i) { | 169 for (size_t i = 0; i < render_passes_in_draw_order.size(); ++i) { |
170 if (!render_pass_textures_.contains(render_passes_in_draw_order[i]->id)) { | 170 if (!render_pass_textures_.contains(render_passes_in_draw_order[i]->id)) { |
171 scoped_ptr<CachedResource> texture = | 171 scoped_ptr<CachedResource> texture = |
172 CachedResource::Create(resource_provider_); | 172 CachedResource::Create(resource_provider_); |
173 render_pass_textures_.set(render_passes_in_draw_order[i]->id, | 173 render_pass_textures_.set(render_passes_in_draw_order[i]->id, |
174 texture.Pass()); | 174 texture.Pass()); |
175 } | 175 } |
176 } | 176 } |
177 } | 177 } |
178 | 178 |
179 void DirectRenderer::DrawFrame(RenderPassList& render_passes_in_draw_order) { | 179 void DirectRenderer::DrawFrame(RenderPassList* render_passes_in_draw_order) { |
180 TRACE_EVENT0("cc", "DirectRenderer::DrawFrame"); | 180 TRACE_EVENT0("cc", "DirectRenderer::DrawFrame"); |
181 UMA_HISTOGRAM_COUNTS("Renderer4.renderPassCount", | 181 UMA_HISTOGRAM_COUNTS("Renderer4.renderPassCount", |
182 render_passes_in_draw_order.size()); | 182 render_passes_in_draw_order->size()); |
183 | 183 |
184 const RenderPass* root_render_pass = render_passes_in_draw_order.back(); | 184 const RenderPass* root_render_pass = render_passes_in_draw_order->back(); |
185 DCHECK(root_render_pass); | 185 DCHECK(root_render_pass); |
186 | 186 |
187 DrawingFrame frame; | 187 DrawingFrame frame; |
188 frame.root_render_pass = root_render_pass; | 188 frame.root_render_pass = root_render_pass; |
189 frame.root_damage_rect = | 189 frame.root_damage_rect = |
190 Capabilities().using_partial_swap ? | 190 Capabilities().using_partial_swap ? |
191 root_render_pass->damage_rect : root_render_pass->output_rect; | 191 root_render_pass->damage_rect : root_render_pass->output_rect; |
192 frame.root_damage_rect.Intersect(gfx::Rect(ViewportSize())); | 192 frame.root_damage_rect.Intersect(gfx::Rect(ViewportSize())); |
193 | 193 |
194 BeginDrawingFrame(frame); | 194 BeginDrawingFrame(&frame); |
195 for (size_t i = 0; i < render_passes_in_draw_order.size(); ++i) | 195 for (size_t i = 0; i < render_passes_in_draw_order->size(); ++i) |
196 DrawRenderPass(frame, render_passes_in_draw_order[i]); | 196 DrawRenderPass(&frame, render_passes_in_draw_order->at(i)); |
197 FinishDrawingFrame(frame); | 197 FinishDrawingFrame(&frame); |
198 | 198 |
199 render_passes_in_draw_order.clear(); | 199 render_passes_in_draw_order->clear(); |
200 } | 200 } |
201 | 201 |
202 gfx::RectF DirectRenderer::ComputeScissorRectForRenderPass( | 202 gfx::RectF DirectRenderer::ComputeScissorRectForRenderPass( |
203 const DrawingFrame& frame) { | 203 const DrawingFrame* frame) { |
204 gfx::RectF render_pass_scissor = frame.current_render_pass->output_rect; | 204 gfx::RectF render_pass_scissor = frame->current_render_pass->output_rect; |
205 | 205 |
206 if (frame.root_damage_rect == frame.root_render_pass->output_rect) | 206 if (frame->root_damage_rect == frame->root_render_pass->output_rect) |
207 return render_pass_scissor; | 207 return render_pass_scissor; |
208 | 208 |
209 gfx::Transform inverse_transform(gfx::Transform::kSkipInitialization); | 209 gfx::Transform inverse_transform(gfx::Transform::kSkipInitialization); |
210 if (frame.current_render_pass->transform_to_root_target.GetInverse( | 210 if (frame->current_render_pass->transform_to_root_target.GetInverse( |
211 &inverse_transform)) { | 211 &inverse_transform)) { |
212 // Only intersect inverse-projected damage if the transform is invertible. | 212 // Only intersect inverse-projected damage if the transform is invertible. |
213 gfx::RectF damage_rect_in_render_pass_space = | 213 gfx::RectF damage_rect_in_render_pass_space = |
214 MathUtil::ProjectClippedRect(inverse_transform, frame.root_damage_rect); | 214 MathUtil::ProjectClippedRect(inverse_transform, |
| 215 frame->root_damage_rect); |
215 render_pass_scissor.Intersect(damage_rect_in_render_pass_space); | 216 render_pass_scissor.Intersect(damage_rect_in_render_pass_space); |
216 } | 217 } |
217 | 218 |
218 return render_pass_scissor; | 219 return render_pass_scissor; |
219 } | 220 } |
220 | 221 |
221 void DirectRenderer::SetScissorStateForQuad(const DrawingFrame& frame, | 222 void DirectRenderer::SetScissorStateForQuad(const DrawingFrame* frame, |
222 const DrawQuad& quad) { | 223 const DrawQuad& quad) { |
223 if (quad.isClipped()) { | 224 if (quad.isClipped()) { |
224 gfx::RectF quad_scissor_rect = quad.clipRect(); | 225 gfx::RectF quad_scissor_rect = quad.clipRect(); |
225 SetScissorTestRect(MoveScissorToWindowSpace(frame, quad_scissor_rect)); | 226 SetScissorTestRect(MoveScissorToWindowSpace(frame, quad_scissor_rect)); |
226 } else { | 227 } else { |
227 EnsureScissorTestDisabled(); | 228 EnsureScissorTestDisabled(); |
228 } | 229 } |
229 } | 230 } |
230 | 231 |
231 void DirectRenderer::SetScissorStateForQuadWithRenderPassScissor( | 232 void DirectRenderer::SetScissorStateForQuadWithRenderPassScissor( |
232 const DrawingFrame& frame, | 233 const DrawingFrame* frame, |
233 const DrawQuad& quad, | 234 const DrawQuad& quad, |
234 const gfx::RectF& render_pass_scissor, | 235 const gfx::RectF& render_pass_scissor, |
235 bool* should_skip_quad) { | 236 bool* should_skip_quad) { |
236 gfx::RectF quad_scissor_rect = render_pass_scissor; | 237 gfx::RectF quad_scissor_rect = render_pass_scissor; |
237 | 238 |
238 if (quad.isClipped()) | 239 if (quad.isClipped()) |
239 quad_scissor_rect.Intersect(quad.clipRect()); | 240 quad_scissor_rect.Intersect(quad.clipRect()); |
240 | 241 |
241 if (quad_scissor_rect.IsEmpty()) { | 242 if (quad_scissor_rect.IsEmpty()) { |
242 *should_skip_quad = true; | 243 *should_skip_quad = true; |
243 return; | 244 return; |
244 } | 245 } |
245 | 246 |
246 *should_skip_quad = false; | 247 *should_skip_quad = false; |
247 SetScissorTestRect(MoveScissorToWindowSpace(frame, quad_scissor_rect)); | 248 SetScissorTestRect(MoveScissorToWindowSpace(frame, quad_scissor_rect)); |
248 } | 249 } |
249 | 250 |
250 void DirectRenderer::FinishDrawingQuadList() {} | 251 void DirectRenderer::FinishDrawingQuadList() {} |
251 | 252 |
252 void DirectRenderer::DrawRenderPass(DrawingFrame& frame, | 253 void DirectRenderer::DrawRenderPass(DrawingFrame* frame, |
253 const RenderPass* render_pass) { | 254 const RenderPass* render_pass) { |
254 TRACE_EVENT0("cc", "DirectRenderer::DrawRenderPass"); | 255 TRACE_EVENT0("cc", "DirectRenderer::DrawRenderPass"); |
255 if (!UseRenderPass(frame, render_pass)) | 256 if (!UseRenderPass(frame, render_pass)) |
256 return; | 257 return; |
257 | 258 |
258 bool using_scissor_as_optimization = Capabilities().using_partial_swap; | 259 bool using_scissor_as_optimization = Capabilities().using_partial_swap; |
259 gfx::RectF render_pass_scissor; | 260 gfx::RectF render_pass_scissor; |
260 | 261 |
261 if (using_scissor_as_optimization) { | 262 if (using_scissor_as_optimization) { |
262 render_pass_scissor = ComputeScissorRectForRenderPass(frame); | 263 render_pass_scissor = ComputeScissorRectForRenderPass(frame); |
263 SetScissorTestRect(MoveScissorToWindowSpace(frame, render_pass_scissor)); | 264 SetScissorTestRect(MoveScissorToWindowSpace(frame, render_pass_scissor)); |
264 } | 265 } |
265 | 266 |
266 if (frame.current_render_pass != frame.root_render_pass || | 267 if (frame->current_render_pass != frame->root_render_pass || |
267 client_->ShouldClearRootRenderPass()) { | 268 client_->ShouldClearRootRenderPass()) { |
268 if (!using_scissor_as_optimization) | 269 if (!using_scissor_as_optimization) |
269 EnsureScissorTestDisabled(); | 270 EnsureScissorTestDisabled(); |
270 ClearFramebuffer(frame); | 271 ClearFramebuffer(frame); |
271 } | 272 } |
272 | 273 |
273 const QuadList& quad_list = render_pass->quad_list; | 274 const QuadList& quad_list = render_pass->quad_list; |
274 for (QuadList::ConstBackToFrontIterator it = quad_list.BackToFrontBegin(); | 275 for (QuadList::ConstBackToFrontIterator it = quad_list.BackToFrontBegin(); |
275 it != quad_list.BackToFrontEnd(); | 276 it != quad_list.BackToFrontEnd(); |
276 ++it) { | 277 ++it) { |
(...skipping 12 matching lines...) Expand all Loading... |
289 } | 290 } |
290 FinishDrawingQuadList(); | 291 FinishDrawingQuadList(); |
291 | 292 |
292 CachedResource* texture = render_pass_textures_.get(render_pass->id); | 293 CachedResource* texture = render_pass_textures_.get(render_pass->id); |
293 if (texture) { | 294 if (texture) { |
294 texture->set_is_complete( | 295 texture->set_is_complete( |
295 !render_pass->has_occlusion_from_outside_target_surface); | 296 !render_pass->has_occlusion_from_outside_target_surface); |
296 } | 297 } |
297 } | 298 } |
298 | 299 |
299 bool DirectRenderer::UseRenderPass(DrawingFrame& frame, | 300 bool DirectRenderer::UseRenderPass(DrawingFrame* frame, |
300 const RenderPass* render_pass) { | 301 const RenderPass* render_pass) { |
301 frame.current_render_pass = render_pass; | 302 frame->current_render_pass = render_pass; |
302 frame.current_texture = NULL; | 303 frame->current_texture = NULL; |
303 | 304 |
304 if (render_pass == frame.root_render_pass) { | 305 if (render_pass == frame->root_render_pass) { |
305 BindFramebufferToOutputSurface(frame); | 306 BindFramebufferToOutputSurface(frame); |
306 InitializeMatrices(frame, render_pass->output_rect, FlippedFramebuffer()); | 307 InitializeMatrices(frame, render_pass->output_rect, FlippedFramebuffer()); |
307 SetDrawViewportSize(render_pass->output_rect.size()); | 308 SetDrawViewportSize(render_pass->output_rect.size()); |
308 return true; | 309 return true; |
309 } | 310 } |
310 | 311 |
311 CachedResource* texture = render_pass_textures_.get(render_pass->id); | 312 CachedResource* texture = render_pass_textures_.get(render_pass->id); |
312 DCHECK(texture); | 313 DCHECK(texture); |
313 | 314 |
314 gfx::Size size = RenderPassTextureSize(render_pass); | 315 gfx::Size size = RenderPassTextureSize(render_pass); |
(...skipping 21 matching lines...) Expand all Loading... |
336 gfx::Size DirectRenderer::RenderPassTextureSize(const RenderPass* render_pass) { | 337 gfx::Size DirectRenderer::RenderPassTextureSize(const RenderPass* render_pass) { |
337 return render_pass->output_rect.size(); | 338 return render_pass->output_rect.size(); |
338 } | 339 } |
339 | 340 |
340 // static | 341 // static |
341 GLenum DirectRenderer::RenderPassTextureFormat(const RenderPass* render_pass) { | 342 GLenum DirectRenderer::RenderPassTextureFormat(const RenderPass* render_pass) { |
342 return GL_RGBA; | 343 return GL_RGBA; |
343 } | 344 } |
344 | 345 |
345 } // namespace cc | 346 } // namespace cc |
OLD | NEW |