| 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 "flutter/shell/platform/linux/fl_opengl_manager.h"
6
7 struct _FlOpenGLManager {
8 GObject parent_instance;
9
10 // OpenGL rendering context used by GDK.
11 GdkGLContext* gdk_context;
12
13 // Main OpenGL rendering context used by Flutter.
14 GdkGLContext* main_context;
15
16 // OpenGL rendering context used by a Flutter background thread for
17 // asynchronous texture uploads.
18 GdkGLContext* resource_context;
19 };
20
21 G_DEFINE_TYPE(FlOpenGLManager, fl_opengl_manager, G_TYPE_OBJECT)
22
23 static void fl_opengl_manager_dispose(GObject* object) {
24 FlOpenGLManager* self = FL_OPENGL_MANAGER(object);
25
26 g_clear_object(&self->gdk_context);
27 g_clear_object(&self->main_context);
28 g_clear_object(&self->resource_context);
29
30 G_OBJECT_CLASS(fl_opengl_manager_parent_class)->dispose(object);
31 }
32
33 static void fl_opengl_manager_class_init(FlOpenGLManagerClass* klass) {
34 G_OBJECT_CLASS(klass)->dispose = fl_opengl_manager_dispose;
35 }
36
37 static void fl_opengl_manager_init(FlOpenGLManager* self) {}
38
39 FlOpenGLManager* fl_opengl_manager_new() {
40 FlOpenGLManager* self =
41 FL_OPENGL_MANAGER(g_object_new(fl_opengl_manager_get_type(), nullptr));
42 return self;
43 }
44
45 gboolean fl_opengl_manager_create_contexts(FlOpenGLManager* self,
46 GdkWindow* window,
47 GError** error) {
48 g_return_val_if_fail(FL_IS_OPENGL_MANAGER(self), FALSE);
49
50 self->gdk_context = gdk_window_create_gl_context(window, error);
51 if (self->gdk_context == nullptr) {
52 return FALSE;
53 }
54 if (!gdk_gl_context_realize(self->gdk_context, error)) {
55 return FALSE;
56 }
57
58 self->main_context = gdk_window_create_gl_context(window, error);
59 if (self->main_context == nullptr) {
60 return FALSE;
61 }
62 if (!gdk_gl_context_realize(self->main_context, error)) {
63 return FALSE;
64 }
65
66 self->resource_context = gdk_window_create_gl_context(window, error);
67 if (self->resource_context == nullptr) {
68 return FALSE;
69 }
70 if (!gdk_gl_context_realize(self->resource_context, error)) {
71 return FALSE;
72 }
73
74 return TRUE;
75 }
76
77 GdkGLContext* fl_opengl_manager_get_context(FlOpenGLManager* self) {
78 g_return_val_if_fail(FL_IS_OPENGL_MANAGER(self), nullptr);
79 return self->gdk_context;
80 }
81
82 void fl_opengl_manager_make_current(FlOpenGLManager* self) {
83 gdk_gl_context_make_current(self->main_context);
84 }
85
86 void fl_opengl_manager_make_resource_current(FlOpenGLManager* self) {
87 gdk_gl_context_make_current(self->resource_context);
88 }
89
90 void fl_opengl_manager_clear_current(FlOpenGLManager* self) {
91 gdk_gl_context_clear_current();
92 }
window
return window
Definition: fl_application.cc:41
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
fl_opengl_manager_dispose
static void fl_opengl_manager_dispose(GObject *object)
Definition: fl_opengl_manager.cc:23
fl_opengl_manager_clear_current
void fl_opengl_manager_clear_current(FlOpenGLManager *self)
Definition: fl_opengl_manager.cc:90
fl_opengl_manager_class_init
static void fl_opengl_manager_class_init(FlOpenGLManagerClass *klass)
Definition: fl_opengl_manager.cc:33
fl_opengl_manager_new
FlOpenGLManager * fl_opengl_manager_new()
Definition: fl_opengl_manager.cc:39
fl_opengl_manager_create_contexts
gboolean fl_opengl_manager_create_contexts(FlOpenGLManager *self, GdkWindow *window, GError **error)
Definition: fl_opengl_manager.cc:45
fl_opengl_manager_make_current
void fl_opengl_manager_make_current(FlOpenGLManager *self)
Definition: fl_opengl_manager.cc:82
fl_opengl_manager_get_context
GdkGLContext * fl_opengl_manager_get_context(FlOpenGLManager *self)
Definition: fl_opengl_manager.cc:77
fl_opengl_manager_make_resource_current
void fl_opengl_manager_make_resource_current(FlOpenGLManager *self)
Definition: fl_opengl_manager.cc:86
fl_opengl_manager_init
static void fl_opengl_manager_init(FlOpenGLManager *self)
Definition: fl_opengl_manager.cc:37
fl_opengl_manager.h
TRUE
return TRUE
Definition: fl_pixel_buffer_texture_test.cc:53
error
const uint8_t uint32_t uint32_t GError ** error
Definition: fl_pixel_buffer_texture_test.cc:40
_FlOpenGLManager
Definition: fl_opengl_manager.cc:7
_FlOpenGLManager::resource_context
GdkGLContext * resource_context
Definition: fl_opengl_manager.cc:18
_FlOpenGLManager::main_context
GdkGLContext * main_context
Definition: fl_opengl_manager.cc:14
_FlOpenGLManager::gdk_context
GdkGLContext * gdk_context
Definition: fl_opengl_manager.cc:11
_FlOpenGLManager::parent_instance
GObject parent_instance
Definition: fl_opengl_manager.cc:8