Coverage Report

Created: 2024-05-20 07:14

/src/skia/tools/graphite/GraphiteTestContext.h
Line
Count
Source (jump to first uncovered line)
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
#ifndef skiatest_graphite_GraphiteTestContext_DEFINED
9
#define skiatest_graphite_GraphiteTestContext_DEFINED
10
11
#include "include/core/SkRefCnt.h"
12
#include "include/gpu/graphite/GraphiteTypes.h"
13
14
namespace skgpu {
15
enum class BackendApi : unsigned;
16
enum class ContextType;
17
}
18
namespace skgpu::graphite {
19
class Context;
20
struct ContextOptions;
21
class Recording;
22
}
23
24
namespace sk_gpu_test { class FlushFinishTracker; }
25
26
namespace skiatest::graphite {
27
28
struct TestOptions;
29
30
/**
31
 * An offscreen 3D context. This class is intended for Skia's internal testing needs and not
32
 * for general use.
33
 */
34
class GraphiteTestContext {
35
public:
36
    GraphiteTestContext(const GraphiteTestContext&) = delete;
37
    GraphiteTestContext& operator=(const GraphiteTestContext&) = delete;
38
39
    virtual ~GraphiteTestContext();
40
41
    virtual skgpu::BackendApi backend() = 0;
42
43
    virtual skgpu::ContextType contextType() = 0;
44
45
    virtual std::unique_ptr<skgpu::graphite::Context> makeContext(const TestOptions&) = 0;
46
47
0
    bool getMaxGpuFrameLag(int *maxFrameLag) const {
48
0
        *maxFrameLag = kMaxFrameLag;
49
0
        return true;
50
0
    }
51
52
    /**
53
     * This will insert a Recording and submit work to the GPU. Additionally, we will add a finished
54
     * callback to our insert recording call. We allow ourselves to have kMaxFrameLag number of
55
     * unfinished flushes active on the GPU at a time. If we have 2 outstanding flushes then we will
56
     * wait on the CPU until one has finished.
57
     */
58
    void submitRecordingAndWaitOnSync(skgpu::graphite::Context*, skgpu::graphite::Recording*);
59
60
    /**
61
     * Allow the GPU API to make or detect forward progress on submitted work. For most APIs this is
62
     * a no-op as the API can do this on another thread.
63
     */
64
0
    virtual void tick() {}
65
66
    /**
67
     * If the context supports CPU/GPU sync'ing this calls submit with skgpu::SyncToCpu::kYes.
68
     * Otherwise it calls it with kNo in a busy loop.
69
     */
70
    void syncedSubmit(skgpu::graphite::Context*);
71
72
protected:
73
    static constexpr int kMaxFrameLag = 3;
74
75
    sk_sp<sk_gpu_test::FlushFinishTracker> fFinishTrackers[kMaxFrameLag - 1];
76
    int fCurrentFlushIdx = 0;
77
78
    GraphiteTestContext();
79
};
80
81
82
}  // namespace skiatest::graphite
83
84
#endif // skiatest_graphite_GraphiteTestContext_DEFINED