epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | |
| 2 | /* |
| 3 | * Copyright 2011 Google Inc. |
| 4 | * |
| 5 | * Use of this source code is governed by a BSD-style license that can be |
| 6 | * found in the LICENSE file. |
| 7 | */ |
reed@android.com | 6c924ad | 2009-03-31 03:48:49 +0000 | [diff] [blame] | 8 | #include "SkNWayCanvas.h" |
| 9 | |
| 10 | SkNWayCanvas::SkNWayCanvas() {} |
| 11 | |
| 12 | SkNWayCanvas::~SkNWayCanvas() { |
| 13 | this->removeAll(); |
| 14 | } |
| 15 | |
| 16 | void SkNWayCanvas::addCanvas(SkCanvas* canvas) { |
| 17 | if (canvas) { |
| 18 | canvas->ref(); |
| 19 | *fList.append() = canvas; |
| 20 | } |
| 21 | } |
| 22 | |
| 23 | void SkNWayCanvas::removeCanvas(SkCanvas* canvas) { |
| 24 | int index = fList.find(canvas); |
| 25 | if (index >= 0) { |
| 26 | canvas->unref(); |
| 27 | fList.removeShuffle(index); |
| 28 | } |
| 29 | } |
| 30 | |
| 31 | void SkNWayCanvas::removeAll() { |
| 32 | fList.unrefAll(); |
| 33 | fList.reset(); |
| 34 | } |
| 35 | |
| 36 | /////////////////////////////////////////////////////////////////////////// |
| 37 | // These are forwarded to the N canvases we're referencing |
| 38 | |
| 39 | class SkNWayCanvas::Iter { |
| 40 | public: |
| 41 | Iter(const SkTDArray<SkCanvas*>& list) : fList(list) { |
| 42 | fIndex = 0; |
| 43 | } |
| 44 | bool next() { |
| 45 | if (fIndex < fList.count()) { |
| 46 | fCanvas = fList[fIndex++]; |
| 47 | return true; |
| 48 | } |
| 49 | return false; |
| 50 | } |
| 51 | SkCanvas* operator->() { return fCanvas; } |
vandebo@chromium.org | 74b4619 | 2012-01-28 01:45:11 +0000 | [diff] [blame^] | 52 | |
reed@android.com | 6c924ad | 2009-03-31 03:48:49 +0000 | [diff] [blame] | 53 | private: |
| 54 | const SkTDArray<SkCanvas*>& fList; |
| 55 | int fIndex; |
| 56 | SkCanvas* fCanvas; |
| 57 | }; |
| 58 | |
| 59 | int SkNWayCanvas::save(SaveFlags flags) { |
| 60 | Iter iter(fList); |
| 61 | while (iter.next()) { |
| 62 | iter->save(flags); |
| 63 | } |
| 64 | return this->INHERITED::save(flags); |
| 65 | } |
| 66 | |
| 67 | int SkNWayCanvas::saveLayer(const SkRect* bounds, const SkPaint* paint, |
| 68 | SaveFlags flags) { |
| 69 | Iter iter(fList); |
| 70 | while (iter.next()) { |
| 71 | iter->saveLayer(bounds, paint, flags); |
| 72 | } |
| 73 | return this->INHERITED::saveLayer(bounds, paint, flags); |
| 74 | } |
| 75 | |
| 76 | void SkNWayCanvas::restore() { |
| 77 | Iter iter(fList); |
| 78 | while (iter.next()) { |
| 79 | iter->restore(); |
| 80 | } |
| 81 | this->INHERITED::restore(); |
| 82 | } |
| 83 | |
| 84 | bool SkNWayCanvas::translate(SkScalar dx, SkScalar dy) { |
| 85 | Iter iter(fList); |
| 86 | while (iter.next()) { |
| 87 | iter->translate(dx, dy); |
| 88 | } |
| 89 | return this->INHERITED::translate(dx, dy); |
| 90 | } |
| 91 | |
| 92 | bool SkNWayCanvas::scale(SkScalar sx, SkScalar sy) { |
| 93 | Iter iter(fList); |
| 94 | while (iter.next()) { |
| 95 | iter->scale(sx, sy); |
| 96 | } |
| 97 | return this->INHERITED::scale(sx, sy); |
| 98 | } |
| 99 | |
| 100 | bool SkNWayCanvas::rotate(SkScalar degrees) { |
| 101 | Iter iter(fList); |
| 102 | while (iter.next()) { |
| 103 | iter->rotate(degrees); |
| 104 | } |
| 105 | return this->INHERITED::rotate(degrees); |
| 106 | } |
| 107 | |
| 108 | bool SkNWayCanvas::skew(SkScalar sx, SkScalar sy) { |
| 109 | Iter iter(fList); |
| 110 | while (iter.next()) { |
| 111 | iter->skew(sx, sy); |
| 112 | } |
| 113 | return this->INHERITED::skew(sx, sy); |
| 114 | } |
| 115 | |
| 116 | bool SkNWayCanvas::concat(const SkMatrix& matrix) { |
| 117 | Iter iter(fList); |
| 118 | while (iter.next()) { |
| 119 | iter->concat(matrix); |
| 120 | } |
| 121 | return this->INHERITED::concat(matrix); |
| 122 | } |
| 123 | |
| 124 | void SkNWayCanvas::setMatrix(const SkMatrix& matrix) { |
| 125 | Iter iter(fList); |
| 126 | while (iter.next()) { |
| 127 | iter->setMatrix(matrix); |
| 128 | } |
| 129 | this->INHERITED::setMatrix(matrix); |
| 130 | } |
| 131 | |
reed@google.com | 071eef9 | 2011-10-12 11:52:53 +0000 | [diff] [blame] | 132 | bool SkNWayCanvas::clipRect(const SkRect& rect, SkRegion::Op op, bool doAA) { |
reed@android.com | 6c924ad | 2009-03-31 03:48:49 +0000 | [diff] [blame] | 133 | Iter iter(fList); |
| 134 | while (iter.next()) { |
reed@google.com | 071eef9 | 2011-10-12 11:52:53 +0000 | [diff] [blame] | 135 | iter->clipRect(rect, op, doAA); |
reed@android.com | 6c924ad | 2009-03-31 03:48:49 +0000 | [diff] [blame] | 136 | } |
reed@google.com | 071eef9 | 2011-10-12 11:52:53 +0000 | [diff] [blame] | 137 | return this->INHERITED::clipRect(rect, op, doAA); |
reed@android.com | 6c924ad | 2009-03-31 03:48:49 +0000 | [diff] [blame] | 138 | } |
| 139 | |
reed@google.com | 071eef9 | 2011-10-12 11:52:53 +0000 | [diff] [blame] | 140 | bool SkNWayCanvas::clipPath(const SkPath& path, SkRegion::Op op, bool doAA) { |
reed@android.com | 6c924ad | 2009-03-31 03:48:49 +0000 | [diff] [blame] | 141 | Iter iter(fList); |
| 142 | while (iter.next()) { |
reed@google.com | 071eef9 | 2011-10-12 11:52:53 +0000 | [diff] [blame] | 143 | iter->clipPath(path, op, doAA); |
reed@android.com | 6c924ad | 2009-03-31 03:48:49 +0000 | [diff] [blame] | 144 | } |
reed@google.com | 071eef9 | 2011-10-12 11:52:53 +0000 | [diff] [blame] | 145 | return this->INHERITED::clipPath(path, op, doAA); |
reed@android.com | 6c924ad | 2009-03-31 03:48:49 +0000 | [diff] [blame] | 146 | } |
| 147 | |
| 148 | bool SkNWayCanvas::clipRegion(const SkRegion& deviceRgn, SkRegion::Op op) { |
| 149 | Iter iter(fList); |
| 150 | while (iter.next()) { |
| 151 | iter->clipRegion(deviceRgn, op); |
| 152 | } |
| 153 | return this->INHERITED::clipRegion(deviceRgn, op); |
| 154 | } |
| 155 | |
| 156 | void SkNWayCanvas::drawPaint(const SkPaint& paint) { |
| 157 | Iter iter(fList); |
| 158 | while (iter.next()) { |
| 159 | iter->drawPaint(paint); |
| 160 | } |
| 161 | } |
| 162 | |
| 163 | void SkNWayCanvas::drawPoints(PointMode mode, size_t count, const SkPoint pts[], |
| 164 | const SkPaint& paint) { |
| 165 | Iter iter(fList); |
| 166 | while (iter.next()) { |
| 167 | iter->drawPoints(mode, count, pts, paint); |
| 168 | } |
| 169 | } |
| 170 | |
| 171 | void SkNWayCanvas::drawRect(const SkRect& rect, const SkPaint& paint) { |
| 172 | Iter iter(fList); |
| 173 | while (iter.next()) { |
| 174 | iter->drawRect(rect, paint); |
| 175 | } |
| 176 | } |
| 177 | |
| 178 | void SkNWayCanvas::drawPath(const SkPath& path, const SkPaint& paint) { |
| 179 | Iter iter(fList); |
| 180 | while (iter.next()) { |
| 181 | iter->drawPath(path, paint); |
| 182 | } |
| 183 | } |
| 184 | |
| 185 | void SkNWayCanvas::drawBitmap(const SkBitmap& bitmap, SkScalar x, SkScalar y, |
| 186 | const SkPaint* paint) { |
| 187 | Iter iter(fList); |
| 188 | while (iter.next()) { |
| 189 | iter->drawBitmap(bitmap, x, y, paint); |
| 190 | } |
| 191 | } |
| 192 | |
| 193 | void SkNWayCanvas::drawBitmapRect(const SkBitmap& bitmap, const SkIRect* src, |
| 194 | const SkRect& dst, const SkPaint* paint) { |
| 195 | Iter iter(fList); |
| 196 | while (iter.next()) { |
| 197 | iter->drawBitmapRect(bitmap, src, dst, paint); |
| 198 | } |
| 199 | } |
| 200 | |
| 201 | void SkNWayCanvas::drawBitmapMatrix(const SkBitmap& bitmap, const SkMatrix& m, |
| 202 | const SkPaint* paint) { |
| 203 | Iter iter(fList); |
| 204 | while (iter.next()) { |
| 205 | iter->drawBitmapMatrix(bitmap, m, paint); |
| 206 | } |
| 207 | } |
| 208 | |
| 209 | void SkNWayCanvas::drawSprite(const SkBitmap& bitmap, int x, int y, |
| 210 | const SkPaint* paint) { |
| 211 | Iter iter(fList); |
| 212 | while (iter.next()) { |
| 213 | iter->drawSprite(bitmap, x, y, paint); |
| 214 | } |
| 215 | } |
| 216 | |
| 217 | void SkNWayCanvas::drawText(const void* text, size_t byteLength, SkScalar x, |
| 218 | SkScalar y, const SkPaint& paint) { |
| 219 | Iter iter(fList); |
| 220 | while (iter.next()) { |
| 221 | iter->drawText(text, byteLength, x, y, paint); |
| 222 | } |
| 223 | } |
| 224 | |
| 225 | void SkNWayCanvas::drawPosText(const void* text, size_t byteLength, |
| 226 | const SkPoint pos[], const SkPaint& paint) { |
| 227 | Iter iter(fList); |
| 228 | while (iter.next()) { |
| 229 | iter->drawPosText(text, byteLength, pos, paint); |
| 230 | } |
| 231 | } |
| 232 | |
| 233 | void SkNWayCanvas::drawPosTextH(const void* text, size_t byteLength, |
| 234 | const SkScalar xpos[], SkScalar constY, |
| 235 | const SkPaint& paint) { |
| 236 | Iter iter(fList); |
| 237 | while (iter.next()) { |
| 238 | iter->drawPosTextH(text, byteLength, xpos, constY, paint); |
| 239 | } |
| 240 | } |
| 241 | |
| 242 | void SkNWayCanvas::drawTextOnPath(const void* text, size_t byteLength, |
| 243 | const SkPath& path, const SkMatrix* matrix, |
| 244 | const SkPaint& paint) { |
| 245 | Iter iter(fList); |
| 246 | while (iter.next()) { |
| 247 | iter->drawTextOnPath(text, byteLength, path, matrix, paint); |
| 248 | } |
| 249 | } |
| 250 | |
| 251 | void SkNWayCanvas::drawPicture(SkPicture& picture) { |
| 252 | Iter iter(fList); |
| 253 | while (iter.next()) { |
| 254 | iter->drawPicture(picture); |
| 255 | } |
| 256 | } |
| 257 | |
reed@android.com | 6c924ad | 2009-03-31 03:48:49 +0000 | [diff] [blame] | 258 | void SkNWayCanvas::drawVertices(VertexMode vmode, int vertexCount, |
| 259 | const SkPoint vertices[], const SkPoint texs[], |
| 260 | const SkColor colors[], SkXfermode* xmode, |
| 261 | const uint16_t indices[], int indexCount, |
| 262 | const SkPaint& paint) { |
| 263 | Iter iter(fList); |
| 264 | while (iter.next()) { |
| 265 | iter->drawVertices(vmode, vertexCount, vertices, texs, colors, xmode, |
| 266 | indices, indexCount, paint); |
| 267 | } |
| 268 | } |
| 269 | |
| 270 | SkBounder* SkNWayCanvas::setBounder(SkBounder* bounder) { |
| 271 | Iter iter(fList); |
| 272 | while (iter.next()) { |
| 273 | iter->setBounder(bounder); |
| 274 | } |
| 275 | return this->INHERITED::setBounder(bounder); |
| 276 | } |
| 277 | |
| 278 | SkDrawFilter* SkNWayCanvas::setDrawFilter(SkDrawFilter* filter) { |
| 279 | Iter iter(fList); |
| 280 | while (iter.next()) { |
| 281 | iter->setDrawFilter(filter); |
| 282 | } |
| 283 | return this->INHERITED::setDrawFilter(filter); |
| 284 | } |
| 285 | |
| 286 | |