Flutter Engine
mock_egl.cc File Reference
#include <EGL/egl.h>

Go to the source code of this file.

Classes

struct  MockConfig
 
struct  MockDisplay
 
struct  MockContext
 
struct  MockSurface
 

Functions

static bool check_display (EGLDisplay dpy)
 
static bool check_initialized (EGLDisplay dpy)
 
static bool check_config (EGLConfig config)
 
static EGLBoolean bool_success ()
 
static EGLBoolean bool_failure (EGLint error)
 
EGLBoolean eglBindAPI (EGLenum api)
 
EGLBoolean eglChooseConfig (EGLDisplay dpy, const EGLint *attrib_list, EGLConfig *configs, EGLint config_size, EGLint *num_config)
 
EGLContext eglCreateContext (EGLDisplay dpy, EGLConfig config, EGLContext share_context, const EGLint *attrib_list)
 
EGLSurface eglCreatePbufferSurface (EGLDisplay dpy, EGLConfig config, const EGLint *attrib_list)
 
EGLSurface eglCreateWindowSurface (EGLDisplay dpy, EGLConfig config, EGLNativeWindowType win, const EGLint *attrib_list)
 
EGLBoolean eglGetConfigAttrib (EGLDisplay dpy, EGLConfig config, EGLint attribute, EGLint *value)
 
EGLDisplay eglGetDisplay (EGLNativeDisplayType display_id)
 
EGLint eglGetError ()
 
EGLBoolean eglInitialize (EGLDisplay dpy, EGLint *major, EGLint *minor)
 
EGLBoolean eglMakeCurrent (EGLDisplay dpy, EGLSurface draw, EGLSurface read, EGLContext ctx)
 
EGLBoolean eglSwapBuffers (EGLDisplay dpy, EGLSurface surface)
 

Variables

static bool display_initialized = false
 
static MockDisplay mock_display
 
static MockConfig mock_config
 
static MockContext mock_context
 
static MockSurface mock_surface
 
static EGLint mock_error = EGL_SUCCESS
 
void(*)(void) eglGetProcAddress (const char *procname)
 

Function Documentation

◆ bool_failure()

static EGLBoolean bool_failure ( EGLint  error)
static

Definition at line 86 of file mock_egl.cc.

References error, and mock_error.

Referenced by eglGetConfigAttrib().

86  {
87  mock_error = error;
88  return EGL_FALSE;
89 }
FlMethodResponse GError ** error
static EGLint mock_error
Definition: mock_egl.cc:52

◆ bool_success()

static EGLBoolean bool_success ( )
static

Definition at line 81 of file mock_egl.cc.

References mock_error.

Referenced by eglBindAPI(), eglChooseConfig(), eglGetConfigAttrib(), eglInitialize(), eglMakeCurrent(), and eglSwapBuffers().

81  {
82  mock_error = EGL_SUCCESS;
83  return EGL_TRUE;
84 }
static EGLint mock_error
Definition: mock_egl.cc:52

◆ check_config()

static bool check_config ( EGLConfig  config)
static

Definition at line 72 of file mock_egl.cc.

References mock_error.

Referenced by eglCreateContext(), eglCreatePbufferSurface(), eglCreateWindowSurface(), and eglGetConfigAttrib().

72  {
73  if (config == nullptr) {
74  mock_error = EGL_BAD_CONFIG;
75  return false;
76  }
77 
78  return true;
79 }
static EGLint mock_error
Definition: mock_egl.cc:52

◆ check_display()

static bool check_display ( EGLDisplay  dpy)
static

Definition at line 54 of file mock_egl.cc.

References mock_error.

Referenced by eglChooseConfig(), eglCreateContext(), eglCreatePbufferSurface(), eglCreateWindowSurface(), eglGetConfigAttrib(), eglInitialize(), eglMakeCurrent(), and eglSwapBuffers().

54  {
55  if (dpy == nullptr) {
56  mock_error = EGL_BAD_DISPLAY;
57  return false;
58  }
59 
60  return true;
61 }
static EGLint mock_error
Definition: mock_egl.cc:52

