blob: e8caeb28092c22371cb2acbf0fac419df0d93df1 [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"
Brian Salomonbe1084b2021-01-26 13:29:30 -050013
14sk_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 Salomon75ee7372021-04-06 15:04:35 -040020 int levelCount) {
Brian Salomonbe1084b2021-01-26 13:29:30 -050021 return sk_sp<GrRenderTask>(new GrWritePixelsTask(dm,
22 std::move(dst),
23 rect,
24 srcColorType,
25 dstColorType,
26 texels,
Brian Salomon75ee7372021-04-06 15:04:35 -040027 levelCount));
Brian Salomonbe1084b2021-01-26 13:29:30 -050028}
29
30GrWritePixelsTask::GrWritePixelsTask(GrDrawingManager* dm,
31 sk_sp<GrSurfaceProxy> dst,
32 SkIRect rect,
33 GrColorType srcColorType,
34 GrColorType dstColorType,
35 const GrMipLevel texels[],
Brian Salomon75ee7372021-04-06 15:04:35 -040036 int levelCount)
Brian Salomonea1d39b2021-04-01 17:06:52 -040037 : fRect(rect)
38 , fSrcColorType(srcColorType)
Brian Salomon75ee7372021-04-06 15:04:35 -040039 , fDstColorType(dstColorType) {
Brian Salomonbe1084b2021-01-26 13:29:30 -050040 this->addTarget(dm, std::move(dst));
41 fLevels.reset(levelCount);
42 std::copy_n(texels, levelCount, fLevels.get());
43}
44
45void GrWritePixelsTask::gatherProxyIntervals(GrResourceAllocator* alloc) const {
Adlai Holler7f7a5df2021-02-09 17:41:10 +000046 alloc->addInterval(this->target(0), alloc->curOp(), alloc->curOp(),
47 GrResourceAllocator::ActualUse::kYes);
Brian Salomonbe1084b2021-01-26 13:29:30 -050048 alloc->incOps();
49}
50
51GrRenderTask::ExpectedOutcome GrWritePixelsTask::onMakeClosed(const GrCaps&,
52 SkIRect* targetUpdateBounds) {
53 *targetUpdateBounds = fRect;
54 return ExpectedOutcome::kTargetDirty;
55}
56
57bool GrWritePixelsTask::onExecute(GrOpFlushState* flushState) {
58 GrSurfaceProxy* dstProxy = this->target(0);
59 if (!dstProxy->isInstantiated()) {
60 return false;
61 }
62 GrSurface* dstSurface = dstProxy->peekSurface();
63 return flushState->gpu()->writePixels(dstSurface,
64 fRect.fLeft,
65 fRect.fTop,
66 fRect.width(),
67 fRect.height(),
68 fDstColorType,
69 fSrcColorType,
70 fLevels.get(),
Brian Salomon75ee7372021-04-06 15:04:35 -040071 fLevels.count());
Brian Salomonbe1084b2021-01-26 13:29:30 -050072}