Debian Codegraph @

tools/graphite/GraphiteTestContext.cpp

raw
1 /*
2 * Copyright 2021 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 "tools/graphite/GraphiteTestContext.h"
9
10 #include "include/gpu/graphite/Context.h"
11 #include "include/gpu/graphite/GraphiteTypes.h"
12 #include "include/gpu/graphite/Recording.h"
13 #include "src/core/SkTraceEvent.h"
14 #include "src/gpu/graphite/Caps.h"
15 #include "src/gpu/graphite/ContextPriv.h"
16 #include "tools/gpu/FlushFinishTracker.h"
17
18 namespace skiatest::graphite {
19
20 GraphiteTestContext::GraphiteTestContext() {}
21
22 GraphiteTestContext::~GraphiteTestContext() {}
23
24 void GraphiteTestContext::submitRecordingAndWaitOnSync(skgpu::graphite::Context* context,
25 skgpu::graphite::Recording* recording) {
26 TRACE_EVENT0("skia.gpu", TRACE_FUNC);
27 SkASSERT(context);
28 SkASSERT(recording);
29
30 if (fFinishTrackers[fCurrentFlushIdx]) {
31 fFinishTrackers[fCurrentFlushIdx]->waitTillFinished([this] { tick(); });
32 }
33
34 fFinishTrackers[fCurrentFlushIdx].reset(new sk_gpu_test::FlushFinishTracker(context));
35
36 // We add an additional ref to the current flush tracker here. This ref is owned by the finish
37 // callback on the flush call. The finish callback will unref the tracker when called.
38 fFinishTrackers[fCurrentFlushIdx]->ref();
39
40 skgpu::graphite::InsertRecordingInfo info;
41 info.fRecording = recording;
42 info.fFinishedContext = fFinishTrackers[fCurrentFlushIdx].get();
43 info.fFinishedProc = sk_gpu_test::FlushFinishTracker::FlushFinishedResult;
44 context->insertRecording(info);
45
46 context->submit(skgpu::graphite::SyncToCpu::kNo);
47
48 fCurrentFlushIdx = (fCurrentFlushIdx + 1) % std::size(fFinishTrackers);
49 }
50
51 void GraphiteTestContext::syncedSubmit(skgpu::graphite::Context* context) {
52 skgpu::graphite::SyncToCpu sync = context->priv().caps()->allowCpuSync()
53 ? skgpu::graphite::SyncToCpu::kYes
54 : skgpu::graphite::SyncToCpu::kNo;
55 context->submit(sync);
56 if (sync == skgpu::graphite::SyncToCpu::kNo) {
57 while (context->hasUnfinishedGpuWork()) {
58 this->tick();
59 context->checkAsyncWorkCompletion();
60 }
61 }
62 }
63
64 } // namespace skiatest::graphite