blob: 9280b7f247621b19fff76e686c584ba76bad5cbc [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
edisonn@google.comac03d912013-07-22 15:36:39 +000032 virtual ~SkTrackDevice() {}
33
edisonn@google.comd03c2c72013-10-11 18:26:45 +000034 // Install a tracker - we can reuse the tracker between multiple devices, and the state of the
35 // tracker is preserved - number and location of poinbts, ...
edisonn@google.comac03d912013-07-22 15:36:39 +000036 void installTracker(SkTracker* tracker) {
37 fTracker = tracker;
38 fTracker->newFrame();
39 }
40
41protected:
reedb19ce312014-12-04 08:39:09 -080042#if 0 // clear is deprecated (and private)
edisonn@google.comac03d912013-07-22 15:36:39 +000043 virtual void clear(SkColor color) {
44 before();
45 INHERITED::clear(color);
46 after();
47 }
reedb19ce312014-12-04 08:39:09 -080048#endif
edisonn@google.comac03d912013-07-22 15:36:39 +000049
50 virtual void drawPaint(const SkDraw& dummy1, const SkPaint& paint) {
51 before();
52 INHERITED::drawPaint(dummy1, paint);
53 after();
54 }
55
56 virtual void drawPoints(const SkDraw& dummy1, SkCanvas::PointMode mode, size_t count,
57 const SkPoint dummy2[], const SkPaint& paint) {
58 before();
59 INHERITED::drawPoints(dummy1, mode, count, dummy2, paint);
60 after();
61 }
62
63 virtual void drawRect(const SkDraw& dummy1, const SkRect& r,
64 const SkPaint& paint) {
65 before();
66 INHERITED::drawRect(dummy1, r, paint);
67 after();
68 }
69
70
71 virtual void drawOval(const SkDraw& dummy1, const SkRect& oval,
72 const SkPaint& paint) {
73 before();
74 INHERITED::drawOval(dummy1, oval, paint);
75 after();
76 }
77
78 virtual void drawRRect(const SkDraw& dummy1, const SkRRect& rr,
79 const SkPaint& paint) {
80 before();
81 INHERITED::drawRRect(dummy1, rr, paint);
82 after();
83 }
84
85 virtual void drawPath(const SkDraw& dummy1, const SkPath& path,
86 const SkPaint& paint,
87 const SkMatrix* prePathMatrix = NULL,
88 bool pathIsMutable = false) {
89 before();
90 INHERITED::drawPath(dummy1, path, paint, prePathMatrix, pathIsMutable);
91 after();
92 }
93
94 virtual void drawBitmap(const SkDraw& dummy1, const SkBitmap& bitmap,
edisonn@google.comac03d912013-07-22 15:36:39 +000095 const SkMatrix& matrix, const SkPaint& paint) {
96 before();
edisonn@google.com50bbdb42013-07-25 15:33:13 +000097 INHERITED::drawBitmap(dummy1, bitmap, matrix, paint);
edisonn@google.comac03d912013-07-22 15:36:39 +000098 after();
99 }
100
101 virtual void drawSprite(const SkDraw& dummy1, const SkBitmap& bitmap,
102 int x, int y, const SkPaint& paint) {
103 before();
104 INHERITED::drawSprite(dummy1, bitmap, x, y, paint);
105 after();
106 }
107
108 virtual void drawBitmapRect(const SkDraw& dummy1, const SkBitmap& dummy2,
109 const SkRect* srcOrNull, const SkRect& dst,
edisonn@google.com2c817772013-08-16 16:30:02 +0000110 const SkPaint& paint,
111 SkCanvas::DrawBitmapRectFlags flags) {
edisonn@google.comac03d912013-07-22 15:36:39 +0000112 before();
edisonn@google.com2c817772013-08-16 16:30:02 +0000113 INHERITED::drawBitmapRect(dummy1, dummy2, srcOrNull, dst, paint, flags);
edisonn@google.comac03d912013-07-22 15:36:39 +0000114 after();
115 }
116
117 virtual void drawText(const SkDraw& dummy1, const void* text, size_t len,
118 SkScalar x, SkScalar y, const SkPaint& paint) {
119 before();
120 INHERITED::drawText(dummy1, text, len, x, y, paint);
121 after();
122 }
123
124 virtual void drawPosText(const SkDraw& dummy1, const void* text, size_t len,
fmalita05c4a432014-09-29 06:29:53 -0700125 const SkScalar pos[], int scalarsPerPos,
126 const SkPoint& offset, const SkPaint& paint) {
edisonn@google.comac03d912013-07-22 15:36:39 +0000127 before();
fmalita05c4a432014-09-29 06:29:53 -0700128 INHERITED::drawPosText(dummy1, text, len, pos, scalarsPerPos, offset, paint);
edisonn@google.comac03d912013-07-22 15:36:39 +0000129 after();
130 }
131
132 virtual void drawTextOnPath(const SkDraw& dummy1, const void* text, size_t len,
133 const SkPath& path, const SkMatrix* matrix,
134 const SkPaint& paint) {
135 before();
136 INHERITED::drawTextOnPath(dummy1, text, len, path, matrix, paint);
137 after();
138 }
139
edisonn@google.comac03d912013-07-22 15:36:39 +0000140 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();
edisonn@google.come50d9a12013-10-10 20:58:22 +0000146 INHERITED::drawVertices(dummy1, dummy2, vertexCount,verts, texs,colors, xmode, indices,
147 indexCount, paint);
edisonn@google.comac03d912013-07-22 15:36:39 +0000148 after();
149 }
150
robertphillips@google.com1f2f3382013-08-29 11:54:56 +0000151 virtual void drawDevice(const SkDraw& dummy1, SkBaseDevice* dummy2, int x, int y,
edisonn@google.comac03d912013-07-22 15:36:39 +0000152 const SkPaint& dummy3) {
153 before();
154 INHERITED::drawDevice(dummy1, dummy2, x, y, dummy3);
155 after();
156 }
157
158private:
159 void before() {
160 if (fTracker) {
161 fTracker->before(accessBitmap(false));
162 }
163 }
164
165 // any/all of the expected touched has to be changed, and all expected untouched must be intact
166 void after() {
167 if (fTracker) {
168 fTracker->after(accessBitmap(false));
169 }
170 }
171
172private:
173 SkTracker* fTracker;
174
robertphillips@google.com1f2f3382013-08-29 11:54:56 +0000175 typedef SkBitmapDevice INHERITED;
edisonn@google.comac03d912013-07-22 15:36:39 +0000176};
177
edisonn@google.comcf2cfa12013-08-21 16:31:37 +0000178#endif // SkTrackDevice_DEFINED