Home | History | Annotate | Download | only in utils
      1 /*
      2  * Copyright 2015 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 #ifndef SkPaintFilterCanvas_DEFINED
      9 #define SkPaintFilterCanvas_DEFINED
     10 
     11 #include "SkNWayCanvas.h"
     12 
     13 /** \class SkPaintFilterCanvas
     14 
     15     A utility proxy base class for implementing paint filters.
     16 */
     17 class SK_API SkPaintFilterCanvas : public SkNWayCanvas {
     18 public:
     19     SkPaintFilterCanvas(int width, int height);
     20 
     21     enum Type {
     22         kPaint_Type,
     23         kPoint_Type,
     24         kBitmap_Type,
     25         kRect_Type,
     26         kRRect_Type,
     27         kDRRect_Type,
     28         kOval_Type,
     29         kPath_Type,
     30         kPicture_Type,
     31         kText_Type,
     32         kTextBlob_Type,
     33         kVertices_Type,
     34         kPatch_Type,
     35 
     36         kTypeCount
     37     };
     38 
     39 protected:
     40     /**
     41      *  Called with the paint that will be used to draw the specified type.
     42      *  The implementation may modify the paint as they wish.
     43      *
     44      *  Note: The base implementation calls onFilterPaint() for top-level/explicit paints only.
     45      *        To also filter encapsulated paints (e.g. SkPicture, SkTextBlob), clients may need to
     46      *        override the relevant methods (i.e. drawPicture, drawTextBlob).
     47      */
     48     virtual void onFilterPaint(SkPaint* paint, Type type) const = 0;
     49 
     50     void onDrawPaint(const SkPaint&) override;
     51     void onDrawPoints(PointMode, size_t count, const SkPoint pts[], const SkPaint&) override;
     52     void onDrawRect(const SkRect&, const SkPaint&) override;
     53     void onDrawRRect(const SkRRect&, const SkPaint&) override;
     54     void onDrawDRRect(const SkRRect&, const SkRRect&, const SkPaint&) override;
     55     void onDrawOval(const SkRect&, const SkPaint&) override;
     56     void onDrawPath(const SkPath&, const SkPaint&) override;
     57     void onDrawBitmap(const SkBitmap&, SkScalar left, SkScalar top, const SkPaint*) override;
     58     void onDrawBitmapRect(const SkBitmap&, const SkRect* src, const SkRect& dst, const SkPaint*,
     59                           DrawBitmapRectFlags flags) override;
     60     void onDrawImage(const SkImage*, SkScalar left, SkScalar top, const SkPaint*) override;
     61     void onDrawImageRect(const SkImage*, const SkRect* src, const SkRect& dst,
     62                          const SkPaint*) override;
     63     void onDrawBitmapNine(const SkBitmap&, const SkIRect& center, const SkRect& dst,
     64                           const SkPaint*) override;
     65     void onDrawSprite(const SkBitmap&, int left, int top, const SkPaint*) override;
     66     void onDrawVertices(VertexMode vmode, int vertexCount,
     67                               const SkPoint vertices[], const SkPoint texs[],
     68                               const SkColor colors[], SkXfermode* xmode,
     69                               const uint16_t indices[], int indexCount,
     70                               const SkPaint&) override;
     71     void onDrawPatch(const SkPoint cubics[12], const SkColor colors[4],
     72                              const SkPoint texCoords[4], SkXfermode* xmode,
     73                              const SkPaint& paint) override;
     74     void onDrawPicture(const SkPicture*, const SkMatrix*, const SkPaint*) override;
     75 
     76     void onDrawText(const void* text, size_t byteLength, SkScalar x, SkScalar y,
     77                     const SkPaint&) override;
     78     void onDrawPosText(const void* text, size_t byteLength, const SkPoint pos[],
     79                        const SkPaint&) override;
     80     void onDrawPosTextH(const void* text, size_t byteLength, const SkScalar xpos[],
     81                         SkScalar constY, const SkPaint&) override;
     82     void onDrawTextOnPath(const void* text, size_t byteLength, const SkPath& path,
     83                           const SkMatrix* matrix, const SkPaint&) override;
     84     void onDrawTextBlob(const SkTextBlob* blob, SkScalar x, SkScalar y,
     85                         const SkPaint& paint) override;
     86 
     87 private:
     88     class AutoPaintFilter;
     89 
     90     typedef SkNWayCanvas INHERITED;
     91 };
     92 
     93 #endif
     94