| Flutter Linux Embedder |

fl_renderer_gdk.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_renderer_gdk.h"
6
7 struct _FlRendererGdk {
8 FlRenderer parent_instance;
9
10 // Window being rendered on.
11 GdkWindow* window;
12
13 // OpenGL rendering context used by GDK.
14 GdkGLContext* gdk_context;
15
16 // Main OpenGL rendering context used by Flutter.
17 GdkGLContext* main_context;
18
19 // Secondary OpenGL rendering context used by Flutter.
20 GdkGLContext* resource_context;
21 };
22
23 G_DEFINE_TYPE(FlRendererGdk, fl_renderer_gdk, fl_renderer_get_type())
24
25 // Implements FlRenderer::make_current.
26 static void fl_renderer_gdk_make_current(FlRenderer* renderer) {
27 FlRendererGdk* self = FL_RENDERER_GDK(renderer);
28 gdk_gl_context_make_current(self->main_context);
29 }
30
31 // Implements FlRenderer::make_resource_current.
32 static void fl_renderer_gdk_make_resource_current(FlRenderer* renderer) {
33 FlRendererGdk* self = FL_RENDERER_GDK(renderer);
34 gdk_gl_context_make_current(self->resource_context);
35 }
36
37 // Implements FlRenderer::clear_current.
38 static void fl_renderer_gdk_clear_current(FlRenderer* renderer) {
39 gdk_gl_context_clear_current();
40 }
41
42 static void fl_renderer_gdk_dispose(GObject* object) {
43 FlRendererGdk* self = FL_RENDERER_GDK(object);
44
45 g_clear_object(&self->gdk_context);
46 g_clear_object(&self->main_context);
47 g_clear_object(&self->resource_context);
48
49 G_OBJECT_CLASS(fl_renderer_gdk_parent_class)->dispose(object);
50 }
51
52 static void fl_renderer_gdk_class_init(FlRendererGdkClass* klass) {
53 G_OBJECT_CLASS(klass)->dispose = fl_renderer_gdk_dispose;
54
55 FL_RENDERER_CLASS(klass)->make_current = fl_renderer_gdk_make_current;
56 FL_RENDERER_CLASS(klass)->make_resource_current =
57 fl_renderer_gdk_make_resource_current;
58 FL_RENDERER_CLASS(klass)->clear_current = fl_renderer_gdk_clear_current;
59 }
60
61 static void fl_renderer_gdk_init(FlRendererGdk* self) {}
62
63 FlRendererGdk* fl_renderer_gdk_new(GdkWindow* window) {
64 FlRendererGdk* self =
65 FL_RENDERER_GDK(g_object_new(fl_renderer_gdk_get_type(), nullptr));
66 self->window = window;
67 return self;
68 }
69
70 gboolean fl_renderer_gdk_create_contexts(FlRendererGdk* self, GError** error) {
71 self->gdk_context = gdk_window_create_gl_context(self->window, error);
72 if (self->gdk_context == nullptr) {
73 return FALSE;
74 }
75 if (!gdk_gl_context_realize(self->gdk_context, error)) {
76 return FALSE;
77 }
78
79 self->main_context = gdk_window_create_gl_context(self->window, error);
80 if (self->main_context == nullptr) {
81 return FALSE;
82 }
83 if (!gdk_gl_context_realize(self->main_context, error)) {
84 return FALSE;
85 }
86
87 self->resource_context = gdk_window_create_gl_context(self->window, error);
88 if (self->resource_context == nullptr) {
89 return FALSE;
90 }
91 if (!gdk_gl_context_realize(self->resource_context, error)) {
92 return FALSE;
93 }
94
95 return TRUE;
96 }
97
98 GdkGLContext* fl_renderer_gdk_get_context(FlRendererGdk* self) {
99 g_return_val_if_fail(FL_IS_RENDERER_GDK(self), nullptr);
100 return self->gdk_context;
101 }
_FlRendererGdk::resource_context
GdkGLContext * resource_context
Definition: fl_renderer_gdk.cc:20
_FlRendererGdk::window
GdkWindow * window
Definition: fl_renderer_gdk.cc:11
fl_renderer_gdk_clear_current
static void fl_renderer_gdk_clear_current(FlRenderer *renderer)
Definition: fl_renderer_gdk.cc:38
fl_renderer_gdk_make_resource_current
static void fl_renderer_gdk_make_resource_current(FlRenderer *renderer)
Definition: fl_renderer_gdk.cc:32
fl_renderer_gdk_get_context
GdkGLContext * fl_renderer_gdk_get_context(FlRendererGdk *self)
Definition: fl_renderer_gdk.cc:98
fl_renderer_gdk_init
static void fl_renderer_gdk_init(FlRendererGdk *self)
Definition: fl_renderer_gdk.cc:61
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_renderer_gdk_create_contexts
gboolean fl_renderer_gdk_create_contexts(FlRendererGdk *self, GError **error)
Definition: fl_renderer_gdk.cc:70
TRUE
return TRUE
Definition: fl_pixel_buffer_texture_test.cc:53
fl_renderer_gdk_class_init
static void fl_renderer_gdk_class_init(FlRendererGdkClass *klass)
Definition: fl_renderer_gdk.cc:52
fl_renderer_gdk.h
error
const uint8_t uint32_t uint32_t GError ** error
Definition: fl_pixel_buffer_texture_test.cc:40
_FlRendererGdk::gdk_context
GdkGLContext * gdk_context
Definition: fl_renderer_gdk.cc:14
_FlRendererGdk::main_context
GdkGLContext * main_context
Definition: fl_renderer_gdk.cc:17
fl_renderer_gdk_make_current
static void fl_renderer_gdk_make_current(FlRenderer *renderer)
Definition: fl_renderer_gdk.cc:26
_FlRendererGdk
Definition: fl_renderer_gdk.cc:7
fl_renderer_gdk_dispose
static void fl_renderer_gdk_dispose(GObject *object)
Definition: fl_renderer_gdk.cc:42
_FlRendererGdk::parent_instance
FlRenderer parent_instance
Definition: fl_renderer_gdk.cc:8
fl_renderer_gdk_new
FlRendererGdk * fl_renderer_gdk_new(GdkWindow *window)
Definition: fl_renderer_gdk.cc:63