blob: 0b7738320d3589a718f80e9beb690cc06df01290 [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 Dalton4ece96d2019-08-30 11:26:39 -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
Chris Dalton6aeb8e82019-08-27 11:52:19 -060017void GrTextureResolveRenderTask::init(const GrCaps& caps) {
Chris Dalton4ece96d2019-08-30 11:26:39 -060018 if (GrSurfaceProxy::ResolveFlags::kMSAA & fResolveFlags) {
19 GrRenderTargetProxy* renderTargetProxy = fTarget->asRenderTargetProxy();
20 SkASSERT(renderTargetProxy);
21 SkASSERT(renderTargetProxy->isMSAADirty());
22 renderTargetProxy->markMSAAResolved();
23 }
24
25 if (GrSurfaceProxy::ResolveFlags::kMipMaps & fResolveFlags) {
26 GrTextureProxy* textureProxy = fTarget->asTextureProxy();
27 SkASSERT(GrMipMapped::kYes == textureProxy->mipMapped());
28 SkASSERT(textureProxy->mipMapsAreDirty());
29 textureProxy->markMipMapsClean();
30 }
31
Chris Dalton3d770272019-08-14 09:24:37 -060032 // Add the target as a dependency: We will read the existing contents of this texture while
33 // generating mipmap levels and/or resolving MSAA.
34 //
35 // NOTE: This must be called before makeClosed.
Chris Dalton6aeb8e82019-08-27 11:52:19 -060036 this->addDependency(fTarget.get(), GrMipMapped::kNo, GrTextureResolveManager(nullptr), caps);
37 fTarget->setLastRenderTask(this);
Chris Dalton3d770272019-08-14 09:24:37 -060038
Greg Danielf41b2bd2019-08-22 16:19:24 -040039 // We only resolve the texture; nobody should try to do anything else with this opsTask.
Chris Dalton6aeb8e82019-08-27 11:52:19 -060040 this->makeClosed(caps);
Chris Dalton3d770272019-08-14 09:24:37 -060041}
42
43void GrTextureResolveRenderTask::gatherProxyIntervals(GrResourceAllocator* alloc) const {
44 // 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 -040045 // fEndOfOpsTaskOpIndices will remain in sync), so we create a fake op# to capture the fact that
Chris Dalton3d770272019-08-14 09:24:37 -060046 // we manipulate fTarget.
47 alloc->addInterval(fTarget.get(), alloc->curOp(), alloc->curOp(),
48 GrResourceAllocator::ActualUse::kYes);
49 alloc->incOps();
50}
51
52bool GrTextureResolveRenderTask::onExecute(GrOpFlushState* flushState) {
Chris Dalton4ece96d2019-08-30 11:26:39 -060053 // Resolve msaa before regenerating mipmaps.
54 if (GrSurfaceProxy::ResolveFlags::kMSAA & fResolveFlags) {
55 GrRenderTarget* renderTarget = fTarget->peekRenderTarget();
56 SkASSERT(renderTarget);
57 if (renderTarget->needsResolve()) {
58 flushState->gpu()->resolveRenderTarget(renderTarget);
59 }
60 }
Chris Dalton3d770272019-08-14 09:24:37 -060061
Chris Dalton4ece96d2019-08-30 11:26:39 -060062 if (GrSurfaceProxy::ResolveFlags::kMipMaps & fResolveFlags) {
63 GrTexture* texture = fTarget->peekTexture();
64 SkASSERT(texture);
65 if (texture->texturePriv().mipMapsAreDirty()) {
66 flushState->gpu()->regenerateMipMapLevels(texture);
67 }
Chris Dalton3d770272019-08-14 09:24:37 -060068 }
69
70 return true;
71}