1/*
2 * Copyright 2013 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 SkNulCanvas_DEFINED
9#define SkNulCanvas_DEFINED
10
11#include "SkCanvas.h"
12
13/** \class SkNulCanvas
14 *
15 *   Nul Canvas is a canvas that does nothing. It is used to measure the perf of just parsing
16 *   a pdf, without actually rendering anything.
17 *
18 */
19class SK_API SkNulCanvas : public SkCanvas {
20public:
21    SK_DECLARE_INST_COUNT(SkNulCanvas);
22
23    SkNulCanvas() {}
24    explicit SkNulCanvas(SkBaseDevice* device) : SkCanvas(device) {}
25
26    explicit SkNulCanvas(const SkBitmap& bitmap) : SkCanvas(bitmap) {}
27    virtual ~SkNulCanvas() {}
28
29    void beginCommentGroup(const char* description) override {}
30    void addComment(const char* kywd, const char* value) override {}
31    void endCommentGroup() override {}
32    SkDrawFilter* setDrawFilter(SkDrawFilter* filter) override {return NULL;}
33
34    bool isClipEmpty() const override { return false; }
35    bool getClipBounds(SkRect* bounds) const override {
36        if (NULL != bounds) {
37            bounds->setXYWH(0, 0,
38                            SkIntToScalar(this->imageInfo().width()),
39                            SkIntToScalar(this->imageInfo().height()));
40        }
41        return true;
42    }
43    bool getClipDeviceBounds(SkIRect* bounds) const override {
44        if (NULL != bounds) {
45            bounds->setLargest();
46        }
47        return true;
48    }
49
50protected:
51    virtual SkCanvas* canvasForDrawIter() {return NULL;}
52    virtual SkBaseDevice* setDevice(SkBaseDevice* device) {return NULL;}
53
54    virtual SaveLayerStrategy willSaveLayer(const SkRect* bounds, const SkPaint* paint,
55                                            SaveFlags flags) override {
56        this->INHERITED::willSaveLayer(bounds, paint, flags);
57        return kNoLayer_SaveLayerStrategy;
58    }
59
60    virtual void onDrawText(const void* text, size_t byteLength, SkScalar x,
61                          SkScalar y, const SkPaint& paint) override {}
62    virtual void onDrawPosText(const void* text, size_t byteLength,
63                             const SkPoint pos[], const SkPaint& paint) override {}
64    virtual void onDrawPosTextH(const void* text, size_t byteLength,
65                              const SkScalar xpos[], SkScalar constY,
66                              const SkPaint& paint) override {}
67    virtual void onDrawTextOnPath(const void* text, size_t byteLength,
68                                const SkPath& path, const SkMatrix* matrix,
69                                const SkPaint& paint) override {}
70
71    void onClipRect(const SkRect&, SkRegion::Op, ClipEdgeStyle) override {}
72    void onClipRRect(const SkRRect&, SkRegion::Op, ClipEdgeStyle) override {}
73    void onClipPath(const SkPath&, SkRegion::Op, ClipEdgeStyle) override {}
74    void onClipRegion(const SkRegion&, SkRegion::Op)  override {}
75
76    void onDrawPicture(const SkPicture*, const SkMatrix*, const SkPaint*) override {}
77
78    void onDrawPaint(const SkPaint& paint) override {}
79    void onDrawPoints(PointMode mode, size_t count, const SkPoint pts[],
80                      const SkPaint& paint) override {}
81    void onDrawRect(const SkRect& rect, const SkPaint& paint) override {}
82    void onDrawOval(const SkRect& oval, const SkPaint&) override {}
83    void onDrawRRect(const SkRRect& rrect, const SkPaint& paint) override {}
84    void onDrawPath(const SkPath& path, const SkPaint& paint) override {}
85    void onDrawBitmap(const SkBitmap& bitmap, SkScalar left, SkScalar top,
86                      const SkPaint* paint = NULL) override {}
87    void onDrawBitmapRect(const SkBitmap& bitmap, const SkRect* src,
88                          const SkRect& dst,
89                          const SkPaint* paint,
90                          DrawBitmapRectFlags flags) override {}
91    void onDrawImage(const SkImage*, SkScalar left, SkScalar top, const SkPaint*) override {}
92    void onDrawImageRect(const SkImage*, const SkRect* src, const SkRect& dst,
93                         const SkPaint*) override{}
94    void onDrawBitmapNine(const SkBitmap& bitmap, const SkIRect& center,
95                          const SkRect& dst, const SkPaint* paint = NULL) override {}
96    void onDrawSprite(const SkBitmap& bitmap, int left, int top,
97                      const SkPaint* paint = NULL) override {}
98    void onDrawVertices(VertexMode vmode, int vertexCount,
99                        const SkPoint vertices[], const SkPoint texs[],
100                        const SkColor colors[], SkXfermode* xmode,
101                        const uint16_t indices[], int indexCount,
102                        const SkPaint& paint) override {}
103
104
105private:
106    typedef SkCanvas INHERITED;
107};
108
109#endif  // SkNulCanvas_DEFINED
110