blob: 2613d6205ef646d21a98a26708fcbdd7499d5ce6 [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[],
20 int levelCount,
21 sk_sp<SkData> pixelStorage) {
22 return sk_sp<GrRenderTask>(new GrWritePixelsTask(dm,
23 std::move(dst),
24 rect,
25 srcColorType,
26 dstColorType,
27 texels,
28 levelCount,
29 std::move(pixelStorage)));
30}
31
32GrWritePixelsTask::GrWritePixelsTask(GrDrawingManager* dm,
33 sk_sp<GrSurfaceProxy> dst,
34 SkIRect rect,
35 GrColorType srcColorType,
36 GrColorType dstColorType,
37 const GrMipLevel texels[],
38 int levelCount,
39 sk_sp<SkData> pixelStorage)
40 : fRect(rect)
41 , fSrcColorType(srcColorType)
42 , fDstColorType(dstColorType)
43 , fStorage(std::move(pixelStorage)) {
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(),
75 fLevels.count());
76}