Flutter Linux Embedder
fl_opengl_manager.cc File Reference
#include <epoxy/egl.h>
#include <gdk/gdkwayland.h>
#include "flutter/shell/platform/linux/fl_opengl_manager.h"

Go to the source code of this file.

Classes

struct  _FlOpenGLManager
 

Functions

static void fl_opengl_manager_dispose (GObject *object)
 
static void fl_opengl_manager_class_init (FlOpenGLManagerClass *klass)
 
static void fl_opengl_manager_init (FlOpenGLManager *self)
 
FlOpenGLManager * fl_opengl_manager_new ()
 
gboolean fl_opengl_manager_make_current (FlOpenGLManager *self)
 
gboolean fl_opengl_manager_make_resource_current (FlOpenGLManager *self)
 
gboolean fl_opengl_manager_make_platform_current (FlOpenGLManager *self)
 
gboolean fl_opengl_manager_clear_current (FlOpenGLManager *self)
 

Function Documentation

◆ fl_opengl_manager_class_init()

static void fl_opengl_manager_class_init ( FlOpenGLManagerClass *  klass)
static

Definition at line 42 of file fl_opengl_manager.cc.

42  {
43  G_OBJECT_CLASS(klass)->dispose = fl_opengl_manager_dispose;
44 }
static void fl_opengl_manager_dispose(GObject *object)

References fl_opengl_manager_dispose().

◆ fl_opengl_manager_clear_current()

gboolean fl_opengl_manager_clear_current ( FlOpenGLManager *  manager)

fl_opengl_manager_clear_current: @manager: an #FlOpenGLManager.

Clears the current rendering context.

Returns: TRUE if the context cleared.

Definition at line 113 of file fl_opengl_manager.cc.

113  {
114  return eglMakeCurrent(self->display, EGL_NO_SURFACE, EGL_NO_SURFACE,
115  EGL_NO_CONTEXT) == EGL_TRUE;
116 }

Referenced by fl_engine_gl_clear_current(), and realize_cb().

◆ fl_opengl_manager_dispose()

static void fl_opengl_manager_dispose ( GObject *  object)
static

Definition at line 31 of file fl_opengl_manager.cc.

31  {
32  FlOpenGLManager* self = FL_OPENGL_MANAGER(object);
33 
34  eglDestroyContext(self->display, self->render_context);
35  eglDestroyContext(self->display, self->resource_context);
36  eglDestroyContext(self->display, self->platform_context);
37  eglTerminate(self->display);
38 
39  G_OBJECT_CLASS(fl_opengl_manager_parent_class)->dispose(object);
40 }

Referenced by fl_opengl_manager_class_init().

◆ fl_opengl_manager_init()

static void fl_opengl_manager_init ( FlOpenGLManager *  self)
static

Definition at line 46 of file fl_opengl_manager.cc.

46  {
47  GdkDisplay* display = gdk_display_get_default();
48  if (GDK_IS_WAYLAND_DISPLAY(display)) {
49  self->display = eglGetPlatformDisplayEXT(
50  EGL_PLATFORM_WAYLAND_EXT, gdk_wayland_display_get_wl_display(display),
51  NULL);
52 #ifdef GDK_WINDOWING_X11
53  } else if (GDK_IS_X11_DISPLAY(display)) {
54  self->display = eglGetPlatformDisplayEXT(
55  EGL_PLATFORM_X11_EXT, gdk_x11_display_get_xdisplay(display), NULL);
56 #endif
57  } else {
58  g_critical("Unsupported GDK backend, unable to get EGL display");
59  }
60 
61  eglInitialize(self->display, nullptr, nullptr);
62 
63  const EGLint config_attributes[] = {EGL_RED_SIZE, 8, EGL_GREEN_SIZE, 8,
64  EGL_BLUE_SIZE, 8, EGL_ALPHA_SIZE, 8,
65  EGL_DEPTH_SIZE, 8, EGL_STENCIL_SIZE, 8,
66  EGL_NONE};
67  EGLConfig config = nullptr;
68  EGLint num_config = 0;
69  eglChooseConfig(self->display, config_attributes, &config, 1, &num_config);
70 
71  const EGLint context_attributes[] = {EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE};
72 
73  self->render_context = eglCreateContext(self->display, config, EGL_NO_CONTEXT,
74  context_attributes);
75  if (self->render_context == EGL_NO_CONTEXT) {
76  g_warning("Failed to create EGL context for rendering");
77  }
78 
79  self->resource_context = eglCreateContext(
80  self->display, config, self->render_context, context_attributes);
81  if (self->resource_context == EGL_NO_CONTEXT) {
82  g_warning("Failed to create EGL context for resource sharing");
83  }
84 
85  self->platform_context = eglCreateContext(
86  self->display, config, self->render_context, context_attributes);
87  if (self->platform_context == EGL_NO_CONTEXT) {
88  g_warning("Failed to create EGL context for platform thread");
89  }
90 }

◆ fl_opengl_manager_make_current()

gboolean fl_opengl_manager_make_current ( FlOpenGLManager *  manager)

fl_opengl_manager_make_current: @manager: an #FlOpenGLManager.

Makes the rendering context current.

Returns: TRUE if the context made current.

Definition at line 98 of file fl_opengl_manager.cc.

98  {
99  return eglMakeCurrent(self->display, EGL_NO_SURFACE, EGL_NO_SURFACE,
100  self->render_context) == EGL_TRUE;
101 }

Referenced by collect_opengl_backing_store(), create_opengl_backing_store(), and fl_engine_gl_make_current().

◆ fl_opengl_manager_make_platform_current()

gboolean fl_opengl_manager_make_platform_current ( FlOpenGLManager *  manager)

fl_opengl_manager_make_platform_current: @manager: an #FlOpenGLManager.

Makes the platform rendering context current.

Returns: TRUE if the context made current.

Definition at line 108 of file fl_opengl_manager.cc.

108  {
109  return eglMakeCurrent(self->display, EGL_NO_SURFACE, EGL_NO_SURFACE,
110  self->platform_context) == EGL_TRUE;
111 }

Referenced by cleanup_shader(), and setup_shader().

◆ fl_opengl_manager_make_resource_current()

gboolean fl_opengl_manager_make_resource_current ( FlOpenGLManager *  manager)

fl_opengl_manager_make_resource_current: @manager: an #FlOpenGLManager.

Makes the resource rendering context current.

Returns: TRUE if the context made current.

Definition at line 103 of file fl_opengl_manager.cc.

103  {
104  return eglMakeCurrent(self->display, EGL_NO_SURFACE, EGL_NO_SURFACE,
105  self->resource_context) == EGL_TRUE;
106 }

Referenced by fl_engine_gl_make_resource_current().

◆ fl_opengl_manager_new()

FlOpenGLManager* fl_opengl_manager_new ( )

Definition at line 92 of file fl_opengl_manager.cc.

92  {
93  FlOpenGLManager* self =
94  FL_OPENGL_MANAGER(g_object_new(fl_opengl_manager_get_type(), nullptr));
95  return self;
96 }

Referenced by fl_engine_init(), and TEST().