Dawn: refactor texture uploading from GrDawnTexture to GrDawnGpu.
We'll need this for a proper implementation of onUpdateBackendTexture(). Change-Id: I4b9ac93934ef39ed3c82a55f7d74fc1f826f7740 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/323558 Reviewed-by: Greg Daniel <egdaniel@google.com> Commit-Queue: Stephen White <senorblanco@google.com>
This commit is contained in:
parent
041fd0ad7d
commit
38e6d226f2
@ -11,6 +11,7 @@
|
||||
#include "include/gpu/GrBackendSurface.h"
|
||||
#include "include/gpu/GrContextOptions.h"
|
||||
#include "include/gpu/GrDirectContext.h"
|
||||
#include "src/core/SkConvertPixels.h"
|
||||
#include "src/gpu/GrContextPriv.h"
|
||||
#include "src/gpu/GrDataUtils.h"
|
||||
#include "src/gpu/GrGeometryProcessor.h"
|
||||
@ -165,8 +166,8 @@ bool GrDawnGpu::onWritePixels(GrSurface* surface, int left, int top, int width,
|
||||
if (!texture) {
|
||||
return false;
|
||||
}
|
||||
texture->upload(srcColorType, texels, mipLevelCount,
|
||||
SkIRect::MakeXYWH(left, top, width, height), this->getCopyEncoder());
|
||||
this->uploadTextureData(srcColorType, texels, mipLevelCount,
|
||||
SkIRect::MakeXYWH(left, top, width, height), texture->texture());
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -340,6 +341,45 @@ GrBackendTexture GrDawnGpu::onCreateBackendTexture(SkISize dimensions,
|
||||
return GrBackendTexture(dimensions.width(), dimensions.height(), info);
|
||||
}
|
||||
|
||||
void GrDawnGpu::uploadTextureData(GrColorType srcColorType, const GrMipLevel texels[],
|
||||
int mipLevelCount, const SkIRect& rect,
|
||||
wgpu::Texture texture) {
|
||||
uint32_t x = rect.x();
|
||||
uint32_t y = rect.y();
|
||||
uint32_t width = rect.width();
|
||||
uint32_t height = rect.height();
|
||||
|
||||
for (int i = 0; i < mipLevelCount; i++) {
|
||||
const void* src = texels[i].fPixels;
|
||||
size_t srcRowBytes = texels[i].fRowBytes;
|
||||
SkColorType colorType = GrColorTypeToSkColorType(srcColorType);
|
||||
size_t trimRowBytes = width * SkColorTypeBytesPerPixel(colorType);
|
||||
size_t dstRowBytes = GrDawnRoundRowBytes(trimRowBytes);
|
||||
size_t size = dstRowBytes * height;
|
||||
GrStagingBufferManager::Slice slice =
|
||||
this->stagingBufferManager()->allocateStagingBufferSlice(size);
|
||||
SkRectMemcpy(slice.fOffsetMapPtr, dstRowBytes, src, srcRowBytes, trimRowBytes, height);
|
||||
|
||||
wgpu::BufferCopyView srcBuffer = {};
|
||||
srcBuffer.buffer = static_cast<GrDawnBuffer*>(slice.fBuffer)->get();
|
||||
srcBuffer.layout.offset = slice.fOffset;
|
||||
srcBuffer.layout.bytesPerRow = dstRowBytes;
|
||||
srcBuffer.layout.rowsPerImage = height;
|
||||
|
||||
wgpu::TextureCopyView dstTexture;
|
||||
dstTexture.texture = texture;
|
||||
dstTexture.mipLevel = i;
|
||||
dstTexture.origin = {x, y, 0};
|
||||
|
||||
wgpu::Extent3D copySize = {width, height, 1};
|
||||
this->getCopyEncoder().CopyBufferToTexture(&srcBuffer, &dstTexture, ©Size);
|
||||
x /= 2;
|
||||
y /= 2;
|
||||
width = std::max(1u, width / 2);
|
||||
height = std::max(1u, height / 2);
|
||||
}
|
||||
}
|
||||
|
||||
bool GrDawnGpu::onUpdateBackendTexture(const GrBackendTexture& backendTexture,
|
||||
sk_sp<GrRefCntedCallback> finishedCallback,
|
||||
const BackendTextureData* data) {
|
||||
|
@ -198,6 +198,9 @@ private:
|
||||
|
||||
bool onSubmitToGpu(bool syncCpu) override;
|
||||
|
||||
void uploadTextureData(GrColorType srcColorType, const GrMipLevel texels[], int mipLevelCount,
|
||||
const SkIRect& rect, wgpu::Texture texture);
|
||||
|
||||
void moveStagingBuffersToBusyAndMapAsync();
|
||||
void checkForCompletedStagingBuffers();
|
||||
|
||||
|
@ -7,7 +7,6 @@
|
||||
|
||||
#include "src/gpu/dawn/GrDawnTexture.h"
|
||||
|
||||
#include "src/core/SkConvertPixels.h"
|
||||
#include "src/gpu/dawn/GrDawnGpu.h"
|
||||
#include "src/gpu/dawn/GrDawnTextureRenderTarget.h"
|
||||
#include "src/gpu/dawn/GrDawnUtil.h"
|
||||
@ -113,50 +112,3 @@ void GrDawnTexture::onAbandon() {
|
||||
GrBackendTexture GrDawnTexture::getBackendTexture() const {
|
||||
return GrBackendTexture(this->width(), this->height(), fInfo);
|
||||
}
|
||||
|
||||
void GrDawnTexture::upload(GrColorType srcColorType, const GrMipLevel texels[],
|
||||
int mipLevels, wgpu::CommandEncoder copyEncoder) {
|
||||
this->upload(srcColorType, texels, mipLevels, SkIRect::MakeWH(width(), height()),
|
||||
copyEncoder);
|
||||
}
|
||||
|
||||
void GrDawnTexture::upload(GrColorType srcColorType, const GrMipLevel texels[],
|
||||
int mipLevels, const SkIRect& rect,
|
||||
wgpu::CommandEncoder copyEncoder) {
|
||||
wgpu::Device device = this->getDawnGpu()->device();
|
||||
|
||||
uint32_t x = rect.x();
|
||||
uint32_t y = rect.y();
|
||||
uint32_t width = rect.width();
|
||||
uint32_t height = rect.height();
|
||||
|
||||
for (int i = 0; i < mipLevels; i++) {
|
||||
const void* src = texels[i].fPixels;
|
||||
size_t srcRowBytes = texels[i].fRowBytes;
|
||||
SkColorType colorType = GrColorTypeToSkColorType(srcColorType);
|
||||
size_t trimRowBytes = width * SkColorTypeBytesPerPixel(colorType);
|
||||
size_t dstRowBytes = GrDawnRoundRowBytes(trimRowBytes);
|
||||
size_t size = dstRowBytes * height;
|
||||
GrStagingBufferManager::Slice slice =
|
||||
this->getDawnGpu()->stagingBufferManager()->allocateStagingBufferSlice(size);
|
||||
SkRectMemcpy(slice.fOffsetMapPtr, dstRowBytes, src, srcRowBytes, trimRowBytes, height);
|
||||
|
||||
wgpu::BufferCopyView srcBuffer = {};
|
||||
srcBuffer.buffer = static_cast<GrDawnBuffer*>(slice.fBuffer)->get();
|
||||
srcBuffer.layout.offset = slice.fOffset;
|
||||
srcBuffer.layout.bytesPerRow = dstRowBytes;
|
||||
srcBuffer.layout.rowsPerImage = height;
|
||||
|
||||
wgpu::TextureCopyView dstTexture;
|
||||
dstTexture.texture = fInfo.fTexture;
|
||||
dstTexture.mipLevel = i;
|
||||
dstTexture.origin = {x, y, 0};
|
||||
|
||||
wgpu::Extent3D copySize = {width, height, 1};
|
||||
copyEncoder.CopyBufferToTexture(&srcBuffer, &dstTexture, ©Size);
|
||||
x /= 2;
|
||||
y /= 2;
|
||||
width = std::max(1u, width / 2);
|
||||
height = std::max(1u, height / 2);
|
||||
}
|
||||
}
|
||||
|
@ -31,11 +31,6 @@ public:
|
||||
|
||||
void textureParamsModified() override {}
|
||||
|
||||
void upload(GrColorType, const GrMipLevel texels[], int mipLevels,
|
||||
wgpu::CommandEncoder copyEncoder);
|
||||
void upload(GrColorType, const GrMipLevel texels[], int mipLevels,
|
||||
const SkIRect& dstRect, wgpu::CommandEncoder copyEncoder);
|
||||
|
||||
wgpu::Texture texture() const { return fInfo.fTexture; }
|
||||
protected:
|
||||
GrDawnTexture(GrDawnGpu*, SkISize dimensions, const GrDawnTextureInfo&, GrMipmapStatus);
|
||||
|
Loading…
Reference in New Issue
Block a user