| 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! | 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, | 15 // TODO(edisonn): Minimal PDF to draw some points - remove everything that it is
      not needed, | 
| 16 //                save pdf uncompressed | 16 //                save pdf uncompressed | 
| 17 | 17 | 
| 18 #define MAX_TRACKING_POINTS 100 | 18 #define MAX_TRACKING_POINTS 100 | 
| 19 | 19 | 
| 20 /** \class SkTracker | 20 /** \class SkTracker | 
| 21  * | 21  * | 
| 22  *   A Tracker can be attached to a SkTrackDevice and it will store the track pi
     xels. | 22  *   A Tracker can be attached to a SkTrackDevice and it will store the track pi
     xels. | 
| 23  *   It can be used with SampleApp to investigate bugs (CL not checked in yet). | 23  *   It can be used with SampleApp to investigate bugs (CL not checked in yet). | 
| 24  * | 24  * | 
|  | 25  *   The Tracker tracks 2 sets of points | 
|  | 26  *     A) one which is expected to issue breackpoints if the pixels are changes | 
|  | 27  *     B) one which if changes will disable the breackpoint | 
|  | 28  *   For point in A) there are two modes: | 
|  | 29  *     A.1) a breackpoint require that any of the points is changed | 
|  | 30  *     A.2) a breackpoint require that all of the points is changed | 
|  | 31  *   Points in B are allways in "any mode" - chaning the value of any pixel, wil
     l disable | 
|  | 32  *     the breackpoint | 
|  | 33  * | 
|  | 34  *   Point in A) are used to show what are the areas of interest, while poit in 
     B are used to | 
|  | 35  *     disable breackpoints which would be issued in background change. | 
|  | 36  * | 
| 25  */ | 37  */ | 
| 26 class SkTracker { | 38 class SkTracker { | 
| 27 public: | 39 public: | 
| 28     SkTracker() : fEnabled(false) | 40     SkTracker() : fEnabled(false) | 
| 29                 , fBreakOnAny(false) | 41                 , fBreakOnAny(false) | 
| 30                 , fCntExpectedTouched(0) | 42                 , fCntExpectedTouched(0) | 
| 31                 , fCntExpectedUntouched(0) | 43                 , fCntExpectedUntouched(0) | 
| 32                 , fHits(0) {} | 44                 , fHits(0) {} | 
| 33 | 45 | 
| 34     virtual ~SkTracker() {} | 46     virtual ~SkTracker() {} | 
| 35 | 47 | 
|  | 48     // Clears all the points, but preserves the break mode. | 
| 36     void clearPoints() { | 49     void clearPoints() { | 
| 37         fCntExpectedTouched = 0; | 50         fCntExpectedTouched = 0; | 
| 38         fCntExpectedUntouched = 0; | 51         fCntExpectedUntouched = 0; | 
| 39     } | 52     } | 
| 40 | 53 | 
|  | 54     // Enable the breackpoints. | 
| 41     void enableTracking(bool b) { | 55     void enableTracking(bool b) { | 
| 42         fEnabled = b; | 56         fEnabled = b; | 
| 43     } | 57     } | 
| 44 | 58 | 
|  | 59     // Returns true if breackpoints are enabled. | 
| 45     bool trackingEnabled() { | 60     bool trackingEnabled() { | 
| 46         return fEnabled; | 61         return fEnabled; | 
| 47     } | 62     } | 
| 48 | 63 | 
|  | 64     // Puts the tracker in Any mode. | 
| 49     void any() { | 65     void any() { | 
| 50         fBreakOnAny = true; | 66         fBreakOnAny = true; | 
| 51     } | 67     } | 
| 52 | 68 | 
|  | 69     // Puts the tracker in Any mode. | 
| 53     void all() { | 70     void all() { | 
| 54         fBreakOnAny = false; | 71         fBreakOnAny = false; | 
| 55     } | 72     } | 
| 56 | 73 | 
|  | 74     // returns true in in All mode. False for Any mode. | 
| 57     bool requireAllExpectedTouched() { | 75     bool requireAllExpectedTouched() { | 
| 58         return !fBreakOnAny; | 76         return !fBreakOnAny; | 
| 59     } | 77     } | 
| 60 | 78 | 
|  | 79     // Returns the numbers of points in which if touched, would trigger a breack
     point. | 
| 61     int cntExpectedTouched() { | 80     int cntExpectedTouched() { | 
| 62         return fCntExpectedTouched; | 81         return fCntExpectedTouched; | 
| 63     } | 82     } | 
| 64 | 83 | 
|  | 84     // Returns the points which if touched, would trigger a breackpoint. | 
|  | 85     // the Tracker owns the array | 
| 65     const SkIPoint* expectedTouched() { | 86     const SkIPoint* expectedTouched() { | 
| 66         return fExpectedTouched; | 87         return fExpectedTouched; | 
| 67     } | 88     } | 
| 68 | 89 | 
|  | 90     // Returns the numbers of points in which if touched, would disable a breack
     point. | 
| 69     int cntExpectedUntouched() { | 91     int cntExpectedUntouched() { | 
| 70         return fCntExpectedUntouched; | 92         return fCntExpectedUntouched; | 
| 71     } | 93     } | 
| 72 | 94 | 
|  | 95     // Returns the points which if touched, would disable a breackpoint. | 
|  | 96     // the Tracker owns the array | 
| 73     const SkIPoint* expectedUntouched() { | 97     const SkIPoint* expectedUntouched() { | 
| 74         return fExpectedUntouched; | 98         return fExpectedUntouched; | 
| 75     } | 99     } | 
| 76 | 100 | 
|  | 101     // Adds a point which if changes in a drawFoo operation, would trigger a bre
     akpoint. | 
| 77     bool addExpectTouch(int x, int y) { | 102     bool addExpectTouch(int x, int y) { | 
| 78         if (fCntExpectedTouched >= MAX_TRACKING_POINTS) { | 103         if (fCntExpectedTouched >= MAX_TRACKING_POINTS) { | 
| 79             return false; | 104             return false; | 
| 80         } | 105         } | 
| 81         if (found(x, y)) { | 106         if (found(x, y)) { | 
| 82             return false; | 107             return false; | 
| 83         } | 108         } | 
| 84         fExpectedTouched[fCntExpectedTouched] = SkIPoint::Make(x, y); | 109         fExpectedTouched[fCntExpectedTouched] = SkIPoint::Make(x, y); | 
| 85         fCntExpectedTouched++; | 110         fCntExpectedTouched++; | 
| 86         return true; | 111         return true; | 
| 87     } | 112     } | 
| 88 | 113 | 
|  | 114     // Adds a point which if changes in a drawFoo operation, would disable a bre
     akpoint. | 
| 89     bool addExpectUntouch(int x, int y) { | 115     bool addExpectUntouch(int x, int y) { | 
| 90         if (fCntExpectedUntouched >= MAX_TRACKING_POINTS) { | 116         if (fCntExpectedUntouched >= MAX_TRACKING_POINTS) { | 
| 91             return false; | 117             return false; | 
| 92         } | 118         } | 
| 93         if (found(x, y)) { | 119         if (found(x, y)) { | 
| 94             return false; | 120             return false; | 
| 95         } | 121         } | 
| 96         fExpectedUntouched[fCntExpectedUntouched] = SkIPoint::Make(x, y); | 122         fExpectedUntouched[fCntExpectedUntouched] = SkIPoint::Make(x, y); | 
| 97         fCntExpectedUntouched++; | 123         fCntExpectedUntouched++; | 
| 98         return true; | 124         return true; | 
| 99     } | 125     } | 
| 100 | 126 | 
|  | 127     // Starts a new rendering session - reset the number of hits. | 
| 101     void newFrame() { | 128     void newFrame() { | 
| 102         fHits = 0; | 129         fHits = 0; | 
| 103     } | 130     } | 
| 104 | 131 | 
|  | 132     // returns the number of breackpoints issues in this rendering session. | 
| 105     int hits() { | 133     int hits() { | 
| 106         return fHits; | 134         return fHits; | 
| 107     } | 135     } | 
| 108 | 136 | 
|  | 137     // Called before drawFoo to store the state of the pixels | 
| 109     void before(const SkBitmap& bitmap) { | 138     void before(const SkBitmap& bitmap) { | 
| 110         if (fCntExpectedTouched == 0) { | 139         if (fCntExpectedTouched == 0) { | 
| 111             return; | 140             return; | 
| 112         } | 141         } | 
| 113 | 142 | 
| 114         for (int i = 0 ; i < fCntExpectedTouched; i++) { | 143         for (int i = 0 ; i < fCntExpectedTouched; i++) { | 
| 115             fBeforeTouched[i] = pickColor(bitmap, fExpectedTouched[i].x(), fExpe
     ctedTouched[i].y()); | 144             fBeforeTouched[i] = pickColor(bitmap, fExpectedTouched[i].x(), fExpe
     ctedTouched[i].y()); | 
| 116         } | 145         } | 
| 117         for (int i = 0 ; i < fCntExpectedUntouched; i++) { | 146         for (int i = 0 ; i < fCntExpectedUntouched; i++) { | 
| 118             fBeforeUntouched[i] = pickColor(bitmap, fExpectedUntouched[i].x(), | 147             fBeforeUntouched[i] = pickColor(bitmap, fExpectedUntouched[i].x(), | 
| 119                                             fExpectedUntouched[i].y()); | 148                                             fExpectedUntouched[i].y()); | 
| 120         } | 149         } | 
| 121     } | 150     } | 
| 122 | 151 | 
|  | 152     // Called after drawFoo to evaluate what pixels have changed, it could issue
      a breakpoint. | 
| 123     // any/all of the expected touched has to be changed, and all expected untou
     ched must be intact | 153     // any/all of the expected touched has to be changed, and all expected untou
     ched must be intact | 
| 124     void after(const SkBitmap& bitmap) { | 154     void after(const SkBitmap& bitmap) { | 
| 125         if (fCntExpectedTouched == 0) { | 155         if (fCntExpectedTouched == 0) { | 
| 126             return; | 156             return; | 
| 127         } | 157         } | 
| 128 | 158 | 
| 129         bool doBreak; | 159         bool doBreak; | 
| 130         if (fBreakOnAny) { | 160         if (fBreakOnAny) { | 
| 131             doBreak = false; | 161             doBreak = false; | 
| 132             for (int i = 0 ; i < fCntExpectedTouched; i++) { | 162             for (int i = 0 ; i < fCntExpectedTouched; i++) { | 
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 186     int fCntExpectedTouched; | 216     int fCntExpectedTouched; | 
| 187 | 217 | 
| 188     SkIPoint fExpectedUntouched[MAX_TRACKING_POINTS]; | 218     SkIPoint fExpectedUntouched[MAX_TRACKING_POINTS]; | 
| 189     SkColor fBeforeUntouched[MAX_TRACKING_POINTS]; | 219     SkColor fBeforeUntouched[MAX_TRACKING_POINTS]; | 
| 190     int fCntExpectedUntouched; | 220     int fCntExpectedUntouched; | 
| 191 | 221 | 
| 192     int fHits; | 222     int fHits; | 
| 193 }; | 223 }; | 
| 194 | 224 | 
| 195 #endif  // SkTracker_DEFINED | 225 #endif  // SkTracker_DEFINED | 
| OLD | NEW | 
|---|