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(const 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 void Region::operator=(const Region& region) { |
| 32 skregion_ = region.skregion_; |
| 33 } |
| 34 |
| 35 bool Region::IsEmpty() const { |
| 36 return skregion_.isEmpty(); |
| 37 } |
| 38 |
| 39 bool Region::Contains(const gfx::Point& point) const { |
| 40 return skregion_.contains(point.x(), point.y()); |
| 41 } |
| 42 |
| 43 bool Region::Contains(const gfx::Rect& rect) const { |
| 44 return skregion_.contains(ToSkIRect(rect)); |
| 45 } |
| 46 |
| 47 void Region::Subtract(const gfx::Rect& rect) { |
| 48 skregion_.op(ToSkIRect(rect), SkRegion::kDifference_Op); |
| 49 } |
| 50 |
| 51 void Region::Subtract(const Region& region) { |
| 52 skregion_.op(region.skregion_, SkRegion::kDifference_Op); |
| 53 } |
| 54 |
| 55 void Region::Union(const gfx::Rect& rect) { |
| 56 skregion_.op(ToSkIRect(rect), SkRegion::kUnion_Op); |
| 57 } |
| 58 |
| 59 void Region::Union(const Region& region) { |
| 60 skregion_.op(region.skregion_, SkRegion::kUnion_Op); |
| 61 } |
| 62 |
| 63 void Region::Intersect(const gfx::Rect& rect) { |
| 64 skregion_.op(ToSkIRect(rect), SkRegion::kIntersect_Op); |
| 65 } |
| 66 |
| 67 void Region::Intersect(const Region& region) { |
| 68 skregion_.op(region.skregion_, SkRegion::kIntersect_Op); |
| 69 } |
| 70 |
| 71 std::string Region::ToString() const { |
| 72 if (IsEmpty()) |
| 73 return gfx::Rect().ToString(); |
| 74 |
| 75 std::string result; |
| 76 for (Iterator it(*this); it.has_rect(); it.next()) { |
| 77 if (!result.empty()) |
| 78 result += " | "; |
| 79 result += it.rect().ToString(); |
| 80 } |
| 81 return result; |
| 82 } |
| 83 |
| 84 Region::Iterator::Iterator(const Region& region) |
| 85 : it_(region.skregion_) { |
| 86 } |
| 87 |
| 88 Region::Iterator::~Iterator() { |
| 89 } |
| 90 |
| 91 } // namespace cc |
OLD | NEW |