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