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

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

Issue 2743663006: Allow switching DirectCompositionSurfaceWin between drawing modes. (Closed)
Patch Set: remove const Created 3 years, 9 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
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 #include "cc/output/direct_renderer.h" 5 #include "cc/output/direct_renderer.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <unordered_map> 9 #include <unordered_map>
10 #include <utility> 10 #include <utility>
11 #include <vector> 11 #include <vector>
12 12
13 #include "base/auto_reset.h" 13 #include "base/auto_reset.h"
14 #include "base/metrics/histogram_macros.h" 14 #include "base/metrics/histogram_macros.h"
15 #include "base/numerics/safe_conversions.h" 15 #include "base/numerics/safe_conversions.h"
16 #include "base/trace_event/trace_event.h" 16 #include "base/trace_event/trace_event.h"
17 #include "cc/base/math_util.h" 17 #include "cc/base/math_util.h"
18 #include "cc/output/bsp_tree.h" 18 #include "cc/output/bsp_tree.h"
19 #include "cc/output/bsp_walk_action.h" 19 #include "cc/output/bsp_walk_action.h"
20 #include "cc/output/copy_output_request.h" 20 #include "cc/output/copy_output_request.h"
21 #include "cc/output/renderer_settings.h" 21 #include "cc/output/renderer_settings.h"
22 #include "cc/quads/draw_quad.h" 22 #include "cc/quads/draw_quad.h"
23 #include "cc/resources/scoped_resource.h" 23 #include "cc/resources/scoped_resource.h"
24 #include "ui/gfx/geometry/quad_f.h" 24 #include "ui/gfx/geometry/quad_f.h"
25 #include "ui/gfx/geometry/rect_conversions.h" 25 #include "ui/gfx/geometry/rect_conversions.h"
26 #include "ui/gfx/transform.h" 26 #include "ui/gfx/transform.h"
27 27
28 namespace {
28 static gfx::Transform OrthoProjectionMatrix(float left, 29 static gfx::Transform OrthoProjectionMatrix(float left,
danakj 2017/03/21 15:54:05 nit: whitespace after namespace {
29 float right, 30 float right,
30 float bottom, 31 float bottom,
31 float top) { 32 float top) {
32 // Use the standard formula to map the clipping frustum to the cube from 33 // Use the standard formula to map the clipping frustum to the cube from
33 // [-1, -1, -1] to [1, 1, 1]. 34 // [-1, -1, -1] to [1, 1, 1].
34 float delta_x = right - left; 35 float delta_x = right - left;
35 float delta_y = top - bottom; 36 float delta_y = top - bottom;
36 gfx::Transform proj; 37 gfx::Transform proj;
37 if (!delta_x || !delta_y) 38 if (!delta_x || !delta_y)
38 return proj; 39 return proj;
(...skipping 16 matching lines...) Expand all
55 canvas.Translate3d(x, y, 0); 56 canvas.Translate3d(x, y, 0);
56 canvas.Scale3d(width, height, 0); 57 canvas.Scale3d(width, height, 0);
57 58
58 // Map from ([-1, -1] to [1, 1]) -> ([0, 0] to [1, 1]) 59 // Map from ([-1, -1] to [1, 1]) -> ([0, 0] to [1, 1])
59 canvas.Translate3d(0.5, 0.5, 0.5); 60 canvas.Translate3d(0.5, 0.5, 0.5);
60 canvas.Scale3d(0.5, 0.5, 0.5); 61 canvas.Scale3d(0.5, 0.5, 0.5);
61 62
62 return canvas; 63 return canvas;
63 } 64 }
64 65
66 // Switching between enabling DC layers and not is expensive, so only
67 // switch away after a large number of frames not needing DC layers have
68 // been produced.
69 const int kNumberOfFramesBeforeDisablingDCLayers = 60;
danakj 2017/03/21 15:54:05 constexpr
70
71 } // namespace
72
65 namespace cc { 73 namespace cc {
66 74
67 DirectRenderer::DrawingFrame::DrawingFrame() = default; 75 DirectRenderer::DrawingFrame::DrawingFrame() = default;
68 DirectRenderer::DrawingFrame::~DrawingFrame() = default; 76 DirectRenderer::DrawingFrame::~DrawingFrame() = default;
69 77
70 DirectRenderer::DirectRenderer(const RendererSettings* settings, 78 DirectRenderer::DirectRenderer(const RendererSettings* settings,
71 OutputSurface* output_surface, 79 OutputSurface* output_surface,
72 ResourceProvider* resource_provider) 80 ResourceProvider* resource_provider)
73 : settings_(settings), 81 : settings_(settings),
74 output_surface_(output_surface), 82 output_surface_(output_surface),
75 resource_provider_(resource_provider), 83 resource_provider_(resource_provider),
76 overlay_processor_(new OverlayProcessor(output_surface)) {} 84 overlay_processor_(new OverlayProcessor(output_surface)) {}
77 85
78 DirectRenderer::~DirectRenderer() = default; 86 DirectRenderer::~DirectRenderer() = default;
79 87
80 void DirectRenderer::Initialize() { 88 void DirectRenderer::Initialize() {
81 overlay_processor_->Initialize(); 89 overlay_processor_->Initialize();
82 90
83 auto* context_provider = output_surface_->context_provider(); 91 auto* context_provider = output_surface_->context_provider();
84 92
85 use_partial_swap_ = settings_->partial_swap_enabled && CanPartialSwap(); 93 use_partial_swap_ = settings_->partial_swap_enabled && CanPartialSwap();
86 allow_empty_swap_ = use_partial_swap_; 94 allow_empty_swap_ = use_partial_swap_;
87 if (context_provider) { 95 if (context_provider) {
88 if (context_provider->ContextCapabilities().commit_overlay_planes) 96 if (context_provider->ContextCapabilities().commit_overlay_planes)
89 allow_empty_swap_ = true; 97 allow_empty_swap_ = true;
90 if (context_provider->ContextCapabilities().set_draw_rectangle) 98 if (context_provider->ContextCapabilities().dc_layers)
91 use_set_draw_rectangle_ = true; 99 supports_dc_layers_ = true;
92 } 100 }
93 101
94 initialized_ = true; 102 initialized_ = true;
95 } 103 }
96 104
97 // static 105 // static
98 gfx::RectF DirectRenderer::QuadVertexRect() { 106 gfx::RectF DirectRenderer::QuadVertexRect() {
99 return gfx::RectF(-0.5f, -0.5f, 1.f, 1.f); 107 return gfx::RectF(-0.5f, -0.5f, 1.f, 1.f);
100 } 108 }
101 109
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
307 315
308 // Attempt to replace some or all of the quads of the root render pass with 316 // Attempt to replace some or all of the quads of the root render pass with
309 // overlays. 317 // overlays.
310 overlay_processor_->ProcessForOverlays( 318 overlay_processor_->ProcessForOverlays(
311 resource_provider_, root_render_pass, render_pass_filters_, 319 resource_provider_, root_render_pass, render_pass_filters_,
312 render_pass_background_filters_, &current_frame()->overlay_list, 320 render_pass_background_filters_, &current_frame()->overlay_list,
313 &current_frame()->ca_layer_overlay_list, 321 &current_frame()->ca_layer_overlay_list,
314 &current_frame()->dc_layer_overlay_list, 322 &current_frame()->dc_layer_overlay_list,
315 &current_frame()->root_damage_rect, 323 &current_frame()->root_damage_rect,
316 &current_frame()->root_content_bounds); 324 &current_frame()->root_content_bounds);
325 if (!current_frame()->dc_layer_overlay_list.empty()) {
danakj 2017/03/21 15:54:05 Couple suggestions to make this a bit easier to re
326 if (!using_dc_layers_) {
327 DCHECK(supports_dc_layers_);
328 using_dc_layers_ = true;
329 current_frame()->root_damage_rect =
330 current_frame()->root_render_pass->output_rect;
331 }
332 frames_since_using_dc_layers_ = 0;
333 } else {
danakj 2017/03/21 15:54:05 else if
334 if (++frames_since_using_dc_layers_ >=
335 kNumberOfFramesBeforeDisablingDCLayers) {
336 if (using_dc_layers_) {
337 using_dc_layers_ = false;
338 current_frame()->root_damage_rect =
339 current_frame()->root_render_pass->output_rect;
340 }
341 }
342 }
317 343
318 // We can skip all drawing if the damage rect is now empty. 344 // We can skip all drawing if the damage rect is now empty.
319 bool skip_drawing_root_render_pass = 345 bool skip_drawing_root_render_pass =
320 current_frame()->root_damage_rect.IsEmpty() && allow_empty_swap_; 346 current_frame()->root_damage_rect.IsEmpty() && allow_empty_swap_;
321 347
322 // If we have to draw but don't support partial swap, the whole output should 348 // If we have to draw but don't support partial swap, the whole output should
323 // be considered damaged. 349 // be considered damaged.
324 if (!skip_drawing_root_render_pass && !use_partial_swap_) 350 if (!skip_drawing_root_render_pass && !use_partial_swap_)
325 current_frame()->root_damage_rect = root_render_pass->output_rect; 351 current_frame()->root_damage_rect = root_render_pass->output_rect;
326 352
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
516 } 542 }
517 543
518 bool is_root_render_pass = 544 bool is_root_render_pass =
519 current_frame()->current_render_pass == current_frame()->root_render_pass; 545 current_frame()->current_render_pass == current_frame()->root_render_pass;
520 546
521 // The SetDrawRectangleCHROMIUM spec requires that the scissor bit is always 547 // The SetDrawRectangleCHROMIUM spec requires that the scissor bit is always
522 // set on the root framebuffer or else the rendering may modify something 548 // set on the root framebuffer or else the rendering may modify something
523 // outside the damage rectangle, even if the damage rectangle is the size of 549 // outside the damage rectangle, even if the damage rectangle is the size of
524 // the full backbuffer. 550 // the full backbuffer.
525 bool render_pass_is_clipped = 551 bool render_pass_is_clipped =
526 (use_set_draw_rectangle_ && is_root_render_pass) || 552 (supports_dc_layers_ && is_root_render_pass) ||
527 !render_pass_scissor_in_draw_space.Contains(surface_rect_in_draw_space); 553 !render_pass_scissor_in_draw_space.Contains(surface_rect_in_draw_space);
528 bool has_external_stencil_test = 554 bool has_external_stencil_test =
529 is_root_render_pass && output_surface_->HasExternalStencilTest(); 555 is_root_render_pass && output_surface_->HasExternalStencilTest();
530 bool should_clear_surface = 556 bool should_clear_surface =
531 !has_external_stencil_test && 557 !has_external_stencil_test &&
532 (!is_root_render_pass || settings_->should_clear_root_render_pass); 558 (!is_root_render_pass || settings_->should_clear_root_render_pass);
533 559
534 // If |has_external_stencil_test| we can't discard or clear. Make sure we 560 // If |has_external_stencil_test| we can't discard or clear. Make sure we
535 // don't need to. 561 // don't need to.
536 DCHECK(!has_external_stencil_test || 562 DCHECK(!has_external_stencil_test ||
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
590 render_pass_is_clipped); 616 render_pass_is_clipped);
591 FinishDrawingQuadList(); 617 FinishDrawingQuadList();
592 } 618 }
593 619
594 bool DirectRenderer::UseRenderPass(const RenderPass* render_pass) { 620 bool DirectRenderer::UseRenderPass(const RenderPass* render_pass) {
595 current_frame()->current_render_pass = render_pass; 621 current_frame()->current_render_pass = render_pass;
596 current_frame()->current_texture = nullptr; 622 current_frame()->current_texture = nullptr;
597 if (render_pass == current_frame()->root_render_pass) { 623 if (render_pass == current_frame()->root_render_pass) {
598 BindFramebufferToOutputSurface(); 624 BindFramebufferToOutputSurface();
599 625
600 if (use_set_draw_rectangle_) 626 if (supports_dc_layers_) {
danakj 2017/03/21 15:54:05 I am confused how DC layers and chromecast's SetDr
627 SetEnableDCLayers(using_dc_layers_);
601 output_surface_->SetDrawRectangle(current_frame()->root_damage_rect); 628 output_surface_->SetDrawRectangle(current_frame()->root_damage_rect);
629 }
602 InitializeViewport(current_frame(), render_pass->output_rect, 630 InitializeViewport(current_frame(), render_pass->output_rect,
603 gfx::Rect(current_frame()->device_viewport_size), 631 gfx::Rect(current_frame()->device_viewport_size),
604 current_frame()->device_viewport_size); 632 current_frame()->device_viewport_size);
605 return true; 633 return true;
606 } 634 }
607 635
608 ScopedResource* texture = render_pass_textures_[render_pass->id].get(); 636 ScopedResource* texture = render_pass_textures_[render_pass->id].get();
609 DCHECK(texture); 637 DCHECK(texture);
610 638
611 gfx::Size size = RenderPassTextureSize(render_pass); 639 gfx::Size size = RenderPassTextureSize(render_pass);
(...skipping 25 matching lines...) Expand all
637 gfx::Size DirectRenderer::RenderPassTextureSize(const RenderPass* render_pass) { 665 gfx::Size DirectRenderer::RenderPassTextureSize(const RenderPass* render_pass) {
638 return render_pass->output_rect.size(); 666 return render_pass->output_rect.size();
639 } 667 }
640 668
641 void DirectRenderer::SetCurrentFrameForTesting(const DrawingFrame& frame) { 669 void DirectRenderer::SetCurrentFrameForTesting(const DrawingFrame& frame) {
642 current_frame_valid_ = true; 670 current_frame_valid_ = true;
643 current_frame_ = frame; 671 current_frame_ = frame;
644 } 672 }
645 673
646 } // namespace cc 674 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698