| Flutter Linux Embedder |

fl_pixel_buffer_texture.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_PIXEL_BUFFER_TEXTURE_H_
6 #define FLUTTER_SHELL_PLATFORM_LINUX_PUBLIC_FLUTTER_LINUX_FL_PIXEL_BUFFER_TEXTURE_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 <gmodule.h>
13
14 #include "fl_texture.h"
15
16 G_BEGIN_DECLS
17
18 G_MODULE_EXPORT
19 G_DECLARE_DERIVABLE_TYPE(FlPixelBufferTexture,
20 fl_pixel_buffer_texture,
21 FL,
22 PIXEL_BUFFER_TEXTURE,
23 GObject)
24
25 /**
26 * FlPixelBufferTexture:
27 *
28 * #FlPixelBufferTexture represents an OpenGL texture generated from a pixel
29 * buffer.
30 *
31 * The following example shows how to implement an #FlPixelBufferTexture.
32 * ![<!-- language="C" -->
33 * struct _MyTexture {
34 * FlPixelBufferTexture parent_instance;
35 *
36 * uint8_t *buffer; // your pixel buffer.
37 * }
38 *
39 * G_DEFINE_TYPE(MyTexture,
40 * my_texture,
41 * fl_pixel_buffer_texture_get_type ())
42 *
43 * static gboolean
44 * my_texture_copy_pixels (FlPixelBufferTexture* texture,
45 * const uint8_t** out_buffer,
46 * uint32_t* width,
47 * uint32_t* height,
48 * GError** error) {
49 * // This method is called on Render Thread. Be careful with your
50 * // cross-thread operation.
51 *
52 * // @width and @height are initially stored the canvas size in Flutter.
53 *
54 * // You must prepare your pixel buffer in RGBA format.
55 * // So you may do some format conversion first if your original pixel
56 * // buffer is not in RGBA format.
57 * manage_your_pixel_buffer_here ();
58 *
59 * if (your_operations_are_successfully_finished) {
60 * // Directly return pointer to your pixel buffer here.
61 * // Flutter takes content of your pixel buffer after this function
62 * // is finished. So you must make the buffer live long enough until
63 * // next tick of Render Thread.
64 * // If it is hard to manage lifetime of your pixel buffer, you should
65 * // take look into #FlTextureGL.
66 *
67 * *out_buffer = buffer;
68 * *width = real_width_of_buffer;
69 * *height = real_height_of_buffer;
70 * return TRUE;
71 * } else {
72 * // set @error to report failure.
73 * return FALSE;
74 * }
75 * }
76 *
77 * static void my_texture_class_init(MyTextureClass* klass) {
78 * FL_PIXEL_BUFFER_TEXTURE_CLASS(klass)->copy_pixels =
79 * my_texture_copy_pixels;
80 * }
81 *
82 * static void my_texture_init(MyTexture* self) {}
83 * ]|
84 */
85
86 struct _FlPixelBufferTextureClass {
87 GObjectClass parent_class;
88
89 /**
90 * FlPixelBufferTexture::copy_pixels:
91 * @texture: an #FlPixelBufferTexture.
92 * @buffer: (out): pixel data.
93 * @width: (inout): width of the texture in pixels.
94 * @height: (inout): height of the texture in pixels.
95 * @error: (allow-none): #GError location to store the error occurring, or
96 * %NULL to ignore.
97 *
98 * Retrieve pixel buffer in RGBA format.
99 *
100 * As this method is usually invoked from the render thread, you must
101 * take care of proper synchronization. It also needs to be ensured that
102 * the returned buffer is not released prior to unregistering this texture.
103 *
104 * Returns: %TRUE on success.
105 */
106 gboolean (*copy_pixels)(FlPixelBufferTexture* texture,
107 const uint8_t** buffer,
108 uint32_t* width,
109 uint32_t* height,
110 GError** error);
111 };
112
113 G_END_DECLS
114
115 #endif // FLUTTER_SHELL_PLATFORM_LINUX_PUBLIC_FLUTTER_LINUX_FL_PIXEL_BUFFER_TEXTURE_H_
FL
FL
Definition: fl_binary_messenger.cc:27
height
self height
Definition: fl_compositor_software.cc:43
width
self width
Definition: fl_compositor_software.cc:42
G_DECLARE_DERIVABLE_TYPE
G_BEGIN_DECLS G_MODULE_EXPORT G_DECLARE_DERIVABLE_TYPE(FlPixelBufferTexture, fl_pixel_buffer_texture, FL, PIXEL_BUFFER_TEXTURE, GObject) struct _FlPixelBufferTextureClass
Definition: fl_pixel_buffer_texture.h:19
buffer
static const uint8_t buffer[]
Definition: fl_pixel_buffer_texture_test.cc:44
error
const uint8_t uint32_t uint32_t GError ** error
Definition: fl_pixel_buffer_texture_test.cc:40
fl_texture.h