◆ check_initialized()

static bool check_initialized ( EGLDisplay  dpy)
static

Definition at line 63 of file mock_egl.cc.

References display_initialized, and mock_error.

Referenced by eglChooseConfig(), eglCreateContext(), eglCreatePbufferSurface(), eglCreateWindowSurface(), eglGetConfigAttrib(), eglMakeCurrent(), and eglSwapBuffers().

63  {
64  if (!display_initialized) {
65  mock_error = EGL_NOT_INITIALIZED;
66  return false;
67  }
68 
69  return true;
70 }
static EGLint mock_error
Definition: mock_egl.cc:52
static bool display_initialized
Definition: mock_egl.cc:46

◆ eglBindAPI()

EGLBoolean eglBindAPI ( EGLenum  api)

Definition at line 91 of file mock_egl.cc.

References bool_success().

Referenced by setup_egl_display().

91  {
92  return bool_success();
93 }
static EGLBoolean bool_success()
Definition: mock_egl.cc:81

◆ eglChooseConfig()

EGLBoolean eglChooseConfig ( EGLDisplay  dpy,
const EGLint *  attrib_list,
EGLConfig *  configs,
EGLint  config_size,
EGLint *  num_config 
)

Definition at line 95 of file mock_egl.cc.

References bool_success(), check_display(), check_initialized(), and mock_config.

Referenced by flutter::ChooseEGLConfiguration(), setup_egl_display(), TEST(), flutter::testing::TestGLSurface::TestGLSurface(), and flutter::AngleSurfaceManager::~AngleSurfaceManager().

99  {
100  if (!check_display(dpy) || !check_initialized(dpy))
101  return EGL_FALSE;
102 
103  if (configs == nullptr) {
104  if (num_config != nullptr)
105  *num_config = 1;
106  return bool_success();
107  }
108 
109  EGLint n_returned = 0;
110  if (config_size >= 1) {
111  configs[0] = &mock_config;
112  n_returned++;
113  }
114 
115  if (num_config != nullptr)
116  *num_config = n_returned;
117 
118  return bool_success();
119 }
static EGLBoolean bool_success()
Definition: mock_egl.cc:81
static bool check_display(EGLDisplay dpy)
Definition: mock_egl.cc:54
static MockConfig mock_config
Definition: mock_egl.cc:48
static bool check_initialized(EGLDisplay dpy)
Definition: mock_egl.cc:63

◆ eglCreateContext()

EGLContext eglCreateContext ( EGLDisplay  dpy,
EGLConfig  config,
EGLContext  share_context,
const EGLint *  attrib_list 
)

Definition at line 121 of file mock_egl.cc.

References check_config(), check_display(), check_initialized(), mock_context, and mock_error.

Referenced by flutter::CreateContext(), setup_egl_surfaces(), flutter::testing::TestGLSurface::TestGLSurface(), and flutter::AngleSurfaceManager::~AngleSurfaceManager().

124  {
125  if (!check_display(dpy) || !check_initialized(dpy) || !check_config(config))
126  return EGL_NO_CONTEXT;
127 
128  mock_error = EGL_SUCCESS;
129  return &mock_context;
130 }
static bool check_display(EGLDisplay dpy)
Definition: mock_egl.cc:54
static MockContext mock_context
Definition: mock_egl.cc:49
static bool check_config(EGLConfig config)
Definition: mock_egl.cc:72
static bool check_initialized(EGLDisplay dpy)
Definition: mock_egl.cc:63
static EGLint mock_error
Definition: mock_egl.cc:52

◆ eglCreatePbufferSurface()

EGLSurface eglCreatePbufferSurface ( EGLDisplay  dpy,
EGLConfig  config,
const EGLint *  attrib_list 
)

Definition at line 132 of file mock_egl.cc.

References check_config(), check_display(), check_initialized(), mock_error, and mock_surface.

Referenced by flutter::AndroidContextGL::CreateOffscreenSurface(), fl_mock_renderer_create_surfaces(), and flutter::testing::TestGLSurface::TestGLSurface().

