| OLD | NEW |
| 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 |
| 99 std::string Region::ToString() const { | 93 std::string Region::ToString() const { |
| 100 if (IsEmpty()) | 94 if (IsEmpty()) |
| 101 return gfx::Rect().ToString(); | 95 return gfx::Rect().ToString(); |
| 102 | 96 |
| 103 std::string result; | 97 std::string result; |
| 104 for (Iterator it(*this); it.has_rect(); it.next()) { | 98 for (Iterator it(*this); it.has_rect(); it.next()) { |
| 105 if (!result.empty()) | 99 if (!result.empty()) |
| 106 result += " | "; | 100 result += " | "; |
| 107 result += it.rect().ToString(); | 101 result += it.rect().ToString(); |
| 108 } | 102 } |
| 109 return result; | 103 return result; |
| 110 } | 104 } |
| 111 | 105 |
| 112 Region::Iterator::Iterator(const Region& region) | 106 Region::Iterator::Iterator(const Region& region) |
| 113 : it_(region.skregion_) { | 107 : it_(region.skregion_) { |
| 114 } | 108 } |
| 115 | 109 |
| 116 Region::Iterator::~Iterator() { | 110 Region::Iterator::~Iterator() { |
| 117 } | 111 } |
| 118 | 112 |
| 119 } // namespace cc | 113 } // namespace cc |
| OLD | NEW |