OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "cc/region.h" | |
6 | |
7 namespace cc { | |
8 | |
9 Region::Region() { | |
10 } | |
11 | |
12 Region::Region(const Region& region) | |
13 : skregion_(region.skregion_) { | |
14 } | |
15 | |
16 Region::Region(gfx::Rect rect) | |
17 : skregion_(gfx::RectToSkIRect(rect)) { | |
18 } | |
19 | |
20 Region::~Region() { | |
21 } | |
22 | |
23 const Region& Region::operator=(gfx::Rect rect) { | |
24 skregion_ = SkRegion(gfx::RectToSkIRect(rect)); | |
25 return *this; | |
26 } | |
27 | |
28 const Region& Region::operator=(const Region& region) { | |
29 skregion_ = region.skregion_; | |
30 return *this; | |
31 } | |
32 | |
33 void Region::Swap(Region& region) { | |
34 region.skregion_.swap(skregion_); | |
35 } | |
36 | |
37 void Region::Clear() { | |
38 skregion_.setEmpty(); | |
39 } | |
40 | |
41 bool Region::IsEmpty() const { | |
42 return skregion_.isEmpty(); | |
43 } | |
44 | |
45 bool Region::Contains(gfx::Point point) const { | |
46 return skregion_.contains(point.x(), point.y()); | |
47 } | |
48 | |
49 bool Region::Contains(gfx::Rect rect) const { | |
50 if (rect.IsEmpty()) | |
51 return true; | |
52 return skregion_.contains(gfx::RectToSkIRect(rect)); | |
53 } | |
54 | |
55 bool Region::Contains(const Region& region) const { | |
56 if (region.IsEmpty()) | |
57 return true; | |
58 return skregion_.contains(region.skregion_); | |
59 } | |
60 | |
61 bool Region::Intersects(gfx::Rect rect) const { | |
62 return skregion_.intersects(gfx::RectToSkIRect(rect)); | |
63 } | |
64 | |
65 bool Region::Intersects(const Region& region) const { | |
66 return skregion_.intersects(region.skregion_); | |
67 } | |
68 | |
69 void Region::Subtract(gfx::Rect rect) { | |
70 skregion_.op(gfx::RectToSkIRect(rect), SkRegion::kDifference_Op); | |
71 } | |
72 | |
73 void Region::Subtract(const Region& region) { | |
74 skregion_.op(region.skregion_, SkRegion::kDifference_Op); | |
75 } | |
76 | |
77 void Region::Union(gfx::Rect rect) { | |
78 skregion_.op(gfx::RectToSkIRect(rect), SkRegion::kUnion_Op); | |
79 } | |
80 | |
81 void Region::Union(const Region& region) { | |
82 skregion_.op(region.skregion_, SkRegion::kUnion_Op); | |
83 } | |
84 | |
85 void Region::Intersect(gfx::Rect rect) { | |
86 skregion_.op(gfx::RectToSkIRect(rect), SkRegion::kIntersect_Op); | |
87 } | |
88 | |
89 void Region::Intersect(const Region& region) { | |
90 skregion_.op(region.skregion_, SkRegion::kIntersect_Op); | |
91 } | |
92 | |
93 std::string Region::ToString() const { | |
94 if (IsEmpty()) | |
95 return gfx::Rect().ToString(); | |
96 | |
97 std::string result; | |
98 for (Iterator it(*this); it.has_rect(); it.next()) { | |
99 if (!result.empty()) | |
100 result += " | "; | |
101 result += it.rect().ToString(); | |
102 } | |
103 return result; | |
104 } | |
105 | |
106 Region::Iterator::Iterator() { | |
107 } | |
108 | |
109 Region::Iterator::Iterator(const Region& region) | |
110 : it_(region.skregion_) { | |
111 } | |
112 | |
113 Region::Iterator::~Iterator() { | |
114 } | |
115 | |
116 } // namespace cc | |
OLD | NEW |