|
11 | 11 | #include "include/gpu/GrBackendSurface.h" |
12 | 12 | #include "include/gpu/GrContextOptions.h" |
13 | 13 | #include "include/gpu/GrDirectContext.h" |
| 14 | +#include "src/core/SkConvertPixels.h" |
14 | 15 | #include "src/gpu/GrContextPriv.h" |
15 | 16 | #include "src/gpu/GrDataUtils.h" |
16 | 17 | #include "src/gpu/GrGeometryProcessor.h" |
@@ -165,8 +166,8 @@ bool GrDawnGpu::onWritePixels(GrSurface* surface, int left, int top, int width, |
165 | 166 | if (!texture) { |
166 | 167 | return false; |
167 | 168 | } |
168 | | - texture->upload(srcColorType, texels, mipLevelCount, |
169 | | - SkIRect::MakeXYWH(left, top, width, height), this->getCopyEncoder()); |
| 169 | + this->uploadTextureData(srcColorType, texels, mipLevelCount, |
| 170 | + SkIRect::MakeXYWH(left, top, width, height), texture->texture()); |
170 | 171 | return true; |
171 | 172 | } |
172 | 173 |
|
@@ -340,6 +341,45 @@ GrBackendTexture GrDawnGpu::onCreateBackendTexture(SkISize dimensions, |
340 | 341 | return GrBackendTexture(dimensions.width(), dimensions.height(), info); |
341 | 342 | } |
342 | 343 |
|
| 344 | +void GrDawnGpu::uploadTextureData(GrColorType srcColorType, const GrMipLevel texels[], |
| 345 | + int mipLevelCount, const SkIRect& rect, |
| 346 | + wgpu::Texture texture) { |
| 347 | + uint32_t x = rect.x(); |
| 348 | + uint32_t y = rect.y(); |
| 349 | + uint32_t width = rect.width(); |
| 350 | + uint32_t height = rect.height(); |
| 351 | + |
| 352 | + for (int i = 0; i < mipLevelCount; i++) { |
| 353 | + const void* src = texels[i].fPixels; |
| 354 | + size_t srcRowBytes = texels[i].fRowBytes; |
| 355 | + SkColorType colorType = GrColorTypeToSkColorType(srcColorType); |
| 356 | + size_t trimRowBytes = width * SkColorTypeBytesPerPixel(colorType); |
| 357 | + size_t dstRowBytes = GrDawnRoundRowBytes(trimRowBytes); |
| 358 | + size_t size = dstRowBytes * height; |
| 359 | + GrStagingBufferManager::Slice slice = |
| 360 | + this->stagingBufferManager()->allocateStagingBufferSlice(size); |
| 361 | + SkRectMemcpy(slice.fOffsetMapPtr, dstRowBytes, src, srcRowBytes, trimRowBytes, height); |
| 362 | + |
| 363 | + wgpu::BufferCopyView srcBuffer = {}; |
| 364 | + srcBuffer.buffer = static_cast<GrDawnBuffer*>(slice.fBuffer)->get(); |
| 365 | + srcBuffer.layout.offset = slice.fOffset; |
| 366 | + srcBuffer.layout.bytesPerRow = dstRowBytes; |
| 367 | + srcBuffer.layout.rowsPerImage = height; |
| 368 | + |
| 369 | + wgpu::TextureCopyView dstTexture; |
| 370 | + dstTexture.texture = texture; |
| 371 | + dstTexture.mipLevel = i; |
| 372 | + dstTexture.origin = {x, y, 0}; |
| 373 | + |
| 374 | + wgpu::Extent3D copySize = {width, height, 1}; |
| 375 | + this->getCopyEncoder().CopyBufferToTexture(&srcBuffer, &dstTexture, ©Size); |
| 376 | + x /= 2; |
| 377 | + y /= 2; |
| 378 | + width = std::max(1u, width / 2); |
| 379 | + height = std::max(1u, height / 2); |
| 380 | + } |
| 381 | +} |
| 382 | + |
343 | 383 | bool GrDawnGpu::onUpdateBackendTexture(const GrBackendTexture& backendTexture, |
344 | 384 | sk_sp<GrRefCntedCallback> finishedCallback, |
345 | 385 | const BackendTextureData* data) { |
|
0 commit comments