| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #ifndef SkTracker_DEFINED | 8 #ifndef SkTracker_DEFINED |
| 9 #define SkTracker_DEFINED | 9 #define SkTracker_DEFINED |
| 10 | 10 |
| 11 #include "SkBitmap.h" | 11 #include "SkBitmap.h" |
| 12 #include "SkPoint.h" | 12 #include "SkPoint.h" |
| 13 | 13 |
| 14 // TODO(edisonn): draw plan from point! - list of draw ops of a point, like a tr
ee! |
| 15 // TODO(edisonn): Minimal PDF to draw some points - remove everything that it is
not needed, |
| 16 // save pdf uncompressed |
| 17 |
| 14 #define MAX_TRACKING_POINTS 100 | 18 #define MAX_TRACKING_POINTS 100 |
| 15 | 19 |
| 16 class SkTracker { | 20 class SkTracker { |
| 17 public: | 21 public: |
| 18 SkTracker() : fEnabled(false) | 22 SkTracker() : fEnabled(false) |
| 19 , fBreakOnAny(false) | 23 , fBreakOnAny(false) |
| 20 , fCntExpectedTouched(0) | 24 , fCntExpectedTouched(0) |
| 21 , fCntExpectedUntouched(0) | 25 , fCntExpectedUntouched(0) |
| 22 , fHits(0) {} | 26 , fHits(0) {} |
| 23 | 27 |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 | 102 |
| 99 void before(const SkBitmap& bitmap) { | 103 void before(const SkBitmap& bitmap) { |
| 100 if (fCntExpectedTouched == 0) { | 104 if (fCntExpectedTouched == 0) { |
| 101 return; | 105 return; |
| 102 } | 106 } |
| 103 | 107 |
| 104 for (int i = 0 ; i < fCntExpectedTouched; i++) { | 108 for (int i = 0 ; i < fCntExpectedTouched; i++) { |
| 105 fBeforeTouched[i] = pickColor(bitmap, fExpectedTouched[i].x(), fExpe
ctedTouched[i].y()); | 109 fBeforeTouched[i] = pickColor(bitmap, fExpectedTouched[i].x(), fExpe
ctedTouched[i].y()); |
| 106 } | 110 } |
| 107 for (int i = 0 ; i < fCntExpectedUntouched; i++) { | 111 for (int i = 0 ; i < fCntExpectedUntouched; i++) { |
| 108 fBeforeUntouched[i] = pickColor(bitmap, fExpectedUntouched[i].x(), f
ExpectedUntouched[i].y()); | 112 fBeforeUntouched[i] = pickColor(bitmap, fExpectedUntouched[i].x(), |
| 113 fExpectedUntouched[i].y()); |
| 109 } | 114 } |
| 110 } | 115 } |
| 111 | 116 |
| 112 // any/all of the expected touched has to be changed, and all expected untou
ched must be intact | 117 // any/all of the expected touched has to be changed, and all expected untou
ched must be intact |
| 113 void after(const SkBitmap& bitmap) { | 118 void after(const SkBitmap& bitmap) { |
| 114 if (fCntExpectedTouched == 0) { | 119 if (fCntExpectedTouched == 0) { |
| 115 return; | 120 return; |
| 116 } | 121 } |
| 117 | 122 |
| 118 bool doBreak; | 123 bool doBreak; |
| 119 if (fBreakOnAny) { | 124 if (fBreakOnAny) { |
| 120 doBreak = false; | 125 doBreak = false; |
| 121 for (int i = 0 ; i < fCntExpectedTouched; i++) { | 126 for (int i = 0 ; i < fCntExpectedTouched; i++) { |
| 122 doBreak = doBreak || fBeforeTouched[i] != pickColor(bitmap, fExp
ectedTouched[i].x(), fExpectedTouched[i].y()); | 127 doBreak = doBreak || fBeforeTouched[i] != pickColor(bitmap, fExp
ectedTouched[i].x(), |
| 128 fExpectedTou
ched[i].y()); |
| 123 } | 129 } |
| 124 } else { | 130 } else { |
| 125 doBreak = true; | 131 doBreak = true; |
| 126 for (int i = 0 ; i < fCntExpectedTouched; i++) { | 132 for (int i = 0 ; i < fCntExpectedTouched; i++) { |
| 127 doBreak = doBreak && fBeforeTouched[i] != pickColor(bitmap, fExp
ectedTouched[i].x(), fExpectedTouched[i].y()); | 133 doBreak = doBreak && fBeforeTouched[i] != pickColor(bitmap, fExp
ectedTouched[i].x(), |
| 134 fExpectedTou
ched[i].y()); |
| 128 } | 135 } |
| 129 } | 136 } |
| 130 | 137 |
| 131 for (int i = 0 ; i < fCntExpectedUntouched; i++) { | 138 for (int i = 0 ; i < fCntExpectedUntouched; i++) { |
| 132 doBreak = doBreak && fBeforeUntouched[i] == pickColor(bitmap, fExpec
tedUntouched[i].x(), fExpectedUntouched[i].y()); | 139 doBreak = doBreak && fBeforeUntouched[i] == pickColor(bitmap, fExpec
tedUntouched[i].x(), |
| 140 fExpectedUntou
ched[i].y()); |
| 133 } | 141 } |
| 134 | 142 |
| 135 if (doBreak) { | 143 if (doBreak) { |
| 136 fHits++; | 144 fHits++; |
| 137 if (fEnabled) { | 145 if (fEnabled) { |
| 138 breakExecution(); | 146 breakExecution(); |
| 139 } | 147 } |
| 140 } | 148 } |
| 141 } | 149 } |
| 142 | 150 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 172 int fCntExpectedTouched; | 180 int fCntExpectedTouched; |
| 173 | 181 |
| 174 SkIPoint fExpectedUntouched[MAX_TRACKING_POINTS]; | 182 SkIPoint fExpectedUntouched[MAX_TRACKING_POINTS]; |
| 175 SkColor fBeforeUntouched[MAX_TRACKING_POINTS]; | 183 SkColor fBeforeUntouched[MAX_TRACKING_POINTS]; |
| 176 int fCntExpectedUntouched; | 184 int fCntExpectedUntouched; |
| 177 | 185 |
| 178 int fHits; | 186 int fHits; |
| 179 }; | 187 }; |
| 180 | 188 |
| 181 #endif // SkTracker_DEFINED | 189 #endif // SkTracker_DEFINED |
| OLD | NEW |