SkCanvasVirtualEnforcer.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. #ifndef SkCanvasVirtualEnforcer_DEFINED
  8. #define SkCanvasVirtualEnforcer_DEFINED
  9. #include "SkCanvas.h"
  10. // If you would ordinarily want to inherit from Base (eg SkCanvas, SkNWayCanvas), instead
  11. // inherit from SkCanvasVirtualEnforcer<Base>, which will make the build fail if you forget
  12. // to override one of SkCanvas' key virtual hooks.
  13. template <typename Base>
  14. class SkCanvasVirtualEnforcer : public Base {
  15. public:
  16. using Base::Base;
  17. protected:
  18. void onDrawPaint(const SkPaint& paint) override = 0;
  19. void onDrawRect(const SkRect& rect, const SkPaint& paint) override = 0;
  20. void onDrawRRect(const SkRRect& rrect, const SkPaint& paint) override = 0;
  21. void onDrawDRRect(const SkRRect& outer, const SkRRect& inner,
  22. const SkPaint& paint) override = 0;
  23. void onDrawOval(const SkRect& rect, const SkPaint& paint) override = 0;
  24. void onDrawArc(const SkRect& rect, SkScalar startAngle, SkScalar sweepAngle, bool useCenter,
  25. const SkPaint& paint) override = 0;
  26. void onDrawPath(const SkPath& path, const SkPaint& paint) override = 0;
  27. void onDrawRegion(const SkRegion& region, const SkPaint& paint) override = 0;
  28. void onDrawText(const void* text, size_t byteLength, SkScalar x, SkScalar y,
  29. const SkPaint& paint) override = 0;
  30. void onDrawPosText(const void* text, size_t byteLength, const SkPoint pos[],
  31. const SkPaint& paint) override = 0;
  32. void onDrawPosTextH(const void* text, size_t byteLength, const SkScalar xpos[],
  33. SkScalar constY, const SkPaint& paint) override = 0;
  34. void onDrawTextRSXform(const void* text, size_t byteLength, const SkRSXform xform[],
  35. const SkRect* cullRect, const SkPaint& paint) override = 0;
  36. void onDrawTextBlob(const SkTextBlob* blob, SkScalar x, SkScalar y,
  37. const SkPaint& paint) override = 0;
  38. void onDrawPatch(const SkPoint cubics[12], const SkColor colors[4],
  39. const SkPoint texCoords[4], SkBlendMode mode,
  40. const SkPaint& paint) override = 0;
  41. void onDrawPoints(SkCanvas::PointMode mode, size_t count, const SkPoint pts[],
  42. const SkPaint& paint) override = 0;
  43. void onDrawVerticesObject(const SkVertices*, const SkVertices::Bone bones[], int boneCount,
  44. SkBlendMode, const SkPaint&) override = 0;
  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. #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.
  56. void onDrawImageSet(const SkCanvas::ImageSetEntry[], int count, SkFilterQuality,
  57. SkBlendMode) override {};
  58. #else
  59. void onDrawImageSet(const SkCanvas::ImageSetEntry[], int count, SkFilterQuality,
  60. SkBlendMode) override = 0;
  61. #endif
  62. void onDrawBitmap(const SkBitmap& bitmap, SkScalar dx, SkScalar dy,
  63. const SkPaint* paint) override = 0;
  64. void onDrawBitmapRect(const SkBitmap& bitmap, const SkRect* src, const SkRect& dst,
  65. const SkPaint* paint,
  66. SkCanvas::SrcRectConstraint constraint) override = 0;
  67. void onDrawBitmapNine(const SkBitmap& bitmap, const SkIRect& center, const SkRect& dst,
  68. const SkPaint* paint) override = 0;
  69. void onDrawBitmapLattice(const SkBitmap& bitmap, const SkCanvas::Lattice& lattice,
  70. const SkRect& dst, const SkPaint* paint) override = 0;
  71. void onDrawAtlas(const SkImage* atlas, const SkRSXform xform[], const SkRect rect[],
  72. const SkColor colors[], int count, SkBlendMode mode, const SkRect* cull,
  73. const SkPaint* paint) override = 0;
  74. void onDrawAnnotation(const SkRect& rect, const char key[], SkData* value) override = 0;
  75. void onDrawShadowRec(const SkPath&, const SkDrawShadowRec&) override = 0;
  76. void onDrawDrawable(SkDrawable* drawable, const SkMatrix* matrix) override = 0;
  77. void onDrawPicture(const SkPicture* picture, const SkMatrix* matrix,
  78. const SkPaint* paint) override = 0;
  79. };
  80. #endif