| Flutter Linux Embedder |

fl_opengl_manager.cc
Go to the documentation of this file.
1 // Copyright 2013 The Flutter Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include <epoxy/egl.h>
6 #include <gdk/gdkwayland.h>
7 #include <gdk/gdkx.h>
8
9 #include "flutter/shell/platform/linux/fl_opengl_manager.h"
10
11 struct _FlOpenGLManager {
12 GObject parent_instance;
13
14 // Display being rendered to.
15 EGLDisplay display;
16
17 // Context used by Flutter to render.
18 EGLContext render_context;
19
20 // Context used by Flutter to share resources.
21 EGLContext resource_context;
22 };
23
24 G_DEFINE_TYPE(FlOpenGLManager, fl_opengl_manager, G_TYPE_OBJECT)
25
26 static void fl_opengl_manager_dispose(GObject* object) {
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 }
35
36 static void fl_opengl_manager_class_init(FlOpenGLManagerClass* klass) {
37 G_OBJECT_CLASS(klass)->dispose = fl_opengl_manager_dispose;
38 }
39
40 static void fl_opengl_manager_init(FlOpenGLManager* self) {
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 }
69
70 FlOpenGLManager* fl_opengl_manager_new() {
71 FlOpenGLManager* self =
72 FL_OPENGL_MANAGER(g_object_new(fl_opengl_manager_get_type(), nullptr));
73 return self;
74 }
75
76 void fl_opengl_manager_make_current(FlOpenGLManager* self) {
77 eglMakeCurrent(self->display, EGL_NO_SURFACE, EGL_NO_SURFACE,
78 self->render_context);
79 }
80
81 void fl_opengl_manager_make_resource_current(FlOpenGLManager* self) {
82 eglMakeCurrent(self->display, EGL_NO_SURFACE, EGL_NO_SURFACE,
83 self->resource_context);
84 }
85
86 void fl_opengl_manager_clear_current(FlOpenGLManager* self) {
87 eglMakeCurrent(self->display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
88 }
G_DEFINE_TYPE
G_DEFINE_TYPE(FlBasicMessageChannelResponseHandle, fl_basic_message_channel_response_handle, G_TYPE_OBJECT) static void fl_basic_message_channel_response_handle_dispose(GObject *object)
Definition: fl_basic_message_channel.cc:37
self
g_cond_signal & self
Definition: fl_compositor_software.cc:67
fl_opengl_manager_dispose
static void fl_opengl_manager_dispose(GObject *object)
Definition: fl_opengl_manager.cc:26
fl_opengl_manager_clear_current
void fl_opengl_manager_clear_current(FlOpenGLManager *self)
Definition: fl_opengl_manager.cc:86
fl_opengl_manager_class_init
static void fl_opengl_manager_class_init(FlOpenGLManagerClass *klass)
Definition: fl_opengl_manager.cc:36
fl_opengl_manager_new
FlOpenGLManager * fl_opengl_manager_new()
Definition: fl_opengl_manager.cc:70
fl_opengl_manager_make_current
void fl_opengl_manager_make_current(FlOpenGLManager *self)
Definition: fl_opengl_manager.cc:76
fl_opengl_manager_make_resource_current
void fl_opengl_manager_make_resource_current(FlOpenGLManager *self)
Definition: fl_opengl_manager.cc:81
fl_opengl_manager_init
static void fl_opengl_manager_init(FlOpenGLManager *self)
Definition: fl_opengl_manager.cc:40
fl_opengl_manager.h
_FlOpenGLManager
Definition: fl_opengl_manager.cc:11
_FlOpenGLManager::resource_context
EGLContext resource_context
Definition: fl_opengl_manager.cc:21
_FlOpenGLManager::display
EGLDisplay display
Definition: fl_opengl_manager.cc:15
_FlOpenGLManager::render_context
EGLContext render_context
Definition: fl_opengl_manager.cc:18
_FlOpenGLManager::parent_instance
GObject parent_instance
Definition: fl_opengl_manager.cc:12