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 "SkBigPicture.h" 13 #include "SkCanvas.h" 14 #include "SkMatrix.h" 15 #include "SkRecord.h" 16 17 class SkDrawable; 18 class SkLayerInfo; 19 20 // Calculate conservative identity space bounds for each op in the record. 21 void SkRecordFillBounds(const SkRect& cullRect, const SkRecord&, SkRect bounds[]); 22 23 // SkRecordFillBounds(), and gathers information about saveLayers and stores it for later 24 // use (e.g., layer hoisting). The gathered information is sufficient to determine 25 // where each saveLayer will land and which ops in the picture it represents. 26 void SkRecordComputeLayers(const SkRect& cullRect, const SkRecord&, SkRect bounds[], 27 const SkBigPicture::SnapshotArray*, SkLayerInfo* data); 28 29 // Draw an SkRecord into an SkCanvas. A convenience wrapper around SkRecords::Draw. 30 void SkRecordDraw(const SkRecord&, SkCanvas*, SkPicture const* const drawablePicts[], 31 SkDrawable* const drawables[], int drawableCount, 32 const SkBBoxHierarchy*, SkPicture::AbortCallback*); 33 34 // Draw a portion of an SkRecord into an SkCanvas. 35 // When drawing a portion of an SkRecord the CTM on the passed in canvas must be 36 // the composition of the replay matrix with the record-time CTM (for the portion 37 // of the record that is being replayed). For setMatrix calls to behave correctly 38 // the initialCTM parameter must set to just the replay matrix. 39 void SkRecordPartialDraw(const SkRecord&, SkCanvas*, 40 SkPicture const* const drawablePicts[], int drawableCount, 41 int start, int stop, const SkMatrix& initialCTM); 42 43 namespace SkRecords { 44 45 // This is an SkRecord visitor that will draw that SkRecord to an SkCanvas. 46 class Draw : SkNoncopyable { 47 public: 48 explicit Draw(SkCanvas* canvas, SkPicture const* const drawablePicts[], 49 SkDrawable* const drawables[], int drawableCount, 50 const SkMatrix* initialCTM = nullptr) 51 : fInitialCTM(initialCTM ? *initialCTM : canvas->getTotalMatrix()) 52 , fCanvas(canvas) 53 , fDrawablePicts(drawablePicts) 54 , fDrawables(drawables) 55 , fDrawableCount(drawableCount) 56 {} 57 58 // This operator calls methods on the |canvas|. The various draw() wrapper 59 // methods around SkCanvas are defined by the DRAW() macro in 60 // SkRecordDraw.cpp. operator()61 template <typename T> void operator()(const T& r) { 62 this->draw(r); 63 } 64 65 protected: drawablePicts()66 SkPicture const* const* drawablePicts() const { return fDrawablePicts; } drawableCount()67 int drawableCount() const { return fDrawableCount; } 68 69 private: 70 // No base case, so we'll be compile-time checked that we implement all possibilities. 71 template <typename T> void draw(const T&); 72 73 const SkMatrix fInitialCTM; 74 SkCanvas* fCanvas; 75 SkPicture const* const* fDrawablePicts; 76 SkDrawable* const* fDrawables; 77 int fDrawableCount; 78 }; 79 80 } // namespace SkRecords 81 82 #endif//SkRecordDraw_DEFINED 83