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" |
Brian Salomon | be1084b | 2021-01-26 13:29:30 -0500 | [diff] [blame] | 13 | |
| 14 | sk_sp<GrRenderTask> GrWritePixelsTask::Make(GrDrawingManager* dm, |
| 15 | sk_sp<GrSurfaceProxy> dst, |
| 16 | SkIRect rect, |
| 17 | GrColorType srcColorType, |
| 18 | GrColorType dstColorType, |
| 19 | const GrMipLevel texels[], |
Brian Salomon | 2c67340 | 2021-04-02 14:36:58 -0400 | [diff] [blame^] | 20 | int levelCount) { |
Brian Salomon | be1084b | 2021-01-26 13:29:30 -0500 | [diff] [blame] | 21 | return sk_sp<GrRenderTask>(new GrWritePixelsTask(dm, |
| 22 | std::move(dst), |
| 23 | rect, |
| 24 | srcColorType, |
| 25 | dstColorType, |
| 26 | texels, |
Brian Salomon | 2c67340 | 2021-04-02 14:36:58 -0400 | [diff] [blame^] | 27 | levelCount)); |
Brian Salomon | be1084b | 2021-01-26 13:29:30 -0500 | [diff] [blame] | 28 | } |
| 29 | |
| 30 | GrWritePixelsTask::GrWritePixelsTask(GrDrawingManager* dm, |
| 31 | sk_sp<GrSurfaceProxy> dst, |
| 32 | SkIRect rect, |
| 33 | GrColorType srcColorType, |
| 34 | GrColorType dstColorType, |
| 35 | const GrMipLevel texels[], |
Brian Salomon | 2c67340 | 2021-04-02 14:36:58 -0400 | [diff] [blame^] | 36 | int levelCount) |
| 37 | : fRect(rect), fSrcColorType(srcColorType), fDstColorType(dstColorType) { |
Brian Salomon | be1084b | 2021-01-26 13:29:30 -0500 | [diff] [blame] | 38 | this->addTarget(dm, std::move(dst)); |
| 39 | fLevels.reset(levelCount); |
| 40 | std::copy_n(texels, levelCount, fLevels.get()); |
| 41 | } |
| 42 | |
| 43 | void GrWritePixelsTask::gatherProxyIntervals(GrResourceAllocator* alloc) const { |
Adlai Holler | 7f7a5df | 2021-02-09 17:41:10 +0000 | [diff] [blame] | 44 | alloc->addInterval(this->target(0), alloc->curOp(), alloc->curOp(), |
| 45 | GrResourceAllocator::ActualUse::kYes); |
Brian Salomon | be1084b | 2021-01-26 13:29:30 -0500 | [diff] [blame] | 46 | alloc->incOps(); |
| 47 | } |
| 48 | |
| 49 | GrRenderTask::ExpectedOutcome GrWritePixelsTask::onMakeClosed(const GrCaps&, |
| 50 | SkIRect* targetUpdateBounds) { |
| 51 | *targetUpdateBounds = fRect; |
| 52 | return ExpectedOutcome::kTargetDirty; |
| 53 | } |
| 54 | |
| 55 | bool GrWritePixelsTask::onExecute(GrOpFlushState* flushState) { |
| 56 | GrSurfaceProxy* dstProxy = this->target(0); |
| 57 | if (!dstProxy->isInstantiated()) { |
| 58 | return false; |
| 59 | } |
| 60 | GrSurface* dstSurface = dstProxy->peekSurface(); |
| 61 | return flushState->gpu()->writePixels(dstSurface, |
| 62 | fRect.fLeft, |
| 63 | fRect.fTop, |
| 64 | fRect.width(), |
| 65 | fRect.height(), |
| 66 | fDstColorType, |
| 67 | fSrcColorType, |
| 68 | fLevels.get(), |
| 69 | fLevels.count()); |
| 70 | } |