blob: 20f9e6867ead04cb54f0aea5185a2bb5e378f26f [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 *
19 */
robertphillips@google.com1f2f3382013-08-29 11:54:56 +000020class SkTrackDevice : public SkBitmapDevice {
edisonn@google.comac03d912013-07-22 15:36:39 +000021public:
22 SK_DECLARE_INST_COUNT(SkTrackDevice)
23
robertphillips@google.com1f2f3382013-08-29 11:54:56 +000024 SkTrackDevice(const SkBitmap& bitmap) : SkBitmapDevice(bitmap)
edisonn@google.comac03d912013-07-22 15:36:39 +000025 , fTracker(NULL) {}
26
27 SkTrackDevice(const SkBitmap& bitmap, const SkDeviceProperties& deviceProperties)
robertphillips@google.com1f2f3382013-08-29 11:54:56 +000028 : SkBitmapDevice(bitmap, deviceProperties)
edisonn@google.comac03d912013-07-22 15:36:39 +000029 , fTracker(NULL) {}
30
31 SkTrackDevice(SkBitmap::Config config, int width, int height, bool isOpaque = false)
robertphillips@google.com1f2f3382013-08-29 11:54:56 +000032 : SkBitmapDevice(config, width, height, isOpaque)
edisonn@google.comac03d912013-07-22 15:36:39 +000033 , fTracker(NULL) {}
34
35 SkTrackDevice(SkBitmap::Config config, int width, int height, bool isOpaque,
36 const SkDeviceProperties& deviceProperties)
robertphillips@google.com1f2f3382013-08-29 11:54:56 +000037 : SkBitmapDevice(config, width, height, isOpaque, deviceProperties)
edisonn@google.comac03d912013-07-22 15:36:39 +000038 , fTracker(NULL) {}
39
40 virtual ~SkTrackDevice() {}
41
42 void installTracker(SkTracker* tracker) {
43 fTracker = tracker;
44 fTracker->newFrame();
45 }
46
47protected:
48 virtual void clear(SkColor color) {
49 before();
50 INHERITED::clear(color);
51 after();
52 }
53
54 virtual void drawPaint(const SkDraw& dummy1, const SkPaint& paint) {
55 before();
56 INHERITED::drawPaint(dummy1, paint);
57 after();
58 }
59
60 virtual void drawPoints(const SkDraw& dummy1, SkCanvas::PointMode mode, size_t count,
61 const SkPoint dummy2[], const SkPaint& paint) {
62 before();
63 INHERITED::drawPoints(dummy1, mode, count, dummy2, paint);
64 after();
65 }
66
67 virtual void drawRect(const SkDraw& dummy1, const SkRect& r,
68 const SkPaint& paint) {
69 before();
70 INHERITED::drawRect(dummy1, r, paint);
71 after();
72 }
73
74
75 virtual void drawOval(const SkDraw& dummy1, const SkRect& oval,
76 const SkPaint& paint) {
77 before();
78 INHERITED::drawOval(dummy1, oval, paint);
79 after();
80 }
81
82 virtual void drawRRect(const SkDraw& dummy1, const SkRRect& rr,
83 const SkPaint& paint) {
84 before();
85 INHERITED::drawRRect(dummy1, rr, paint);
86 after();
87 }
88
89 virtual void drawPath(const SkDraw& dummy1, const SkPath& path,
90 const SkPaint& paint,
91 const SkMatrix* prePathMatrix = NULL,
92 bool pathIsMutable = false) {
93 before();
94 INHERITED::drawPath(dummy1, path, paint, prePathMatrix, pathIsMutable);
95 after();
96 }
97
98 virtual void drawBitmap(const SkDraw& dummy1, const SkBitmap& bitmap,
edisonn@google.comac03d912013-07-22 15:36:39 +000099 const SkMatrix& matrix, const SkPaint& paint) {
100 before();
edisonn@google.com50bbdb42013-07-25 15:33:13 +0000101 INHERITED::drawBitmap(dummy1, bitmap, matrix, paint);
edisonn@google.comac03d912013-07-22 15:36:39 +0000102 after();
103 }
104
105 virtual void drawSprite(const SkDraw& dummy1, const SkBitmap& bitmap,
106 int x, int y, const SkPaint& paint) {
107 before();
108 INHERITED::drawSprite(dummy1, bitmap, x, y, paint);
109 after();
110 }
111
112 virtual void drawBitmapRect(const SkDraw& dummy1, const SkBitmap& dummy2,
113 const SkRect* srcOrNull, const SkRect& dst,
edisonn@google.com2c817772013-08-16 16:30:02 +0000114 const SkPaint& paint,
115 SkCanvas::DrawBitmapRectFlags flags) {
edisonn@google.comac03d912013-07-22 15:36:39 +0000116 before();
edisonn@google.com2c817772013-08-16 16:30:02 +0000117 INHERITED::drawBitmapRect(dummy1, dummy2, srcOrNull, dst, paint, flags);
edisonn@google.comac03d912013-07-22 15:36:39 +0000118 after();
119 }
120
121 virtual void drawText(const SkDraw& dummy1, const void* text, size_t len,
122 SkScalar x, SkScalar y, const SkPaint& paint) {
123 before();
124 INHERITED::drawText(dummy1, text, len, x, y, paint);
125 after();
126 }
127
128 virtual void drawPosText(const SkDraw& dummy1, const void* text, size_t len,
129 const SkScalar pos[], SkScalar constY,
130 int scalarsPerPos, const SkPaint& paint) {
131 before();
132 INHERITED::drawPosText(dummy1, text, len, pos, constY, scalarsPerPos, paint);
133 after();
134 }
135
136 virtual void drawTextOnPath(const SkDraw& dummy1, const void* text, size_t len,
137 const SkPath& path, const SkMatrix* matrix,
138 const SkPaint& paint) {
139 before();
140 INHERITED::drawTextOnPath(dummy1, text, len, path, matrix, paint);
141 after();
142 }
143
144#ifdef SK_BUILD_FOR_ANDROID
145 virtual void drawPosTextOnPath(const SkDraw& draw, const void* text, size_t len,
146 const SkPoint pos[], const SkPaint& paint,
147 const SkPath& path, const SkMatrix* matrix) {
148 before();
149 INHERITED::drawPosTextOnPath(draw, text, len, pos, paint, path, matrix);
150 after();
151 }
152#endif
153 virtual void drawVertices(const SkDraw& dummy1, SkCanvas::VertexMode dummy2, int vertexCount,
154 const SkPoint verts[], const SkPoint texs[],
155 const SkColor colors[], SkXfermode* xmode,
156 const uint16_t indices[], int indexCount,
157 const SkPaint& paint) {
158 before();
edisonn@google.come50d9a12013-10-10 20:58:22 +0000159 INHERITED::drawVertices(dummy1, dummy2, vertexCount,verts, texs,colors, xmode, indices,
160 indexCount, paint);
edisonn@google.comac03d912013-07-22 15:36:39 +0000161 after();
162 }
163
robertphillips@google.com1f2f3382013-08-29 11:54:56 +0000164 virtual void drawDevice(const SkDraw& dummy1, SkBaseDevice* dummy2, int x, int y,
edisonn@google.comac03d912013-07-22 15:36:39 +0000165 const SkPaint& dummy3) {
166 before();
167 INHERITED::drawDevice(dummy1, dummy2, x, y, dummy3);
168 after();
169 }
170
171private:
172 void before() {
173 if (fTracker) {
174 fTracker->before(accessBitmap(false));
175 }
176 }
177
178 // any/all of the expected touched has to be changed, and all expected untouched must be intact
179 void after() {
180 if (fTracker) {
181 fTracker->after(accessBitmap(false));
182 }
183 }
184
185private:
186 SkTracker* fTracker;
187
robertphillips@google.com1f2f3382013-08-29 11:54:56 +0000188 typedef SkBitmapDevice INHERITED;
edisonn@google.comac03d912013-07-22 15:36:39 +0000189};
190
edisonn@google.comcf2cfa12013-08-21 16:31:37 +0000191#endif // SkTrackDevice_DEFINED