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::graphite { 15 class Context; 16 class Recording; 17 } 18 19 namespace sk_gpu_test { class FlushFinishTracker; } 20 21 namespace skiatest::graphite { 22 23 /** 24 * An offscreen 3D context. This class is intended for Skia's internal testing needs and not 25 * for general use. 26 */ 27 class GraphiteTestContext { 28 public: 29 GraphiteTestContext(const GraphiteTestContext&) = delete; 30 GraphiteTestContext& operator=(const GraphiteTestContext&) = delete; 31 32 virtual ~GraphiteTestContext(); 33 34 virtual skgpu::BackendApi backend() = 0; 35 36 virtual std::unique_ptr<skgpu::graphite::Context> makeContext() = 0; 37 getMaxGpuFrameLag(int * maxFrameLag)38 bool getMaxGpuFrameLag(int *maxFrameLag) const { 39 *maxFrameLag = kMaxFrameLag; 40 return true; 41 } 42 43 /** 44 * This will insert a Recording and submit work to the GPU. Additionally, we will add a finished 45 * callback to our insert recording call. We allow ourselves to have kMaxFrameLag number of 46 * unfinished flushes active on the GPU at a time. If we have 2 outstanding flushes then we will 47 * wait on the CPU until one has finished. 48 */ 49 void submitRecordingAndWaitOnSync(skgpu::graphite::Context*, skgpu::graphite::Recording*); 50 51 protected: 52 static constexpr int kMaxFrameLag = 3; 53 54 sk_sp<sk_gpu_test::FlushFinishTracker> fFinishTrackers[kMaxFrameLag - 1]; 55 int fCurrentFlushIdx = 0; 56 57 GraphiteTestContext(); 58 }; 59 60 61 } // namespace skiatest::graphite 62 63 #endif // skiatest_graphite_GraphiteTestContext_DEFINED 64