134  {
135  if (!check_display(dpy) || !check_initialized(dpy) || !check_config(config))
136  return EGL_NO_SURFACE;
137 
138  mock_error = EGL_SUCCESS;
139  return &mock_surface;
140 }
static MockSurface mock_surface
Definition: mock_egl.cc:50
static bool check_display(EGLDisplay dpy)
Definition: mock_egl.cc:54
static bool check_config(EGLConfig config)
Definition: mock_egl.cc:72
static bool check_initialized(EGLDisplay dpy)
Definition: mock_egl.cc:63
static EGLint mock_error
Definition: mock_egl.cc:52

◆ eglCreateWindowSurface()

EGLSurface eglCreateWindowSurface ( EGLDisplay  dpy,
EGLConfig  config,
EGLNativeWindowType  win,
const EGLint *  attrib_list 
)

Definition at line 142 of file mock_egl.cc.

References check_config(), check_display(), check_initialized(), mock_error, and mock_surface.

Referenced by flutter::AndroidContextGL::CreateOnscreenSurface(), flutter::AngleSurfaceManager::CreateSurface(), fl_mock_renderer_create_surfaces(), and fl_renderer_wayland_create_surfaces().

145  {
146  if (!check_display(dpy) || !check_initialized(dpy) || !check_config(config))
147  return EGL_NO_SURFACE;
148 
149  mock_error = EGL_SUCCESS;
150  return &mock_surface;
151 }
static MockSurface mock_surface
Definition: mock_egl.cc:50
static bool check_display(EGLDisplay dpy)
Definition: mock_egl.cc:54
static bool check_config(EGLConfig config)
Definition: mock_egl.cc:72
static bool check_initialized(EGLDisplay dpy)
Definition: mock_egl.cc:63
static EGLint mock_error
Definition: mock_egl.cc:52

◆ eglGetConfigAttrib()

EGLBoolean eglGetConfigAttrib ( EGLDisplay  dpy,
EGLConfig  config,
EGLint  attribute,
EGLint *  value 
)

Definition at line 153 of file mock_egl.cc.

References MockConfig::alpha_size, MockConfig::bind_to_texture_rgb, MockConfig::bind_to_texture_rgba, MockConfig::blue_size, bool_failure(), bool_success(), MockConfig::buffer_size, check_config(), check_display(), check_initialized(), MockConfig::color_buffer_type, MockConfig::config_caveat, MockConfig::config_id, MockConfig::conformant, MockConfig::depth_size, MockConfig::green_size, MockConfig::level, MockConfig::max_pbuffer_height, MockConfig::max_pbuffer_pixels, MockConfig::max_pbuffer_width, MockConfig::max_swap_interval, MockConfig::min_swap_interval, MockConfig::native_renderable, MockConfig::native_visual_id, MockConfig::native_visual_type, MockConfig::red_size, MockConfig::renderable_type, MockConfig::sample_buffers, MockConfig::samples, MockConfig::stencil_size, MockConfig::surface_type, and MockConfig::transparent_type.

Referenced by egl_config_to_string().

