Home | History | Annotate | Download | only in utils
      1 
      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 #ifndef SkProxyCanvas_DEFINED
      9 #define SkProxyCanvas_DEFINED
     10 
     11 #include "SkCanvas.h"
     12 
     13 /** This class overrides all virtual methods on SkCanvas, and redirects them
     14     to a "proxy", another SkCanvas instance. It can be the basis for
     15     intercepting (and possibly modifying) calls to a canvas.
     16 
     17     There must be a proxy installed before the proxycanvas can be used (i.e.
     18     before its virtual methods can be called).
     19  */
     20 class SkProxyCanvas : public SkCanvas {
     21 public:
     22     SkProxyCanvas() : fProxy(NULL) {}
     23     SkProxyCanvas(SkCanvas* proxy);
     24     virtual ~SkProxyCanvas();
     25 
     26     SkCanvas*   getProxy() const { return fProxy; }
     27     void        setProxy(SkCanvas* proxy);
     28 
     29     virtual int save(SaveFlags flags = kMatrixClip_SaveFlag) SK_OVERRIDE;
     30     virtual int saveLayer(const SkRect* bounds, const SkPaint* paint,
     31                           SaveFlags flags = kARGB_ClipLayer_SaveFlag) SK_OVERRIDE;
     32     virtual void restore() SK_OVERRIDE;
     33 
     34     virtual bool translate(SkScalar dx, SkScalar dy) SK_OVERRIDE;
     35     virtual bool scale(SkScalar sx, SkScalar sy) SK_OVERRIDE;
     36     virtual bool rotate(SkScalar degrees) SK_OVERRIDE;
     37     virtual bool skew(SkScalar sx, SkScalar sy) SK_OVERRIDE;
     38     virtual bool concat(const SkMatrix& matrix) SK_OVERRIDE;
     39     virtual void setMatrix(const SkMatrix& matrix) SK_OVERRIDE;
     40 
     41     virtual bool clipRect(const SkRect&, SkRegion::Op, bool) SK_OVERRIDE;
     42     virtual bool clipPath(const SkPath&, SkRegion::Op, bool) SK_OVERRIDE;
     43     virtual bool clipRegion(const SkRegion& deviceRgn,
     44                             SkRegion::Op op = SkRegion::kIntersect_Op) SK_OVERRIDE;
     45 
     46     virtual void drawPaint(const SkPaint& paint) SK_OVERRIDE;
     47     virtual void drawPoints(PointMode mode, size_t count, const SkPoint pts[],
     48                             const SkPaint& paint) SK_OVERRIDE;
     49     virtual void drawRect(const SkRect& rect, const SkPaint& paint) SK_OVERRIDE;
     50     virtual void drawPath(const SkPath& path, const SkPaint& paint) SK_OVERRIDE;
     51     virtual void drawBitmap(const SkBitmap& bitmap, SkScalar left, SkScalar top,
     52                             const SkPaint* paint = NULL) SK_OVERRIDE;
     53     virtual void drawBitmapRect(const SkBitmap& bitmap, const SkIRect* src,
     54                                 const SkRect& dst, const SkPaint* paint = NULL) SK_OVERRIDE;
     55     virtual void drawBitmapMatrix(const SkBitmap& bitmap, const SkMatrix& m,
     56                                   const SkPaint* paint = NULL) SK_OVERRIDE;
     57     virtual void drawSprite(const SkBitmap& bitmap, int left, int top,
     58                             const SkPaint* paint = NULL) SK_OVERRIDE;
     59     virtual void drawText(const void* text, size_t byteLength, SkScalar x,
     60                           SkScalar y, const SkPaint& paint) SK_OVERRIDE;
     61     virtual void drawPosText(const void* text, size_t byteLength,
     62                              const SkPoint pos[], const SkPaint& paint) SK_OVERRIDE;
     63     virtual void drawPosTextH(const void* text, size_t byteLength,
     64                               const SkScalar xpos[], SkScalar constY,
     65                               const SkPaint& paint) SK_OVERRIDE;
     66     virtual void drawTextOnPath(const void* text, size_t byteLength,
     67                                 const SkPath& path, const SkMatrix* matrix,
     68                                 const SkPaint& paint) SK_OVERRIDE;
     69     virtual void drawPicture(SkPicture&) SK_OVERRIDE;
     70     virtual void drawVertices(VertexMode vmode, int vertexCount,
     71                               const SkPoint vertices[], const SkPoint texs[],
     72                               const SkColor colors[], SkXfermode* xmode,
     73                               const uint16_t indices[], int indexCount,
     74                               const SkPaint& paint) SK_OVERRIDE;
     75     virtual void drawData(const void* data, size_t length) SK_OVERRIDE;
     76 
     77     virtual SkBounder* setBounder(SkBounder* bounder) SK_OVERRIDE;
     78     virtual SkDrawFilter* setDrawFilter(SkDrawFilter* filter) SK_OVERRIDE;
     79 
     80 private:
     81     SkCanvas*   fProxy;
     82 
     83     typedef SkCanvas INHERITED;
     84 };
     85 
     86 #endif
     87