SkRecorder.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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. #ifndef SkRecorder_DEFINED
  8. #define SkRecorder_DEFINED
  9. #include "include/core/SkCanvasVirtualEnforcer.h"
  10. #include "include/private/SkTDArray.h"
  11. #include "include/utils/SkNoDrawCanvas.h"
  12. #include "src/core/SkBigPicture.h"
  13. #include "src/core/SkMiniRecorder.h"
  14. #include "src/core/SkRecord.h"
  15. #include "src/core/SkRecords.h"
  16. class SkBBHFactory;
  17. class SkDrawableList : SkNoncopyable {
  18. public:
  19. SkDrawableList() {}
  20. ~SkDrawableList();
  21. int count() const { return fArray.count(); }
  22. SkDrawable* const* begin() const { return fArray.begin(); }
  23. void append(SkDrawable* drawable);
  24. // Return a new or ref'd array of pictures that were snapped from our drawables.
  25. SkBigPicture::SnapshotArray* newDrawableSnapshot();
  26. private:
  27. SkTDArray<SkDrawable*> fArray;
  28. };
  29. // SkRecorder provides an SkCanvas interface for recording into an SkRecord.
  30. class SkRecorder final : public SkCanvasVirtualEnforcer<SkNoDrawCanvas> {
  31. public:
  32. // Does not take ownership of the SkRecord.
  33. SkRecorder(SkRecord*, int width, int height, SkMiniRecorder* = nullptr); // legacy version
  34. SkRecorder(SkRecord*, const SkRect& bounds, SkMiniRecorder* = nullptr);
  35. enum DrawPictureMode { Record_DrawPictureMode, Playback_DrawPictureMode };
  36. void reset(SkRecord*, const SkRect& bounds, DrawPictureMode, SkMiniRecorder* = nullptr);
  37. size_t approxBytesUsedBySubPictures() const { return fApproxBytesUsedBySubPictures; }
  38. SkDrawableList* getDrawableList() const { return fDrawableList.get(); }
  39. std::unique_ptr<SkDrawableList> detachDrawableList() { return std::move(fDrawableList); }
  40. // Make SkRecorder forget entirely about its SkRecord*; all calls to SkRecorder will fail.
  41. void forgetRecord();
  42. void onFlush() override;
  43. void willSave() override;
  44. SaveLayerStrategy getSaveLayerStrategy(const SaveLayerRec&) override;
  45. bool onDoSaveBehind(const SkRect*) override;
  46. void willRestore() override {}
  47. void didRestore() override;
  48. void didConcat(const SkMatrix&) override;
  49. void didSetMatrix(const SkMatrix&) override;
  50. void didTranslate(SkScalar, SkScalar) override;
  51. void onDrawDRRect(const SkRRect&, const SkRRect&, const SkPaint&) override;
  52. void onDrawDrawable(SkDrawable*, const SkMatrix*) override;
  53. void onDrawTextBlob(const SkTextBlob* blob,
  54. SkScalar x,
  55. SkScalar y,
  56. const SkPaint& paint) override;
  57. void onDrawPatch(const SkPoint cubics[12], const SkColor colors[4],
  58. const SkPoint texCoords[4], SkBlendMode,
  59. const SkPaint& paint) override;
  60. void onDrawPaint(const SkPaint&) override;
  61. void onDrawBehind(const SkPaint&) override;
  62. void onDrawPoints(PointMode, size_t count, const SkPoint pts[], const SkPaint&) override;
  63. void onDrawRect(const SkRect&, const SkPaint&) override;
  64. void onDrawRegion(const SkRegion&, const SkPaint&) override;
  65. void onDrawOval(const SkRect&, const SkPaint&) override;
  66. void onDrawArc(const SkRect&, SkScalar, SkScalar, bool, const SkPaint&) override;
  67. void onDrawRRect(const SkRRect&, const SkPaint&) override;
  68. void onDrawPath(const SkPath&, const SkPaint&) override;
  69. void onDrawBitmap(const SkBitmap&, SkScalar left, SkScalar top, const SkPaint*) override;
  70. void onDrawBitmapRect(const SkBitmap&, const SkRect* src, const SkRect& dst, const SkPaint*,
  71. SrcRectConstraint) override;
  72. void onDrawImage(const SkImage*, SkScalar left, SkScalar top, const SkPaint*) override;
  73. void onDrawImageRect(const SkImage*, const SkRect* src, const SkRect& dst,
  74. const SkPaint*, SrcRectConstraint) override;
  75. void onDrawImageNine(const SkImage*, const SkIRect& center, const SkRect& dst,
  76. const SkPaint*) override;
  77. void onDrawBitmapNine(const SkBitmap&, const SkIRect& center, const SkRect& dst,
  78. const SkPaint*) override;
  79. void onDrawImageLattice(const SkImage*, const Lattice& lattice, const SkRect& dst,
  80. const SkPaint*) override;
  81. void onDrawBitmapLattice(const SkBitmap&, const Lattice& lattice, const SkRect& dst,
  82. const SkPaint*) override;
  83. void onDrawVerticesObject(const SkVertices*, const SkVertices::Bone bones[], int boneCount,
  84. SkBlendMode, const SkPaint&) override;
  85. void onDrawAtlas(const SkImage*, const SkRSXform[], const SkRect[], const SkColor[],
  86. int count, SkBlendMode, const SkRect* cull, const SkPaint*) override;
  87. void onDrawShadowRec(const SkPath&, const SkDrawShadowRec&) override;
  88. void onClipRect(const SkRect& rect, SkClipOp, ClipEdgeStyle) override;
  89. void onClipRRect(const SkRRect& rrect, SkClipOp, ClipEdgeStyle) override;
  90. void onClipPath(const SkPath& path, SkClipOp, ClipEdgeStyle) override;
  91. void onClipRegion(const SkRegion& deviceRgn, SkClipOp) override;
  92. void onDrawPicture(const SkPicture*, const SkMatrix*, const SkPaint*) override;
  93. void onDrawAnnotation(const SkRect&, const char[], SkData*) override;
  94. void onDrawEdgeAAQuad(const SkRect&, const SkPoint[4], QuadAAFlags, SkColor,
  95. SkBlendMode) override;
  96. void onDrawEdgeAAImageSet(const ImageSetEntry[], int count, const SkPoint[], const SkMatrix[],
  97. const SkPaint*, SrcRectConstraint) override;
  98. sk_sp<SkSurface> onNewSurface(const SkImageInfo&, const SkSurfaceProps&) override;
  99. void flushMiniRecorder();
  100. private:
  101. template <typename T>
  102. T* copy(const T*);
  103. template <typename T>
  104. T* copy(const T[], size_t count);
  105. template<typename T, typename... Args>
  106. void append(Args&&...);
  107. DrawPictureMode fDrawPictureMode;
  108. size_t fApproxBytesUsedBySubPictures;
  109. SkRecord* fRecord;
  110. std::unique_ptr<SkDrawableList> fDrawableList;
  111. SkMiniRecorder* fMiniRecorder;
  112. };
  113. #endif//SkRecorder_DEFINED