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

Side by Side Diff: cc/region.cc

Issue 11410025: ui: Add SkIRectToRect() function to convert from SkIRect type to gfx::Rect. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 1 month 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/region.h" 5 #include "cc/region.h"
6 6
7 namespace cc { 7 namespace cc {
8 8
9 // TODO(danakj) Use method from ui/gfx/skia_utils.h when it exists.
10 static inline SkIRect ToSkIRect(gfx::Rect rect)
11 {
12 return SkIRect::MakeXYWH(rect.x(), rect.y(), rect.width(), rect.height());
13 }
14
15 Region::Region() { 9 Region::Region() {
16 } 10 }
17 11
18 Region::Region(const Region& region) 12 Region::Region(const Region& region)
19 : skregion_(region.skregion_) { 13 : skregion_(region.skregion_) {
20 } 14 }
21 15
22 Region::Region(gfx::Rect rect) 16 Region::Region(gfx::Rect rect)
23 : skregion_(ToSkIRect(rect)) { 17 : skregion_(gfx::RectToSkIRect(rect)) {
24 } 18 }
25 19
26 Region::~Region() { 20 Region::~Region() {
27 } 21 }
28 22
29 const Region& Region::operator=(gfx::Rect rect) { 23 const Region& Region::operator=(gfx::Rect rect) {
30 skregion_ = SkRegion(ToSkIRect(rect)); 24 skregion_ = SkRegion(gfx::RectToSkIRect(rect));
31 return *this; 25 return *this;
32 } 26 }
33 27
34 const Region& Region::operator=(const Region& region) { 28 const Region& Region::operator=(const Region& region) {
35 skregion_ = region.skregion_; 29 skregion_ = region.skregion_;
36 return *this; 30 return *this;
37 } 31 }
38 32
39 void Region::Swap(Region& region) { 33 void Region::Swap(Region& region) {
40 region.skregion_.swap(skregion_); 34 region.skregion_.swap(skregion_);
41 } 35 }
42 36
43 void Region::Clear() { 37 void Region::Clear() {
44 skregion_.setEmpty(); 38 skregion_.setEmpty();
45 } 39 }
46 40
47 bool Region::IsEmpty() const { 41 bool Region::IsEmpty() const {
48 return skregion_.isEmpty(); 42 return skregion_.isEmpty();
49 } 43 }
50 44
51 bool Region::Contains(gfx::Point point) const { 45 bool Region::Contains(gfx::Point point) const {
52 return skregion_.contains(point.x(), point.y()); 46 return skregion_.contains(point.x(), point.y());
53 } 47 }
54 48
55 bool Region::Contains(gfx::Rect rect) const { 49 bool Region::Contains(gfx::Rect rect) const {
56 if (rect.IsEmpty()) 50 if (rect.IsEmpty())
57 return true; 51 return true;
58 return skregion_.contains(ToSkIRect(rect)); 52 return skregion_.contains(gfx::RectToSkIRect(rect));
59 } 53 }
60 54
61 bool Region::Contains(const Region& region) const { 55 bool Region::Contains(const Region& region) const {
62 if (region.IsEmpty()) 56 if (region.IsEmpty())
63 return true; 57 return true;
64 return skregion_.contains(region.skregion_); 58 return skregion_.contains(region.skregion_);
65 } 59 }
66 60
67 bool Region::Intersects(gfx::Rect rect) const { 61 bool Region::Intersects(gfx::Rect rect) const {
68 return skregion_.intersects(ToSkIRect(rect)); 62 return skregion_.intersects(gfx::RectToSkIRect(rect));
69 } 63 }
70 64
71 bool Region::Intersects(const Region& region) const { 65 bool Region::Intersects(const Region& region) const {
72 return skregion_.intersects(region.skregion_); 66 return skregion_.intersects(region.skregion_);
73 } 67 }
74 68
75 void Region::Subtract(gfx::Rect rect) { 69 void Region::Subtract(gfx::Rect rect) {
76 skregion_.op(ToSkIRect(rect), SkRegion::kDifference_Op); 70 skregion_.op(gfx::RectToSkIRect(rect), SkRegion::kDifference_Op);
77 } 71 }
78 72
79 void Region::Subtract(const Region& region) { 73 void Region::Subtract(const Region& region) {
80 skregion_.op(region.skregion_, SkRegion::kDifference_Op); 74 skregion_.op(region.skregion_, SkRegion::kDifference_Op);
81 } 75 }
82 76
83 void Region::Union(gfx::Rect rect) { 77 void Region::Union(gfx::Rect rect) {
84 skregion_.op(ToSkIRect(rect), SkRegion::kUnion_Op); 78 skregion_.op(gfx::RectToSkIRect(rect), SkRegion::kUnion_Op);
85 } 79 }
86 80
87 void Region::Union(const Region& region) { 81 void Region::Union(const Region& region) {
88 skregion_.op(region.skregion_, SkRegion::kUnion_Op); 82 skregion_.op(region.skregion_, SkRegion::kUnion_Op);
89 } 83 }
90 84
91 void Region::Intersect(gfx::Rect rect) { 85 void Region::Intersect(gfx::Rect rect) {
92 skregion_.op(ToSkIRect(rect), SkRegion::kIntersect_Op); 86 skregion_.op(gfx::RectToSkIRect(rect), SkRegion::kIntersect_Op);
93 } 87 }
94 88
95 void Region::Intersect(const Region& region) { 89 void Region::Intersect(const Region& region) {
96 skregion_.op(region.skregion_, SkRegion::kIntersect_Op); 90 skregion_.op(region.skregion_, SkRegion::kIntersect_Op);
97 } 91 }
98 92
93 bool Region::Equals(const Region& other) const {
94 return skregion_ == other.skregion_;
95 }
96
99 std::string Region::ToString() const { 97 std::string Region::ToString() const {
100 if (IsEmpty()) 98 if (IsEmpty())
101 return gfx::Rect().ToString(); 99 return gfx::Rect().ToString();
102 100
103 std::string result; 101 std::string result;
104 for (Iterator it(*this); it.has_rect(); it.next()) { 102 for (Iterator it(*this); it.has_rect(); it.next()) {
105 if (!result.empty()) 103 if (!result.empty())
106 result += " | "; 104 result += " | ";
107 result += it.rect().ToString(); 105 result += it.rect().ToString();
108 } 106 }
109 return result; 107 return result;
110 } 108 }
111 109
112 Region::Iterator::Iterator(const Region& region) 110 Region::Iterator::Iterator(const Region& region)
113 : it_(region.skregion_) { 111 : it_(region.skregion_) {
114 } 112 }
115 113
116 Region::Iterator::~Iterator() { 114 Region::Iterator::~Iterator() {
117 } 115 }
118 116
119 } // namespace cc 117 } // namespace cc
OLDNEW
« cc/region.h ('K') | « cc/region.h ('k') | ui/gfx/skia_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698