Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
GrContextFactory.h
Go to the documentation of this file.
1/*
2 * Copyright 2012 Google Inc.
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 GrContextFactory_DEFINED
9#define GrContextFactory_DEFINED
10
13
17
18#ifdef SK_GL
20#endif
21
23
24namespace sk_gpu_test {
25class ContextInfo;
26
27/**
28 * This is a simple class that is useful in test apps that use different
29 * GrContexts backed by different types of GL contexts. It manages creating the
30 * GL context and a GrContext that uses it. The GL/Gr contexts persist until the
31 * factory is destroyed (though the caller can always grab a ref on the returned
32 * Gr and GL contexts to make them outlive the factory).
33 */
35public:
37
38 /**
39 * Overrides for the initial GrContextOptions provided at construction time, and required
40 * features that will cause context creation to fail if not present.
41 */
42 enum class ContextOverrides {
43 kNone = 0x0,
46 kReducedShaders = 0x4,
47 };
48
49 explicit GrContextFactory(const GrContextOptions& opts);
51
53
54 void destroyContexts();
55 void abandonContexts();
57
58 /**
59 * Get a context initialized with a type of GL context. It also makes the GL context current.
60 */
62
63 /**
64 * Get a context in the same share group as the passed in GrContext, with the same type and
65 * overrides. To get multiple contexts in a single share group, pass the same shareContext,
66 * with different values for shareIndex.
67 */
68 ContextInfo getSharedContextInfo(GrDirectContext* shareContext, uint32_t shareIndex = 0);
69
70 /**
71 * Get a GrContext initialized with a type of GL context. It also makes the GL context current.
72 */
74 const GrContextOptions& getGlobalOptions() const { return fGlobalOptions; }
75
76private:
77 ContextInfo getContextInfoInternal(ContextType type, ContextOverrides overrides,
78 GrDirectContext* shareContext, uint32_t shareIndex);
79
80 struct Context {
81 ContextType fType;
82 ContextOverrides fOverrides;
83 GrContextOptions fOptions;
84 GrBackendApi fBackend;
85 TestContext* fTestContext;
86 GrDirectContext* fGrContext;
87 GrDirectContext* fShareContext;
88 uint32_t fShareIndex;
89
90 bool fAbandoned;
91 };
93#ifdef SK_GL
94 std::unique_ptr<GLTestContext> fSentinelGLContext;
95#endif
96
97 const GrContextOptions fGlobalOptions;
98};
99
101public:
102 ContextInfo() = default;
103 ContextInfo(const ContextInfo&) = default;
105
106 skgpu::ContextType type() const { return fType; }
108
109 GrDirectContext* directContext() const { return fContext; }
110 TestContext* testContext() const { return fTestContext; }
111
112#ifdef SK_GL
113 GLTestContext* glContext() const {
115 return static_cast<GLTestContext*>(fTestContext);
116 }
117#endif
118
119 const GrContextOptions& options() const { return fOptions; }
120
121private:
124 GrDirectContext* context,
126 : fType(type), fTestContext(testContext), fContext(context), fOptions(options) {}
127
128 skgpu::ContextType fType = skgpu::ContextType::kGL;
129 // Valid until the factory destroys it via abandonContexts() or destroyContexts().
130 TestContext* fTestContext = nullptr;
131 GrDirectContext* fContext = nullptr;
132 GrContextOptions fOptions;
133
134 friend class GrContextFactory;
135};
136
137} // namespace sk_gpu_test
138
140
141#endif
#define GR_MAKE_BITFIELD_CLASS_OPS(X)
Definition GrTypes.h:42
GrBackendApi
Definition GrTypes.h:95
#define SkASSERT(cond)
Definition SkAssert.h:116
const GrContextOptions & options() const
GrBackendApi backend() const
ContextInfo & operator=(const ContextInfo &)=default
GrDirectContext * directContext() const
ContextInfo(const ContextInfo &)=default
TestContext * testContext() const
skgpu::ContextType type() const
ContextInfo getContextInfo(ContextType type, ContextOverrides=ContextOverrides::kNone)
ContextInfo getSharedContextInfo(GrDirectContext *shareContext, uint32_t shareIndex=0)
GrDirectContext * get(ContextType type, ContextOverrides overrides=ContextOverrides::kNone)
const GrContextOptions & getGlobalOptions() const
GrBackendApi ContextTypeBackend(skgpu::ContextType type)