Home | History | Annotate | Download | only in core
      1 /*
      2  * Copyright 2014 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 SkPicturePlayback_DEFINED
      9 #define SkPicturePlayback_DEFINED
     10 
     11 #include "SkPictureFlat.h"  // for DrawType
     12 #include "SkPictureStateTree.h"
     13 
     14 class SkBitmap;
     15 class SkCanvas;
     16 class SkDrawPictureCallback;
     17 class SkPaint;
     18 class SkPictureData;
     19 
     20 // The basic picture playback class replays the provided picture into a canvas.
     21 // If the picture was generated with a BBH it is used to accelerate drawing
     22 // unless disabled via setUseBBH.
     23 class SkPicturePlayback : SkNoncopyable {
     24 public:
     25     SkPicturePlayback(const SkPicture* picture)
     26         : fPictureData(picture->fData.get())
     27         , fCurOffset(0)
     28         , fUseBBH(true) {
     29     }
     30     virtual ~SkPicturePlayback() { }
     31 
     32     virtual void draw(SkCanvas* canvas, SkDrawPictureCallback*);
     33 
     34     // TODO: remove the curOp calls after cleaning up GrGatherDevice
     35     // Return the ID of the operation currently being executed when playing
     36     // back. 0 indicates no call is active.
     37     size_t curOpID() const { return fCurOffset; }
     38     void resetOpID() { fCurOffset = 0; }
     39 
     40     // TODO: remove setUseBBH after cleaning up GrGatherCanvas
     41     void setUseBBH(bool useBBH) { fUseBBH = useBBH; }
     42 
     43 protected:
     44     const SkPictureData* fPictureData;
     45 
     46     // The offset of the current operation when within the draw method
     47     size_t fCurOffset;
     48 
     49     bool   fUseBBH;
     50 
     51     void handleOp(SkReader32* reader,
     52                   DrawType op,
     53                   uint32_t size,
     54                   SkCanvas* canvas,
     55                   const SkMatrix& initialMatrix);
     56 
     57     const SkPicture::OperationList* getActiveOps(const SkCanvas* canvas);
     58     bool initIterator(SkPictureStateTree::Iterator* iter,
     59                       SkCanvas* canvas,
     60                       const SkPicture::OperationList *activeOpsList);
     61     static void StepIterator(SkPictureStateTree::Iterator* iter, SkReader32* reader);
     62     static void SkipIterTo(SkPictureStateTree::Iterator* iter,
     63                            SkReader32* reader, uint32_t skipTo);
     64 
     65     static DrawType ReadOpAndSize(SkReader32* reader, uint32_t* size);
     66 
     67     class AutoResetOpID {
     68     public:
     69         AutoResetOpID(SkPicturePlayback* playback) : fPlayback(playback) { }
     70         ~AutoResetOpID() {
     71             if (fPlayback) {
     72                 fPlayback->resetOpID();
     73             }
     74         }
     75 
     76     private:
     77         SkPicturePlayback* fPlayback;
     78     };
     79 
     80 private:
     81     typedef SkNoncopyable INHERITED;
     82 };
     83 
     84 #endif
     85