blob: 08df318eaa82039b100efb5ab81f03b8a4decd57 [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"
13#include "src/gpu/GrResourceAllocator.h"
14#include "src/gpu/GrTexturePriv.h"
15
16sk_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 // On some old ISO C++11 compilers, 'resolveTask' will require an explicit std::move() when
40 // returned from this function. This is because its type (sk_sp<GrTextureResolveRenderTask>)
41 // does not match the return type (sk_sp<GrRenderTask>).
42 return std::move(resolveTask);
43}
44
45void GrTextureResolveRenderTask::gatherProxyIntervals(GrResourceAllocator* alloc) const {
46 // This renderTask doesn't have "normal" ops. In this case we still need to add an interval (so
47 // fEndOfOpListOpIndices will remain in sync), so we create a fake op# to capture the fact that
48 // we manipulate fTarget.
49 alloc->addInterval(fTarget.get(), alloc->curOp(), alloc->curOp(),
50 GrResourceAllocator::ActualUse::kYes);
51 alloc->incOps();
52}
53
54bool GrTextureResolveRenderTask::onExecute(GrOpFlushState* flushState) {
55 GrTexture* texture = fTarget->peekTexture();
56 SkASSERT(texture);
57
58 if (GrTextureResolveFlags::kMipMaps & fResolveFlags) {
59 SkASSERT(texture->texturePriv().mipMapsAreDirty());
60 flushState->gpu()->regenerateMipMapLevels(texture);
61 }
62
63 return true;
64}