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

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

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

mercurial