Home | History | Annotate | Download | only in gpu
      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 GrRecordReplaceDraw_DEFINED
      9 #define GrRecordReplaceDraw_DEFINED
     10 
     11 #include "SkDrawPictureCallback.h"
     12 #include "SkRect.h"
     13 #include "SkTDArray.h"
     14 
     15 class SkBBoxHierarchy;
     16 class SkBitmap;
     17 class SkCanvas;
     18 class SkImage;
     19 class SkPaint;
     20 class SkRecord;
     21 
     22 // GrReplacements collects op ranges that can be replaced with
     23 // a single drawBitmap call (using a precomputed bitmap).
     24 class GrReplacements {
     25 public:
     26     // All the operations between fStart and fStop (inclusive) will be replaced with
     27     // a single drawBitmap call using fPos, fBM and fPaint.
     28     struct ReplacementInfo {
     29         unsigned        fStart;
     30         unsigned        fStop;
     31         SkIPoint        fPos;
     32         SkImage*        fImage;  // Owns a ref
     33         const SkPaint*  fPaint;  // Owned by this object
     34 
     35         SkIRect         fSrcRect;
     36     };
     37 
     38     ~GrReplacements() { this->freeAll(); }
     39 
     40     // Add a new replacement range. The replacement ranges should be
     41     // sorted in increasing order and non-overlapping (esp. no nested
     42     // saveLayers).
     43     ReplacementInfo* push();
     44 
     45     // look up a replacement range by its start offset.
     46     // lastLookedUp is an in/out parameter that is used to speed up the search.
     47     // It should be initialized to 0 on the first call and then passed back in
     48     // unmodified on subsequent calls.
     49     const ReplacementInfo* lookupByStart(size_t start, int* lastLookedUp) const;
     50 
     51 private:
     52     SkTDArray<ReplacementInfo> fReplacements;
     53 
     54     void freeAll();
     55 
     56 #ifdef SK_DEBUG
     57     void validate() const;
     58 #endif
     59 };
     60 
     61 // Draw an SkRecord into an SkCanvas replacing saveLayer/restore blocks with
     62 // drawBitmap calls.  A convenience wrapper around SkRecords::Draw.
     63 void GrRecordReplaceDraw(const SkRecord&,
     64                          SkCanvas*,
     65                          const SkBBoxHierarchy*,
     66                          const GrReplacements*,
     67                          SkDrawPictureCallback*);
     68 
     69 #endif // GrRecordReplaceDraw_DEFINED
     70