blob: 9369f84ce6d81ef85a2322da933a51f2c4cce1e7 [file] [log] [blame]
edisonn@google.comac03d912013-07-22 15:36:39 +00001#ifndef EXPERIMENTAL_PDFVIEWER_SKTRACKDEVICE_H_
2#define EXPERIMENTAL_PDFVIEWER_SKTRACKDEVICE_H_
3
4#include "SkDevice.h"
5#include "SkTracker.h"
6
7class SkTrackDevice : public SkDevice {
8public:
9 SK_DECLARE_INST_COUNT(SkTrackDevice)
10
11 SkTrackDevice(const SkBitmap& bitmap) : SkDevice(bitmap)
12 , fTracker(NULL) {}
13
14 SkTrackDevice(const SkBitmap& bitmap, const SkDeviceProperties& deviceProperties)
15 : SkDevice(bitmap, deviceProperties)
16 , fTracker(NULL) {}
17
18 SkTrackDevice(SkBitmap::Config config, int width, int height, bool isOpaque = false)
19 : SkDevice(config, width, height, isOpaque)
20 , fTracker(NULL) {}
21
22 SkTrackDevice(SkBitmap::Config config, int width, int height, bool isOpaque,
23 const SkDeviceProperties& deviceProperties)
24 : SkDevice(config, width, height, isOpaque, deviceProperties)
25 , fTracker(NULL) {}
26
27 virtual ~SkTrackDevice() {}
28
29 void installTracker(SkTracker* tracker) {
30 fTracker = tracker;
31 fTracker->newFrame();
32 }
33
34protected:
35 virtual void clear(SkColor color) {
36 before();
37 INHERITED::clear(color);
38 after();
39 }
40
41 virtual void drawPaint(const SkDraw& dummy1, const SkPaint& paint) {
42 before();
43 INHERITED::drawPaint(dummy1, paint);
44 after();
45 }
46
47 virtual void drawPoints(const SkDraw& dummy1, SkCanvas::PointMode mode, size_t count,
48 const SkPoint dummy2[], const SkPaint& paint) {
49 before();
50 INHERITED::drawPoints(dummy1, mode, count, dummy2, paint);
51 after();
52 }
53
54 virtual void drawRect(const SkDraw& dummy1, const SkRect& r,
55 const SkPaint& paint) {
56 before();
57 INHERITED::drawRect(dummy1, r, paint);
58 after();
59 }
60
61
62 virtual void drawOval(const SkDraw& dummy1, const SkRect& oval,
63 const SkPaint& paint) {
64 before();
65 INHERITED::drawOval(dummy1, oval, paint);
66 after();
67 }
68
69 virtual void drawRRect(const SkDraw& dummy1, const SkRRect& rr,
70 const SkPaint& paint) {
71 before();
72 INHERITED::drawRRect(dummy1, rr, paint);
73 after();
74 }
75
76 virtual void drawPath(const SkDraw& dummy1, const SkPath& path,
77 const SkPaint& paint,
78 const SkMatrix* prePathMatrix = NULL,
79 bool pathIsMutable = false) {
80 before();
81 INHERITED::drawPath(dummy1, path, paint, prePathMatrix, pathIsMutable);
82 after();
83 }
84
85 virtual void drawBitmap(const SkDraw& dummy1, const SkBitmap& bitmap,
edisonn@google.comac03d912013-07-22 15:36:39 +000086 const SkMatrix& matrix, const SkPaint& paint) {
87 before();
edisonn@google.com50bbdb42013-07-25 15:33:13 +000088 INHERITED::drawBitmap(dummy1, bitmap, matrix, paint);
edisonn@google.comac03d912013-07-22 15:36:39 +000089 after();
90 }
91
92 virtual void drawSprite(const SkDraw& dummy1, const SkBitmap& bitmap,
93 int x, int y, const SkPaint& paint) {
94 before();
95 INHERITED::drawSprite(dummy1, bitmap, x, y, paint);
96 after();
97 }
98
99 virtual void drawBitmapRect(const SkDraw& dummy1, const SkBitmap& dummy2,
100 const SkRect* srcOrNull, const SkRect& dst,
101 const SkPaint& paint) {
102 before();
103 INHERITED::drawBitmapRect(dummy1, dummy2, srcOrNull, dst, paint);
104 after();
105 }
106
107 virtual void drawText(const SkDraw& dummy1, const void* text, size_t len,
108 SkScalar x, SkScalar y, const SkPaint& paint) {
109 before();
110 INHERITED::drawText(dummy1, text, len, x, y, paint);
111 after();
112 }
113
114 virtual void drawPosText(const SkDraw& dummy1, const void* text, size_t len,
115 const SkScalar pos[], SkScalar constY,
116 int scalarsPerPos, const SkPaint& paint) {
117 before();
118 INHERITED::drawPosText(dummy1, text, len, pos, constY, scalarsPerPos, paint);
119 after();
120 }
121
122 virtual void drawTextOnPath(const SkDraw& dummy1, const void* text, size_t len,
123 const SkPath& path, const SkMatrix* matrix,
124 const SkPaint& paint) {
125 before();
126 INHERITED::drawTextOnPath(dummy1, text, len, path, matrix, paint);
127 after();
128 }
129
130#ifdef SK_BUILD_FOR_ANDROID
131 virtual void drawPosTextOnPath(const SkDraw& draw, const void* text, size_t len,
132 const SkPoint pos[], const SkPaint& paint,
133 const SkPath& path, const SkMatrix* matrix) {
134 before();
135 INHERITED::drawPosTextOnPath(draw, text, len, pos, paint, path, matrix);
136 after();
137 }
138#endif
139 virtual void drawVertices(const SkDraw& dummy1, SkCanvas::VertexMode dummy2, int vertexCount,
140 const SkPoint verts[], const SkPoint texs[],
141 const SkColor colors[], SkXfermode* xmode,
142 const uint16_t indices[], int indexCount,
143 const SkPaint& paint) {
144 before();
145 INHERITED::drawVertices(dummy1, dummy2, vertexCount,verts, texs,colors, xmode, indices, indexCount, paint);
146 after();
147 }
148
149 virtual void drawDevice(const SkDraw& dummy1, SkDevice* dummy2, int x, int y,
150 const SkPaint& dummy3) {
151 before();
152 INHERITED::drawDevice(dummy1, dummy2, x, y, dummy3);
153 after();
154 }
155
156private:
157 void before() {
158 if (fTracker) {
159 fTracker->before(accessBitmap(false));
160 }
161 }
162
163 // any/all of the expected touched has to be changed, and all expected untouched must be intact
164 void after() {
165 if (fTracker) {
166 fTracker->after(accessBitmap(false));
167 }
168 }
169
170private:
171 SkTracker* fTracker;
172
173 typedef SkDevice INHERITED;
174};
175
176#endif // EXPERIMENTAL_PDFVIEWER_SKTRACKDEVICE_H_