156  {
157  if (!check_display(dpy) || !check_initialized(dpy) || !check_config(config))
158  return EGL_FALSE;
159 
160  MockConfig* c = static_cast<MockConfig*>(config);
161  switch (attribute) {
162  case EGL_CONFIG_ID:
163  *value = c->config_id;
164  return bool_success();
165  case EGL_BUFFER_SIZE:
166  *value = c->buffer_size;
167  return bool_success();
168  case EGL_COLOR_BUFFER_TYPE:
169  *value = c->color_buffer_type;
170  return bool_success();
171  case EGL_TRANSPARENT_TYPE:
172  *value = c->transparent_type;
173  return bool_success();
174  case EGL_LEVEL:
175  *value = c->level;
176  return bool_success();
177  case EGL_RED_SIZE:
178  *value = c->red_size;
179  return bool_success();
180  case EGL_GREEN_SIZE:
181  *value = c->green_size;
182  return bool_success();
183  case EGL_BLUE_SIZE:
184  *value = c->blue_size;
185  return bool_success();
186  case EGL_ALPHA_SIZE:
187  *value = c->alpha_size;
188  return bool_success();
189  case EGL_DEPTH_SIZE:
190  *value = c->depth_size;
191  return bool_success();
192  case EGL_STENCIL_SIZE:
193  *value = c->stencil_size;
194  return bool_success();
195  case EGL_SAMPLES:
196  *value = c->samples;
197  return bool_success();
198  case EGL_SAMPLE_BUFFERS:
199  *value = c->sample_buffers;
200  return bool_success();
201  case EGL_NATIVE_VISUAL_ID:
202  *value = c->native_visual_id;
203  return bool_success();
204  case EGL_NATIVE_VISUAL_TYPE:
206  return bool_success();
207  case EGL_NATIVE_RENDERABLE:
208  *value = c->native_renderable;
209  return bool_success();
210  case EGL_CONFIG_CAVEAT:
211  *value = c->config_caveat;
212  return bool_success();
213  case EGL_BIND_TO_TEXTURE_RGB:
215  return bool_success();
216  case EGL_BIND_TO_TEXTURE_RGBA:
218  return bool_success();
219  case EGL_RENDERABLE_TYPE:
220  *value = c->renderable_type;
221  return bool_success();
222  case EGL_CONFORMANT:
223  *value = c->conformant;
224  return bool_success();
225  case EGL_SURFACE_TYPE:
226  *value = c->surface_type;
227  return bool_success();
228  case EGL_MAX_PBUFFER_WIDTH:
229  *value = c->max_pbuffer_width;
230  return bool_success();
231  case EGL_MAX_PBUFFER_HEIGHT:
233  return bool_success();
234  case EGL_MAX_PBUFFER_PIXELS:
236  return bool_success();
237  case EGL_MIN_SWAP_INTERVAL:
238  *value = c->min_swap_interval;
239  return bool_success();
240  case EGL_MAX_SWAP_INTERVAL:
241  *value = c->max_swap_interval;
242  return bool_success();
243  default:
244  return bool_failure(EGL_BAD_ATTRIBUTE);
245  }
246 }
EGLint max_pbuffer_height
Definition: mock_egl.cc:31
static EGLBoolean bool_success()
Definition: mock_egl.cc:81
EGLint surface_type
Definition: mock_egl.cc:29
EGLint green_size
Definition: mock_egl.cc:14
EGLint bind_to_texture_rgb
Definition: mock_egl.cc:25
EGLint renderable_type
Definition: mock_egl.cc:27
EGLint alpha_size
Definition: mock_egl.cc:16
EGLint transparent_type
Definition: mock_egl.cc:11
static EGLBoolean bool_failure(EGLint error)
Definition: mock_egl.cc:86
EGLint samples
Definition: mock_egl.cc:19
EGLint buffer_size
Definition: mock_egl.cc:9
EGLint conformant
Definition: mock_egl.cc:28
EGLint stencil_size
Definition: mock_egl.cc:18
EGLint max_swap_interval
Definition: mock_egl.cc:34
static bool check_display(EGLDisplay dpy)
Definition: mock_egl.cc:54
uint8_t value
EGLint min_swap_interval
Definition: mock_egl.cc:33
EGLint config_id
Definition: mock_egl.cc:8
EGLint color_buffer_type
Definition: mock_egl.cc:10
static bool check_config(EGLConfig config)
Definition: mock_egl.cc:72
EGLint native_visual_id
Definition: mock_egl.cc:21
EGLint native_renderable
Definition: mock_egl.cc:23
EGLint bind_to_texture_rgba
Definition: mock_egl.cc:26
static bool check_initialized(EGLDisplay dpy)
Definition: mock_egl.cc:63
EGLint red_size
Definition: mock_egl.cc:13
EGLint sample_buffers
Definition: mock_egl.cc:20
EGLint max_pbuffer_width
Definition: mock_egl.cc:30
EGLint level
Definition: mock_egl.cc:12
EGLint blue_size
Definition: mock_egl.cc:15
EGLint native_visual_type
Definition: mock_egl.cc:22
EGLint max_pbuffer_pixels
Definition: mock_egl.cc:32
EGLint depth_size
Definition: mock_egl.cc:17
EGLint config_caveat
Definition: mock_egl.cc:24

