Flutter Linux Embedder
fl_opengl_manager.cc File Reference
#include <epoxy/egl.h>
#include <gdk/gdkwayland.h>
#include <gdk/gdkx.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_clear_current (FlOpenGLManager *self)
 

Function Documentation

◆ fl_opengl_manager_class_init()

static void fl_opengl_manager_class_init ( FlOpenGLManagerClass *  klass)
static

Definition at line 36 of file fl_opengl_manager.cc.

36  {
37  G_OBJECT_CLASS(klass)->dispose = fl_opengl_manager_dispose;
38 }
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 86 of file fl_opengl_manager.cc.

86  {
87  return eglMakeCurrent(self->display, EGL_NO_SURFACE, EGL_NO_SURFACE,
88  EGL_NO_CONTEXT) == EGL_TRUE;
89 }

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 26 of file fl_opengl_manager.cc.

26  {
27  FlOpenGLManager* self = FL_OPENGL_MANAGER(object);
28 
29  eglDestroyContext(self->display, self->render_context);
30  eglDestroyContext(self->display, self->resource_context);
31  eglTerminate(self->display);
32 
33  G_OBJECT_CLASS(fl_opengl_manager_parent_class)->dispose(object);
34 }

Referenced by fl_opengl_manager_class_init().

◆ fl_opengl_manager_init()

static void fl_opengl_manager_init ( FlOpenGLManager *  self)
static

Definition at line 40 of file fl_opengl_manager.cc.

40  {
41  GdkDisplay* display = gdk_display_get_default();
42  if (GDK_IS_WAYLAND_DISPLAY(display)) {
43  self->display = eglGetPlatformDisplayEXT(
44  EGL_PLATFORM_WAYLAND_EXT, gdk_wayland_display_get_wl_display(display),
45  NULL);
46  } else if (GDK_IS_X11_DISPLAY(display)) {
47  self->display = eglGetPlatformDisplayEXT(
48  EGL_PLATFORM_X11_EXT, gdk_x11_display_get_xdisplay(display), NULL);
49  } else {
50  g_critical("Unsupported GDK backend, unable to get EGL display");
51  }
52 
53  eglInitialize(self->display, nullptr, nullptr);
54 
55  const EGLint config_attributes[] = {EGL_RED_SIZE, 8, EGL_GREEN_SIZE, 8,
56  EGL_BLUE_SIZE, 8, EGL_ALPHA_SIZE, 8,
57  EGL_DEPTH_SIZE, 8, EGL_STENCIL_SIZE, 8,
58  EGL_NONE};
59  EGLConfig config = nullptr;
60  EGLint num_config = 0;
61  eglChooseConfig(self->display, config_attributes, &config, 1, &num_config);
62 
63  const EGLint context_attributes[] = {EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE};
64  self->render_context = eglCreateContext(self->display, config, EGL_NO_CONTEXT,
65  context_attributes);
66  self->resource_context = eglCreateContext(
67  self->display, config, self->render_context, context_attributes);
68 }

◆ 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 76 of file fl_opengl_manager.cc.

76  {
77  return eglMakeCurrent(self->display, EGL_NO_SURFACE, EGL_NO_SURFACE,
78  self->render_context) == EGL_TRUE;
79 }

Referenced by cleanup_shader(), collect_opengl_backing_store(), create_opengl_backing_store(), fl_engine_gl_make_current(), 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 81 of file fl_opengl_manager.cc.

81  {
82  return eglMakeCurrent(self->display, EGL_NO_SURFACE, EGL_NO_SURFACE,
83  self->resource_context) == EGL_TRUE;
84 }

Referenced by fl_engine_gl_make_resource_current().

◆ fl_opengl_manager_new()

FlOpenGLManager* fl_opengl_manager_new ( )

Definition at line 70 of file fl_opengl_manager.cc.

70  {
71  FlOpenGLManager* self =
72  FL_OPENGL_MANAGER(g_object_new(fl_opengl_manager_get_type(), nullptr));
73  return self;
74 }

Referenced by fl_engine_init(), and TEST().