Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(450)

Side by Side Diff: cc/base/simple_enclosed_region.cc

Issue 2866063002: Improve overdraw with multiple windows (Closed)
Patch Set: Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
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 gfx::Rect overlap = gfx::IntersectRects(rect_, adjusted_new_rect);
132
133 int64_t weighted_rect_area =
danakj 2017/05/15 21:47:42 I suggest to build 3 rects, old_rect_area, overlap
yiyix 2017/05/17 03:00:31 I agree. If the area calculation is done separatel
134 static_cast<int64_t>(rect_.width() * rect_.height()) +
danakj 2017/05/15 21:47:42 cast just the width, that will promote before the
yiyix 2017/05/17 03:00:31 Done.
135 static_cast<int64_t>(overlap.width() * overlap.height());
danakj 2017/05/15 21:47:42 same
yiyix 2017/05/17 03:00:31 Done.
136 int64_t weighted_adjusted_new_rect_area =
137 2 * static_cast<int64_t>(adjusted_new_rect.width() *
danakj 2017/05/15 21:47:42 same
yiyix 2017/05/17 03:00:31 Done.
138 adjusted_new_rect.height());
139 if (weighted_adjusted_new_rect_area > weighted_rect_area)
danakj 2017/05/15 21:47:42 Can you put a comment here explaining roughly what
yiyix 2017/05/17 03:00:31 I will add this to both. Your wording is better! T
131 rect_ = adjusted_new_rect; 140 rect_ = adjusted_new_rect;
132 } 141 }
133 142
134 gfx::Rect SimpleEnclosedRegion::GetRect(size_t i) const { 143 gfx::Rect SimpleEnclosedRegion::GetRect(size_t i) const {
135 DCHECK_LT(i, GetRegionComplexity()); 144 DCHECK_LT(i, GetRegionComplexity());
136 return rect_; 145 return rect_;
137 } 146 }
138 147
139 } // namespace cc 148 } // namespace cc
OLDNEW
« no previous file with comments | « no previous file | cc/base/simple_enclosed_region_unittest.cc » ('j') | cc/base/simple_enclosed_region_unittest.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698