Robert Phillips | 091694f | 2021-09-30 11:41:16 -0400 | [diff] [blame] | 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 sk_graphite_test_ContextFactory_DEFINED |
| 9 | #define sk_graphite_test_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 sk_graphite_test { |
| 21 | |
| 22 | class ContextFactory { |
| 23 | public: |
| 24 | enum class ContextType { |
| 25 | kMetal, |
| 26 | kMock, |
| 27 | }; |
| 28 | |
| 29 | class ContextInfo { |
| 30 | public: |
| 31 | ContextInfo() = default; |
| 32 | ContextInfo(ContextInfo&& other) |
| 33 | : fType(other.fType) |
| 34 | , fTestContext(std::move(other.fTestContext)) |
| 35 | , fContext(std::move(other.fContext)) { |
| 36 | } |
| 37 | |
| 38 | ~ContextInfo() = default; |
| 39 | |
| 40 | ContextFactory::ContextType type() const { return fType; } |
| 41 | |
| 42 | skgpu::Context* context() const { return fContext.get(); } |
| 43 | sk_sp<skgpu::Context> refContext() const { return fContext; } |
| 44 | GraphiteTestContext* testContext() const { return fTestContext.get(); } |
| 45 | |
| 46 | private: |
| 47 | friend class ContextFactory; // for ctor |
| 48 | |
| 49 | ContextInfo(ContextFactory::ContextType type, |
| 50 | std::unique_ptr<GraphiteTestContext> testContext, |
| 51 | sk_sp<skgpu::Context> context) |
| 52 | : fType(type) |
| 53 | , fTestContext(std::move(testContext)) |
| 54 | , fContext(std::move(context)) { |
| 55 | } |
| 56 | |
| 57 | ContextType fType = ContextType::kMock; |
| 58 | std::unique_ptr<GraphiteTestContext> fTestContext; |
| 59 | sk_sp<skgpu::Context> fContext; |
| 60 | }; |
| 61 | |
| 62 | ContextFactory() = default; |
| 63 | ContextFactory(const ContextFactory&) = delete; |
| 64 | ContextFactory& operator=(const ContextFactory&) = delete; |
| 65 | |
| 66 | ~ContextFactory() = default; |
| 67 | |
| 68 | std::tuple<GraphiteTestContext*, sk_sp<skgpu::Context>> getContextInfo(ContextType); |
| 69 | |
| 70 | private: |
| 71 | std::vector<ContextInfo> fContexts; |
| 72 | }; |
| 73 | |
| 74 | } // namespace sk_graphite_test |
| 75 | |
| 76 | #endif // sk_graphite_test_ContextFactory_DEFINED |