gfx/skia/trunk/src/utils/SkNWayCanvas.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gfx/skia/trunk/src/utils/SkNWayCanvas.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,363 @@
     1.4 +
     1.5 +/*
     1.6 + * Copyright 2011 Google Inc.
     1.7 + *
     1.8 + * Use of this source code is governed by a BSD-style license that can be
     1.9 + * found in the LICENSE file.
    1.10 + */
    1.11 +#include "SkNWayCanvas.h"
    1.12 +
    1.13 +SkNWayCanvas::SkNWayCanvas(int width, int height)
    1.14 +        : INHERITED(width, height) {}
    1.15 +
    1.16 +SkNWayCanvas::~SkNWayCanvas() {
    1.17 +    this->removeAll();
    1.18 +}
    1.19 +
    1.20 +void SkNWayCanvas::addCanvas(SkCanvas* canvas) {
    1.21 +    if (canvas) {
    1.22 +        canvas->ref();
    1.23 +        *fList.append() = canvas;
    1.24 +    }
    1.25 +}
    1.26 +
    1.27 +void SkNWayCanvas::removeCanvas(SkCanvas* canvas) {
    1.28 +    int index = fList.find(canvas);
    1.29 +    if (index >= 0) {
    1.30 +        canvas->unref();
    1.31 +        fList.removeShuffle(index);
    1.32 +    }
    1.33 +}
    1.34 +
    1.35 +void SkNWayCanvas::removeAll() {
    1.36 +    fList.unrefAll();
    1.37 +    fList.reset();
    1.38 +}
    1.39 +
    1.40 +///////////////////////////////////////////////////////////////////////////
    1.41 +// These are forwarded to the N canvases we're referencing
    1.42 +
    1.43 +class SkNWayCanvas::Iter {
    1.44 +public:
    1.45 +    Iter(const SkTDArray<SkCanvas*>& list) : fList(list) {
    1.46 +        fIndex = 0;
    1.47 +    }
    1.48 +    bool next() {
    1.49 +        if (fIndex < fList.count()) {
    1.50 +            fCanvas = fList[fIndex++];
    1.51 +            return true;
    1.52 +        }
    1.53 +        return false;
    1.54 +    }
    1.55 +    SkCanvas* operator->() { return fCanvas; }
    1.56 +
    1.57 +private:
    1.58 +    const SkTDArray<SkCanvas*>& fList;
    1.59 +    int fIndex;
    1.60 +    SkCanvas* fCanvas;
    1.61 +};
    1.62 +
    1.63 +void SkNWayCanvas::willSave(SaveFlags flags) {
    1.64 +    Iter iter(fList);
    1.65 +    while (iter.next()) {
    1.66 +        iter->save(flags);
    1.67 +    }
    1.68 +
    1.69 +    this->INHERITED::willSave(flags);
    1.70 +}
    1.71 +
    1.72 +SkCanvas::SaveLayerStrategy SkNWayCanvas::willSaveLayer(const SkRect* bounds, const SkPaint* paint,
    1.73 +                                                        SaveFlags flags) {
    1.74 +    Iter iter(fList);
    1.75 +    while (iter.next()) {
    1.76 +        iter->saveLayer(bounds, paint, flags);
    1.77 +    }
    1.78 +
    1.79 +    this->INHERITED::willSaveLayer(bounds, paint, flags);
    1.80 +    // No need for a layer.
    1.81 +    return kNoLayer_SaveLayerStrategy;
    1.82 +}
    1.83 +
    1.84 +void SkNWayCanvas::willRestore() {
    1.85 +    Iter iter(fList);
    1.86 +    while (iter.next()) {
    1.87 +        iter->restore();
    1.88 +    }
    1.89 +    this->INHERITED::willRestore();
    1.90 +}
    1.91 +
    1.92 +void SkNWayCanvas::didTranslate(SkScalar dx, SkScalar dy) {
    1.93 +    Iter iter(fList);
    1.94 +    while (iter.next()) {
    1.95 +        iter->translate(dx, dy);
    1.96 +    }
    1.97 +    this->INHERITED::didTranslate(dx, dy);
    1.98 +}
    1.99 +
   1.100 +void SkNWayCanvas::didScale(SkScalar sx, SkScalar sy) {
   1.101 +    Iter iter(fList);
   1.102 +    while (iter.next()) {
   1.103 +        iter->scale(sx, sy);
   1.104 +    }
   1.105 +    this->INHERITED::didScale(sx, sy);
   1.106 +}
   1.107 +
   1.108 +void SkNWayCanvas::didRotate(SkScalar degrees) {
   1.109 +    Iter iter(fList);
   1.110 +    while (iter.next()) {
   1.111 +        iter->rotate(degrees);
   1.112 +    }
   1.113 +    this->INHERITED::didRotate(degrees);
   1.114 +}
   1.115 +
   1.116 +void SkNWayCanvas::didSkew(SkScalar sx, SkScalar sy) {
   1.117 +    Iter iter(fList);
   1.118 +    while (iter.next()) {
   1.119 +        iter->skew(sx, sy);
   1.120 +    }
   1.121 +    this->INHERITED::didSkew(sx, sy);
   1.122 +}
   1.123 +
   1.124 +void SkNWayCanvas::didConcat(const SkMatrix& matrix) {
   1.125 +    Iter iter(fList);
   1.126 +    while (iter.next()) {
   1.127 +        iter->concat(matrix);
   1.128 +    }
   1.129 +    this->INHERITED::didConcat(matrix);
   1.130 +}
   1.131 +
   1.132 +void SkNWayCanvas::didSetMatrix(const SkMatrix& matrix) {
   1.133 +    Iter iter(fList);
   1.134 +    while (iter.next()) {
   1.135 +        iter->setMatrix(matrix);
   1.136 +    }
   1.137 +    this->INHERITED::didSetMatrix(matrix);
   1.138 +}
   1.139 +
   1.140 +void SkNWayCanvas::onClipRect(const SkRect& rect, SkRegion::Op op, ClipEdgeStyle edgeStyle) {
   1.141 +    Iter iter(fList);
   1.142 +    while (iter.next()) {
   1.143 +        iter->clipRect(rect, op, kSoft_ClipEdgeStyle == edgeStyle);
   1.144 +    }
   1.145 +    this->INHERITED::onClipRect(rect, op, edgeStyle);
   1.146 +}
   1.147 +
   1.148 +void SkNWayCanvas::onClipRRect(const SkRRect& rrect, SkRegion::Op op, ClipEdgeStyle edgeStyle) {
   1.149 +    Iter iter(fList);
   1.150 +    while (iter.next()) {
   1.151 +        iter->clipRRect(rrect, op, kSoft_ClipEdgeStyle == edgeStyle);
   1.152 +    }
   1.153 +    this->INHERITED::onClipRRect(rrect, op, edgeStyle);
   1.154 +}
   1.155 +
   1.156 +void SkNWayCanvas::onClipPath(const SkPath& path, SkRegion::Op op, ClipEdgeStyle edgeStyle) {
   1.157 +    Iter iter(fList);
   1.158 +    while (iter.next()) {
   1.159 +        iter->clipPath(path, op, kSoft_ClipEdgeStyle == edgeStyle);
   1.160 +    }
   1.161 +    this->INHERITED::onClipPath(path, op, edgeStyle);
   1.162 +}
   1.163 +
   1.164 +void SkNWayCanvas::onClipRegion(const SkRegion& deviceRgn, SkRegion::Op op) {
   1.165 +    Iter iter(fList);
   1.166 +    while (iter.next()) {
   1.167 +        iter->clipRegion(deviceRgn, op);
   1.168 +    }
   1.169 +    this->INHERITED::onClipRegion(deviceRgn, op);
   1.170 +}
   1.171 +
   1.172 +void SkNWayCanvas::clear(SkColor color) {
   1.173 +    Iter iter(fList);
   1.174 +    while (iter.next()) {
   1.175 +        iter->clear(color);
   1.176 +    }
   1.177 +}
   1.178 +
   1.179 +void SkNWayCanvas::drawPaint(const SkPaint& paint) {
   1.180 +    Iter iter(fList);
   1.181 +    while (iter.next()) {
   1.182 +        iter->drawPaint(paint);
   1.183 +    }
   1.184 +}
   1.185 +
   1.186 +void SkNWayCanvas::drawPoints(PointMode mode, size_t count, const SkPoint pts[],
   1.187 +                        const SkPaint& paint) {
   1.188 +    Iter iter(fList);
   1.189 +    while (iter.next()) {
   1.190 +        iter->drawPoints(mode, count, pts, paint);
   1.191 +    }
   1.192 +}
   1.193 +
   1.194 +void SkNWayCanvas::drawRect(const SkRect& rect, const SkPaint& paint) {
   1.195 +    Iter iter(fList);
   1.196 +    while (iter.next()) {
   1.197 +        iter->drawRect(rect, paint);
   1.198 +    }
   1.199 +}
   1.200 +
   1.201 +void SkNWayCanvas::drawOval(const SkRect& rect, const SkPaint& paint) {
   1.202 +    Iter iter(fList);
   1.203 +    while (iter.next()) {
   1.204 +        iter->drawOval(rect, paint);
   1.205 +    }
   1.206 +}
   1.207 +
   1.208 +void SkNWayCanvas::drawRRect(const SkRRect& rrect, const SkPaint& paint) {
   1.209 +    Iter iter(fList);
   1.210 +    while (iter.next()) {
   1.211 +        iter->drawRRect(rrect, paint);
   1.212 +    }
   1.213 +}
   1.214 +
   1.215 +void SkNWayCanvas::onDrawDRRect(const SkRRect& outer, const SkRRect& inner,
   1.216 +                                const SkPaint& paint) {
   1.217 +    Iter iter(fList);
   1.218 +    while (iter.next()) {
   1.219 +        iter->drawDRRect(outer, inner, paint);
   1.220 +    }
   1.221 +}
   1.222 +
   1.223 +void SkNWayCanvas::drawPath(const SkPath& path, const SkPaint& paint) {
   1.224 +    Iter iter(fList);
   1.225 +    while (iter.next()) {
   1.226 +        iter->drawPath(path, paint);
   1.227 +    }
   1.228 +}
   1.229 +
   1.230 +void SkNWayCanvas::drawBitmap(const SkBitmap& bitmap, SkScalar x, SkScalar y,
   1.231 +                              const SkPaint* paint) {
   1.232 +    Iter iter(fList);
   1.233 +    while (iter.next()) {
   1.234 +        iter->drawBitmap(bitmap, x, y, paint);
   1.235 +    }
   1.236 +}
   1.237 +
   1.238 +void SkNWayCanvas::drawBitmapRectToRect(const SkBitmap& bitmap, const SkRect* src,
   1.239 +                                  const SkRect& dst, const SkPaint* paint,
   1.240 +                                  DrawBitmapRectFlags flags) {
   1.241 +    Iter iter(fList);
   1.242 +    while (iter.next()) {
   1.243 +        iter->drawBitmapRectToRect(bitmap, src, dst, paint, flags);
   1.244 +    }
   1.245 +}
   1.246 +
   1.247 +void SkNWayCanvas::drawBitmapMatrix(const SkBitmap& bitmap, const SkMatrix& m,
   1.248 +                                    const SkPaint* paint) {
   1.249 +    Iter iter(fList);
   1.250 +    while (iter.next()) {
   1.251 +        iter->drawBitmapMatrix(bitmap, m, paint);
   1.252 +    }
   1.253 +}
   1.254 +
   1.255 +void SkNWayCanvas::drawBitmapNine(const SkBitmap& bitmap, const SkIRect& center,
   1.256 +                                  const SkRect& dst, const SkPaint* paint) {
   1.257 +    Iter iter(fList);
   1.258 +    while (iter.next()) {
   1.259 +        iter->drawBitmapNine(bitmap, center, dst, paint);
   1.260 +    }
   1.261 +}
   1.262 +
   1.263 +void SkNWayCanvas::drawSprite(const SkBitmap& bitmap, int x, int y,
   1.264 +                              const SkPaint* paint) {
   1.265 +    Iter iter(fList);
   1.266 +    while (iter.next()) {
   1.267 +        iter->drawSprite(bitmap, x, y, paint);
   1.268 +    }
   1.269 +}
   1.270 +
   1.271 +void SkNWayCanvas::drawText(const void* text, size_t byteLength, SkScalar x,
   1.272 +                            SkScalar y, const SkPaint& paint) {
   1.273 +    Iter iter(fList);
   1.274 +    while (iter.next()) {
   1.275 +        iter->drawText(text, byteLength, x, y, paint);
   1.276 +    }
   1.277 +}
   1.278 +
   1.279 +void SkNWayCanvas::drawPosText(const void* text, size_t byteLength,
   1.280 +                               const SkPoint pos[], const SkPaint& paint) {
   1.281 +    Iter iter(fList);
   1.282 +    while (iter.next()) {
   1.283 +        iter->drawPosText(text, byteLength, pos, paint);
   1.284 +    }
   1.285 +}
   1.286 +
   1.287 +void SkNWayCanvas::drawPosTextH(const void* text, size_t byteLength,
   1.288 +                                const SkScalar xpos[], SkScalar constY,
   1.289 +                                const SkPaint& paint) {
   1.290 +    Iter iter(fList);
   1.291 +    while (iter.next()) {
   1.292 +        iter->drawPosTextH(text, byteLength, xpos, constY, paint);
   1.293 +    }
   1.294 +}
   1.295 +
   1.296 +void SkNWayCanvas::drawTextOnPath(const void* text, size_t byteLength,
   1.297 +                                  const SkPath& path, const SkMatrix* matrix,
   1.298 +                                  const SkPaint& paint) {
   1.299 +    Iter iter(fList);
   1.300 +    while (iter.next()) {
   1.301 +        iter->drawTextOnPath(text, byteLength, path, matrix, paint);
   1.302 +    }
   1.303 +}
   1.304 +
   1.305 +void SkNWayCanvas::drawPicture(SkPicture& picture) {
   1.306 +    Iter iter(fList);
   1.307 +    while (iter.next()) {
   1.308 +        iter->drawPicture(picture);
   1.309 +    }
   1.310 +}
   1.311 +
   1.312 +void SkNWayCanvas::drawVertices(VertexMode vmode, int vertexCount,
   1.313 +                          const SkPoint vertices[], const SkPoint texs[],
   1.314 +                          const SkColor colors[], SkXfermode* xmode,
   1.315 +                          const uint16_t indices[], int indexCount,
   1.316 +                          const SkPaint& paint) {
   1.317 +    Iter iter(fList);
   1.318 +    while (iter.next()) {
   1.319 +        iter->drawVertices(vmode, vertexCount, vertices, texs, colors, xmode,
   1.320 +                           indices, indexCount, paint);
   1.321 +    }
   1.322 +}
   1.323 +
   1.324 +void SkNWayCanvas::drawData(const void* data, size_t length) {
   1.325 +    Iter iter(fList);
   1.326 +    while (iter.next()) {
   1.327 +        iter->drawData(data, length);
   1.328 +    }
   1.329 +}
   1.330 +
   1.331 +SkBounder* SkNWayCanvas::setBounder(SkBounder* bounder) {
   1.332 +    Iter iter(fList);
   1.333 +    while (iter.next()) {
   1.334 +        iter->setBounder(bounder);
   1.335 +    }
   1.336 +    return this->INHERITED::setBounder(bounder);
   1.337 +}
   1.338 +
   1.339 +SkDrawFilter* SkNWayCanvas::setDrawFilter(SkDrawFilter* filter) {
   1.340 +    Iter iter(fList);
   1.341 +    while (iter.next()) {
   1.342 +        iter->setDrawFilter(filter);
   1.343 +    }
   1.344 +    return this->INHERITED::setDrawFilter(filter);
   1.345 +}
   1.346 +
   1.347 +void SkNWayCanvas::beginCommentGroup(const char* description) {
   1.348 +    Iter iter(fList);
   1.349 +    while (iter.next()) {
   1.350 +        iter->beginCommentGroup(description);
   1.351 +    }
   1.352 +}
   1.353 +
   1.354 +void SkNWayCanvas::addComment(const char* kywd, const char* value) {
   1.355 +    Iter iter(fList);
   1.356 +    while (iter.next()) {
   1.357 +        iter->addComment(kywd, value);
   1.358 +    }
   1.359 +}
   1.360 +
   1.361 +void SkNWayCanvas::endCommentGroup() {
   1.362 +    Iter iter(fList);
   1.363 +    while (iter.next()) {
   1.364 +        iter->endCommentGroup();
   1.365 +    }
   1.366 +}

mercurial