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_ContextFactory_DEFINED 9 #define skiatest_graphite_ContextFactory_DEFINED 10 11 #include <vector> 12 #include "experimental/graphite/include/GraphiteTypes.h" 13 #include "include/core/SkRefCnt.h" 14 #include "tools/graphite/GraphiteTestContext.h" 15 16 namespace skgpu { 17 class Context; 18 }; 19 20 namespace skiatest::graphite { 21 22 class ContextFactory { 23 public: 24 enum class ContextType { 25 kDirect3D, 26 kMetal, 27 kVulkan, 28 kMock, 29 }; 30 31 class ContextInfo { 32 public: 33 ContextInfo() = default; 34 ContextInfo(ContextInfo&& other); 35 ~ContextInfo() = default; 36 type()37 ContextFactory::ContextType type() const { return fType; } 38 context()39 skgpu::Context* context() const { return fContext.get(); } testContext()40 GraphiteTestContext* testContext() const { return fTestContext.get(); } 41 42 private: 43 friend class ContextFactory; // for ctor 44 45 ContextInfo(ContextFactory::ContextType type, 46 std::unique_ptr<GraphiteTestContext> testContext, 47 std::unique_ptr<skgpu::Context> context); 48 49 ContextType fType = ContextType::kMock; 50 std::unique_ptr<GraphiteTestContext> fTestContext; 51 std::unique_ptr<skgpu::Context> fContext; 52 }; 53 54 ContextFactory() = default; 55 ContextFactory(const ContextFactory&) = delete; 56 ContextFactory& operator=(const ContextFactory&) = delete; 57 58 ~ContextFactory() = default; 59 60 std::tuple<GraphiteTestContext*, skgpu::Context*> getContextInfo(ContextType); 61 62 private: 63 std::vector<ContextInfo> fContexts; 64 }; 65 66 } // namespace skiatest::graphite 67 68 #endif // skiatest_graphite_ContextFactory_DEFINED 69