| 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" |
| 11 #include "cc/quads/solid_color_draw_quad.h" | 11 #include "cc/quads/solid_color_draw_quad.h" |
| 12 #include "ui/gfx/geometry/dip_util.h" |
| 13 #include "ui/gfx/geometry/rect_conversions.h" |
| 12 | 14 |
| 13 namespace cc { | 15 namespace cc { |
| 14 | 16 |
| 15 namespace { | |
| 16 | |
| 17 void ClipDisplayAndUVRects(gfx::Rect* display_rect, | |
| 18 gfx::RectF* uv_rect, | |
| 19 const gfx::Rect& clip_rect) { | |
| 20 gfx::Rect display_cropped_rect = | |
| 21 gfx::IntersectRects(*display_rect, clip_rect); | |
| 22 | |
| 23 gfx::RectF uv_cropped_rect = gfx::RectF(display_cropped_rect); | |
| 24 uv_cropped_rect -= gfx::Vector2dF(display_rect->x(), display_rect->y()); | |
| 25 uv_cropped_rect.Scale(uv_rect->width() / display_rect->width(), | |
| 26 uv_rect->height() / display_rect->height()); | |
| 27 uv_cropped_rect += gfx::Vector2dF(uv_rect->x(), uv_rect->y()); | |
| 28 | |
| 29 *display_rect = display_cropped_rect; | |
| 30 *uv_rect = uv_cropped_rect; | |
| 31 } | |
| 32 | |
| 33 } // namespace | |
| 34 | |
| 35 OverlayStrategySandwich::~OverlayStrategySandwich() {} | 17 OverlayStrategySandwich::~OverlayStrategySandwich() {} |
| 36 | 18 |
| 37 OverlayResult OverlayStrategySandwich::TryOverlay( | 19 OverlayResult OverlayStrategySandwich::TryOverlay( |
| 38 OverlayCandidateValidator* capability_checker, | 20 OverlayCandidateValidator* capability_checker, |
| 39 RenderPassList* render_passes_in_draw_order, | 21 RenderPassList* render_passes_in_draw_order, |
| 40 OverlayCandidateList* candidate_list, | 22 OverlayCandidateList* candidate_list, |
| 41 const OverlayCandidate& candidate, | 23 const OverlayCandidate& candidate, |
| 42 QuadList::Iterator* candidate_iter_in_quad_list, | 24 QuadList::Iterator* candidate_iter_in_quad_list, |
| 43 float device_scale_factor) { | 25 float device_scale_factor) { |
| 44 RenderPass* root_render_pass = render_passes_in_draw_order->back(); | 26 RenderPass* root_render_pass = render_passes_in_draw_order->back(); |
| 45 QuadList& quad_list = root_render_pass->quad_list; | 27 QuadList& quad_list = root_render_pass->quad_list; |
| 46 gfx::Rect pixel_bounds = root_render_pass->output_rect; | 28 gfx::Rect pixel_bounds = root_render_pass->output_rect; |
| 47 | 29 |
| 48 const DrawQuad* candidate_quad = **candidate_iter_in_quad_list; | 30 const DrawQuad* candidate_quad = **candidate_iter_in_quad_list; |
| 49 const gfx::Transform& candidate_transform = | 31 const gfx::Transform& candidate_transform = |
| 50 candidate_quad->shared_quad_state->quad_to_target_transform; | 32 candidate_quad->shared_quad_state->quad_to_target_transform; |
| 51 gfx::Transform candidate_inverse_transform; | 33 gfx::Transform candidate_inverse_transform; |
| 52 if (!candidate_transform.GetInverse(&candidate_inverse_transform)) | 34 if (!candidate_transform.GetInverse(&candidate_inverse_transform)) |
| 53 return DID_NOT_CREATE_OVERLAY; | 35 return DID_NOT_CREATE_OVERLAY; |
| 54 | 36 |
| 55 // Compute the candidate's rect in display space (pixels on the screen). | 37 // Compute the candidate's rect in display space (pixels on the screen). The |
| 56 gfx::Rect candidate_pixel_rect = candidate.quad_rect_in_target_space; | 38 // rect needs to be DIP-aligned, or we cannot use it. |
| 57 gfx::RectF candidate_uv_rect = candidate.uv_rect; | 39 const gfx::Rect candidate_pixel_rect = |
| 58 if (candidate.is_clipped && | 40 gfx::ToNearestRect(candidate.display_rect); |
| 59 !candidate.clip_rect.Contains(candidate_pixel_rect)) { | |
| 60 ClipDisplayAndUVRects(&candidate_pixel_rect, &candidate_uv_rect, | |
| 61 candidate.clip_rect); | |
| 62 } | |
| 63 | 41 |
| 64 // Don't allow overlapping overlays for now. | 42 // Don't allow overlapping overlays for now. |
| 65 for (const OverlayCandidate& other_candidate : *candidate_list) { | 43 for (const OverlayCandidate& other_candidate : *candidate_list) { |
| 66 if (other_candidate.display_rect.Intersects(candidate.display_rect) && | 44 if (other_candidate.display_rect.Intersects(candidate.display_rect) && |
| 67 other_candidate.plane_z_order == 1) { | 45 other_candidate.plane_z_order == 1) { |
| 68 return DID_NOT_CREATE_OVERLAY; | 46 return DID_NOT_CREATE_OVERLAY; |
| 69 } | 47 } |
| 70 } | 48 } |
| 71 | 49 |
| 72 // Iterate through the quads in front of |candidate|, and compute the region | 50 // Iterate through the quads in front of |candidate|, and compute the region |
| 73 // of |candidate| that is covered. | 51 // of |candidate| that is covered. |
| 74 Region pixel_covered_region; | 52 Region pixel_covered_region; |
| 75 for (auto overlap_iter = quad_list.cbegin(); | 53 for (auto overlap_iter = quad_list.cbegin(); |
| 76 overlap_iter != *candidate_iter_in_quad_list; ++overlap_iter) { | 54 overlap_iter != *candidate_iter_in_quad_list; ++overlap_iter) { |
| 77 if (OverlayStrategyCommon::IsInvisibleQuad(*overlap_iter)) | 55 if (OverlayStrategyCommon::IsInvisibleQuad(*overlap_iter)) |
| 78 continue; | 56 continue; |
| 79 // Compute the quad's bounds in display space. | 57 // Compute the quad's bounds in display space, and ensure that it is rounded |
| 58 // up to be DIP-aligned. |
| 80 gfx::Rect pixel_covered_rect = MathUtil::MapEnclosingClippedRect( | 59 gfx::Rect pixel_covered_rect = MathUtil::MapEnclosingClippedRect( |
| 81 overlap_iter->shared_quad_state->quad_to_target_transform, | 60 overlap_iter->shared_quad_state->quad_to_target_transform, |
| 82 overlap_iter->rect); | 61 overlap_iter->rect); |
| 83 | 62 |
| 84 // Include the intersection of that quad with the candidate's quad in the | 63 // Include the intersection of that quad with the candidate's quad in the |
| 85 // covered region. | 64 // covered region. |
| 86 pixel_covered_rect.Intersect(candidate_pixel_rect); | 65 pixel_covered_rect.Intersect(candidate_pixel_rect); |
| 87 pixel_covered_region.Union(pixel_covered_rect); | 66 pixel_covered_region.Union(pixel_covered_rect); |
| 88 } | 67 } |
| 89 | 68 |
| 90 // Add the candidate's overlay. | 69 // Add the candidate's overlay. |
| 91 DCHECK(candidate.resource_id); | 70 DCHECK(candidate.resource_id); |
| 92 OverlayCandidateList new_candidate_list = *candidate_list; | 71 OverlayCandidateList new_candidate_list = *candidate_list; |
| 93 new_candidate_list.push_back(candidate); | 72 new_candidate_list.push_back(candidate); |
| 94 OverlayCandidate& new_candidate = new_candidate_list.back(); | 73 new_candidate_list.back().plane_z_order = 1; |
| 95 new_candidate.plane_z_order = 1; | |
| 96 new_candidate.display_rect = gfx::RectF(candidate_pixel_rect); | |
| 97 new_candidate.quad_rect_in_target_space = candidate_pixel_rect; | |
| 98 new_candidate.uv_rect = candidate_uv_rect; | |
| 99 | 74 |
| 100 // Add an overlay of the primary surface for any part of the candidate's | 75 // Add an overlay of the primary surface for any part of the candidate's |
| 101 // quad that was covered. | 76 // quad that was covered. |
| 102 std::vector<gfx::Rect> pixel_covered_rects; | 77 std::vector<gfx::Rect> pixel_covered_rects; |
| 103 for (Region::Iterator it(pixel_covered_region); it.has_rect(); it.next()) | 78 for (Region::Iterator it(pixel_covered_region); it.has_rect(); it.next()) |
| 104 pixel_covered_rects.push_back(it.rect()); | 79 pixel_covered_rects.push_back(it.rect()); |
| 105 for (const gfx::Rect& pixel_covered_rect : pixel_covered_rects) { | 80 for (const gfx::Rect& pixel_covered_rect : pixel_covered_rects) { |
| 106 OverlayCandidate main_image_on_top; | 81 OverlayCandidate main_image_on_top; |
| 107 main_image_on_top.display_rect = gfx::RectF(pixel_covered_rect); | 82 main_image_on_top.display_rect = gfx::RectF(pixel_covered_rect); |
| 108 main_image_on_top.uv_rect = gfx::RectF(pixel_covered_rect); | 83 main_image_on_top.uv_rect = gfx::RectF(pixel_covered_rect); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 SK_ColorTRANSPARENT, true); | 129 SK_ColorTRANSPARENT, true); |
| 155 ++(*candidate_iter_in_quad_list); | 130 ++(*candidate_iter_in_quad_list); |
| 156 } | 131 } |
| 157 } | 132 } |
| 158 | 133 |
| 159 candidate_list->swap(new_candidate_list); | 134 candidate_list->swap(new_candidate_list); |
| 160 return CREATED_OVERLAY_KEEP_LOOKING; | 135 return CREATED_OVERLAY_KEEP_LOOKING; |
| 161 } | 136 } |
| 162 | 137 |
| 163 } // namespace cc | 138 } // namespace cc |
| OLD | NEW |