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/ganesh/GrWritePixelsRenderTask.h"
9
10 #include "src/gpu/ganesh/GrGpu.h"
11 #include "src/gpu/ganesh/GrOpFlushState.h"
12 #include "src/gpu/ganesh/GrResourceAllocator.h"
13
Make(GrDrawingManager * dm,sk_sp<GrSurfaceProxy> dst,SkIRect rect,GrColorType srcColorType,GrColorType dstColorType,const GrMipLevel texels[],int levelCount)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[],
20 int levelCount) {
21 return sk_sp<GrRenderTask>(new GrWritePixelsTask(dm,
22 std::move(dst),
23 rect,
24 srcColorType,
25 dstColorType,
26 texels,
27 levelCount));
28 }
29
GrWritePixelsTask(GrDrawingManager * dm,sk_sp<GrSurfaceProxy> dst,SkIRect rect,GrColorType srcColorType,GrColorType dstColorType,const GrMipLevel texels[],int levelCount)30 GrWritePixelsTask::GrWritePixelsTask(GrDrawingManager* dm,
31 sk_sp<GrSurfaceProxy> dst,
32 SkIRect rect,
33 GrColorType srcColorType,
34 GrColorType dstColorType,
35 const GrMipLevel texels[],
36 int levelCount)
37 : fRect(rect)
38 , fSrcColorType(srcColorType)
39 , fDstColorType(dstColorType) {
40 this->addTarget(dm, std::move(dst));
41 fLevels.reset(levelCount);
42 std::copy_n(texels, levelCount, fLevels.get());
43 }
44
gatherProxyIntervals(GrResourceAllocator * alloc) const45 void GrWritePixelsTask::gatherProxyIntervals(GrResourceAllocator* alloc) const {
46 alloc->addInterval(this->target(0), alloc->curOp(), alloc->curOp(),
47 GrResourceAllocator::ActualUse::kYes,
48 GrResourceAllocator::AllowRecycling::kYes);
49 alloc->incOps();
50 }
51
onMakeClosed(GrRecordingContext *,SkIRect * targetUpdateBounds)52 GrRenderTask::ExpectedOutcome GrWritePixelsTask::onMakeClosed(GrRecordingContext*,
53 SkIRect* targetUpdateBounds) {
54 *targetUpdateBounds = fRect;
55 return ExpectedOutcome::kTargetDirty;
56 }
57
onExecute(GrOpFlushState * flushState)58 bool GrWritePixelsTask::onExecute(GrOpFlushState* flushState) {
59 GrSurfaceProxy* dstProxy = this->target(0);
60 if (!dstProxy->isInstantiated()) {
61 return false;
62 }
63 GrSurface* dstSurface = dstProxy->peekSurface();
64 return flushState->gpu()->writePixels(dstSurface,
65 fRect,
66 fDstColorType,
67 fSrcColorType,
68 fLevels.get(),
69 fLevels.count());
70 }
71