edisonn@google.com | cf2cfa1 | 2013-08-21 16:31:37 +0000 | [diff] [blame] | 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 |
edisonn@google.com | ac03d91 | 2013-07-22 15:36:39 +0000 | [diff] [blame] | 10 | |
edisonn@google.com | e91260c | 2013-09-04 17:29:06 +0000 | [diff] [blame] | 11 | #include "SkBitmapDevice.h" |
edisonn@google.com | ac03d91 | 2013-07-22 15:36:39 +0000 | [diff] [blame] | 12 | #include "SkTracker.h" |
| 13 | |
edisonn@google.com | 2af2ad9 | 2013-10-11 16:17:44 +0000 | [diff] [blame] | 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 | * |
edisonn@google.com | d03c2c7 | 2013-10-11 18:26:45 +0000 | [diff] [blame] | 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 | * |
edisonn@google.com | 2af2ad9 | 2013-10-11 16:17:44 +0000 | [diff] [blame] | 24 | */ |
robertphillips@google.com | 1f2f338 | 2013-08-29 11:54:56 +0000 | [diff] [blame] | 25 | class SkTrackDevice : public SkBitmapDevice { |
edisonn@google.com | ac03d91 | 2013-07-22 15:36:39 +0000 | [diff] [blame] | 26 | public: |
| 27 | SK_DECLARE_INST_COUNT(SkTrackDevice) |
| 28 | |
robertphillips@google.com | 1f2f338 | 2013-08-29 11:54:56 +0000 | [diff] [blame] | 29 | SkTrackDevice(const SkBitmap& bitmap) : SkBitmapDevice(bitmap) |
edisonn@google.com | ac03d91 | 2013-07-22 15:36:39 +0000 | [diff] [blame] | 30 | , fTracker(NULL) {} |
| 31 | |
| 32 | SkTrackDevice(const SkBitmap& bitmap, const SkDeviceProperties& deviceProperties) |
robertphillips@google.com | 1f2f338 | 2013-08-29 11:54:56 +0000 | [diff] [blame] | 33 | : SkBitmapDevice(bitmap, deviceProperties) |
edisonn@google.com | ac03d91 | 2013-07-22 15:36:39 +0000 | [diff] [blame] | 34 | , fTracker(NULL) {} |
| 35 | |
edisonn@google.com | ac03d91 | 2013-07-22 15:36:39 +0000 | [diff] [blame] | 36 | virtual ~SkTrackDevice() {} |
| 37 | |
edisonn@google.com | d03c2c7 | 2013-10-11 18:26:45 +0000 | [diff] [blame] | 38 | // 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.com | ac03d91 | 2013-07-22 15:36:39 +0000 | [diff] [blame] | 40 | void installTracker(SkTracker* tracker) { |
| 41 | fTracker = tracker; |
| 42 | fTracker->newFrame(); |
| 43 | } |
| 44 | |
| 45 | protected: |
| 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.com | ac03d91 | 2013-07-22 15:36:39 +0000 | [diff] [blame] | 97 | const SkMatrix& matrix, const SkPaint& paint) { |
| 98 | before(); |
edisonn@google.com | 50bbdb4 | 2013-07-25 15:33:13 +0000 | [diff] [blame] | 99 | INHERITED::drawBitmap(dummy1, bitmap, matrix, paint); |
edisonn@google.com | ac03d91 | 2013-07-22 15:36:39 +0000 | [diff] [blame] | 100 | 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.com | 2c81777 | 2013-08-16 16:30:02 +0000 | [diff] [blame] | 112 | const SkPaint& paint, |
| 113 | SkCanvas::DrawBitmapRectFlags flags) { |
edisonn@google.com | ac03d91 | 2013-07-22 15:36:39 +0000 | [diff] [blame] | 114 | before(); |
edisonn@google.com | 2c81777 | 2013-08-16 16:30:02 +0000 | [diff] [blame] | 115 | INHERITED::drawBitmapRect(dummy1, dummy2, srcOrNull, dst, paint, flags); |
edisonn@google.com | ac03d91 | 2013-07-22 15:36:39 +0000 | [diff] [blame] | 116 | 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.com | ac03d91 | 2013-07-22 15:36:39 +0000 | [diff] [blame] | 142 | 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.com | e50d9a1 | 2013-10-10 20:58:22 +0000 | [diff] [blame] | 148 | INHERITED::drawVertices(dummy1, dummy2, vertexCount,verts, texs,colors, xmode, indices, |
| 149 | indexCount, paint); |
edisonn@google.com | ac03d91 | 2013-07-22 15:36:39 +0000 | [diff] [blame] | 150 | after(); |
| 151 | } |
| 152 | |
robertphillips@google.com | 1f2f338 | 2013-08-29 11:54:56 +0000 | [diff] [blame] | 153 | virtual void drawDevice(const SkDraw& dummy1, SkBaseDevice* dummy2, int x, int y, |
edisonn@google.com | ac03d91 | 2013-07-22 15:36:39 +0000 | [diff] [blame] | 154 | const SkPaint& dummy3) { |
| 155 | before(); |
| 156 | INHERITED::drawDevice(dummy1, dummy2, x, y, dummy3); |
| 157 | after(); |
| 158 | } |
| 159 | |
| 160 | private: |
| 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 | |
| 174 | private: |
| 175 | SkTracker* fTracker; |
| 176 | |
robertphillips@google.com | 1f2f338 | 2013-08-29 11:54:56 +0000 | [diff] [blame] | 177 | typedef SkBitmapDevice INHERITED; |
edisonn@google.com | ac03d91 | 2013-07-22 15:36:39 +0000 | [diff] [blame] | 178 | }; |
| 179 | |
edisonn@google.com | cf2cfa1 | 2013-08-21 16:31:37 +0000 | [diff] [blame] | 180 | #endif // SkTrackDevice_DEFINED |