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 SkRecordDraw_DEFINED 9 #define SkRecordDraw_DEFINED 10 11 #include "SkBBoxHierarchy.h" 12 #include "SkCanvas.h" 13 #include "SkDrawPictureCallback.h" 14 #include "SkMatrix.h" 15 #include "SkRecord.h" 16 17 // Fill a BBH to be used by SkRecordDraw to accelerate playback. 18 void SkRecordFillBounds(const SkRecord&, SkBBoxHierarchy*); 19 20 // Draw an SkRecord into an SkCanvas. A convenience wrapper around SkRecords::Draw. 21 void SkRecordDraw(const SkRecord&, SkCanvas*, const SkBBoxHierarchy*, SkDrawPictureCallback*); 22 23 // Draw a portion of an SkRecord into an SkCanvas while replacing clears with drawRects. 24 // When drawing a portion of an SkRecord the CTM on the passed in canvas must be 25 // the composition of the replay matrix with the record-time CTM (for the portion 26 // of the record that is being replayed). For setMatrix calls to behave correctly 27 // the initialCTM parameter must set to just the replay matrix. 28 void SkRecordPartialDraw(const SkRecord&, SkCanvas*, const SkRect&, unsigned start, unsigned stop, 29 const SkMatrix& initialCTM); 30 31 namespace SkRecords { 32 33 // This is an SkRecord visitor that will draw that SkRecord to an SkCanvas. 34 class Draw : SkNoncopyable { 35 public: 36 explicit Draw(SkCanvas* canvas, const SkMatrix* initialCTM = NULL) 37 : fInitialCTM(initialCTM ? *initialCTM : canvas->getTotalMatrix()) 38 , fCanvas(canvas) {} 39 40 template <typename T> void operator()(const T& r) { 41 this->draw(r); 42 } 43 44 private: 45 // No base case, so we'll be compile-time checked that we implement all possibilities. 46 template <typename T> void draw(const T&); 47 48 const SkMatrix fInitialCTM; 49 SkCanvas* fCanvas; 50 }; 51 52 // Used by SkRecordPartialDraw. 53 class PartialDraw : public Draw { 54 public: 55 PartialDraw(SkCanvas* canvas, const SkRect& clearRect, const SkMatrix& initialCTM) 56 : INHERITED(canvas, &initialCTM), fClearRect(clearRect) {} 57 58 // Same as Draw for all ops except Clear. 59 template <typename T> void operator()(const T& r) { 60 this->INHERITED::operator()(r); 61 } 62 void operator()(const Clear& c) { 63 SkPaint p; 64 p.setColor(c.color); 65 DrawRect drawRect(p, fClearRect); 66 this->INHERITED::operator()(drawRect); 67 } 68 69 private: 70 const SkRect fClearRect; 71 typedef Draw INHERITED; 72 }; 73 74 } // namespace SkRecords 75 76 #endif//SkRecordDraw_DEFINED 77