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     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, ...
     36     void installTracker(SkTracker* tracker) {
     37         fTracker = tracker;
     38         fTracker->newFrame();
     39     }
     40 
     41 protected:
     42 #if 0   // clear is deprecated (and private)
     43     virtual void clear(SkColor color) {
     44         before();
     45         INHERITED::clear(color);
     46         after();
     47     }
     48 #endif
     49 
     50     virtual void drawPaint(const SkDraw& dummy1, const SkPaint& paint) {
     51         before();
     52         INHERITED::drawPaint(dummy1, paint);
     53         after();
     54     }
     55 
     56     virtual void drawPoints(const SkDraw& dummy1, SkCanvas::PointMode mode, size_t count,
     57                             const SkPoint dummy2[], const SkPaint& paint) {
     58         before();
     59         INHERITED::drawPoints(dummy1, mode, count, dummy2, paint);
     60         after();
     61     }
     62 
     63     virtual void drawRect(const SkDraw& dummy1, const SkRect& r,
     64                           const SkPaint& paint) {
     65         before();
     66         INHERITED::drawRect(dummy1, r, paint);
     67         after();
     68     }
     69 
     70 
     71     virtual void drawOval(const SkDraw& dummy1, const SkRect& oval,
     72                           const SkPaint& paint) {
     73         before();
     74         INHERITED::drawOval(dummy1, oval, paint);
     75         after();
     76     }
     77 
     78     virtual void drawRRect(const SkDraw& dummy1, const SkRRect& rr,
     79                            const SkPaint& paint) {
     80         before();
     81         INHERITED::drawRRect(dummy1, rr, paint);
     82         after();
     83     }
     84 
     85     virtual void drawPath(const SkDraw& dummy1, const SkPath& path,
     86                           const SkPaint& paint,
     87                           const SkMatrix* prePathMatrix = NULL,
     88                           bool pathIsMutable = false) {
     89         before();
     90         INHERITED::drawPath(dummy1, path, paint, prePathMatrix, pathIsMutable);
     91         after();
     92     }
     93 
     94     virtual void drawBitmap(const SkDraw& dummy1, const SkBitmap& bitmap,
     95                             const SkMatrix& matrix, const SkPaint& paint) {
     96         before();
     97         INHERITED::drawBitmap(dummy1, bitmap, matrix, paint);
     98         after();
     99     }
    100 
    101     virtual void drawSprite(const SkDraw& dummy1, const SkBitmap& bitmap,
    102                             int x, int y, const SkPaint& paint) {
    103         before();
    104         INHERITED::drawSprite(dummy1, bitmap, x, y, paint);
    105         after();
    106     }
    107 
    108     virtual void drawBitmapRect(const SkDraw& dummy1, const SkBitmap& dummy2,
    109                                 const SkRect* srcOrNull, const SkRect& dst,
    110                                 const SkPaint& paint,
    111                                 SkCanvas::DrawBitmapRectFlags flags) {
    112         before();
    113         INHERITED::drawBitmapRect(dummy1, dummy2, srcOrNull, dst, paint, flags);
    114         after();
    115     }
    116 
    117     virtual void drawText(const SkDraw& dummy1, const void* text, size_t len,
    118                           SkScalar x, SkScalar y, const SkPaint& paint) {
    119         before();
    120         INHERITED::drawText(dummy1, text, len, x, y, paint);
    121         after();
    122     }
    123 
    124     virtual void drawPosText(const SkDraw& dummy1, const void* text, size_t len,
    125                              const SkScalar pos[], int scalarsPerPos,
    126                              const SkPoint& offset, const SkPaint& paint) {
    127         before();
    128         INHERITED::drawPosText(dummy1, text, len, pos, scalarsPerPos, offset, paint);
    129         after();
    130     }
    131 
    132     virtual void drawTextOnPath(const SkDraw& dummy1, const void* text, size_t len,
    133                                 const SkPath& path, const SkMatrix* matrix,
    134                                 const SkPaint& paint)  {
    135         before();
    136         INHERITED::drawTextOnPath(dummy1, text, len, path, matrix, paint);
    137         after();
    138     }
    139 
    140     virtual void drawVertices(const SkDraw& dummy1, SkCanvas::VertexMode dummy2, int vertexCount,
    141                               const SkPoint verts[], const SkPoint texs[],
    142                               const SkColor colors[], SkXfermode* xmode,
    143                               const uint16_t indices[], int indexCount,
    144                               const SkPaint& paint) {
    145         before();
    146         INHERITED::drawVertices(dummy1, dummy2, vertexCount,verts, texs,colors, xmode, indices,
    147                                 indexCount, paint);
    148         after();
    149     }
    150 
    151     virtual void drawDevice(const SkDraw& dummy1, SkBaseDevice* dummy2, int x, int y,
    152                             const SkPaint& dummy3) {
    153         before();
    154         INHERITED::drawDevice(dummy1, dummy2, x, y, dummy3);
    155         after();
    156     }
    157 
    158 private:
    159     void before() {
    160         if (fTracker) {
    161             fTracker->before(accessBitmap(false));
    162         }
    163     }
    164 
    165     // any/all of the expected touched has to be changed, and all expected untouched must be intact
    166     void after() {
    167         if (fTracker) {
    168             fTracker->after(accessBitmap(false));
    169         }
    170     }
    171 
    172 private:
    173     SkTracker* fTracker;
    174 
    175     typedef SkBitmapDevice INHERITED;
    176 };
    177 
    178 #endif  // SkTrackDevice_DEFINED
    179