xref: /aosp_15_r20/external/skia/tools/gpu/FlushFinishTracker.cpp (revision c8dee2aa9b3f27cf6c858bd81872bdeb2c07ed17)
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 "include/gpu/ganesh/GrDirectContext.h"
11 #include "src/core/SkTraceEvent.h"
12 
13 #if defined(SK_GRAPHITE)
14 #include "include/gpu/graphite/Context.h"
15 #endif
16 
17 #include <chrono>
18 
19 namespace sk_gpu_test {
20 
waitTillFinished(std::function<void ()> tick)21 void FlushFinishTracker::waitTillFinished(std::function<void()> tick) {
22     TRACE_EVENT0("skia.gpu", TRACE_FUNC);
23     auto begin = std::chrono::steady_clock::now();
24     auto end = begin;
25     while (!fIsFinished && (end - begin) < std::chrono::seconds(2)) {
26         if (tick) {
27             tick();
28         }
29         if (fContext) {
30             fContext->checkAsyncWorkCompletion();
31         } else {
32 #if defined(SK_GRAPHITE)
33             SkASSERT(fGraphiteContext);
34             fGraphiteContext->checkAsyncWorkCompletion();
35 #else
36             SkDEBUGFAIL("No valid context");
37 #endif
38         }
39         end = std::chrono::steady_clock::now();
40     }
41     if (!fIsFinished) {
42         SkDebugf("WARNING: Wait failed for flush sync. Timings might not be accurate.\n");
43     }
44 }
45 
46 } //namespace sk_gpu_test
47