blob: 613f6bdaa1e44e57533ce9131f0743818c0d9c06 [file] [log] [blame]
Chris Dalton3d770272019-08-14 09:24:37 -06001/*
2 * Copyright 2019 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/GrTextureResolveRenderTask.h"
9
10#include "src/gpu/GrGpu.h"
11#include "src/gpu/GrMemoryPool.h"
12#include "src/gpu/GrOpFlushState.h"
13#include "src/gpu/GrResourceAllocator.h"
14#include "src/gpu/GrTexturePriv.h"
15
16sk_sp<GrRenderTask> GrTextureResolveRenderTask::Make(
Greg Danielbbfec9d2019-08-20 10:56:51 -040017 sk_sp<GrTextureProxy> textureProxy, GrTextureResolveFlags flags, const GrCaps& caps) {
18 GrTextureProxy* textureProxyPtr = textureProxy.get();
Chris Dalton3d770272019-08-14 09:24:37 -060019 sk_sp<GrTextureResolveRenderTask> resolveTask(
Greg Danielbbfec9d2019-08-20 10:56:51 -040020 new GrTextureResolveRenderTask(std::move(textureProxy), flags));
Chris Dalton3d770272019-08-14 09:24:37 -060021
22 // Add the target as a dependency: We will read the existing contents of this texture while
23 // generating mipmap levels and/or resolving MSAA.
24 //
25 // NOTE: This must be called before makeClosed.
26 resolveTask->addDependency(
Greg Danielbbfec9d2019-08-20 10:56:51 -040027 textureProxyPtr, GrMipMapped::kNo, GrTextureResolveManager(nullptr), caps);
28 textureProxyPtr->setLastRenderTask(resolveTask.get());
Chris Dalton3d770272019-08-14 09:24:37 -060029
30 // We only resolve the texture; nobody should try to do anything else with this opList.
31 resolveTask->makeClosed(caps);
32
33 if (GrTextureResolveFlags::kMipMaps & flags) {
Greg Danielbbfec9d2019-08-20 10:56:51 -040034 SkASSERT(GrMipMapped::kYes == textureProxyPtr->mipMapped());
35 SkASSERT(textureProxyPtr->mipMapsAreDirty());
36 textureProxyPtr->markMipMapsClean();
Chris Dalton3d770272019-08-14 09:24:37 -060037 }
38
Brian Salomon9c73e3d2019-08-15 10:55:49 -040039 return resolveTask;
Chris Dalton3d770272019-08-14 09:24:37 -060040}
41
42void GrTextureResolveRenderTask::gatherProxyIntervals(GrResourceAllocator* alloc) const {
43 // This renderTask doesn't have "normal" ops. In this case we still need to add an interval (so
44 // fEndOfOpListOpIndices will remain in sync), so we create a fake op# to capture the fact that
45 // we manipulate fTarget.
46 alloc->addInterval(fTarget.get(), alloc->curOp(), alloc->curOp(),
47 GrResourceAllocator::ActualUse::kYes);
48 alloc->incOps();
49}
50
51bool GrTextureResolveRenderTask::onExecute(GrOpFlushState* flushState) {
52 GrTexture* texture = fTarget->peekTexture();
53 SkASSERT(texture);
54
55 if (GrTextureResolveFlags::kMipMaps & fResolveFlags) {
56 SkASSERT(texture->texturePriv().mipMapsAreDirty());
57 flushState->gpu()->regenerateMipMapLevels(texture);
58 }
59
60 return true;
61}