| 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/region.h" | 7 #include "cc/base/region.h" |
| 8 #include "cc/output/overlay_candidate_validator.h" | 8 #include "cc/output/overlay_candidate_validator.h" |
| 9 #include "cc/quads/draw_quad.h" | 9 #include "cc/quads/draw_quad.h" |
| 10 #include "cc/quads/solid_color_draw_quad.h" | 10 #include "cc/quads/solid_color_draw_quad.h" |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 main_image.display_rect = pixel_bounds; | 87 main_image.display_rect = pixel_bounds; |
| 88 new_candidate_list.push_back(main_image); | 88 new_candidate_list.push_back(main_image); |
| 89 | 89 |
| 90 // Add the candidate's overlay. | 90 // Add the candidate's overlay. |
| 91 DCHECK(candidate.resource_id); | 91 DCHECK(candidate.resource_id); |
| 92 new_candidate_list.push_back(candidate); | 92 new_candidate_list.push_back(candidate); |
| 93 new_candidate_list.back().plane_z_order = 1; | 93 new_candidate_list.back().plane_z_order = 1; |
| 94 | 94 |
| 95 // Add an overlay of the primary surface for any part of the candidate's | 95 // Add an overlay of the primary surface for any part of the candidate's |
| 96 // quad that was covered. | 96 // quad that was covered. |
| 97 // TODO(ccameron): Create an OverlayCandidate for each rect in the region. | 97 std::vector<gfx::Rect> pixel_covered_rects; |
| 98 gfx::Rect pixel_covered_rect = pixel_covered_region.bounds(); | 98 for (Region::Iterator it(pixel_covered_region); it.has_rect(); it.next()) { |
| 99 DCHECK(IsPixelRectAlignedToDIP(device_scale_factor, pixel_covered_rect)); | 99 DCHECK(IsPixelRectAlignedToDIP(device_scale_factor, it.rect())); |
| 100 if (!pixel_covered_rect.IsEmpty()) { | 100 pixel_covered_rects.push_back(it.rect()); |
| 101 } |
| 102 for (const gfx::Rect& pixel_covered_rect : pixel_covered_rects) { |
| 101 OverlayCandidate main_image_on_top; | 103 OverlayCandidate main_image_on_top; |
| 102 main_image_on_top.display_rect = pixel_covered_rect; | 104 main_image_on_top.display_rect = pixel_covered_rect; |
| 103 main_image_on_top.uv_rect = pixel_covered_rect; | 105 main_image_on_top.uv_rect = pixel_covered_rect; |
| 104 main_image_on_top.uv_rect.Scale(1.f / pixel_bounds.width(), | 106 main_image_on_top.uv_rect.Scale(1.f / pixel_bounds.width(), |
| 105 1.f / pixel_bounds.height()); | 107 1.f / pixel_bounds.height()); |
| 106 main_image_on_top.plane_z_order = 2; | 108 main_image_on_top.plane_z_order = 2; |
| 107 main_image_on_top.transform = gfx::OVERLAY_TRANSFORM_NONE; | 109 main_image_on_top.transform = gfx::OVERLAY_TRANSFORM_NONE; |
| 108 main_image_on_top.use_output_surface_for_resource = true; | 110 main_image_on_top.use_output_surface_for_resource = true; |
| 109 new_candidate_list.push_back(main_image_on_top); | 111 new_candidate_list.push_back(main_image_on_top); |
| 110 } | 112 } |
| 111 | 113 |
| 112 // Check for support. | 114 // Check for support. |
| 113 capability_checker->CheckOverlaySupport(&new_candidate_list); | 115 capability_checker->CheckOverlaySupport(&new_candidate_list); |
| 114 for (const OverlayCandidate& candidate : new_candidate_list) { | 116 for (const OverlayCandidate& candidate : new_candidate_list) { |
| 115 if (candidate.plane_z_order > 0 && !candidate.overlay_handled) | 117 if (candidate.plane_z_order > 0 && !candidate.overlay_handled) |
| 116 return false; | 118 return false; |
| 117 } | 119 } |
| 118 | 120 |
| 119 // Remove the quad for the overlay quad. Replace it with a transparent quad | 121 // Remove the quad for the overlay quad. Replace it with a transparent quad |
| 120 // if we're putting a new overlay on top. | 122 // if we're putting a new overlay on top. |
| 121 if (pixel_covered_rect.IsEmpty()) { | 123 if (pixel_covered_rects.empty()) { |
| 122 quad_list.EraseAndInvalidateAllPointers(candidate_iter_in_quad_list); | 124 quad_list.EraseAndInvalidateAllPointers(candidate_iter_in_quad_list); |
| 123 } else { | 125 } else { |
| 124 gfx::RectF quad_space_covered_rect_float = pixel_covered_rect; | 126 // Cache the information from the candidate quad that we'll need to |
| 125 candidate_inverse_transform.TransformRect(&quad_space_covered_rect_float); | 127 // construct the solid color quads. |
| 126 gfx::Rect quad_space_covered_rect = | 128 const SharedQuadState* candidate_shared_quad_state = |
| 127 gfx::ToEnclosingRect(quad_space_covered_rect_float); | 129 candidate_quad->shared_quad_state; |
| 128 quad_space_covered_rect.Intersect(candidate_quad->rect); | 130 const gfx::Rect candidate_rect = candidate_quad->rect; |
| 129 | 131 |
| 130 const SharedQuadState* shared_quad_state = | 132 // Reserve space in the quad list for the transparent quads. |
| 131 candidate_quad->shared_quad_state; | 133 quad_list.ReplaceExistingElement<SolidColorDrawQuad>( |
| 134 candidate_iter_in_quad_list); |
| 135 candidate_iter_in_quad_list = |
| 136 quad_list.InsertBeforeAndInvalidateAllPointers<SolidColorDrawQuad>( |
| 137 candidate_iter_in_quad_list, pixel_covered_rects.size() - 1); |
| 132 | 138 |
| 133 SolidColorDrawQuad* replacement = | 139 // Cover the region with transparent quads. |
| 134 quad_list.ReplaceExistingElement<SolidColorDrawQuad>( | 140 for (const gfx::Rect& pixel_covered_rect : pixel_covered_rects) { |
| 135 candidate_iter_in_quad_list); | 141 gfx::RectF quad_space_covered_rect_float = pixel_covered_rect; |
| 136 replacement->SetAll(shared_quad_state, quad_space_covered_rect, | 142 candidate_inverse_transform.TransformRect(&quad_space_covered_rect_float); |
| 137 quad_space_covered_rect, quad_space_covered_rect, false, | 143 gfx::Rect quad_space_covered_rect = |
| 138 SK_ColorTRANSPARENT, true); | 144 gfx::ToEnclosingRect(quad_space_covered_rect_float); |
| 145 quad_space_covered_rect.Intersect(candidate_rect); |
| 146 |
| 147 SolidColorDrawQuad* transparent_quad = |
| 148 static_cast<SolidColorDrawQuad*>(*candidate_iter_in_quad_list); |
| 149 transparent_quad->SetAll(candidate_shared_quad_state, |
| 150 quad_space_covered_rect, quad_space_covered_rect, |
| 151 quad_space_covered_rect, false, |
| 152 SK_ColorTRANSPARENT, true); |
| 153 ++candidate_iter_in_quad_list; |
| 154 } |
| 139 } | 155 } |
| 140 | 156 |
| 141 output_candidate_list->swap(new_candidate_list); | 157 output_candidate_list->swap(new_candidate_list); |
| 142 return true; | 158 return true; |
| 143 } | 159 } |
| 144 | 160 |
| 145 } // namespace cc | 161 } // namespace cc |
| OLD | NEW |