1 /* 2 * Copyright 2018 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 SkCanvasVirtualEnforcer_DEFINED 9 #define SkCanvasVirtualEnforcer_DEFINED 10 11 #include "SkCanvas.h" 12 13 // If you would ordinarily want to inherit from Base (eg SkCanvas, SkNWayCanvas), instead 14 // inherit from SkCanvasVirtualEnforcer<Base>, which will make the build fail if you forget 15 // to override one of SkCanvas' key virtual hooks. 16 template <typename Base> 17 class SkCanvasVirtualEnforcer : public Base { 18 public: 19 using Base::Base; 20 21 protected: 22 void onDrawPaint(const SkPaint& paint) override = 0; 23 void onDrawRect(const SkRect& rect, const SkPaint& paint) override = 0; 24 void onDrawRRect(const SkRRect& rrect, const SkPaint& paint) override = 0; 25 void onDrawDRRect(const SkRRect& outer, const SkRRect& inner, 26 const SkPaint& paint) override = 0; 27 void onDrawOval(const SkRect& rect, const SkPaint& paint) override = 0; 28 void onDrawArc(const SkRect& rect, SkScalar startAngle, SkScalar sweepAngle, bool useCenter, 29 const SkPaint& paint) override = 0; 30 void onDrawPath(const SkPath& path, const SkPaint& paint) override = 0; 31 void onDrawRegion(const SkRegion& region, const SkPaint& paint) override = 0; 32 33 void onDrawTextBlob(const SkTextBlob* blob, SkScalar x, SkScalar y, 34 const SkPaint& paint) override = 0; 35 36 void onDrawPatch(const SkPoint cubics[12], const SkColor colors[4], 37 const SkPoint texCoords[4], SkBlendMode mode, 38 const SkPaint& paint) override = 0; 39 void onDrawPoints(SkCanvas::PointMode mode, size_t count, const SkPoint pts[], 40 const SkPaint& paint) override = 0; 41 void onDrawVerticesObject(const SkVertices*, const SkVertices::Bone bones[], int boneCount, 42 SkBlendMode, const SkPaint&) override = 0; 43 44 void onDrawImage(const SkImage* image, SkScalar dx, SkScalar dy, 45 const SkPaint* paint) override = 0; 46 void onDrawImageRect(const SkImage* image, const SkRect* src, const SkRect& dst, 47 const SkPaint* paint, SkCanvas::SrcRectConstraint constraint) override = 0; 48 void onDrawImageNine(const SkImage* image, const SkIRect& center, const SkRect& dst, 49 const SkPaint* paint) override = 0; 50 void onDrawImageLattice(const SkImage* image, const SkCanvas::Lattice& lattice, 51 const SkRect& dst, const SkPaint* paint) override = 0; 52 53 #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK 54 // This is under active development for Chrome and not used in Android. Hold off on adding 55 // implementations in Android's SkCanvas subclasses until this stabilizes. onDrawImageSet(const SkCanvas::ImageSetEntry[],int count,SkFilterQuality,SkBlendMode)56 void onDrawImageSet(const SkCanvas::ImageSetEntry[], int count, SkFilterQuality, 57 SkBlendMode) override {}; onDrawEdgeAARect(const SkRect & rect,SkCanvas::QuadAAFlags edgeAA,SkColor color,SkBlendMode mode)58 void onDrawEdgeAARect(const SkRect& rect, SkCanvas::QuadAAFlags edgeAA, SkColor color, 59 SkBlendMode mode) override {}; 60 #else 61 void onDrawImageSet(const SkCanvas::ImageSetEntry[], int count, SkFilterQuality, 62 SkBlendMode) override = 0; 63 void onDrawEdgeAARect(const SkRect& rect, SkCanvas::QuadAAFlags edgeAA, SkColor color, 64 SkBlendMode mode) override = 0; 65 #endif 66 67 void onDrawBitmap(const SkBitmap& bitmap, SkScalar dx, SkScalar dy, 68 const SkPaint* paint) override = 0; 69 void onDrawBitmapRect(const SkBitmap& bitmap, const SkRect* src, const SkRect& dst, 70 const SkPaint* paint, 71 SkCanvas::SrcRectConstraint constraint) override = 0; 72 void onDrawBitmapNine(const SkBitmap& bitmap, const SkIRect& center, const SkRect& dst, 73 const SkPaint* paint) override = 0; 74 void onDrawBitmapLattice(const SkBitmap& bitmap, const SkCanvas::Lattice& lattice, 75 const SkRect& dst, const SkPaint* paint) override = 0; 76 77 void onDrawAtlas(const SkImage* atlas, const SkRSXform xform[], const SkRect rect[], 78 const SkColor colors[], int count, SkBlendMode mode, const SkRect* cull, 79 const SkPaint* paint) override = 0; 80 81 void onDrawAnnotation(const SkRect& rect, const char key[], SkData* value) override = 0; 82 void onDrawShadowRec(const SkPath&, const SkDrawShadowRec&) override = 0; 83 84 void onDrawDrawable(SkDrawable* drawable, const SkMatrix* matrix) override = 0; 85 void onDrawPicture(const SkPicture* picture, const SkMatrix* matrix, 86 const SkPaint* paint) override = 0; 87 }; 88 89 #endif 90