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 "config.h" |
| 6 |
| 7 #include "cc/region.h" |
| 8 |
| 9 namespace cc { |
| 10 |
| 11 // TODO(danakj) Use method from ui/gfx/skia_utils.h when it exists. |
| 12 static inline SkIRect ToSkIRect(gfx::Rect rect) |
| 13 { |
| 14 return SkIRect::MakeXYWH(rect.x(), rect.y(), rect.width(), rect.height()); |
| 15 } |
| 16 |
| 17 Region::Region() { |
| 18 } |
| 19 |
| 20 Region::Region(const Region& region) |
| 21 : skregion_(region.skregion_) { |
| 22 } |
| 23 |
| 24 Region::Region(gfx::Rect rect) |
| 25 : skregion_(ToSkIRect(rect)) { |
| 26 } |
| 27 |
| 28 Region::~Region() { |
| 29 } |
| 30 |
| 31 const Region& Region::operator=(gfx::Rect rect) { |
| 32 skregion_ = SkRegion(ToSkIRect(rect)); |
| 33 return *this; |
| 34 } |
| 35 |
| 36 const Region& Region::operator=(const Region& region) { |
| 37 skregion_ = region.skregion_; |
| 38 return *this; |
| 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 return skregion_.contains(ToSkIRect(rect)); |
| 51 } |
| 52 |
| 53 bool Region::Contains(const Region& region) const { |
| 54 return skregion_.contains(region.skregion_); |
| 55 } |
| 56 |
| 57 bool Region::Intersects(gfx::Rect rect) const { |
| 58 return skregion_.intersects(ToSkIRect(rect)); |
| 59 } |
| 60 |
| 61 bool Region::Intersects(const Region& region) const { |
| 62 return skregion_.intersects(region.skregion_); |
| 63 } |
| 64 |
| 65 void Region::Subtract(gfx::Rect rect) { |
| 66 skregion_.op(ToSkIRect(rect), SkRegion::kDifference_Op); |
| 67 } |
| 68 |
| 69 void Region::Subtract(const Region& region) { |
| 70 skregion_.op(region.skregion_, SkRegion::kDifference_Op); |
| 71 } |
| 72 |
| 73 void Region::Union(gfx::Rect rect) { |
| 74 skregion_.op(ToSkIRect(rect), SkRegion::kUnion_Op); |
| 75 } |
| 76 |
| 77 void Region::Union(const Region& region) { |
| 78 skregion_.op(region.skregion_, SkRegion::kUnion_Op); |
| 79 } |
| 80 |
| 81 void Region::Intersect(gfx::Rect rect) { |
| 82 skregion_.op(ToSkIRect(rect), SkRegion::kIntersect_Op); |
| 83 } |
| 84 |
| 85 void Region::Intersect(const Region& region) { |
| 86 skregion_.op(region.skregion_, SkRegion::kIntersect_Op); |
| 87 } |
| 88 |
| 89 std::string Region::ToString() const { |
| 90 if (IsEmpty()) |
| 91 return gfx::Rect().ToString(); |
| 92 |
| 93 std::string result; |
| 94 for (Iterator it(*this); it.has_rect(); it.next()) { |
| 95 if (!result.empty()) |
| 96 result += " | "; |
| 97 result += it.rect().ToString(); |
| 98 } |
| 99 return result; |
| 100 } |
| 101 |
| 102 Region::Iterator::Iterator(const Region& region) |
| 103 : it_(region.skregion_) { |
| 104 } |
| 105 |
| 106 Region::Iterator::~Iterator() { |
| 107 } |
| 108 |
| 109 } // namespace cc |
OLD | NEW |