blob: 51901a03c3c200767d1e1a9fb6f3de7b7dc3215a [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 Salomonea1d39b2021-04-01 17:06:52 -040020 int levelCount,
21 bool prepForSampling) {
Brian Salomonbe1084b2021-01-26 13:29:30 -050022 return sk_sp<GrRenderTask>(new GrWritePixelsTask(dm,
23 std::move(dst),
24 rect,
25 srcColorType,
26 dstColorType,
27 texels,
Brian Salomonea1d39b2021-04-01 17:06:52 -040028 levelCount,
29 prepForSampling));
Brian Salomonbe1084b2021-01-26 13:29:30 -050030}
31
32GrWritePixelsTask::GrWritePixelsTask(GrDrawingManager* dm,
33 sk_sp<GrSurfaceProxy> dst,
34 SkIRect rect,
35 GrColorType srcColorType,
36 GrColorType dstColorType,
37 const GrMipLevel texels[],
Brian Salomonea1d39b2021-04-01 17:06:52 -040038 int levelCount,
39 bool prepForSampling)
40 : fRect(rect)
41 , fSrcColorType(srcColorType)
42 , fDstColorType(dstColorType)
43 , fPrepForSampling(prepForSampling) {
Brian Salomonbe1084b2021-01-26 13:29:30 -050044 this->addTarget(dm, std::move(dst));
45 fLevels.reset(levelCount);
46 std::copy_n(texels, levelCount, fLevels.get());
47}
48
49void GrWritePixelsTask::gatherProxyIntervals(GrResourceAllocator* alloc) const {
Adlai Holler7f7a5df2021-02-09 17:41:10 +000050 alloc->addInterval(this->target(0), alloc->curOp(), alloc->curOp(),
51 GrResourceAllocator::ActualUse::kYes);
Brian Salomonbe1084b2021-01-26 13:29:30 -050052 alloc->incOps();
53}
54
55GrRenderTask::ExpectedOutcome GrWritePixelsTask::onMakeClosed(const GrCaps&,
56 SkIRect* targetUpdateBounds) {
57 *targetUpdateBounds = fRect;
58 return ExpectedOutcome::kTargetDirty;
59}
60
61bool 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 Salomonea1d39b2021-04-01 17:06:52 -040075 fLevels.count(),
76 fPrepForSampling);
Brian Salomonbe1084b2021-01-26 13:29:30 -050077}