1cb93a386Sopenharmony_ci/* 2cb93a386Sopenharmony_ci * Copyright 2021 Google LLC 3cb93a386Sopenharmony_ci * 4cb93a386Sopenharmony_ci * Use of this source code is governed by a BSD-style license that can be 5cb93a386Sopenharmony_ci * found in the LICENSE file. 6cb93a386Sopenharmony_ci */ 7cb93a386Sopenharmony_ci 8cb93a386Sopenharmony_ci#ifndef skiatest_graphite_ContextFactory_DEFINED 9cb93a386Sopenharmony_ci#define skiatest_graphite_ContextFactory_DEFINED 10cb93a386Sopenharmony_ci 11cb93a386Sopenharmony_ci#include <vector> 12cb93a386Sopenharmony_ci#include "experimental/graphite/include/GraphiteTypes.h" 13cb93a386Sopenharmony_ci#include "include/core/SkRefCnt.h" 14cb93a386Sopenharmony_ci#include "tools/graphite/GraphiteTestContext.h" 15cb93a386Sopenharmony_ci 16cb93a386Sopenharmony_cinamespace skgpu { 17cb93a386Sopenharmony_ci class Context; 18cb93a386Sopenharmony_ci}; 19cb93a386Sopenharmony_ci 20cb93a386Sopenharmony_cinamespace skiatest::graphite { 21cb93a386Sopenharmony_ci 22cb93a386Sopenharmony_ciclass ContextFactory { 23cb93a386Sopenharmony_cipublic: 24cb93a386Sopenharmony_ci enum class ContextType { 25cb93a386Sopenharmony_ci kDirect3D, 26cb93a386Sopenharmony_ci kMetal, 27cb93a386Sopenharmony_ci kVulkan, 28cb93a386Sopenharmony_ci kMock, 29cb93a386Sopenharmony_ci }; 30cb93a386Sopenharmony_ci 31cb93a386Sopenharmony_ci class ContextInfo { 32cb93a386Sopenharmony_ci public: 33cb93a386Sopenharmony_ci ContextInfo() = default; 34cb93a386Sopenharmony_ci ContextInfo(ContextInfo&& other); 35cb93a386Sopenharmony_ci ~ContextInfo() = default; 36cb93a386Sopenharmony_ci 37cb93a386Sopenharmony_ci ContextFactory::ContextType type() const { return fType; } 38cb93a386Sopenharmony_ci 39cb93a386Sopenharmony_ci skgpu::Context* context() const { return fContext.get(); } 40cb93a386Sopenharmony_ci sk_sp<skgpu::Context> refContext() const; 41cb93a386Sopenharmony_ci GraphiteTestContext* testContext() const { return fTestContext.get(); } 42cb93a386Sopenharmony_ci 43cb93a386Sopenharmony_ci private: 44cb93a386Sopenharmony_ci friend class ContextFactory; // for ctor 45cb93a386Sopenharmony_ci 46cb93a386Sopenharmony_ci ContextInfo(ContextFactory::ContextType type, 47cb93a386Sopenharmony_ci std::unique_ptr<GraphiteTestContext> testContext, 48cb93a386Sopenharmony_ci sk_sp<skgpu::Context> context); 49cb93a386Sopenharmony_ci 50cb93a386Sopenharmony_ci ContextType fType = ContextType::kMock; 51cb93a386Sopenharmony_ci std::unique_ptr<GraphiteTestContext> fTestContext; 52cb93a386Sopenharmony_ci sk_sp<skgpu::Context> fContext; 53cb93a386Sopenharmony_ci }; 54cb93a386Sopenharmony_ci 55cb93a386Sopenharmony_ci ContextFactory() = default; 56cb93a386Sopenharmony_ci ContextFactory(const ContextFactory&) = delete; 57cb93a386Sopenharmony_ci ContextFactory& operator=(const ContextFactory&) = delete; 58cb93a386Sopenharmony_ci 59cb93a386Sopenharmony_ci ~ContextFactory() = default; 60cb93a386Sopenharmony_ci 61cb93a386Sopenharmony_ci std::tuple<GraphiteTestContext*, sk_sp<skgpu::Context>> getContextInfo(ContextType); 62cb93a386Sopenharmony_ci 63cb93a386Sopenharmony_ciprivate: 64cb93a386Sopenharmony_ci std::vector<ContextInfo> fContexts; 65cb93a386Sopenharmony_ci}; 66cb93a386Sopenharmony_ci 67cb93a386Sopenharmony_ci} // namespace skiatest::graphite 68cb93a386Sopenharmony_ci 69cb93a386Sopenharmony_ci#endif // skiatest_graphite_ContextFactory_DEFINED 70