Flutter Engine
The Flutter Engine
DrawTask.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2024 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
9
13
14namespace skgpu::graphite {
15
17
18DrawTask::~DrawTask() = default;
19
21 ScratchResourceManager* scratchManager,
22 const RuntimeEffectDictionary* rteDict) {
23 const int pendingReadCount = scratchManager->pendingReadCount(fTarget.get());
24 if (pendingReadCount) {
25 // This DrawTask defines the content of a scratch device that has incremented the pending
26 // read count before snap() was called. The target may have already been instantiated if
27 // we've processed this task's children before.
28 SkASSERT(!fTarget->isLazy());
29 // Even though we may discard the task, we always want to mark it as in-use to track the
30 // pending reads to know when to return the texture.;
31 scratchManager->markResourceInUse(this);
32
33 if (fPrepared) {
34 // If the task has already had prepareResources() called once, it should have had
35 // its target instantiated.
36 SkASSERT(fTarget->isInstantiated());
37 // Return kDiscard so that this reference to the task is removed and the original
38 // encounter in the graph will be the only time addCommands() is invoked.
39 return Status::kDiscard;
40 }
41 } else {
42 // A non-scratch DrawTask should only ever be in the task graph one time.
43 SkASSERT(!fPrepared);
44 }
45
46 fPrepared = true;
47 // NOTE: This prepareResources() pushes a new scope for scratch resource management, which is
48 // what we want since the child tasks are what will actually instantiate any scratch device and
49 // trigger returns of any grand-child resources. The above markResourceInUse() should happen
50 // above this so that pending returns are handled in caller's scope.
51 return fChildTasks.prepareResources(resourceProvider, scratchManager, rteDict);
52}
53
54void DrawTask::onUseCompleted(ScratchResourceManager* scratchManager) {
55 // Now that the render task has completed, actually decrement the read count of the target proxy
56 // If the count hits zero, this was the last pending read that needed to use the DrawTask's
57 // results so we can return the texture to the ScratchResourceManager for reuse.
58 SkASSERT(!fTarget->isLazy() && fTarget->isInstantiated());
59 SkASSERT(scratchManager->pendingReadCount(fTarget.get()) > 0);
60 if (scratchManager->removePendingRead(fTarget.get())) {
61 scratchManager->returnTexture(fTarget->refTexture());
62 }
63}
64
66 CommandBuffer* commandBuffer,
67 ReplayTargetData replayTarget) {
68 SkASSERT(fTarget->isInstantiated());
69 return fChildTasks.addCommands(ctx, commandBuffer, replayTarget);
70}
71
72} // namespace skgpu::graphite
#define SkASSERT(cond)
Definition: SkAssert.h:116
Status prepareResources(ResourceProvider *, ScratchResourceManager *, const RuntimeEffectDictionary *) override
Definition: DrawTask.cpp:20
DrawTask(sk_sp< TextureProxy > target)
Definition: DrawTask.cpp:16
Status addCommands(Context *, CommandBuffer *, ReplayTargetData) override
Definition: DrawTask.cpp:65
int pendingReadCount(const TextureProxy *proxy) const
void markResourceInUse(PendingUseListener *listener)
bool removePendingRead(const TextureProxy *proxy)
Task::Status addCommands(Context *, CommandBuffer *, Task::ReplayTargetData)
Definition: TaskList.cpp:50
Task::Status prepareResources(ResourceProvider *, ScratchResourceManager *, const RuntimeEffectDictionary *)
Definition: TaskList.cpp:38
uint32_t * target
Definition: ref_ptr.h:256