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 "include/core/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; onDrawBehind(const SkPaint &)23 void onDrawBehind(const SkPaint&) override {} // make zero after android updates 24 void onDrawRect(const SkRect& rect, const SkPaint& paint) override = 0; 25 void onDrawRRect(const SkRRect& rrect, const SkPaint& paint) override = 0; 26 void onDrawDRRect(const SkRRect& outer, const SkRRect& inner, 27 const SkPaint& paint) override = 0; 28 void onDrawOval(const SkRect& rect, const SkPaint& paint) override = 0; 29 void onDrawArc(const SkRect& rect, SkScalar startAngle, SkScalar sweepAngle, bool useCenter, 30 const SkPaint& paint) override = 0; 31 void onDrawPath(const SkPath& path, const SkPaint& paint) override = 0; 32 void onDrawRegion(const SkRegion& region, const SkPaint& paint) override = 0; 33 34 void onDrawTextBlob(const SkTextBlob* blob, SkScalar x, SkScalar y, 35 const SkPaint& paint) override = 0; 36 37 void onDrawPatch(const SkPoint cubics[12], const SkColor colors[4], 38 const SkPoint texCoords[4], SkBlendMode mode, 39 const SkPaint& paint) override = 0; 40 void onDrawPoints(SkCanvas::PointMode mode, size_t count, const SkPoint pts[], 41 const SkPaint& paint) override = 0; 42 void onDrawVerticesObject(const SkVertices*, const SkVertices::Bone bones[], int boneCount, 43 SkBlendMode, const SkPaint&) override = 0; 44 45 void onDrawImage(const SkImage* image, SkScalar dx, SkScalar dy, 46 const SkPaint* paint) override = 0; 47 void onDrawImageRect(const SkImage* image, const SkRect* src, const SkRect& dst, 48 const SkPaint* paint, SkCanvas::SrcRectConstraint constraint) override = 0; 49 void onDrawImageNine(const SkImage* image, const SkIRect& center, const SkRect& dst, 50 const SkPaint* paint) override = 0; 51 void onDrawImageLattice(const SkImage* image, const SkCanvas::Lattice& lattice, 52 const SkRect& dst, const SkPaint* paint) override = 0; 53 54 #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK 55 // This is under active development for Chrome and not used in Android. Hold off on adding 56 // implementations in Android's SkCanvas subclasses until this stabilizes. onDrawEdgeAAQuad(const SkRect & rect,const SkPoint clip[4],SkCanvas::QuadAAFlags aaFlags,SkColor color,SkBlendMode mode)57 void onDrawEdgeAAQuad(const SkRect& rect, const SkPoint clip[4], 58 SkCanvas::QuadAAFlags aaFlags, SkColor color, SkBlendMode mode) override {} onDrawEdgeAAImageSet(const SkCanvas::ImageSetEntry imageSet[],int count,const SkPoint dstClips[],const SkMatrix preViewMatrices[],const SkPaint * paint,SkCanvas::SrcRectConstraint constraint)59 void onDrawEdgeAAImageSet(const SkCanvas::ImageSetEntry imageSet[], int count, 60 const SkPoint dstClips[], const SkMatrix preViewMatrices[], const SkPaint* paint, 61 SkCanvas::SrcRectConstraint constraint) override {} 62 #else 63 void onDrawEdgeAAQuad(const SkRect& rect, const SkPoint clip[4], 64 SkCanvas::QuadAAFlags aaFlags, SkColor color, SkBlendMode mode) override = 0; 65 void onDrawEdgeAAImageSet(const SkCanvas::ImageSetEntry imageSet[], int count, 66 const SkPoint dstClips[], const SkMatrix preViewMatrices[], const SkPaint* paint, 67 SkCanvas::SrcRectConstraint constraint) override = 0; 68 #endif 69 70 void onDrawBitmap(const SkBitmap& bitmap, SkScalar dx, SkScalar dy, 71 const SkPaint* paint) override = 0; 72 void onDrawBitmapRect(const SkBitmap& bitmap, const SkRect* src, const SkRect& dst, 73 const SkPaint* paint, 74 SkCanvas::SrcRectConstraint constraint) override = 0; 75 void onDrawBitmapNine(const SkBitmap& bitmap, const SkIRect& center, const SkRect& dst, 76 const SkPaint* paint) override = 0; 77 void onDrawBitmapLattice(const SkBitmap& bitmap, const SkCanvas::Lattice& lattice, 78 const SkRect& dst, const SkPaint* paint) override = 0; 79 80 void onDrawAtlas(const SkImage* atlas, const SkRSXform xform[], const SkRect rect[], 81 const SkColor colors[], int count, SkBlendMode mode, const SkRect* cull, 82 const SkPaint* paint) override = 0; 83 84 void onDrawAnnotation(const SkRect& rect, const char key[], SkData* value) override = 0; 85 void onDrawShadowRec(const SkPath&, const SkDrawShadowRec&) override = 0; 86 87 void onDrawDrawable(SkDrawable* drawable, const SkMatrix* matrix) override = 0; 88 void onDrawPicture(const SkPicture* picture, const SkMatrix* matrix, 89 const SkPaint* paint) override = 0; 90 }; 91 92 #endif 93