SkBigPicture.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. #ifndef SkBigPicture_DEFINED
  8. #define SkBigPicture_DEFINED
  9. #include "include/core/SkPicture.h"
  10. #include "include/core/SkRect.h"
  11. #include "include/private/SkNoncopyable.h"
  12. #include "include/private/SkOnce.h"
  13. #include "include/private/SkTemplates.h"
  14. class SkBBoxHierarchy;
  15. class SkMatrix;
  16. class SkRecord;
  17. // An implementation of SkPicture supporting an arbitrary number of drawing commands.
  18. class SkBigPicture final : public SkPicture {
  19. public:
  20. // An array of refcounted const SkPicture pointers.
  21. class SnapshotArray : ::SkNoncopyable {
  22. public:
  23. SnapshotArray(const SkPicture* pics[], int count) : fPics(pics), fCount(count) {}
  24. ~SnapshotArray() { for (int i = 0; i < fCount; i++) { fPics[i]->unref(); } }
  25. const SkPicture* const* begin() const { return fPics; }
  26. int count() const { return fCount; }
  27. private:
  28. SkAutoTMalloc<const SkPicture*> fPics;
  29. int fCount;
  30. };
  31. SkBigPicture(const SkRect& cull,
  32. SkRecord*, // We take ownership of the caller's ref.
  33. SnapshotArray*, // We take exclusive ownership.
  34. SkBBoxHierarchy*, // We take ownership of the caller's ref.
  35. size_t approxBytesUsedBySubPictures);
  36. // SkPicture overrides
  37. void playback(SkCanvas*, AbortCallback*) const override;
  38. SkRect cullRect() const override;
  39. int approximateOpCount() const override;
  40. size_t approximateBytesUsed() const override;
  41. const SkBigPicture* asSkBigPicture() const override { return this; }
  42. // Used by GrLayerHoister
  43. void partialPlayback(SkCanvas*,
  44. int start,
  45. int stop,
  46. const SkMatrix& initialCTM) const;
  47. // Used by GrRecordReplaceDraw
  48. const SkBBoxHierarchy* bbh() const { return fBBH.get(); }
  49. const SkRecord* record() const { return fRecord.get(); }
  50. private:
  51. int drawableCount() const;
  52. SkPicture const* const* drawablePicts() const;
  53. const SkRect fCullRect;
  54. const size_t fApproxBytesUsedBySubPictures;
  55. sk_sp<const SkRecord> fRecord;
  56. std::unique_ptr<const SnapshotArray> fDrawablePicts;
  57. sk_sp<const SkBBoxHierarchy> fBBH;
  58. };
  59. #endif//SkBigPicture_DEFINED