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 SkNulCanvas_DEFINED
      9 #define SkNulCanvas_DEFINED
     10 
     11 #include "SkCanvas.h"
     12 
     13 /** \class SkNulCanvas
     14  *
     15  *   Nul Canvas is a canvas that does nothing. It is used to measure the perf of just parsing
     16  *   a pdf, without actually rendering anything.
     17  *
     18  */
     19 class SK_API SkNulCanvas : public SkCanvas {
     20 public:
     21     SK_DECLARE_INST_COUNT(SkNulCanvas);
     22 
     23     SkNulCanvas() {}
     24     explicit SkNulCanvas(SkBaseDevice* device) : SkCanvas(device) {}
     25 
     26     explicit SkNulCanvas(const SkBitmap& bitmap) : SkCanvas(bitmap) {}
     27     virtual ~SkNulCanvas() {}
     28 
     29     virtual bool isDrawingToLayer() const SK_OVERRIDE {return false;}
     30     virtual void clear(SkColor) SK_OVERRIDE {}
     31     virtual void drawPaint(const SkPaint& paint) SK_OVERRIDE {}
     32     virtual void drawPoints(PointMode mode, size_t count, const SkPoint pts[],
     33                             const SkPaint& paint) SK_OVERRIDE {}
     34     virtual void drawRect(const SkRect& rect, const SkPaint& paint) SK_OVERRIDE {}
     35     virtual void drawOval(const SkRect& oval, const SkPaint&) SK_OVERRIDE {}
     36     virtual void drawRRect(const SkRRect& rrect, const SkPaint& paint) SK_OVERRIDE {}
     37     virtual void drawPath(const SkPath& path, const SkPaint& paint) SK_OVERRIDE {}
     38     virtual void drawBitmap(const SkBitmap& bitmap, SkScalar left, SkScalar top,
     39                             const SkPaint* paint = NULL) SK_OVERRIDE {}
     40     virtual void drawBitmapRectToRect(const SkBitmap& bitmap, const SkRect* src,
     41                                       const SkRect& dst,
     42                                       const SkPaint* paint,
     43                                       DrawBitmapRectFlags flags) SK_OVERRIDE {}
     44     virtual void drawBitmapMatrix(const SkBitmap& bitmap, const SkMatrix& m,
     45                                   const SkPaint* paint = NULL) SK_OVERRIDE {}
     46     virtual void drawBitmapNine(const SkBitmap& bitmap, const SkIRect& center,
     47                                 const SkRect& dst, const SkPaint* paint = NULL) SK_OVERRIDE {}
     48     virtual void drawSprite(const SkBitmap& bitmap, int left, int top,
     49                             const SkPaint* paint = NULL) SK_OVERRIDE {}
     50     virtual void drawVertices(VertexMode vmode, int vertexCount,
     51                               const SkPoint vertices[], const SkPoint texs[],
     52                               const SkColor colors[], SkXfermode* xmode,
     53                               const uint16_t indices[], int indexCount,
     54                               const SkPaint& paint) SK_OVERRIDE {}
     55     virtual void drawData(const void* data, size_t length) SK_OVERRIDE {}
     56     virtual void beginCommentGroup(const char* description) SK_OVERRIDE {}
     57     virtual void addComment(const char* kywd, const char* value) SK_OVERRIDE {}
     58     virtual void endCommentGroup() SK_OVERRIDE {}
     59     virtual SkDrawFilter* setDrawFilter(SkDrawFilter* filter) SK_OVERRIDE {return NULL;}
     60 
     61     virtual bool isClipEmpty() const SK_OVERRIDE { return false; }
     62 #ifdef SK_SUPPORT_LEGACY_GETCLIPTYPE
     63     virtual ClipType getClipType() const SK_OVERRIDE { return kRect_ClipType; }
     64 #endif
     65     virtual bool getClipBounds(SkRect* bounds) const SK_OVERRIDE {
     66         if (NULL != bounds) {
     67             bounds->setXYWH(0, 0,
     68                             SkIntToScalar(this->imageInfo().fWidth),
     69                             SkIntToScalar(this->imageInfo().fHeight));
     70         }
     71         return true;
     72     }
     73     virtual bool getClipDeviceBounds(SkIRect* bounds) const SK_OVERRIDE {
     74         if (NULL != bounds) {
     75             bounds->setLargest();
     76         }
     77         return true;
     78     }
     79 
     80 protected:
     81     virtual SkCanvas* canvasForDrawIter() {return NULL;}
     82     virtual SkBaseDevice* setDevice(SkBaseDevice* device) {return NULL;}
     83 
     84     virtual SaveLayerStrategy willSaveLayer(const SkRect* bounds, const SkPaint* paint,
     85                                             SaveFlags flags) SK_OVERRIDE {
     86         this->INHERITED::willSaveLayer(bounds, paint, flags);
     87         return kNoLayer_SaveLayerStrategy;
     88     }
     89 
     90     virtual void onDrawText(const void* text, size_t byteLength, SkScalar x,
     91                           SkScalar y, const SkPaint& paint) SK_OVERRIDE {}
     92     virtual void onDrawPosText(const void* text, size_t byteLength,
     93                              const SkPoint pos[], const SkPaint& paint) SK_OVERRIDE {}
     94     virtual void onDrawPosTextH(const void* text, size_t byteLength,
     95                               const SkScalar xpos[], SkScalar constY,
     96                               const SkPaint& paint) SK_OVERRIDE {}
     97     virtual void onDrawTextOnPath(const void* text, size_t byteLength,
     98                                 const SkPath& path, const SkMatrix* matrix,
     99                                 const SkPaint& paint) SK_OVERRIDE {}
    100 
    101     virtual void onClipRect(const SkRect&, SkRegion::Op, ClipEdgeStyle) SK_OVERRIDE {}
    102     virtual void onClipRRect(const SkRRect&, SkRegion::Op, ClipEdgeStyle) SK_OVERRIDE {}
    103     virtual void onClipPath(const SkPath&, SkRegion::Op, ClipEdgeStyle) SK_OVERRIDE {}
    104     virtual void onClipRegion(const SkRegion&, SkRegion::Op)  SK_OVERRIDE {}
    105 
    106     virtual void onDrawPicture(const SkPicture* picture) SK_OVERRIDE {}
    107 
    108 private:
    109     typedef SkCanvas INHERITED;
    110 };
    111 
    112 #endif  // SkNulCanvas_DEFINED
    113