• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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
10 
11 #include "SkBitmapDevice.h"
12 #include "SkTracker.h"
13 
14 /** \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  *   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  *
24  */
25 class SkTrackDevice : public SkBitmapDevice {
26 public:
SK_DECLARE_INST_COUNT(SkTrackDevice)27     SK_DECLARE_INST_COUNT(SkTrackDevice)
28 
29     SkTrackDevice(const SkBitmap& bitmap) : SkBitmapDevice(bitmap)
30                                           , fTracker(NULL) {}
31 
~SkTrackDevice()32     virtual ~SkTrackDevice() {}
33 
34     // 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, ...
installTracker(SkTracker * tracker)36     void installTracker(SkTracker* tracker) {
37         fTracker = tracker;
38         fTracker->newFrame();
39     }
40 
41 protected:
clear(SkColor color)42     virtual void clear(SkColor color) {
43         before();
44         INHERITED::clear(color);
45         after();
46     }
47 
drawPaint(const SkDraw & dummy1,const SkPaint & paint)48     virtual void drawPaint(const SkDraw& dummy1, const SkPaint& paint) {
49         before();
50         INHERITED::drawPaint(dummy1, paint);
51         after();
52     }
53 
drawPoints(const SkDraw & dummy1,SkCanvas::PointMode mode,size_t count,const SkPoint dummy2[],const SkPaint & paint)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 
drawRect(const SkDraw & dummy1,const SkRect & r,const SkPaint & paint)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 
drawOval(const SkDraw & dummy1,const SkRect & oval,const SkPaint & paint)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 
drawRRect(const SkDraw & dummy1,const SkRRect & rr,const SkPaint & paint)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 
drawBitmap(const SkDraw & dummy1,const SkBitmap & bitmap,const SkMatrix & matrix,const SkPaint & paint)92     virtual void drawBitmap(const SkDraw& dummy1, const SkBitmap& bitmap,
93                             const SkMatrix& matrix, const SkPaint& paint) {
94         before();
95         INHERITED::drawBitmap(dummy1, bitmap, matrix, paint);
96         after();
97     }
98 
drawSprite(const SkDraw & dummy1,const SkBitmap & bitmap,int x,int y,const SkPaint & paint)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 
drawBitmapRect(const SkDraw & dummy1,const SkBitmap & dummy2,const SkRect * srcOrNull,const SkRect & dst,const SkPaint & paint,SkCanvas::DrawBitmapRectFlags flags)106     virtual void drawBitmapRect(const SkDraw& dummy1, const SkBitmap& dummy2,
107                                 const SkRect* srcOrNull, const SkRect& dst,
108                                 const SkPaint& paint,
109                                 SkCanvas::DrawBitmapRectFlags flags) {
110         before();
111         INHERITED::drawBitmapRect(dummy1, dummy2, srcOrNull, dst, paint, flags);
112         after();
113     }
114 
drawText(const SkDraw & dummy1,const void * text,size_t len,SkScalar x,SkScalar y,const SkPaint & paint)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 
drawPosText(const SkDraw & dummy1,const void * text,size_t len,const SkScalar pos[],SkScalar constY,int scalarsPerPos,const SkPaint & paint)122     virtual void drawPosText(const SkDraw& dummy1, const void* text, size_t len,
123                              const SkScalar pos[], SkScalar constY,
124                              int scalarsPerPos, const SkPaint& paint) {
125         before();
126         INHERITED::drawPosText(dummy1, text, len, pos, constY, scalarsPerPos, paint);
127         after();
128     }
129 
drawTextOnPath(const SkDraw & dummy1,const void * text,size_t len,const SkPath & path,const SkMatrix * matrix,const SkPaint & paint)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 
drawVertices(const SkDraw & dummy1,SkCanvas::VertexMode dummy2,int vertexCount,const SkPoint verts[],const SkPoint texs[],const SkColor colors[],SkXfermode * xmode,const uint16_t indices[],int indexCount,const SkPaint & paint)138     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();
144         INHERITED::drawVertices(dummy1, dummy2, vertexCount,verts, texs,colors, xmode, indices,
145                                 indexCount, paint);
146         after();
147     }
148 
drawDevice(const SkDraw & dummy1,SkBaseDevice * dummy2,int x,int y,const SkPaint & dummy3)149     virtual void drawDevice(const SkDraw& dummy1, SkBaseDevice* dummy2, int x, int y,
150                             const SkPaint& dummy3) {
151         before();
152         INHERITED::drawDevice(dummy1, dummy2, x, y, dummy3);
153         after();
154     }
155 
156 private:
before()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
after()164     void after() {
165         if (fTracker) {
166             fTracker->after(accessBitmap(false));
167         }
168     }
169 
170 private:
171     SkTracker* fTracker;
172 
173     typedef SkBitmapDevice INHERITED;
174 };
175 
176 #endif  // SkTrackDevice_DEFINED
177