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