blob: 1d01bbdd643405bc103f9831c78c3f4cf8578341 [file] [log] [blame]
Brian Salomonbe1084b2021-01-26 13:29:30 -05001/*
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
15sk_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
33GrWritePixelsTask::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
51void GrWritePixelsTask::gatherProxyIntervals(GrResourceAllocator* alloc) const {
52 alloc->addInterval(this->target(0), alloc->curOp(), alloc->curOp(),
53 GrResourceAllocator::ActualUse::kYes);
54 alloc->incOps();
55}
56
57GrRenderTask::ExpectedOutcome GrWritePixelsTask::onMakeClosed(const GrCaps&,
58 SkIRect* targetUpdateBounds) {
59 *targetUpdateBounds = fRect;
60 return ExpectedOutcome::kTargetDirty;
61}
62
63bool GrWritePixelsTask::onExecute(GrOpFlushState* flushState) {
64 GrSurfaceProxy* dstProxy = this->target(0);
65 if (!dstProxy->isInstantiated()) {
66 return false;
67 }
68 GrSurface* dstSurface = dstProxy->peekSurface();
69 return flushState->gpu()->writePixels(dstSurface,
70 fRect.fLeft,
71 fRect.fTop,
72 fRect.width(),
73 fRect.height(),
74 fDstColorType,
75 fSrcColorType,
76 fLevels.get(),
77 fLevels.count());
78}