Brian Salomon | be1084b | 2021-01-26 13:29:30 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2021 Google LLC |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
| 8 | #include "src/gpu/GrWritePixelsRenderTask.h" |
| 9 | |
| 10 | #include "src/gpu/GrGpu.h" |
| 11 | #include "src/gpu/GrOpFlushState.h" |
| 12 | #include "src/gpu/GrResourceAllocator.h" |
| 13 | // |
| 14 | |
| 15 | sk_sp<GrRenderTask> GrWritePixelsTask::Make(GrDrawingManager* dm, |
| 16 | sk_sp<GrSurfaceProxy> dst, |
| 17 | SkIRect rect, |
| 18 | GrColorType srcColorType, |
| 19 | GrColorType dstColorType, |
| 20 | const GrMipLevel texels[], |
| 21 | int levelCount, |
| 22 | sk_sp<SkData> pixelStorage) { |
| 23 | return sk_sp<GrRenderTask>(new GrWritePixelsTask(dm, |
| 24 | std::move(dst), |
| 25 | rect, |
| 26 | srcColorType, |
| 27 | dstColorType, |
| 28 | texels, |
| 29 | levelCount, |
| 30 | std::move(pixelStorage))); |
| 31 | } |
| 32 | |
| 33 | GrWritePixelsTask::GrWritePixelsTask(GrDrawingManager* dm, |
| 34 | sk_sp<GrSurfaceProxy> dst, |
| 35 | SkIRect rect, |
| 36 | GrColorType srcColorType, |
| 37 | GrColorType dstColorType, |
| 38 | const GrMipLevel texels[], |
| 39 | int levelCount, |
| 40 | sk_sp<SkData> pixelStorage) |
| 41 | : fRect(rect) |
| 42 | , fSrcColorType(srcColorType) |
| 43 | , fDstColorType(dstColorType) |
| 44 | , fStorage(std::move(pixelStorage)) { |
| 45 | SkASSERT(fStorage); |
| 46 | this->addTarget(dm, std::move(dst)); |
| 47 | fLevels.reset(levelCount); |
| 48 | std::copy_n(texels, levelCount, fLevels.get()); |
| 49 | } |
| 50 | |
| 51 | void GrWritePixelsTask::gatherProxyIntervals(GrResourceAllocator* alloc) const { |
Adlai Holler | b80fb08 | 2021-02-08 12:47:00 -0500 | [diff] [blame] | 52 | alloc->addInterval(this->target(0), alloc->curOp(), alloc->curOp()); |
Brian Salomon | be1084b | 2021-01-26 13:29:30 -0500 | [diff] [blame] | 53 | alloc->incOps(); |
| 54 | } |
| 55 | |
| 56 | GrRenderTask::ExpectedOutcome GrWritePixelsTask::onMakeClosed(const GrCaps&, |
| 57 | SkIRect* targetUpdateBounds) { |
| 58 | *targetUpdateBounds = fRect; |
| 59 | return ExpectedOutcome::kTargetDirty; |
| 60 | } |
| 61 | |
| 62 | bool GrWritePixelsTask::onExecute(GrOpFlushState* flushState) { |
| 63 | GrSurfaceProxy* dstProxy = this->target(0); |
| 64 | if (!dstProxy->isInstantiated()) { |
| 65 | return false; |
| 66 | } |
| 67 | GrSurface* dstSurface = dstProxy->peekSurface(); |
| 68 | return flushState->gpu()->writePixels(dstSurface, |
| 69 | fRect.fLeft, |
| 70 | fRect.fTop, |
| 71 | fRect.width(), |
| 72 | fRect.height(), |
| 73 | fDstColorType, |
| 74 | fSrcColorType, |
| 75 | fLevels.get(), |
| 76 | fLevels.count()); |
| 77 | } |