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" |
| 13 | #include "src/gpu/GrResourceAllocator.h" |
| 14 | #include "src/gpu/GrTexturePriv.h" |
| 15 | |
Chris Dalton | 6aeb8e8 | 2019-08-27 11:52:19 -0600 | [diff] [blame^] | 16 | void GrTextureResolveRenderTask::init(const GrCaps& caps) { |
Chris Dalton | 3d77027 | 2019-08-14 09:24:37 -0600 | [diff] [blame] | 17 | // 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 Dalton | 6aeb8e8 | 2019-08-27 11:52:19 -0600 | [diff] [blame^] | 21 | this->addDependency(fTarget.get(), GrMipMapped::kNo, GrTextureResolveManager(nullptr), caps); |
| 22 | fTarget->setLastRenderTask(this); |
Chris Dalton | 3d77027 | 2019-08-14 09:24:37 -0600 | [diff] [blame] | 23 | |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 24 | // We only resolve the texture; nobody should try to do anything else with this opsTask. |
Chris Dalton | 6aeb8e8 | 2019-08-27 11:52:19 -0600 | [diff] [blame^] | 25 | this->makeClosed(caps); |
Chris Dalton | 3d77027 | 2019-08-14 09:24:37 -0600 | [diff] [blame] | 26 | |
Chris Dalton | 6aeb8e8 | 2019-08-27 11:52:19 -0600 | [diff] [blame^] | 27 | if (GrTextureResolveFlags::kMipMaps & fResolveFlags) { |
| 28 | GrTextureProxy* textureProxy = fTarget->asTextureProxy(); |
| 29 | SkASSERT(GrMipMapped::kYes == textureProxy->mipMapped()); |
| 30 | SkASSERT(textureProxy->mipMapsAreDirty()); |
| 31 | textureProxy->markMipMapsClean(); |
Chris Dalton | 6f31cc3 | 2019-08-26 20:18:44 +0000 | [diff] [blame] | 32 | } |
Chris Dalton | 3d77027 | 2019-08-14 09:24:37 -0600 | [diff] [blame] | 33 | } |
| 34 | |
| 35 | void 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 Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 37 | // fEndOfOpsTaskOpIndices will remain in sync), so we create a fake op# to capture the fact that |
Chris Dalton | 3d77027 | 2019-08-14 09:24:37 -0600 | [diff] [blame] | 38 | // we manipulate fTarget. |
| 39 | alloc->addInterval(fTarget.get(), alloc->curOp(), alloc->curOp(), |
| 40 | GrResourceAllocator::ActualUse::kYes); |
| 41 | alloc->incOps(); |
| 42 | } |
| 43 | |
| 44 | bool GrTextureResolveRenderTask::onExecute(GrOpFlushState* flushState) { |
Chris Dalton | 6f31cc3 | 2019-08-26 20:18:44 +0000 | [diff] [blame] | 45 | GrTexture* texture = fTarget->peekTexture(); |
| 46 | SkASSERT(texture); |
Chris Dalton | 3d77027 | 2019-08-14 09:24:37 -0600 | [diff] [blame] | 47 | |
| 48 | if (GrTextureResolveFlags::kMipMaps & fResolveFlags) { |
Chris Dalton | 3d77027 | 2019-08-14 09:24:37 -0600 | [diff] [blame] | 49 | SkASSERT(texture->texturePriv().mipMapsAreDirty()); |
| 50 | flushState->gpu()->regenerateMipMapLevels(texture); |
| 51 | } |
| 52 | |
| 53 | return true; |
| 54 | } |