blob: 9ba841986f1679ce1a4798a1aaadfbe7e49b2d77 [file] [log] [blame]
Robert Phillipsd034db72021-09-29 14:29:32 -04001/*
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
Robert Phillips30627592021-10-11 11:28:21 -04008#ifndef skiatest_graphite_GraphiteTestContext_DEFINED
9#define skiatest_graphite_GraphiteTestContext_DEFINED
Robert Phillipsd034db72021-09-29 14:29:32 -040010
Robert Phillipsd034db72021-09-29 14:29:32 -040011#include "include/core/SkRefCnt.h"
Jim Van Verth42f710f2022-04-11 11:48:46 -040012#include "include/gpu/graphite/GraphiteTypes.h"
Robert Phillipsd034db72021-09-29 14:29:32 -040013
John Stiles946718b2023-09-18 12:52:29 -040014namespace skgpu {
15enum class BackendApi : unsigned;
16enum class ContextType;
17}
Jim Van Verth38714792022-04-07 16:08:04 -040018namespace skgpu::graphite {
Greg Daniel5d67b172022-03-28 15:27:44 -040019class Context;
Robert Phillipsc983b972023-06-20 12:59:31 -040020struct ContextOptions;
Greg Daniel5d67b172022-03-28 15:27:44 -040021class Recording;
22}
23
24namespace sk_gpu_test { class FlushFinishTracker; }
Robert Phillipsd034db72021-09-29 14:29:32 -040025
Robert Phillips30627592021-10-11 11:28:21 -040026namespace skiatest::graphite {
Robert Phillipsd034db72021-09-29 14:29:32 -040027
Brian Salomon23e1cb22023-12-05 19:46:43 -050028struct TestOptions;
29
Robert Phillipsd034db72021-09-29 14:29:32 -040030/**
31 * An offscreen 3D context. This class is intended for Skia's internal testing needs and not
32 * for general use.
33 */
34class GraphiteTestContext {
35public:
36 GraphiteTestContext(const GraphiteTestContext&) = delete;
37 GraphiteTestContext& operator=(const GraphiteTestContext&) = delete;
38
39 virtual ~GraphiteTestContext();
40
Greg Daniela8ca8112022-10-10 18:25:22 -040041 virtual skgpu::BackendApi backend() = 0;
Robert Phillipsd034db72021-09-29 14:29:32 -040042
John Stiles946718b2023-09-18 12:52:29 -040043 virtual skgpu::ContextType contextType() = 0;
44
Brian Salomon23e1cb22023-12-05 19:46:43 -050045 virtual std::unique_ptr<skgpu::graphite::Context> makeContext(const TestOptions&) = 0;
Robert Phillipsd034db72021-09-29 14:29:32 -040046
Greg Daniel5d67b172022-03-28 15:27:44 -040047 bool getMaxGpuFrameLag(int *maxFrameLag) const {
48 *maxFrameLag = kMaxFrameLag;
49 return true;
50 }
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 */
Jim Van Verth38714792022-04-07 16:08:04 -040058 void submitRecordingAndWaitOnSync(skgpu::graphite::Context*, skgpu::graphite::Recording*);
Greg Daniel5d67b172022-03-28 15:27:44 -040059
Brian Salomonf8daeeb2023-11-17 16:06:37 -050060 /**
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 virtual void tick() {}
65
Brian Salomonc759bbf2023-12-05 11:11:27 -050066 /**
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
Robert Phillipsd034db72021-09-29 14:29:32 -040072protected:
Greg Daniel5d67b172022-03-28 15:27:44 -040073 static constexpr int kMaxFrameLag = 3;
74
75 sk_sp<sk_gpu_test::FlushFinishTracker> fFinishTrackers[kMaxFrameLag - 1];
76 int fCurrentFlushIdx = 0;
77
Robert Phillipsd034db72021-09-29 14:29:32 -040078 GraphiteTestContext();
79};
80
81
Robert Phillips30627592021-10-11 11:28:21 -040082} // namespace skiatest::graphite
Robert Phillipsd034db72021-09-29 14:29:32 -040083
Robert Phillips30627592021-10-11 11:28:21 -040084#endif // skiatest_graphite_GraphiteTestContext_DEFINED