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
Make(sk_sp<GrTextureProxy> textureProxyPtr,GrTextureResolveFlags flags,const GrCaps & caps)16 sk_sp<GrRenderTask> GrTextureResolveRenderTask::Make(
17 sk_sp<GrTextureProxy> textureProxyPtr, GrTextureResolveFlags flags, const GrCaps& caps) {
18 GrTextureProxy* textureProxy = textureProxyPtr.get();
19 sk_sp<GrTextureResolveRenderTask> resolveTask(
20 new GrTextureResolveRenderTask(std::move(textureProxyPtr), flags));
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(
27 textureProxy, GrMipMapped::kNo, GrTextureResolveManager(nullptr), caps);
28 textureProxy->setLastRenderTask(resolveTask.get());
29
30 // We only resolve the texture; nobody should try to do anything else with this opList.
31 resolveTask->makeClosed(caps);
32
33 if (GrTextureResolveFlags::kMipMaps & flags) {
34 SkASSERT(GrMipMapped::kYes == textureProxy->mipMapped());
35 SkASSERT(textureProxy->mipMapsAreDirty());
36 textureProxy->markMipMapsClean();
37 }
38
39 return resolveTask;
40 }
41
gatherProxyIntervals(GrResourceAllocator * alloc) const42 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
44 // fEndOfOpListOpIndices will remain in sync), so we create a fake op# to capture the fact that
45 // we manipulate fTarget.
46 alloc->addInterval(fTarget.get(), alloc->curOp(), alloc->curOp(),
47 GrResourceAllocator::ActualUse::kYes);
48 alloc->incOps();
49 }
50
onExecute(GrOpFlushState * flushState)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 }
62