Pass sk_sps through the GrGpu transferPixels* calls.
Currently non of the backends are directly holding ownership of the new sk_sp, but in follow on CLs will start having the buffers be tracked on the command buffer via these refs. Bug: skia:11232 Change-Id: I894f1672868061636286569d999dbe97456342a6 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/364016 Reviewed-by: Brian Salomon <bsalomon@google.com>
This commit is contained in:
parent
21d2b6a651
commit
5ad5a37784
@ -458,7 +458,7 @@ bool GrGpu::writePixels(GrSurface* surface, int left, int top, int width, int he
|
||||
|
||||
bool GrGpu::transferPixelsTo(GrTexture* texture, int left, int top, int width, int height,
|
||||
GrColorType textureColorType, GrColorType bufferColorType,
|
||||
GrGpuBuffer* transferBuffer, size_t offset, size_t rowBytes) {
|
||||
sk_sp<GrGpuBuffer> transferBuffer, size_t offset, size_t rowBytes) {
|
||||
TRACE_EVENT0("skia.gpu", TRACE_FUNC);
|
||||
SkASSERT(texture);
|
||||
SkASSERT(transferBuffer);
|
||||
@ -490,7 +490,7 @@ bool GrGpu::transferPixelsTo(GrTexture* texture, int left, int top, int width, i
|
||||
|
||||
this->handleDirtyContext();
|
||||
if (this->onTransferPixelsTo(texture, left, top, width, height, textureColorType,
|
||||
bufferColorType, transferBuffer, offset, rowBytes)) {
|
||||
bufferColorType, std::move(transferBuffer), offset, rowBytes)) {
|
||||
SkIRect rect = SkIRect::MakeXYWH(left, top, width, height);
|
||||
this->didWriteToSurface(texture, kTopLeft_GrSurfaceOrigin, &rect);
|
||||
fStats.incTransfersToTexture();
|
||||
@ -502,7 +502,7 @@ bool GrGpu::transferPixelsTo(GrTexture* texture, int left, int top, int width, i
|
||||
|
||||
bool GrGpu::transferPixelsFrom(GrSurface* surface, int left, int top, int width, int height,
|
||||
GrColorType surfaceColorType, GrColorType bufferColorType,
|
||||
GrGpuBuffer* transferBuffer, size_t offset) {
|
||||
sk_sp<GrGpuBuffer> transferBuffer, size_t offset) {
|
||||
TRACE_EVENT0("skia.gpu", TRACE_FUNC);
|
||||
SkASSERT(surface);
|
||||
SkASSERT(transferBuffer);
|
||||
@ -524,7 +524,7 @@ bool GrGpu::transferPixelsFrom(GrSurface* surface, int left, int top, int width,
|
||||
|
||||
this->handleDirtyContext();
|
||||
if (this->onTransferPixelsFrom(surface, left, top, width, height, surfaceColorType,
|
||||
bufferColorType, transferBuffer, offset)) {
|
||||
bufferColorType, std::move(transferBuffer), offset)) {
|
||||
fStats.incTransfersFromSurface();
|
||||
return true;
|
||||
}
|
||||
|
@ -302,7 +302,7 @@ public:
|
||||
*/
|
||||
bool transferPixelsTo(GrTexture* texture, int left, int top, int width, int height,
|
||||
GrColorType textureColorType, GrColorType bufferColorType,
|
||||
GrGpuBuffer* transferBuffer, size_t offset, size_t rowBytes);
|
||||
sk_sp<GrGpuBuffer> transferBuffer, size_t offset, size_t rowBytes);
|
||||
|
||||
/**
|
||||
* Reads the pixels from a rectangle of a surface into a buffer. Use
|
||||
@ -327,7 +327,7 @@ public:
|
||||
*/
|
||||
bool transferPixelsFrom(GrSurface* surface, int left, int top, int width, int height,
|
||||
GrColorType surfaceColorType, GrColorType bufferColorType,
|
||||
GrGpuBuffer* transferBuffer, size_t offset);
|
||||
sk_sp<GrGpuBuffer> transferBuffer, size_t offset);
|
||||
|
||||
// Called to perform a surface to surface copy. Fallbacks to issuing a draw from the src to dst
|
||||
// take place at higher levels and this function implement faster copy paths. The rect
|
||||
@ -849,12 +849,13 @@ private:
|
||||
// overridden by backend-specific derived class to perform the texture transfer
|
||||
virtual bool onTransferPixelsTo(GrTexture*, int left, int top, int width, int height,
|
||||
GrColorType textiueColorType, GrColorType bufferColorType,
|
||||
GrGpuBuffer* transferBuffer, size_t offset,
|
||||
sk_sp<GrGpuBuffer> transferBuffer, size_t offset,
|
||||
size_t rowBytes) = 0;
|
||||
// overridden by backend-specific derived class to perform the surface transfer
|
||||
virtual bool onTransferPixelsFrom(GrSurface*, int left, int top, int width, int height,
|
||||
GrColorType surfaceColorType, GrColorType bufferColorType,
|
||||
GrGpuBuffer* transferBuffer, size_t offset) = 0;
|
||||
sk_sp<GrGpuBuffer> transferBuffer,
|
||||
size_t offset) = 0;
|
||||
|
||||
// overridden by backend-specific derived class to perform the resolve
|
||||
virtual void onResolveRenderTarget(GrRenderTarget* target, const SkIRect& resolveRect) = 0;
|
||||
|
@ -26,5 +26,5 @@ bool GrTransferFromRenderTask::onExecute(GrOpFlushState* flushState) {
|
||||
}
|
||||
return flushState->gpu()->transferPixelsFrom(
|
||||
fSrcProxy->peekSurface(), fSrcRect.fLeft, fSrcRect.fTop, fSrcRect.width(),
|
||||
fSrcRect.height(), fSurfaceColorType, fDstColorType, fDstBuffer.get(), fDstOffset);
|
||||
fSrcRect.height(), fSurfaceColorType, fDstColorType, fDstBuffer, fDstOffset);
|
||||
}
|
||||
|
@ -176,12 +176,13 @@ private:
|
||||
|
||||
bool onTransferPixelsTo(GrTexture* texture, int left, int top, int width, int height,
|
||||
GrColorType surfaceColorType, GrColorType bufferColorType,
|
||||
GrGpuBuffer* transferBuffer, size_t offset, size_t rowBytes) override {
|
||||
sk_sp<GrGpuBuffer> transferBuffer, size_t offset,
|
||||
size_t rowBytes) override {
|
||||
return true;
|
||||
}
|
||||
bool onTransferPixelsFrom(GrSurface* surface, int left, int top, int width, int height,
|
||||
GrColorType surfaceColorType, GrColorType bufferColorType,
|
||||
GrGpuBuffer* transferBuffer, size_t offset) override {
|
||||
sk_sp<GrGpuBuffer> transferBuffer, size_t offset) override {
|
||||
return true;
|
||||
}
|
||||
bool onCopySurface(GrSurface* dst, GrSurface* src, const SkIRect& srcRect,
|
||||
|
@ -189,7 +189,7 @@ bool GrDawnGpu::onWritePixels(GrSurface* surface, int left, int top, int width,
|
||||
|
||||
bool GrDawnGpu::onTransferPixelsTo(GrTexture* texture, int left, int top, int width, int height,
|
||||
GrColorType textureColorType, GrColorType bufferColorType,
|
||||
GrGpuBuffer* transferBuffer, size_t bufferOffset,
|
||||
sk_sp<GrGpuBuffer> transferBuffer, size_t bufferOffset,
|
||||
size_t rowBytes) {
|
||||
SkASSERT(!"unimplemented");
|
||||
return false;
|
||||
@ -197,7 +197,7 @@ bool GrDawnGpu::onTransferPixelsTo(GrTexture* texture, int left, int top, int wi
|
||||
|
||||
bool GrDawnGpu::onTransferPixelsFrom(GrSurface* surface, int left, int top, int width, int height,
|
||||
GrColorType surfaceColorType, GrColorType bufferColorType,
|
||||
GrGpuBuffer* transferBuffer, size_t offset) {
|
||||
sk_sp<GrGpuBuffer> transferBuffer, size_t offset) {
|
||||
SkASSERT(!"unimplemented");
|
||||
return false;
|
||||
}
|
||||
|
@ -172,11 +172,12 @@ private:
|
||||
|
||||
bool onTransferPixelsTo(GrTexture*, int left, int top, int width, int height,
|
||||
GrColorType textureColorType, GrColorType bufferColorType,
|
||||
GrGpuBuffer* transferBuffer, size_t offset, size_t rowBytes) override;
|
||||
sk_sp<GrGpuBuffer> transferBuffer, size_t offset,
|
||||
size_t rowBytes) override;
|
||||
|
||||
bool onTransferPixelsFrom(GrSurface* surface, int left, int top, int width, int height,
|
||||
GrColorType surfaceColorType, GrColorType bufferColorType,
|
||||
GrGpuBuffer* transferBuffer, size_t offset) override;
|
||||
sk_sp<GrGpuBuffer> transferBuffer, size_t offset) override;
|
||||
|
||||
void onResolveRenderTarget(GrRenderTarget*, const SkIRect&) override {}
|
||||
|
||||
|
@ -835,7 +835,8 @@ bool GrGLGpu::onWritePixels(GrSurface* surface, int left, int top, int width, in
|
||||
|
||||
bool GrGLGpu::onTransferPixelsTo(GrTexture* texture, int left, int top, int width, int height,
|
||||
GrColorType textureColorType, GrColorType bufferColorType,
|
||||
GrGpuBuffer* transferBuffer, size_t offset, size_t rowBytes) {
|
||||
sk_sp<GrGpuBuffer> transferBuffer, size_t offset,
|
||||
size_t rowBytes) {
|
||||
GrGLTexture* glTex = static_cast<GrGLTexture*>(texture);
|
||||
|
||||
// Can't transfer compressed data
|
||||
@ -854,7 +855,7 @@ bool GrGLGpu::onTransferPixelsTo(GrTexture* texture, int left, int top, int widt
|
||||
|
||||
SkASSERT(!transferBuffer->isMapped());
|
||||
SkASSERT(!transferBuffer->isCpuBuffer());
|
||||
const GrGLBuffer* glBuffer = static_cast<const GrGLBuffer*>(transferBuffer);
|
||||
const GrGLBuffer* glBuffer = static_cast<const GrGLBuffer*>(transferBuffer.get());
|
||||
this->bindBuffer(GrGpuBufferType::kXferCpuToGpu, glBuffer);
|
||||
|
||||
SkDEBUGCODE(
|
||||
@ -906,8 +907,8 @@ bool GrGLGpu::onTransferPixelsTo(GrTexture* texture, int left, int top, int widt
|
||||
|
||||
bool GrGLGpu::onTransferPixelsFrom(GrSurface* surface, int left, int top, int width, int height,
|
||||
GrColorType surfaceColorType, GrColorType dstColorType,
|
||||
GrGpuBuffer* transferBuffer, size_t offset) {
|
||||
auto* glBuffer = static_cast<GrGLBuffer*>(transferBuffer);
|
||||
sk_sp<GrGpuBuffer> transferBuffer, size_t offset) {
|
||||
auto* glBuffer = static_cast<GrGLBuffer*>(transferBuffer.get());
|
||||
this->bindBuffer(GrGpuBufferType::kXferGpuToCpu, glBuffer);
|
||||
auto offsetAsPtr = reinterpret_cast<void*>(offset);
|
||||
return this->readOrTransferPixelsFrom(surface, left, top, width, height, surfaceColorType,
|
||||
|
@ -303,10 +303,11 @@ private:
|
||||
|
||||
bool onTransferPixelsTo(GrTexture*, int left, int top, int width, int height,
|
||||
GrColorType textureColorType, GrColorType bufferColorType,
|
||||
GrGpuBuffer* transferBuffer, size_t offset, size_t rowBytes) override;
|
||||
sk_sp<GrGpuBuffer> transferBuffer, size_t offset,
|
||||
size_t rowBytes) override;
|
||||
bool onTransferPixelsFrom(GrSurface*, int left, int top, int width, int height,
|
||||
GrColorType surfaceColorType, GrColorType bufferColorType,
|
||||
GrGpuBuffer* transferBuffer, size_t offset) override;
|
||||
sk_sp<GrGpuBuffer> transferBuffer, size_t offset) override;
|
||||
bool readOrTransferPixelsFrom(GrSurface*, int left, int top, int width, int height,
|
||||
GrColorType surfaceColorType, GrColorType dstColorType,
|
||||
void* offsetOrPtr, int rowWidthInPixels);
|
||||
|
@ -104,12 +104,13 @@ private:
|
||||
|
||||
bool onTransferPixelsTo(GrTexture* texture, int left, int top, int width, int height,
|
||||
GrColorType surfaceColorType, GrColorType bufferColorType,
|
||||
GrGpuBuffer* transferBuffer, size_t offset, size_t rowBytes) override {
|
||||
sk_sp<GrGpuBuffer> transferBuffer, size_t offset,
|
||||
size_t rowBytes) override {
|
||||
return true;
|
||||
}
|
||||
bool onTransferPixelsFrom(GrSurface* surface, int left, int top, int width, int height,
|
||||
GrColorType surfaceColorType, GrColorType bufferColorType,
|
||||
GrGpuBuffer* transferBuffer, size_t offset) override {
|
||||
sk_sp<GrGpuBuffer> transferBuffer, size_t offset) override {
|
||||
return true;
|
||||
}
|
||||
bool onCopySurface(GrSurface* dst, GrSurface* src, const SkIRect& srcRect,
|
||||
|
@ -190,11 +190,11 @@ private:
|
||||
bool prepForTexSampling) override;
|
||||
|
||||
bool onTransferPixelsTo(GrTexture*, int left, int top, int width, int height,
|
||||
GrColorType textureColorType, GrColorType bufferColorType, GrGpuBuffer*,
|
||||
size_t offset, size_t rowBytes) override;
|
||||
GrColorType textureColorType, GrColorType bufferColorType,
|
||||
sk_sp<GrGpuBuffer>, size_t offset, size_t rowBytes) override;
|
||||
bool onTransferPixelsFrom(GrSurface*, int left, int top, int width, int height,
|
||||
GrColorType surfaceColorType, GrColorType bufferColorType,
|
||||
GrGpuBuffer*, size_t offset) override;
|
||||
sk_sp<GrGpuBuffer>, size_t offset) override;
|
||||
|
||||
bool onRegenerateMipMapLevels(GrTexture*) override;
|
||||
|
||||
|
@ -1259,7 +1259,8 @@ bool GrMtlGpu::onReadPixels(GrSurface* surface, int left, int top, int width, in
|
||||
|
||||
bool GrMtlGpu::onTransferPixelsTo(GrTexture* texture, int left, int top, int width, int height,
|
||||
GrColorType textureColorType, GrColorType bufferColorType,
|
||||
GrGpuBuffer* transferBuffer, size_t offset, size_t rowBytes) {
|
||||
sk_sp<GrGpuBuffer> transferBuffer, size_t offset,
|
||||
size_t rowBytes) {
|
||||
SkASSERT(texture);
|
||||
SkASSERT(transferBuffer);
|
||||
if (textureColorType != bufferColorType) {
|
||||
@ -1270,7 +1271,7 @@ bool GrMtlGpu::onTransferPixelsTo(GrTexture* texture, int left, int top, int wid
|
||||
id<MTLTexture> mtlTexture = grMtlTexture->mtlTexture();
|
||||
SkASSERT(mtlTexture);
|
||||
|
||||
GrMtlBuffer* grMtlBuffer = static_cast<GrMtlBuffer*>(transferBuffer);
|
||||
GrMtlBuffer* grMtlBuffer = static_cast<GrMtlBuffer*>(transferBuffer.get());
|
||||
id<MTLBuffer> mtlBuffer = grMtlBuffer->mtlBuffer();
|
||||
SkASSERT(mtlBuffer);
|
||||
|
||||
@ -1300,7 +1301,7 @@ bool GrMtlGpu::onTransferPixelsTo(GrTexture* texture, int left, int top, int wid
|
||||
|
||||
bool GrMtlGpu::onTransferPixelsFrom(GrSurface* surface, int left, int top, int width, int height,
|
||||
GrColorType surfaceColorType, GrColorType bufferColorType,
|
||||
GrGpuBuffer* transferBuffer, size_t offset) {
|
||||
sk_sp<GrGpuBuffer> transferBuffer, size_t offset) {
|
||||
SkASSERT(surface);
|
||||
SkASSERT(transferBuffer);
|
||||
|
||||
@ -1317,7 +1318,7 @@ bool GrMtlGpu::onTransferPixelsFrom(GrSurface* surface, int left, int top, int w
|
||||
return false;
|
||||
}
|
||||
|
||||
GrMtlBuffer* grMtlBuffer = static_cast<GrMtlBuffer*>(transferBuffer);
|
||||
GrMtlBuffer* grMtlBuffer = static_cast<GrMtlBuffer*>(transferBuffer.get());
|
||||
|
||||
size_t transBufferRowBytes = bpp * width;
|
||||
size_t transBufferImageBytes = transBufferRowBytes * height;
|
||||
|
@ -473,7 +473,7 @@ bool GrVkGpu::onWritePixels(GrSurface* surface, int left, int top, int width, in
|
||||
|
||||
bool GrVkGpu::onTransferPixelsTo(GrTexture* texture, int left, int top, int width, int height,
|
||||
GrColorType surfaceColorType, GrColorType bufferColorType,
|
||||
GrGpuBuffer* transferBuffer, size_t bufferOffset,
|
||||
sk_sp<GrGpuBuffer> transferBuffer, size_t bufferOffset,
|
||||
size_t rowBytes) {
|
||||
if (!this->currentCommandBuffer()) {
|
||||
return false;
|
||||
@ -499,7 +499,7 @@ bool GrVkGpu::onTransferPixelsTo(GrTexture* texture, int left, int top, int widt
|
||||
// Can't transfer compressed data
|
||||
SkASSERT(!GrVkFormatIsCompressed(vkTex->imageFormat()));
|
||||
|
||||
GrVkTransferBuffer* vkBuffer = static_cast<GrVkTransferBuffer*>(transferBuffer);
|
||||
GrVkTransferBuffer* vkBuffer = static_cast<GrVkTransferBuffer*>(transferBuffer.get());
|
||||
if (!vkBuffer) {
|
||||
return false;
|
||||
}
|
||||
@ -541,7 +541,7 @@ bool GrVkGpu::onTransferPixelsTo(GrTexture* texture, int left, int top, int widt
|
||||
|
||||
bool GrVkGpu::onTransferPixelsFrom(GrSurface* surface, int left, int top, int width, int height,
|
||||
GrColorType surfaceColorType, GrColorType bufferColorType,
|
||||
GrGpuBuffer* transferBuffer, size_t offset) {
|
||||
sk_sp<GrGpuBuffer> transferBuffer, size_t offset) {
|
||||
if (!this->currentCommandBuffer()) {
|
||||
return false;
|
||||
}
|
||||
@ -554,7 +554,7 @@ bool GrVkGpu::onTransferPixelsFrom(GrSurface* surface, int left, int top, int wi
|
||||
return false;
|
||||
}
|
||||
|
||||
GrVkTransferBuffer* vkBuffer = static_cast<GrVkTransferBuffer*>(transferBuffer);
|
||||
GrVkTransferBuffer* vkBuffer = static_cast<GrVkTransferBuffer*>(transferBuffer.get());
|
||||
|
||||
GrVkImage* srcImage;
|
||||
if (GrVkRenderTarget* rt = static_cast<GrVkRenderTarget*>(surface->asRenderTarget())) {
|
||||
|
@ -270,10 +270,11 @@ private:
|
||||
|
||||
bool onTransferPixelsTo(GrTexture*, int left, int top, int width, int height,
|
||||
GrColorType textureColorType, GrColorType bufferColorType,
|
||||
GrGpuBuffer* transferBuffer, size_t offset, size_t rowBytes) override;
|
||||
sk_sp<GrGpuBuffer> transferBuffer, size_t offset,
|
||||
size_t rowBytes) override;
|
||||
bool onTransferPixelsFrom(GrSurface* surface, int left, int top, int width, int height,
|
||||
GrColorType surfaceColorType, GrColorType bufferColorType,
|
||||
GrGpuBuffer* transferBuffer, size_t offset) override;
|
||||
sk_sp<GrGpuBuffer> transferBuffer, size_t offset) override;
|
||||
|
||||
bool onCopySurface(GrSurface* dst, GrSurface* src, const SkIRect& srcRect,
|
||||
const SkIPoint& dstPoint) override;
|
||||
|
@ -168,7 +168,7 @@ void basic_transfer_to_test(skiatest::Reporter* reporter,
|
||||
|
||||
bool result;
|
||||
result = gpu->transferPixelsTo(tex.get(), 0, 0, kTexDims.fWidth, kTexDims.fHeight, colorType,
|
||||
allowedSrc.fColorType, buffer.get(), 0, srcRowBytes);
|
||||
allowedSrc.fColorType, buffer, 0, srcRowBytes);
|
||||
REPORTER_ASSERT(reporter, result);
|
||||
|
||||
size_t dstRowBytes = GrColorTypeBytesPerPixel(colorType) * kTexDims.fWidth;
|
||||
@ -227,10 +227,10 @@ void basic_transfer_to_test(skiatest::Reporter* reporter,
|
||||
buffer->unmap();
|
||||
|
||||
result = gpu->transferPixelsTo(tex.get(), left, top, width, height, colorType,
|
||||
allowedSrc.fColorType, buffer.get(), offset, srcRowBytes);
|
||||
allowedSrc.fColorType, buffer, offset, srcRowBytes);
|
||||
if (!result) {
|
||||
gpu->transferPixelsTo(tex.get(), left, top, width, height, colorType, allowedSrc.fColorType,
|
||||
buffer.get(), offset, srcRowBytes);
|
||||
buffer, offset, srcRowBytes);
|
||||
ERRORF(reporter, "Could not transfer pixels to texture, color type: %d",
|
||||
static_cast<int>(colorType));
|
||||
return;
|
||||
@ -327,7 +327,7 @@ void basic_transfer_from_test(skiatest::Reporter* reporter, const sk_gpu_test::C
|
||||
//////////////////////////
|
||||
// transfer full data
|
||||
bool result = gpu->transferPixelsFrom(tex.get(), 0, 0, kTexDims.fWidth, kTexDims.fHeight,
|
||||
colorType, allowedRead.fColorType, buffer.get(), 0);
|
||||
colorType, allowedRead.fColorType, buffer, 0);
|
||||
if (!result) {
|
||||
ERRORF(reporter, "transferPixelsFrom failed.");
|
||||
return;
|
||||
@ -368,7 +368,7 @@ void basic_transfer_from_test(skiatest::Reporter* reporter, const sk_gpu_test::C
|
||||
// Now test a partial read at an offset into the buffer.
|
||||
result = gpu->transferPixelsFrom(tex.get(), kPartialLeft, kPartialTop, kPartialWidth,
|
||||
kPartialHeight, colorType, allowedRead.fColorType,
|
||||
buffer.get(), partialReadOffset);
|
||||
buffer, partialReadOffset);
|
||||
if (!result) {
|
||||
ERRORF(reporter, "transferPixelsFrom failed.");
|
||||
return;
|
||||
|
Loading…
Reference in New Issue
Block a user