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