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 */ 8 #include "SkNWayCanvas.h" 9 10 static SkBitmap make_noconfig_bm(int width, int height) { 11 SkBitmap bm; 12 bm.setConfig(SkBitmap::kNo_Config, width, height); 13 return bm; 14 } 15 16 SkNWayCanvas::SkNWayCanvas(int width, int height) 17 : INHERITED(make_noconfig_bm(width, height)) {} 18 19 SkNWayCanvas::~SkNWayCanvas() { 20 this->removeAll(); 21 } 22 23 void SkNWayCanvas::addCanvas(SkCanvas* canvas) { 24 if (canvas) { 25 canvas->ref(); 26 *fList.append() = canvas; 27 } 28 } 29 30 void SkNWayCanvas::removeCanvas(SkCanvas* canvas) { 31 int index = fList.find(canvas); 32 if (index >= 0) { 33 canvas->unref(); 34 fList.removeShuffle(index); 35 } 36 } 37 38 void SkNWayCanvas::removeAll() { 39 fList.unrefAll(); 40 fList.reset(); 41 } 42 43 /////////////////////////////////////////////////////////////////////////// 44 // These are forwarded to the N canvases we're referencing 45 46 class SkNWayCanvas::Iter { 47 public: 48 Iter(const SkTDArray<SkCanvas*>& list) : fList(list) { 49 fIndex = 0; 50 } 51 bool next() { 52 if (fIndex < fList.count()) { 53 fCanvas = fList[fIndex++]; 54 return true; 55 } 56 return false; 57 } 58 SkCanvas* operator->() { return fCanvas; } 59 60 private: 61 const SkTDArray<SkCanvas*>& fList; 62 int fIndex; 63 SkCanvas* fCanvas; 64 }; 65 66 int SkNWayCanvas::save(SaveFlags flags) { 67 Iter iter(fList); 68 while (iter.next()) { 69 iter->save(flags); 70 } 71 return this->INHERITED::save(flags); 72 } 73 74 int SkNWayCanvas::saveLayer(const SkRect* bounds, const SkPaint* paint, 75 SaveFlags flags) { 76 Iter iter(fList); 77 while (iter.next()) { 78 iter->saveLayer(bounds, paint, flags); 79 } 80 return this->INHERITED::saveLayer(bounds, paint, flags); 81 } 82 83 void SkNWayCanvas::restore() { 84 Iter iter(fList); 85 while (iter.next()) { 86 iter->restore(); 87 } 88 this->INHERITED::restore(); 89 } 90 91 bool SkNWayCanvas::translate(SkScalar dx, SkScalar dy) { 92 Iter iter(fList); 93 while (iter.next()) { 94 iter->translate(dx, dy); 95 } 96 return this->INHERITED::translate(dx, dy); 97 } 98 99 bool SkNWayCanvas::scale(SkScalar sx, SkScalar sy) { 100 Iter iter(fList); 101 while (iter.next()) { 102 iter->scale(sx, sy); 103 } 104 return this->INHERITED::scale(sx, sy); 105 } 106 107 bool SkNWayCanvas::rotate(SkScalar degrees) { 108 Iter iter(fList); 109 while (iter.next()) { 110 iter->rotate(degrees); 111 } 112 return this->INHERITED::rotate(degrees); 113 } 114 115 bool SkNWayCanvas::skew(SkScalar sx, SkScalar sy) { 116 Iter iter(fList); 117 while (iter.next()) { 118 iter->skew(sx, sy); 119 } 120 return this->INHERITED::skew(sx, sy); 121 } 122 123 bool SkNWayCanvas::concat(const SkMatrix& matrix) { 124 Iter iter(fList); 125 while (iter.next()) { 126 iter->concat(matrix); 127 } 128 return this->INHERITED::concat(matrix); 129 } 130 131 void SkNWayCanvas::setMatrix(const SkMatrix& matrix) { 132 Iter iter(fList); 133 while (iter.next()) { 134 iter->setMatrix(matrix); 135 } 136 this->INHERITED::setMatrix(matrix); 137 } 138 139 bool SkNWayCanvas::clipRect(const SkRect& rect, SkRegion::Op op, bool doAA) { 140 Iter iter(fList); 141 while (iter.next()) { 142 iter->clipRect(rect, op, doAA); 143 } 144 return this->INHERITED::clipRect(rect, op, doAA); 145 } 146 147 bool SkNWayCanvas::clipRRect(const SkRRect& rrect, SkRegion::Op op, bool doAA) { 148 Iter iter(fList); 149 while (iter.next()) { 150 iter->clipRRect(rrect, op, doAA); 151 } 152 return this->INHERITED::clipRRect(rrect, op, doAA); 153 } 154 155 bool SkNWayCanvas::clipPath(const SkPath& path, SkRegion::Op op, bool doAA) { 156 Iter iter(fList); 157 while (iter.next()) { 158 iter->clipPath(path, op, doAA); 159 } 160 return this->INHERITED::clipPath(path, op, doAA); 161 } 162 163 bool SkNWayCanvas::clipRegion(const SkRegion& deviceRgn, SkRegion::Op op) { 164 Iter iter(fList); 165 while (iter.next()) { 166 iter->clipRegion(deviceRgn, op); 167 } 168 return this->INHERITED::clipRegion(deviceRgn, op); 169 } 170 171 void SkNWayCanvas::clear(SkColor color) { 172 Iter iter(fList); 173 while (iter.next()) { 174 iter->clear(color); 175 } 176 } 177 178 void SkNWayCanvas::drawPaint(const SkPaint& paint) { 179 Iter iter(fList); 180 while (iter.next()) { 181 iter->drawPaint(paint); 182 } 183 } 184 185 void SkNWayCanvas::drawPoints(PointMode mode, size_t count, const SkPoint pts[], 186 const SkPaint& paint) { 187 Iter iter(fList); 188 while (iter.next()) { 189 iter->drawPoints(mode, count, pts, paint); 190 } 191 } 192 193 void SkNWayCanvas::drawRect(const SkRect& rect, const SkPaint& paint) { 194 Iter iter(fList); 195 while (iter.next()) { 196 iter->drawRect(rect, paint); 197 } 198 } 199 200 void SkNWayCanvas::drawOval(const SkRect& rect, const SkPaint& paint) { 201 Iter iter(fList); 202 while (iter.next()) { 203 iter->drawOval(rect, paint); 204 } 205 } 206 207 void SkNWayCanvas::drawRRect(const SkRRect& rrect, const SkPaint& paint) { 208 Iter iter(fList); 209 while (iter.next()) { 210 iter->drawRRect(rrect, paint); 211 } 212 } 213 214 void SkNWayCanvas::drawPath(const SkPath& path, const SkPaint& paint) { 215 Iter iter(fList); 216 while (iter.next()) { 217 iter->drawPath(path, paint); 218 } 219 } 220 221 void SkNWayCanvas::drawBitmap(const SkBitmap& bitmap, SkScalar x, SkScalar y, 222 const SkPaint* paint) { 223 Iter iter(fList); 224 while (iter.next()) { 225 iter->drawBitmap(bitmap, x, y, paint); 226 } 227 } 228 229 void SkNWayCanvas::drawBitmapRectToRect(const SkBitmap& bitmap, const SkRect* src, 230 const SkRect& dst, const SkPaint* paint, 231 DrawBitmapRectFlags flags) { 232 Iter iter(fList); 233 while (iter.next()) { 234 iter->drawBitmapRectToRect(bitmap, src, dst, paint, flags); 235 } 236 } 237 238 void SkNWayCanvas::drawBitmapMatrix(const SkBitmap& bitmap, const SkMatrix& m, 239 const SkPaint* paint) { 240 Iter iter(fList); 241 while (iter.next()) { 242 iter->drawBitmapMatrix(bitmap, m, paint); 243 } 244 } 245 246 void SkNWayCanvas::drawBitmapNine(const SkBitmap& bitmap, const SkIRect& center, 247 const SkRect& dst, const SkPaint* paint) { 248 Iter iter(fList); 249 while (iter.next()) { 250 iter->drawBitmapNine(bitmap, center, dst, paint); 251 } 252 } 253 254 void SkNWayCanvas::drawSprite(const SkBitmap& bitmap, int x, int y, 255 const SkPaint* paint) { 256 Iter iter(fList); 257 while (iter.next()) { 258 iter->drawSprite(bitmap, x, y, paint); 259 } 260 } 261 262 void SkNWayCanvas::drawText(const void* text, size_t byteLength, SkScalar x, 263 SkScalar y, const SkPaint& paint) { 264 Iter iter(fList); 265 while (iter.next()) { 266 iter->drawText(text, byteLength, x, y, paint); 267 } 268 } 269 270 void SkNWayCanvas::drawPosText(const void* text, size_t byteLength, 271 const SkPoint pos[], const SkPaint& paint) { 272 Iter iter(fList); 273 while (iter.next()) { 274 iter->drawPosText(text, byteLength, pos, paint); 275 } 276 } 277 278 void SkNWayCanvas::drawPosTextH(const void* text, size_t byteLength, 279 const SkScalar xpos[], SkScalar constY, 280 const SkPaint& paint) { 281 Iter iter(fList); 282 while (iter.next()) { 283 iter->drawPosTextH(text, byteLength, xpos, constY, paint); 284 } 285 } 286 287 void SkNWayCanvas::drawTextOnPath(const void* text, size_t byteLength, 288 const SkPath& path, const SkMatrix* matrix, 289 const SkPaint& paint) { 290 Iter iter(fList); 291 while (iter.next()) { 292 iter->drawTextOnPath(text, byteLength, path, matrix, paint); 293 } 294 } 295 296 void SkNWayCanvas::drawPicture(SkPicture& picture) { 297 Iter iter(fList); 298 while (iter.next()) { 299 iter->drawPicture(picture); 300 } 301 } 302 303 void SkNWayCanvas::drawVertices(VertexMode vmode, int vertexCount, 304 const SkPoint vertices[], const SkPoint texs[], 305 const SkColor colors[], SkXfermode* xmode, 306 const uint16_t indices[], int indexCount, 307 const SkPaint& paint) { 308 Iter iter(fList); 309 while (iter.next()) { 310 iter->drawVertices(vmode, vertexCount, vertices, texs, colors, xmode, 311 indices, indexCount, paint); 312 } 313 } 314 315 void SkNWayCanvas::drawData(const void* data, size_t length) { 316 Iter iter(fList); 317 while (iter.next()) { 318 iter->drawData(data, length); 319 } 320 } 321 322 SkBounder* SkNWayCanvas::setBounder(SkBounder* bounder) { 323 Iter iter(fList); 324 while (iter.next()) { 325 iter->setBounder(bounder); 326 } 327 return this->INHERITED::setBounder(bounder); 328 } 329 330 SkDrawFilter* SkNWayCanvas::setDrawFilter(SkDrawFilter* filter) { 331 Iter iter(fList); 332 while (iter.next()) { 333 iter->setDrawFilter(filter); 334 } 335 return this->INHERITED::setDrawFilter(filter); 336 } 337 338 void SkNWayCanvas::beginCommentGroup(const char* description) { 339 Iter iter(fList); 340 while (iter.next()) { 341 iter->beginCommentGroup(description); 342 } 343 } 344 345 void SkNWayCanvas::addComment(const char* kywd, const char* value) { 346 Iter iter(fList); 347 while (iter.next()) { 348 iter->addComment(kywd, value); 349 } 350 } 351 352 void SkNWayCanvas::endCommentGroup() { 353 Iter iter(fList); 354 while (iter.next()) { 355 iter->endCommentGroup(); 356 } 357 } 358