1 /* 2 * Copyright 2015 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 SkBigPicture_DEFINED 9 #define SkBigPicture_DEFINED 10 11 #include "SkOnce.h" 12 #include "SkPicture.h" 13 #include "SkRect.h" 14 #include "SkTemplates.h" 15 16 class SkBBoxHierarchy; 17 class SkMatrix; 18 class SkRecord; 19 20 // An implementation of SkPicture supporting an arbitrary number of drawing commands. 21 class SkBigPicture final : public SkPicture { 22 public: 23 // An array of refcounted const SkPicture pointers. 24 class SnapshotArray : ::SkNoncopyable { 25 public: SnapshotArray(const SkPicture * pics[],int count)26 SnapshotArray(const SkPicture* pics[], int count) : fPics(pics), fCount(count) {} ~SnapshotArray()27 ~SnapshotArray() { for (int i = 0; i < fCount; i++) { fPics[i]->unref(); } } 28 begin()29 const SkPicture* const* begin() const { return fPics; } count()30 int count() const { return fCount; } 31 private: 32 SkAutoTMalloc<const SkPicture*> fPics; 33 int fCount; 34 }; 35 36 SkBigPicture(const SkRect& cull, 37 SkRecord*, // We take ownership of the caller's ref. 38 SnapshotArray*, // We take exclusive ownership. 39 SkBBoxHierarchy*, // We take ownership of the caller's ref. 40 size_t approxBytesUsedBySubPictures); 41 42 43 // SkPicture overrides 44 void playback(SkCanvas*, AbortCallback*) const override; 45 SkRect cullRect() const override; 46 bool willPlayBackBitmaps() const override; 47 int approximateOpCount() const override; 48 size_t approximateBytesUsed() const override; asSkBigPicture()49 const SkBigPicture* asSkBigPicture() const override { return this; } 50 51 // Used by GrLayerHoister 52 void partialPlayback(SkCanvas*, 53 int start, 54 int stop, 55 const SkMatrix& initialCTM) const; 56 // Used by GrRecordReplaceDraw bbh()57 const SkBBoxHierarchy* bbh() const { return fBBH.get(); } record()58 const SkRecord* record() const { return fRecord.get(); } 59 60 private: 61 struct Analysis { 62 void init(const SkRecord&); 63 64 bool suitableForGpuRasterization(const char** reason) const; 65 66 uint8_t fNumSlowPathsAndDashEffects; 67 bool fWillPlaybackBitmaps : 1; 68 }; 69 70 int numSlowPaths() const override; 71 const Analysis& analysis() const; 72 int drawableCount() const; 73 SkPicture const* const* drawablePicts() const; 74 75 const SkRect fCullRect; 76 const size_t fApproxBytesUsedBySubPictures; 77 mutable SkOnce fAnalysisOnce; 78 mutable Analysis fAnalysis; 79 sk_sp<const SkRecord> fRecord; 80 std::unique_ptr<const SnapshotArray> fDrawablePicts; 81 sk_sp<const SkBBoxHierarchy> fBBH; 82 }; 83 84 #endif//SkBigPicture_DEFINED 85