blob: 1e52b8793f3ed07835b84091679b3c43e3ea5ce2 [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
Greg Danielf41b2bd2019-08-22 16:19:24 -040030 // We only resolve the texture; nobody should try to do anything else with this opsTask.
Chris Dalton3d770272019-08-14 09:24:37 -060031 resolveTask->makeClosed(caps);
32
Chris Dalton6f31cc32019-08-26 20:18:44 +000033 if (GrTextureResolveFlags::kMipMaps & flags) {
34 SkASSERT(GrMipMapped::kYes == textureProxyPtr->mipMapped());
35 SkASSERT(textureProxyPtr->mipMapsAreDirty());
36 textureProxyPtr->markMipMapsClean();
37 }
38
39 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
Greg Danielf41b2bd2019-08-22 16:19:24 -040044 // fEndOfOpsTaskOpIndices will remain in sync), so we create a fake op# to capture the fact that
Chris Dalton3d770272019-08-14 09:24:37 -060045 // 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) {
Chris Dalton6f31cc32019-08-26 20:18:44 +000052 GrTexture* texture = fTarget->peekTexture();
53 SkASSERT(texture);
Chris Dalton3d770272019-08-14 09:24:37 -060054
55 if (GrTextureResolveFlags::kMipMaps & fResolveFlags) {
Chris Dalton3d770272019-08-14 09:24:37 -060056 SkASSERT(texture->texturePriv().mipMapsAreDirty());
57 flushState->gpu()->regenerateMipMapLevels(texture);
58 }
59
60 return true;
61}