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