Coverage Report

Created: 2024-05-20 07:14

/src/skia/src/gpu/ganesh/GrDrawingManager.cpp
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright 2015 Google Inc.
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/ganesh/GrDrawingManager.h"
9
10
#include <algorithm>
11
#include <memory>
12
13
#include "include/gpu/GrBackendSemaphore.h"
14
#include "include/gpu/GrDirectContext.h"
15
#include "include/gpu/GrRecordingContext.h"
16
#include "include/private/chromium/GrDeferredDisplayList.h"
17
#include "src/base/SkTInternalLList.h"
18
#include "src/gpu/ganesh/GrBufferTransferRenderTask.h"
19
#include "src/gpu/ganesh/GrBufferUpdateRenderTask.h"
20
#include "src/gpu/ganesh/GrClientMappedBufferManager.h"
21
#include "src/gpu/ganesh/GrCopyRenderTask.h"
22
#include "src/gpu/ganesh/GrDDLTask.h"
23
#include "src/gpu/ganesh/GrDeferredDisplayListPriv.h"
24
#include "src/gpu/ganesh/GrDirectContextPriv.h"
25
#include "src/gpu/ganesh/GrGpu.h"
26
#include "src/gpu/ganesh/GrMemoryPool.h"
27
#include "src/gpu/ganesh/GrNativeRect.h"
28
#include "src/gpu/ganesh/GrOnFlushResourceProvider.h"
29
#include "src/gpu/ganesh/GrOpFlushState.h"
30
#include "src/gpu/ganesh/GrRecordingContextPriv.h"
31
#include "src/gpu/ganesh/GrRenderTargetProxy.h"
32
#include "src/gpu/ganesh/GrRenderTask.h"
33
#include "src/gpu/ganesh/GrRenderTaskCluster.h"
34
#include "src/gpu/ganesh/GrResourceAllocator.h"
35
#include "src/gpu/ganesh/GrResourceProvider.h"
36
#include "src/gpu/ganesh/GrSurfaceProxyPriv.h"
37
#include "src/gpu/ganesh/GrTTopoSort.h"
38
#include "src/gpu/ganesh/GrTexture.h"
39
#include "src/gpu/ganesh/GrTextureProxy.h"
40
#include "src/gpu/ganesh/GrTextureProxyPriv.h"
41
#include "src/gpu/ganesh/GrTextureResolveRenderTask.h"
42
#include "src/gpu/ganesh/GrTracing.h"
43
#include "src/gpu/ganesh/GrTransferFromRenderTask.h"
44
#include "src/gpu/ganesh/GrWaitRenderTask.h"
45
#include "src/gpu/ganesh/GrWritePixelsRenderTask.h"
46
#include "src/gpu/ganesh/ops/OpsTask.h"
47
#include "src/gpu/ganesh/ops/SoftwarePathRenderer.h"
48
#include "src/gpu/ganesh/surface/SkSurface_Ganesh.h"
49
#include "src/text/gpu/SDFTControl.h"
50
51
using namespace skia_private;
52
53
///////////////////////////////////////////////////////////////////////////////////////////////////
54
GrDrawingManager::GrDrawingManager(GrRecordingContext* rContext,
55
                                   const PathRendererChain::Options& optionsForPathRendererChain,
56
                                   bool reduceOpsTaskSplitting)
57
        : fContext(rContext)
58
        , fOptionsForPathRendererChain(optionsForPathRendererChain)
59
        , fPathRendererChain(nullptr)
60
        , fSoftwarePathRenderer(nullptr)
