SkPaintFilterCanvas.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /*
  2. * Copyright 2015 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 SkPaintFilterCanvas_DEFINED
  8. #define SkPaintFilterCanvas_DEFINED
  9. #include "include/core/SkCanvasVirtualEnforcer.h"
  10. #include "include/utils/SkNWayCanvas.h"
  11. class SkAndroidFrameworkUtils;
  12. /** \class SkPaintFilterCanvas
  13. A utility proxy base class for implementing draw/paint filters.
  14. */
  15. class SK_API SkPaintFilterCanvas : public SkCanvasVirtualEnforcer<SkNWayCanvas> {
  16. public:
  17. /**
  18. * The new SkPaintFilterCanvas is configured for forwarding to the
  19. * specified canvas. Also copies the target canvas matrix and clip bounds.
  20. */
  21. SkPaintFilterCanvas(SkCanvas* canvas);
  22. enum Type {
  23. kPicture_Type,
  24. };
  25. // Forwarded to the wrapped canvas.
  26. SkISize getBaseLayerSize() const override { return proxy()->getBaseLayerSize(); }
  27. GrContext* getGrContext() override { return proxy()->getGrContext(); }
  28. GrRenderTargetContext* internal_private_accessTopLayerRenderTargetContext() override {
  29. return proxy()->internal_private_accessTopLayerRenderTargetContext();
  30. }
  31. protected:
  32. /**
  33. * Called with the paint that will be used to draw the specified type.
  34. * The implementation may modify the paint as they wish.
  35. *
  36. * The result bool is used to determine whether the draw op is to be
  37. * executed (true) or skipped (false).
  38. *
  39. * Note: The base implementation calls onFilter() for top-level/explicit paints only.
  40. * To also filter encapsulated paints (e.g. SkPicture, SkTextBlob), clients may need to
  41. * override the relevant methods (i.e. drawPicture, drawTextBlob).
  42. */
  43. virtual bool onFilter(SkPaint& paint) const = 0;
  44. void onDrawPaint(const SkPaint&) override;
  45. void onDrawBehind(const SkPaint&) override;
  46. void onDrawPoints(PointMode, size_t count, const SkPoint pts[], const SkPaint&) override;
  47. void onDrawRect(const SkRect&, const SkPaint&) override;
  48. void onDrawRRect(const SkRRect&, const SkPaint&) override;
  49. void onDrawDRRect(const SkRRect&, const SkRRect&, const SkPaint&) override;
  50. void onDrawRegion(const SkRegion&, const SkPaint&) override;
  51. void onDrawOval(const SkRect&, const SkPaint&) override;
  52. void onDrawArc(const SkRect&, SkScalar, SkScalar, bool, const SkPaint&) override;
  53. void onDrawPath(const SkPath&, const SkPaint&) override;
  54. void onDrawBitmap(const SkBitmap&, SkScalar left, SkScalar top, const SkPaint*) override;
  55. void onDrawBitmapRect(const SkBitmap&, const SkRect* src, const SkRect& dst, const SkPaint*,
  56. SrcRectConstraint) override;
  57. void onDrawBitmapNine(const SkBitmap&, const SkIRect& center, const SkRect& dst,
  58. const SkPaint*) override;
  59. void onDrawBitmapLattice(const SkBitmap&, const Lattice&, const SkRect&,
  60. const SkPaint*) override;
  61. void onDrawImage(const SkImage*, SkScalar left, SkScalar top, const SkPaint*) override;
  62. void onDrawImageRect(const SkImage*, const SkRect* src, const SkRect& dst,
  63. const SkPaint*, SrcRectConstraint) override;
  64. void onDrawImageNine(const SkImage*, const SkIRect& center, const SkRect& dst,
  65. const SkPaint*) override;
  66. void onDrawImageLattice(const SkImage*, const Lattice&, const SkRect&,
  67. const SkPaint*) override;
  68. void onDrawVerticesObject(const SkVertices*, const SkVertices::Bone bones[], int boneCount,
  69. SkBlendMode, const SkPaint&) override;
  70. void onDrawPatch(const SkPoint cubics[12], const SkColor colors[4],
  71. const SkPoint texCoords[4], SkBlendMode,
  72. const SkPaint& paint) override;
  73. void onDrawPicture(const SkPicture*, const SkMatrix*, const SkPaint*) override;
  74. void onDrawDrawable(SkDrawable*, const SkMatrix*) override;
  75. void onDrawTextBlob(const SkTextBlob* blob, SkScalar x, SkScalar y,
  76. const SkPaint& paint) override;
  77. void onDrawAtlas(const SkImage*, const SkRSXform[], const SkRect[], const SkColor[],
  78. int, SkBlendMode, const SkRect*, const SkPaint*) override;
  79. void onDrawAnnotation(const SkRect& rect, const char key[], SkData* value) override;
  80. void onDrawShadowRec(const SkPath& path, const SkDrawShadowRec& rec) override;
  81. void onDrawEdgeAAQuad(const SkRect&, const SkPoint[4], QuadAAFlags, SkColor,
  82. SkBlendMode) override;
  83. void onDrawEdgeAAImageSet(const ImageSetEntry[], int count, const SkPoint[], const SkMatrix[],
  84. const SkPaint*, SrcRectConstraint) override;
  85. // Forwarded to the wrapped canvas.
  86. sk_sp<SkSurface> onNewSurface(const SkImageInfo&, const SkSurfaceProps&) override;
  87. bool onPeekPixels(SkPixmap* pixmap) override;
  88. bool onAccessTopLayerPixels(SkPixmap* pixmap) override;
  89. SkImageInfo onImageInfo() const override;
  90. bool onGetProps(SkSurfaceProps* props) const override;
  91. private:
  92. class AutoPaintFilter;
  93. SkCanvas* proxy() const { SkASSERT(fList.count() == 1); return fList[0]; }
  94. SkPaintFilterCanvas* internal_private_asPaintFilterCanvas() const override {
  95. return const_cast<SkPaintFilterCanvas*>(this);
  96. }
  97. friend class SkAndroidFrameworkUtils;
  98. };
  99. #endif