blob: 0064fe618d1b2f0b4766df929929582f7fa4ca43 [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"
Chris Dalton804f6a02019-08-26 12:07:30 -060013#include "src/gpu/GrRenderTarget.h"
Chris Dalton3d770272019-08-14 09:24:37 -060014#include "src/gpu/GrResourceAllocator.h"
15#include "src/gpu/GrTexturePriv.h"
16
17sk_sp<GrRenderTask> GrTextureResolveRenderTask::Make(
Greg Danielbbfec9d2019-08-20 10:56:51 -040018 sk_sp<GrTextureProxy> textureProxy, GrTextureResolveFlags flags, const GrCaps& caps) {
19 GrTextureProxy* textureProxyPtr = textureProxy.get();
Chris Dalton3d770272019-08-14 09:24:37 -060020 sk_sp<GrTextureResolveRenderTask> resolveTask(
Greg Danielbbfec9d2019-08-20 10:56:51 -040021 new GrTextureResolveRenderTask(std::move(textureProxy), flags));
Chris Dalton3d770272019-08-14 09:24:37 -060022
Chris Dalton804f6a02019-08-26 12:07:30 -060023 // Ensure the last render task that operated on the textureProxy is closed. That's where msaa
24 // and mipmaps should have been marked dirty.
25 SkASSERT(!textureProxyPtr->getLastRenderTask() ||
26 textureProxyPtr->getLastRenderTask()->isClosed());
27
28 if (GrTextureResolveFlags::kMSAA & flags) {
29 GrRenderTargetProxy* renderTargetProxy = textureProxyPtr->asRenderTargetProxy();
30 SkASSERT(renderTargetProxy);
31 SkASSERT(renderTargetProxy->isMSAADirty());
32 renderTargetProxy->markMSAAResolved();
33 }
34
35 if (GrTextureResolveFlags::kMipMaps & flags) {
36 SkASSERT(GrMipMapped::kYes == textureProxyPtr->mipMapped());
37 SkASSERT(textureProxyPtr->mipMapsAreDirty());
38 textureProxyPtr->markMipMapsClean();
39 }
40
Chris Dalton3d770272019-08-14 09:24:37 -060041 // Add the target as a dependency: We will read the existing contents of this texture while
42 // generating mipmap levels and/or resolving MSAA.
43 //
44 // NOTE: This must be called before makeClosed.
45 resolveTask->addDependency(
Greg Danielbbfec9d2019-08-20 10:56:51 -040046 textureProxyPtr, GrMipMapped::kNo, GrTextureResolveManager(nullptr), caps);
47 textureProxyPtr->setLastRenderTask(resolveTask.get());
Chris Dalton3d770272019-08-14 09:24:37 -060048
Greg Danielf41b2bd2019-08-22 16:19:24 -040049 // We only resolve the texture; nobody should try to do anything else with this opsTask.
Chris Dalton3d770272019-08-14 09:24:37 -060050 resolveTask->makeClosed(caps);
51
Chris Dalton804f6a02019-08-26 12:07:30 -060052 return std::move(resolveTask);
Chris Dalton3d770272019-08-14 09:24:37 -060053}
54
55void GrTextureResolveRenderTask::gatherProxyIntervals(GrResourceAllocator* alloc) const {
56 // 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 -040057 // fEndOfOpsTaskOpIndices will remain in sync), so we create a fake op# to capture the fact that
Chris Dalton3d770272019-08-14 09:24:37 -060058 // we manipulate fTarget.
59 alloc->addInterval(fTarget.get(), alloc->curOp(), alloc->curOp(),
60 GrResourceAllocator::ActualUse::kYes);
61 alloc->incOps();
62}
63
64bool GrTextureResolveRenderTask::onExecute(GrOpFlushState* flushState) {
Chris Dalton804f6a02019-08-26 12:07:30 -060065 // Resolve msaa before regenerating mipmaps.
66 if (GrTextureResolveFlags::kMSAA & fResolveFlags) {
67 GrRenderTarget* renderTarget = fTarget->peekRenderTarget();
68 SkASSERT(renderTarget);
69 SkASSERT(renderTarget->needsResolve());
70 flushState->gpu()->resolveRenderTarget(renderTarget);
71 }
Chris Dalton3d770272019-08-14 09:24:37 -060072
73 if (GrTextureResolveFlags::kMipMaps & fResolveFlags) {
Chris Dalton804f6a02019-08-26 12:07:30 -060074 GrTexture* texture = fTarget->peekTexture();
75 SkASSERT(texture);
Chris Dalton3d770272019-08-14 09:24:37 -060076 SkASSERT(texture->texturePriv().mipMapsAreDirty());
77 flushState->gpu()->regenerateMipMapLevels(texture);
78 }
79
80 return true;
81}