@@ -19,18 +19,9 @@ static std::mutex g_test_lock;
1919
2020static std::weak_ptr<MockGLES> g_mock_gles;
2121
22- static ProcTableGLES::Resolver g_resolver ;
22+ static std::vector< const char *> g_extensions ;
2323
24- static std::vector<const unsigned char *> g_extensions;
25-
26- static const unsigned char * g_version;
27-
28- // Has friend visibility into MockGLES to record calls.
29- void RecordGLCall (const char * name) {
30- if (auto mock_gles = g_mock_gles.lock ()) {
31- mock_gles->RecordCall (name);
32- }
33- }
24+ static const char * g_version;
3425
3526template <typename T, typename U>
3627struct CheckSameSignature : std::false_type {};
@@ -41,22 +32,34 @@ struct CheckSameSignature<Ret(Args...), Ret(Args...)> : std::true_type {};
4132// This is a stub function that does nothing/records nothing.
4233void doNothing () {}
4334
44- auto const kMockVendor = ( unsigned char *) " MockGLES" ;
45- const auto kMockShadingLanguageVersion = ( unsigned char *) " GLSL ES 1.0" ;
46- auto const kExtensions = std::vector<const unsigned char *>{
47- ( unsigned char *) " GL_KHR_debug" //
35+ auto const kMockVendor = " MockGLES" ;
36+ const auto kMockShadingLanguageVersion = " GLSL ES 1.0" ;
37+ auto const kExtensions = std::vector<const char *>{
38+ " GL_KHR_debug" //
4839};
4940
41+ namespace {
42+ template <typename Func, typename ... Args>
43+ void CallMockMethod (Func func, Args&&... args) {
44+ if (auto mock_gles = g_mock_gles.lock ()) {
45+ if (mock_gles->GetImpl ()) {
46+ (mock_gles->GetImpl ()->*func)(std::forward<Args>(args)...);
47+ }
48+ }
49+ }
50+ } // namespace
51+
5052const unsigned char * mockGetString (GLenum name) {
5153 switch (name) {
5254 case GL_VENDOR:
53- return kMockVendor ;
55+ return reinterpret_cast < const unsigned char *>( kMockVendor ) ;
5456 case GL_VERSION:
55- return g_version;
57+ return reinterpret_cast < const unsigned char *>( g_version) ;
5658 case GL_SHADING_LANGUAGE_VERSION:
57- return kMockShadingLanguageVersion ;
59+ return reinterpret_cast <const unsigned char *>(
60+ kMockShadingLanguageVersion );
5861 default :
59- return ( unsigned char *) " " ;
62+ return reinterpret_cast < const unsigned char *>( " " ) ;
6063 }
6164}
6265
@@ -66,9 +69,9 @@ static_assert(CheckSameSignature<decltype(mockGetString), //
6669const unsigned char * mockGetStringi (GLenum name, GLuint index) {
6770 switch (name) {
6871 case GL_EXTENSIONS:
69- return g_extensions[index];
72+ return reinterpret_cast < const unsigned char *>( g_extensions[index]) ;
7073 default :
71- return ( unsigned char *) " " ;
74+ return reinterpret_cast < const unsigned char *>( " " ) ;
7275 }
7376}
7477
@@ -102,89 +105,73 @@ GLenum mockGetError() {
102105static_assert (CheckSameSignature<decltype (mockGetError), //
103106 decltype (glGetError)>::value);
104107
105- void mockPopDebugGroupKHR () {
106- RecordGLCall (" PopDebugGroupKHR" );
107- }
108+ void mockPopDebugGroupKHR () {}
108109
109110static_assert (CheckSameSignature<decltype (mockPopDebugGroupKHR), //
110111 decltype (glPopDebugGroupKHR)>::value);
111112
112113void mockPushDebugGroupKHR (GLenum source,
113114 GLuint id,
114115 GLsizei length,
115- const GLchar* message) {
116- RecordGLCall (" PushDebugGroupKHR" );
117- }
116+ const GLchar* message) {}
118117
119118static_assert (CheckSameSignature<decltype (mockPushDebugGroupKHR), //
120119 decltype (glPushDebugGroupKHR)>::value);
121120
122121void mockGenQueriesEXT (GLsizei n, GLuint* ids) {
123- RecordGLCall (" glGenQueriesEXT" );
124- for (auto i = 0 ; i < n; i++) {
125- ids[i] = i + 1 ;
126- }
122+ CallMockMethod (&IMockGLESImpl::GenQueriesEXT, n, ids);
127123}
128124
129125static_assert (CheckSameSignature<decltype (mockGenQueriesEXT), //
130126 decltype (glGenQueriesEXT)>::value);
131127
132128void mockBeginQueryEXT (GLenum target, GLuint id) {
133- RecordGLCall ( " glBeginQueryEXT " );
129+ CallMockMethod (&IMockGLESImpl::BeginQueryEXT, target, id );
134130}
135131
136132static_assert (CheckSameSignature<decltype (mockBeginQueryEXT), //
137133 decltype (glBeginQueryEXT)>::value);
138134
139135void mockEndQueryEXT (GLuint id) {
140- RecordGLCall ( " glEndQueryEXT " );
136+ CallMockMethod (&IMockGLESImpl::EndQueryEXT, id );
141137}
142138
143139static_assert (CheckSameSignature<decltype (mockEndQueryEXT), //
144140 decltype (glEndQueryEXT)>::value);
145141
146142void mockGetQueryObjectuivEXT (GLuint id, GLenum target, GLuint* result) {
147- RecordGLCall (" glGetQueryObjectuivEXT" );
148- *result = GL_TRUE;
143+ CallMockMethod (&IMockGLESImpl::GetQueryObjectuivEXT, id, target, result);
149144}
150145
151146static_assert (CheckSameSignature<decltype (mockGetQueryObjectuivEXT), //
152147 decltype (glGetQueryObjectuivEXT)>::value);
153148
154149void mockGetQueryObjectui64vEXT (GLuint id, GLenum target, GLuint64* result) {
155- RecordGLCall (" glGetQueryObjectui64vEXT" );
156- *result = 1000u ;
150+ CallMockMethod (&IMockGLESImpl::GetQueryObjectui64vEXT, id, target, result);
157151}
158152
159153static_assert (CheckSameSignature<decltype (mockGetQueryObjectui64vEXT), //
160154 decltype (glGetQueryObjectui64vEXT)>::value);
161155
162156void mockDeleteQueriesEXT (GLsizei size, const GLuint* queries) {
163- RecordGLCall ( " glDeleteQueriesEXT " );
157+ CallMockMethod (&IMockGLESImpl::DeleteQueriesEXT, size, queries );
164158}
165159
166160void mockDeleteTextures (GLsizei size, const GLuint* queries) {
167- RecordGLCall ( " glDeleteTextures " );
161+ CallMockMethod (&IMockGLESImpl::DeleteTextures, size, queries );
168162}
169163
170164static_assert (CheckSameSignature<decltype (mockDeleteQueriesEXT), //
171165 decltype (glDeleteQueriesEXT)>::value);
172166
173167void mockUniform1fv (GLint location, GLsizei count, const GLfloat* value) {
174- RecordGLCall ( " glUniform1fv " );
168+ CallMockMethod (&IMockGLESImpl::Uniform1fv, location, count, value );
175169}
176170static_assert (CheckSameSignature<decltype (mockUniform1fv), //
177171 decltype (glUniform1fv)>::value);
178172
179173void mockGenTextures (GLsizei n, GLuint* textures) {
180- RecordGLCall (" glGenTextures" );
181- if (auto mock_gles = g_mock_gles.lock ()) {
182- std::optional<uint64_t > next_texture;
183- std::swap (mock_gles->next_texture_ , next_texture);
184- if (next_texture.has_value ()) {
185- textures[0 ] = next_texture.value ();
186- }
187- }
174+ CallMockMethod (&IMockGLESImpl::GenTextures, n, textures);
188175}
189176
190177static_assert (CheckSameSignature<decltype (mockGenTextures), //
@@ -194,20 +181,35 @@ void mockObjectLabelKHR(GLenum identifier,
194181 GLuint name,
195182 GLsizei length,
196183 const GLchar* label) {
197- RecordGLCall (" glObjectLabelKHR" );
184+ CallMockMethod (&IMockGLESImpl::ObjectLabelKHR, identifier, name, length,
185+ label);
198186}
199187static_assert (CheckSameSignature<decltype (mockObjectLabelKHR), //
200188 decltype (glObjectLabelKHR)>::value);
201189
190+ // static
191+ std::shared_ptr<MockGLES> MockGLES::Init (
192+ std::unique_ptr<MockGLESImpl> impl,
193+ const std::optional<std::vector<const char *>>& extensions) {
194+ FML_CHECK (g_test_lock.try_lock ())
195+ << " MockGLES is already being used by another test." ;
196+ g_extensions = extensions.value_or (kExtensions );
197+ g_version = " OpenGL ES 3.0" ;
198+ auto mock_gles = std::shared_ptr<MockGLES>(new MockGLES ());
199+ mock_gles->impl_ = std::move (impl);
200+ g_mock_gles = mock_gles;
201+ return mock_gles;
202+ }
203+
202204std::shared_ptr<MockGLES> MockGLES::Init (
203- const std::optional<std::vector<const unsigned char *>>& extensions,
205+ const std::optional<std::vector<const char *>>& extensions,
204206 const char * version_string,
205207 ProcTableGLES::Resolver resolver) {
206208 // If we cannot obtain a lock, MockGLES is already being used elsewhere.
207209 FML_CHECK (g_test_lock.try_lock ())
208210 << " MockGLES is already being used by another test." ;
209- g_version = (unsigned char *)version_string;
210211 g_extensions = extensions.value_or (kExtensions );
212+ g_version = version_string;
211213 auto mock_gles = std::shared_ptr<MockGLES>(new MockGLES (std::move (resolver)));
212214 g_mock_gles = mock_gles;
213215 return mock_gles;
0 commit comments