Coverage Report

Created: 2024-05-20 07:14

/src/skia/tools/gpu/FlushFinishTracker.h
Line
Count
Source (jump to first uncovered line)
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
#ifndef FlushFinishTracker_DEFINED
9
#define FlushFinishTracker_DEFINED
10
11
#include "include/core/SkRefCnt.h"
12
#include "include/gpu/GpuTypes.h"
13
14
#include <functional>
15
16
class GrDirectContext;
17
18
#if defined(SK_GRAPHITE)
19
namespace skgpu::graphite { class Context; }
20
#endif
21
22
namespace sk_gpu_test {
23
24
class FlushFinishTracker : public SkRefCnt {
25
public:
26
0
    static void FlushFinished(void* finishedContext) {
27
0
        auto tracker = static_cast<FlushFinishTracker*>(finishedContext);
28
0
        tracker->setFinished();
29
0
        tracker->unref();
30
0
    }
31
32
0
    static void FlushFinishedResult(void* finishedContext, skgpu::CallbackResult) {
33
0
        FlushFinished(finishedContext);
34
0
    }
35
36
0
    FlushFinishTracker(GrDirectContext* context) : fContext(context) {}
37
#if defined(SK_GRAPHITE)
38
0
    FlushFinishTracker(skgpu::graphite::Context* context) : fGraphiteContext(context) {}
39
#endif
40
41
0
    void setFinished() { fIsFinished = true; }
42
43
    void waitTillFinished(std::function<void()> tick = {});
44
45
private:
46
    GrDirectContext* fContext = nullptr;
47
#if defined(SK_GRAPHITE)
48
    skgpu::graphite::Context*  fGraphiteContext = nullptr;
49
#endif
50
51
    // Currently we don't have the this bool be atomic cause all current uses of this class happen
52
    // on a single thread. In other words we call flush, checkAsyncWorkCompletion, and
53
    // waitTillFinished all on the same thread. If we ever want to support the flushing and waiting
54
    // to happen on different threads then we should make this atomic.
55
    bool fIsFinished = false;
56
};
57
58
} //namespace sk_gpu_test
59
60
#endif