| 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 SkRecordCanvas_DEFINED |
| 9 |
#define SkRecordCanvas_DEFINED |
| 10 |
|
| 11 |
#include "include/core/SkCPURecorder.h" |
| 12 |
#include "include/core/SkCanvasVirtualEnforcer.h" |
| 13 |
#include "include/core/SkColor.h" |
| 14 |
#include "include/core/SkM44.h" |
| 15 |
#include "include/core/SkRefCnt.h" |
| 16 |
#include "include/core/SkSamplingOptions.h" |
| 17 |
#include "include/core/SkScalar.h" |
| 18 |
#include "include/core/SkTypes.h" |
| 19 |
#include "include/private/base/SkNoncopyable.h" |
| 20 |
#include "include/private/base/SkTDArray.h" |
| 21 |
#include "include/utils/SkNoDrawCanvas.h" |
| 22 |
#include "src/core/SkBigPicture.h" |
| 23 |
|
| 24 |
#include <cstddef> |
| 25 |
#include <memory> |
| 26 |
#include <utility> |
| 27 |
|
| 28 |
class SkBlender; |
| 29 |
class SkData; |
| 30 |
class SkDrawable; |
| 31 |
class SkImage; |
| 32 |
class SkMatrix; |
| 33 |
class SkMesh; |
| 34 |
class SkPaint; |
| 35 |
class SkPath; |
| 36 |
class SkPicture; |
| 37 |
class SkRRect; |
| 38 |
class SkRecord; |
| 39 |
class SkRecorder; |
| 40 |
class SkRegion; |
| 41 |
class SkShader; |
| 42 |
class SkSurface; |
| 43 |
class SkSurfaceProps; |
| 44 |
class SkTextBlob; |
| 45 |
class SkVertices; |
| 46 |
enum class SkBlendMode; |
| 47 |
enum class SkClipOp; |
| 48 |
struct SkDrawShadowRec; |
| 49 |
struct SkImageInfo; |
| 50 |
struct SkPoint; |
| 51 |
struct SkRSXform; |
| 52 |
struct SkRect; |
| 53 |
|
| 54 |
namespace sktext { |
| 55 |
class GlyphRunList; |
| 56 |
namespace gpu { |
| 57 |
class Slug; |
| 58 |
} |
| 59 |
} // namespace sktext |
| 60 |
|
| 61 |
class SkDrawableList : SkNoncopyable { |
| 62 |
public: |
| 63 |
SkDrawableList() {} |
| 64 |
~SkDrawableList(); |
| 65 |
|
| 66 |
int count() const { return fArray.size(); } |
| 67 |
SkDrawable* const* begin() const { return fArray.begin(); } |
| 68 |
SkDrawable* const* end() const { return fArray.end(); } |
| 69 |
|
| 70 |
void append(SkDrawable* drawable); |
| 71 |
|
| 72 |
// Return a new or ref'd array of pictures that were snapped from our drawables. |
| 73 |
SkBigPicture::SnapshotArray* newDrawableSnapshot(); |
| 74 |
|
| 75 |
private: |
| 76 |
SkTDArray<SkDrawable*> fArray; |
| 77 |
}; |
| 78 |
|
| 79 |
// SkRecordCanvas provides an SkCanvas interface for recording into an SkRecord. |
| 80 |
|
| 81 |
class SkRecordCanvas final : public SkCanvasVirtualEnforcer<SkNoDrawCanvas> { |
| 82 |
public: |
| 83 |
// Does not take ownership of the SkRecord. |
| 84 |
SkRecordCanvas(SkRecord*, int width, int height); // TODO: remove |
| 85 |
SkRecordCanvas(SkRecord*, const SkRect& bounds); |
| 86 |
|
| 87 |
void reset(SkRecord*, const SkRect& bounds); |
| 88 |
|
| 89 |
size_t approxBytesUsedBySubPictures() const { return fApproxBytesUsedBySubPictures; } |
| 90 |
|
| 91 |
SkDrawableList* getDrawableList() const { return fDrawableList.get(); } |
| 92 |
std::unique_ptr<SkDrawableList> detachDrawableList() { return std::move(fDrawableList); } |
| 93 |
|
| 94 |
// Make SkRecordCanvas forget entirely about its SkRecord*; all calls to SkRecordCanvas will |
| 95 |
// fail. |
| 96 |
void forgetRecord(); |
| 97 |
|
| 98 |
void willSave() override; |
| 99 |
SaveLayerStrategy getSaveLayerStrategy(const SaveLayerRec&) override; |
| 100 |
bool onDoSaveBehind(const SkRect*) override; |
| 101 |
void willRestore() override {} |
| 102 |
void didRestore() override; |
| 103 |
SkRecorder* baseRecorder() const override { |
| 104 |
// TODO(kjlubick) this class should implement SkRecorder (or maybe Record should). |
| 105 |
return skcpu::Recorder::TODO(); |
| 106 |
} |
| 107 |
|
| 108 |
void didConcat44(const SkM44&) override; |
| 109 |
void didSetM44(const SkM44&) override; |
| 110 |
void didScale(SkScalar, SkScalar) override; |
| 111 |
void didTranslate(SkScalar, SkScalar) override; |
| 112 |
|
| 113 |
void onDrawDRRect(const SkRRect&, const SkRRect&, const SkPaint&) override; |
| 114 |
void onDrawDrawable(SkDrawable*, const SkMatrix*) override; |
| 115 |
void onDrawTextBlob(const SkTextBlob* blob, |
| 116 |
SkScalar x, |
| 117 |
SkScalar y, |
| 118 |
const SkPaint& paint) override; |
| 119 |
void onDrawSlug(const sktext::gpu::Slug* slug, const SkPaint& paint) override; |
| 120 |
void onDrawGlyphRunList(const sktext::GlyphRunList& glyphRunList, |
| 121 |
const SkPaint& paint) override; |
| 122 |
void onDrawPatch(const SkPoint cubics[12], |
| 123 |
const SkColor colors[4], |
| 124 |
const SkPoint texCoords[4], |
| 125 |
SkBlendMode, |
| 126 |
const SkPaint& paint) override; |
| 127 |
|
| 128 |
void onDrawPaint(const SkPaint&) override; |
| 129 |
void onDrawBehind(const SkPaint&) override; |
| 130 |
void onDrawPoints(PointMode, size_t count, const SkPoint pts[], const SkPaint&) override; |
| 131 |
void onDrawRect(const SkRect&, const SkPaint&) override; |
| 132 |
void onDrawRegion(const SkRegion&, const SkPaint&) override; |
| 133 |
void onDrawOval(const SkRect&, const SkPaint&) override; |
| 134 |
void onDrawArc(const SkRect&, SkScalar, SkScalar, bool, const SkPaint&) override; |
| 135 |
void onDrawRRect(const SkRRect&, const SkPaint&) override; |
| 136 |
void onDrawPath(const SkPath&, const SkPaint&) override; |
| 137 |
|
| 138 |
void onDrawImage2( |
| 139 |
const SkImage*, SkScalar, SkScalar, const SkSamplingOptions&, const SkPaint*) override; |
| 140 |
void onDrawImageRect2(const SkImage*, |
| 141 |
const SkRect&, |
| 142 |
const SkRect&, |
| 143 |
const SkSamplingOptions&, |
| 144 |
const SkPaint*, |
| 145 |
SrcRectConstraint) override; |
| 146 |
void onDrawImageLattice2( |
| 147 |
const SkImage*, const Lattice&, const SkRect&, SkFilterMode, const SkPaint*) override; |
| 148 |
void onDrawAtlas2(const SkImage*, |
| 149 |
const SkRSXform[], |
| 150 |
const SkRect[], |
| 151 |
const SkColor[], |
| 152 |
int, |
| 153 |
SkBlendMode, |
| 154 |
const SkSamplingOptions&, |
| 155 |
const SkRect*, |
| 156 |
const SkPaint*) override; |
| 157 |
|
| 158 |
void onDrawVerticesObject(const SkVertices*, SkBlendMode, const SkPaint&) override; |
| 159 |
|
| 160 |
void onDrawMesh(const SkMesh&, sk_sp<SkBlender>, const SkPaint&) override; |
| 161 |
|
| 162 |
void onDrawShadowRec(const SkPath&, const SkDrawShadowRec&) override; |
| 163 |
|
| 164 |
void onClipRect(const SkRect& rect, SkClipOp, ClipEdgeStyle) override; |
| 165 |
void onClipRRect(const SkRRect& rrect, SkClipOp, ClipEdgeStyle) override; |
| 166 |
void onClipPath(const SkPath& path, SkClipOp, ClipEdgeStyle) override; |
| 167 |
void onClipShader(sk_sp<SkShader>, SkClipOp) override; |
| 168 |
void onClipRegion(const SkRegion& deviceRgn, SkClipOp) override; |
| 169 |
void onResetClip() override; |
| 170 |
|
| 171 |
void onDrawPicture(const SkPicture*, const SkMatrix*, const SkPaint*) override; |
| 172 |
|
| 173 |
void onDrawAnnotation(const SkRect&, const char[], SkData*) override; |
| 174 |
|
| 175 |
void onDrawEdgeAAQuad( |
| 176 |
const SkRect&, const SkPoint[4], QuadAAFlags, const SkColor4f&, SkBlendMode) override; |
| 177 |
void onDrawEdgeAAImageSet2(const ImageSetEntry[], |
| 178 |
int count, |
| 179 |
const SkPoint[], |
| 180 |
const SkMatrix[], |
| 181 |
const SkSamplingOptions&, |
| 182 |
const SkPaint*, |
| 183 |
SrcRectConstraint) override; |
| 184 |
|
| 185 |
sk_sp<SkSurface> onNewSurface(const SkImageInfo&, const SkSurfaceProps&) override; |
| 186 |
|
| 187 |
private: |
| 188 |
template <typename T> T* copy(const T*); |
| 189 |
|
| 190 |
template <typename T> T* copy(const T[], size_t count); |
| 191 |
|
| 192 |
template <typename T, typename... Args> void append(Args&&...); |
| 193 |
|
| 194 |
size_t fApproxBytesUsedBySubPictures; |
| 195 |
SkRecord* fRecord; |
| 196 |
std::unique_ptr<SkDrawableList> fDrawableList; |
| 197 |
}; |
| 198 |
|
| 199 |
#endif // SkRecordCanvas_DEFINED |