aboutsummaryrefslogtreecommitdiffhomepage
path: root/experimental/PdfViewer/SkTrackDevice.h
blob: e3e78e309769c3582e4d8f2f8b9c0127da540507 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
/*
 * Copyright 2013 Google Inc.
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#ifndef SkTrackDevice_DEFINED
#define SkTrackDevice_DEFINED

#include "SkBitmapDevice.h"
#include "SkTracker.h"

/** \class SkTrackDevice
 *
 *   A Track Device is used to track the callstack of an operation that affected some pixels.
 *   It can be used with SampleApp to investigate bugs (CL not checked in yet).
 *
 *   every drawFoo is implemented as such:
 *      before();   // - collects state of interesting pixels
 *      INHERITED::drawFoo(...);
 *      after();  // - checks if pixels of interest, and issue a breakpoint.
 *
 */
// TODO: can this be derived from SkBaseDevice instead?
class SkTrackDevice : public SkBitmapDevice {
public:
    SK_DECLARE_INST_COUNT(SkTrackDevice)

    SkTrackDevice(const SkBitmap& bitmap)
        : INHERITED(bitmap, SkSurfaceProps(0, kUnknown_SkPixelGeometry))
        , fTracker(NULL) {
    }

    virtual ~SkTrackDevice() {}

    // Install a tracker - we can reuse the tracker between multiple devices, and the state of the
    // tracker is preserved - number and location of poinbts, ...
    void installTracker(SkTracker* tracker) {
        fTracker = tracker;
        fTracker->newFrame();
    }

protected:
#if 0   // clear is deprecated (and private)
    virtual void clear(SkColor color) {
        before();
        INHERITED::clear(color);
        after();
    }
#endif

    virtual void drawPaint(const SkDraw& dummy1, const SkPaint& paint) {
        before();
        INHERITED::drawPaint(dummy1, paint);
        after();
    }

    virtual void drawPoints(const SkDraw& dummy1, SkCanvas::PointMode mode, size_t count,
                            const SkPoint dummy2[], const SkPaint& paint) {
        before();
        INHERITED::drawPoints(dummy1, mode, count, dummy2, paint);
        after();
    }

    virtual void drawRect(const SkDraw& dummy1, const SkRect& r,
                          const SkPaint& paint) {
        before();
        INHERITED::drawRect(dummy1, r, paint);
        after();
    }


    virtual void drawOval(const SkDraw& dummy1, const SkRect& oval,
                          const SkPaint& paint) {
        before();
        INHERITED::drawOval(dummy1, oval, paint);
        after();
    }

    virtual void drawRRect(const SkDraw& dummy1, const SkRRect& rr,
                           const SkPaint& paint) {
        before();
        INHERITED::drawRRect(dummy1, rr, paint);
        after();
    }

    virtual void drawPath(const SkDraw& dummy1, const SkPath& path,
                          const SkPaint& paint,
                          const SkMatrix* prePathMatrix = NULL,
                          bool pathIsMutable = false) {
        before();
        INHERITED::drawPath(dummy1, path, paint, prePathMatrix, pathIsMutable);
        after();
    }

    virtual void drawBitmap(const SkDraw& dummy1, const SkBitmap& bitmap,
                            const SkMatrix& matrix, const SkPaint& paint) {
        before();
        INHERITED::drawBitmap(dummy1, bitmap, matrix, paint);
        after();
    }

    virtual void drawSprite(const SkDraw& dummy1, const SkBitmap& bitmap,
                            int x, int y, const SkPaint& paint) {
        before();
        INHERITED::drawSprite(dummy1, bitmap, x, y, paint);
        after();
    }

    virtual void drawBitmapRect(const SkDraw& dummy1, const SkBitmap& dummy2,
                                const SkRect* srcOrNull, const SkRect& dst,
                                const SkPaint& paint,
                                SkCanvas::DrawBitmapRectFlags flags) {
        before();
        INHERITED::drawBitmapRect(dummy1, dummy2, srcOrNull, dst, paint, flags);
        after();
    }

    virtual void drawText(const SkDraw& dummy1, const void* text, size_t len,
                          SkScalar x, SkScalar y, const SkPaint& paint) {
        before();
        INHERITED::drawText(dummy1, text, len, x, y, paint);
        after();
    }

    virtual void drawPosText(const SkDraw& dummy1, const void* text, size_t len,
                             const SkScalar pos[], int scalarsPerPos,
                             const SkPoint& offset, const SkPaint& paint) {
        before();
        INHERITED::drawPosText(dummy1, text, len, pos, scalarsPerPos, offset, paint);
        after();
    }

    virtual void drawTextOnPath(const SkDraw& dummy1, const void* text, size_t len,
                                const SkPath& path, const SkMatrix* matrix,
                                const SkPaint& paint)  {
        before();
        INHERITED::drawTextOnPath(dummy1, text, len, path, matrix, paint);
        after();
    }

    virtual void drawVertices(const SkDraw& dummy1, SkCanvas::VertexMode dummy2, int vertexCount,
                              const SkPoint verts[], const SkPoint texs[],
                              const SkColor colors[], SkXfermode* xmode,
                              const uint16_t indices[], int indexCount,
                              const SkPaint& paint) {
        before();
        INHERITED::drawVertices(dummy1, dummy2, vertexCount,verts, texs,colors, xmode, indices,
                                indexCount, paint);
        after();
    }

    virtual void drawDevice(const SkDraw& dummy1, SkBaseDevice* dummy2, int x, int y,
                            const SkPaint& dummy3) {
        before();
        INHERITED::drawDevice(dummy1, dummy2, x, y, dummy3);
        after();
    }

private:
    void before() {
        if (fTracker) {
            fTracker->before(accessBitmap(false));
        }
    }

    // any/all of the expected touched has to be changed, and all expected untouched must be intact
    void after() {
        if (fTracker) {
            fTracker->after(accessBitmap(false));
        }
    }

private:
    SkTracker* fTracker;

    typedef SkBitmapDevice INHERITED;
};

#endif  // SkTrackDevice_DEFINED