blob: 6018fcd30cc0670d22aa2d3b707bb0ef4a16a3f3 [file] [log] [blame]
edisonn@google.comcf2cfa12013-08-21 16:31:37 +00001/*
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 SkTrackDevice_DEFINED
9#define SkTrackDevice_DEFINED
edisonn@google.comac03d912013-07-22 15:36:39 +000010
edisonn@google.come91260c2013-09-04 17:29:06 +000011#include "SkBitmapDevice.h"
edisonn@google.comac03d912013-07-22 15:36:39 +000012#include "SkTracker.h"
13
edisonn@google.com2af2ad92013-10-11 16:17:44 +000014/** \class SkTrackDevice
15 *
16 * A Track Device is used to track that callstack of an operation that affected some pixels.
17 * It can be used with SampleApp to investigate bugs (CL not checked in yet).
18 *
edisonn@google.comd03c2c72013-10-11 18:26:45 +000019 * every drawFoo is implemented as such:
20 * before(); // - collects state of interesting pixels
21 * INHERITED::drawFoo(...);
22 * after(); // - checks if pixels of interest, and issue a breakpoint.
23 *
edisonn@google.com2af2ad92013-10-11 16:17:44 +000024 */
robertphillips@google.com1f2f3382013-08-29 11:54:56 +000025class SkTrackDevice : public SkBitmapDevice {
edisonn@google.comac03d912013-07-22 15:36:39 +000026public:
27 SK_DECLARE_INST_COUNT(SkTrackDevice)
28
robertphillips@google.com1f2f3382013-08-29 11:54:56 +000029 SkTrackDevice(const SkBitmap& bitmap) : SkBitmapDevice(bitmap)
edisonn@google.comac03d912013-07-22 15:36:39 +000030 , fTracker(NULL) {}
31
32 SkTrackDevice(const SkBitmap& bitmap, const SkDeviceProperties& deviceProperties)
robertphillips@google.com1f2f3382013-08-29 11:54:56 +000033 : SkBitmapDevice(bitmap, deviceProperties)
edisonn@google.comac03d912013-07-22 15:36:39 +000034 , fTracker(NULL) {}
35
36 SkTrackDevice(SkBitmap::Config config, int width, int height, bool isOpaque = false)
robertphillips@google.com1f2f3382013-08-29 11:54:56 +000037 : SkBitmapDevice(config, width, height, isOpaque)
edisonn@google.comac03d912013-07-22 15:36:39 +000038 , fTracker(NULL) {}
39
40 SkTrackDevice(SkBitmap::Config config, int width, int height, bool isOpaque,
41 const SkDeviceProperties& deviceProperties)
robertphillips@google.com1f2f3382013-08-29 11:54:56 +000042 : SkBitmapDevice(config, width, height, isOpaque, deviceProperties)
edisonn@google.comac03d912013-07-22 15:36:39 +000043 , fTracker(NULL) {}
44
45 virtual ~SkTrackDevice() {}
46
edisonn@google.comd03c2c72013-10-11 18:26:45 +000047 // Install a tracker - we can reuse the tracker between multiple devices, and the state of the
48 // tracker is preserved - number and location of poinbts, ...
edisonn@google.comac03d912013-07-22 15:36:39 +000049 void installTracker(SkTracker* tracker) {
50 fTracker = tracker;
51 fTracker->newFrame();
52 }
53
54protected:
55 virtual void clear(SkColor color) {
56 before();
57 INHERITED::clear(color);
58 after();
59 }
60
61 virtual void drawPaint(const SkDraw& dummy1, const SkPaint& paint) {
62 before();
63 INHERITED::drawPaint(dummy1, paint);
64 after();
65 }
66
67 virtual void drawPoints(const SkDraw& dummy1, SkCanvas::PointMode mode, size_t count,
68 const SkPoint dummy2[], const SkPaint& paint) {
69 before();
70 INHERITED::drawPoints(dummy1, mode, count, dummy2, paint);
71 after();
72 }
73
74 virtual void drawRect(const SkDraw& dummy1, const SkRect& r,
75 const SkPaint& paint) {
76 before();
77 INHERITED::drawRect(dummy1, r, paint);
78 after();
79 }
80
81
82 virtual void drawOval(const SkDraw& dummy1, const SkRect& oval,
83 const SkPaint& paint) {
84 before();
85 INHERITED::drawOval(dummy1, oval, paint);
86 after();
87 }
88
89 virtual void drawRRect(const SkDraw& dummy1, const SkRRect& rr,
90 const SkPaint& paint) {
91 before();
92 INHERITED::drawRRect(dummy1, rr, paint);
93 after();
94 }
95
96 virtual void drawPath(const SkDraw& dummy1, const SkPath& path,
97 const SkPaint& paint,
98 const SkMatrix* prePathMatrix = NULL,
99 bool pathIsMutable = false) {
100 before();
101 INHERITED::drawPath(dummy1, path, paint, prePathMatrix, pathIsMutable);
102 after();
103 }
104
105 virtual void drawBitmap(const SkDraw& dummy1, const SkBitmap& bitmap,
edisonn@google.comac03d912013-07-22 15:36:39 +0000106 const SkMatrix& matrix, const SkPaint& paint) {
107 before();
edisonn@google.com50bbdb42013-07-25 15:33:13 +0000108 INHERITED::drawBitmap(dummy1, bitmap, matrix, paint);
edisonn@google.comac03d912013-07-22 15:36:39 +0000109 after();
110 }
111
112 virtual void drawSprite(const SkDraw& dummy1, const SkBitmap& bitmap,
113 int x, int y, const SkPaint& paint) {
114 before();
115 INHERITED::drawSprite(dummy1, bitmap, x, y, paint);
116 after();
117 }
118
119 virtual void drawBitmapRect(const SkDraw& dummy1, const SkBitmap& dummy2,
120 const SkRect* srcOrNull, const SkRect& dst,
edisonn@google.com2c817772013-08-16 16:30:02 +0000121 const SkPaint& paint,
122 SkCanvas::DrawBitmapRectFlags flags) {
edisonn@google.comac03d912013-07-22 15:36:39 +0000123 before();
edisonn@google.com2c817772013-08-16 16:30:02 +0000124 INHERITED::drawBitmapRect(dummy1, dummy2, srcOrNull, dst, paint, flags);
edisonn@google.comac03d912013-07-22 15:36:39 +0000125 after();
126 }
127
128 virtual void drawText(const SkDraw& dummy1, const void* text, size_t len,
129 SkScalar x, SkScalar y, const SkPaint& paint) {
130 before();
131 INHERITED::drawText(dummy1, text, len, x, y, paint);
132 after();
133 }
134
135 virtual void drawPosText(const SkDraw& dummy1, const void* text, size_t len,
136 const SkScalar pos[], SkScalar constY,
137 int scalarsPerPos, const SkPaint& paint) {
138 before();
139 INHERITED::drawPosText(dummy1, text, len, pos, constY, scalarsPerPos, paint);
140 after();
141 }
142
143 virtual void drawTextOnPath(const SkDraw& dummy1, const void* text, size_t len,
144 const SkPath& path, const SkMatrix* matrix,
145 const SkPaint& paint) {
146 before();
147 INHERITED::drawTextOnPath(dummy1, text, len, path, matrix, paint);
148 after();
149 }
150
151#ifdef SK_BUILD_FOR_ANDROID
152 virtual void drawPosTextOnPath(const SkDraw& draw, const void* text, size_t len,
153 const SkPoint pos[], const SkPaint& paint,
154 const SkPath& path, const SkMatrix* matrix) {
155 before();
156 INHERITED::drawPosTextOnPath(draw, text, len, pos, paint, path, matrix);
157 after();
158 }
159#endif
160 virtual void drawVertices(const SkDraw& dummy1, SkCanvas::VertexMode dummy2, int vertexCount,
161 const SkPoint verts[], const SkPoint texs[],
162 const SkColor colors[], SkXfermode* xmode,
163 const uint16_t indices[], int indexCount,
164 const SkPaint& paint) {
165 before();
edisonn@google.come50d9a12013-10-10 20:58:22 +0000166 INHERITED::drawVertices(dummy1, dummy2, vertexCount,verts, texs,colors, xmode, indices,
167 indexCount, paint);
edisonn@google.comac03d912013-07-22 15:36:39 +0000168 after();
169 }
170
robertphillips@google.com1f2f3382013-08-29 11:54:56 +0000171 virtual void drawDevice(const SkDraw& dummy1, SkBaseDevice* dummy2, int x, int y,
edisonn@google.comac03d912013-07-22 15:36:39 +0000172 const SkPaint& dummy3) {
173 before();
174 INHERITED::drawDevice(dummy1, dummy2, x, y, dummy3);
175 after();
176 }
177
178private:
179 void before() {
180 if (fTracker) {
181 fTracker->before(accessBitmap(false));
182 }
183 }
184
185 // any/all of the expected touched has to be changed, and all expected untouched must be intact
186 void after() {
187 if (fTracker) {
188 fTracker->after(accessBitmap(false));
189 }
190 }
191
192private:
193 SkTracker* fTracker;
194
robertphillips@google.com1f2f3382013-08-29 11:54:56 +0000195 typedef SkBitmapDevice INHERITED;
edisonn@google.comac03d912013-07-22 15:36:39 +0000196};
197
edisonn@google.comcf2cfa12013-08-21 16:31:37 +0000198#endif // SkTrackDevice_DEFINED