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