Flutter Engine
The Flutter Engine
mock_epoxy.cc
Go to the documentation of this file.
1// Copyright 2013 The Flutter Authors. All rights reserved.
2
3// Use of this source code is governed by a BSD-style license that can be
4// found in the LICENSE file.
5
6#include <epoxy/egl.h>
7#include <epoxy/gl.h>
8
9typedef struct {
10 EGLint config_id;
14 EGLint level;
15 EGLint red_size;
16 EGLint green_size;
17 EGLint blue_size;
18 EGLint alpha_size;
19 EGLint depth_size;
21 EGLint samples;
30 EGLint conformant;
38
39typedef struct {
41
42typedef struct {
44
45typedef struct {
47
48static bool display_initialized = false;
53
54static EGLint mock_error = EGL_SUCCESS;
55
56static bool check_display(EGLDisplay dpy) {
57 if (dpy == nullptr) {
58 mock_error = EGL_BAD_DISPLAY;
59 return false;
60 }
61
62 return true;
63}
64
65static bool check_initialized(EGLDisplay dpy) {
67 mock_error = EGL_NOT_INITIALIZED;
68 return false;
69 }
70
71 return true;
72}
73
74static bool check_config(EGLConfig config) {
75 if (config == nullptr) {
76 mock_error = EGL_BAD_CONFIG;
77 return false;
78 }
79
80 return true;
81}
82
83static EGLBoolean bool_success() {
84 mock_error = EGL_SUCCESS;
85 return EGL_TRUE;
86}
87
88static EGLBoolean bool_failure(EGLint error) {
90 return EGL_FALSE;
91}
92
93EGLBoolean _eglBindAPI(EGLenum api) {
94 return bool_success();
95}
96
97EGLBoolean _eglChooseConfig(EGLDisplay dpy,
98 const EGLint* attrib_list,
99 EGLConfig* configs,
100 EGLint config_size,
101 EGLint* num_config) {
102 if (!check_display(dpy) || !check_initialized(dpy)) {
103 return EGL_FALSE;
104 }
105
106 if (configs == nullptr) {
107 if (num_config != nullptr) {
108 *num_config = 1;
109 }
110 return bool_success();
111 }
112
113 EGLint n_returned = 0;
114 if (config_size >= 1) {
115 configs[0] = &mock_config;
116 n_returned++;
117 }
118
119 if (num_config != nullptr) {
120 *num_config = n_returned;
121 }
122
123 return bool_success();
124}
125
126EGLContext _eglCreateContext(EGLDisplay dpy,
127 EGLConfig config,
128 EGLContext share_context,
129 const EGLint* attrib_list) {
130 if (!check_display(dpy) || !check_initialized(dpy) || !check_config(config)) {
131 return EGL_NO_CONTEXT;
132 }
133
134 mock_error = EGL_SUCCESS;
135 return &mock_context;
136}
137
138EGLSurface _eglCreatePbufferSurface(EGLDisplay dpy,
139 EGLConfig config,
140 const EGLint* attrib_list) {
141 if (!check_display(dpy) || !check_initialized(dpy) || !check_config(config)) {
142 return EGL_NO_SURFACE;
143 }
144
145 mock_error = EGL_SUCCESS;
146 return &mock_surface;
147}
148
149EGLSurface _eglCreateWindowSurface(EGLDisplay dpy,
150 EGLConfig config,
151 EGLNativeWindowType win,
152 const EGLint* attrib_list) {
153 if (!check_display(dpy) || !check_initialized(dpy) || !check_config(config)) {
154 return EGL_NO_SURFACE;
155 }
156
157 mock_error = EGL_SUCCESS;
158 return &mock_surface;
159}
160
161EGLBoolean _eglGetConfigAttrib(EGLDisplay dpy,
162 EGLConfig config,
163 EGLint attribute,
164 EGLint* value) {
165 if (!check_display(dpy) || !check_initialized(dpy) || !check_config(config)) {
166 return EGL_FALSE;
167 }
168
169 MockConfig* c = static_cast<MockConfig*>(config);
170 switch (attribute) {
171 case EGL_CONFIG_ID:
172 *value = c->config_id;
173 return bool_success();
174 case EGL_BUFFER_SIZE:
175 *value = c->buffer_size;
176 return bool_success();
177 case EGL_COLOR_BUFFER_TYPE:
179 return bool_success();
180 case EGL_TRANSPARENT_TYPE:
182 return bool_success();
183 case EGL_LEVEL:
184 *value = c->level;
185 return bool_success();
186 case EGL_RED_SIZE:
187 *value = c->red_size;
188 return bool_success();
189 case EGL_GREEN_SIZE:
190 *value = c->green_size;
191 return bool_success();
192 case EGL_BLUE_SIZE:
193 *value = c->blue_size;
194 return bool_success();
195 case EGL_ALPHA_SIZE:
196 *value = c->alpha_size;
197 return bool_success();
198 case EGL_DEPTH_SIZE:
199 *value = c->depth_size;
200 return bool_success();
201 case EGL_STENCIL_SIZE:
202 *value = c->stencil_size;
203 return bool_success();
204 case EGL_SAMPLES:
205 *value = c->samples;
206 return bool_success();
207 case EGL_SAMPLE_BUFFERS:
208 *value = c->sample_buffers;
209 return bool_success();
210 case EGL_NATIVE_VISUAL_ID:
212 return bool_success();
213 case EGL_NATIVE_VISUAL_TYPE:
215 return bool_success();
216 case EGL_NATIVE_RENDERABLE:
218 return bool_success();
219 case EGL_CONFIG_CAVEAT:
220 *value = c->config_caveat;
221 return bool_success();
222 case EGL_BIND_TO_TEXTURE_RGB:
224 return bool_success();
225 case EGL_BIND_TO_TEXTURE_RGBA:
227 return bool_success();
228 case EGL_RENDERABLE_TYPE:
230 return bool_success();
231 case EGL_CONFORMANT:
232 *value = c->conformant;
233 return bool_success();
234 case EGL_SURFACE_TYPE:
235 *value = c->surface_type;
236 return bool_success();
237 case EGL_MAX_PBUFFER_WIDTH:
239 return bool_success();
240 case EGL_MAX_PBUFFER_HEIGHT:
242 return bool_success();
243 case EGL_MAX_PBUFFER_PIXELS:
245 return bool_success();
246 case EGL_MIN_SWAP_INTERVAL:
248 return bool_success();
249 case EGL_MAX_SWAP_INTERVAL:
251 return bool_success();
252 default:
253 return bool_failure(EGL_BAD_ATTRIBUTE);
254 }
255}
256
257EGLDisplay _eglGetDisplay(EGLNativeDisplayType display_id) {
258 return &mock_display;
259}
260
261EGLint _eglGetError() {
262 EGLint error = mock_error;
263 mock_error = EGL_SUCCESS;
264 return error;
265}
266
267void (*_eglGetProcAddress(const char* procname))(void) {
268 mock_error = EGL_SUCCESS;
269 return nullptr;
270}
271
272EGLBoolean _eglInitialize(EGLDisplay dpy, EGLint* major, EGLint* minor) {
273 if (!check_display(dpy)) {
274 return EGL_FALSE;
275 }
276
277 if (!display_initialized) {
280 mock_config.color_buffer_type = EGL_RGB_BUFFER;
281 mock_config.transparent_type = EGL_NONE;
282 mock_config.level = 1;
294 mock_config.config_caveat = EGL_NONE;
297 mock_config.renderable_type = EGL_OPENGL_ES2_BIT;
298 mock_config.conformant = EGL_OPENGL_ES2_BIT;
299 mock_config.surface_type = EGL_WINDOW_BIT | EGL_PBUFFER_BIT;
302 mock_config.max_pbuffer_pixels = 1024 * 1024;
305 display_initialized = true;
306 }
307
308 if (major != nullptr) {
309 *major = 1;
310 }
311 if (minor != nullptr) {
312 *minor = 5;
313 }
314
315 return bool_success();
316}
317
318EGLBoolean _eglMakeCurrent(EGLDisplay dpy,
319 EGLSurface draw,
320 EGLSurface read,
321 EGLContext ctx) {
322 if (!check_display(dpy) || !check_initialized(dpy)) {
323 return EGL_FALSE;
324 }
325
326 return bool_success();
327}
328EGLBoolean _eglQueryContext(EGLDisplay display,
329 EGLContext context,
330 EGLint attribute,
331 EGLint* value) {
332 if (attribute == EGL_CONTEXT_CLIENT_TYPE) {
333 *value = EGL_OPENGL_API;
334 return EGL_TRUE;
335 }
336 return EGL_FALSE;
337}
338
339EGLBoolean _eglSwapBuffers(EGLDisplay dpy, EGLSurface surface) {
340 if (!check_display(dpy) || !check_initialized(dpy)) {
341 return EGL_FALSE;
342 }
343
344 return bool_success();
345}
346
347static GLuint bound_texture_2d;
348
349static void _glBindFramebuffer(GLenum target, GLuint framebuffer) {}
350
351static void _glBindTexture(GLenum target, GLuint texture) {
352 if (target == GL_TEXTURE_2D) {
354 }
355}
356
357void _glDeleteFramebuffers(GLsizei n, const GLuint* framebuffers) {}
358
359void _glDeleteTextures(GLsizei n, const GLuint* textures) {}
360
362 GLenum attachment,
363 GLenum textarget,
364 GLuint texture,
365 GLint level) {}
366
367static void _glGenTextures(GLsizei n, GLuint* textures) {
368 for (GLsizei i = 0; i < n; i++) {
369 textures[i] = 0;
370 }
371}
372
373static void _glGenFramebuffers(GLsizei n, GLuint* framebuffers) {
374 for (GLsizei i = 0; i < n; i++) {
375 framebuffers[i] = 0;
376 }
377}
378
379static void _glGetIntegerv(GLenum pname, GLint* data) {
380 if (pname == GL_TEXTURE_BINDING_2D) {
382 }
383}
384
385static void _glTexParameterf(GLenum target, GLenum pname, GLfloat param) {}
386
387static void _glTexParameteri(GLenum target, GLenum pname, GLint param) {}
388
389static void _glTexImage2D(GLenum target,
390 GLint level,
391 GLint internalformat,
392 GLsizei width,
393 GLsizei height,
394 GLint border,
395 GLenum format,
396 GLenum type,
397 const void* pixels) {}
398
399static GLenum _glGetError() {
400 return GL_NO_ERROR;
401}
402
403bool epoxy_has_gl_extension(const char* extension) {
404 return false;
405}
406
408 return false;
409}
410
412 return 0;
413}
414
415#ifdef __GNUC__
416#define CONSTRUCT(_func) static void _func(void) __attribute__((constructor));
417#define DESTRUCT(_func) static void _func(void) __attribute__((destructor));
418#elif defined(_MSC_VER) && (_MSC_VER >= 1500)
419#define CONSTRUCT(_func) \
420 static void _func(void); \
421 static int _func##_wrapper(void) { \
422 _func(); \
423 return 0; \
424 } \
425 __pragma(section(".CRT$XCU", read)) \
426 __declspec(allocate(".CRT$XCU")) static int (*_array##_func)(void) = \
427 _func##_wrapper;
428
429#else
430#error "You will need constructor support for your compiler"
431#endif
432
433CONSTRUCT(library_init)
434
435EGLBoolean (*epoxy_eglBindAPI)(EGLenum api);
436EGLBoolean (*epoxy_eglChooseConfig)(EGLDisplay dpy,
437 const EGLint* attrib_list,
438 EGLConfig* configs,
439 EGLint config_size,
440 EGLint* num_config);
441EGLContext (*epoxy_eglCreateContext)(EGLDisplay dpy,
442 EGLConfig config,
443 EGLContext share_context,
444 const EGLint* attrib_list);
445EGLSurface (*epoxy_eglCreatePbufferSurface)(EGLDisplay dpy,
446 EGLConfig config,
447 const EGLint* attrib_list);
448EGLSurface (*epoxy_eglCreateWindowSurface)(EGLDisplay dpy,
449 EGLConfig config,
450 EGLNativeWindowType win,
451 const EGLint* attrib_list);
452EGLBoolean (*epoxy_eglGetConfigAttrib)(EGLDisplay dpy,
453 EGLConfig config,
454 EGLint attribute,
455 EGLint* value);
456EGLDisplay (*epoxy_eglGetDisplay)(EGLNativeDisplayType display_id);
458void (*(*epoxy_eglGetProcAddress)(const char* procname))(void);
459EGLBoolean (*epoxy_eglInitialize)(EGLDisplay dpy, EGLint* major, EGLint* minor);
460EGLBoolean (*epoxy_eglMakeCurrent)(EGLDisplay dpy,
461 EGLSurface draw,
462 EGLSurface read,
463 EGLContext ctx);
464EGLBoolean (*epoxy_eglSwapBuffers)(EGLDisplay dpy, EGLSurface surface);
465
466void (*epoxy_glBindFramebuffer)(GLenum target, GLuint framebuffer);
467void (*epoxy_glBindTexture)(GLenum target, GLuint texture);
468void (*epoxy_glDeleteFramebuffers)(GLsizei n, const GLuint* framebuffers);
469void (*epoxy_glDeleteTextures)(GLsizei n, const GLuint* textures);
471 GLenum attachment,
472 GLenum textarget,
473 GLuint texture,
474 GLint level);
475void (*epoxy_glGenFramebuffers)(GLsizei n, GLuint* framebuffers);
476void (*epoxy_glGenTextures)(GLsizei n, GLuint* textures);
477void (*epoxy_glTexParameterf)(GLenum target, GLenum pname, GLfloat param);
478void (*epoxy_glTexParameteri)(GLenum target, GLenum pname, GLint param);
480 GLint level,
481 GLint internalformat,
482 GLsizei width,
483 GLsizei height,
484 GLint border,
485 GLenum format,
486 GLenum type,
487 const void* pixels);
489
490static void library_init() {
502 epoxy_eglQueryContext = _eglQueryContext;
504
512 epoxy_glGetIntegerv = _glGetIntegerv;
517}
static bool read(SkStream *stream, void *buffer, size_t amount)
static void draw(SkCanvas *canvas, SkRect &target, int x, int y)
Definition: aaclip.cpp:27
GLenum type
VkSurfaceKHR surface
Definition: main.cc:49
const uint8_t uint32_t uint32_t GError ** error
uint8_t value
uint32_t uint32_t * format
uint32_t * target
static EGLBoolean bool_failure(EGLint error)
Definition: mock_epoxy.cc:88
static void _glGenFramebuffers(GLsizei n, GLuint *framebuffers)
Definition: mock_epoxy.cc:373
static bool check_config(EGLConfig config)
Definition: mock_epoxy.cc:74
void(* epoxy_glBindTexture)(GLenum target, GLuint texture)
Definition: mock_epoxy.cc:467
EGLBoolean _eglGetConfigAttrib(EGLDisplay dpy, EGLConfig config, EGLint attribute, EGLint *value)
Definition: mock_epoxy.cc:161
EGLSurface(* epoxy_eglCreateWindowSurface)(EGLDisplay dpy, EGLConfig config, EGLNativeWindowType win, const EGLint *attrib_list)
Definition: mock_epoxy.cc:448
EGLBoolean _eglChooseConfig(EGLDisplay dpy, const EGLint *attrib_list, EGLConfig *configs, EGLint config_size, EGLint *num_config)
Definition: mock_epoxy.cc:97
void(* epoxy_glDeleteTextures)(GLsizei n, const GLuint *textures)
Definition: mock_epoxy.cc:469
EGLBoolean _eglInitialize(EGLDisplay dpy, EGLint *major, EGLint *minor)
Definition: mock_epoxy.cc:272
static void _glFramebufferTexture2D(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level)
Definition: mock_epoxy.cc:361
EGLBoolean _eglQueryContext(EGLDisplay display, EGLContext context, EGLint attribute, EGLint *value)
Definition: mock_epoxy.cc:328
static GLuint bound_texture_2d
Definition: mock_epoxy.cc:347
void(* epoxy_glGenFramebuffers)(GLsizei n, GLuint *framebuffers)
Definition: mock_epoxy.cc:475
bool epoxy_has_gl_extension(const char *extension)
Definition: mock_epoxy.cc:403
void(* epoxy_glTexParameteri)(GLenum target, GLenum pname, GLint param)
Definition: mock_epoxy.cc:478
static MockContext mock_context
Definition: mock_epoxy.cc:51
static void library_init()
Definition: mock_epoxy.cc:490
void(* epoxy_glTexImage2D)(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const void *pixels)
Definition: mock_epoxy.cc:479
static void _glTexParameteri(GLenum target, GLenum pname, GLint param)
Definition: mock_epoxy.cc:387
static void _glTexParameterf(GLenum target, GLenum pname, GLfloat param)
Definition: mock_epoxy.cc:385
void(*(* epoxy_eglGetProcAddress)(const char *procname))(void)
Definition: mock_epoxy.cc:458
EGLSurface _eglCreateWindowSurface(EGLDisplay dpy, EGLConfig config, EGLNativeWindowType win, const EGLint *attrib_list)
Definition: mock_epoxy.cc:149
EGLBoolean _eglBindAPI(EGLenum api)
Definition: mock_epoxy.cc:93
EGLContext(* epoxy_eglCreateContext)(EGLDisplay dpy, EGLConfig config, EGLContext share_context, const EGLint *attrib_list)
Definition: mock_epoxy.cc:441
static void _glBindFramebuffer(GLenum target, GLuint framebuffer)
Definition: mock_epoxy.cc:349
static bool check_initialized(EGLDisplay dpy)
Definition: mock_epoxy.cc:65
EGLBoolean(* epoxy_eglGetConfigAttrib)(EGLDisplay dpy, EGLConfig config, EGLint attribute, EGLint *value)
Definition: mock_epoxy.cc:452
EGLint _eglGetError()
Definition: mock_epoxy.cc:261
static MockConfig mock_config
Definition: mock_epoxy.cc:50
void(* epoxy_glDeleteFramebuffers)(GLsizei n, const GLuint *framebuffers)
Definition: mock_epoxy.cc:468
void(* epoxy_glTexParameterf)(GLenum target, GLenum pname, GLfloat param)
Definition: mock_epoxy.cc:477
EGLBoolean(* epoxy_eglInitialize)(EGLDisplay dpy, EGLint *major, EGLint *minor)
Definition: mock_epoxy.cc:459
static void _glBindTexture(GLenum target, GLuint texture)
Definition: mock_epoxy.cc:351
EGLDisplay _eglGetDisplay(EGLNativeDisplayType display_id)
Definition: mock_epoxy.cc:257
static bool check_display(EGLDisplay dpy)
Definition: mock_epoxy.cc:56
void(* epoxy_glGenTextures)(GLsizei n, GLuint *textures)
Definition: mock_epoxy.cc:476
void _glDeleteTextures(GLsizei n, const GLuint *textures)
Definition: mock_epoxy.cc:359
void(* epoxy_glBindFramebuffer)(GLenum target, GLuint framebuffer)
Definition: mock_epoxy.cc:466
EGLSurface _eglCreatePbufferSurface(EGLDisplay dpy, EGLConfig config, const EGLint *attrib_list)
Definition: mock_epoxy.cc:138
EGLSurface(* epoxy_eglCreatePbufferSurface)(EGLDisplay dpy, EGLConfig config, const EGLint *attrib_list)
Definition: mock_epoxy.cc:445
static bool display_initialized
Definition: mock_epoxy.cc:48
void _glDeleteFramebuffers(GLsizei n, const GLuint *framebuffers)
Definition: mock_epoxy.cc:357
static void _glGenTextures(GLsizei n, GLuint *textures)
Definition: mock_epoxy.cc:367
void(*)(void) _eglGetProcAddress(const char *procname)
Definition: mock_epoxy.cc:267
EGLDisplay(* epoxy_eglGetDisplay)(EGLNativeDisplayType display_id)
Definition: mock_epoxy.cc:456
EGLint(* epoxy_eglGetError)()
Definition: mock_epoxy.cc:457
static EGLBoolean bool_success()
Definition: mock_epoxy.cc:83
static void _glTexImage2D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const void *pixels)
Definition: mock_epoxy.cc:389
GLenum(* epoxy_glGetError)()
Definition: mock_epoxy.cc:488
bool epoxy_is_desktop_gl(void)
Definition: mock_epoxy.cc:407
int epoxy_gl_version(void)
Definition: mock_epoxy.cc:411
EGLBoolean(* epoxy_eglSwapBuffers)(EGLDisplay dpy, EGLSurface surface)
Definition: mock_epoxy.cc:464
static EGLint mock_error
Definition: mock_epoxy.cc:54
EGLContext _eglCreateContext(EGLDisplay dpy, EGLConfig config, EGLContext share_context, const EGLint *attrib_list)
Definition: mock_epoxy.cc:126
EGLBoolean _eglMakeCurrent(EGLDisplay dpy, EGLSurface draw, EGLSurface read, EGLContext ctx)
Definition: mock_epoxy.cc:318
EGLBoolean(* epoxy_eglMakeCurrent)(EGLDisplay dpy, EGLSurface draw, EGLSurface read, EGLContext ctx)
Definition: mock_epoxy.cc:460
EGLBoolean(* epoxy_eglBindAPI)(EGLenum api)
Definition: mock_epoxy.cc:435
static void _glGetIntegerv(GLenum pname, GLint *data)
Definition: mock_epoxy.cc:379
EGLBoolean(* epoxy_eglChooseConfig)(EGLDisplay dpy, const EGLint *attrib_list, EGLConfig *configs, EGLint config_size, EGLint *num_config)
Definition: mock_epoxy.cc:436
static MockDisplay mock_display
Definition: mock_epoxy.cc:49
static MockSurface mock_surface
Definition: mock_epoxy.cc:52
void(* epoxy_glFramebufferTexture2D)(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level)
Definition: mock_epoxy.cc:470
EGLBoolean _eglSwapBuffers(EGLDisplay dpy, EGLSurface surface)
Definition: mock_epoxy.cc:339
static GLenum _glGetError()
Definition: mock_epoxy.cc:399
FlTexture * texture
int32_t height
int32_t width
EGLint depth_size
Definition: mock_epoxy.cc:19
EGLint renderable_type
Definition: mock_epoxy.cc:29
EGLint native_renderable
Definition: mock_epoxy.cc:25
EGLint bind_to_texture_rgba
Definition: mock_epoxy.cc:28
EGLint native_visual_type
Definition: mock_epoxy.cc:24
EGLint max_pbuffer_width
Definition: mock_epoxy.cc:32
EGLint conformant
Definition: mock_epoxy.cc:30
EGLint green_size
Definition: mock_epoxy.cc:16
EGLint config_id
Definition: mock_epoxy.cc:10
EGLint buffer_size
Definition: mock_epoxy.cc:11
EGLint surface_type
Definition: mock_epoxy.cc:31
EGLint level
Definition: mock_epoxy.cc:14
EGLint config_caveat
Definition: mock_epoxy.cc:26
EGLint color_buffer_type
Definition: mock_epoxy.cc:12
EGLint min_swap_interval
Definition: mock_epoxy.cc:35
EGLint native_visual_id
Definition: mock_epoxy.cc:23
EGLint max_pbuffer_pixels
Definition: mock_epoxy.cc:34
EGLint red_size
Definition: mock_epoxy.cc:15
EGLint max_pbuffer_height
Definition: mock_epoxy.cc:33
EGLint sample_buffers
Definition: mock_epoxy.cc:22
EGLint max_swap_interval
Definition: mock_epoxy.cc:36
EGLint stencil_size
Definition: mock_epoxy.cc:20
EGLint samples
Definition: mock_epoxy.cc:21
EGLint blue_size
Definition: mock_epoxy.cc:17
EGLint alpha_size
Definition: mock_epoxy.cc:18
EGLint transparent_type
Definition: mock_epoxy.cc:13
EGLint bind_to_texture_rgb
Definition: mock_epoxy.cc:27
std::shared_ptr< const fml::Mapping > data
Definition: texture_gles.cc:63