| OLD | NEW |
| (Empty) | |
| 1 /* |
| 2 * Copyright (C) 2007 The Android Open Source Project |
| 3 * |
| 4 * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 * you may not use this file except in compliance with the License. |
| 6 * You may obtain a copy of the License at |
| 7 * |
| 8 * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 * |
| 10 * Unless required by applicable law or agreed to in writing, software |
| 11 * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 * See the License for the specific language governing permissions and |
| 14 * limitations under the License. |
| 15 */ |
| 16 |
| 17 #ifndef ANDROID_UI_REGION_H |
| 18 #define ANDROID_UI_REGION_H |
| 19 |
| 20 #include <vector> |
| 21 |
| 22 #include "base/basictypes.h" |
| 23 #include "cc/cc_export.h" |
| 24 #include "third_party/skia/include/core/SkRect.h" |
| 25 #include "ui/gfx/point.h" |
| 26 |
| 27 namespace android { |
| 28 // --------------------------------------------------------------------------- |
| 29 |
| 30 class String8; |
| 31 |
| 32 // --------------------------------------------------------------------------- |
| 33 class CC_EXPORT Region |
| 34 { |
| 35 public: |
| 36 Region(); |
| 37 Region(const Region& rhs); |
| 38 explicit Region(const SkIRect& rhs); |
| 39 #if 0 |
| 40 explicit Region(const void* buffer); |
| 41 #endif |
| 42 ~Region(); |
| 43 |
| 44 Region& operator = (const Region& rhs); |
| 45 |
| 46 inline bool isEmpty() const { return mBounds.isEmpty(); } |
| 47 inline bool isRect() const { return mStorage.empty(); } |
| 48 |
| 49 inline SkIRect getBounds() const { return mBounds; } |
| 50 inline SkIRect bounds() const { return getBounds(); } |
| 51 |
| 52 // the region becomes its bounds |
| 53 Region& makeBoundsSelf(); |
| 54 |
| 55 void clear(); |
| 56 void set(const SkIRect& r); |
| 57 void set(int w, int h); |
| 58 |
| 59 Region& orSelf(const SkIRect& rhs); |
| 60 Region& xorSelf(const SkIRect& rhs); |
| 61 Region& andSelf(const SkIRect& rhs); |
| 62 Region& subtractSelf(const SkIRect& rhs); |
| 63 |
| 64 // boolean operators, applied on this |
| 65 Region& orSelf(const Region& rhs); |
| 66 Region& xorSelf(const Region& rhs); |
| 67 Region& andSelf(const Region& rhs); |
| 68 Region& subtractSelf(const Region& rhs); |
| 69 |
| 70 // boolean operators |
| 71 const Region merge(const SkIRect& rhs) const; |
| 72 const Region mergeExclusive(const SkIRect& rhs) const; |
| 73 const Region intersect(const SkIRect& rhs) const; |
| 74 const Region subtract(const SkIRect& rhs) const; |
| 75 |
| 76 // boolean operators |
| 77 const Region merge(const Region& rhs) const; |
| 78 const Region mergeExclusive(const Region& rhs) const; |
| 79 const Region intersect(const Region& rhs) const; |
| 80 const Region subtract(const Region& rhs) const; |
| 81 |
| 82 // these translate rhs first |
| 83 Region& translateSelf(int dx, int dy); |
| 84 Region& orSelf(const Region& rhs, int dx, int dy); |
| 85 Region& xorSelf(const Region& rhs, int dx, int dy); |
| 86 Region& andSelf(const Region& rhs, int dx, int dy); |
| 87 Region& subtractSelf(const Region& rhs, int dx, int dy); |
| 88 |
| 89 // these translate rhs first |
| 90 const Region translate(int dx, int dy) const; |
| 91 const Region merge(const Region& rhs, int dx, int dy) const; |
| 92 const Region mergeExclusive(const Region& rhs, int dx, int dy) const; |
| 93 const Region intersect(const Region& rhs, int dx, int dy) const; |
| 94 const Region subtract(const Region& rhs, int dx, int dy) const; |
| 95 |
| 96 // convenience operators overloads |
| 97 inline const Region operator | (const Region& rhs) const; |
| 98 inline const Region operator ^ (const Region& rhs) const; |
| 99 inline const Region operator & (const Region& rhs) const; |
| 100 inline const Region operator - (const Region& rhs) const; |
| 101 inline const Region operator + (const gfx::Point& pt) const; |
| 102 |
| 103 inline Region& operator |= (const Region& rhs); |
| 104 inline Region& operator ^= (const Region& rhs); |
| 105 inline Region& operator &= (const Region& rhs); |
| 106 inline Region& operator -= (const Region& rhs); |
| 107 inline Region& operator += (const gfx::Point& pt); |
| 108 |
| 109 |
| 110 /* various ways to access the rectangle list */ |
| 111 |
| 112 typedef SkIRect const* const_iterator; |
| 113 |
| 114 const_iterator begin() const; |
| 115 const_iterator end() const; |
| 116 |
| 117 /* no user serviceable parts here... */ |
| 118 |
| 119 size_t getRects(std::vector<SkIRect>& rectList) const; |
| 120 SkIRect const* getArray(size_t* count) const; |
| 121 |
| 122 |
| 123 // add a rectangle to the internal list. This rectangle must |
| 124 // be sorted in Y and X and must not make the region invalid. |
| 125 void addRectUnchecked(int l, int t, int r, int b); |
| 126 |
| 127 #if 0 |
| 128 // flatten/unflatten a region to/from a raw buffer |
| 129 ssize_t write(void* buffer, size_t size) const; |
| 130 static ssize_t writeEmpty(void* buffer, size_t size); |
| 131 |
| 132 ssize_t read(const void* buffer); |
| 133 static bool isEmpty(void* buffer); |
| 134 |
| 135 void dump(String8& out, const char* what, uint32_t flags=0) const; |
| 136 void dump(const char* what, uint32_t flags=0) const; |
| 137 #endif |
| 138 |
| 139 private: |
| 140 class rasterizer; |
| 141 friend class rasterizer; |
| 142 |
| 143 Region& operationSelf(const SkIRect& r, int op); |
| 144 Region& operationSelf(const Region& r, int op); |
| 145 Region& operationSelf(const Region& r, int dx, int dy, int op); |
| 146 const Region operation(const SkIRect& rhs, int op) const; |
| 147 const Region operation(const Region& rhs, int op) const; |
| 148 const Region operation(const Region& rhs, int dx, int dy, int op) const; |
| 149 |
| 150 static void boolean_operation(int op, Region& dst, |
| 151 const Region& lhs, const Region& rhs, int dx, int dy); |
| 152 static void boolean_operation(int op, Region& dst, |
| 153 const Region& lhs, const SkIRect& rhs, int dx, int dy); |
| 154 |
| 155 static void boolean_operation(int op, Region& dst, |
| 156 const Region& lhs, const Region& rhs); |
| 157 static void boolean_operation(int op, Region& dst, |
| 158 const Region& lhs, const SkIRect& rhs); |
| 159 |
| 160 static void translate(Region& reg, int dx, int dy); |
| 161 static void translate(Region& dst, const Region& reg, int dx, int dy); |
| 162 |
| 163 static bool validate(const Region& reg, const char* name); |
| 164 |
| 165 SkIRect mBounds; |
| 166 std::vector<SkIRect> mStorage; |
| 167 }; |
| 168 |
| 169 |
| 170 const Region Region::operator | (const Region& rhs) const { |
| 171 return merge(rhs); |
| 172 } |
| 173 const Region Region::operator ^ (const Region& rhs) const { |
| 174 return mergeExclusive(rhs); |
| 175 } |
| 176 const Region Region::operator & (const Region& rhs) const { |
| 177 return intersect(rhs); |
| 178 } |
| 179 const Region Region::operator - (const Region& rhs) const { |
| 180 return subtract(rhs); |
| 181 } |
| 182 const Region Region::operator + (const gfx::Point& pt) const { |
| 183 return translate(pt.x(), pt.y()); |
| 184 } |
| 185 |
| 186 |
| 187 Region& Region::operator |= (const Region& rhs) { |
| 188 return orSelf(rhs); |
| 189 } |
| 190 Region& Region::operator ^= (const Region& rhs) { |
| 191 return xorSelf(rhs); |
| 192 } |
| 193 Region& Region::operator &= (const Region& rhs) { |
| 194 return andSelf(rhs); |
| 195 } |
| 196 Region& Region::operator -= (const Region& rhs) { |
| 197 return subtractSelf(rhs); |
| 198 } |
| 199 Region& Region::operator += (const gfx::Point& pt) { |
| 200 return translateSelf(pt.x(), pt.y()); |
| 201 } |
| 202 // --------------------------------------------------------------------------- |
| 203 }; // namespace android |
| 204 |
| 205 #endif // ANDROID_UI_REGION_H |
| OLD | NEW |