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 Daltonfac91962019-09-18 08:23:51 +000017void GrTextureResolveRenderTask::init(const GrCaps& caps) {
18 if (GrSurfaceProxy::ResolveFlags::kMSAA & fResolveFlags) {
19 GrRenderTargetProxy* renderTargetProxy = fTarget->asRenderTargetProxy();
Chris Dalton4ece96d2019-08-30 11:26:39 -060020 SkASSERT(renderTargetProxy);
21 SkASSERT(renderTargetProxy->isMSAADirty());
22 renderTargetProxy->markMSAAResolved();
23 }
24
Chris Daltonfac91962019-09-18 08:23:51 +000025 if (GrSurfaceProxy::ResolveFlags::kMipMaps & fResolveFlags) {
26 GrTextureProxy* textureProxy = fTarget->asTextureProxy();
Chris Dalton4ece96d2019-08-30 11:26:39 -060027 SkASSERT(GrMipMapped::kYes == textureProxy->mipMapped());
28 SkASSERT(textureProxy->mipMapsAreDirty());
29 textureProxy->markMipMapsClean();
30 }
31
Chris Daltonfac91962019-09-18 08:23:51 +000032 // Add the target as a dependency: We will read the existing contents of this texture while
Chris Dalton3d770272019-08-14 09:24:37 -060033 // generating mipmap levels and/or resolving MSAA.
Chris Daltonfac91962019-09-18 08:23:51 +000034 //
35 // NOTE: This must be called before makeClosed.
36 this->addDependency(fTarget.get(), GrMipMapped::kNo, GrTextureResolveManager(nullptr), caps);
37 fTarget->setLastRenderTask(this);
Chris Dalton3d770272019-08-14 09:24:37 -060038
Chris Daltonfac91962019-09-18 08:23:51 +000039 // We only resolve the texture; nobody should try to do anything else with this opsTask.
40 this->makeClosed(caps);
Chris Dalton3d770272019-08-14 09:24:37 -060041}
42
43void GrTextureResolveRenderTask::gatherProxyIntervals(GrResourceAllocator* alloc) const {
Chris Daltonfac91962019-09-18 08:23:51 +000044 // This renderTask doesn't have "normal" ops. In this case we still need to add an interval (so
45 // fEndOfOpsTaskOpIndices will remain in sync), so we create a fake op# to capture the fact that
46 // we manipulate fTarget.
47 alloc->addInterval(fTarget.get(), alloc->curOp(), alloc->curOp(),
48 GrResourceAllocator::ActualUse::kYes);
Chris Dalton3d770272019-08-14 09:24:37 -060049 alloc->incOps();
50}
51
52bool GrTextureResolveRenderTask::onExecute(GrOpFlushState* flushState) {
Chris Daltonfac91962019-09-18 08:23:51 +000053 // 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);
Chris Dalton4ece96d2019-08-30 11:26:39 -060059 }
60 }
Chris Daltonfac91962019-09-18 08:23:51 +000061
62 if (GrSurfaceProxy::ResolveFlags::kMipMaps & fResolveFlags) {
63 GrTexture* texture = fTarget->peekTexture();
64 SkASSERT(texture);
65 if (texture->texturePriv().mipMapsAreDirty()) {
66 flushState->gpu()->regenerateMipMapLevels(texture);
Chris Dalton4ece96d2019-08-30 11:26:39 -060067 }
Chris Dalton3d770272019-08-14 09:24:37 -060068 }
69
70 return true;
71}