Chris Dalton | 3d77027 | 2019-08-14 09:24:37 -0600 | [diff] [blame] | 1 | /* |
| 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 Dalton | 4ece96d | 2019-08-30 11:26:39 -0600 | [diff] [blame] | 13 | #include "src/gpu/GrRenderTarget.h" |
Chris Dalton | 3d77027 | 2019-08-14 09:24:37 -0600 | [diff] [blame] | 14 | #include "src/gpu/GrResourceAllocator.h" |
| 15 | #include "src/gpu/GrTexturePriv.h" |
| 16 | |
Chris Dalton | fac9196 | 2019-09-18 08:23:51 +0000 | [diff] [blame^] | 17 | void GrTextureResolveRenderTask::init(const GrCaps& caps) { |
| 18 | if (GrSurfaceProxy::ResolveFlags::kMSAA & fResolveFlags) { |
| 19 | GrRenderTargetProxy* renderTargetProxy = fTarget->asRenderTargetProxy(); |
Chris Dalton | 4ece96d | 2019-08-30 11:26:39 -0600 | [diff] [blame] | 20 | SkASSERT(renderTargetProxy); |
| 21 | SkASSERT(renderTargetProxy->isMSAADirty()); |
| 22 | renderTargetProxy->markMSAAResolved(); |
| 23 | } |
| 24 | |
Chris Dalton | fac9196 | 2019-09-18 08:23:51 +0000 | [diff] [blame^] | 25 | if (GrSurfaceProxy::ResolveFlags::kMipMaps & fResolveFlags) { |
| 26 | GrTextureProxy* textureProxy = fTarget->asTextureProxy(); |
Chris Dalton | 4ece96d | 2019-08-30 11:26:39 -0600 | [diff] [blame] | 27 | SkASSERT(GrMipMapped::kYes == textureProxy->mipMapped()); |
| 28 | SkASSERT(textureProxy->mipMapsAreDirty()); |
| 29 | textureProxy->markMipMapsClean(); |
| 30 | } |
| 31 | |
Chris Dalton | fac9196 | 2019-09-18 08:23:51 +0000 | [diff] [blame^] | 32 | // Add the target as a dependency: We will read the existing contents of this texture while |
Chris Dalton | 3d77027 | 2019-08-14 09:24:37 -0600 | [diff] [blame] | 33 | // generating mipmap levels and/or resolving MSAA. |
Chris Dalton | fac9196 | 2019-09-18 08:23:51 +0000 | [diff] [blame^] | 34 | // |
| 35 | // NOTE: This must be called before makeClosed. |
| 36 | this->addDependency(fTarget.get(), GrMipMapped::kNo, GrTextureResolveManager(nullptr), caps); |
| 37 | fTarget->setLastRenderTask(this); |
Chris Dalton | 3d77027 | 2019-08-14 09:24:37 -0600 | [diff] [blame] | 38 | |
Chris Dalton | fac9196 | 2019-09-18 08:23:51 +0000 | [diff] [blame^] | 39 | // We only resolve the texture; nobody should try to do anything else with this opsTask. |
| 40 | this->makeClosed(caps); |
Chris Dalton | 3d77027 | 2019-08-14 09:24:37 -0600 | [diff] [blame] | 41 | } |
| 42 | |
| 43 | void GrTextureResolveRenderTask::gatherProxyIntervals(GrResourceAllocator* alloc) const { |
Chris Dalton | fac9196 | 2019-09-18 08:23:51 +0000 | [diff] [blame^] | 44 | // 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 Dalton | 3d77027 | 2019-08-14 09:24:37 -0600 | [diff] [blame] | 49 | alloc->incOps(); |
| 50 | } |
| 51 | |
| 52 | bool GrTextureResolveRenderTask::onExecute(GrOpFlushState* flushState) { |
Chris Dalton | fac9196 | 2019-09-18 08:23:51 +0000 | [diff] [blame^] | 53 | // 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 Dalton | 4ece96d | 2019-08-30 11:26:39 -0600 | [diff] [blame] | 59 | } |
| 60 | } |
Chris Dalton | fac9196 | 2019-09-18 08:23:51 +0000 | [diff] [blame^] | 61 | |
| 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 Dalton | 4ece96d | 2019-08-30 11:26:39 -0600 | [diff] [blame] | 67 | } |
Chris Dalton | 3d77027 | 2019-08-14 09:24:37 -0600 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | return true; |
| 71 | } |