blob: 0ae9356383e42c9d4e64d1287e660ba179b29e17 [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
Chris Dalton6aeb8e82019-08-27 11:52:19 -060016void GrTextureResolveRenderTask::init(const GrCaps& caps) {
Chris Dalton3d770272019-08-14 09:24:37 -060017 // Add the target as a dependency: We will read the existing contents of this texture while
18 // generating mipmap levels and/or resolving MSAA.
19 //
20 // NOTE: This must be called before makeClosed.
Chris Dalton6aeb8e82019-08-27 11:52:19 -060021 this->addDependency(fTarget.get(), GrMipMapped::kNo, GrTextureResolveManager(nullptr), caps);
22 fTarget->setLastRenderTask(this);
Chris Dalton3d770272019-08-14 09:24:37 -060023
Greg Danielf41b2bd2019-08-22 16:19:24 -040024 // We only resolve the texture; nobody should try to do anything else with this opsTask.
Chris Dalton6aeb8e82019-08-27 11:52:19 -060025 this->makeClosed(caps);
Chris Dalton3d770272019-08-14 09:24:37 -060026
Chris Dalton6aeb8e82019-08-27 11:52:19 -060027 if (GrTextureResolveFlags::kMipMaps & fResolveFlags) {
28 GrTextureProxy* textureProxy = fTarget->asTextureProxy();
29 SkASSERT(GrMipMapped::kYes == textureProxy->mipMapped());
30 SkASSERT(textureProxy->mipMapsAreDirty());
31 textureProxy->markMipMapsClean();
Chris Dalton6f31cc32019-08-26 20:18:44 +000032 }
Chris Dalton3d770272019-08-14 09:24:37 -060033}
34
35void GrTextureResolveRenderTask::gatherProxyIntervals(GrResourceAllocator* alloc) const {
36 // 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 -040037 // fEndOfOpsTaskOpIndices will remain in sync), so we create a fake op# to capture the fact that
Chris Dalton3d770272019-08-14 09:24:37 -060038 // we manipulate fTarget.
39 alloc->addInterval(fTarget.get(), alloc->curOp(), alloc->curOp(),
40 GrResourceAllocator::ActualUse::kYes);
41 alloc->incOps();
42}
43
44bool GrTextureResolveRenderTask::onExecute(GrOpFlushState* flushState) {
Chris Dalton6f31cc32019-08-26 20:18:44 +000045 GrTexture* texture = fTarget->peekTexture();
46 SkASSERT(texture);
Chris Dalton3d770272019-08-14 09:24:37 -060047
48 if (GrTextureResolveFlags::kMipMaps & fResolveFlags) {
Chris Dalton3d770272019-08-14 09:24:37 -060049 SkASSERT(texture->texturePriv().mipMapsAreDirty());
50 flushState->gpu()->regenerateMipMapLevels(texture);
51 }
52
53 return true;
54}