OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/overlay_strategy_sandwich.h" | 5 #include "cc/output/overlay_strategy_sandwich.h" |
6 | 6 |
7 #include "cc/base/math_util.h" | 7 #include "cc/base/math_util.h" |
8 #include "cc/base/region.h" | 8 #include "cc/base/region.h" |
9 #include "cc/output/overlay_candidate_validator.h" | 9 #include "cc/output/overlay_candidate_validator.h" |
10 #include "cc/quads/draw_quad.h" | 10 #include "cc/quads/draw_quad.h" |
(...skipping 13 matching lines...) Expand all Loading... |
24 bool IsPixelRectAlignedToDIP(float scale_factor, const gfx::Rect& pixel_rect) { | 24 bool IsPixelRectAlignedToDIP(float scale_factor, const gfx::Rect& pixel_rect) { |
25 return (pixel_rect == AlignPixelRectToDIP(scale_factor, pixel_rect)); | 25 return (pixel_rect == AlignPixelRectToDIP(scale_factor, pixel_rect)); |
26 } | 26 } |
27 | 27 |
28 } // namespace | 28 } // namespace |
29 | 29 |
30 namespace cc { | 30 namespace cc { |
31 | 31 |
32 OverlayStrategySandwich::~OverlayStrategySandwich() {} | 32 OverlayStrategySandwich::~OverlayStrategySandwich() {} |
33 | 33 |
34 bool OverlayStrategySandwich::TryOverlay( | 34 OverlayResult OverlayStrategySandwich::TryOverlay( |
35 OverlayCandidateValidator* capability_checker, | 35 OverlayCandidateValidator* capability_checker, |
36 RenderPassList* render_passes_in_draw_order, | 36 RenderPassList* render_passes_in_draw_order, |
37 OverlayCandidateList* output_candidate_list, | 37 OverlayCandidateList* candidate_list, |
38 const OverlayCandidate& candidate, | 38 const OverlayCandidate& candidate, |
39 QuadList::Iterator candidate_iter_in_quad_list, | 39 QuadList::Iterator* candidate_iter_in_quad_list, |
40 float device_scale_factor) { | 40 float device_scale_factor) { |
41 RenderPass* root_render_pass = render_passes_in_draw_order->back(); | 41 RenderPass* root_render_pass = render_passes_in_draw_order->back(); |
42 QuadList& quad_list = root_render_pass->quad_list; | 42 QuadList& quad_list = root_render_pass->quad_list; |
43 gfx::Rect pixel_bounds = root_render_pass->output_rect; | 43 gfx::Rect pixel_bounds = root_render_pass->output_rect; |
44 | 44 |
45 const DrawQuad* candidate_quad = *candidate_iter_in_quad_list; | 45 const DrawQuad* candidate_quad = **candidate_iter_in_quad_list; |
46 const gfx::Transform& candidate_transform = | 46 const gfx::Transform& candidate_transform = |
47 candidate_quad->shared_quad_state->quad_to_target_transform; | 47 candidate_quad->shared_quad_state->quad_to_target_transform; |
48 gfx::Transform candidate_inverse_transform; | 48 gfx::Transform candidate_inverse_transform; |
49 if (!candidate_transform.GetInverse(&candidate_inverse_transform)) | 49 if (!candidate_transform.GetInverse(&candidate_inverse_transform)) |
50 return false; | 50 return DID_NOT_CREATE_OVERLAY; |
51 | 51 |
52 // Compute the candidate's rect in display space (pixels on the screen). The | 52 // Compute the candidate's rect in display space (pixels on the screen). The |
53 // rect needs to be DIP-aligned, or we cannot use it. | 53 // rect needs to be DIP-aligned, or we cannot use it. |
54 gfx::RectF candidate_pixel_rect_float = MathUtil::MapClippedRect( | 54 const gfx::Rect candidate_pixel_rect = |
55 candidate_transform, gfx::RectF(candidate_quad->rect)); | 55 gfx::ToNearestRect(candidate.display_rect); |
56 if (!candidate_pixel_rect_float.IsExpressibleAsRect()) | |
57 return false; | |
58 gfx::Rect candidate_pixel_rect = | |
59 gfx::ToNearestRect(candidate_pixel_rect_float); | |
60 if (!IsPixelRectAlignedToDIP(device_scale_factor, candidate_pixel_rect)) | 56 if (!IsPixelRectAlignedToDIP(device_scale_factor, candidate_pixel_rect)) |
61 return false; | 57 return DID_NOT_CREATE_OVERLAY; |
62 | 58 |
63 // Iterate through the quads in front of |potential_candidate|, and compute | 59 // Don't allow overlapping overlays for now. |
64 // the region of |potential_candidate| that is covered. | 60 for (const OverlayCandidate& other_candidate : *candidate_list) { |
| 61 if (other_candidate.display_rect.Intersects(candidate.display_rect) && |
| 62 other_candidate.plane_z_order == 1) { |
| 63 return DID_NOT_CREATE_OVERLAY; |
| 64 } |
| 65 } |
| 66 |
| 67 // Iterate through the quads in front of |candidate|, and compute the region |
| 68 // of |candidate| that is covered. |
65 Region pixel_covered_region; | 69 Region pixel_covered_region; |
66 for (auto overlap_iter = quad_list.cbegin(); | 70 for (auto overlap_iter = quad_list.cbegin(); |
67 overlap_iter != candidate_iter_in_quad_list; ++overlap_iter) { | 71 overlap_iter != *candidate_iter_in_quad_list; ++overlap_iter) { |
68 if (OverlayStrategyCommon::IsInvisibleQuad(*overlap_iter)) | 72 if (OverlayStrategyCommon::IsInvisibleQuad(*overlap_iter)) |
69 continue; | 73 continue; |
70 // Compute the quad's bounds in display space, and ensure that it is rounded | 74 // Compute the quad's bounds in display space, and ensure that it is rounded |
71 // up to be DIP-aligned. | 75 // up to be DIP-aligned. |
72 gfx::Rect unaligned_pixel_covered_rect = MathUtil::MapEnclosingClippedRect( | 76 gfx::Rect unaligned_pixel_covered_rect = MathUtil::MapEnclosingClippedRect( |
73 overlap_iter->shared_quad_state->quad_to_target_transform, | 77 overlap_iter->shared_quad_state->quad_to_target_transform, |
74 overlap_iter->rect); | 78 overlap_iter->rect); |
75 gfx::Rect pixel_covered_rect = | 79 gfx::Rect pixel_covered_rect = |
76 AlignPixelRectToDIP(device_scale_factor, unaligned_pixel_covered_rect); | 80 AlignPixelRectToDIP(device_scale_factor, unaligned_pixel_covered_rect); |
77 | 81 |
78 // Include the intersection of that quad with the candidate's quad in the | 82 // Include the intersection of that quad with the candidate's quad in the |
79 // covered region. | 83 // covered region. |
80 pixel_covered_rect.Intersect(candidate_pixel_rect); | 84 pixel_covered_rect.Intersect(candidate_pixel_rect); |
81 pixel_covered_region.Union(pixel_covered_rect); | 85 pixel_covered_region.Union(pixel_covered_rect); |
82 } | 86 } |
83 | 87 |
84 // Add our primary surface. | |
85 OverlayCandidateList new_candidate_list; | |
86 OverlayCandidate main_image; | |
87 main_image.display_rect = gfx::RectF(pixel_bounds); | |
88 new_candidate_list.push_back(main_image); | |
89 | |
90 // Add the candidate's overlay. | 88 // Add the candidate's overlay. |
91 DCHECK(candidate.resource_id); | 89 DCHECK(candidate.resource_id); |
| 90 OverlayCandidateList new_candidate_list = *candidate_list; |
92 new_candidate_list.push_back(candidate); | 91 new_candidate_list.push_back(candidate); |
93 new_candidate_list.back().plane_z_order = 1; | 92 new_candidate_list.back().plane_z_order = 1; |
94 | 93 |
95 // Add an overlay of the primary surface for any part of the candidate's | 94 // Add an overlay of the primary surface for any part of the candidate's |
96 // quad that was covered. | 95 // quad that was covered. |
97 std::vector<gfx::Rect> pixel_covered_rects; | 96 std::vector<gfx::Rect> pixel_covered_rects; |
98 for (Region::Iterator it(pixel_covered_region); it.has_rect(); it.next()) { | 97 for (Region::Iterator it(pixel_covered_region); it.has_rect(); it.next()) { |
99 DCHECK(IsPixelRectAlignedToDIP(device_scale_factor, it.rect())); | 98 DCHECK(IsPixelRectAlignedToDIP(device_scale_factor, it.rect())); |
100 pixel_covered_rects.push_back(it.rect()); | 99 pixel_covered_rects.push_back(it.rect()); |
101 } | 100 } |
102 for (const gfx::Rect& pixel_covered_rect : pixel_covered_rects) { | 101 for (const gfx::Rect& pixel_covered_rect : pixel_covered_rects) { |
103 OverlayCandidate main_image_on_top; | 102 OverlayCandidate main_image_on_top; |
104 main_image_on_top.display_rect = gfx::RectF(pixel_covered_rect); | 103 main_image_on_top.display_rect = gfx::RectF(pixel_covered_rect); |
105 main_image_on_top.uv_rect = gfx::RectF(pixel_covered_rect); | 104 main_image_on_top.uv_rect = gfx::RectF(pixel_covered_rect); |
106 main_image_on_top.uv_rect.Scale(1.f / pixel_bounds.width(), | 105 main_image_on_top.uv_rect.Scale(1.f / pixel_bounds.width(), |
107 1.f / pixel_bounds.height()); | 106 1.f / pixel_bounds.height()); |
108 main_image_on_top.plane_z_order = 2; | 107 main_image_on_top.plane_z_order = 2; |
109 main_image_on_top.transform = gfx::OVERLAY_TRANSFORM_NONE; | 108 main_image_on_top.transform = gfx::OVERLAY_TRANSFORM_NONE; |
110 main_image_on_top.use_output_surface_for_resource = true; | 109 main_image_on_top.use_output_surface_for_resource = true; |
111 new_candidate_list.push_back(main_image_on_top); | 110 new_candidate_list.push_back(main_image_on_top); |
112 } | 111 } |
113 | 112 |
114 // Check for support. | 113 // Check for support. |
115 capability_checker->CheckOverlaySupport(&new_candidate_list); | 114 capability_checker->CheckOverlaySupport(&new_candidate_list); |
116 for (const OverlayCandidate& candidate : new_candidate_list) { | 115 for (const OverlayCandidate& candidate : new_candidate_list) { |
117 if (candidate.plane_z_order > 0 && !candidate.overlay_handled) | 116 if (candidate.plane_z_order > 0 && !candidate.overlay_handled) |
118 return false; | 117 return DID_NOT_CREATE_OVERLAY; |
119 } | 118 } |
120 | 119 |
121 // Remove the quad for the overlay quad. Replace it with a transparent quad | 120 // Remove the quad for the overlay quad. Replace it with a transparent quad |
122 // if we're putting a new overlay on top. | 121 // if we're putting a new overlay on top. |
123 if (pixel_covered_rects.empty()) { | 122 if (pixel_covered_rects.empty()) { |
124 quad_list.EraseAndInvalidateAllPointers(candidate_iter_in_quad_list); | 123 *candidate_iter_in_quad_list = |
| 124 quad_list.EraseAndInvalidateAllPointers(*candidate_iter_in_quad_list); |
125 } else { | 125 } else { |
126 // Cache the information from the candidate quad that we'll need to | 126 // Cache the information from the candidate quad that we'll need to |
127 // construct the solid color quads. | 127 // construct the solid color quads. |
128 const SharedQuadState* candidate_shared_quad_state = | 128 const SharedQuadState* candidate_shared_quad_state = |
129 candidate_quad->shared_quad_state; | 129 candidate_quad->shared_quad_state; |
130 const gfx::Rect candidate_rect = candidate_quad->rect; | 130 const gfx::Rect candidate_rect = candidate_quad->rect; |
131 | 131 |
132 // Reserve space in the quad list for the transparent quads. | 132 // Reserve space in the quad list for the transparent quads. |
133 quad_list.ReplaceExistingElement<SolidColorDrawQuad>( | 133 quad_list.ReplaceExistingElement<SolidColorDrawQuad>( |
134 candidate_iter_in_quad_list); | 134 *candidate_iter_in_quad_list); |
135 candidate_iter_in_quad_list = | 135 *candidate_iter_in_quad_list = |
136 quad_list.InsertBeforeAndInvalidateAllPointers<SolidColorDrawQuad>( | 136 quad_list.InsertBeforeAndInvalidateAllPointers<SolidColorDrawQuad>( |
137 candidate_iter_in_quad_list, pixel_covered_rects.size() - 1); | 137 *candidate_iter_in_quad_list, pixel_covered_rects.size() - 1); |
138 | 138 |
139 // Cover the region with transparent quads. | 139 // Cover the region with transparent quads. |
140 for (const gfx::Rect& pixel_covered_rect : pixel_covered_rects) { | 140 for (const gfx::Rect& pixel_covered_rect : pixel_covered_rects) { |
141 gfx::Rect quad_space_covered_rect = MathUtil::MapEnclosingClippedRect( | 141 gfx::Rect quad_space_covered_rect = MathUtil::MapEnclosingClippedRect( |
142 candidate_inverse_transform, pixel_covered_rect); | 142 candidate_inverse_transform, pixel_covered_rect); |
143 quad_space_covered_rect.Intersect(candidate_rect); | 143 quad_space_covered_rect.Intersect(candidate_rect); |
144 | 144 |
145 SolidColorDrawQuad* transparent_quad = | 145 SolidColorDrawQuad* transparent_quad = |
146 static_cast<SolidColorDrawQuad*>(*candidate_iter_in_quad_list); | 146 static_cast<SolidColorDrawQuad*>(**candidate_iter_in_quad_list); |
147 transparent_quad->SetAll(candidate_shared_quad_state, | 147 transparent_quad->SetAll(candidate_shared_quad_state, |
148 quad_space_covered_rect, quad_space_covered_rect, | 148 quad_space_covered_rect, quad_space_covered_rect, |
149 quad_space_covered_rect, false, | 149 quad_space_covered_rect, false, |
150 SK_ColorTRANSPARENT, true); | 150 SK_ColorTRANSPARENT, true); |
151 ++candidate_iter_in_quad_list; | 151 ++(*candidate_iter_in_quad_list); |
152 } | 152 } |
153 } | 153 } |
154 | 154 |
155 output_candidate_list->swap(new_candidate_list); | 155 candidate_list->swap(new_candidate_list); |
156 return true; | 156 return CREATED_OVERLAY_KEEP_LOOKING; |
157 } | 157 } |
158 | 158 |
159 } // namespace cc | 159 } // namespace cc |
OLD | NEW |