@@ -19,9 +19,18 @@ static std::mutex g_test_lock;
1919
2020static std::weak_ptr<MockGLES> g_mock_gles;
2121
22- static std::vector< const char *> g_extensions ;
22+ static ProcTableGLES::Resolver g_resolver ;
2323
24- static const char * g_version;
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+ }
2534
2635template <typename T, typename U>
2736struct CheckSameSignature : std::false_type {};
@@ -32,34 +41,22 @@ struct CheckSameSignature<Ret(Args...), Ret(Args...)> : std::true_type {};
3241// This is a stub function that does nothing/records nothing.
3342void doNothing () {}
3443
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" //
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" //
3948};
4049
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-
5250const unsigned char * mockGetString (GLenum name) {
5351 switch (name) {
5452 case GL_VENDOR:
55- return reinterpret_cast < const unsigned char *>( kMockVendor ) ;
53+ return kMockVendor ;
5654 case GL_VERSION:
57- return reinterpret_cast < const unsigned char *>( g_version) ;
55+ return g_version;
5856 case GL_SHADING_LANGUAGE_VERSION:
59- return reinterpret_cast <const unsigned char *>(
60- kMockShadingLanguageVersion );
57+ return kMockShadingLanguageVersion ;
6158 default :
62- return reinterpret_cast < const unsigned char *>( " " ) ;
59+ return ( unsigned char *) " " ;
6360 }
6461}
6562
@@ -69,9 +66,9 @@ static_assert(CheckSameSignature<decltype(mockGetString), //
6966const unsigned char * mockGetStringi (GLenum name, GLuint index) {
7067 switch (name) {
7168 case GL_EXTENSIONS:
72- return reinterpret_cast < const unsigned char *>( g_extensions[index]) ;
69+ return g_extensions[index];
7370 default :
74- return reinterpret_cast < const unsigned char *>( " " ) ;
71+ return ( unsigned char *) " " ;
7572 }
7673}
7774
@@ -105,73 +102,89 @@ GLenum mockGetError() {
105102static_assert (CheckSameSignature<decltype (mockGetError), //
106103 decltype (glGetError)>::value);
107104
108- void mockPopDebugGroupKHR () {}
105+ void mockPopDebugGroupKHR () {
106+ RecordGLCall (" PopDebugGroupKHR" );
107+ }
109108
110109static_assert (CheckSameSignature<decltype (mockPopDebugGroupKHR), //
111110 decltype (glPopDebugGroupKHR)>::value);
112111
113112void mockPushDebugGroupKHR (GLenum source,
114113 GLuint id,
115114 GLsizei length,
116- const GLchar* message) {}
115+ const GLchar* message) {
116+ RecordGLCall (" PushDebugGroupKHR" );
117+ }
117118
118119static_assert (CheckSameSignature<decltype (mockPushDebugGroupKHR), //
119120 decltype (glPushDebugGroupKHR)>::value);
120121
121122void mockGenQueriesEXT (GLsizei n, GLuint* ids) {
122- CallMockMethod (&IMockGLESImpl::GenQueriesEXT, n, ids);
123+ RecordGLCall (" glGenQueriesEXT" );
124+ for (auto i = 0 ; i < n; i++) {
125+ ids[i] = i + 1 ;
126+ }
123127}
124128
125129static_assert (CheckSameSignature<decltype (mockGenQueriesEXT), //
126130 decltype (glGenQueriesEXT)>::value);
127131
128132void mockBeginQueryEXT (GLenum target, GLuint id) {
129- CallMockMethod (&IMockGLESImpl::BeginQueryEXT, target, id );
133+ RecordGLCall ( " glBeginQueryEXT " );
130134}
131135
132136static_assert (CheckSameSignature<decltype (mockBeginQueryEXT), //
133137 decltype (glBeginQueryEXT)>::value);
134138
135139void mockEndQueryEXT (GLuint id) {
136- CallMockMethod (&IMockGLESImpl::EndQueryEXT, id );
140+ RecordGLCall ( " glEndQueryEXT " );
137141}
138142
139143static_assert (CheckSameSignature<decltype (mockEndQueryEXT), //
140144 decltype (glEndQueryEXT)>::value);
141145
142146void mockGetQueryObjectuivEXT (GLuint id, GLenum target, GLuint* result) {
143- CallMockMethod (&IMockGLESImpl::GetQueryObjectuivEXT, id, target, result);
147+ RecordGLCall (" glGetQueryObjectuivEXT" );
148+ *result = GL_TRUE;
144149}
145150
146151static_assert (CheckSameSignature<decltype (mockGetQueryObjectuivEXT), //
147152 decltype (glGetQueryObjectuivEXT)>::value);
148153
149154void mockGetQueryObjectui64vEXT (GLuint id, GLenum target, GLuint64* result) {
150- CallMockMethod (&IMockGLESImpl::GetQueryObjectui64vEXT, id, target, result);
155+ RecordGLCall (" glGetQueryObjectui64vEXT" );
156+ *result = 1000u ;
151157}
152158
153159static_assert (CheckSameSignature<decltype (mockGetQueryObjectui64vEXT), //
154160 decltype (glGetQueryObjectui64vEXT)>::value);
155161
156162void mockDeleteQueriesEXT (GLsizei size, const GLuint* queries) {
157- CallMockMethod (&IMockGLESImpl::DeleteQueriesEXT, size, queries );
163+ RecordGLCall ( " glDeleteQueriesEXT " );
158164}
159165
160166void mockDeleteTextures (GLsizei size, const GLuint* queries) {
161- CallMockMethod (&IMockGLESImpl::DeleteTextures, size, queries );
167+ RecordGLCall ( " glDeleteTextures " );
162168}
163169
164170static_assert (CheckSameSignature<decltype (mockDeleteQueriesEXT), //
165171 decltype (glDeleteQueriesEXT)>::value);
166172
167173void mockUniform1fv (GLint location, GLsizei count, const GLfloat* value) {
168- CallMockMethod (&IMockGLESImpl::Uniform1fv, location, count, value );
174+ RecordGLCall ( " glUniform1fv " );
169175}
170176static_assert (CheckSameSignature<decltype (mockUniform1fv), //
171177 decltype (glUniform1fv)>::value);
172178
173179void mockGenTextures (GLsizei n, GLuint* textures) {
174- CallMockMethod (&IMockGLESImpl::GenTextures, n, 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+ }
175188}
176189
177190static_assert (CheckSameSignature<decltype (mockGenTextures), //
@@ -181,35 +194,20 @@ void mockObjectLabelKHR(GLenum identifier,
181194 GLuint name,
182195 GLsizei length,
183196 const GLchar* label) {
184- CallMockMethod (&IMockGLESImpl::ObjectLabelKHR, identifier, name, length,
185- label);
197+ RecordGLCall (" glObjectLabelKHR" );
186198}
187199static_assert (CheckSameSignature<decltype (mockObjectLabelKHR), //
188200 decltype (glObjectLabelKHR)>::value);
189201
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-
204202std::shared_ptr<MockGLES> MockGLES::Init (
205- const std::optional<std::vector<const char *>>& extensions,
203+ const std::optional<std::vector<const unsigned char *>>& extensions,
206204 const char * version_string,
207205 ProcTableGLES::Resolver resolver) {
208206 // If we cannot obtain a lock, MockGLES is already being used elsewhere.
209207 FML_CHECK (g_test_lock.try_lock ())
210208 << " MockGLES is already being used by another test." ;
209+ g_version = (unsigned char *)version_string;
211210 g_extensions = extensions.value_or (kExtensions );
212- g_version = version_string;
213211 auto mock_gles = std::shared_ptr<MockGLES>(new MockGLES (std::move (resolver)));
214212 g_mock_gles = mock_gles;
215213 return mock_gles;
0 commit comments