OLD | NEW |
| (Empty) |
1 // Copyright 2014 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. | |
4 | |
5 #include "components/display_compositor/compositor_overlay_candidate_validator_o
zone.h" | |
6 | |
7 #include <stddef.h> | |
8 | |
9 #include <utility> | |
10 | |
11 #include "base/bind.h" | |
12 #include "base/memory/ptr_util.h" | |
13 #include "base/strings/string_split.h" | |
14 #include "cc/output/overlay_strategy_fullscreen.h" | |
15 #include "cc/output/overlay_strategy_single_on_top.h" | |
16 #include "cc/output/overlay_strategy_underlay.h" | |
17 #include "cc/output/overlay_strategy_underlay_cast.h" | |
18 #include "ui/ozone/public/overlay_candidates_ozone.h" | |
19 | |
20 namespace display_compositor { | |
21 namespace { | |
22 // Templated function used to create an OverlayProcessor::Strategy | |
23 // of type |S|. | |
24 template <typename S> | |
25 std::unique_ptr<cc::OverlayProcessor::Strategy> MakeOverlayStrategy( | |
26 CompositorOverlayCandidateValidatorOzone* capability_checker) { | |
27 return base::MakeUnique<S>(capability_checker); | |
28 } | |
29 | |
30 } // namespace | |
31 | |
32 // |overlay_candidates| is an object used to answer questions about possible | |
33 // overlays configuarations. | |
34 // |strategies_string| is a comma-separated string containing all the overaly | |
35 // strategies that should be returned by GetStrategies. | |
36 // If |strategies_string| is empty "single-on-top,underlay" will be used as | |
37 // default. | |
38 CompositorOverlayCandidateValidatorOzone:: | |
39 CompositorOverlayCandidateValidatorOzone( | |
40 std::unique_ptr<ui::OverlayCandidatesOzone> overlay_candidates, | |
41 std::string strategies_string) | |
42 : overlay_candidates_(std::move(overlay_candidates)), | |
43 software_mirror_active_(false) { | |
44 if (!strategies_string.length()) | |
45 strategies_string = "single-on-top,underlay"; | |
46 | |
47 for (const auto& strategy_name : | |
48 base::SplitStringPiece(strategies_string, ",", base::TRIM_WHITESPACE, | |
49 base::SPLIT_WANT_NONEMPTY)) { | |
50 if (strategy_name == "single-fullscreen") { | |
51 strategies_instantiators_.push_back( | |
52 base::Bind(MakeOverlayStrategy<cc::OverlayStrategyFullscreen>)); | |
53 } else if (strategy_name == "single-on-top") { | |
54 strategies_instantiators_.push_back( | |
55 base::Bind(MakeOverlayStrategy<cc::OverlayStrategySingleOnTop>)); | |
56 } else if (strategy_name == "underlay") { | |
57 strategies_instantiators_.push_back( | |
58 base::Bind(MakeOverlayStrategy<cc::OverlayStrategyUnderlay>)); | |
59 } else if (strategy_name == "cast") { | |
60 strategies_instantiators_.push_back( | |
61 base::Bind(MakeOverlayStrategy<cc::OverlayStrategyUnderlayCast>)); | |
62 } else { | |
63 LOG(WARNING) << "Unrecognized overlay strategy " << strategy_name; | |
64 } | |
65 } | |
66 } | |
67 | |
68 CompositorOverlayCandidateValidatorOzone:: | |
69 ~CompositorOverlayCandidateValidatorOzone() {} | |
70 | |
71 void CompositorOverlayCandidateValidatorOzone::GetStrategies( | |
72 cc::OverlayProcessor::StrategyList* strategies) { | |
73 for (auto& instantiator : strategies_instantiators_) | |
74 strategies->push_back(instantiator.Run(this)); | |
75 } | |
76 | |
77 bool CompositorOverlayCandidateValidatorOzone::AllowCALayerOverlays() { | |
78 return false; | |
79 } | |
80 | |
81 bool CompositorOverlayCandidateValidatorOzone::AllowDCLayerOverlays() { | |
82 return false; | |
83 } | |
84 | |
85 void CompositorOverlayCandidateValidatorOzone::CheckOverlaySupport( | |
86 cc::OverlayCandidateList* surfaces) { | |
87 // SW mirroring copies out of the framebuffer, so we can't remove any | |
88 // quads for overlaying, otherwise the output is incorrect. | |
89 if (software_mirror_active_) { | |
90 for (size_t i = 0; i < surfaces->size(); i++) { | |
91 surfaces->at(i).overlay_handled = false; | |
92 } | |
93 return; | |
94 } | |
95 | |
96 DCHECK_GE(2U, surfaces->size()); | |
97 ui::OverlayCandidatesOzone::OverlaySurfaceCandidateList ozone_surface_list; | |
98 ozone_surface_list.resize(surfaces->size()); | |
99 | |
100 for (size_t i = 0; i < surfaces->size(); i++) { | |
101 ozone_surface_list.at(i).transform = surfaces->at(i).transform; | |
102 ozone_surface_list.at(i).format = surfaces->at(i).format; | |
103 ozone_surface_list.at(i).display_rect = surfaces->at(i).display_rect; | |
104 ozone_surface_list.at(i).crop_rect = surfaces->at(i).uv_rect; | |
105 ozone_surface_list.at(i).quad_rect_in_target_space = | |
106 surfaces->at(i).quad_rect_in_target_space; | |
107 ozone_surface_list.at(i).clip_rect = surfaces->at(i).clip_rect; | |
108 ozone_surface_list.at(i).is_clipped = surfaces->at(i).is_clipped; | |
109 ozone_surface_list.at(i).plane_z_order = surfaces->at(i).plane_z_order; | |
110 ozone_surface_list.at(i).buffer_size = | |
111 surfaces->at(i).resource_size_in_pixels; | |
112 } | |
113 | |
114 overlay_candidates_->CheckOverlaySupport(&ozone_surface_list); | |
115 DCHECK_EQ(surfaces->size(), ozone_surface_list.size()); | |
116 | |
117 for (size_t i = 0; i < surfaces->size(); i++) { | |
118 surfaces->at(i).overlay_handled = ozone_surface_list.at(i).overlay_handled; | |
119 surfaces->at(i).display_rect = ozone_surface_list.at(i).display_rect; | |
120 } | |
121 } | |
122 | |
123 void CompositorOverlayCandidateValidatorOzone::SetSoftwareMirrorMode( | |
124 bool enabled) { | |
125 software_mirror_active_ = enabled; | |
126 } | |
127 | |
128 } // namespace display_compositor | |
OLD | NEW |