| 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 |
|
| 8 |
#ifndef SkPaintFilterCanvas_DEFINED |
| 9 |
#define SkPaintFilterCanvas_DEFINED |
| 10 |
|
| 11 |
#include "include/core/SkCanvas.h" |
| 12 |
#include "include/core/SkCanvasVirtualEnforcer.h" |
| 13 |
#include "include/core/SkColor.h" |
| 14 |
#include "include/core/SkImageInfo.h" |
| 15 |
#include "include/core/SkRefCnt.h" |
| 16 |
#include "include/core/SkSamplingOptions.h" |
| 17 |
#include "include/core/SkScalar.h" |
| 18 |
#include "include/core/SkSize.h" |
| 19 |
#include "include/core/SkTypes.h" |
| 20 |
#include "include/private/base/SkTDArray.h" |
| 21 |
#include "include/utils/SkNWayCanvas.h" |
| 22 |
|
| 23 |
#include <cstddef> |
| 24 |
|
| 25 |
namespace sktext { |
| 26 |
class GlyphRunList; |
| 27 |
} |
| 28 |
|
| 29 |
class GrRecordingContext; |
| 30 |
class SkData; |
| 31 |
class SkDrawable; |
| 32 |
class SkImage; |
| 33 |
class SkMatrix; |
| 34 |
class SkPaint; |
| 35 |
class SkPath; |
| 36 |
class SkPicture; |
| 37 |
class SkPixmap; |
| 38 |
class SkRRect; |
| 39 |
class SkRegion; |
| 40 |
class SkSurface; |
| 41 |
class SkSurfaceProps; |
| 42 |
class SkTextBlob; |
| 43 |
class SkVertices; |
| 44 |
enum class SkBlendMode; |
| 45 |
struct SkDrawShadowRec; |
| 46 |
struct SkPoint; |
| 47 |
struct SkRSXform; |
| 48 |
struct SkRect; |
| 49 |
|
| 50 |
/** \class SkPaintFilterCanvas |
| 51 |
|
| 52 |
A utility proxy base class for implementing draw/paint filters. |
| 53 |
*/ |
| 54 |
class SK_API SkPaintFilterCanvas : public SkCanvasVirtualEnforcer<SkNWayCanvas> { |
| 55 |
public: |
| 56 |
/** |
| 57 |
* The new SkPaintFilterCanvas is configured for forwarding to the |
| 58 |
* specified canvas. Also copies the target canvas matrix and clip bounds. |
| 59 |
*/ |
| 60 |
explicit SkPaintFilterCanvas(SkCanvas* canvas); |
| 61 |
|
| 62 |
enum Type { |
| 63 |
kPicture_Type, |
| 64 |
}; |
| 65 |
|
| 66 |
// Forwarded to the wrapped canvas. |
| 67 |
SkISize getBaseLayerSize() const override { return proxy()->getBaseLayerSize(); } |
| 68 |
GrRecordingContext* recordingContext() const override { return proxy()->recordingContext(); } |
| 69 |
protected: |
| 70 |
/** |
| 71 |
* Called with the paint that will be used to draw the specified type. |
| 72 |
* The implementation may modify the paint as they wish. |
| 73 |
* |
| 74 |
* The result bool is used to determine whether the draw op is to be |
| 75 |
* executed (true) or skipped (false). |
| 76 |
* |
| 77 |
* Note: The base implementation calls onFilter() for top-level/explicit paints only. |
| 78 |
* To also filter encapsulated paints (e.g. SkPicture, SkTextBlob), clients may need to |
| 79 |
* override the relevant methods (i.e. drawPicture, drawTextBlob). |
| 80 |
*/ |
| 81 |
virtual bool onFilter(SkPaint& paint) const = 0; |
| 82 |
|
| 83 |
void onDrawPaint(const SkPaint&) override; |
| 84 |
void onDrawBehind(const SkPaint&) override; |
| 85 |
void onDrawPoints(PointMode, size_t count, const SkPoint pts[], const SkPaint&) override; |
| 86 |
void onDrawRect(const SkRect&, const SkPaint&) override; |
| 87 |
void onDrawRRect(const SkRRect&, const SkPaint&) override; |
| 88 |
void onDrawDRRect(const SkRRect&, const SkRRect&, const SkPaint&) override; |
| 89 |
void onDrawRegion(const SkRegion&, const SkPaint&) override; |
| 90 |
void onDrawOval(const SkRect&, const SkPaint&) override; |
| 91 |
void onDrawArc(const SkRect&, SkScalar, SkScalar, bool, const SkPaint&) override; |
| 92 |
void onDrawPath(const SkPath&, const SkPaint&) override; |
| 93 |
|
| 94 |
void onDrawImage2(const SkImage*, SkScalar, SkScalar, const SkSamplingOptions&, |
| 95 |
const SkPaint*) override; |
| 96 |
void onDrawImageRect2(const SkImage*, const SkRect&, const SkRect&, const SkSamplingOptions&, |
| 97 |
const SkPaint*, SrcRectConstraint) override; |
| 98 |
void onDrawImageLattice2(const SkImage*, const Lattice&, const SkRect&, SkFilterMode, |
| 99 |
const SkPaint*) override; |
| 100 |
void onDrawAtlas2(const SkImage*, const SkRSXform[], const SkRect[], const SkColor[], int, |
| 101 |
SkBlendMode, const SkSamplingOptions&, const SkRect*, const SkPaint*) override; |
| 102 |
|
| 103 |
void onDrawVerticesObject(const SkVertices*, SkBlendMode, const SkPaint&) override; |
| 104 |
void onDrawPatch(const SkPoint cubics[12], const SkColor colors[4], |
| 105 |
const SkPoint texCoords[4], SkBlendMode, |
| 106 |
const SkPaint& paint) override; |
| 107 |
void onDrawPicture(const SkPicture*, const SkMatrix*, const SkPaint*) override; |
| 108 |
void onDrawDrawable(SkDrawable*, const SkMatrix*) override; |
| 109 |
|
| 110 |
void onDrawGlyphRunList(const sktext::GlyphRunList&, const SkPaint&) override; |
| 111 |
void onDrawTextBlob(const SkTextBlob* blob, SkScalar x, SkScalar y, |
| 112 |
const SkPaint& paint) override; |
| 113 |
void onDrawAnnotation(const SkRect& rect, const char key[], SkData* value) override; |
| 114 |
void onDrawShadowRec(const SkPath& path, const SkDrawShadowRec& rec) override; |
| 115 |
|
| 116 |
void onDrawEdgeAAQuad(const SkRect&, const SkPoint[4], QuadAAFlags, const SkColor4f&, |
| 117 |
SkBlendMode) override; |
| 118 |
void onDrawEdgeAAImageSet2(const ImageSetEntry[], int count, const SkPoint[], const SkMatrix[], |
| 119 |
const SkSamplingOptions&,const SkPaint*, SrcRectConstraint) override; |
| 120 |
|
| 121 |
// Forwarded to the wrapped canvas. |
| 122 |
sk_sp<SkSurface> onNewSurface(const SkImageInfo&, const SkSurfaceProps&) override; |
| 123 |
bool onPeekPixels(SkPixmap* pixmap) override; |
| 124 |
bool onAccessTopLayerPixels(SkPixmap* pixmap) override; |
| 125 |
SkImageInfo onImageInfo() const override; |
| 126 |
bool onGetProps(SkSurfaceProps* props, bool top) const override; |
| 127 |
|
| 128 |
private: |
| 129 |
class AutoPaintFilter; |
| 130 |
|
| 131 |
SkCanvas* proxy() const { SkASSERT(fList.size() == 1); return fList[0]; } |
| 132 |
|
| 133 |
SkPaintFilterCanvas* internal_private_asPaintFilterCanvas() const override { |
| 134 |
return const_cast<SkPaintFilterCanvas*>(this); |
| 135 |
} |
| 136 |
|
| 137 |
friend class SkAndroidFrameworkUtils; |
| 138 |
}; |
| 139 |
|
| 140 |
#endif |