61
2.58k
        , fReduceOpsTaskSplitting(reduceOpsTaskSplitting) {
62
2.58k
}
63
64
2.58k
GrDrawingManager::~GrDrawingManager() {
65
2.58k
    this->closeAllTasks();
66
2.58k
    this->removeRenderTasks();
67
2.58k
}
68
69
36.8k
bool GrDrawingManager::wasAbandoned() const {
70
36.8k
    return fContext->abandoned();
71
36.8k
}
72
73
0
void GrDrawingManager::freeGpuResources() {
74
0
    for (int i = fOnFlushCBObjects.size() - 1; i >= 0; --i) {
75
0
        if (!fOnFlushCBObjects[i]->retainOnFreeGpuResources()) {
76
            // it's safe to just do this because we're iterating in reverse
77
0
            fOnFlushCBObjects.removeShuffle(i);
78
0
        }
79
0
    }
80
81
    // a path renderer may be holding onto resources
82
0
    fPathRendererChain = nullptr;
83
0
    fSoftwarePathRenderer = nullptr;
84
0
}
85
86
// MDB TODO: make use of the 'proxies' parameter.
87
bool GrDrawingManager::flush(SkSpan<GrSurfaceProxy*> proxies,
88
                             SkSurfaces::BackendSurfaceAccess access,
89
                             const GrFlushInfo& info,
90
18.4k
                             const skgpu::MutableTextureState* newState) {
91
18.4k
    GR_CREATE_TRACE_MARKER_CONTEXT("GrDrawingManager", "flush", fContext);
92
93
18.4k
    if (fFlushing || this->wasAbandoned()) {
94
0
        if (info.fSubmittedProc) {
95
0
            info.fSubmittedProc(info.fSubmittedContext, false);
96
0
        }
97
0
        if (info.fFinishedProc) {
98
0
            info.fFinishedProc(info.fFinishedContext);
99
0
        }
100
0
        return false;
101
0
    }
102
103
18.4k
    SkDEBUGCODE(this->validate());
104
105
    // As of now we only short-circuit if we got an explicit list of surfaces to flush.
106
18.4k
    if (!proxies.empty() && !info.fNumSemaphores && !info.fFinishedProc &&
107
18.4k
        access == SkSurfaces::BackendSurfaceAccess::kNoAccess && !newState) {
108
0
        bool allUnused = std::all_of(proxies.begin(), proxies.end(), [&](GrSurfaceProxy* proxy) {
109
0
            bool used = std::any_of(fDAG.begin(), fDAG.end(), [&](auto& task) {
110
0
                return task && task->isUsed(proxy);
111
0
            });
112
0
            return !used;
113
0
        });
114
0
        if (allUnused) {
115
0
            if (info.fSubmittedProc) {
116
0
                info.fSubmittedProc(info.fSubmittedContext, true);
117
0
            }
118
0
            return false;
119
0
        }
120
0
    }
121
122
18.4k
    auto dContext = fContext->asDirectContext();
123
18.4k
    SkASSERT(dContext);
124
18.4k
    dContext->priv().clientMappedBufferManager()->process();
125
126
18.4k
    GrGpu* gpu = dContext->priv().getGpu();
127
    // We have a non abandoned and direct GrContext. It must have a GrGpu.
128
18.4k
    SkASSERT(gpu);
129
130
18.4k
    fFlushing = true;
131
132
18.4k
    auto resourceProvider = dContext->priv().resourceProvider();
133
18.4k
    auto resourceCache = dContext->priv().getResourceCache();
134
135
    // Semi-usually the GrRenderTasks are already closed at this point, but sometimes Ganesh needs
136
    // to flush mid-draw. In that case, the SkGpuDevice's opsTasks won't be closed but need to be
137
    // flushed anyway. Closing such opsTasks here will mean new ones will be created to replace them
138
    // if the SkGpuDevice(s) write to them again.
139
18.4k
    this->closeAllTasks();
140
18.4k
    fActiveOpsTask = nullptr;
141
142
18.4k
    this->sortTasks();
143
144
18.4k
    if (!fCpuBufferCache) {
145
        // We cache more buffers when the backend is using client side arrays. Otherwise, we
146
        // expect each pool will use a CPU buffer as a staging buffer before uploading to a GPU
147
        // buffer object. Each pool only requires one staging buffer at a time.
148
2.58k
        int maxCachedBuffers = fContext->priv().caps()->preferClientSideDynamicBuffers() ? 2 : 6;
149
2.58k
        fCpuBufferCache = GrBufferAllocPool::CpuBufferCache::Make(maxCachedBuffers);
150
2.58k
    }
151
152
18.4k
    GrOpFlushState flushState(gpu, resourceProvider, &fTokenTracker, fCpuBufferCache);
153
154
18.4k
    GrOnFlushResourceProvider onFlushProvider(this);
155
156
    // Prepare any onFlush op lists (e.g. atlases).
157
18.4k
    bool preFlushSuccessful = true;
158
22.8k
    for (GrOnFlushCallbackObject* onFlushCBObject : fOnFlushCBObjects) {
159
22.8k
        preFlushSuccessful &= onFlushCBObject->preFlush(&onFlushProvider);
160
22.8k
    }
161
162
18.4k
    bool cachePurgeNeeded = false;
163
164
18.4k
    if (preFlushSuccessful) {
165
18.4k
        bool usingReorderedDAG = false;
166
18.4k
        GrResourceAllocator resourceAllocator(dContext);
167
18.4k
        if (fReduceOpsTaskSplitting) {
168
18.4k
            usingReorderedDAG = this->reorderTasks(&resourceAllocator);
169
18.4k
            if (!usingReorderedDAG) {
170
17.3k
                resourceAllocator.reset();
171
17.3k
            }
172
18.4k
        }
173
174
#if 0
175
        // Enable this to print out verbose GrOp information
176
        SkDEBUGCODE(SkDebugf("RenderTasks (%d):\n", fDAG.count()));
177
        for (const auto& task : fDAG) {
178
            SkDEBUGCODE(task->dump(/* printDependencies */ true);)
179
        }
180
#endif
181
182
18.4k
        if (!resourceAllocator.failedInstantiation()) {
183
18.4k
            if (!usingReorderedDAG) {
184
30.2k
                for (const auto& task : fDAG) {
185
30.2k
                    SkASSERT(task);
186
30.2k
                    task->gatherProxyIntervals(&resourceAllocator);
187
30.2k
                }
188
17.3k
                resourceAllocator.planAssignment();
189
17.3k
            }
190
18.4k
            resourceAllocator.assign();
191
18.4k
        }
192
193
18.4k
        cachePurgeNeeded = !resourceAllocator.failedInstantiation() &&
194
18.4k
                           this->executeRenderTasks(&flushState);
195
18.4k
    }
196
18.4k
    this->removeRenderTasks();
197
198
18.4k
    gpu->executeFlushInfo(proxies, access, info, newState);
199
200
    // Give the cache a chance to purge resources that become purgeable due to flushing.
201
18.4k
    if (cachePurgeNeeded) {
202
3.28k
        resourceCache->purgeAsNeeded();
203
3.28k
        cachePurgeNeeded = false;
204
3.28k
    }
205
22.9k
    for (GrOnFlushCallbackObject* onFlushCBObject : fOnFlushCBObjects) {
206
22.9k
        onFlushCBObject->postFlush(fTokenTracker.nextFlushToken());
207
22.9k
        cachePurgeNeeded = true;
208
22.9k
    }
209
18.4k
    if (cachePurgeNeeded) {
210
18.4k
        resourceCache->purgeAsNeeded();
211
18.4k
    }
212
18.4k
    fFlushing = false;
213
214
18.4k
    return true;
215
18.4k
}
216
217
0
bool GrDrawingManager::submitToGpu(GrSyncCpu sync) {
218
0
    if (fFlushing || this->wasAbandoned()) {
219
0
        return false;
220
0
    }
221
222
0
    auto direct = fContext->asDirectContext();
223
0
    if (!direct) {
224
0
        return false; // Can't submit while DDL recording
225
0
    }
226
0
    GrGpu* gpu = direct->priv().getGpu();
227
0
    return gpu->submitToGpu(sync);
228
0
}
229
230
18.4k
bool GrDrawingManager::executeRenderTasks(GrOpFlushState* flushState) {
231
#if GR_FLUSH_TIME_OP_SPEW
232
    SkDebugf("Flushing %d opsTasks\n", fDAG.size());
233
    for (int i = 0; i < fDAG.size(); ++i) {
234
        if (fDAG[i]) {
235
            SkString label;
236
            label.printf("task %d/%d", i, fDAG.size());
237
            fDAG[i]->dump(label, {}, true, true);
238
        }
239
    }
240
#endif
241
242
18.4k
    bool anyRenderTasksExecuted = false;
243
244
126k
    for (const auto& renderTask : fDAG) {
245
126k
        if (!renderTask || !renderTask->isInstantiated()) {
246
0
             continue;
247
0
        }
248
249
126k
        SkASSERT(renderTask->deferredProxiesAreInstantiated());
250
251
126k
        renderTask->prepare(flushState);
252
126k
    }
253
254
    // Upload all data to the GPU
255
18.4k
    flushState->preExecuteDraws();
256
257
    // For Vulkan, if we have too many oplists to be flushed we end up allocating a lot of resources
258
    // for each command buffer associated with the oplists. If this gets too large we can cause the
259
    // devices to go OOM. In practice we usually only hit this case in our tests, but to be safe we
260
    // put a cap on the number of oplists we will execute before flushing to the GPU to relieve some
261
    // memory pressure.
262
18.4k
    static constexpr int kMaxRenderTasksBeforeFlush = 100;
263
18.4k
    int numRenderTasksExecuted = 0;
264
265
    // Execute the normal op lists.
266
126k
    for (const auto& renderTask : fDAG) {
267
126k
        SkASSERT(renderTask);
268
126k
        if (!renderTask->isInstantiated()) {
269
0
            continue;
270
0
        }
271
272
126k
        if (renderTask->execute(flushState)) {
273
126k
            anyRenderTasksExecuted = true;
274
126k
        }
275
126k
        if (++numRenderTasksExecuted >= kMaxRenderTasksBeforeFlush) {
276
876
            flushState->gpu()->submitToGpu(GrSyncCpu::kNo);
277
876
            numRenderTasksExecuted = 0;
278
876
        }
279
126k
    }
280
281
18.4k
    SkASSERT(!flushState->opsRenderPass());
282
18.4k
    SkASSERT(fTokenTracker.nextDrawToken() == fTokenTracker.nextFlushToken());
283
284
    // We reset the flush state before the RenderTasks so that the last resources to be freed are
285
    // those that are written to in the RenderTasks. This helps to make sure the most recently used
286
    // resources are the last to be purged by the resource cache.
287
18.4k
    flushState->reset();
288
289
18.4k
    return anyRenderTasksExecuted;
290
18.4k
}
GrDrawingManager::executeRenderTasks(GrOpFlushState*)
Line
Count
Source
230
18.4k
bool GrDrawingManager::executeRenderTasks(GrOpFlushState* flushState) {
231
#if GR_FLUSH_TIME_OP_SPEW
232
    SkDebugf("Flushing %d opsTasks\n", fDAG.size());
233
    for (int i = 0; i < fDAG.size(); ++i) {
234
        if (fDAG[i]) {
235
            SkString label;
236
            label.printf("task %d/%d", i, fDAG.size());
237
            fDAG[i]->dump(label, {}, true, true);
238
        }
239
    }
240
#endif
241
242
18.4k
    bool anyRenderTasksExecuted = false;
243
244
126k
    for (const auto& renderTask : fDAG) {
245
126k
        if (!renderTask || !renderTask->isInstantiated()) {
246
0
             continue;
247
0
        }
248
249
126k
        SkASSERT(renderTask->deferredProxiesAreInstantiated());
250
251
126k
        renderTask->prepare(flushState);
252
126k
    }
253
254
    // Upload all data to the GPU
255
18.4k
    flushState->preExecuteDraws();
256
257
    // For Vulkan, if we have too many oplists to be flushed we end up allocating a lot of resources
258
    // for each command buffer associated with the oplists. If this gets too large we can cause the
259
    // devices to go OOM. In practice we usually only hit this case in our tests, but to be safe we
260
    // put a cap on the number of oplists we will execute before flushing to the GPU to relieve some
261
    // memory pressure.
262
18.4k
    static constexpr int kMaxRenderTasksBeforeFlush = 100;
263
18.4k
    int numRenderTasksExecuted = 0;
264
265
    // Execute the normal op lists.
266
126k
    for (const auto& renderTask : fDAG) {
267
126k
        SkASSERT(renderTask);
268
126k
        if (!renderTask->isInstantiated()) {
269
0
            continue;
270
0
        }
271
272
126k
        if (renderTask->execute(flushState)) {
273
126k
            anyRenderTasksExecuted = true;
274
126k
        }
275
126k
        if (++numRenderTasksExecuted >= kMaxRenderTasksBeforeFlush) {
276
876
            flushState->gpu()->submitToGpu(GrSyncCpu::kNo);
277
876
            numRenderTasksExecuted = 0;
278
876
        }
279
126k
    }
280
281
18.4k
    SkASSERT(!flushState->opsRenderPass());
282
18.4k
    SkASSERT(fTokenTracker.nextDrawToken() == fTokenTracker.nextFlushToken());
283
284
    // We reset the flush state before the RenderTasks so that the last resources to be freed are
285
    // those that are written to in the RenderTasks. This helps to make sure the most recently used
286
    // resources are the last to be purged by the resource cache.
287
18.4k
    flushState->reset();
288
289
18.4k
    return anyRenderTasksExecuted;
290
18.4k
}
Unexecuted instantiation: GrDrawingManager::executeRenderTasks(GrOpFlushState*)
291
292
21.0k
void GrDrawingManager::removeRenderTasks() {
293
126k
    for (const auto& task : fDAG) {
294
126k
        SkASSERT(task);
295
126k
        if (!task->unique() || task->requiresExplicitCleanup()) {
296
            // TODO: Eventually uniqueness should be guaranteed: http://skbug.com/7111.
297
            // DDLs, however, will always require an explicit notification for when they
298
            // can clean up resources.
299
1.03k
            task->endFlush(this);
300
1.03k
        }
301
126k
        task->disown(this);
302
126k
    }
303
21.0k
    fDAG.clear();
304
21.0k
    fReorderBlockerTaskIndices.clear();
305
21.0k
    fLastRenderTasks.reset();
306
21.0k
}
307
308
18.4k
void GrDrawingManager::sortTasks() {
309
    // We separately sort the ranges around non-reorderable tasks.
310
21.7k
    for (size_t i = 0, start = 0, end; start < SkToSizeT(fDAG.size()); ++i, start = end + 1) {
311
3.28k
        end = i == fReorderBlockerTaskIndices.size() ? fDAG.size() : fReorderBlockerTaskIndices[i];
312
3.28k
        SkSpan span(fDAG.begin() + start, end - start);
313
314
3.28k
        SkASSERT(std::none_of(span.begin(), span.end(), [](const auto& t) {
315
3.28k
            return t->blocksReordering();
316
3.28k
        }));
317
3.28k
        SkASSERT(span.end() == fDAG.end() || fDAG[end]->blocksReordering());
318
319
#if defined(SK_DEBUG)
320
        // In order to partition the dag array like this it must be the case that each partition
321
        // only depends on nodes in the partition or earlier partitions.
322
0
        auto check = [&](const GrRenderTask* task, auto&& check) -> void {
323
0
            SkASSERT(GrRenderTask::TopoSortTraits::WasOutput(task) ||
324
0
                     std::find_if(span.begin(), span.end(), [task](const auto& n) {
325
0
                         return n.get() == task; }));
326
0
            for (int i = 0; i < task->fDependencies.size(); ++i) {
327
0
                check(task->fDependencies[i], check);
328
0
            }
329
0
        };
330
0
        for (const auto& node : span) {
331
0
            check(node.get(), check);
332
0
        }
333
#endif
334
335
3.28k
        bool sorted = GrTTopoSort<GrRenderTask, GrRenderTask::TopoSortTraits>(span, start);
336
3.28k
        if (!sorted) {
337
0
            SkDEBUGFAIL("Render task topo sort failed.");
338
0
        }
339
340
#ifdef SK_DEBUG
341
0
        if (sorted && !span.empty()) {
342
            // This block checks for any unnecessary splits in the opsTasks. If two sequential
343
            // opsTasks could have merged it means the opsTask was artificially split.
344
0
            auto prevOpsTask = span[0]->asOpsTask();
345
0
            for (size_t j = 1; j < span.size(); ++j) {
346
0
                auto curOpsTask = span[j]->asOpsTask();
347
348
0
                if (prevOpsTask && curOpsTask) {
349
0
                    SkASSERT(!prevOpsTask->canMerge(curOpsTask));
350
0
                }
351
352
0
                prevOpsTask = curOpsTask;
353
0
            }
354
0
        }
355
#endif
356
3.28k
    }
357
18.4k
}
GrDrawingManager::sortTasks()
Line
Count
Source
308
18.4k
void GrDrawingManager::sortTasks() {
309
    // We separately sort the ranges around non-reorderable tasks.
310
21.7k
    for (size_t i = 0, start = 0, end; start < SkToSizeT(fDAG.size()); ++i, start = end + 1) {
311
3.28k
        end = i == fReorderBlockerTaskIndices.size() ? fDAG.size() : fReorderBlockerTaskIndices[i];
312
3.28k
        SkSpan span(fDAG.begin() + start, end - start);
313
314
3.28k
        SkASSERT(std::none_of(span.begin(), span.end(), [](const auto& t) {
315
3.28k
            return t->blocksReordering();
316
3.28k
        }));
317
3.28k
        SkASSERT(span.end() == fDAG.end() || fDAG[end]->blocksReordering());
318
319
#if defined(SK_DEBUG)
320
        // In order to partition the dag array like this it must be the case that each partition
321
        // only depends on nodes in the partition or earlier partitions.
322
        auto check = [&](const GrRenderTask* task, auto&& check) -> void {
323
            SkASSERT(GrRenderTask::TopoSortTraits::WasOutput(task) ||
324
                     std::find_if(span.begin(), span.end(), [task](const auto& n) {
325
                         return n.get() == task; }));
326
            for (int i = 0; i < task->fDependencies.size(); ++i) {
327
                check(task->fDependencies[i], check);
328
            }
329
        };
330
        for (const auto& node : span) {
331
            check(node.get(), check);
332
        }
333
#endif
334
335
3.28k
        bool sorted = GrTTopoSort<GrRenderTask, GrRenderTask::TopoSortTraits>(span, start);
336
3.28k
        if (!sorted) {
337
0
            SkDEBUGFAIL("Render task topo sort failed.");
338
0
        }
339
340
#ifdef SK_DEBUG
341
        if (sorted && !span.empty()) {
342
            // This block checks for any unnecessary splits in the opsTasks. If two sequential
343
            // opsTasks could have merged it means the opsTask was artificially split.
344
            auto prevOpsTask = span[0]->asOpsTask();
345
            for (size_t j = 1; j < span.size(); ++j) {
346
                auto curOpsTask = span[j]->asOpsTask();
347
348
                if (prevOpsTask && curOpsTask) {
349
                    SkASSERT(!prevOpsTask->canMerge(curOpsTask));
350
                }
351
352
                prevOpsTask = curOpsTask;
353
            }
354
        }
355
#endif
356
3.28k
    }
357
18.4k
}
Unexecuted instantiation: GrDrawingManager::sortTasks()
358
359
// Reorder the array to match the llist without reffing & unreffing sk_sp's.
360
// Both args must contain the same objects.
361
// This is basically a shim because clustering uses LList but the rest of drawmgr uses array.
362
template <typename T>
363
1.09k
static void reorder_array_by_llist(const SkTInternalLList<T>& llist, TArray<sk_sp<T>>* array) {
364
1.09k
    int i = 0;
365
108k
    for (T* t : llist) {
366
        // Release the pointer that used to live here so it doesn't get unreffed.
367
108k
        [[maybe_unused]] T* old = array->at(i).release();
368
108k
        array->at(i++).reset(t);
369
108k
    }
370
1.09k
    SkASSERT(i == array->size());
371
1.09k
}
372
373
18.4k
bool GrDrawingManager::reorderTasks(GrResourceAllocator* resourceAllocator) {
374
18.4k
    SkASSERT(fReduceOpsTaskSplitting);
375
    // We separately sort the ranges around non-reorderable tasks.
376
18.4k
    bool clustered = false;
377
18.4k
    SkTInternalLList<GrRenderTask> llist;
378
21.7k
    for (size_t i = 0, start = 0, end; start < SkToSizeT(fDAG.size()); ++i, start = end + 1) {
379
3.28k
        end = i == fReorderBlockerTaskIndices.size() ? fDAG.size() : fReorderBlockerTaskIndices[i];
380
3.28k
        SkSpan span(fDAG.begin() + start, end - start);
381
3.28k
        SkASSERT(std::none_of(span.begin(), span.end(), [](const auto& t) {
382
3.28k
            return t->blocksReordering();
383
3.28k
        }));
384
385
3.28k
        SkTInternalLList<GrRenderTask> subllist;
386
3.28k
        if (GrClusterRenderTasks(span, &subllist)) {
387
1.09k
            clustered = true;
388
1.09k
        }
389
390
3.28k
        if (i < fReorderBlockerTaskIndices.size()) {
391
0
            SkASSERT(fDAG[fReorderBlockerTaskIndices[i]]->blocksReordering());
392
0
            subllist.addToTail(fDAG[fReorderBlockerTaskIndices[i]].get());
393
0
        }
394
3.28k
        llist.concat(std::move(subllist));
395
3.28k
    }
396
18.4k
    if (!clustered) {
397
17.3k
        return false;
398
17.3k
    }
399
400
115k
    for (GrRenderTask* task : llist) {
401
115k
        task->gatherProxyIntervals(resourceAllocator);
402
115k
    }
403
1.09k
    if (!resourceAllocator->planAssignment()) {
404
0
        return false;
405
0
    }
406
1.09k
    if (!resourceAllocator->makeBudgetHeadroom()) {
407
7
        auto dContext = fContext->asDirectContext();
408
7
        SkASSERT(dContext);
409
7
        dContext->priv().getGpu()->stats()->incNumReorderedDAGsOverBudget();
410
7
        return false;
411
7
    }
412
1.09k
    reorder_array_by_llist(llist, &fDAG);
413
414
1.09k
    int newCount = 0;
415
97.5k
    for (int i = 0; i < fDAG.size(); i++) {
416
96.4k
        sk_sp<GrRenderTask>& task = fDAG[i];
417
96.4k
        if (auto opsTask = task->asOpsTask()) {
418
70.4k
            size_t remaining = fDAG.size() - i - 1;
419
70.4k
            SkSpan<sk_sp<GrRenderTask>> nextTasks{fDAG.end() - remaining, remaining};
420
70.4k
            int removeCount = opsTask->mergeFrom(nextTasks);
421
70.4k
            for (const auto& removed : nextTasks.first(removeCount)) {
422
11.5k
                removed->disown(this);
423
11.5k
            }
424
70.4k
            i += removeCount;
425
70.4k
        }
426
96.4k
        fDAG[newCount++] = std::move(task);
427
96.4k
    }
428
1.09k
    fDAG.resize_back(newCount);
429
1.09k
    return true;
430
1.09k
}
431
432
21.0k
void GrDrawingManager::closeAllTasks() {
433
138k
    for (auto& task : fDAG) {
434
138k
        if (task) {
435
138k
            task->makeClosed(fContext);
436
138k
        }
437
138k
    }
438
21.0k
}
439
440
0
GrRenderTask* GrDrawingManager::insertTaskBeforeLast(sk_sp<GrRenderTask> task) {
441
0
    if (!task) {
442
0
        return nullptr;
443
0
    }
444
0
    if (fDAG.empty()) {
445
0
        return fDAG.push_back(std::move(task)).get();
446
0
    }
447
0
    if (!fReorderBlockerTaskIndices.empty() && fReorderBlockerTaskIndices.back() == fDAG.size()) {
448
0
        fReorderBlockerTaskIndices.back()++;
449
0
    }
450
0
    fDAG.push_back(std::move(task));
451
0
    auto& penultimate = fDAG.fromBack(1);
452
0
    fDAG.back().swap(penultimate);
453
0
    return penultimate.get();
454
0
}
455
456
138k
GrRenderTask* GrDrawingManager::appendTask(sk_sp<GrRenderTask> task) {
457
138k
    if (!task) {
458
0
        return nullptr;
459
0
    }
460
138k
    if (task->blocksReordering()) {
461
0
        fReorderBlockerTaskIndices.push_back(fDAG.size());
462
0
    }
463
138k
    return fDAG.push_back(std::move(task)).get();
464
138k
}
465
466
0
static void resolve_and_mipmap(GrGpu* gpu, GrSurfaceProxy* proxy) {
467
0
    if (!proxy->isInstantiated()) {
468
0
        return;
469
0
    }
470
471
    // In the flushSurfaces case, we need to resolve MSAA immediately after flush. This is
472
    // because clients expect the flushed surface's backing texture to be fully resolved
473
    // upon return.
474
0
    if (proxy->requiresManualMSAAResolve()) {
475
0
        auto* rtProxy = proxy->asRenderTargetProxy();
476
0
        SkASSERT(rtProxy);
477
0
        if (rtProxy->isMSAADirty()) {
478
0
            SkASSERT(rtProxy->peekRenderTarget());
479
0
            gpu->resolveRenderTarget(rtProxy->peekRenderTarget(), rtProxy->msaaDirtyRect());
480
0
            gpu->submitToGpu(GrSyncCpu::kNo);
481
0
            rtProxy->markMSAAResolved();
482
0
        }
483
0
    }
484
    // If, after a flush, any of the proxies of interest have dirty mipmaps, regenerate them in
485
    // case their backend textures are being stolen.
486
    // (This special case is exercised by the ReimportImageTextureWithMipLevels test.)
487
    // FIXME: It may be more ideal to plumb down a "we're going to steal the backends" flag.
488
0
    if (auto* textureProxy = proxy->asTextureProxy()) {
489
0
        if (textureProxy->mipmapsAreDirty()) {
490
0
            SkASSERT(textureProxy->peekTexture());
491
0
            gpu->regenerateMipMapLevels(textureProxy->peekTexture());
492
0
            textureProxy->markMipmapsClean();
493
0
        }
494
0
    }
495
0
}
Unexecuted instantiation: GrDrawingManager.cpp:resolve_and_mipmap(GrGpu*, GrSurfaceProxy*)
Unexecuted instantiation: GrDrawingManager.cpp:resolve_and_mipmap(GrGpu*, GrSurfaceProxy*)
496
497
GrSemaphoresSubmitted GrDrawingManager::flushSurfaces(SkSpan<GrSurfaceProxy*> proxies,
498
                                                      SkSurfaces::BackendSurfaceAccess access,
499
                                                      const GrFlushInfo& info,
500
18.4k
                                                      const skgpu::MutableTextureState* newState) {
501
18.4k
    if (this->wasAbandoned()) {
502
0
        if (info.fSubmittedProc) {
503
0
            info.fSubmittedProc(info.fSubmittedContext, false);
504
0
        }
505
0
        if (info.fFinishedProc) {
506
0
            info.fFinishedProc(info.fFinishedContext);
507
0
        }
508
0
        return GrSemaphoresSubmitted::kNo;
509
0
    }
510
18.4k
    SkDEBUGCODE(this->validate());
511
512
18.4k
    auto direct = fContext->asDirectContext();
513
18.4k
    SkASSERT(direct);
514
18.4k
    GrGpu* gpu = direct->priv().getGpu();
515
    // We have a non abandoned and direct GrContext. It must have a GrGpu.
516
18.4k
    SkASSERT(gpu);
517
518
    // TODO: It is important to upgrade the drawingmanager to just flushing the
519
    // portion of the DAG required by 'proxies' in order to restore some of the
520
    // semantics of this method.
521
18.4k
    bool didFlush = this->flush(proxies, access, info, newState);
522
18.4k
    for (GrSurfaceProxy* proxy : proxies) {
523
0
        resolve_and_mipmap(gpu, proxy);
524
0
    }
525
526
18.4k
    SkDEBUGCODE(this->validate());
527
528
18.4k
    if (!didFlush || (!direct->priv().caps()->backendSemaphoreSupport() && info.fNumSemaphores)) {
529
0
        return GrSemaphoresSubmitted::kNo;
530
0
    }
531
18.4k
    return GrSemaphoresSubmitted::kYes;
532
18.4k
}
533
534
2.67k
void GrDrawingManager::addOnFlushCallbackObject(GrOnFlushCallbackObject* onFlushCBObject) {
535
2.67k
    fOnFlushCBObjects.push_back(onFlushCBObject);
536
2.67k
}
537
538
#if defined(GR_TEST_UTILS)
539
0
void GrDrawingManager::testingOnly_removeOnFlushCallbackObject(GrOnFlushCallbackObject* cb) {
540
0
    int n = std::find(fOnFlushCBObjects.begin(), fOnFlushCBObjects.end(), cb) -
541
0
            fOnFlushCBObjects.begin();
542
0
    SkASSERT(n < fOnFlushCBObjects.size());
543
0
    fOnFlushCBObjects.removeShuffle(n);
544
0
}
Unexecuted instantiation: GrDrawingManager::testingOnly_removeOnFlushCallbackObject(GrOnFlushCallbackObject*)
Unexecuted instantiation: GrDrawingManager::testingOnly_removeOnFlushCallbackObject(GrOnFlushCallbackObject*)
545
#endif
546
547
241k
void GrDrawingManager::setLastRenderTask(const GrSurfaceProxy* proxy, GrRenderTask* task) {
548
#ifdef SK_DEBUG
549
    if (auto prior = this->getLastRenderTask(proxy)) {
550
        SkASSERT(prior->isClosed() || prior == task);
551
    }
552
#endif
553
241k
    uint32_t key = proxy->uniqueID().asUInt();
554
241k
    if (task) {
555
138k
        fLastRenderTasks.set(key, task);
556
138k
    } else if (fLastRenderTasks.find(key)) {
557
103k
        fLastRenderTasks.remove(key);
558
103k
    }
559
241k
}
560
561
447k
GrRenderTask* GrDrawingManager::getLastRenderTask(const GrSurfaceProxy* proxy) const {
562
447k
    auto entry = fLastRenderTasks.find(proxy->uniqueID().asUInt());
563
447k
    return entry ? *entry : nullptr;
564
447k
}
565
566
89.0k
skgpu::ganesh::OpsTask* GrDrawingManager::getLastOpsTask(const GrSurfaceProxy* proxy) const {
567
89.0k
    GrRenderTask* task = this->getLastRenderTask(proxy);
568
89.0k
    return task ? task->asOpsTask() : nullptr;
569
89.0k
}
570
571
0
void GrDrawingManager::moveRenderTasksToDDL(GrDeferredDisplayList* ddl) {
572
0
    SkDEBUGCODE(this->validate());
573
574
    // no renderTask should receive a new command after this
575
0
    this->closeAllTasks();
576
0
    fActiveOpsTask = nullptr;
577
578
0
    this->sortTasks();
579
580
0
    fDAG.swap(ddl->fRenderTasks);
581
0
    SkASSERT(fDAG.empty());
582
0
    fReorderBlockerTaskIndices.clear();
583
584
0
    for (auto& renderTask : ddl->fRenderTasks) {
585
0
        renderTask->disown(this);
586
0
        renderTask->prePrepare(fContext);
587
0
    }
588
589
0
    ddl->fArenas = std::move(fContext->priv().detachArenas());
590
591
0
    fContext->priv().detachProgramData(&ddl->fProgramData);
592
593
0
    SkDEBUGCODE(this->validate());
594
0
}
Unexecuted instantiation: GrDrawingManager::moveRenderTasksToDDL(GrDeferredDisplayList*)
Unexecuted instantiation: GrDrawingManager::moveRenderTasksToDDL(GrDeferredDisplayList*)
595
596
void GrDrawingManager::createDDLTask(sk_sp<const GrDeferredDisplayList> ddl,
597
0
                                     sk_sp<GrRenderTargetProxy> newDest) {
598
0
    SkDEBUGCODE(this->validate());
599
600
0
    if (fActiveOpsTask) {
601
        // This is a temporary fix for the partial-MDB world. In that world we're not
602
        // reordering so ops that (in the single opsTask world) would've just glommed onto the
603
        // end of the single opsTask but referred to a far earlier RT need to appear in their
604
        // own opsTask.
605
0
        fActiveOpsTask->makeClosed(fContext);
606
0
        fActiveOpsTask = nullptr;
607
0
    }
608
609
    // Propagate the DDL proxy's state information to the replay target.
610
0
    if (ddl->priv().targetProxy()->isMSAADirty()) {
611
0
        auto nativeRect = GrNativeRect::MakeIRectRelativeTo(
612
0
                ddl->characterization().origin(),
613
0
                ddl->priv().targetProxy()->backingStoreDimensions().height(),
614
0
                ddl->priv().targetProxy()->msaaDirtyRect());
615
0
        newDest->markMSAADirty(nativeRect);
616
0
    }
617
0
    GrTextureProxy* newTextureProxy = newDest->asTextureProxy();
618
0
    if (newTextureProxy && skgpu::Mipmapped::kYes == newTextureProxy->mipmapped()) {
619
0
        newTextureProxy->markMipmapsDirty();
620
0
    }
621
622
    // Here we jam the proxy that backs the current replay SkSurface into the LazyProxyData.
623
    // The lazy proxy that references it (in the DDL opsTasks) will then steal its GrTexture.
624
0
    ddl->fLazyProxyData->fReplayDest = newDest.get();
625
626
    // Add a task to handle drawing and lifetime management of the DDL.
627
0
    SkDEBUGCODE(auto ddlTask =) this->appendTask(sk_make_sp<GrDDLTask>(this,
628
0
                                                                       std::move(newDest),
629
0
                                                                       std::move(ddl)));
630
0
    SkASSERT(ddlTask->isClosed());
631
632
0
    SkDEBUGCODE(this->validate());
633
0
}
Unexecuted instantiation: GrDrawingManager::createDDLTask(sk_sp<GrDeferredDisplayList const>, sk_sp<GrRenderTargetProxy>)
Unexecuted instantiation: GrDrawingManager::createDDLTask(sk_sp<GrDeferredDisplayList const>, sk_sp<GrRenderTargetProxy>)
634
635
#ifdef SK_DEBUG
636
0
void GrDrawingManager::validate() const {
637
0
    if (fActiveOpsTask) {
638
0
        SkASSERT(!fDAG.empty());
639
0
        SkASSERT(!fActiveOpsTask->isClosed());
640
0
        SkASSERT(fActiveOpsTask == fDAG.back().get());
641
0
    }
642
643
0
    for (int i = 0; i < fDAG.size(); ++i) {
644
0
        if (fActiveOpsTask != fDAG[i].get()) {
645
            // The resolveTask associated with the activeTask remains open for as long as the
646
            // activeTask does.
647
0
            bool isActiveResolveTask =
648
0
                fActiveOpsTask && fActiveOpsTask->fTextureResolveTask == fDAG[i].get();
649
0
            bool isAtlas = fDAG[i]->isSetFlag(GrRenderTask::kAtlas_Flag);
650
0
            SkASSERT(isActiveResolveTask || isAtlas || fDAG[i]->isClosed());
651
0
        }
652
0
    }
653
654
    // The active opsTask, if any, should always be at the back of the DAG.
655
0
    if (!fDAG.empty()) {
656
0
        if (fDAG.back()->isSetFlag(GrRenderTask::kAtlas_Flag)) {
657
0
            SkASSERT(fActiveOpsTask == nullptr);
658
0
            SkASSERT(!fDAG.back()->isClosed());
659
0
        } else if (fDAG.back()->isClosed()) {
660
0
            SkASSERT(fActiveOpsTask == nullptr);
661
0
        } else {
662
0
            SkASSERT(fActiveOpsTask == fDAG.back().get());
663
0
        }
664
0
    } else {
665
0
        SkASSERT(fActiveOpsTask == nullptr);
666
0
    }
667
0
}
668
#endif // SK_DEBUG
669
670
138k
void GrDrawingManager::closeActiveOpsTask() {
671
138k
    if (fActiveOpsTask) {
672
        // This is a temporary fix for the partial-MDB world. In that world we're not
673
        // reordering so ops that (in the single opsTask world) would've just glommed onto the
674
        // end of the single opsTask but referred to a far earlier RT need to appear in their
675
        // own opsTask.
676
96.2k
        fActiveOpsTask->makeClosed(fContext);
677
96.2k
        fActiveOpsTask = nullptr;
678
96.2k
    }
679
138k
}
680
681
sk_sp<skgpu::ganesh::OpsTask> GrDrawingManager::newOpsTask(GrSurfaceProxyView surfaceView,
682
99.5k
                                                           sk_sp<GrArenas> arenas) {
683
99.5k
    SkDEBUGCODE(this->validate());
684
99.5k
    SkASSERT(fContext);
685
686
99.5k
    this->closeActiveOpsTask();
687
688
99.5k
    sk_sp<skgpu::ganesh::OpsTask> opsTask(new skgpu::ganesh::OpsTask(
689
99.5k
            this, std::move(surfaceView), fContext->priv().auditTrail(), std::move(arenas)));
690
691
99.5k
    SkASSERT(this->getLastRenderTask(opsTask->target(0)) == opsTask.get());
692
693
99.5k
    this->appendTask(opsTask);
694
695
99.5k
    fActiveOpsTask = opsTask.get();
696
697
99.5k
    SkDEBUGCODE(this->validate());
698
99.5k
    return opsTask;
699
99.5k
}
700
701
void GrDrawingManager::addAtlasTask(sk_sp<GrRenderTask> atlasTask,
702
0
                                    GrRenderTask* previousAtlasTask) {
703
0
    SkDEBUGCODE(this->validate());
704
0
    SkASSERT(fContext);
705
706
0
    if (previousAtlasTask) {
707
0
        previousAtlasTask->makeClosed(fContext);
708
0
        for (GrRenderTask* previousAtlasUser : previousAtlasTask->dependents()) {
709
            // Make the new atlas depend on everybody who used the old atlas, and close their tasks.
710
            // This guarantees that the previous atlas is totally out of service before we render
711
            // the next one, meaning there is only ever one atlas active at a time and that they can
712
            // all share the same texture.
713
0
            atlasTask->addDependency(previousAtlasUser);
714
0
            previousAtlasUser->makeClosed(fContext);
715
0
            if (previousAtlasUser == fActiveOpsTask) {
716
0
                fActiveOpsTask = nullptr;
717
0
            }
718
0
        }
719
0
    }
720
721
0
    atlasTask->setFlag(GrRenderTask::kAtlas_Flag);
722
0
    this->insertTaskBeforeLast(std::move(atlasTask));
723
724
0
    SkDEBUGCODE(this->validate());
725
0
}
Unexecuted instantiation: GrDrawingManager::addAtlasTask(sk_sp<GrRenderTask>, GrRenderTask*)
Unexecuted instantiation: GrDrawingManager::addAtlasTask(sk_sp<GrRenderTask>, GrRenderTask*)
726
727
GrTextureResolveRenderTask* GrDrawingManager::newTextureResolveRenderTaskBefore(
728
0
        const GrCaps& caps) {
729
    // Unlike in the "new opsTask" case, we do not want to close the active opsTask, nor (if we are
730
    // in sorting and opsTask reduction mode) the render tasks that depend on any proxy's current
731
    // state. This is because those opsTasks can still receive new ops and because if they refer to
732
    // the mipmapped version of 'proxy', they will then come to depend on the render task being
733
    // created here.
734
    //
735
    // Add the new textureResolveTask before the fActiveOpsTask (if not in
736
    // sorting/opsTask-splitting-reduction mode) because it will depend upon this resolve task.
737
    // NOTE: Putting it here will also reduce the amount of work required by the topological sort.
738
0
    GrRenderTask* task = this->insertTaskBeforeLast(sk_make_sp<GrTextureResolveRenderTask>());
739
0
    return static_cast<GrTextureResolveRenderTask*>(task);
740
0
}
741
742
void GrDrawingManager::newTextureResolveRenderTask(sk_sp<GrSurfaceProxy> proxy,
743
                                                   GrSurfaceProxy::ResolveFlags flags,
744
0
                                                   const GrCaps& caps) {
745
0
    SkDEBUGCODE(this->validate());
746
0
    SkASSERT(fContext);
747
748
0
    if (!proxy->requiresManualMSAAResolve()) {
749
0
        SkDEBUGCODE(this->validate());
750
0
        return;
751
0
    }
752
753
0
    GrRenderTask* lastTask = this->getLastRenderTask(proxy.get());
754
0
    if (!proxy->asRenderTargetProxy()->isMSAADirty() && (!lastTask || lastTask->isClosed())) {
755
0
        SkDEBUGCODE(this->validate());
756
0
        return;
757
0
    }
758
759
0
    this->closeActiveOpsTask();
760
761
0
    auto resolveTask = sk_make_sp<GrTextureResolveRenderTask>();
762
    // Add proxy also adds all the needed dependencies we need
763
0
    resolveTask->addProxy(this, std::move(proxy), flags, caps);
764
765
0
    auto task = this->appendTask(std::move(resolveTask));
766
0
    task->makeClosed(fContext);
767
768
    // We have closed the previous active oplist but since a new oplist isn't being added there
769
    // shouldn't be an active one.
770
0
    SkASSERT(!fActiveOpsTask);
771
0
    SkDEBUGCODE(this->validate());
772
0
}
Unexecuted instantiation: GrDrawingManager::newTextureResolveRenderTask(sk_sp<GrSurfaceProxy>, GrSurfaceProxy::ResolveFlags, GrCaps const&)
Unexecuted instantiation: GrDrawingManager::newTextureResolveRenderTask(sk_sp<GrSurfaceProxy>, GrSurfaceProxy::ResolveFlags, GrCaps const&)
773
774
void GrDrawingManager::newWaitRenderTask(const sk_sp<GrSurfaceProxy>& proxy,
775
                                         std::unique_ptr<std::unique_ptr<GrSemaphore>[]> semaphores,
776
0
                                         int numSemaphores) {
777
0
    SkDEBUGCODE(this->validate());
778
0
    SkASSERT(fContext);
779
780
0
    sk_sp<GrWaitRenderTask> waitTask = sk_make_sp<GrWaitRenderTask>(GrSurfaceProxyView(proxy),
781
0
                                                                    std::move(semaphores),
782
0
                                                                    numSemaphores);
783
784
0
    if (fActiveOpsTask && (fActiveOpsTask->target(0) == proxy.get())) {
785
0
        SkASSERT(this->getLastRenderTask(proxy.get()) == fActiveOpsTask);
786
0
        this->insertTaskBeforeLast(waitTask);
787
        // In this case we keep the current renderTask open but just insert the new waitTask
788
        // before it in the list. The waitTask will never need to trigger any resolves or mip
789
        // map generation which is the main advantage of going through the proxy version.
790
        // Additionally we would've had to temporarily set the wait task as the lastRenderTask
791
        // on the proxy, add the dependency, and then reset the lastRenderTask to
792
        // fActiveOpsTask. Additionally we make the waitTask depend on all of fActiveOpsTask
793
        // dependencies so that we don't unnecessarily reorder the waitTask before them.
794
        // Note: Any previous Ops already in fActiveOpsTask will get blocked by the wait
795
        // semaphore even though they don't need to be for correctness.
796
797
        // Make sure we add the dependencies of fActiveOpsTask to waitTask first or else we'll
798
        // get a circular self dependency of waitTask on waitTask.
799
0
        waitTask->addDependenciesFromOtherTask(fActiveOpsTask);
800
0
        fActiveOpsTask->addDependency(waitTask.get());
801
0
    } else {
802
        // In this case we just close the previous RenderTask and start and append the waitTask
803
        // to the DAG. Since it is the last task now we call setLastRenderTask on the proxy. If
804
        // there is a lastTask on the proxy we make waitTask depend on that task. This
805
        // dependency isn't strictly needed but it does keep the DAG from reordering the
806
        // waitTask earlier and blocking more tasks.
807
0
        if (GrRenderTask* lastTask = this->getLastRenderTask(proxy.get())) {
808
0
            waitTask->addDependency(lastTask);
809
0
        }
810
0
        this->setLastRenderTask(proxy.get(), waitTask.get());
811
0
        this->closeActiveOpsTask();
812
0
        this->appendTask(waitTask);
813
0
    }
814
0
    waitTask->makeClosed(fContext);
815
816
0
    SkDEBUGCODE(this->validate());
817
0
}
Unexecuted instantiation: GrDrawingManager::newWaitRenderTask(sk_sp<GrSurfaceProxy> const&, std::__1::unique_ptr<std::__1::unique_ptr<GrSemaphore, std::__1::default_delete<GrSemaphore> > [], std::__1::default_delete<std::__1::unique_ptr<GrSemaphore, std::__1::default_delete<GrSemaphore> > []> >, int)
Unexecuted instantiation: GrDrawingManager::newWaitRenderTask(sk_sp<GrSurfaceProxy> const&, std::__1::unique_ptr<std::__1::unique_ptr<GrSemaphore, std::__1::default_delete<GrSemaphore> > [], std::__1::default_delete<std::__1::unique_ptr<GrSemaphore, std::__1::default_delete<GrSemaphore> > []> >, int)
818
819
void GrDrawingManager::newTransferFromRenderTask(const sk_sp<GrSurfaceProxy>& srcProxy,
820
                                                 const SkIRect& srcRect,
821
                                                 GrColorType surfaceColorType,
822
                                                 GrColorType dstColorType,
823
                                                 sk_sp<GrGpuBuffer> dstBuffer,
824
0
                                                 size_t dstOffset) {
825
0
    SkDEBUGCODE(this->validate());
826
0
    SkASSERT(fContext);
827
0
    this->closeActiveOpsTask();
828
829
0
    GrRenderTask* task = this->appendTask(sk_make_sp<GrTransferFromRenderTask>(
830
0
            srcProxy, srcRect, surfaceColorType, dstColorType,
831
0
            std::move(dstBuffer), dstOffset));
832
833
0
    const GrCaps& caps = *fContext->priv().caps();
834
835
    // We always say skgpu::Mipmapped::kNo here since we are always just copying from the base
836
    // layer. We don't need to make sure the whole mip map chain is valid.
837
0
    task->addDependency(
838
0
            this, srcProxy.get(), skgpu::Mipmapped::kNo, GrTextureResolveManager(this), caps);
839
0
    task->makeClosed(fContext);
840
841
    // We have closed the previous active oplist but since a new oplist isn't being added there
842
    // shouldn't be an active one.
843
0
    SkASSERT(!fActiveOpsTask);
844
0
    SkDEBUGCODE(this->validate());
845
0
}
Unexecuted instantiation: GrDrawingManager::newTransferFromRenderTask(sk_sp<GrSurfaceProxy> const&, SkIRect const&, GrColorType, GrColorType, sk_sp<GrGpuBuffer>, unsigned long)
Unexecuted instantiation: GrDrawingManager::newTransferFromRenderTask(sk_sp<GrSurfaceProxy> const&, SkIRect const&, GrColorType, GrColorType, sk_sp<GrGpuBuffer>, unsigned long)
846
847
void GrDrawingManager::newBufferTransferTask(sk_sp<GrGpuBuffer> src,
848
                                             size_t srcOffset,
849
                                             sk_sp<GrGpuBuffer> dst,
850
                                             size_t dstOffset,
851
0
                                             size_t size) {
852
0
    SkASSERT(src);
853
0
    SkASSERT(dst);
854
0
    SkASSERT(srcOffset + size <= src->size());
855
0
    SkASSERT(dstOffset + size <= dst->size());
856
0
    SkASSERT(src->intendedType() == GrGpuBufferType::kXferCpuToGpu);
857
0
    SkASSERT(dst->intendedType() != GrGpuBufferType::kXferCpuToGpu);
858
859
0
    SkDEBUGCODE(this->validate());
860
0
    SkASSERT(fContext);
861
862
0
    this->closeActiveOpsTask();
863
864
0
    sk_sp<GrRenderTask> task = GrBufferTransferRenderTask::Make(std::move(src),
865
0
                                                                srcOffset,
866
0
                                                                std::move(dst),
867
0
                                                                dstOffset,
868
0
                                                                size);
869
0
    SkASSERT(task);
870
871
0
    this->appendTask(task);
872
0
    task->makeClosed(fContext);
873
874
    // We have closed the previous active oplist but since a new oplist isn't being added there
875
    // shouldn't be an active one.
876
0
    SkASSERT(!fActiveOpsTask);
877
0
    SkDEBUGCODE(this->validate());
878
0
}
Unexecuted instantiation: GrDrawingManager::newBufferTransferTask(sk_sp<GrGpuBuffer>, unsigned long, sk_sp<GrGpuBuffer>, unsigned long, unsigned long)
Unexecuted instantiation: GrDrawingManager::newBufferTransferTask(sk_sp<GrGpuBuffer>, unsigned long, sk_sp<GrGpuBuffer>, unsigned long, unsigned long)
879
880
void GrDrawingManager::newBufferUpdateTask(sk_sp<SkData> src,
881
                                           sk_sp<GrGpuBuffer> dst,
882
0
                                           size_t dstOffset) {
883
0
    SkASSERT(src);
884
0
    SkASSERT(dst);
885
0
    SkASSERT(dstOffset + src->size() <= dst->size());
886
0
    SkASSERT(dst->intendedType() != GrGpuBufferType::kXferCpuToGpu);
887
0
    SkASSERT(!dst->isMapped());
888
889
0
    SkDEBUGCODE(this->validate());
890
0
    SkASSERT(fContext);
891
892
0
    this->closeActiveOpsTask();
893
894
0
    sk_sp<GrRenderTask> task = GrBufferUpdateRenderTask::Make(std::move(src),
895
0
                                                              std::move(dst),
896
0
                                                              dstOffset);
897
0
    SkASSERT(task);
898
899
0
    this->appendTask(task);
900
0
    task->makeClosed(fContext);
901
902
    // We have closed the previous active oplist but since a new oplist isn't being added there
903
    // shouldn't be an active one.
904
0
    SkASSERT(!fActiveOpsTask);
905
0
    SkDEBUGCODE(this->validate());
906
0
}
Unexecuted instantiation: GrDrawingManager::newBufferUpdateTask(sk_sp<SkData>, sk_sp<GrGpuBuffer>, unsigned long)
Unexecuted instantiation: GrDrawingManager::newBufferUpdateTask(sk_sp<SkData>, sk_sp<GrGpuBuffer>, unsigned long)
907
908
sk_sp<GrRenderTask> GrDrawingManager::newCopyRenderTask(sk_sp<GrSurfaceProxy> dst,
909
                                                        SkIRect dstRect,
910
                                                        const sk_sp<GrSurfaceProxy>& src,
911
                                                        SkIRect srcRect,
912
                                                        GrSamplerState::Filter filter,
913
38.6k
                                                        GrSurfaceOrigin origin) {
914
38.6k
    SkDEBUGCODE(this->validate());
915
38.6k
    SkASSERT(fContext);
916
917
    // It'd be nicer to check this in GrCopyRenderTask::Make. This gets complicated because of
918
    // "active ops task" tracking. dst will be the target of our copy task but it might also be the
919
    // target of the active ops task. We currently require the active ops task to be closed before
920
    // making a new task that targets the same proxy. However, if we first close the active ops
921
    // task, then fail to make a copy task, the next active ops task may target the same proxy. This
922
    // will trip an assert related to unnecessary ops task splitting.
923
38.6k
    if (src->framebufferOnly()) {
924
0
        return nullptr;
925
0
    }
926
927
38.6k
    this->closeActiveOpsTask();
928
929
38.6k
    sk_sp<GrRenderTask> task = GrCopyRenderTask::Make(this,
930
38.6k
                                                      std::move(dst),
931
38.6k
                                                      dstRect,
932
38.6k
                                                      src,
933
38.6k
                                                      srcRect,
934
38.6k
                                                      filter,
935
38.6k
                                                      origin);
936
38.6k
    if (!task) {
937
0
        return nullptr;
938
0
    }
939
940
38.6k
    this->appendTask(task);
941
942
38.6k
    const GrCaps& caps = *fContext->priv().caps();
943
    // We always say skgpu::Mipmapped::kNo here since we are always just copying from the base layer
944
    // to another base layer. We don't need to make sure the whole mip map chain is valid.
945
38.6k
    task->addDependency(
946
38.6k
            this, src.get(), skgpu::Mipmapped::kNo, GrTextureResolveManager(this), caps);
947
38.6k
    task->makeClosed(fContext);
948
949
    // We have closed the previous active oplist but since a new oplist isn't being added there
950
    // shouldn't be an active one.
951
38.6k
    SkASSERT(!fActiveOpsTask);
952
38.6k
    SkDEBUGCODE(this->validate());
953
38.6k
    return task;
954
38.6k
}
955
956
bool GrDrawingManager::newWritePixelsTask(sk_sp<GrSurfaceProxy> dst,
957
                                          SkIRect rect,
958
                                          GrColorType srcColorType,
959
                                          GrColorType dstColorType,
960
                                          const GrMipLevel levels[],
961
0
                                          int levelCount) {
962
0
    SkDEBUGCODE(this->validate());
963
0
    SkASSERT(fContext);
964
965
0
    this->closeActiveOpsTask();
966
0
    const GrCaps& caps = *fContext->priv().caps();
967
968
    // On platforms that prefer flushes over VRAM use (i.e., ANGLE) we're better off forcing a
969
    // complete flush here.
970
0
    if (!caps.preferVRAMUseOverFlushes()) {
971
0
        this->flushSurfaces(SkSpan<GrSurfaceProxy*>{},
972
0
                            SkSurfaces::BackendSurfaceAccess::kNoAccess,
973
0
                            GrFlushInfo{},
974
0
                            nullptr);
975
0
    }
976
977
0
    GrRenderTask* task = this->appendTask(GrWritePixelsTask::Make(this,
978
0
                                                                  std::move(dst),
979
0
                                                                  rect,
980
0
                                                                  srcColorType,
981
0
                                                                  dstColorType,
982
0
                                                                  levels,
983
0
                                                                  levelCount));
984
0
    if (!task) {
985
0
        return false;
986
0
    }
987
988
0
    task->makeClosed(fContext);
989
990
    // We have closed the previous active oplist but since a new oplist isn't being added there
991
    // shouldn't be an active one.
992
0
    SkASSERT(!fActiveOpsTask);
993
0
    SkDEBUGCODE(this->validate());
994
0
    return true;
995
0
}
Unexecuted instantiation: GrDrawingManager::newWritePixelsTask(sk_sp<GrSurfaceProxy>, SkIRect, GrColorType, GrColorType, GrMipLevel const*, int)
Unexecuted instantiation: GrDrawingManager::newWritePixelsTask(sk_sp<GrSurfaceProxy>, SkIRect, GrColorType, GrColorType, GrMipLevel const*, int)
996
997
/*
998
 * This method finds a path renderer that can draw the specified path on
999
 * the provided target.
1000
 * Due to its expense, the software path renderer has split out so it can
1001
 * can be individually allowed/disallowed via the "allowSW" boolean.
1002
 */
