| 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/base/region.h" | 5 #include "cc/base/region.h" |
| 6 #include "base/values.h" | 6 #include "base/values.h" |
| 7 | 7 |
| 8 namespace cc { | 8 namespace cc { |
| 9 | 9 |
| 10 Region::Region() { | 10 Region::Region() { |
| 11 } | 11 } |
| 12 | 12 |
| 13 Region::Region(const Region& region) | 13 Region::Region(const Region& region) |
| 14 : skregion_(region.skregion_) { | 14 : skregion_(region.skregion_) { |
| 15 } | 15 } |
| 16 | 16 |
| 17 Region::Region(gfx::Rect rect) | 17 Region::Region(const gfx::Rect& rect) |
| 18 : skregion_(gfx::RectToSkIRect(rect)) { | 18 : skregion_(gfx::RectToSkIRect(rect)) { |
| 19 } | 19 } |
| 20 | 20 |
| 21 Region::~Region() { | 21 Region::~Region() { |
| 22 } | 22 } |
| 23 | 23 |
| 24 const Region& Region::operator=(gfx::Rect rect) { | 24 const Region& Region::operator=(const gfx::Rect& rect) { |
| 25 skregion_ = SkRegion(gfx::RectToSkIRect(rect)); | 25 skregion_ = SkRegion(gfx::RectToSkIRect(rect)); |
| 26 return *this; | 26 return *this; |
| 27 } | 27 } |
| 28 | 28 |
| 29 const Region& Region::operator=(const Region& region) { | 29 const Region& Region::operator=(const Region& region) { |
| 30 skregion_ = region.skregion_; | 30 skregion_ = region.skregion_; |
| 31 return *this; | 31 return *this; |
| 32 } | 32 } |
| 33 | 33 |
| 34 void Region::Swap(Region* region) { | 34 void Region::Swap(Region* region) { |
| 35 region->skregion_.swap(skregion_); | 35 region->skregion_.swap(skregion_); |
| 36 } | 36 } |
| 37 | 37 |
| 38 void Region::Clear() { | 38 void Region::Clear() { |
| 39 skregion_.setEmpty(); | 39 skregion_.setEmpty(); |
| 40 } | 40 } |
| 41 | 41 |
| 42 bool Region::IsEmpty() const { | 42 bool Region::IsEmpty() const { |
| 43 return skregion_.isEmpty(); | 43 return skregion_.isEmpty(); |
| 44 } | 44 } |
| 45 | 45 |
| 46 int Region::GetRegionComplexity() const { | 46 int Region::GetRegionComplexity() const { |
| 47 return skregion_.computeRegionComplexity(); | 47 return skregion_.computeRegionComplexity(); |
| 48 } | 48 } |
| 49 | 49 |
| 50 bool Region::Contains(gfx::Point point) const { | 50 bool Region::Contains(gfx::Point point) const { |
| 51 return skregion_.contains(point.x(), point.y()); | 51 return skregion_.contains(point.x(), point.y()); |
| 52 } | 52 } |
| 53 | 53 |
| 54 bool Region::Contains(gfx::Rect rect) const { | 54 bool Region::Contains(const gfx::Rect& rect) const { |
| 55 if (rect.IsEmpty()) | 55 if (rect.IsEmpty()) |
| 56 return true; | 56 return true; |
| 57 return skregion_.contains(gfx::RectToSkIRect(rect)); | 57 return skregion_.contains(gfx::RectToSkIRect(rect)); |
| 58 } | 58 } |
| 59 | 59 |
| 60 bool Region::Contains(const Region& region) const { | 60 bool Region::Contains(const Region& region) const { |
| 61 if (region.IsEmpty()) | 61 if (region.IsEmpty()) |
| 62 return true; | 62 return true; |
| 63 return skregion_.contains(region.skregion_); | 63 return skregion_.contains(region.skregion_); |
| 64 } | 64 } |
| 65 | 65 |
| 66 bool Region::Intersects(gfx::Rect rect) const { | 66 bool Region::Intersects(const gfx::Rect& rect) const { |
| 67 return skregion_.intersects(gfx::RectToSkIRect(rect)); | 67 return skregion_.intersects(gfx::RectToSkIRect(rect)); |
| 68 } | 68 } |
| 69 | 69 |
| 70 bool Region::Intersects(const Region& region) const { | 70 bool Region::Intersects(const Region& region) const { |
| 71 return skregion_.intersects(region.skregion_); | 71 return skregion_.intersects(region.skregion_); |
| 72 } | 72 } |
| 73 | 73 |
| 74 void Region::Subtract(gfx::Rect rect) { | 74 void Region::Subtract(const gfx::Rect& rect) { |
| 75 skregion_.op(gfx::RectToSkIRect(rect), SkRegion::kDifference_Op); | 75 skregion_.op(gfx::RectToSkIRect(rect), SkRegion::kDifference_Op); |
| 76 } | 76 } |
| 77 | 77 |
| 78 void Region::Subtract(const Region& region) { | 78 void Region::Subtract(const Region& region) { |
| 79 skregion_.op(region.skregion_, SkRegion::kDifference_Op); | 79 skregion_.op(region.skregion_, SkRegion::kDifference_Op); |
| 80 } | 80 } |
| 81 | 81 |
| 82 void Region::Union(gfx::Rect rect) { | 82 void Region::Union(const gfx::Rect& rect) { |
| 83 skregion_.op(gfx::RectToSkIRect(rect), SkRegion::kUnion_Op); | 83 skregion_.op(gfx::RectToSkIRect(rect), SkRegion::kUnion_Op); |
| 84 } | 84 } |
| 85 | 85 |
| 86 void Region::Union(const Region& region) { | 86 void Region::Union(const Region& region) { |
| 87 skregion_.op(region.skregion_, SkRegion::kUnion_Op); | 87 skregion_.op(region.skregion_, SkRegion::kUnion_Op); |
| 88 } | 88 } |
| 89 | 89 |
| 90 void Region::Intersect(gfx::Rect rect) { | 90 void Region::Intersect(const gfx::Rect& rect) { |
| 91 skregion_.op(gfx::RectToSkIRect(rect), SkRegion::kIntersect_Op); | 91 skregion_.op(gfx::RectToSkIRect(rect), SkRegion::kIntersect_Op); |
| 92 } | 92 } |
| 93 | 93 |
| 94 void Region::Intersect(const Region& region) { | 94 void Region::Intersect(const Region& region) { |
| 95 skregion_.op(region.skregion_, SkRegion::kIntersect_Op); | 95 skregion_.op(region.skregion_, SkRegion::kIntersect_Op); |
| 96 } | 96 } |
| 97 | 97 |
| 98 std::string Region::ToString() const { | 98 std::string Region::ToString() const { |
| 99 if (IsEmpty()) | 99 if (IsEmpty()) |
| 100 return gfx::Rect().ToString(); | 100 return gfx::Rect().ToString(); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 124 } | 124 } |
| 125 | 125 |
| 126 Region::Iterator::Iterator(const Region& region) | 126 Region::Iterator::Iterator(const Region& region) |
| 127 : it_(region.skregion_) { | 127 : it_(region.skregion_) { |
| 128 } | 128 } |
| 129 | 129 |
| 130 Region::Iterator::~Iterator() { | 130 Region::Iterator::~Iterator() { |
| 131 } | 131 } |
| 132 | 132 |
| 133 } // namespace cc | 133 } // namespace cc |
| OLD | NEW |