1/*
2 * Copyright 2016 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 SkNoDrawCanvas_DEFINED
9#define SkNoDrawCanvas_DEFINED
10
11#include "include/core/SkBlurTypes.h"
12#include "include/core/SkCanvas.h"
13#include "include/core/SkCanvasVirtualEnforcer.h"
14
15struct SkIRect;
16
17// SkNoDrawCanvas is a helper for SkCanvas subclasses which do not need to
18// actually rasterize (e.g., analysis of the draw calls).
19//
20// It provides the following simplifications:
21//
22//   * not backed by any device/pixels
23//   * conservative clipping (clipping calls only use rectangles)
24//
25class SK_API SkNoDrawCanvas : public SkCanvasVirtualEnforcer<SkCanvas> {
26public:
27    SkNoDrawCanvas(int width, int height);
28    SkNoDrawCanvas(const SkIRect&);
29
30    explicit SkNoDrawCanvas(sk_sp<SkBaseDevice> device);
31
32    // Optimization to reset state to be the same as after construction.
33    void resetCanvas(int w, int h)        { this->resetForNextPicture(SkIRect::MakeWH(w, h)); }
34    void resetCanvas(const SkIRect& rect) { this->resetForNextPicture(rect); }
35
36protected:
37    SaveLayerStrategy getSaveLayerStrategy(const SaveLayerRec& rec) override;
38    bool onDoSaveBehind(const SkRect*) override;
39
40    // No-op overrides for aborting rasterization earlier than SkNullBlitter.
41    void onDrawAnnotation(const SkRect&, const char[], SkData*) override {}
42    void onDrawDRRect(const SkRRect&, const SkRRect&, const SkPaint&) override {}
43    void onDrawDrawable(SkDrawable*, const SkMatrix*) override {}
44    void onDrawTextBlob(const SkTextBlob*, SkScalar, SkScalar, const SkPaint&) override {}
45    void onDrawPatch(const SkPoint[12], const SkColor[4], const SkPoint[4], SkBlendMode,
46                     const SkPaint&) override {}
47
48    void onDrawPaint(const SkPaint&) override {}
49    void onDrawBehind(const SkPaint&) override {}
50    void onDrawPoints(PointMode, size_t, const SkPoint[], const SkPaint&) override {}
51    void onDrawRect(const SkRect&, const SkPaint&) override {}
52    void onDrawRegion(const SkRegion&, const SkPaint&) override {}
53    void onDrawOval(const SkRect&, const SkPaint&) override {}
54    void onDrawArc(const SkRect&, SkScalar, SkScalar, bool, const SkPaint&) override {}
55    void onDrawRRect(const SkRRect&, const SkPaint&) override {}
56    void onDrawPath(const SkPath&, const SkPaint&) override {}
57
58    void onDrawImage2(const SkImage*, SkScalar, SkScalar, const SkSamplingOptions&,
59                      const SkPaint*) override {}
60    void onDrawImageRect2(const SkImage*, const SkRect&, const SkRect&, const SkSamplingOptions&,
61                          const SkPaint*, SrcRectConstraint) override {}
62    void onDrawImageLattice2(const SkImage*, const Lattice&, const SkRect&, SkFilterMode,
63                             const SkPaint*) override {}
64    void onDrawAtlas2(const SkImage*, const SkRSXform[], const SkRect[], const SkColor[], int,
65                  SkBlendMode, const SkSamplingOptions&, const SkRect*, const SkPaint*) override {}
66
67    void onDrawVerticesObject(const SkVertices*, SkBlendMode, const SkPaint&) override {}
68    void onDrawShadowRec(const SkPath&, const SkDrawShadowRec&) override {}
69    void onDrawPicture(const SkPicture*, const SkMatrix*, const SkPaint*) override {}
70
71    void onDrawEdgeAAQuad(const SkRect&, const SkPoint[4], QuadAAFlags, const SkColor4f&,
72                          SkBlendMode) override {}
73    void onDrawEdgeAAImageSet2(const ImageSetEntry[], int, const SkPoint[], const SkMatrix[],
74                               const SkSamplingOptions&, const SkPaint*,
75                               SrcRectConstraint) override {}
76
77    bool onDrawBlurImage(const SkImage* image, const SkBlurArg& blurArg) override { return false; }
78
79private:
80    using INHERITED = SkCanvasVirtualEnforcer<SkCanvas>;
81};
82
83#endif // SkNoDrawCanvas_DEFINED
84