diff --git a/experimental/graphite/src/Device.h b/experimental/graphite/src/Device.h index 19111cf9d4..c2461d2164 100644 --- a/experimental/graphite/src/Device.h +++ b/experimental/graphite/src/Device.h @@ -38,6 +38,8 @@ public: SkColorType, SkAlphaType); + Device* asGraphiteDevice() override { return this; } + Recorder* recorder() { return fRecorder; } // This call is triggered from the Recorder on its registered Devices. It is typically called // when the Recorder is abandoned or deleted. diff --git a/experimental/graphite/src/Surface_Graphite.cpp b/experimental/graphite/src/Surface_Graphite.cpp index 7796e138d7..327d2945a7 100644 --- a/experimental/graphite/src/Surface_Graphite.cpp +++ b/experimental/graphite/src/Surface_Graphite.cpp @@ -21,6 +21,10 @@ Surface::Surface(sk_sp device) Surface::~Surface() {} +Recorder* Surface::onGetRecorder() { + return fDevice->recorder(); +} + SkCanvas* Surface::onNewCanvas() { return new SkCanvas(fDevice); } sk_sp Surface::onNewSurface(const SkImageInfo& ii) { diff --git a/experimental/graphite/src/Surface_Graphite.h b/experimental/graphite/src/Surface_Graphite.h index 0faad2459f..9f82d24038 100644 --- a/experimental/graphite/src/Surface_Graphite.h +++ b/experimental/graphite/src/Surface_Graphite.h @@ -21,6 +21,7 @@ public: Surface(sk_sp); ~Surface() override; + Recorder* onGetRecorder() override; SkCanvas* onNewCanvas() override; sk_sp onNewSurface(const SkImageInfo&) override; sk_sp onNewImageSnapshot(const SkIRect* subset) override; diff --git a/include/core/SkCanvas.h b/include/core/SkCanvas.h index b16d27aee4..f858c89403 100644 --- a/include/core/SkCanvas.h +++ b/include/core/SkCanvas.h @@ -66,6 +66,8 @@ class SkSurface_Base; class SkTextBlob; class SkVertices; +namespace skgpu { class Recorder; } + /** \class SkCanvas SkCanvas provides an interface for drawing, and how the drawing is clipped and transformed. SkCanvas contains a stack of SkMatrix and clip values. @@ -297,6 +299,12 @@ public: */ 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 * pointer to that surface, else this will return nullptr. */ diff --git a/include/core/SkSurface.h b/include/core/SkSurface.h index 14901ea5f3..9d4e82d8de 100644 --- a/include/core/SkSurface.h +++ b/include/core/SkSurface.h @@ -38,6 +38,8 @@ class GrRecordingContext; class GrRenderTarget; enum GrSurfaceOrigin: int; +namespace skgpu { class Recorder; } + /** \class SkSurface 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). @@ -517,6 +519,12 @@ public: */ GrRecordingContext* recordingContext(); + /** Returns the recorder being used by the SkSurface. + + @return the recorder, if available; nullptr otherwise + */ + skgpu::Recorder* recorder(); + #if SK_SUPPORT_GPU enum BackendHandleAccess { kFlushRead_BackendHandleAccess, //!< back-end object is readable diff --git a/src/core/SkCanvas.cpp b/src/core/SkCanvas.cpp index 4bf154977a..6f9f88a0f7 100644 --- a/src/core/SkCanvas.cpp +++ b/src/core/SkCanvas.cpp @@ -62,6 +62,10 @@ #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_FALSE(pred) do { if (!(pred)) return; } while (0) @@ -1706,7 +1710,7 @@ GrBackendRenderTarget SkCanvas::topLayerBackendRenderTarget() const { GrRecordingContext* SkCanvas::recordingContext() { #if SK_SUPPORT_GPU - if (auto gpuDevice = this->topDevice()->asGpuDevice()) { + if (auto gpuDevice = this->topDevice()->asGaneshDevice()) { return gpuDevice->recordingContext(); } #endif @@ -1714,6 +1718,17 @@ GrRecordingContext* SkCanvas::recordingContext() { 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, const SkPaint& paint) { TRACE_EVENT0("skia", TRACE_FUNC); diff --git a/src/core/SkCanvasPriv.cpp b/src/core/SkCanvasPriv.cpp index b11e9a392a..a282099d5d 100644 --- a/src/core/SkCanvasPriv.cpp +++ b/src/core/SkCanvasPriv.cpp @@ -117,7 +117,7 @@ void SkCanvasPriv::DrawCustomMesh(SkCanvas* canvas, #if SK_GPU_V1 skgpu::v1::SurfaceDrawContext* SkCanvasPriv::TopDeviceSurfaceDrawContext(SkCanvas* canvas) { - if (auto gpuDevice = canvas->topDevice()->asGpuDevice()) { + if (auto gpuDevice = canvas->topDevice()->asGaneshDevice()) { return gpuDevice->surfaceDrawContext(); } @@ -126,7 +126,7 @@ skgpu::v1::SurfaceDrawContext* SkCanvasPriv::TopDeviceSurfaceDrawContext(SkCanva #endif // SK_GPU_V1 skgpu::SurfaceFillContext* SkCanvasPriv::TopDeviceSurfaceFillContext(SkCanvas* canvas) { - if (auto gpuDevice = canvas->topDevice()->asGpuDevice()) { + if (auto gpuDevice = canvas->topDevice()->asGaneshDevice()) { return gpuDevice->surfaceFillContext(); } @@ -153,7 +153,7 @@ skgpu::SurfaceFillContext* SkCanvasPriv::TopDeviceSurfaceFillContext(SkCanvas* c #include "src/gpu/BaseDevice.h" GrRenderTargetProxy* SkCanvasPriv::TopDeviceTargetProxy(SkCanvas* canvas) { - if (auto gpuDevice = canvas->topDevice()->asGpuDevice()) { + if (auto gpuDevice = canvas->topDevice()->asGaneshDevice()) { return gpuDevice->targetProxy(); } diff --git a/src/core/SkDevice.h b/src/core/SkDevice.h index 2b2fac2381..cde2e20ad3 100644 --- a/src/core/SkDevice.h +++ b/src/core/SkDevice.h @@ -33,7 +33,10 @@ class SkRasterHandleAllocator; class SkSpecialImage; namespace skif { class Mapping; } -namespace skgpu { class BaseDevice; } +namespace skgpu { +class BaseDevice; +class Device; +} class SkBaseDevice : public SkRefCnt, public SkMatrixProvider { public: @@ -188,7 +191,8 @@ public: 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. void drawGlyphRunList(SkCanvas*, const SkGlyphRunList& glyphRunList, const SkPaint& paint); diff --git a/src/gpu/BaseDevice.h b/src/gpu/BaseDevice.h index 7c9e2c3492..7d6cdd6f10 100644 --- a/src/gpu/BaseDevice.h +++ b/src/gpu/BaseDevice.h @@ -44,7 +44,7 @@ public: GrSurfaceProxyView readSurfaceView(); - BaseDevice* asGpuDevice() override { return this; } + BaseDevice* asGaneshDevice() override { return this; } #if SK_GPU_V1 virtual v1::SurfaceDrawContext* surfaceDrawContext() { return nullptr; } diff --git a/src/image/SkSurface.cpp b/src/image/SkSurface.cpp index 9be89f36e8..b6f9d17753 100644 --- a/src/image/SkSurface.cpp +++ b/src/image/SkSurface.cpp @@ -54,6 +54,10 @@ GrRecordingContext* SkSurface_Base::onGetRecordingContext() { return nullptr; } +skgpu::Recorder* SkSurface_Base::onGetRecorder() { + return nullptr; +} + #if SK_SUPPORT_GPU GrBackendTexture SkSurface_Base::onGetBackendTexture(BackendHandleAccess) { return GrBackendTexture(); // invalid @@ -318,6 +322,10 @@ GrRecordingContext* SkSurface::recordingContext() { return asSB(this)->onGetRecordingContext(); } +skgpu::Recorder* SkSurface::recorder() { + return asSB(this)->onGetRecorder(); +} + bool SkSurface::wait(int numSemaphores, const GrBackendSemaphore* waitSemaphores, bool deleteSemaphoresAfterWait) { return asSB(this)->onWait(numSemaphores, waitSemaphores, deleteSemaphoresAfterWait); diff --git a/src/image/SkSurface_Base.h b/src/image/SkSurface_Base.h index 7c3112139d..e094422d47 100644 --- a/src/image/SkSurface_Base.h +++ b/src/image/SkSurface_Base.h @@ -21,6 +21,7 @@ public: ~SkSurface_Base() override; virtual GrRecordingContext* onGetRecordingContext(); + virtual skgpu::Recorder* onGetRecorder(); #if SK_SUPPORT_GPU virtual GrBackendTexture onGetBackendTexture(BackendHandleAccess);