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