Home | History | Annotate | Download | only in PdfViewer
      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:
     27     SK_DECLARE_INST_COUNT(SkTrackDevice)
     28 
     29     SkTrackDevice(const SkBitmap& bitmap) : SkBitmapDevice(bitmap)
     30                                           , fTracker(NULL) {}
     31 
     32     SkTrackDevice(const SkBitmap& bitmap, const SkDeviceProperties& deviceProperties)
     33         : SkBitmapDevice(bitmap, deviceProperties)
     34         , fTracker(NULL) {}
     35 
     36     virtual ~SkTrackDevice() {}
     37 
     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, ...
     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,
     97                             const SkMatrix& matrix, const SkPaint& paint) {
     98         before();
     99         INHERITED::drawBitmap(dummy1, bitmap, matrix, paint);
    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,
    112                                 const SkPaint& paint,
    113                                 SkCanvas::DrawBitmapRectFlags flags) {
    114         before();
    115         INHERITED::drawBitmapRect(dummy1, dummy2, srcOrNull, dst, paint, flags);
    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 
    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();
    148         INHERITED::drawVertices(dummy1, dummy2, vertexCount,verts, texs,colors, xmode, indices,
    149                                 indexCount, paint);
    150         after();
    151     }
    152 
    153     virtual void drawDevice(const SkDraw& dummy1, SkBaseDevice* dummy2, int x, int y,
    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 
    177     typedef SkBitmapDevice INHERITED;
    178 };
    179 
    180 #endif  // SkTrackDevice_DEFINED
    181