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