| 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 <utility> | 7 #include <utility> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/containers/hash_tables.h" | 10 #include "base/containers/hash_tables.h" |
| 11 #include "base/containers/scoped_ptr_hash_map.h" | 11 #include "base/containers/scoped_ptr_hash_map.h" |
| 12 #include "base/debug/trace_event.h" | 12 #include "base/debug/trace_event.h" |
| 13 #include "base/debug/stack_trace.h" |
| 13 #include "base/metrics/histogram.h" | 14 #include "base/metrics/histogram.h" |
| 14 #include "cc/base/math_util.h" | 15 #include "cc/base/math_util.h" |
| 15 #include "cc/output/copy_output_request.h" | 16 #include "cc/output/copy_output_request.h" |
| 17 #include "cc/output/overlay_renderer.h" |
| 16 #include "cc/quads/draw_quad.h" | 18 #include "cc/quads/draw_quad.h" |
| 17 #include "ui/gfx/rect_conversions.h" | 19 #include "ui/gfx/rect_conversions.h" |
| 18 #include "ui/gfx/transform.h" | 20 #include "ui/gfx/transform.h" |
| 19 | 21 |
| 20 static gfx::Transform OrthoProjectionMatrix(float left, | 22 static gfx::Transform OrthoProjectionMatrix(float left, |
| 21 float right, | 23 float right, |
| 22 float bottom, | 24 float bottom, |
| 23 float top) { | 25 float top) { |
| 24 // Use the standard formula to map the clipping frustum to the cube from | 26 // Use the standard formula to map the clipping frustum to the cube from |
| 25 // [-1, -1, -1] to [1, 1, 1]. | 27 // [-1, -1, -1] to [1, 1, 1]. |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 window_rect.set_y(current_surface_size_.height() - window_rect.bottom()); | 127 window_rect.set_y(current_surface_size_.height() - window_rect.bottom()); |
| 126 return window_rect; | 128 return window_rect; |
| 127 } | 129 } |
| 128 | 130 |
| 129 DirectRenderer::DirectRenderer(RendererClient* client, | 131 DirectRenderer::DirectRenderer(RendererClient* client, |
| 130 const LayerTreeSettings* settings, | 132 const LayerTreeSettings* settings, |
| 131 OutputSurface* output_surface, | 133 OutputSurface* output_surface, |
| 132 ResourceProvider* resource_provider) | 134 ResourceProvider* resource_provider) |
| 133 : Renderer(client, settings), | 135 : Renderer(client, settings), |
| 134 output_surface_(output_surface), | 136 output_surface_(output_surface), |
| 135 resource_provider_(resource_provider) {} | 137 resource_provider_(resource_provider) { |
| 138 overlay_renderer_.reset(new OverlayRenderer()); |
| 139 overlay_renderer_->Initialize(); |
| 140 } |
| 136 | 141 |
| 137 DirectRenderer::~DirectRenderer() {} | 142 DirectRenderer::~DirectRenderer() {} |
| 138 | 143 |
| 139 bool DirectRenderer::CanReadPixels() const { return true; } | 144 bool DirectRenderer::CanReadPixels() const { return true; } |
| 140 | 145 |
| 141 void DirectRenderer::SetEnlargePassTextureAmountForTesting( | 146 void DirectRenderer::SetEnlargePassTextureAmountForTesting( |
| 142 gfx::Vector2d amount) { | 147 gfx::Vector2d amount) { |
| 143 enlarge_pass_texture_amount_ = amount; | 148 enlarge_pass_texture_amount_ = amount; |
| 144 } | 149 } |
| 145 | 150 |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 ContextProvider* offscreen_context_provider, | 201 ContextProvider* offscreen_context_provider, |
| 197 float device_scale_factor, | 202 float device_scale_factor, |
| 198 gfx::Rect device_viewport_rect, | 203 gfx::Rect device_viewport_rect, |
| 199 gfx::Rect device_clip_rect, | 204 gfx::Rect device_clip_rect, |
| 200 bool allow_partial_swap, | 205 bool allow_partial_swap, |
| 201 bool disable_picture_quad_image_filtering) { | 206 bool disable_picture_quad_image_filtering) { |
| 202 TRACE_EVENT0("cc", "DirectRenderer::DrawFrame"); | 207 TRACE_EVENT0("cc", "DirectRenderer::DrawFrame"); |
| 203 UMA_HISTOGRAM_COUNTS("Renderer4.renderPassCount", | 208 UMA_HISTOGRAM_COUNTS("Renderer4.renderPassCount", |
| 204 render_passes_in_draw_order->size()); | 209 render_passes_in_draw_order->size()); |
| 205 | 210 |
| 211 overlay_renderer_->ProcessForOverlays(render_passes_in_draw_order); |
| 212 |
| 206 const RenderPass* root_render_pass = render_passes_in_draw_order->back(); | 213 const RenderPass* root_render_pass = render_passes_in_draw_order->back(); |
| 207 DCHECK(root_render_pass); | 214 DCHECK(root_render_pass); |
| 208 | 215 |
| 209 DrawingFrame frame; | 216 DrawingFrame frame; |
| 210 frame.root_render_pass = root_render_pass; | 217 frame.root_render_pass = root_render_pass; |
| 211 frame.root_damage_rect = | 218 frame.root_damage_rect = |
| 212 Capabilities().using_partial_swap && allow_partial_swap | 219 Capabilities().using_partial_swap && allow_partial_swap |
| 213 ? root_render_pass->damage_rect | 220 ? root_render_pass->damage_rect |
| 214 : root_render_pass->output_rect; | 221 : root_render_pass->output_rect; |
| 215 frame.root_damage_rect.Intersect(gfx::Rect(device_viewport_rect.size())); | 222 frame.root_damage_rect.Intersect(gfx::Rect(device_viewport_rect.size())); |
| 216 frame.device_viewport_rect = device_viewport_rect; | 223 frame.device_viewport_rect = device_viewport_rect; |
| 217 frame.device_clip_rect = device_clip_rect; | 224 frame.device_clip_rect = device_clip_rect; |
| 218 frame.offscreen_context_provider = offscreen_context_provider; | 225 frame.offscreen_context_provider = offscreen_context_provider; |
| 219 frame.disable_picture_quad_image_filtering = | 226 frame.disable_picture_quad_image_filtering = |
| 220 disable_picture_quad_image_filtering; | 227 disable_picture_quad_image_filtering; |
| 221 | 228 |
| 222 EnsureBackbuffer(); | 229 EnsureBackbuffer(); |
| 223 | 230 |
| 224 // Only reshape when we know we are going to draw. Otherwise, the reshape | 231 // Only reshape when we know we are going to draw. Otherwise, the reshape |
| 225 // can leave the window at the wrong size if we never draw and the proper | 232 // can leave the window at the wrong size if we never draw and the proper |
| 226 // viewport size is never set. | 233 // viewport size is never set. |
| 227 output_surface_->Reshape(device_viewport_rect.size(), device_scale_factor); | 234 output_surface_->Reshape(device_viewport_rect.size(), device_scale_factor); |
| 228 | 235 |
| 229 BeginDrawingFrame(&frame); | 236 BeginDrawingFrame(&frame); |
| 230 for (size_t i = 0; i < render_passes_in_draw_order->size(); ++i) { | 237 for (size_t i = 0; i < render_passes_in_draw_order->size(); ++i) { |
| 231 RenderPass* pass = render_passes_in_draw_order->at(i); | 238 RenderPass* pass = render_passes_in_draw_order->at(i); |
| 239 if (!pass->should_render) { |
| 240 continue; |
| 241 } |
| 232 DrawRenderPass(&frame, pass, allow_partial_swap); | 242 DrawRenderPass(&frame, pass, allow_partial_swap); |
| 233 | 243 |
| 234 for (ScopedPtrVector<CopyOutputRequest>::iterator it = | 244 for (ScopedPtrVector<CopyOutputRequest>::iterator it = |
| 235 pass->copy_requests.begin(); | 245 pass->copy_requests.begin(); |
| 236 it != pass->copy_requests.end(); | 246 it != pass->copy_requests.end(); |
| 237 ++it) { | 247 ++it) { |
| 238 if (i > 0) { | 248 if (i > 0) { |
| 239 // Doing a readback is destructive of our state on Mac, so make sure | 249 // Doing a readback is destructive of our state on Mac, so make sure |
| 240 // we restore the state between readbacks. http://crbug.com/99393. | 250 // we restore the state between readbacks. http://crbug.com/99393. |
| 241 UseRenderPass(&frame, pass); | 251 UseRenderPass(&frame, pass); |
| 242 } | 252 } |
| 243 CopyCurrentRenderPassToBitmap(&frame, pass->copy_requests.take(it)); | 253 CopyCurrentRenderPassToBitmap(&frame, pass->copy_requests.take(it)); |
| 244 } | 254 } |
| 245 } | 255 } |
| 246 FinishDrawingFrame(&frame); | 256 FinishDrawingFrame(&frame); |
| 247 | |
| 248 render_passes_in_draw_order->clear(); | |
| 249 } | 257 } |
| 250 | 258 |
| 251 gfx::RectF DirectRenderer::ComputeScissorRectForRenderPass( | 259 gfx::RectF DirectRenderer::ComputeScissorRectForRenderPass( |
| 252 const DrawingFrame* frame) { | 260 const DrawingFrame* frame) { |
| 253 gfx::RectF render_pass_scissor = frame->current_render_pass->output_rect; | 261 gfx::RectF render_pass_scissor = frame->current_render_pass->output_rect; |
| 254 | 262 |
| 255 if (frame->root_damage_rect == frame->root_render_pass->output_rect) | 263 if (frame->root_damage_rect == frame->root_render_pass->output_rect) |
| 256 return render_pass_scissor; | 264 return render_pass_scissor; |
| 257 | 265 |
| 258 gfx::Transform inverse_transform(gfx::Transform::kSkipInitialization); | 266 gfx::Transform inverse_transform(gfx::Transform::kSkipInitialization); |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 420 ScopedResource* texture = render_pass_textures_.get(id); | 428 ScopedResource* texture = render_pass_textures_.get(id); |
| 421 return texture && texture->id(); | 429 return texture && texture->id(); |
| 422 } | 430 } |
| 423 | 431 |
| 424 // static | 432 // static |
| 425 gfx::Size DirectRenderer::RenderPassTextureSize(const RenderPass* render_pass) { | 433 gfx::Size DirectRenderer::RenderPassTextureSize(const RenderPass* render_pass) { |
| 426 return render_pass->output_rect.size(); | 434 return render_pass->output_rect.size(); |
| 427 } | 435 } |
| 428 | 436 |
| 429 } // namespace cc | 437 } // namespace cc |
| OLD | NEW |