1003
skgpu::ganesh::PathRenderer* GrDrawingManager::getPathRenderer(
1004
        const PathRenderer::CanDrawPathArgs& args,
1005
        bool allowSW,
1006
        PathRendererChain::DrawType drawType,
1007
51.4k
        PathRenderer::StencilSupport* stencilSupport) {
1008
51.4k
    if (!fPathRendererChain) {
1009
421
        fPathRendererChain =
1010
421
                std::make_unique<PathRendererChain>(fContext, fOptionsForPathRendererChain);
1011
421
    }
1012
1013
51.4k
    auto pr = fPathRendererChain->getPathRenderer(args, drawType, stencilSupport);
1014
51.4k
    if (!pr && allowSW) {
1015
0
        auto swPR = this->getSoftwarePathRenderer();
1016
0
        if (PathRenderer::CanDrawPath::kNo != swPR->canDrawPath(args)) {
1017
0
            pr = swPR;
1018
0
        }
1019
0
    }
1020
1021
#if GR_PATH_RENDERER_SPEW
1022
    if (pr) {
1023
        SkDebugf("getPathRenderer: %s\n", pr->name());
1024
    }
1025
#endif
1026
1027
51.4k
    return pr;
1028
51.4k
}
1029
1030
7.24k
skgpu::ganesh::PathRenderer* GrDrawingManager::getSoftwarePathRenderer() {
1031
7.24k
    if (!fSoftwarePathRenderer) {
1032
327
        fSoftwarePathRenderer.reset(new skgpu::ganesh::SoftwarePathRenderer(
1033
327
                fContext->priv().proxyProvider(),
1034
327
                fOptionsForPathRendererChain.fAllowPathMaskCaching));
1035
327
    }
1036
7.24k
    return fSoftwarePathRenderer.get();
1037
7.24k
}
1038
1039
9.78k
skgpu::ganesh::AtlasPathRenderer* GrDrawingManager::getAtlasPathRenderer() {
1040
9.78k
    if (!fPathRendererChain) {
1041
387
        fPathRendererChain = std::make_unique<PathRendererChain>(fContext,
1042
387
                                                                 fOptionsForPathRendererChain);
1043
387
    }
1044
9.78k
    return fPathRendererChain->getAtlasPathRenderer();
1045
9.78k
}
1046
1047
14.6k
skgpu::ganesh::PathRenderer* GrDrawingManager::getTessellationPathRenderer() {
1048
14.6k
    if (!fPathRendererChain) {
1049
382
        fPathRendererChain = std::make_unique<PathRendererChain>(fContext,
1050
382
                                                                 fOptionsForPathRendererChain);
1051
382
    }
1052
14.6k
    return fPathRendererChain->getTessellationPathRenderer();
1053
14.6k
}
1054
1055
220k
void GrDrawingManager::flushIfNecessary() {
1056
220k
    auto direct = fContext->asDirectContext();
1057
220k
    if (!direct) {
1058
0
        return;
1059
0
    }
1060
1061
220k
    auto resourceCache = direct->priv().getResourceCache();
1062
220k
    if (resourceCache && resourceCache->requestsFlush()) {
1063
0
        if (this->flush({}, SkSurfaces::BackendSurfaceAccess::kNoAccess, GrFlushInfo(), nullptr)) {
1064
0
            this->submitToGpu(GrSyncCpu::kNo);
1065
0
        }
1066
0
        resourceCache->purgeAsNeeded();
1067
0
    }
1068
220k
}