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 | |
| 16 | sk_sp<GrRenderTask> GrTextureResolveRenderTask::Make( |
Greg Daniel | bbfec9d | 2019-08-20 10:56:51 -0400 | [diff] [blame] | 17 | sk_sp<GrTextureProxy> textureProxy, GrTextureResolveFlags flags, const GrCaps& caps) { |
| 18 | GrTextureProxy* textureProxyPtr = textureProxy.get(); |
Chris Dalton | 3d77027 | 2019-08-14 09:24:37 -0600 | [diff] [blame] | 19 | sk_sp<GrTextureResolveRenderTask> resolveTask( |
Greg Daniel | bbfec9d | 2019-08-20 10:56:51 -0400 | [diff] [blame] | 20 | new GrTextureResolveRenderTask(std::move(textureProxy), flags)); |
Chris Dalton | 3d77027 | 2019-08-14 09:24:37 -0600 | [diff] [blame] | 21 | |
| 22 | // Add the target as a dependency: We will read the existing contents of this texture while |
| 23 | // generating mipmap levels and/or resolving MSAA. |
| 24 | // |
| 25 | // NOTE: This must be called before makeClosed. |
| 26 | resolveTask->addDependency( |
Greg Daniel | bbfec9d | 2019-08-20 10:56:51 -0400 | [diff] [blame] | 27 | textureProxyPtr, GrMipMapped::kNo, GrTextureResolveManager(nullptr), caps); |
| 28 | textureProxyPtr->setLastRenderTask(resolveTask.get()); |
Chris Dalton | 3d77027 | 2019-08-14 09:24:37 -0600 | [diff] [blame] | 29 | |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame^] | 30 | // We only resolve the texture; nobody should try to do anything else with this opsTask. |
Chris Dalton | 3d77027 | 2019-08-14 09:24:37 -0600 | [diff] [blame] | 31 | resolveTask->makeClosed(caps); |
| 32 | |
| 33 | if (GrTextureResolveFlags::kMipMaps & flags) { |
Greg Daniel | bbfec9d | 2019-08-20 10:56:51 -0400 | [diff] [blame] | 34 | SkASSERT(GrMipMapped::kYes == textureProxyPtr->mipMapped()); |
| 35 | SkASSERT(textureProxyPtr->mipMapsAreDirty()); |
| 36 | textureProxyPtr->markMipMapsClean(); |
Chris Dalton | 3d77027 | 2019-08-14 09:24:37 -0600 | [diff] [blame] | 37 | } |
| 38 | |
Brian Salomon | 9c73e3d | 2019-08-15 10:55:49 -0400 | [diff] [blame] | 39 | return resolveTask; |
Chris Dalton | 3d77027 | 2019-08-14 09:24:37 -0600 | [diff] [blame] | 40 | } |
| 41 | |
| 42 | void GrTextureResolveRenderTask::gatherProxyIntervals(GrResourceAllocator* alloc) const { |
| 43 | // 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^] | 44 | // 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] | 45 | // we manipulate fTarget. |
| 46 | alloc->addInterval(fTarget.get(), alloc->curOp(), alloc->curOp(), |
| 47 | GrResourceAllocator::ActualUse::kYes); |
| 48 | alloc->incOps(); |
| 49 | } |
| 50 | |
| 51 | bool GrTextureResolveRenderTask::onExecute(GrOpFlushState* flushState) { |
| 52 | GrTexture* texture = fTarget->peekTexture(); |
| 53 | SkASSERT(texture); |
| 54 | |
| 55 | if (GrTextureResolveFlags::kMipMaps & fResolveFlags) { |
| 56 | SkASSERT(texture->texturePriv().mipMapsAreDirty()); |
| 57 | flushState->gpu()->regenerateMipMapLevels(texture); |
| 58 | } |
| 59 | |
| 60 | return true; |
| 61 | } |