◆ eglGetDisplay()

EGLDisplay eglGetDisplay ( EGLNativeDisplayType  display_id)

Definition at line 248 of file mock_egl.cc.

References mock_display.

Referenced by fl_mock_renderer_create_display(), fl_renderer_wayland_create_display(), TEST(), and flutter::testing::TestGLSurface::TestGLSurface().

248  {
249  return &mock_display;
250 }
static MockDisplay mock_display
Definition: mock_egl.cc:47

◆ eglGetError()

EGLint eglGetError ( )

Definition at line 252 of file mock_egl.cc.

References error, and mock_error.

Referenced by fl_renderer_clear_current(), fl_renderer_make_current(), fl_renderer_make_resource_current(), fl_renderer_present(), fl_renderer_wayland_create_surfaces(), flutter::testing::GetEGLError(), flutter::LogLastEGLError(), setup_egl_display(), and setup_egl_surfaces().

252  {
253  EGLint error = mock_error;
254  mock_error = EGL_SUCCESS;
255  return error;
256 }
FlMethodResponse GError ** error
static EGLint mock_error
Definition: mock_egl.cc:52

◆ eglInitialize()

EGLBoolean eglInitialize ( EGLDisplay  dpy,
EGLint *  major,
EGLint *  minor 
)

Definition at line 263 of file mock_egl.cc.

References MockConfig::alpha_size, MockConfig::bind_to_texture_rgb, MockConfig::bind_to_texture_rgba, MockConfig::blue_size, bool_success(), MockConfig::buffer_size, check_display(), MockConfig::color_buffer_type, MockConfig::config_caveat, MockConfig::config_id, MockConfig::conformant, MockConfig::depth_size, display_initialized, MockConfig::green_size, MockConfig::level, MockConfig::max_pbuffer_height, MockConfig::max_pbuffer_pixels, MockConfig::max_pbuffer_width, MockConfig::max_swap_interval, MockConfig::min_swap_interval, MockConfig::native_renderable, MockConfig::native_visual_id, MockConfig::native_visual_type, MockConfig::red_size, MockConfig::renderable_type, MockConfig::sample_buffers, MockConfig::samples, MockConfig::stencil_size, MockConfig::surface_type, and MockConfig::transparent_type.

Referenced by setup_egl_display(), TEST(), flutter::testing::TestGLSurface::TestGLSurface(), and flutter::AngleSurfaceManager::~AngleSurfaceManager().

