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