Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/base/simple_enclosed_region.h" | 5 #include "cc/base/simple_enclosed_region.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "cc/base/region.h" | 11 #include "cc/base/region.h" |
| 12 #include "ui/gfx/geometry/rect.h" | |
| 12 | 13 |
| 13 namespace cc { | 14 namespace cc { |
| 14 | 15 |
| 15 static bool RectIsLargerArea(const gfx::Rect& a, const gfx::Rect b) { | 16 static bool RectIsLargerArea(const gfx::Rect& a, const gfx::Rect b) { |
| 16 int64_t a_area = static_cast<int64_t>(a.width()) * a.height(); | 17 int64_t a_area = static_cast<int64_t>(a.width()) * a.height(); |
| 17 int64_t b_area = static_cast<int64_t>(b.width()) * b.height(); | 18 int64_t b_area = static_cast<int64_t>(b.width()) * b.height(); |
| 18 return a_area > b_area; | 19 return a_area > b_area; |
| 19 } | 20 } |
| 20 | 21 |
| 21 SimpleEnclosedRegion::SimpleEnclosedRegion(const Region& region) { | 22 SimpleEnclosedRegion::SimpleEnclosedRegion(const Region& region) { |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 117 if (right > new_right && left <= new_right) | 118 if (right > new_right && left <= new_right) |
| 118 new_right = right; | 119 new_right = right; |
| 119 } else if (left <= new_left && right >= new_right) { | 120 } else if (left <= new_left && right >= new_right) { |
| 120 if (top < new_top && bottom >= new_top) | 121 if (top < new_top && bottom >= new_top) |
| 121 new_top = top; | 122 new_top = top; |
| 122 if (bottom > new_bottom && top <= new_bottom) | 123 if (bottom > new_bottom && top <= new_bottom) |
| 123 new_bottom = bottom; | 124 new_bottom = bottom; |
| 124 } | 125 } |
| 125 | 126 |
| 126 rect_.SetRect(left, top, right - left, bottom - top); | 127 rect_.SetRect(left, top, right - left, bottom - top); |
| 127 | 128 int64_t rect_area = static_cast<int64_t>(rect_.width()) * rect_.height(); |
| 128 gfx::Rect adjusted_new_rect( | 129 gfx::Rect adjusted_new_rect( |
| 129 new_left, new_top, new_right - new_left, new_bottom - new_top); | 130 new_left, new_top, new_right - new_left, new_bottom - new_top); |
| 130 if (RectIsLargerArea(adjusted_new_rect, rect_)) | 131 int64_t adjust_new_rect_area = |
| 132 static_cast<int64_t>(adjusted_new_rect.width()) * | |
| 133 adjusted_new_rect.height(); | |
| 134 gfx::Rect overlap = gfx::IntersectRects(rect_, adjusted_new_rect); | |
| 135 int64_t overlap_area = | |
| 136 static_cast<int64_t>(overlap.width()) * overlap.height(); | |
| 137 | |
| 138 // Based on the assumption that as we compute occlusion, each step is | |
| 139 // more likely to be occluded by things added to this region more recently due | |
| 140 // to the way we build scenes with overlapping elements adjacent to each other | |
| 141 // in the Z order. So, the area of the new rect as a weight of 2 in the | |
|
danakj
2017/05/17 15:17:40
has a weight
| |
| 142 // weighted area calculation. | |
| 143 if (adjust_new_rect_area * 2 > rect_area + overlap_area) | |
| 131 rect_ = adjusted_new_rect; | 144 rect_ = adjusted_new_rect; |
| 132 } | 145 } |
| 133 | 146 |
| 134 gfx::Rect SimpleEnclosedRegion::GetRect(size_t i) const { | 147 gfx::Rect SimpleEnclosedRegion::GetRect(size_t i) const { |
| 135 DCHECK_LT(i, GetRegionComplexity()); | 148 DCHECK_LT(i, GetRegionComplexity()); |
| 136 return rect_; | 149 return rect_; |
| 137 } | 150 } |
| 138 | 151 |
| 139 } // namespace cc | 152 } // namespace cc |
| OLD | NEW |