blob: 25857f6635cc373f9a74d46f987e832155f72f39 [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
edisonn@google.comac03d912013-07-22 15:36:39 +000036 virtual ~SkTrackDevice() {}
37
edisonn@google.comd03c2c72013-10-11 18:26:45 +000038 // Install a tracker - we can reuse the tracker between multiple devices, and the state of the
39 // tracker is preserved - number and location of poinbts, ...
edisonn@google.comac03d912013-07-22 15:36:39 +000040 void installTracker(SkTracker* tracker) {
41 fTracker = tracker;
42 fTracker->newFrame();
43 }
44
45protected:
46 virtual void clear(SkColor color) {
47 before();
48 INHERITED::clear(color);
49 after();
50 }
51
52 virtual void drawPaint(const SkDraw& dummy1, const SkPaint& paint) {
53 before();
54 INHERITED::drawPaint(dummy1, paint);
55 after();
56 }
57
58 virtual void drawPoints(const SkDraw& dummy1, SkCanvas::PointMode mode, size_t count,
59 const SkPoint dummy2[], const SkPaint& paint) {
60 before();
61 INHERITED::drawPoints(dummy1, mode, count, dummy2, paint);
62 after();
63 }
64
65 virtual void drawRect(const SkDraw& dummy1, const SkRect& r,
66 const SkPaint& paint) {
67 before();
68 INHERITED::drawRect(dummy1, r, paint);
69 after();
70 }
71
72
73 virtual void drawOval(const SkDraw& dummy1, const SkRect& oval,
74 const SkPaint& paint) {
75 before();
76 INHERITED::drawOval(dummy1, oval, paint);
77 after();
78 }
79
80 virtual void drawRRect(const SkDraw& dummy1, const SkRRect& rr,
81 const SkPaint& paint) {
82 before();
83 INHERITED::drawRRect(dummy1, rr, paint);
84 after();
85 }
86
87 virtual void drawPath(const SkDraw& dummy1, const SkPath& path,
88 const SkPaint& paint,
89 const SkMatrix* prePathMatrix = NULL,
90 bool pathIsMutable = false) {
91 before();
92 INHERITED::drawPath(dummy1, path, paint, prePathMatrix, pathIsMutable);
93 after();
94 }
95
96 virtual void drawBitmap(const SkDraw& dummy1, const SkBitmap& bitmap,
edisonn@google.comac03d912013-07-22 15:36:39 +000097 const SkMatrix& matrix, const SkPaint& paint) {
98 before();
edisonn@google.com50bbdb42013-07-25 15:33:13 +000099 INHERITED::drawBitmap(dummy1, bitmap, matrix, paint);
edisonn@google.comac03d912013-07-22 15:36:39 +0000100 after();
101 }
102
103 virtual void drawSprite(const SkDraw& dummy1, const SkBitmap& bitmap,
104 int x, int y, const SkPaint& paint) {
105 before();
106 INHERITED::drawSprite(dummy1, bitmap, x, y, paint);
107 after();
108 }
109
110 virtual void drawBitmapRect(const SkDraw& dummy1, const SkBitmap& dummy2,
111 const SkRect* srcOrNull, const SkRect& dst,
edisonn@google.com2c817772013-08-16 16:30:02 +0000112 const SkPaint& paint,
113 SkCanvas::DrawBitmapRectFlags flags) {
edisonn@google.comac03d912013-07-22 15:36:39 +0000114 before();
edisonn@google.com2c817772013-08-16 16:30:02 +0000115 INHERITED::drawBitmapRect(dummy1, dummy2, srcOrNull, dst, paint, flags);
edisonn@google.comac03d912013-07-22 15:36:39 +0000116 after();
117 }
118
119 virtual void drawText(const SkDraw& dummy1, const void* text, size_t len,
120 SkScalar x, SkScalar y, const SkPaint& paint) {
121 before();
122 INHERITED::drawText(dummy1, text, len, x, y, paint);
123 after();
124 }
125
126 virtual void drawPosText(const SkDraw& dummy1, const void* text, size_t len,
127 const SkScalar pos[], SkScalar constY,
128 int scalarsPerPos, const SkPaint& paint) {
129 before();
130 INHERITED::drawPosText(dummy1, text, len, pos, constY, scalarsPerPos, paint);
131 after();
132 }
133
134 virtual void drawTextOnPath(const SkDraw& dummy1, const void* text, size_t len,
135 const SkPath& path, const SkMatrix* matrix,
136 const SkPaint& paint) {
137 before();
138 INHERITED::drawTextOnPath(dummy1, text, len, path, matrix, paint);
139 after();
140 }
141
edisonn@google.comac03d912013-07-22 15:36:39 +0000142 virtual void drawVertices(const SkDraw& dummy1, SkCanvas::VertexMode dummy2, int vertexCount,
143 const SkPoint verts[], const SkPoint texs[],
144 const SkColor colors[], SkXfermode* xmode,
145 const uint16_t indices[], int indexCount,
146 const SkPaint& paint) {
147 before();
edisonn@google.come50d9a12013-10-10 20:58:22 +0000148 INHERITED::drawVertices(dummy1, dummy2, vertexCount,verts, texs,colors, xmode, indices,
149 indexCount, paint);
edisonn@google.comac03d912013-07-22 15:36:39 +0000150 after();
151 }
152
robertphillips@google.com1f2f3382013-08-29 11:54:56 +0000153 virtual void drawDevice(const SkDraw& dummy1, SkBaseDevice* dummy2, int x, int y,
edisonn@google.comac03d912013-07-22 15:36:39 +0000154 const SkPaint& dummy3) {
155 before();
156 INHERITED::drawDevice(dummy1, dummy2, x, y, dummy3);
157 after();
158 }
159
160private:
161 void before() {
162 if (fTracker) {
163 fTracker->before(accessBitmap(false));
164 }
165 }
166
167 // any/all of the expected touched has to be changed, and all expected untouched must be intact
168 void after() {
169 if (fTracker) {
170 fTracker->after(accessBitmap(false));
171 }
172 }
173
174private:
175 SkTracker* fTracker;
176
robertphillips@google.com1f2f3382013-08-29 11:54:56 +0000177 typedef SkBitmapDevice INHERITED;
edisonn@google.comac03d912013-07-22 15:36:39 +0000178};
179
edisonn@google.comcf2cfa12013-08-21 16:31:37 +0000180#endif // SkTrackDevice_DEFINED