Move discard and asyncRescaleAndReadPixels* to SkBaseGpuDevice
The goal here is to delegate these calls to the SkBaseGpuDevice-derived classes so SkSurface_Gpu doesn't need to know about SDCs. Bug: skia:11837 Change-Id: I28bea7ad1cf5d9fc0ce690b2bd70ff79e022f8d2 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/414998 Reviewed-by: Michael Ludwig <michaelludwig@google.com> Commit-Queue: Robert Phillips <robertphillips@google.com>
This commit is contained in:
parent
785ecad487
commit
dca342a773
@ -10,6 +10,8 @@
|
||||
|
||||
#include "src/gpu/GrSurfaceProxyView.h"
|
||||
|
||||
#include "include/core/SkImage.h"
|
||||
|
||||
// NOTE: when not defined, SkGpuDevice extends SkBaseDevice directly and manages its clip stack
|
||||
// using GrClipStack. When false, SkGpuDevice continues to extend SkClipStackDevice and uses
|
||||
// SkClipStack and GrClipStackClip to manage the clip stack.
|
||||
@ -52,6 +54,7 @@ public:
|
||||
virtual bool wait(int numSemaphores,
|
||||
const GrBackendSemaphore* waitSemaphores,
|
||||
bool deleteSemaphoresAfterWait) = 0;
|
||||
virtual void discard() = 0;
|
||||
|
||||
virtual bool replaceBackingProxy(SkSurface::ContentChangeMode,
|
||||
sk_sp<GrRenderTargetProxy>,
|
||||
@ -61,6 +64,27 @@ public:
|
||||
const SkSurfaceProps&) = 0;
|
||||
bool replaceBackingProxy(SkSurface::ContentChangeMode);
|
||||
|
||||
using RescaleGamma = SkImage::RescaleGamma;
|
||||
using RescaleMode = SkImage::RescaleMode;
|
||||
using ReadPixelsCallback = SkImage::ReadPixelsCallback;
|
||||
using ReadPixelsContext = SkImage::ReadPixelsContext;
|
||||
|
||||
virtual void asyncRescaleAndReadPixels(const SkImageInfo& info,
|
||||
const SkIRect& srcRect,
|
||||
RescaleGamma rescaleGamma,
|
||||
RescaleMode rescaleMode,
|
||||
ReadPixelsCallback callback,
|
||||
ReadPixelsContext context) = 0;
|
||||
|
||||
virtual void asyncRescaleAndReadPixelsYUV420(SkYUVColorSpace yuvColorSpace,
|
||||
sk_sp<SkColorSpace> dstColorSpace,
|
||||
const SkIRect& srcRect,
|
||||
SkISize dstSize,
|
||||
RescaleGamma rescaleGamma,
|
||||
RescaleMode,
|
||||
ReadPixelsCallback callback,
|
||||
ReadPixelsContext context) = 0;
|
||||
|
||||
protected:
|
||||
sk_sp<GrRecordingContext> fContext;
|
||||
|
||||
|
@ -994,6 +994,47 @@ bool SkGpuDevice::replaceBackingProxy(SkSurface::ContentChangeMode mode,
|
||||
return true;
|
||||
}
|
||||
|
||||
void SkGpuDevice::asyncRescaleAndReadPixels(const SkImageInfo& info,
|
||||
const SkIRect& srcRect,
|
||||
RescaleGamma rescaleGamma,
|
||||
RescaleMode rescaleMode,
|
||||
ReadPixelsCallback callback,
|
||||
ReadPixelsContext context) {
|
||||
auto* sdc = fSurfaceDrawContext.get();
|
||||
// Context TODO: Elevate direct context requirement to public API.
|
||||
auto dContext = sdc->recordingContext()->asDirectContext();
|
||||
if (!dContext) {
|
||||
return;
|
||||
}
|
||||
sdc->asyncRescaleAndReadPixels(dContext, info, srcRect, rescaleGamma, rescaleMode, callback,
|
||||
context);
|
||||
}
|
||||
|
||||
void SkGpuDevice::asyncRescaleAndReadPixelsYUV420(SkYUVColorSpace yuvColorSpace,
|
||||
sk_sp<SkColorSpace> dstColorSpace,
|
||||
const SkIRect& srcRect,
|
||||
SkISize dstSize,
|
||||
RescaleGamma rescaleGamma,
|
||||
RescaleMode rescaleMode,
|
||||
ReadPixelsCallback callback,
|
||||
ReadPixelsContext context) {
|
||||
auto* sdc = fSurfaceDrawContext.get();
|
||||
// Context TODO: Elevate direct context requirement to public API.
|
||||
auto dContext = sdc->recordingContext()->asDirectContext();
|
||||
if (!dContext) {
|
||||
return;
|
||||
}
|
||||
sdc->asyncRescaleAndReadPixelsYUV420(dContext,
|
||||
yuvColorSpace,
|
||||
std::move(dstColorSpace),
|
||||
srcRect,
|
||||
dstSize,
|
||||
rescaleGamma,
|
||||
rescaleMode,
|
||||
callback,
|
||||
context);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
SkBaseDevice* SkGpuDevice::onCreateDevice(const CreateInfo& cinfo, const SkPaint*) {
|
||||
|
@ -35,13 +35,17 @@ class SkVertices;
|
||||
class SkGpuDevice : public SkBaseGpuDevice {
|
||||
public:
|
||||
GrSurfaceProxyView readSurfaceView() override {
|
||||
return this->surfaceDrawContext()->readSurfaceView();
|
||||
return fSurfaceDrawContext->readSurfaceView();
|
||||
}
|
||||
|
||||
bool wait(int numSemaphores,
|
||||
const GrBackendSemaphore* waitSemaphores,
|
||||
bool deleteSemaphoresAfterWait) override;
|
||||
|
||||
void discard() override {
|
||||
fSurfaceDrawContext->discard();
|
||||
}
|
||||
|
||||
bool replaceBackingProxy(SkSurface::ContentChangeMode,
|
||||
sk_sp<GrRenderTargetProxy>,
|
||||
GrColorType,
|
||||
@ -50,6 +54,22 @@ public:
|
||||
const SkSurfaceProps&) override;
|
||||
using SkBaseGpuDevice::replaceBackingProxy;
|
||||
|
||||
void asyncRescaleAndReadPixels(const SkImageInfo& info,
|
||||
const SkIRect& srcRect,
|
||||
RescaleGamma rescaleGamma,
|
||||
RescaleMode rescaleMode,
|
||||
ReadPixelsCallback callback,
|
||||
ReadPixelsContext context) override;
|
||||
|
||||
void asyncRescaleAndReadPixelsYUV420(SkYUVColorSpace yuvColorSpace,
|
||||
sk_sp<SkColorSpace> dstColorSpace,
|
||||
const SkIRect& srcRect,
|
||||
SkISize dstSize,
|
||||
RescaleGamma rescaleGamma,
|
||||
RescaleMode,
|
||||
ReadPixelsCallback callback,
|
||||
ReadPixelsContext context) override;
|
||||
|
||||
/**
|
||||
* This factory uses the color space, origin, surface properties, and initialization
|
||||
* method along with the provided proxy to create the gpu device.
|
||||
|
@ -24,6 +24,34 @@ SkGpuDevice_nga::SkGpuDevice_nga(sk_sp<GrRecordingContext> rContext,
|
||||
|
||||
SkGpuDevice_nga::~SkGpuDevice_nga() {}
|
||||
|
||||
void SkGpuDevice_nga::asyncRescaleAndReadPixels(const SkImageInfo& info,
|
||||
const SkIRect& srcRect,
|
||||
RescaleGamma rescaleGamma,
|
||||
RescaleMode rescaleMode,
|
||||
ReadPixelsCallback callback,
|
||||
ReadPixelsContext context) {
|
||||
// Context TODO: Elevate direct context requirement to public API.
|
||||
auto dContext = this->recordingContext()->asDirectContext();
|
||||
if (!dContext) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void SkGpuDevice_nga::asyncRescaleAndReadPixelsYUV420(SkYUVColorSpace yuvColorSpace,
|
||||
sk_sp<SkColorSpace> dstColorSpace,
|
||||
const SkIRect& srcRect,
|
||||
SkISize dstSize,
|
||||
RescaleGamma rescaleGamma,
|
||||
RescaleMode,
|
||||
ReadPixelsCallback callback,
|
||||
ReadPixelsContext context) {
|
||||
// Context TODO: Elevate direct context requirement to public API.
|
||||
auto dContext = this->recordingContext()->asDirectContext();
|
||||
if (!dContext) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void SkGpuDevice_nga::onSave() {
|
||||
}
|
||||
|
||||
|
@ -29,6 +29,8 @@ public:
|
||||
return false;
|
||||
}
|
||||
|
||||
void discard() override {}
|
||||
|
||||
bool replaceBackingProxy(SkSurface::ContentChangeMode,
|
||||
sk_sp<GrRenderTargetProxy>,
|
||||
GrColorType,
|
||||
@ -38,6 +40,22 @@ public:
|
||||
return false;
|
||||
}
|
||||
|
||||
void asyncRescaleAndReadPixels(const SkImageInfo&,
|
||||
const SkIRect& srcRect,
|
||||
RescaleGamma,
|
||||
RescaleMode,
|
||||
ReadPixelsCallback,
|
||||
ReadPixelsContext) override;
|
||||
|
||||
void asyncRescaleAndReadPixelsYUV420(SkYUVColorSpace,
|
||||
sk_sp<SkColorSpace> dstColorSpace,
|
||||
const SkIRect& srcRect,
|
||||
SkISize dstSize,
|
||||
RescaleGamma,
|
||||
RescaleMode,
|
||||
ReadPixelsCallback,
|
||||
ReadPixelsContext) override;
|
||||
|
||||
GrSurfaceDrawContext* surfaceDrawContext() override { return nullptr; }
|
||||
|
||||
protected:
|
||||
|
@ -70,8 +70,7 @@ static GrRenderTarget* prepare_rt_for_external_access(SkSurface_Gpu* surface,
|
||||
dContext->priv().flushSurface(surface->getDevice()->targetProxy());
|
||||
|
||||
// Grab the render target *after* firing notifications, as it may get switched if CoW kicks in.
|
||||
GrSurfaceDrawContext* sdc = surface->getDevice()->surfaceDrawContext();
|
||||
return sdc->accessRenderTarget();
|
||||
return surface->getDevice()->targetProxy()->peekRenderTarget();
|
||||
}
|
||||
|
||||
GrBackendTexture SkSurface_Gpu::onGetBackendTexture(BackendHandleAccess access) {
|
||||
@ -159,14 +158,12 @@ void SkSurface_Gpu::onAsyncRescaleAndReadPixels(const SkImageInfo& info,
|
||||
RescaleMode rescaleMode,
|
||||
ReadPixelsCallback callback,
|
||||
ReadPixelsContext context) {
|
||||
auto* sdc = this->fDevice->surfaceDrawContext();
|
||||
// Context TODO: Elevate direct context requirement to public API.
|
||||
auto dContext = sdc->recordingContext()->asDirectContext();
|
||||
if (!dContext) {
|
||||
return;
|
||||
}
|
||||
sdc->asyncRescaleAndReadPixels(dContext, info, srcRect, rescaleGamma, rescaleMode, callback,
|
||||
context);
|
||||
fDevice->asyncRescaleAndReadPixels(info,
|
||||
srcRect,
|
||||
rescaleGamma,
|
||||
rescaleMode,
|
||||
callback,
|
||||
context);
|
||||
}
|
||||
|
||||
void SkSurface_Gpu::onAsyncRescaleAndReadPixelsYUV420(SkYUVColorSpace yuvColorSpace,
|
||||
@ -177,21 +174,14 @@ void SkSurface_Gpu::onAsyncRescaleAndReadPixelsYUV420(SkYUVColorSpace yuvColorSp
|
||||
RescaleMode rescaleMode,
|
||||
ReadPixelsCallback callback,
|
||||
ReadPixelsContext context) {
|
||||
auto* sdc = this->fDevice->surfaceDrawContext();
|
||||
// Context TODO: Elevate direct context requirement to public API.
|
||||
auto dContext = sdc->recordingContext()->asDirectContext();
|
||||
if (!dContext) {
|
||||
return;
|
||||
}
|
||||
sdc->asyncRescaleAndReadPixelsYUV420(dContext,
|
||||
yuvColorSpace,
|
||||
std::move(dstColorSpace),
|
||||
srcRect,
|
||||
dstSize,
|
||||
rescaleGamma,
|
||||
rescaleMode,
|
||||
callback,
|
||||
context);
|
||||
fDevice->asyncRescaleAndReadPixelsYUV420(yuvColorSpace,
|
||||
std::move(dstColorSpace),
|
||||
srcRect,
|
||||
dstSize,
|
||||
rescaleGamma,
|
||||
rescaleMode,
|
||||
callback,
|
||||
context);
|
||||
}
|
||||
|
||||
// Create a new render target and, if necessary, copy the contents of the old
|
||||
@ -212,7 +202,7 @@ void SkSurface_Gpu::onCopyOnWrite(ContentChangeMode mode) {
|
||||
}
|
||||
}
|
||||
|
||||
void SkSurface_Gpu::onDiscard() { fDevice->surfaceDrawContext()->discard(); }
|
||||
void SkSurface_Gpu::onDiscard() { fDevice->discard(); }
|
||||
|
||||
GrSemaphoresSubmitted SkSurface_Gpu::onFlush(BackendSurfaceAccess access, const GrFlushInfo& info,
|
||||
const GrBackendSurfaceMutableState* newState) {
|
||||
|
Loading…
Reference in New Issue
Block a user