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