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