Dawn: update to recent GrGpu/CopySurface changes.

Move all GrSurface copying to GrDawnGpu (refactoring
getDawnTextureFromSurface out of existing code).

Change-Id: I7d18530f6c32d224db1af2719d9d8fc59e755451
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/236916
Commit-Queue: Stephen White <senorblanco@chromium.org>
Reviewed-by: Robert Phillips <robertphillips@google.com>
This commit is contained in:
Stephen White 2019-08-23 15:11:27 -04:00 committed by Skia Commit-Bot
parent d971882c8f
commit e8a2c8053d
4 changed files with 33 additions and 124 deletions

View File

@ -410,13 +410,40 @@ void GrDawnGpu::onFinishFlush(GrSurfaceProxy*[], int n, SkSurface::BackendSurfac
SkASSERT(!"unimplemented");
}
static dawn::Texture get_dawn_texture_from_surface(GrSurface* src) {
if (auto rt = static_cast<GrDawnRenderTarget*>(src->asRenderTarget())) {
return rt->texture();
} else if (auto t = static_cast<GrDawnTexture*>(src->asTexture())) {
return t->texture();
} else {
return nullptr;
}
}
bool GrDawnGpu::onCopySurface(GrSurface* dst,
GrSurface* src,
const SkIRect& srcRect,
const SkIPoint& dstPoint,
bool canDiscardOutsideDstRect) {
SkASSERT(!"unimplemented");
return false;
const SkIPoint& dstPoint) {
dawn::Texture srcTexture = get_dawn_texture_from_surface(src);
dawn::Texture dstTexture = get_dawn_texture_from_surface(dst);
if (!srcTexture || !dstTexture) {
return false;
}
uint32_t width = srcRect.width(), height = srcRect.height();
dawn::TextureCopyView srcTextureView, dstTextureView;
srcTextureView.texture = srcTexture;
srcTextureView.origin = {(uint32_t) srcRect.x(), (uint32_t) srcRect.y(), 0};
dstTextureView.texture = dstTexture;
dstTextureView.origin = {(uint32_t) dstPoint.x(), (uint32_t) dstPoint.y(), 0};
dawn::Extent3D copySize = {width, height, 1};
auto encoder = device().CreateCommandEncoder();
encoder.CopyTextureToTexture(&srcTextureView, &dstTextureView, &copySize);
auto commandBuffer = encoder.Finish();
this->queue().Submit(1, &commandBuffer);
return true;
}
static void callback(DawnBufferMapAsyncStatus status, const void* data, uint64_t dataLength,
@ -427,14 +454,7 @@ static void callback(DawnBufferMapAsyncStatus status, const void* data, uint64_t
bool GrDawnGpu::onReadPixels(GrSurface* surface, int left, int top, int width, int height,
GrColorType surfaceColorType, GrColorType dstColorType, void* buffer,
size_t rowBytes) {
dawn::Texture tex;
if (auto rt = static_cast<GrDawnRenderTarget*>(surface->asRenderTarget())) {
tex = rt->texture();
} else if (auto t = static_cast<GrDawnTexture*>(surface->asTexture())) {
tex = t->texture();
} else {
return false;
}
dawn::Texture tex = get_dawn_texture_from_surface(surface);
if (0 == rowBytes) {
return false;

View File

@ -139,8 +139,7 @@ private:
bool onRegenerateMipMapLevels(GrTexture*) override;
bool onCopySurface(GrSurface* dst, GrSurface* src,
const SkIRect& srcRect, const SkIPoint& dstPoint,
bool canDiscardOutsideDstRect) override;
const SkIRect& srcRect, const SkIPoint& dstPoint) override;
void onFinishFlush(GrSurfaceProxy*[], int n, SkSurface::BackendSurfaceAccess access,
const GrFlushInfo& info, const GrPrepareForExternalIORequests&) override;

View File

@ -30,49 +30,6 @@ GrDawnGpuTextureCommandBuffer::GrDawnGpuTextureCommandBuffer(GrDawnGpu* gpu,
fEncoder = fGpu->device().CreateCommandEncoder();
}
void GrDawnGpuTextureCommandBuffer::copy(GrSurface* src, const SkIRect& srcRect,
const SkIPoint& dstPoint) {
if (!src->asTexture()) {
return;
}
uint32_t width = srcRect.width(), height = srcRect.height();
size_t rowBytes = srcRect.width() * GrBytesPerPixel(src->config());
rowBytes = GrDawnRoundRowBytes(rowBytes);
size_t sizeInBytes = height * rowBytes;
dawn::BufferDescriptor desc;
desc.usage = dawn::BufferUsageBit::CopySrc | dawn::BufferUsageBit::CopyDst;
desc.size = sizeInBytes;
dawn::Buffer buffer = fGpu->device().CreateBuffer(&desc);
dawn::TextureCopyView srcTextureView, dstTextureView;
srcTextureView.texture = static_cast<GrDawnTexture*>(src->asTexture())->texture();
srcTextureView.origin = {(uint32_t) srcRect.x(), (uint32_t) srcRect.y(), 0};
dstTextureView.texture = static_cast<GrDawnTexture*>(fTexture)->texture();
dstTextureView.origin = {(uint32_t) dstPoint.x(), (uint32_t) dstPoint.y(), 0};
dawn::BufferCopyView bufferView;
bufferView.buffer = buffer;
bufferView.offset = 0;
bufferView.rowPitch = rowBytes;
bufferView.imageHeight = height;
dawn::Extent3D copySize = {width, height, 1};
fEncoder.CopyTextureToBuffer(&srcTextureView, &bufferView, &copySize);
fEncoder.CopyBufferToTexture(&bufferView, &dstTextureView, &copySize);
}
void GrDawnGpuTextureCommandBuffer::transferFrom(const SkIRect& srcRect,
GrColorType surfaceColorType,
GrColorType bufferColorType,
GrGpuBuffer* transferBuffer,
size_t offset) {
fGpu->transferPixelsFrom(fTexture, srcRect.fLeft, srcRect.fTop, srcRect.width(),
srcRect.height(), surfaceColorType, bufferColorType, transferBuffer,
offset);
}
void GrDawnGpuTextureCommandBuffer::submit() {
dawn::CommandBuffer commandBuffer = fEncoder.Finish();
if (commandBuffer) {
@ -169,14 +126,6 @@ void GrDawnGpuRTCommandBuffer::insertEventMarker(const char* msg) {
SkASSERT(!"unimplemented");
}
void GrDawnGpuRTCommandBuffer::transferFrom(const SkIRect& srcRect, GrColorType surfaceColorType,
GrColorType bufferColorType,
GrGpuBuffer* transferBuffer, size_t offset) {
fGpu->transferPixelsFrom(fRenderTarget, srcRect.fLeft, srcRect.fTop, srcRect.width(),
srcRect.height(), surfaceColorType, bufferColorType, transferBuffer,
offset);
}
void GrDawnGpuRTCommandBuffer::onClearStencilClip(const GrFixedClip& clip, bool insideStencilMask) {
fPassEncoder.EndPass();
fPassEncoder = beginRenderPass(dawn::LoadOp::Load, dawn::LoadOp::Clear);
@ -194,55 +143,6 @@ void GrDawnGpuRTCommandBuffer::inlineUpload(GrOpFlushState* state,
SkASSERT(!"unimplemented");
}
void GrDawnGpuRTCommandBuffer::copy(GrSurface* src, const SkIRect& srcRect,
const SkIPoint& dstPoint) {
auto s = static_cast<GrDawnTexture*>(src->asTexture());
auto d = static_cast<GrDawnTexture*>(fRenderTarget->asTexture());
if (!s || !d) {
return;
}
dawn::Texture srcTex = s->texture();
dawn::Texture dstTex = d->texture();
uint32_t x = srcRect.x();
uint32_t y = srcRect.y();
uint32_t width = srcRect.width();
uint32_t height = srcRect.height();
int rowPitch = GrDawnRoundRowBytes(width * GrBytesPerPixel(src->config()));
int sizeInBytes = rowPitch * height;
dawn::BufferDescriptor desc;
desc.usage = dawn::BufferUsageBit::CopySrc | dawn::BufferUsageBit::CopyDst;
desc.size = sizeInBytes;
dawn::Buffer buffer = fGpu->device().CreateBuffer(&desc);
uint32_t dstX = dstPoint.x();
uint32_t dstY = dstPoint.y();
fPassEncoder.EndPass();
dawn::TextureCopyView srcTextureCopyView;
srcTextureCopyView.texture = srcTex;
srcTextureCopyView.origin = {x, y, 0};
dawn::TextureCopyView dstTextureCopyView;
dstTextureCopyView.texture = dstTex;
dstTextureCopyView.origin = {dstX, dstY, 0};
dawn::BufferCopyView bufferCopyView;
bufferCopyView.buffer = buffer;
bufferCopyView.offset = 0;
bufferCopyView.rowPitch = rowPitch;
bufferCopyView.imageHeight = height;
dawn::Extent3D copySize = {width, height, 1};
fEncoder.CopyTextureToBuffer(&srcTextureCopyView, &bufferCopyView, &copySize);
fEncoder.CopyBufferToTexture(&bufferCopyView, &dstTextureCopyView, &copySize);
fPassEncoder = beginRenderPass(dawn::LoadOp::Load, dawn::LoadOp::Load);
}
////////////////////////////////////////////////////////////////////////////////
static dawn::VertexFormat to_dawn_vertex_format(GrVertexAttribType type) {

View File

@ -23,11 +23,6 @@ public:
GrDawnGpuTextureCommandBuffer(GrDawnGpu* gpu, GrTexture* texture, GrSurfaceOrigin origin);
~GrDawnGpuTextureCommandBuffer() override;
void copy(GrSurface* src, const SkIRect& srcRect, const SkIPoint& dstPoint) override;
void transferFrom(const SkIRect& srcRect, GrColorType surfaceColorType,
GrColorType bufferColorType, GrGpuBuffer* transferBuffer,
size_t offset) override;
void insertEventMarker(const char*) override {}
void submit();
@ -50,15 +45,10 @@ public:
void end() override;
dawn::RenderPassEncoder beginRenderPass(dawn::LoadOp colorOp, dawn::LoadOp stencilOp);
void transferFrom(const SkIRect& srcRect, GrColorType surfaceColorType,
GrColorType bufferColorType, GrGpuBuffer* transferBuffer,
size_t offset) override;
void insertEventMarker(const char*) override;
void inlineUpload(GrOpFlushState* state, GrDeferredTextureUploadFn& upload) override;
void copy(GrSurface* src, const SkIRect& srcRect, const SkIPoint& dstPoint) override;
void submit();
private: