[graphite] Add Recorder accessors to SkCanvas and SkSurface

Bug: skia:12845
Change-Id: Ic036dea6b58682a6463f8c34d915730c4bfe677b
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/519617
Reviewed-by: Robert Phillips <robertphillips@google.com>
Reviewed-by: Greg Daniel <egdaniel@google.com>
Commit-Queue: Jim Van Verth <jvanverth@google.com>
This commit is contained in:
Jim Van Verth 2022-03-10 14:58:13 -05:00 committed by SkCQ
parent 5fe4b6faeb
commit 6cb3f3d2c7
11 changed files with 58 additions and 7 deletions

View File

@ -38,6 +38,8 @@ public:
SkColorType, SkColorType,
SkAlphaType); SkAlphaType);
Device* asGraphiteDevice() override { return this; }
Recorder* recorder() { return fRecorder; } Recorder* recorder() { return fRecorder; }
// This call is triggered from the Recorder on its registered Devices. It is typically called // This call is triggered from the Recorder on its registered Devices. It is typically called
// when the Recorder is abandoned or deleted. // when the Recorder is abandoned or deleted.

View File

@ -21,6 +21,10 @@ Surface::Surface(sk_sp<Device> device)
Surface::~Surface() {} Surface::~Surface() {}
Recorder* Surface::onGetRecorder() {
return fDevice->recorder();
}
SkCanvas* Surface::onNewCanvas() { return new SkCanvas(fDevice); } SkCanvas* Surface::onNewCanvas() { return new SkCanvas(fDevice); }
sk_sp<SkSurface> Surface::onNewSurface(const SkImageInfo& ii) { sk_sp<SkSurface> Surface::onNewSurface(const SkImageInfo& ii) {

View File

@ -21,6 +21,7 @@ public:
Surface(sk_sp<Device>); Surface(sk_sp<Device>);
~Surface() override; ~Surface() override;
Recorder* onGetRecorder() override;
SkCanvas* onNewCanvas() override; SkCanvas* onNewCanvas() override;
sk_sp<SkSurface> onNewSurface(const SkImageInfo&) override; sk_sp<SkSurface> onNewSurface(const SkImageInfo&) override;
sk_sp<SkImage> onNewImageSnapshot(const SkIRect* subset) override; sk_sp<SkImage> onNewImageSnapshot(const SkIRect* subset) override;

View File

@ -66,6 +66,8 @@ class SkSurface_Base;
class SkTextBlob; class SkTextBlob;
class SkVertices; class SkVertices;
namespace skgpu { class Recorder; }
/** \class SkCanvas /** \class SkCanvas
SkCanvas provides an interface for drawing, and how the drawing is clipped and transformed. SkCanvas provides an interface for drawing, and how the drawing is clipped and transformed.
SkCanvas contains a stack of SkMatrix and clip values. SkCanvas contains a stack of SkMatrix and clip values.
@ -297,6 +299,12 @@ public:
*/ */
virtual GrRecordingContext* recordingContext(); virtual GrRecordingContext* recordingContext();
/** Returns Recorder for the GPU surface associated with SkCanvas.
@return Recorder, if available; nullptr otherwise
*/
virtual skgpu::Recorder* recorder();
/** Sometimes a canvas is owned by a surface. If it is, getSurface() will return a bare /** Sometimes a canvas is owned by a surface. If it is, getSurface() will return a bare
* pointer to that surface, else this will return nullptr. * pointer to that surface, else this will return nullptr.
*/ */

View File

@ -38,6 +38,8 @@ class GrRecordingContext;
class GrRenderTarget; class GrRenderTarget;
enum GrSurfaceOrigin: int; enum GrSurfaceOrigin: int;
namespace skgpu { class Recorder; }
/** \class SkSurface /** \class SkSurface
SkSurface is responsible for managing the pixels that a canvas draws into. The pixels can be SkSurface is responsible for managing the pixels that a canvas draws into. The pixels can be
allocated either in CPU memory (a raster surface) or on the GPU (a GrRenderTarget surface). allocated either in CPU memory (a raster surface) or on the GPU (a GrRenderTarget surface).
@ -517,6 +519,12 @@ public:
*/ */
GrRecordingContext* recordingContext(); GrRecordingContext* recordingContext();
/** Returns the recorder being used by the SkSurface.
@return the recorder, if available; nullptr otherwise
*/
skgpu::Recorder* recorder();
#if SK_SUPPORT_GPU #if SK_SUPPORT_GPU
enum BackendHandleAccess { enum BackendHandleAccess {
kFlushRead_BackendHandleAccess, //!< back-end object is readable kFlushRead_BackendHandleAccess, //!< back-end object is readable

View File

@ -62,6 +62,10 @@
#endif #endif
#endif #endif
#ifdef SK_GRAPHITE_ENABLED
#include "experimental/graphite/src/Device.h"
#endif
#define RETURN_ON_NULL(ptr) do { if (nullptr == (ptr)) return; } while (0) #define RETURN_ON_NULL(ptr) do { if (nullptr == (ptr)) return; } while (0)
#define RETURN_ON_FALSE(pred) do { if (!(pred)) return; } while (0) #define RETURN_ON_FALSE(pred) do { if (!(pred)) return; } while (0)
@ -1706,7 +1710,7 @@ GrBackendRenderTarget SkCanvas::topLayerBackendRenderTarget() const {
GrRecordingContext* SkCanvas::recordingContext() { GrRecordingContext* SkCanvas::recordingContext() {
#if SK_SUPPORT_GPU #if SK_SUPPORT_GPU
if (auto gpuDevice = this->topDevice()->asGpuDevice()) { if (auto gpuDevice = this->topDevice()->asGaneshDevice()) {
return gpuDevice->recordingContext(); return gpuDevice->recordingContext();
} }
#endif #endif
@ -1714,6 +1718,17 @@ GrRecordingContext* SkCanvas::recordingContext() {
return nullptr; return nullptr;
} }
skgpu::Recorder* SkCanvas::recorder() {
#ifdef SK_GRAPHITE_ENABLED
if (auto graphiteDevice = this->topDevice()->asGraphiteDevice()) {
return graphiteDevice->recorder();
}
#endif
return nullptr;
}
void SkCanvas::drawDRRect(const SkRRect& outer, const SkRRect& inner, void SkCanvas::drawDRRect(const SkRRect& outer, const SkRRect& inner,
const SkPaint& paint) { const SkPaint& paint) {
TRACE_EVENT0("skia", TRACE_FUNC); TRACE_EVENT0("skia", TRACE_FUNC);

View File

@ -117,7 +117,7 @@ void SkCanvasPriv::DrawCustomMesh(SkCanvas* canvas,
#if SK_GPU_V1 #if SK_GPU_V1
skgpu::v1::SurfaceDrawContext* SkCanvasPriv::TopDeviceSurfaceDrawContext(SkCanvas* canvas) { skgpu::v1::SurfaceDrawContext* SkCanvasPriv::TopDeviceSurfaceDrawContext(SkCanvas* canvas) {
if (auto gpuDevice = canvas->topDevice()->asGpuDevice()) { if (auto gpuDevice = canvas->topDevice()->asGaneshDevice()) {
return gpuDevice->surfaceDrawContext(); return gpuDevice->surfaceDrawContext();
} }
@ -126,7 +126,7 @@ skgpu::v1::SurfaceDrawContext* SkCanvasPriv::TopDeviceSurfaceDrawContext(SkCanva
#endif // SK_GPU_V1 #endif // SK_GPU_V1
skgpu::SurfaceFillContext* SkCanvasPriv::TopDeviceSurfaceFillContext(SkCanvas* canvas) { skgpu::SurfaceFillContext* SkCanvasPriv::TopDeviceSurfaceFillContext(SkCanvas* canvas) {
if (auto gpuDevice = canvas->topDevice()->asGpuDevice()) { if (auto gpuDevice = canvas->topDevice()->asGaneshDevice()) {
return gpuDevice->surfaceFillContext(); return gpuDevice->surfaceFillContext();
} }
@ -153,7 +153,7 @@ skgpu::SurfaceFillContext* SkCanvasPriv::TopDeviceSurfaceFillContext(SkCanvas* c
#include "src/gpu/BaseDevice.h" #include "src/gpu/BaseDevice.h"
GrRenderTargetProxy* SkCanvasPriv::TopDeviceTargetProxy(SkCanvas* canvas) { GrRenderTargetProxy* SkCanvasPriv::TopDeviceTargetProxy(SkCanvas* canvas) {
if (auto gpuDevice = canvas->topDevice()->asGpuDevice()) { if (auto gpuDevice = canvas->topDevice()->asGaneshDevice()) {
return gpuDevice->targetProxy(); return gpuDevice->targetProxy();
} }

View File

@ -33,7 +33,10 @@ class SkRasterHandleAllocator;
class SkSpecialImage; class SkSpecialImage;
namespace skif { class Mapping; } namespace skif { class Mapping; }
namespace skgpu { class BaseDevice; } namespace skgpu {
class BaseDevice;
class Device;
}
class SkBaseDevice : public SkRefCnt, public SkMatrixProvider { class SkBaseDevice : public SkRefCnt, public SkMatrixProvider {
public: public:
@ -188,7 +191,8 @@ public:
virtual bool android_utils_clipWithStencil() { return false; } virtual bool android_utils_clipWithStencil() { return false; }
virtual skgpu::BaseDevice* asGpuDevice() { return nullptr; } virtual skgpu::BaseDevice* asGaneshDevice() { return nullptr; }
virtual skgpu::Device* asGraphiteDevice() { return nullptr; }
// Ensure that non-RSXForm runs are passed to onDrawGlyphRunList. // Ensure that non-RSXForm runs are passed to onDrawGlyphRunList.
void drawGlyphRunList(SkCanvas*, const SkGlyphRunList& glyphRunList, const SkPaint& paint); void drawGlyphRunList(SkCanvas*, const SkGlyphRunList& glyphRunList, const SkPaint& paint);

View File

@ -44,7 +44,7 @@ public:
GrSurfaceProxyView readSurfaceView(); GrSurfaceProxyView readSurfaceView();
BaseDevice* asGpuDevice() override { return this; } BaseDevice* asGaneshDevice() override { return this; }
#if SK_GPU_V1 #if SK_GPU_V1
virtual v1::SurfaceDrawContext* surfaceDrawContext() { return nullptr; } virtual v1::SurfaceDrawContext* surfaceDrawContext() { return nullptr; }

View File

@ -54,6 +54,10 @@ GrRecordingContext* SkSurface_Base::onGetRecordingContext() {
return nullptr; return nullptr;
} }
skgpu::Recorder* SkSurface_Base::onGetRecorder() {
return nullptr;
}
#if SK_SUPPORT_GPU #if SK_SUPPORT_GPU
GrBackendTexture SkSurface_Base::onGetBackendTexture(BackendHandleAccess) { GrBackendTexture SkSurface_Base::onGetBackendTexture(BackendHandleAccess) {
return GrBackendTexture(); // invalid return GrBackendTexture(); // invalid
@ -318,6 +322,10 @@ GrRecordingContext* SkSurface::recordingContext() {
return asSB(this)->onGetRecordingContext(); return asSB(this)->onGetRecordingContext();
} }
skgpu::Recorder* SkSurface::recorder() {
return asSB(this)->onGetRecorder();
}
bool SkSurface::wait(int numSemaphores, const GrBackendSemaphore* waitSemaphores, bool SkSurface::wait(int numSemaphores, const GrBackendSemaphore* waitSemaphores,
bool deleteSemaphoresAfterWait) { bool deleteSemaphoresAfterWait) {
return asSB(this)->onWait(numSemaphores, waitSemaphores, deleteSemaphoresAfterWait); return asSB(this)->onWait(numSemaphores, waitSemaphores, deleteSemaphoresAfterWait);

View File

@ -21,6 +21,7 @@ public:
~SkSurface_Base() override; ~SkSurface_Base() override;
virtual GrRecordingContext* onGetRecordingContext(); virtual GrRecordingContext* onGetRecordingContext();
virtual skgpu::Recorder* onGetRecorder();
#if SK_SUPPORT_GPU #if SK_SUPPORT_GPU
virtual GrBackendTexture onGetBackendTexture(BackendHandleAccess); virtual GrBackendTexture onGetBackendTexture(BackendHandleAccess);