1 /* 2 * Copyright 2011 Google Inc. 3 * 4 * Use of this source code is governed by a BSD-style license that can be 5 * found in the LICENSE file. 6 */ 7 8 #include "SkNWayCanvas.h" 9 #include "SkCanvasPriv.h" 10 11 SkNWayCanvas::SkNWayCanvas(int width, int height) : INHERITED(width, height) {} 12 13 SkNWayCanvas::~SkNWayCanvas() { 14 this->removeAll(); 15 } 16 17 void SkNWayCanvas::addCanvas(SkCanvas* canvas) { 18 if (canvas) { 19 *fList.append() = canvas; 20 } 21 } 22 23 void SkNWayCanvas::removeCanvas(SkCanvas* canvas) { 24 int index = fList.find(canvas); 25 if (index >= 0) { 26 fList.removeShuffle(index); 27 } 28 } 29 30 void SkNWayCanvas::removeAll() { 31 fList.reset(); 32 } 33 34 /////////////////////////////////////////////////////////////////////////// 35 // These are forwarded to the N canvases we're referencing 36 37 class SkNWayCanvas::Iter { 38 public: 39 Iter(const SkTDArray<SkCanvas*>& list) : fList(list) { 40 fIndex = 0; 41 } 42 bool next() { 43 if (fIndex < fList.count()) { 44 fCanvas = fList[fIndex++]; 45 return true; 46 } 47 return false; 48 } 49 SkCanvas* operator->() { return fCanvas; } 50 SkCanvas* get() const { return fCanvas; } 51 52 private: 53 const SkTDArray<SkCanvas*>& fList; 54 int fIndex; 55 SkCanvas* fCanvas; 56 }; 57 58 void SkNWayCanvas::willSave() { 59 Iter iter(fList); 60 while (iter.next()) { 61 iter->save(); 62 } 63 64 this->INHERITED::willSave(); 65 } 66 67 SkCanvas::SaveLayerStrategy SkNWayCanvas::getSaveLayerStrategy(const SaveLayerRec& rec) { 68 Iter iter(fList); 69 while (iter.next()) { 70 iter->saveLayer(rec); 71 } 72 73 this->INHERITED::getSaveLayerStrategy(rec); 74 // No need for a layer. 75 return kNoLayer_SaveLayerStrategy; 76 } 77 78 bool SkNWayCanvas::onDoSaveBehind(const SkRect* bounds) { 79 Iter iter(fList); 80 while (iter.next()) { 81 SkCanvasPriv::SaveBehind(iter.get(), bounds); 82 } 83 this->INHERITED::onDoSaveBehind(bounds); 84 return false; 85 } 86 87 void SkNWayCanvas::willRestore() { 88 Iter iter(fList); 89 while (iter.next()) { 90 iter->restore(); 91 } 92 this->INHERITED::willRestore(); 93 } 94 95 void SkNWayCanvas::didConcat(const SkMatrix& matrix) { 96 Iter iter(fList); 97 while (iter.next()) { 98 iter->concat(matrix); 99 } 100 this->INHERITED::didConcat(matrix); 101 } 102 103 void SkNWayCanvas::didSetMatrix(const SkMatrix& matrix) { 104 Iter iter(fList); 105 while (iter.next()) { 106 iter->setMatrix(matrix); 107 } 108 this->INHERITED::didSetMatrix(matrix); 109 } 110 111 void SkNWayCanvas::onClipRect(const SkRect& rect, SkClipOp op, ClipEdgeStyle edgeStyle) { 112 Iter iter(fList); 113 while (iter.next()) { 114 iter->clipRect(rect, op, kSoft_ClipEdgeStyle == edgeStyle); 115 } 116 this->INHERITED::onClipRect(rect, op, edgeStyle); 117 } 118 119 void SkNWayCanvas::onClipRRect(const SkRRect& rrect, SkClipOp op, ClipEdgeStyle edgeStyle) { 120 Iter iter(fList); 121 while (iter.next()) { 122 iter->clipRRect(rrect, op, kSoft_ClipEdgeStyle == edgeStyle); 123 } 124 this->INHERITED::onClipRRect(rrect, op, edgeStyle); 125 } 126 127 void SkNWayCanvas::onClipPath(const SkPath& path, SkClipOp op, ClipEdgeStyle edgeStyle) { 128 Iter iter(fList); 129 while (iter.next()) { 130 iter->clipPath(path, op, kSoft_ClipEdgeStyle == edgeStyle); 131 } 132 this->INHERITED::onClipPath(path, op, edgeStyle); 133 } 134 135 void SkNWayCanvas::onClipRegion(const SkRegion& deviceRgn, SkClipOp op) { 136 Iter iter(fList); 137 while (iter.next()) { 138 iter->clipRegion(deviceRgn, op); 139 } 140 this->INHERITED::onClipRegion(deviceRgn, op); 141 } 142 143 void SkNWayCanvas::onDrawPaint(const SkPaint& paint) { 144 Iter iter(fList); 145 while (iter.next()) { 146 iter->drawPaint(paint); 147 } 148 } 149 150 void SkNWayCanvas::onDrawBehind(const SkPaint& paint) { 151 Iter iter(fList); 152 while (iter.next()) { 153 SkCanvasPriv::DrawBehind(iter.get(), paint); 154 } 155 } 156 157 void SkNWayCanvas::onDrawPoints(PointMode mode, size_t count, const SkPoint pts[], 158 const SkPaint& paint) { 159 Iter iter(fList); 160 while (iter.next()) { 161 iter->drawPoints(mode, count, pts, paint); 162 } 163 } 164 165 void SkNWayCanvas::onDrawRect(const SkRect& rect, const SkPaint& paint) { 166 Iter iter(fList); 167 while (iter.next()) { 168 iter->drawRect(rect, paint); 169 } 170 } 171 172 void SkNWayCanvas::onDrawEdgeAARect(const SkRect& rect, SkCanvas::QuadAAFlags aa, SkColor color, 173 SkBlendMode mode) { 174 Iter iter(fList); 175 while (iter.next()) { 176 iter->experimental_DrawEdgeAARectV1(rect, aa, color, mode); 177 } 178 } 179 180 void SkNWayCanvas::onDrawRegion(const SkRegion& region, const SkPaint& paint) { 181 Iter iter(fList); 182 while (iter.next()) { 183 iter->drawRegion(region, paint); 184 } 185 } 186 187 void SkNWayCanvas::onDrawOval(const SkRect& rect, const SkPaint& paint) { 188 Iter iter(fList); 189 while (iter.next()) { 190 iter->drawOval(rect, paint); 191 } 192 } 193 194 void SkNWayCanvas::onDrawArc(const SkRect& rect, SkScalar startAngle, SkScalar sweepAngle, 195 bool useCenter, const SkPaint& paint) { 196 Iter iter(fList); 197 while (iter.next()) { 198 iter->drawArc(rect, startAngle, sweepAngle, useCenter, paint); 199 } 200 } 201 202 void SkNWayCanvas::onDrawRRect(const SkRRect& rrect, const SkPaint& paint) { 203 Iter iter(fList); 204 while (iter.next()) { 205 iter->drawRRect(rrect, paint); 206 } 207 } 208 209 void SkNWayCanvas::onDrawDRRect(const SkRRect& outer, const SkRRect& inner, const SkPaint& paint) { 210 Iter iter(fList); 211 while (iter.next()) { 212 iter->drawDRRect(outer, inner, paint); 213 } 214 } 215 216 void SkNWayCanvas::onDrawPath(const SkPath& path, const SkPaint& paint) { 217 Iter iter(fList); 218 while (iter.next()) { 219 iter->drawPath(path, paint); 220 } 221 } 222 223 void SkNWayCanvas::onDrawBitmap(const SkBitmap& bitmap, SkScalar x, SkScalar y, 224 const SkPaint* paint) { 225 Iter iter(fList); 226 while (iter.next()) { 227 iter->drawBitmap(bitmap, x, y, paint); 228 } 229 } 230 231 void SkNWayCanvas::onDrawBitmapRect(const SkBitmap& bitmap, const SkRect* src, const SkRect& dst, 232 const SkPaint* paint, SrcRectConstraint constraint) { 233 Iter iter(fList); 234 while (iter.next()) { 235 iter->legacy_drawBitmapRect(bitmap, src, dst, paint, (SrcRectConstraint)constraint); 236 } 237 } 238 239 void SkNWayCanvas::onDrawBitmapNine(const SkBitmap& bitmap, const SkIRect& center, 240 const SkRect& dst, const SkPaint* paint) { 241 Iter iter(fList); 242 while (iter.next()) { 243 iter->drawBitmapNine(bitmap, center, dst, paint); 244 } 245 } 246 247 void SkNWayCanvas::onDrawBitmapLattice(const SkBitmap& bitmap, const Lattice& lattice, 248 const SkRect& dst, const SkPaint* paint) { 249 Iter iter(fList); 250 while (iter.next()) { 251 iter->drawBitmapLattice(bitmap, lattice, dst, paint); 252 } 253 } 254 255 void SkNWayCanvas::onDrawImage(const SkImage* image, SkScalar left, SkScalar top, 256 const SkPaint* paint) { 257 Iter iter(fList); 258 while (iter.next()) { 259 iter->drawImage(image, left, top, paint); 260 } 261 } 262 263 void SkNWayCanvas::onDrawImageRect(const SkImage* image, const SkRect* src, const SkRect& dst, 264 const SkPaint* paint, SrcRectConstraint constraint) { 265 Iter iter(fList); 266 while (iter.next()) { 267 iter->legacy_drawImageRect(image, src, dst, paint, constraint); 268 } 269 } 270 271 void SkNWayCanvas::onDrawImageNine(const SkImage* image, const SkIRect& center, const SkRect& dst, 272 const SkPaint* paint) { 273 Iter iter(fList); 274 while (iter.next()) { 275 iter->drawImageNine(image, center, dst, paint); 276 } 277 } 278 279 void SkNWayCanvas::onDrawImageLattice(const SkImage* image, const Lattice& lattice, 280 const SkRect& dst, const SkPaint* paint) { 281 Iter iter(fList); 282 while (iter.next()) { 283 iter->drawImageLattice(image, lattice, dst, paint); 284 } 285 } 286 287 void SkNWayCanvas::onDrawImageSet(const SkCanvas::ImageSetEntry set[], int count, 288 SkFilterQuality filterQuality, SkBlendMode mode) { 289 Iter iter(fList); 290 while (iter.next()) { 291 iter->experimental_DrawImageSetV1(set, count, filterQuality, mode); 292 } 293 } 294 295 void SkNWayCanvas::onDrawTextBlob(const SkTextBlob* blob, SkScalar x, SkScalar y, 296 const SkPaint &paint) { 297 Iter iter(fList); 298 while (iter.next()) { 299 iter->drawTextBlob(blob, x, y, paint); 300 } 301 } 302 303 void SkNWayCanvas::onDrawPicture(const SkPicture* picture, const SkMatrix* matrix, 304 const SkPaint* paint) { 305 Iter iter(fList); 306 while (iter.next()) { 307 iter->drawPicture(picture, matrix, paint); 308 } 309 } 310 311 void SkNWayCanvas::onDrawDrawable(SkDrawable* drawable, const SkMatrix* matrix) { 312 Iter iter(fList); 313 while (iter.next()) { 314 iter->drawDrawable(drawable, matrix); 315 } 316 } 317 318 void SkNWayCanvas::onDrawVerticesObject(const SkVertices* vertices, const SkVertices::Bone bones[], 319 int boneCount, SkBlendMode bmode, const SkPaint& paint) { 320 Iter iter(fList); 321 while (iter.next()) { 322 iter->drawVertices(vertices, bones, boneCount, bmode, paint); 323 } 324 } 325 326 void SkNWayCanvas::onDrawPatch(const SkPoint cubics[12], const SkColor colors[4], 327 const SkPoint texCoords[4], SkBlendMode bmode, 328 const SkPaint& paint) { 329 Iter iter(fList); 330 while (iter.next()) { 331 iter->drawPatch(cubics, colors, texCoords, bmode, paint); 332 } 333 } 334 335 void SkNWayCanvas::onDrawAtlas(const SkImage* image, const SkRSXform xform[], const SkRect tex[], 336 const SkColor colors[], int count, SkBlendMode bmode, 337 const SkRect* cull, const SkPaint* paint) { 338 Iter iter(fList); 339 while (iter.next()) { 340 iter->drawAtlas(image, xform, tex, colors, count, bmode, cull, paint); 341 } 342 } 343 344 void SkNWayCanvas::onDrawShadowRec(const SkPath& path, const SkDrawShadowRec& rec) { 345 Iter iter(fList); 346 while (iter.next()) { 347 iter->private_draw_shadow_rec(path, rec); 348 } 349 } 350 351 void SkNWayCanvas::onDrawAnnotation(const SkRect& rect, const char key[], SkData* data) { 352 Iter iter(fList); 353 while (iter.next()) { 354 iter->drawAnnotation(rect, key, data); 355 } 356 } 357 358 void SkNWayCanvas::onFlush() { 359 Iter iter(fList); 360 while (iter.next()) { 361 iter->flush(); 362 } 363 } 364