The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 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 | #define LOG_TAG "Region" |
| 18 | |
Mathias Agopian | 72b0ffe | 2009-07-06 18:07:26 -0700 | [diff] [blame] | 19 | #include <limits.h> |
| 20 | |
Mathias Agopian | 20f6878 | 2009-05-11 00:03:41 -0700 | [diff] [blame] | 21 | #include <utils/Log.h> |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 22 | #include <utils/String8.h> |
Mathias Agopian | 068d47f | 2012-09-11 18:56:23 -0700 | [diff] [blame^] | 23 | #include <utils/CallStack.h> |
Mathias Agopian | 20f6878 | 2009-05-11 00:03:41 -0700 | [diff] [blame] | 24 | |
| 25 | #include <ui/Rect.h> |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 26 | #include <ui/Region.h> |
Mathias Agopian | 20f6878 | 2009-05-11 00:03:41 -0700 | [diff] [blame] | 27 | #include <ui/Point.h> |
| 28 | |
| 29 | #include <private/ui/RegionHelper.h> |
| 30 | |
| 31 | // ---------------------------------------------------------------------------- |
| 32 | #define VALIDATE_REGIONS (false) |
| 33 | #define VALIDATE_WITH_CORECG (false) |
| 34 | // ---------------------------------------------------------------------------- |
| 35 | |
| 36 | #if VALIDATE_WITH_CORECG |
| 37 | #include <core/SkRegion.h> |
| 38 | #endif |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 39 | |
| 40 | namespace android { |
Mathias Agopian | 20f6878 | 2009-05-11 00:03:41 -0700 | [diff] [blame] | 41 | // ---------------------------------------------------------------------------- |
| 42 | |
| 43 | enum { |
| 44 | op_nand = region_operator<Rect>::op_nand, |
| 45 | op_and = region_operator<Rect>::op_and, |
| 46 | op_or = region_operator<Rect>::op_or, |
| 47 | op_xor = region_operator<Rect>::op_xor |
| 48 | }; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 49 | |
| 50 | // ---------------------------------------------------------------------------- |
| 51 | |
Mathias Agopian | 3ab6855 | 2012-08-31 14:31:40 -0700 | [diff] [blame] | 52 | Region::Region() { |
| 53 | mStorage.add(Rect(0,0)); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | Region::Region(const Region& rhs) |
Mathias Agopian | 3ab6855 | 2012-08-31 14:31:40 -0700 | [diff] [blame] | 57 | : mStorage(rhs.mStorage) |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 58 | { |
Mathias Agopian | d0b55c0 | 2011-03-16 23:18:07 -0700 | [diff] [blame] | 59 | #if VALIDATE_REGIONS |
| 60 | validate(rhs, "rhs copy-ctor"); |
| 61 | #endif |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 62 | } |
| 63 | |
Mathias Agopian | 3ab6855 | 2012-08-31 14:31:40 -0700 | [diff] [blame] | 64 | Region::Region(const Rect& rhs) { |
| 65 | mStorage.add(rhs); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | Region::~Region() |
| 69 | { |
| 70 | } |
| 71 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 72 | Region& Region::operator = (const Region& rhs) |
| 73 | { |
Mathias Agopian | 20f6878 | 2009-05-11 00:03:41 -0700 | [diff] [blame] | 74 | #if VALIDATE_REGIONS |
Mathias Agopian | d0b55c0 | 2011-03-16 23:18:07 -0700 | [diff] [blame] | 75 | validate(*this, "this->operator="); |
| 76 | validate(rhs, "rhs.operator="); |
Mathias Agopian | 20f6878 | 2009-05-11 00:03:41 -0700 | [diff] [blame] | 77 | #endif |
Mathias Agopian | 20f6878 | 2009-05-11 00:03:41 -0700 | [diff] [blame] | 78 | mStorage = rhs.mStorage; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 79 | return *this; |
| 80 | } |
| 81 | |
Mathias Agopian | 9f96145 | 2009-06-29 18:46:37 -0700 | [diff] [blame] | 82 | Region& Region::makeBoundsSelf() |
| 83 | { |
Mathias Agopian | 3ab6855 | 2012-08-31 14:31:40 -0700 | [diff] [blame] | 84 | if (mStorage.size() >= 2) { |
| 85 | const Rect bounds(getBounds()); |
| 86 | mStorage.clear(); |
| 87 | mStorage.add(bounds); |
| 88 | } |
Mathias Agopian | 9f96145 | 2009-06-29 18:46:37 -0700 | [diff] [blame] | 89 | return *this; |
| 90 | } |
| 91 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 92 | void Region::clear() |
| 93 | { |
Mathias Agopian | 20f6878 | 2009-05-11 00:03:41 -0700 | [diff] [blame] | 94 | mStorage.clear(); |
Mathias Agopian | 3ab6855 | 2012-08-31 14:31:40 -0700 | [diff] [blame] | 95 | mStorage.add(Rect(0,0)); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 96 | } |
| 97 | |
| 98 | void Region::set(const Rect& r) |
| 99 | { |
Mathias Agopian | 20f6878 | 2009-05-11 00:03:41 -0700 | [diff] [blame] | 100 | mStorage.clear(); |
Mathias Agopian | 3ab6855 | 2012-08-31 14:31:40 -0700 | [diff] [blame] | 101 | mStorage.add(r); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 102 | } |
| 103 | |
Mathias Agopian | 0926f50 | 2009-05-04 14:17:04 -0700 | [diff] [blame] | 104 | void Region::set(uint32_t w, uint32_t h) |
| 105 | { |
Mathias Agopian | 20f6878 | 2009-05-11 00:03:41 -0700 | [diff] [blame] | 106 | mStorage.clear(); |
Mathias Agopian | 3ab6855 | 2012-08-31 14:31:40 -0700 | [diff] [blame] | 107 | mStorage.add(Rect(w,h)); |
Mathias Agopian | 0926f50 | 2009-05-04 14:17:04 -0700 | [diff] [blame] | 108 | } |
| 109 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 110 | // ---------------------------------------------------------------------------- |
| 111 | |
Mathias Agopian | 20f6878 | 2009-05-11 00:03:41 -0700 | [diff] [blame] | 112 | void Region::addRectUnchecked(int l, int t, int r, int b) |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 113 | { |
Mathias Agopian | 3ab6855 | 2012-08-31 14:31:40 -0700 | [diff] [blame] | 114 | Rect rect(l,t,r,b); |
| 115 | size_t where = mStorage.size() - 1; |
| 116 | mStorage.insertAt(rect, where, 1); |
| 117 | |
Mathias Agopian | 20f6878 | 2009-05-11 00:03:41 -0700 | [diff] [blame] | 118 | #if VALIDATE_REGIONS |
| 119 | validate(*this, "addRectUnchecked"); |
| 120 | #endif |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 121 | } |
| 122 | |
Mathias Agopian | 20f6878 | 2009-05-11 00:03:41 -0700 | [diff] [blame] | 123 | // ---------------------------------------------------------------------------- |
| 124 | |
| 125 | Region& Region::orSelf(const Rect& r) { |
| 126 | return operationSelf(r, op_or); |
| 127 | } |
Romain Guy | b8a2e98 | 2012-02-07 17:04:34 -0800 | [diff] [blame] | 128 | Region& Region::xorSelf(const Rect& r) { |
| 129 | return operationSelf(r, op_xor); |
| 130 | } |
Mathias Agopian | 20f6878 | 2009-05-11 00:03:41 -0700 | [diff] [blame] | 131 | Region& Region::andSelf(const Rect& r) { |
| 132 | return operationSelf(r, op_and); |
| 133 | } |
| 134 | Region& Region::subtractSelf(const Rect& r) { |
| 135 | return operationSelf(r, op_nand); |
| 136 | } |
| 137 | Region& Region::operationSelf(const Rect& r, int op) { |
| 138 | Region lhs(*this); |
| 139 | boolean_operation(op, *this, lhs, r); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 140 | return *this; |
| 141 | } |
| 142 | |
| 143 | // ---------------------------------------------------------------------------- |
| 144 | |
| 145 | Region& Region::orSelf(const Region& rhs) { |
Mathias Agopian | 20f6878 | 2009-05-11 00:03:41 -0700 | [diff] [blame] | 146 | return operationSelf(rhs, op_or); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 147 | } |
Romain Guy | b8a2e98 | 2012-02-07 17:04:34 -0800 | [diff] [blame] | 148 | Region& Region::xorSelf(const Region& rhs) { |
| 149 | return operationSelf(rhs, op_xor); |
| 150 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 151 | Region& Region::andSelf(const Region& rhs) { |
Mathias Agopian | 20f6878 | 2009-05-11 00:03:41 -0700 | [diff] [blame] | 152 | return operationSelf(rhs, op_and); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 153 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 154 | Region& Region::subtractSelf(const Region& rhs) { |
Mathias Agopian | 20f6878 | 2009-05-11 00:03:41 -0700 | [diff] [blame] | 155 | return operationSelf(rhs, op_nand); |
| 156 | } |
| 157 | Region& Region::operationSelf(const Region& rhs, int op) { |
| 158 | Region lhs(*this); |
| 159 | boolean_operation(op, *this, lhs, rhs); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 160 | return *this; |
| 161 | } |
| 162 | |
| 163 | Region& Region::translateSelf(int x, int y) { |
Mathias Agopian | 20f6878 | 2009-05-11 00:03:41 -0700 | [diff] [blame] | 164 | if (x|y) translate(*this, x, y); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 165 | return *this; |
| 166 | } |
| 167 | |
Mathias Agopian | 20f6878 | 2009-05-11 00:03:41 -0700 | [diff] [blame] | 168 | // ---------------------------------------------------------------------------- |
| 169 | |
Mathias Agopian | bed9dd1 | 2009-05-27 17:01:58 -0700 | [diff] [blame] | 170 | const Region Region::merge(const Rect& rhs) const { |
Mathias Agopian | 20f6878 | 2009-05-11 00:03:41 -0700 | [diff] [blame] | 171 | return operation(rhs, op_or); |
| 172 | } |
Romain Guy | b8a2e98 | 2012-02-07 17:04:34 -0800 | [diff] [blame] | 173 | const Region Region::mergeExclusive(const Rect& rhs) const { |
| 174 | return operation(rhs, op_xor); |
| 175 | } |
Mathias Agopian | bed9dd1 | 2009-05-27 17:01:58 -0700 | [diff] [blame] | 176 | const Region Region::intersect(const Rect& rhs) const { |
Mathias Agopian | 20f6878 | 2009-05-11 00:03:41 -0700 | [diff] [blame] | 177 | return operation(rhs, op_and); |
| 178 | } |
Mathias Agopian | bed9dd1 | 2009-05-27 17:01:58 -0700 | [diff] [blame] | 179 | const Region Region::subtract(const Rect& rhs) const { |
Mathias Agopian | 20f6878 | 2009-05-11 00:03:41 -0700 | [diff] [blame] | 180 | return operation(rhs, op_nand); |
| 181 | } |
Mathias Agopian | bed9dd1 | 2009-05-27 17:01:58 -0700 | [diff] [blame] | 182 | const Region Region::operation(const Rect& rhs, int op) const { |
Mathias Agopian | 20f6878 | 2009-05-11 00:03:41 -0700 | [diff] [blame] | 183 | Region result; |
| 184 | boolean_operation(op, result, *this, rhs); |
| 185 | return result; |
| 186 | } |
| 187 | |
| 188 | // ---------------------------------------------------------------------------- |
| 189 | |
Mathias Agopian | bed9dd1 | 2009-05-27 17:01:58 -0700 | [diff] [blame] | 190 | const Region Region::merge(const Region& rhs) const { |
Mathias Agopian | 20f6878 | 2009-05-11 00:03:41 -0700 | [diff] [blame] | 191 | return operation(rhs, op_or); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 192 | } |
Romain Guy | b8a2e98 | 2012-02-07 17:04:34 -0800 | [diff] [blame] | 193 | const Region Region::mergeExclusive(const Region& rhs) const { |
| 194 | return operation(rhs, op_xor); |
| 195 | } |
Mathias Agopian | bed9dd1 | 2009-05-27 17:01:58 -0700 | [diff] [blame] | 196 | const Region Region::intersect(const Region& rhs) const { |
Mathias Agopian | 20f6878 | 2009-05-11 00:03:41 -0700 | [diff] [blame] | 197 | return operation(rhs, op_and); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 198 | } |
Mathias Agopian | bed9dd1 | 2009-05-27 17:01:58 -0700 | [diff] [blame] | 199 | const Region Region::subtract(const Region& rhs) const { |
Mathias Agopian | 20f6878 | 2009-05-11 00:03:41 -0700 | [diff] [blame] | 200 | return operation(rhs, op_nand); |
| 201 | } |
Mathias Agopian | bed9dd1 | 2009-05-27 17:01:58 -0700 | [diff] [blame] | 202 | const Region Region::operation(const Region& rhs, int op) const { |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 203 | Region result; |
Mathias Agopian | 20f6878 | 2009-05-11 00:03:41 -0700 | [diff] [blame] | 204 | boolean_operation(op, result, *this, rhs); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 205 | return result; |
| 206 | } |
| 207 | |
Mathias Agopian | bed9dd1 | 2009-05-27 17:01:58 -0700 | [diff] [blame] | 208 | const Region Region::translate(int x, int y) const { |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 209 | Region result; |
Mathias Agopian | 20f6878 | 2009-05-11 00:03:41 -0700 | [diff] [blame] | 210 | translate(result, *this, x, y); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 211 | return result; |
| 212 | } |
| 213 | |
| 214 | // ---------------------------------------------------------------------------- |
| 215 | |
| 216 | Region& Region::orSelf(const Region& rhs, int dx, int dy) { |
Mathias Agopian | 20f6878 | 2009-05-11 00:03:41 -0700 | [diff] [blame] | 217 | return operationSelf(rhs, dx, dy, op_or); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 218 | } |
Romain Guy | b8a2e98 | 2012-02-07 17:04:34 -0800 | [diff] [blame] | 219 | Region& Region::xorSelf(const Region& rhs, int dx, int dy) { |
| 220 | return operationSelf(rhs, dx, dy, op_xor); |
| 221 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 222 | Region& Region::andSelf(const Region& rhs, int dx, int dy) { |
Mathias Agopian | 20f6878 | 2009-05-11 00:03:41 -0700 | [diff] [blame] | 223 | return operationSelf(rhs, dx, dy, op_and); |
| 224 | } |
| 225 | Region& Region::subtractSelf(const Region& rhs, int dx, int dy) { |
| 226 | return operationSelf(rhs, dx, dy, op_nand); |
| 227 | } |
| 228 | Region& Region::operationSelf(const Region& rhs, int dx, int dy, int op) { |
| 229 | Region lhs(*this); |
| 230 | boolean_operation(op, *this, lhs, rhs, dx, dy); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 231 | return *this; |
| 232 | } |
| 233 | |
Mathias Agopian | 20f6878 | 2009-05-11 00:03:41 -0700 | [diff] [blame] | 234 | // ---------------------------------------------------------------------------- |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 235 | |
Mathias Agopian | bed9dd1 | 2009-05-27 17:01:58 -0700 | [diff] [blame] | 236 | const Region Region::merge(const Region& rhs, int dx, int dy) const { |
Mathias Agopian | 20f6878 | 2009-05-11 00:03:41 -0700 | [diff] [blame] | 237 | return operation(rhs, dx, dy, op_or); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 238 | } |
Romain Guy | b8a2e98 | 2012-02-07 17:04:34 -0800 | [diff] [blame] | 239 | const Region Region::mergeExclusive(const Region& rhs, int dx, int dy) const { |
| 240 | return operation(rhs, dx, dy, op_xor); |
| 241 | } |
Mathias Agopian | bed9dd1 | 2009-05-27 17:01:58 -0700 | [diff] [blame] | 242 | const Region Region::intersect(const Region& rhs, int dx, int dy) const { |
Mathias Agopian | 20f6878 | 2009-05-11 00:03:41 -0700 | [diff] [blame] | 243 | return operation(rhs, dx, dy, op_and); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 244 | } |
Mathias Agopian | bed9dd1 | 2009-05-27 17:01:58 -0700 | [diff] [blame] | 245 | const Region Region::subtract(const Region& rhs, int dx, int dy) const { |
Mathias Agopian | 20f6878 | 2009-05-11 00:03:41 -0700 | [diff] [blame] | 246 | return operation(rhs, dx, dy, op_nand); |
| 247 | } |
Mathias Agopian | bed9dd1 | 2009-05-27 17:01:58 -0700 | [diff] [blame] | 248 | const Region Region::operation(const Region& rhs, int dx, int dy, int op) const { |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 249 | Region result; |
Mathias Agopian | 20f6878 | 2009-05-11 00:03:41 -0700 | [diff] [blame] | 250 | boolean_operation(op, result, *this, rhs, dx, dy); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 251 | return result; |
| 252 | } |
| 253 | |
| 254 | // ---------------------------------------------------------------------------- |
| 255 | |
Mathias Agopian | 20f6878 | 2009-05-11 00:03:41 -0700 | [diff] [blame] | 256 | // This is our region rasterizer, which merges rects and spans together |
| 257 | // to obtain an optimal region. |
| 258 | class Region::rasterizer : public region_operator<Rect>::region_rasterizer |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 259 | { |
Mathias Agopian | 3ab6855 | 2012-08-31 14:31:40 -0700 | [diff] [blame] | 260 | Rect bounds; |
Mathias Agopian | 20f6878 | 2009-05-11 00:03:41 -0700 | [diff] [blame] | 261 | Vector<Rect>& storage; |
| 262 | Rect* head; |
| 263 | Rect* tail; |
| 264 | Vector<Rect> span; |
| 265 | Rect* cur; |
| 266 | public: |
| 267 | rasterizer(Region& reg) |
Mathias Agopian | 3ab6855 | 2012-08-31 14:31:40 -0700 | [diff] [blame] | 268 | : bounds(INT_MAX, 0, INT_MIN, 0), storage(reg.mStorage), head(), tail(), cur() { |
Mathias Agopian | 20f6878 | 2009-05-11 00:03:41 -0700 | [diff] [blame] | 269 | storage.clear(); |
| 270 | } |
| 271 | |
| 272 | ~rasterizer() { |
| 273 | if (span.size()) { |
| 274 | flushSpan(); |
| 275 | } |
| 276 | if (storage.size()) { |
| 277 | bounds.top = storage.itemAt(0).top; |
| 278 | bounds.bottom = storage.top().bottom; |
| 279 | if (storage.size() == 1) { |
| 280 | storage.clear(); |
| 281 | } |
| 282 | } else { |
| 283 | bounds.left = 0; |
| 284 | bounds.right = 0; |
| 285 | } |
Mathias Agopian | 3ab6855 | 2012-08-31 14:31:40 -0700 | [diff] [blame] | 286 | storage.add(bounds); |
Mathias Agopian | 20f6878 | 2009-05-11 00:03:41 -0700 | [diff] [blame] | 287 | } |
| 288 | |
| 289 | virtual void operator()(const Rect& rect) { |
Steve Block | 9d45368 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 290 | //ALOGD(">>> %3d, %3d, %3d, %3d", |
Mathias Agopian | 20f6878 | 2009-05-11 00:03:41 -0700 | [diff] [blame] | 291 | // rect.left, rect.top, rect.right, rect.bottom); |
| 292 | if (span.size()) { |
| 293 | if (cur->top != rect.top) { |
| 294 | flushSpan(); |
| 295 | } else if (cur->right == rect.left) { |
| 296 | cur->right = rect.right; |
| 297 | return; |
| 298 | } |
| 299 | } |
| 300 | span.add(rect); |
| 301 | cur = span.editArray() + (span.size() - 1); |
| 302 | } |
| 303 | private: |
| 304 | template<typename T> |
| 305 | static inline T min(T rhs, T lhs) { return rhs < lhs ? rhs : lhs; } |
| 306 | template<typename T> |
| 307 | static inline T max(T rhs, T lhs) { return rhs > lhs ? rhs : lhs; } |
| 308 | void flushSpan() { |
| 309 | bool merge = false; |
| 310 | if (tail-head == ssize_t(span.size())) { |
Romain Guy | b801624 | 2010-10-27 18:57:51 -0700 | [diff] [blame] | 311 | Rect const* p = span.editArray(); |
Mathias Agopian | 20f6878 | 2009-05-11 00:03:41 -0700 | [diff] [blame] | 312 | Rect const* q = head; |
| 313 | if (p->top == q->bottom) { |
| 314 | merge = true; |
| 315 | while (q != tail) { |
| 316 | if ((p->left != q->left) || (p->right != q->right)) { |
| 317 | merge = false; |
| 318 | break; |
| 319 | } |
| 320 | p++, q++; |
| 321 | } |
| 322 | } |
| 323 | } |
| 324 | if (merge) { |
| 325 | const int bottom = span[0].bottom; |
| 326 | Rect* r = head; |
| 327 | while (r != tail) { |
| 328 | r->bottom = bottom; |
| 329 | r++; |
| 330 | } |
| 331 | } else { |
| 332 | bounds.left = min(span.itemAt(0).left, bounds.left); |
| 333 | bounds.right = max(span.top().right, bounds.right); |
| 334 | storage.appendVector(span); |
| 335 | tail = storage.editArray() + storage.size(); |
| 336 | head = tail - span.size(); |
| 337 | } |
| 338 | span.clear(); |
| 339 | } |
| 340 | }; |
| 341 | |
Mathias Agopian | 068d47f | 2012-09-11 18:56:23 -0700 | [diff] [blame^] | 342 | bool Region::validate(const Region& reg, const char* name, bool silent) |
Mathias Agopian | 20f6878 | 2009-05-11 00:03:41 -0700 | [diff] [blame] | 343 | { |
| 344 | bool result = true; |
| 345 | const_iterator cur = reg.begin(); |
| 346 | const_iterator const tail = reg.end(); |
Mathias Agopian | 068d47f | 2012-09-11 18:56:23 -0700 | [diff] [blame^] | 347 | const_iterator prev = cur; |
Mathias Agopian | 20f6878 | 2009-05-11 00:03:41 -0700 | [diff] [blame] | 348 | Rect b(*prev); |
| 349 | while (cur != tail) { |
Mathias Agopian | 068d47f | 2012-09-11 18:56:23 -0700 | [diff] [blame^] | 350 | if (cur->isValid() == false) { |
| 351 | ALOGE_IF(!silent, "%s: region contains an invalid Rect", name); |
| 352 | result = false; |
| 353 | } |
| 354 | if (cur->right > region_operator<Rect>::max_value) { |
| 355 | ALOGE_IF(!silent, "%s: rect->right > max_value", name); |
| 356 | result = false; |
| 357 | } |
| 358 | if (cur->bottom > region_operator<Rect>::max_value) { |
| 359 | ALOGE_IF(!silent, "%s: rect->right > max_value", name); |
| 360 | result = false; |
| 361 | } |
| 362 | if (prev != cur) { |
| 363 | b.left = b.left < cur->left ? b.left : cur->left; |
| 364 | b.top = b.top < cur->top ? b.top : cur->top; |
| 365 | b.right = b.right > cur->right ? b.right : cur->right; |
| 366 | b.bottom = b.bottom > cur->bottom ? b.bottom : cur->bottom; |
| 367 | if ((*prev < *cur) == false) { |
| 368 | ALOGE_IF(!silent, "%s: region's Rects not sorted", name); |
Mathias Agopian | 20f6878 | 2009-05-11 00:03:41 -0700 | [diff] [blame] | 369 | result = false; |
Mathias Agopian | 068d47f | 2012-09-11 18:56:23 -0700 | [diff] [blame^] | 370 | } |
| 371 | if (cur->top == prev->top) { |
| 372 | if (cur->bottom != prev->bottom) { |
| 373 | ALOGE_IF(!silent, "%s: invalid span %p", name, cur); |
| 374 | result = false; |
| 375 | } else if (cur->left < prev->right) { |
| 376 | ALOGE_IF(!silent, |
| 377 | "%s: spans overlap horizontally prev=%p, cur=%p", |
| 378 | name, prev, cur); |
| 379 | result = false; |
| 380 | } |
| 381 | } else if (cur->top < prev->bottom) { |
| 382 | ALOGE_IF(!silent, |
| 383 | "%s: spans overlap vertically prev=%p, cur=%p", |
Mathias Agopian | 20f6878 | 2009-05-11 00:03:41 -0700 | [diff] [blame] | 384 | name, prev, cur); |
| 385 | result = false; |
| 386 | } |
Mathias Agopian | 068d47f | 2012-09-11 18:56:23 -0700 | [diff] [blame^] | 387 | prev = cur; |
Mathias Agopian | 20f6878 | 2009-05-11 00:03:41 -0700 | [diff] [blame] | 388 | } |
Mathias Agopian | 20f6878 | 2009-05-11 00:03:41 -0700 | [diff] [blame] | 389 | cur++; |
| 390 | } |
| 391 | if (b != reg.getBounds()) { |
| 392 | result = false; |
Mathias Agopian | 068d47f | 2012-09-11 18:56:23 -0700 | [diff] [blame^] | 393 | ALOGE_IF(!silent, |
| 394 | "%s: invalid bounds [%d,%d,%d,%d] vs. [%d,%d,%d,%d]", name, |
Mathias Agopian | 20f6878 | 2009-05-11 00:03:41 -0700 | [diff] [blame] | 395 | b.left, b.top, b.right, b.bottom, |
| 396 | reg.getBounds().left, reg.getBounds().top, |
| 397 | reg.getBounds().right, reg.getBounds().bottom); |
| 398 | } |
Mathias Agopian | 3ab6855 | 2012-08-31 14:31:40 -0700 | [diff] [blame] | 399 | if (reg.mStorage.size() == 2) { |
Mathias Agopian | 068d47f | 2012-09-11 18:56:23 -0700 | [diff] [blame^] | 400 | result = false; |
| 401 | ALOGE_IF(!silent, "%s: mStorage size is 2, which is never valid", name); |
Mathias Agopian | 3ab6855 | 2012-08-31 14:31:40 -0700 | [diff] [blame] | 402 | } |
Mathias Agopian | 068d47f | 2012-09-11 18:56:23 -0700 | [diff] [blame^] | 403 | if (result == false && !silent) { |
Mathias Agopian | 20f6878 | 2009-05-11 00:03:41 -0700 | [diff] [blame] | 404 | reg.dump(name); |
Mathias Agopian | 068d47f | 2012-09-11 18:56:23 -0700 | [diff] [blame^] | 405 | CallStack stack; |
| 406 | stack.update(); |
| 407 | stack.dump(""); |
Mathias Agopian | 20f6878 | 2009-05-11 00:03:41 -0700 | [diff] [blame] | 408 | } |
| 409 | return result; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 410 | } |
| 411 | |
Mathias Agopian | 20f6878 | 2009-05-11 00:03:41 -0700 | [diff] [blame] | 412 | void Region::boolean_operation(int op, Region& dst, |
| 413 | const Region& lhs, |
| 414 | const Region& rhs, int dx, int dy) |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 415 | { |
Mathias Agopian | d0b55c0 | 2011-03-16 23:18:07 -0700 | [diff] [blame] | 416 | #if VALIDATE_REGIONS |
| 417 | validate(lhs, "boolean_operation (before): lhs"); |
| 418 | validate(rhs, "boolean_operation (before): rhs"); |
| 419 | validate(dst, "boolean_operation (before): dst"); |
| 420 | #endif |
| 421 | |
Mathias Agopian | 20f6878 | 2009-05-11 00:03:41 -0700 | [diff] [blame] | 422 | size_t lhs_count; |
| 423 | Rect const * const lhs_rects = lhs.getArray(&lhs_count); |
| 424 | |
| 425 | size_t rhs_count; |
| 426 | Rect const * const rhs_rects = rhs.getArray(&rhs_count); |
| 427 | |
| 428 | region_operator<Rect>::region lhs_region(lhs_rects, lhs_count); |
| 429 | region_operator<Rect>::region rhs_region(rhs_rects, rhs_count, dx, dy); |
| 430 | region_operator<Rect> operation(op, lhs_region, rhs_region); |
| 431 | { // scope for rasterizer (dtor has side effects) |
| 432 | rasterizer r(dst); |
| 433 | operation(r); |
| 434 | } |
| 435 | |
| 436 | #if VALIDATE_REGIONS |
| 437 | validate(lhs, "boolean_operation: lhs"); |
| 438 | validate(rhs, "boolean_operation: rhs"); |
| 439 | validate(dst, "boolean_operation: dst"); |
| 440 | #endif |
| 441 | |
| 442 | #if VALIDATE_WITH_CORECG |
| 443 | SkRegion sk_lhs; |
| 444 | SkRegion sk_rhs; |
| 445 | SkRegion sk_dst; |
| 446 | |
| 447 | for (size_t i=0 ; i<lhs_count ; i++) |
| 448 | sk_lhs.op( |
| 449 | lhs_rects[i].left + dx, |
| 450 | lhs_rects[i].top + dy, |
| 451 | lhs_rects[i].right + dx, |
| 452 | lhs_rects[i].bottom + dy, |
| 453 | SkRegion::kUnion_Op); |
| 454 | |
| 455 | for (size_t i=0 ; i<rhs_count ; i++) |
| 456 | sk_rhs.op( |
| 457 | rhs_rects[i].left + dx, |
| 458 | rhs_rects[i].top + dy, |
| 459 | rhs_rects[i].right + dx, |
| 460 | rhs_rects[i].bottom + dy, |
| 461 | SkRegion::kUnion_Op); |
| 462 | |
| 463 | const char* name = "---"; |
| 464 | SkRegion::Op sk_op; |
| 465 | switch (op) { |
| 466 | case op_or: sk_op = SkRegion::kUnion_Op; name="OR"; break; |
Romain Guy | b8a2e98 | 2012-02-07 17:04:34 -0800 | [diff] [blame] | 467 | case op_xor: sk_op = SkRegion::kUnion_XOR; name="XOR"; break; |
Mathias Agopian | 20f6878 | 2009-05-11 00:03:41 -0700 | [diff] [blame] | 468 | case op_and: sk_op = SkRegion::kIntersect_Op; name="AND"; break; |
| 469 | case op_nand: sk_op = SkRegion::kDifference_Op; name="NAND"; break; |
| 470 | } |
| 471 | sk_dst.op(sk_lhs, sk_rhs, sk_op); |
| 472 | |
| 473 | if (sk_dst.isEmpty() && dst.isEmpty()) |
| 474 | return; |
| 475 | |
| 476 | bool same = true; |
| 477 | Region::const_iterator head = dst.begin(); |
| 478 | Region::const_iterator const tail = dst.end(); |
| 479 | SkRegion::Iterator it(sk_dst); |
| 480 | while (!it.done()) { |
| 481 | if (head != tail) { |
| 482 | if ( |
| 483 | head->left != it.rect().fLeft || |
| 484 | head->top != it.rect().fTop || |
| 485 | head->right != it.rect().fRight || |
| 486 | head->bottom != it.rect().fBottom |
| 487 | ) { |
| 488 | same = false; |
| 489 | break; |
| 490 | } |
| 491 | } else { |
| 492 | same = false; |
| 493 | break; |
| 494 | } |
| 495 | head++; |
| 496 | it.next(); |
| 497 | } |
| 498 | |
| 499 | if (head != tail) { |
| 500 | same = false; |
| 501 | } |
| 502 | |
| 503 | if(!same) { |
Steve Block | 9d45368 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 504 | ALOGD("---\nregion boolean %s failed", name); |
Mathias Agopian | 20f6878 | 2009-05-11 00:03:41 -0700 | [diff] [blame] | 505 | lhs.dump("lhs"); |
| 506 | rhs.dump("rhs"); |
| 507 | dst.dump("dst"); |
Steve Block | 9d45368 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 508 | ALOGD("should be"); |
Mathias Agopian | 20f6878 | 2009-05-11 00:03:41 -0700 | [diff] [blame] | 509 | SkRegion::Iterator it(sk_dst); |
| 510 | while (!it.done()) { |
Steve Block | 9d45368 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 511 | ALOGD(" [%3d, %3d, %3d, %3d]", |
Mathias Agopian | 20f6878 | 2009-05-11 00:03:41 -0700 | [diff] [blame] | 512 | it.rect().fLeft, |
| 513 | it.rect().fTop, |
| 514 | it.rect().fRight, |
| 515 | it.rect().fBottom); |
| 516 | it.next(); |
| 517 | } |
| 518 | } |
| 519 | #endif |
| 520 | } |
| 521 | |
| 522 | void Region::boolean_operation(int op, Region& dst, |
| 523 | const Region& lhs, |
| 524 | const Rect& rhs, int dx, int dy) |
| 525 | { |
Mathias Agopian | 0450452 | 2011-09-19 16:12:08 -0700 | [diff] [blame] | 526 | if (!rhs.isValid()) { |
Steve Block | e6f43dd | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 527 | ALOGE("Region::boolean_operation(op=%d) invalid Rect={%d,%d,%d,%d}", |
Mathias Agopian | 0450452 | 2011-09-19 16:12:08 -0700 | [diff] [blame] | 528 | op, rhs.left, rhs.top, rhs.right, rhs.bottom); |
Mathias Agopian | 0857c8f | 2011-09-26 15:58:20 -0700 | [diff] [blame] | 529 | return; |
Mathias Agopian | 0450452 | 2011-09-19 16:12:08 -0700 | [diff] [blame] | 530 | } |
| 531 | |
Mathias Agopian | 20f6878 | 2009-05-11 00:03:41 -0700 | [diff] [blame] | 532 | #if VALIDATE_WITH_CORECG || VALIDATE_REGIONS |
| 533 | boolean_operation(op, dst, lhs, Region(rhs), dx, dy); |
| 534 | #else |
| 535 | size_t lhs_count; |
| 536 | Rect const * const lhs_rects = lhs.getArray(&lhs_count); |
| 537 | |
| 538 | region_operator<Rect>::region lhs_region(lhs_rects, lhs_count); |
| 539 | region_operator<Rect>::region rhs_region(&rhs, 1, dx, dy); |
| 540 | region_operator<Rect> operation(op, lhs_region, rhs_region); |
| 541 | { // scope for rasterizer (dtor has side effects) |
| 542 | rasterizer r(dst); |
| 543 | operation(r); |
| 544 | } |
| 545 | |
| 546 | #endif |
| 547 | } |
| 548 | |
| 549 | void Region::boolean_operation(int op, Region& dst, |
| 550 | const Region& lhs, const Region& rhs) |
| 551 | { |
| 552 | boolean_operation(op, dst, lhs, rhs, 0, 0); |
| 553 | } |
| 554 | |
| 555 | void Region::boolean_operation(int op, Region& dst, |
| 556 | const Region& lhs, const Rect& rhs) |
| 557 | { |
| 558 | boolean_operation(op, dst, lhs, rhs, 0, 0); |
| 559 | } |
| 560 | |
| 561 | void Region::translate(Region& reg, int dx, int dy) |
| 562 | { |
Mathias Agopian | 4c0a170 | 2012-08-31 12:45:33 -0700 | [diff] [blame] | 563 | if ((dx || dy) && !reg.isEmpty()) { |
Mathias Agopian | 20f6878 | 2009-05-11 00:03:41 -0700 | [diff] [blame] | 564 | #if VALIDATE_REGIONS |
| 565 | validate(reg, "translate (before)"); |
| 566 | #endif |
Mathias Agopian | 20f6878 | 2009-05-11 00:03:41 -0700 | [diff] [blame] | 567 | size_t count = reg.mStorage.size(); |
| 568 | Rect* rects = reg.mStorage.editArray(); |
| 569 | while (count) { |
| 570 | rects->translate(dx, dy); |
| 571 | rects++; |
| 572 | count--; |
| 573 | } |
| 574 | #if VALIDATE_REGIONS |
| 575 | validate(reg, "translate (after)"); |
| 576 | #endif |
| 577 | } |
| 578 | } |
| 579 | |
| 580 | void Region::translate(Region& dst, const Region& reg, int dx, int dy) |
| 581 | { |
| 582 | dst = reg; |
| 583 | translate(dst, dx, dy); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 584 | } |
| 585 | |
| 586 | // ---------------------------------------------------------------------------- |
| 587 | |
Mathias Agopian | 8683fca | 2012-08-12 19:37:16 -0700 | [diff] [blame] | 588 | size_t Region::getSize() const { |
Mathias Agopian | 3ab6855 | 2012-08-31 14:31:40 -0700 | [diff] [blame] | 589 | return mStorage.size() * sizeof(Rect); |
Mathias Agopian | 8683fca | 2012-08-12 19:37:16 -0700 | [diff] [blame] | 590 | } |
| 591 | |
| 592 | status_t Region::flatten(void* buffer) const { |
Mathias Agopian | 068d47f | 2012-09-11 18:56:23 -0700 | [diff] [blame^] | 593 | #if VALIDATE_REGIONS |
| 594 | validate(*this, "Region::flatten"); |
| 595 | #endif |
Mathias Agopian | 8683fca | 2012-08-12 19:37:16 -0700 | [diff] [blame] | 596 | Rect* rects = reinterpret_cast<Rect*>(buffer); |
Mathias Agopian | 8683fca | 2012-08-12 19:37:16 -0700 | [diff] [blame] | 597 | memcpy(rects, mStorage.array(), mStorage.size() * sizeof(Rect)); |
| 598 | return NO_ERROR; |
| 599 | } |
| 600 | |
| 601 | status_t Region::unflatten(void const* buffer, size_t size) { |
Mathias Agopian | 068d47f | 2012-09-11 18:56:23 -0700 | [diff] [blame^] | 602 | Region result; |
Mathias Agopian | 8683fca | 2012-08-12 19:37:16 -0700 | [diff] [blame] | 603 | if (size >= sizeof(Rect)) { |
| 604 | Rect const* rects = reinterpret_cast<Rect const*>(buffer); |
Mathias Agopian | 8683fca | 2012-08-12 19:37:16 -0700 | [diff] [blame] | 605 | size_t count = size / sizeof(Rect); |
| 606 | if (count > 0) { |
Mathias Agopian | 068d47f | 2012-09-11 18:56:23 -0700 | [diff] [blame^] | 607 | result.mStorage.clear(); |
| 608 | ssize_t err = result.mStorage.insertAt(0, count); |
Mathias Agopian | 8683fca | 2012-08-12 19:37:16 -0700 | [diff] [blame] | 609 | if (err < 0) { |
| 610 | return status_t(err); |
| 611 | } |
Mathias Agopian | 068d47f | 2012-09-11 18:56:23 -0700 | [diff] [blame^] | 612 | memcpy(result.mStorage.editArray(), rects, count*sizeof(Rect)); |
Mathias Agopian | b612142 | 2010-02-17 20:22:26 -0800 | [diff] [blame] | 613 | } |
Mathias Agopian | 20f6878 | 2009-05-11 00:03:41 -0700 | [diff] [blame] | 614 | } |
Mathias Agopian | 3ab6855 | 2012-08-31 14:31:40 -0700 | [diff] [blame] | 615 | #if VALIDATE_REGIONS |
Mathias Agopian | 068d47f | 2012-09-11 18:56:23 -0700 | [diff] [blame^] | 616 | validate(result, "Region::unflatten"); |
Mathias Agopian | 3ab6855 | 2012-08-31 14:31:40 -0700 | [diff] [blame] | 617 | #endif |
Mathias Agopian | 068d47f | 2012-09-11 18:56:23 -0700 | [diff] [blame^] | 618 | |
| 619 | if (!result.validate(result, "Region::unflatten", true)) { |
| 620 | ALOGE("Region::unflatten() failed, invalid region"); |
| 621 | return BAD_VALUE; |
| 622 | } |
| 623 | mStorage = result.mStorage; |
Mathias Agopian | 8683fca | 2012-08-12 19:37:16 -0700 | [diff] [blame] | 624 | return NO_ERROR; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 625 | } |
| 626 | |
Mathias Agopian | 20f6878 | 2009-05-11 00:03:41 -0700 | [diff] [blame] | 627 | // ---------------------------------------------------------------------------- |
| 628 | |
| 629 | Region::const_iterator Region::begin() const { |
Mathias Agopian | 3ab6855 | 2012-08-31 14:31:40 -0700 | [diff] [blame] | 630 | return mStorage.array(); |
Mathias Agopian | 20f6878 | 2009-05-11 00:03:41 -0700 | [diff] [blame] | 631 | } |
| 632 | |
| 633 | Region::const_iterator Region::end() const { |
Mathias Agopian | 3ab6855 | 2012-08-31 14:31:40 -0700 | [diff] [blame] | 634 | size_t numRects = isRect() ? 1 : mStorage.size() - 1; |
| 635 | return mStorage.array() + numRects; |
Mathias Agopian | 20f6878 | 2009-05-11 00:03:41 -0700 | [diff] [blame] | 636 | } |
| 637 | |
| 638 | Rect const* Region::getArray(size_t* count) const { |
| 639 | const_iterator const b(begin()); |
| 640 | const_iterator const e(end()); |
| 641 | if (count) *count = e-b; |
| 642 | return b; |
| 643 | } |
| 644 | |
Mathias Agopian | 2401ead | 2012-08-31 15:41:24 -0700 | [diff] [blame] | 645 | SharedBuffer const* Region::getSharedBuffer(size_t* count) const { |
| 646 | // We can get to the SharedBuffer of a Vector<Rect> because Rect has |
| 647 | // a trivial destructor. |
| 648 | SharedBuffer const* sb = SharedBuffer::bufferFromData(mStorage.array()); |
| 649 | if (count) { |
| 650 | size_t numRects = isRect() ? 1 : mStorage.size() - 1; |
| 651 | count[0] = numRects; |
| 652 | } |
| 653 | sb->acquire(); |
| 654 | return sb; |
| 655 | } |
| 656 | |
Mathias Agopian | 20f6878 | 2009-05-11 00:03:41 -0700 | [diff] [blame] | 657 | // ---------------------------------------------------------------------------- |
| 658 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 659 | void Region::dump(String8& out, const char* what, uint32_t flags) const |
| 660 | { |
| 661 | (void)flags; |
Mathias Agopian | 20f6878 | 2009-05-11 00:03:41 -0700 | [diff] [blame] | 662 | const_iterator head = begin(); |
| 663 | const_iterator const tail = end(); |
| 664 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 665 | size_t SIZE = 256; |
| 666 | char buffer[SIZE]; |
Mathias Agopian | 20f6878 | 2009-05-11 00:03:41 -0700 | [diff] [blame] | 667 | |
| 668 | snprintf(buffer, SIZE, " Region %s (this=%p, count=%d)\n", |
| 669 | what, this, tail-head); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 670 | out.append(buffer); |
Mathias Agopian | 20f6878 | 2009-05-11 00:03:41 -0700 | [diff] [blame] | 671 | while (head != tail) { |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 672 | snprintf(buffer, SIZE, " [%3d, %3d, %3d, %3d]\n", |
Mathias Agopian | 20f6878 | 2009-05-11 00:03:41 -0700 | [diff] [blame] | 673 | head->left, head->top, head->right, head->bottom); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 674 | out.append(buffer); |
Mathias Agopian | 20f6878 | 2009-05-11 00:03:41 -0700 | [diff] [blame] | 675 | head++; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 676 | } |
| 677 | } |
| 678 | |
| 679 | void Region::dump(const char* what, uint32_t flags) const |
| 680 | { |
| 681 | (void)flags; |
Mathias Agopian | 20f6878 | 2009-05-11 00:03:41 -0700 | [diff] [blame] | 682 | const_iterator head = begin(); |
| 683 | const_iterator const tail = end(); |
Steve Block | 9d45368 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 684 | ALOGD(" Region %s (this=%p, count=%d)\n", what, this, tail-head); |
Mathias Agopian | 20f6878 | 2009-05-11 00:03:41 -0700 | [diff] [blame] | 685 | while (head != tail) { |
Steve Block | 9d45368 | 2011-12-20 16:23:08 +0000 | [diff] [blame] | 686 | ALOGD(" [%3d, %3d, %3d, %3d]\n", |
Mathias Agopian | 20f6878 | 2009-05-11 00:03:41 -0700 | [diff] [blame] | 687 | head->left, head->top, head->right, head->bottom); |
| 688 | head++; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 689 | } |
| 690 | } |
| 691 | |
| 692 | // ---------------------------------------------------------------------------- |
| 693 | |
| 694 | }; // namespace android |