blob: 8d6a923b18d4af5bdb2f5b9766868d39bf7e3467 [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:
42 virtual void clear(SkColor color) {
43 before();
44 INHERITED::clear(color);
45 after();
46 }
47
48 virtual void drawPaint(const SkDraw& dummy1, const SkPaint& paint) {
49 before();
50 INHERITED::drawPaint(dummy1, paint);
51 after();
52 }
53
54 virtual void drawPoints(const SkDraw& dummy1, SkCanvas::PointMode mode, size_t count,
55 const SkPoint dummy2[], const SkPaint& paint) {
56 before();
57 INHERITED::drawPoints(dummy1, mode, count, dummy2, paint);
58 after();
59 }
60
61 virtual void drawRect(const SkDraw& dummy1, const SkRect& r,
62 const SkPaint& paint) {
63 before();
64 INHERITED::drawRect(dummy1, r, paint);
65 after();
66 }
67
68
69 virtual void drawOval(const SkDraw& dummy1, const SkRect& oval,
70 const SkPaint& paint) {
71 before();
72 INHERITED::drawOval(dummy1, oval, paint);
73 after();
74 }
75
76 virtual void drawRRect(const SkDraw& dummy1, const SkRRect& rr,
77 const SkPaint& paint) {
78 before();
79 INHERITED::drawRRect(dummy1, rr, paint);
80 after();
81 }
82
83 virtual void drawPath(const SkDraw& dummy1, const SkPath& path,
84 const SkPaint& paint,
85 const SkMatrix* prePathMatrix = NULL,
86 bool pathIsMutable = false) {
87 before();
88 INHERITED::drawPath(dummy1, path, paint, prePathMatrix, pathIsMutable);
89 after();
90 }
91
92 virtual void drawBitmap(const SkDraw& dummy1, const SkBitmap& bitmap,
edisonn@google.comac03d912013-07-22 15:36:39 +000093 const SkMatrix& matrix, const SkPaint& paint) {
94 before();
edisonn@google.com50bbdb42013-07-25 15:33:13 +000095 INHERITED::drawBitmap(dummy1, bitmap, matrix, paint);
edisonn@google.comac03d912013-07-22 15:36:39 +000096 after();
97 }
98
99 virtual void drawSprite(const SkDraw& dummy1, const SkBitmap& bitmap,
100 int x, int y, const SkPaint& paint) {
101 before();
102 INHERITED::drawSprite(dummy1, bitmap, x, y, paint);
103 after();
104 }
105
106 virtual void drawBitmapRect(const SkDraw& dummy1, const SkBitmap& dummy2,
107 const SkRect* srcOrNull, const SkRect& dst,
edisonn@google.com2c817772013-08-16 16:30:02 +0000108 const SkPaint& paint,
109 SkCanvas::DrawBitmapRectFlags flags) {
edisonn@google.comac03d912013-07-22 15:36:39 +0000110 before();
edisonn@google.com2c817772013-08-16 16:30:02 +0000111 INHERITED::drawBitmapRect(dummy1, dummy2, srcOrNull, dst, paint, flags);
edisonn@google.comac03d912013-07-22 15:36:39 +0000112 after();
113 }
114
115 virtual void drawText(const SkDraw& dummy1, const void* text, size_t len,
116 SkScalar x, SkScalar y, const SkPaint& paint) {
117 before();
118 INHERITED::drawText(dummy1, text, len, x, y, paint);
119 after();
120 }
121
122 virtual void drawPosText(const SkDraw& dummy1, const void* text, size_t len,
fmalita05c4a432014-09-29 06:29:53 -0700123 const SkScalar pos[], int scalarsPerPos,
124 const SkPoint& offset, const SkPaint& paint) {
edisonn@google.comac03d912013-07-22 15:36:39 +0000125 before();
fmalita05c4a432014-09-29 06:29:53 -0700126 INHERITED::drawPosText(dummy1, text, len, pos, scalarsPerPos, offset, paint);
edisonn@google.comac03d912013-07-22 15:36:39 +0000127 after();
128 }
129
130 virtual void drawTextOnPath(const SkDraw& dummy1, const void* text, size_t len,
131 const SkPath& path, const SkMatrix* matrix,
132 const SkPaint& paint) {
133 before();
134 INHERITED::drawTextOnPath(dummy1, text, len, path, matrix, paint);
135 after();
136 }
137
edisonn@google.comac03d912013-07-22 15:36:39 +0000138 virtual void drawVertices(const SkDraw& dummy1, SkCanvas::VertexMode dummy2, int vertexCount,
139 const SkPoint verts[], const SkPoint texs[],
140 const SkColor colors[], SkXfermode* xmode,
141 const uint16_t indices[], int indexCount,
142 const SkPaint& paint) {
143 before();
edisonn@google.come50d9a12013-10-10 20:58:22 +0000144 INHERITED::drawVertices(dummy1, dummy2, vertexCount,verts, texs,colors, xmode, indices,
145 indexCount, paint);
edisonn@google.comac03d912013-07-22 15:36:39 +0000146 after();
147 }
148
robertphillips@google.com1f2f3382013-08-29 11:54:56 +0000149 virtual void drawDevice(const SkDraw& dummy1, SkBaseDevice* dummy2, int x, int y,
edisonn@google.comac03d912013-07-22 15:36:39 +0000150 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
robertphillips@google.com1f2f3382013-08-29 11:54:56 +0000173 typedef SkBitmapDevice INHERITED;
edisonn@google.comac03d912013-07-22 15:36:39 +0000174};
175
edisonn@google.comcf2cfa12013-08-21 16:31:37 +0000176#endif // SkTrackDevice_DEFINED