Debian Codegraph @

tools/gpu/FlushFinishTracker.cpp

raw
1 /*
2 * Copyright 2020 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/gpu/FlushFinishTracker.h"
9
10 #include "src/core/SkTraceEvent.h"
11
12 #if defined(SK_GANESH)
13 #include "include/gpu/ganesh/GrDirectContext.h"
14 #endif
15
16 #if defined(SK_GRAPHITE)
17 #include "include/gpu/graphite/Context.h"
18 #endif
19
20 #include <chrono>
21
22 namespace sk_gpu_test {
23
24 void FlushFinishTracker::waitTillFinished(std::function<void()> tick) {
25 TRACE_EVENT0("skia.gpu", TRACE_FUNC);
26 auto begin = std::chrono::steady_clock::now();
27 auto end = begin;
28 while (!fIsFinished && (end - begin) < std::chrono::seconds(2)) {
29 if (tick) {
30 tick();
31 }
32 bool foundContext = false;
33 #if defined(SK_GANESH)
34 if (fContext) {
35 fContext->checkAsyncWorkCompletion();
36 foundContext = true;
37 }
38 #endif
39 #if defined(SK_GRAPHITE)
40 if (fGraphiteContext) {
41 SkASSERT(fGraphiteContext);
42 fGraphiteContext->checkAsyncWorkCompletion();
43 foundContext = true;
44 }
45 #endif
46 if (!foundContext) {
47 SkDEBUGFAIL("No valid Context");
48 }
49 end = std::chrono::steady_clock::now();
50 }
51 if (!fIsFinished) {
52 SkDebugf("WARNING: Wait failed for flush sync. Timings might not be accurate.\n");
53 }
54 }
55
56 } //namespace sk_gpu_test