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 SK_API SkProxyCanvas : public SkCanvas { 21 public: SkProxyCanvas()22 SkProxyCanvas() : fProxy(NULL) {} 23 SkProxyCanvas(SkCanvas* proxy); 24 virtual ~SkProxyCanvas(); 25 getProxy()26 SkCanvas* getProxy() const { return fProxy; } 27 void setProxy(SkCanvas* proxy); 28 29 virtual void drawPaint(const SkPaint& paint) SK_OVERRIDE; 30 virtual void drawPoints(PointMode mode, size_t count, const SkPoint pts[], 31 const SkPaint& paint) SK_OVERRIDE; 32 virtual void drawOval(const SkRect&, const SkPaint& paint) SK_OVERRIDE; 33 virtual void drawRect(const SkRect&, const SkPaint& paint) SK_OVERRIDE; 34 virtual void drawRRect(const SkRRect&, const SkPaint& paint) SK_OVERRIDE; 35 virtual void drawPath(const SkPath& path, const SkPaint& paint) SK_OVERRIDE; 36 virtual void drawBitmap(const SkBitmap& bitmap, SkScalar left, SkScalar top, 37 const SkPaint* paint = NULL) SK_OVERRIDE; 38 virtual void drawBitmapRectToRect(const SkBitmap& bitmap, const SkRect* src, 39 const SkRect& dst, const SkPaint* paint, 40 DrawBitmapRectFlags flags) SK_OVERRIDE; 41 virtual void drawBitmapMatrix(const SkBitmap& bitmap, const SkMatrix& m, 42 const SkPaint* paint = NULL) SK_OVERRIDE; 43 virtual void drawSprite(const SkBitmap& bitmap, int left, int top, 44 const SkPaint* paint = NULL) SK_OVERRIDE; 45 virtual void drawVertices(VertexMode vmode, int vertexCount, 46 const SkPoint vertices[], const SkPoint texs[], 47 const SkColor colors[], SkXfermode* xmode, 48 const uint16_t indices[], int indexCount, 49 const SkPaint& paint) SK_OVERRIDE; 50 virtual void drawData(const void* data, size_t length) SK_OVERRIDE; 51 52 virtual void beginCommentGroup(const char* description) SK_OVERRIDE; 53 virtual void addComment(const char* kywd, const char* value) SK_OVERRIDE; 54 virtual void endCommentGroup() SK_OVERRIDE; 55 56 virtual SkDrawFilter* setDrawFilter(SkDrawFilter* filter) SK_OVERRIDE; 57 58 // Transitional, to facilitate migrating subclasses to the new willSave API. 59 using SkCanvas::willSave; 60 61 protected: 62 virtual void willSave(SaveFlags) SK_OVERRIDE; 63 virtual SaveLayerStrategy willSaveLayer(const SkRect*, const SkPaint*, SaveFlags) SK_OVERRIDE; 64 virtual void willRestore() SK_OVERRIDE; 65 66 virtual void didConcat(const SkMatrix&) SK_OVERRIDE; 67 virtual void didSetMatrix(const SkMatrix&) SK_OVERRIDE; 68 69 virtual void onDrawDRRect(const SkRRect&, const SkRRect&, const SkPaint&) SK_OVERRIDE; 70 virtual void onDrawText(const void* text, size_t byteLength, SkScalar x, SkScalar y, 71 const SkPaint&) SK_OVERRIDE; 72 virtual void onDrawPosText(const void* text, size_t byteLength, const SkPoint pos[], 73 const SkPaint&) SK_OVERRIDE; 74 virtual void onDrawPosTextH(const void* text, size_t byteLength, const SkScalar xpos[], 75 SkScalar constY, const SkPaint&) SK_OVERRIDE; 76 virtual void onDrawTextOnPath(const void* text, size_t byteLength, const SkPath& path, 77 const SkMatrix* matrix, const SkPaint&) SK_OVERRIDE; 78 79 virtual void onClipRect(const SkRect&, SkRegion::Op, ClipEdgeStyle) SK_OVERRIDE; 80 virtual void onClipRRect(const SkRRect&, SkRegion::Op, ClipEdgeStyle) SK_OVERRIDE; 81 virtual void onClipPath(const SkPath&, SkRegion::Op, ClipEdgeStyle) SK_OVERRIDE; 82 virtual void onClipRegion(const SkRegion&, SkRegion::Op) SK_OVERRIDE; 83 84 virtual void onDrawPicture(const SkPicture*) SK_OVERRIDE; 85 86 private: 87 SkCanvas* fProxy; 88 89 typedef SkCanvas INHERITED; 90 }; 91 92 #endif 93