| 1 |
/* |
| 2 |
* Copyright 2025 Google LLC |
| 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 SkCaptureCanvas_DEFINED |
| 9 |
#define SkCaptureCanvas_DEFINED |
| 10 |
|
| 11 |
#include <cstddef> |
| 12 |
#include "include/core/SkPictureRecorder.h" |
| 13 |
#include "include/utils/SkNWayCanvas.h" |
| 14 |
|
| 15 |
class SkCaptureManager; |
| 16 |
|
| 17 |
/** |
| 18 |
* SkCaptureCanvas is designed to service a subset of client capture. It wraps a base canvas and |
| 19 |
* manages the life cycle of the recording canvases used for capture. When capture starts, it will |
| 20 |
* spin up the recording canvas. On a snapSKP call, it will generate an SKP, remove the now invalid |
| 21 |
* recording canvas, and replace it with a new one. |
| 22 |
* |
| 23 |
*/ |
| 24 |
class SkCaptureCanvas : public SkNWayCanvas { |
| 25 |
public: |
| 26 |
SkCaptureCanvas(SkCanvas*, SkCaptureManager*); |
| 27 |
~SkCaptureCanvas() override; |
| 28 |
|
| 29 |
sk_sp<SkPicture> snapPicture(); |
| 30 |
|
| 31 |
protected: |
| 32 |
void willSave() override; |
| 33 |
SaveLayerStrategy getSaveLayerStrategy(const SaveLayerRec&) override; |
| 34 |
bool onDoSaveBehind(const SkRect*) override; |
| 35 |
void willRestore() override; |
| 36 |
|
| 37 |
void didConcat44(const SkM44&) override; |
| 38 |
void didSetM44(const SkM44&) override; |
| 39 |
void didScale(SkScalar, SkScalar) override; |
| 40 |
void didTranslate(SkScalar, SkScalar) override; |
| 41 |
|
| 42 |
void onDrawDRRect(const SkRRect&, const SkRRect&, const SkPaint&) override; |
| 43 |
void onDrawGlyphRunList(const sktext::GlyphRunList&, const SkPaint&) override; |
| 44 |
void onDrawTextBlob(const SkTextBlob* blob, |
| 45 |
SkScalar x, |
| 46 |
SkScalar y, |
| 47 |
const SkPaint& paint) override; |
| 48 |
void onDrawSlug(const sktext::gpu::Slug* slug, const SkPaint& paint) override; |
| 49 |
void onDrawPatch(const SkPoint cubics[12], |
| 50 |
const SkColor colors[4], |
| 51 |
const SkPoint texCoords[4], |
| 52 |
SkBlendMode, |
| 53 |
const SkPaint& paint) override; |
| 54 |
|
| 55 |
void onDrawPaint(const SkPaint&) override; |
| 56 |
void onDrawBehind(const SkPaint&) override; |
| 57 |
void onDrawPoints(PointMode, size_t count, const SkPoint pts[], const SkPaint&) override; |
| 58 |
void onDrawRect(const SkRect&, const SkPaint&) override; |
| 59 |
void onDrawRegion(const SkRegion&, const SkPaint&) override; |
| 60 |
void onDrawOval(const SkRect&, const SkPaint&) override; |
| 61 |
void onDrawArc(const SkRect&, SkScalar, SkScalar, bool, const SkPaint&) override; |
| 62 |
void onDrawRRect(const SkRRect&, const SkPaint&) override; |
| 63 |
void onDrawPath(const SkPath&, const SkPaint&) override; |
| 64 |
|
| 65 |
void onDrawImage2( |
| 66 |
const SkImage*, SkScalar, SkScalar, const SkSamplingOptions&, const SkPaint*) override; |
| 67 |
void onDrawImageRect2(const SkImage*, |
| 68 |
const SkRect&, |
| 69 |
const SkRect&, |
| 70 |
const SkSamplingOptions&, |
| 71 |
const SkPaint*, |
| 72 |
SrcRectConstraint) override; |
| 73 |
void onDrawImageLattice2( |
| 74 |
const SkImage*, const Lattice&, const SkRect&, SkFilterMode, const SkPaint*) override; |
| 75 |
void onDrawAtlas2(const SkImage*, |
| 76 |
const SkRSXform[], |
| 77 |
const SkRect[], |
| 78 |
const SkColor[], |
| 79 |
int, |
| 80 |
SkBlendMode, |
| 81 |
const SkSamplingOptions&, |
| 82 |
const SkRect*, |
| 83 |
const SkPaint*) override; |
| 84 |
|
| 85 |
void onDrawVerticesObject(const SkVertices*, SkBlendMode, const SkPaint&) override; |
| 86 |
void onDrawShadowRec(const SkPath&, const SkDrawShadowRec&) override; |
| 87 |
|
| 88 |
void onClipRect(const SkRect&, SkClipOp, ClipEdgeStyle) override; |
| 89 |
void onClipRRect(const SkRRect&, SkClipOp, ClipEdgeStyle) override; |
| 90 |
void onClipPath(const SkPath&, SkClipOp, ClipEdgeStyle) override; |
| 91 |
void onClipShader(sk_sp<SkShader>, SkClipOp) override; |
| 92 |
void onClipRegion(const SkRegion&, SkClipOp) override; |
| 93 |
void onResetClip() override; |
| 94 |
|
| 95 |
void onDrawPicture(const SkPicture*, const SkMatrix*, const SkPaint*) override; |
| 96 |
void onDrawDrawable(SkDrawable*, const SkMatrix*) override; |
| 97 |
void onDrawAnnotation(const SkRect&, const char[], SkData*) override; |
| 98 |
|
| 99 |
void onDrawEdgeAAQuad( |
| 100 |
const SkRect&, const SkPoint[4], QuadAAFlags, const SkColor4f&, SkBlendMode) override; |
| 101 |
void onDrawEdgeAAImageSet2(const ImageSetEntry[], |
| 102 |
int count, |
| 103 |
const SkPoint[], |
| 104 |
const SkMatrix[], |
| 105 |
const SkSamplingOptions&, |
| 106 |
const SkPaint*, |
| 107 |
SrcRectConstraint) override; |
| 108 |
|
| 109 |
private: |
| 110 |
void pollCapturingStatus(); |
| 111 |
void attachRecordingCanvas(); |
| 112 |
void detachRecordingCanvas(); |
| 113 |
|
| 114 |
void onSurfaceDelete() override; |
| 115 |
|
| 116 |
bool fCapturing = false; |
| 117 |
SkPictureRecorder fRecorder; |
| 118 |
SkCanvas* fBaseCanvas = nullptr; |
| 119 |
SkCaptureManager* fManager = nullptr; |
| 120 |
|
| 121 |
// Hide NWay management functions as clients shouldn't be using these directly. |
| 122 |
void addCanvas(SkCanvas* canvas) override {SkNWayCanvas::addCanvas(canvas);} |
| 123 |
void removeCanvas(SkCanvas* canvas) override {SkNWayCanvas::removeCanvas(canvas);} |
| 124 |
void removeAll() override {SkNWayCanvas::removeAll();} |
| 125 |
}; |
| 126 |
|
| 127 |
#endif // SkCaptureCanvas_DEFINED |