263  {
264  if (!check_display(dpy))
265  return EGL_FALSE;
266 
267  if (!display_initialized) {
270  mock_config.color_buffer_type = EGL_RGB_BUFFER;
271  mock_config.transparent_type = EGL_NONE;
272  mock_config.level = 1;
273  mock_config.red_size = 8;
279  mock_config.samples = 0;
283  mock_config.native_renderable = EGL_TRUE;
284  mock_config.config_caveat = EGL_NONE;
285  mock_config.bind_to_texture_rgb = EGL_TRUE;
286  mock_config.bind_to_texture_rgba = EGL_FALSE;
287  mock_config.renderable_type = EGL_OPENGL_ES2_BIT;
288  mock_config.conformant = EGL_OPENGL_ES2_BIT;
289  mock_config.surface_type = EGL_WINDOW_BIT | EGL_PBUFFER_BIT;
292  mock_config.max_pbuffer_pixels = 1024 * 1024;
295  display_initialized = true;
296  }
297 
298  if (major != nullptr)
299  *major = 1;
300  if (minor != nullptr)
301  *major = 5;
302 
303  return bool_success();
304 }
EGLint max_pbuffer_height
Definition: mock_egl.cc:31
static EGLBoolean bool_success()
Definition: mock_egl.cc:81
EGLint surface_type
Definition: mock_egl.cc:29
EGLint green_size
Definition: mock_egl.cc:14
EGLint bind_to_texture_rgb
Definition: mock_egl.cc:25
EGLint renderable_type
Definition: mock_egl.cc:27
EGLint alpha_size
Definition: mock_egl.cc:16
EGLint transparent_type
Definition: mock_egl.cc:11
EGLint samples
Definition: mock_egl.cc:19
EGLint buffer_size
Definition: mock_egl.cc:9
EGLint conformant
Definition: mock_egl.cc:28
EGLint stencil_size
Definition: mock_egl.cc:18
EGLint max_swap_interval
Definition: mock_egl.cc:34
static bool check_display(EGLDisplay dpy)
Definition: mock_egl.cc:54
EGLint min_swap_interval
Definition: mock_egl.cc:33
static MockConfig mock_config
Definition: mock_egl.cc:48
EGLint config_id
Definition: mock_egl.cc:8
EGLint color_buffer_type
Definition: mock_egl.cc:10
EGLint native_visual_id
Definition: mock_egl.cc:21
EGLint native_renderable
Definition: mock_egl.cc:23
EGLint bind_to_texture_rgba
Definition: mock_egl.cc:26
EGLint red_size
Definition: mock_egl.cc:13
EGLint sample_buffers
Definition: mock_egl.cc:20
EGLint max_pbuffer_width
Definition: mock_egl.cc:30
EGLint level
Definition: mock_egl.cc:12
EGLint blue_size
Definition: mock_egl.cc:15
static bool display_initialized
Definition: mock_egl.cc:46
EGLint native_visual_type
Definition: mock_egl.cc:22
EGLint max_pbuffer_pixels
Definition: mock_egl.cc:32
EGLint depth_size
Definition: mock_egl.cc:17
EGLint config_caveat
Definition: mock_egl.cc:24

◆ eglMakeCurrent()

◆ eglSwapBuffers()

EGLBoolean eglSwapBuffers ( EGLDisplay  dpy,
EGLSurface  surface 
)

Definition at line 316 of file mock_egl.cc.

References bool_success(), check_display(), and check_initialized().

Referenced by fl_renderer_present(), flutter::testing::TestGLSurface::Present(), flutter::AndroidEGLSurface::SwapBuffers(), and flutter::AngleSurfaceManager::SwapBuffers().

316  {
317  if (!check_display(dpy) || !check_initialized(dpy))
318  return EGL_FALSE;
319 
320  return bool_success();
321 }
static EGLBoolean bool_success()
Definition: mock_egl.cc:81
static bool check_display(EGLDisplay dpy)
Definition: mock_egl.cc:54
static bool check_initialized(EGLDisplay dpy)
Definition: mock_egl.cc:63

Variable Documentation

◆ display_initialized

bool display_initialized = false
static

Definition at line 46 of file mock_egl.cc.

Referenced by check_initialized(), and eglInitialize().

◆ eglGetProcAddress

void(*)(void) eglGetProcAddress(const char *procname)

Definition at line 258 of file mock_egl.cc.

Referenced by fl_renderer_get_proc_address(), flutter::testing::TestGLSurface::GetProcAddress(), and flutter::AngleSurfaceManager::~AngleSurfaceManager().

258  {
259  mock_error = EGL_SUCCESS;
260  return nullptr;
261 }
static EGLint mock_error
Definition: mock_egl.cc:52

◆ mock_config

MockConfig mock_config
static

Definition at line 48 of file mock_egl.cc.

Referenced by eglChooseConfig().

◆ mock_context

MockContext mock_context
static

Definition at line 49 of file mock_egl.cc.

Referenced by eglCreateContext().

◆ mock_display

MockDisplay mock_display
static

Definition at line 47 of file mock_egl.cc.

Referenced by eglGetDisplay().

◆ mock_error

◆ mock_surface

MockSurface mock_surface
static

Definition at line 50 of file mock_egl.cc.

Referenced by eglCreatePbufferSurface(), and eglCreateWindowSurface().