Flutter Linux Embedder
fl_texture_gl.h
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 #ifndef FLUTTER_SHELL_PLATFORM_LINUX_PUBLIC_FLUTTER_LINUX_FL_TEXTURE_GL_H_
6 #define FLUTTER_SHELL_PLATFORM_LINUX_PUBLIC_FLUTTER_LINUX_FL_TEXTURE_GL_H_
7 
8 #if !defined(__FLUTTER_LINUX_INSIDE__) && !defined(FLUTTER_LINUX_COMPILATION)
9 #error "Only <flutter_linux/flutter_linux.h> can be included directly."
10 #endif
11 
12 #include <glib-object.h>
13 #include <gmodule.h>
14 #include <stdint.h>
15 #include "fl_texture.h"
16 
17 G_BEGIN_DECLS
18 
19 G_MODULE_EXPORT
20 G_DECLARE_DERIVABLE_TYPE(FlTextureGL, fl_texture_gl, FL, TEXTURE_GL, GObject)
21 
22 /**
23  * FlTextureGL:
24  *
25  * #FlTextureGL is an abstract class that represents an OpenGL texture.
26  *
27  * If you want to render textures in other OpenGL context, create and use the
28  * #GdkGLContext by calling gdk_window_create_gl_context () with the #GdkWindow
29  * of #FlView. The context will be shared with the one used by Flutter.
30  *
31  * The following example shows how to implement an #FlTextureGL.
32  * ![<!-- language="C" -->
33  * #include <epoxy/gl.h>
34  *
35  * struct _MyTextureGL {
36  * FlTextureGL parent_instance;
37  *
38  * GLuint texture_id;
39  * };
40  *
41  * G_DEFINE_TYPE(MyTextureGL,
42  * my_texture_gl,
43  * fl_texture_gl_get_type ())
44  *
45  * static gboolean
46  * my_texture_gl_populate (FlTextureGL *texture,
47  * uint32_t *target,
48  * uint32_t *name,
49  * uint32_t *width,
50  * uint32_t *height,
51  * GError **error) {
52  * MyTextureGL *self = MY_TEXTURE_GL (texture);
53  * if (self->texture_id == 0) {
54  * glGenTextures (1, &self->texture_id);
55  * glBindTexture (GL_TEXTURE_2D, self->texture_id);
56  * // further configuration here.
57  * } else {
58  * glBindTexture (GL_TEXTURE_2D, self->texture_id);
59  * }
60  *
61  * // For example, we render pixel buffer here.
62  * // Note that Flutter only accepts textures in GL_RGBA8 format.
63  * static char buffer[] = { 0x1f, 0x2f, 0x3f, 0x4f }; // 1x1 pixel.
64  * glTexImage2D (GL_TEXTURE_2D, 0, GL_RGBA8, 1, 1, 0, GL_RGBA,
65  * GL_UNSIGNED_BYTE, buffer);
66  *
67  * *target = GL_TEXTURE_2D;
68  * *name = self->texture_id;
69  * *width = 1;
70  * *height = 1;
71  *
72  * return TRUE;
73  * }
74  *
75  * static void my_texture_class_init(MyTextureClass* klass) {
76  * FL_TEXTURE_GL_CLASS(klass)->populate = my_texture_gl_populate;
77  * }
78  *
79  * static void my_texture_init(MyTexture* self) {}
80  * ]|
81  */
82 
84  GObjectClass parent_class;
85 
86  /**
87  * Virtual method called when Flutter populates this texture. The OpenGL
88  * context used by Flutter has been already set.
89  * @texture: an #FlTexture.
90  * @target: texture target (example GL_TEXTURE_2D or GL_TEXTURE_RECTANGLE).
91  * @name: (out): name of texture.
92  * @width: (inout): width of the texture in pixels.
93  * @height: (inout): height of the texture in pixels.
94  * @error: (allow-none): #GError location to store the error occurring, or
95  * %NULL to ignore.
96  *
97  * Returns: %TRUE on success.
98  */
99  gboolean (*populate)(FlTextureGL* texture,
100  uint32_t* target,
101  uint32_t* name,
102  uint32_t* width,
103  uint32_t* height,
104  GError** error);
105 };
106 
107 G_END_DECLS
108 
109 #endif // FLUTTER_SHELL_PLATFORM_LINUX_PUBLIC_FLUTTER_LINUX_FL_TEXTURE_GL_H_
G_DECLARE_DERIVABLE_TYPE
G_DECLARE_DERIVABLE_TYPE(FlAccessibleNode, fl_accessible_node, FL, ACCESSIBLE_NODE, AtkObject)
_FlTextureGLClass
Definition: fl_texture_gl.h:83
_FlTextureGLClass::parent_class
GObjectClass parent_class
Definition: fl_texture_gl.h:84
height
G_BEGIN_DECLS int height
Definition: fl_backing_store_provider.h:37
FL
FL
Definition: fl_binary_messenger.cc:27
error
const uint8_t uint32_t uint32_t GError ** error
Definition: fl_pixel_buffer_texture_test.cc:40
target
uint32_t * target
Definition: fl_texture_registrar_test.cc:40
fl_texture.h
width
const uint8_t uint32_t * width
Definition: fl_pixel_buffer_texture_test.cc:38