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