blob: 6f26121d18a2488e4eeafd5a9d43cfa25bc50a0a [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
robertphillips@google.com9b051a32013-08-20 20:06:40 +00007class SkTrackDevice : public SkDevice {
edisonn@google.comac03d912013-07-22 15:36:39 +00008public:
9 SK_DECLARE_INST_COUNT(SkTrackDevice)
10
robertphillips@google.com9b051a32013-08-20 20:06:40 +000011 SkTrackDevice(const SkBitmap& bitmap) : SkDevice(bitmap)
edisonn@google.comac03d912013-07-22 15:36:39 +000012 , fTracker(NULL) {}
13
14 SkTrackDevice(const SkBitmap& bitmap, const SkDeviceProperties& deviceProperties)
robertphillips@google.com9b051a32013-08-20 20:06:40 +000015 : SkDevice(bitmap, deviceProperties)
edisonn@google.comac03d912013-07-22 15:36:39 +000016 , fTracker(NULL) {}
17
18 SkTrackDevice(SkBitmap::Config config, int width, int height, bool isOpaque = false)
robertphillips@google.com9b051a32013-08-20 20:06:40 +000019 : SkDevice(config, width, height, isOpaque)
edisonn@google.comac03d912013-07-22 15:36:39 +000020 , fTracker(NULL) {}
21
22 SkTrackDevice(SkBitmap::Config config, int width, int height, bool isOpaque,
23 const SkDeviceProperties& deviceProperties)
robertphillips@google.com9b051a32013-08-20 20:06:40 +000024 : SkDevice(config, width, height, isOpaque, deviceProperties)
edisonn@google.comac03d912013-07-22 15:36:39 +000025 , 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,
edisonn@google.com2c817772013-08-16 16:30:02 +0000101 const SkPaint& paint,
102 SkCanvas::DrawBitmapRectFlags flags) {
edisonn@google.comac03d912013-07-22 15:36:39 +0000103 before();
edisonn@google.com2c817772013-08-16 16:30:02 +0000104 INHERITED::drawBitmapRect(dummy1, dummy2, srcOrNull, dst, paint, flags);
edisonn@google.comac03d912013-07-22 15:36:39 +0000105 after();
106 }
107
108 virtual void drawText(const SkDraw& dummy1, const void* text, size_t len,
109 SkScalar x, SkScalar y, const SkPaint& paint) {
110 before();
111 INHERITED::drawText(dummy1, text, len, x, y, paint);
112 after();
113 }
114
115 virtual void drawPosText(const SkDraw& dummy1, const void* text, size_t len,
116 const SkScalar pos[], SkScalar constY,
117 int scalarsPerPos, const SkPaint& paint) {
118 before();
119 INHERITED::drawPosText(dummy1, text, len, pos, constY, scalarsPerPos, paint);
120 after();
121 }
122
123 virtual void drawTextOnPath(const SkDraw& dummy1, const void* text, size_t len,
124 const SkPath& path, const SkMatrix* matrix,
125 const SkPaint& paint) {
126 before();
127 INHERITED::drawTextOnPath(dummy1, text, len, path, matrix, paint);
128 after();
129 }
130
131#ifdef SK_BUILD_FOR_ANDROID
132 virtual void drawPosTextOnPath(const SkDraw& draw, const void* text, size_t len,
133 const SkPoint pos[], const SkPaint& paint,
134 const SkPath& path, const SkMatrix* matrix) {
135 before();
136 INHERITED::drawPosTextOnPath(draw, text, len, pos, paint, path, matrix);
137 after();
138 }
139#endif
140 virtual void drawVertices(const SkDraw& dummy1, SkCanvas::VertexMode dummy2, int vertexCount,
141 const SkPoint verts[], const SkPoint texs[],
142 const SkColor colors[], SkXfermode* xmode,
143 const uint16_t indices[], int indexCount,
144 const SkPaint& paint) {
145 before();
146 INHERITED::drawVertices(dummy1, dummy2, vertexCount,verts, texs,colors, xmode, indices, indexCount, paint);
147 after();
148 }
149
robertphillips@google.com9b051a32013-08-20 20:06:40 +0000150 virtual void drawDevice(const SkDraw& dummy1, SkDevice* dummy2, int x, int y,
edisonn@google.comac03d912013-07-22 15:36:39 +0000151 const SkPaint& dummy3) {
152 before();
153 INHERITED::drawDevice(dummy1, dummy2, x, y, dummy3);
154 after();
155 }
156
157private:
158 void before() {
159 if (fTracker) {
160 fTracker->before(accessBitmap(false));
161 }
162 }
163
164 // any/all of the expected touched has to be changed, and all expected untouched must be intact
165 void after() {
166 if (fTracker) {
167 fTracker->after(accessBitmap(false));
168 }
169 }
170
171private:
172 SkTracker* fTracker;
173
robertphillips@google.com9b051a32013-08-20 20:06:40 +0000174 typedef SkDevice INHERITED;
edisonn@google.comac03d912013-07-22 15:36:39 +0000175};
176
177#endif // EXPERIMENTAL_PDFVIEWER_SKTRACKDEVICE_H_