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 #ifndef CC_REGION_H_ |
| 6 #define CC_REGION_H_ |
| 7 |
| 8 #include <string> |
| 9 |
| 10 #include "base/logging.h" |
| 11 #include "cc/cc_export.h" |
| 12 #include "third_party/skia/include/core/SkRegion.h" |
| 13 #include "ui/gfx/rect.h" |
| 14 |
| 15 namespace cc { |
| 16 |
| 17 class CC_EXPORT Region { |
| 18 public: |
| 19 Region(); |
| 20 Region(const Region& region); |
| 21 Region(gfx::Rect rect); |
| 22 ~Region(); |
| 23 |
| 24 const Region& operator=(gfx::Rect rect); |
| 25 const Region& operator=(const Region& region); |
| 26 |
| 27 bool IsEmpty() const; |
| 28 |
| 29 bool Contains(gfx::Point point) const; |
| 30 bool Contains(gfx::Rect rect) const; |
| 31 bool Contains(const Region& region) const; |
| 32 |
| 33 bool Intersects(gfx::Rect rect) const; |
| 34 bool Intersects(const Region& region) const; |
| 35 |
| 36 void Subtract(gfx::Rect rect); |
| 37 void Subtract(const Region& region); |
| 38 void Union(gfx::Rect rect); |
| 39 void Union(const Region& region); |
| 40 void Intersect(gfx::Rect rect); |
| 41 void Intersect(const Region& region); |
| 42 |
| 43 bool Equals(const Region& other) const { return skregion_ == other.skregion_;
} |
| 44 |
| 45 gfx::Rect bounds() const { |
| 46 SkIRect r = skregion_.getBounds(); |
| 47 // TODO(danakj) Use method from ui/gfx/skia_utils.h when it exists. |
| 48 return gfx::Rect(r.x(), r.y(), r.width(), r.height()); |
| 49 } |
| 50 |
| 51 std::string ToString() const; |
| 52 |
| 53 class CC_EXPORT Iterator { |
| 54 public: |
| 55 Iterator(const Region& region); |
| 56 ~Iterator(); |
| 57 |
| 58 gfx::Rect rect() const { |
| 59 SkIRect r = it_.rect(); |
| 60 // TODO(danakj) Use method from ui/gfx/skia_utils.h when it exists. |
| 61 return gfx::Rect(r.x(), r.y(), r.width(), r.height()); |
| 62 } |
| 63 |
| 64 void next() { |
| 65 it_.next(); |
| 66 } |
| 67 bool has_rect() const { |
| 68 return !it_.done(); |
| 69 } |
| 70 |
| 71 private: |
| 72 SkRegion::Iterator it_; |
| 73 }; |
| 74 |
| 75 private: |
| 76 SkRegion skregion_; |
| 77 }; |
| 78 |
| 79 inline bool operator==(const Region& a, const Region& b) { |
| 80 return a.Equals(b); |
| 81 } |
| 82 |
| 83 inline bool operator!=(const Region& a, const Region& b) { |
| 84 return !(a == b); |
| 85 } |
| 86 |
| 87 inline Region SubtractRegions(const Region& a, const Region& b) { |
| 88 Region result = a; |
| 89 result.Subtract(b); |
| 90 return result; |
| 91 } |
| 92 |
| 93 inline Region SubtractRegions(const Region& a, gfx::Rect b) { |
| 94 Region result = a; |
| 95 result.Subtract(b); |
| 96 return result; |
| 97 } |
| 98 |
| 99 inline Region IntersectRegions(const Region& a, const Region& b) { |
| 100 Region result = a; |
| 101 result.Intersect(b); |
| 102 return result; |
| 103 } |
| 104 |
| 105 inline Region IntersectRegions(const Region& a, gfx::Rect b) { |
| 106 Region result = a; |
| 107 result.Intersect(b); |
| 108 return result; |
| 109 } |
| 110 |
| 111 inline Region UnionRegions(const Region& a, const Region& b) { |
| 112 Region result = a; |
| 113 result.Union(b); |
| 114 return result; |
| 115 } |
| 116 |
| 117 inline Region UnionRegions(const Region& a, gfx::Rect b) { |
| 118 Region result = a; |
| 119 result.Union(b); |
| 120 return result; |
| 121 } |
| 122 |
| 123 } // namespace cc |
| 124 |
| 125 #endif // CC_REGION_H_ |
OLD | NEW |