| Flutter Linux Embedder |

Classes | Functions
fl_framebuffer.cc File Reference
`#include "fl_framebuffer.h"`
`#include <epoxy/egl.h>`
`#include <epoxy/gl.h>`

Go to the source code of this file.

## Classes
struct | _FlFramebuffer

## Functions
static EGLImage | create_egl_image (GLuint texture_id)
static void | fl_framebuffer_dispose (GObject *object)
static void | fl_framebuffer_class_init (FlFramebufferClass *klass)
static void | fl_framebuffer_init (FlFramebuffer *self)
FlFramebuffer * | fl_framebuffer_new (GLint format, size_t width, size_t height, gboolean shareable)
gboolean | fl_framebuffer_get_shareable (FlFramebuffer *self)
FlFramebuffer * | fl_framebuffer_create_sibling (FlFramebuffer *self)
GLuint | fl_framebuffer_get_id (FlFramebuffer *self)
GLuint | fl_framebuffer_get_texture_id (FlFramebuffer *self)
size_t | fl_framebuffer_get_width (FlFramebuffer *self)
size_t | fl_framebuffer_get_height (FlFramebuffer *self)

## Function Documentation

## ◆ create_egl_image()

static EGLImage create_egl_image | ( | GLuint | texture_id | ) |
| static

Definition at line 34 of file fl_framebuffer.cc.

34 {
35 EGLDisplay egl_display = eglGetCurrentDisplay();
36 if (egl_display == EGL_NO_DISPLAY) {
37 g_warning("Failed to create EGL image: Failed to get current EGL display");
38 return nullptr;
39 }
40
41 EGLContext egl_context = eglGetCurrentContext();
42 if (egl_context == EGL_NO_CONTEXT) {
43 g_warning("Failed to create EGL image: Failed to get current EGL context");
44 return nullptr;
45 }
46
47 return eglCreateImage(
48 egl_display, egl_context, EGL_GL_TEXTURE_2D,
49 reinterpret_cast<EGLClientBuffer>(static_cast<intptr_t>(texture_id)),
50 nullptr);
51 }
texture_id
int64_t texture_id
Definition: texture_registrar_unittests.cc:24

References texture_id.

Referenced by fl_framebuffer_new().

## ◆ fl_framebuffer_class_init()

static void fl_framebuffer_class_init | ( | FlFramebufferClass * | klass | ) |
| static

Definition at line 63 of file fl_framebuffer.cc.

63 {
64 G_OBJECT_CLASS(klass)->dispose = fl_framebuffer_dispose;
65 }
fl_framebuffer_dispose
static void fl_framebuffer_dispose(GObject *object)
Definition: fl_framebuffer.cc:53

References fl_framebuffer_dispose().

## ◆ fl_framebuffer_create_sibling()

FlFramebuffer* fl_framebuffer_create_sibling | ( | FlFramebuffer * | framebuffer | ) |

fl_framebuffer_create_sibling: @framebuffer: an #FlFramebuffer.

Creates a new framebuffer with the same backing texture as the original. This uses EGLImage to share the texture and allows a framebuffer created in one OpenGL context to be used in another.

Returns: a new #FlFramebuffer.

Definition at line 120 of file fl_framebuffer.cc.

120 {
121 g_return_val_if_fail(FL_IS_FRAMEBUFFER(self), nullptr);
122 g_return_val_if_fail(self->image != nullptr, nullptr);
123
124 FlFramebuffer* sibling =
125 FL_FRAMEBUFFER(g_object_new(fl_framebuffer_get_type(), nullptr));
126
127 sibling->width = self->width;
128 sibling->height = self->height;
129 sibling->image = self->image;
130
131 // Make texture from existing image.
132 glGenTextures(1, &sibling->texture_id);
133 glBindTexture(GL_TEXTURE_2D, sibling->texture_id);
134 glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, self->image);
135
136 // Make framebuffer that uses this texture.
137 glGenFramebuffers(1, &sibling->framebuffer_id);
138 GLint saved_framebuffer_binding;
139 glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, &saved_framebuffer_binding);
140 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, sibling->framebuffer_id);
141 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,
142 sibling->texture_id, 0);
143 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, saved_framebuffer_binding);
144
145 return sibling;
146 }
self
g_cond_signal & self
Definition: fl_compositor_software.cc:67

References self.

Referenced by fl_compositor_opengl_render(), and TEST().

## ◆ fl_framebuffer_dispose()

static void fl_framebuffer_dispose | ( | GObject * | object | ) |
| static

Definition at line 53 of file fl_framebuffer.cc.

53 {
54 FlFramebuffer* self = FL_FRAMEBUFFER(object);
55
56 glDeleteFramebuffers(1, &self->framebuffer_id);
57 glDeleteTextures(1, &self->texture_id);
58 glDeleteRenderbuffers(1, &self->depth_stencil);
59
60 G_OBJECT_CLASS(fl_framebuffer_parent_class)->dispose(object);
61 }

References self.

Referenced by fl_framebuffer_class_init().

## ◆ fl_framebuffer_get_height()

size_t fl_framebuffer_get_height | ( | FlFramebuffer * | framebuffer | ) |

fl_framebuffer_get_height: @framebuffer: an #FlFramebuffer.

Gets the height of the framebuffer in pixels.

Returns: height in pixels.

Definition at line 160 of file fl_framebuffer.cc.

160 {
161 return self->height;
162 }

Referenced by composite_layer(), fl_compositor_opengl_present_layers(), and fl_compositor_opengl_render().

## ◆ fl_framebuffer_get_id()

GLuint fl_framebuffer_get_id | ( | FlFramebuffer * | framebuffer | ) |

fl_framebuffer_get_id: @framebuffer: an #FlFramebuffer.

Gets the ID for this framebuffer.

Returns: OpenGL framebuffer id or 0 if creation failed.

Definition at line 148 of file fl_framebuffer.cc.

148 {
149 return self->framebuffer_id;
150 }

Referenced by create_opengl_backing_store(), and fl_compositor_opengl_present_layers().

## ◆ fl_framebuffer_get_shareable()

gboolean fl_framebuffer_get_shareable | ( | FlFramebuffer * | framebuffer | ) |

fl_framebuffer_get_shareable: @framebuffer: an #FlFramebuffer.

Checks if this framebuffer can be shared between contexts (using fl_framebuffer_create_sibling).

Returns: TRUE if this framebuffer can be shared.

Definition at line 115 of file fl_framebuffer.cc.

115 {
116 g_return_val_if_fail(FL_IS_FRAMEBUFFER(self), FALSE);
117 return self->image != nullptr;
118 }

Referenced by fl_compositor_opengl_render().

## ◆ fl_framebuffer_get_texture_id()

GLuint fl_framebuffer_get_texture_id | ( | FlFramebuffer * | framebuffer | ) |

fl_framebuffer_get_texture_id: @framebuffer: an #FlFramebuffer.

Gets the ID of the texture associated with this framebuffer.

Returns: OpenGL texture id or 0 if creation failed.

Definition at line 152 of file fl_framebuffer.cc.

152 {
153 return self->texture_id;
154 }

Referenced by composite_layer(), and fl_compositor_opengl_render().

## ◆ fl_framebuffer_get_width()

size_t fl_framebuffer_get_width | ( | FlFramebuffer * | framebuffer | ) |

fl_framebuffer_get_width: @framebuffer: an #FlFramebuffer.

Gets the width of the framebuffer in pixels.

Returns: width in pixels.

Definition at line 156 of file fl_framebuffer.cc.

156 {
157 return self->width;
158 }

Referenced by composite_layer(), fl_compositor_opengl_present_layers(), and fl_compositor_opengl_render().

## ◆ fl_framebuffer_init()

static void fl_framebuffer_init | ( | FlFramebuffer * | self | ) |
| static

Definition at line 67 of file fl_framebuffer.cc.

67 {}

## ◆ fl_framebuffer_new()

FlFramebuffer* fl_framebuffer_new | ( | GLint | format,
|  | size_t | width,
|  | size_t | height,
|  | gboolean | shareable
| ) |  |

FlFramebuffer:

#FlFramebuffer creates framebuffers and their backing textures for use by the Flutter compositor. fl_framebuffer_new: @format: format, e.g. GL_RGB, GL_BGR @width: width of texture. @height: height of texture. @shareable: TRUE if this framebuffer can be shared between contexts (requires EGL).

Creates a new frame buffer. Requires a valid OpenGL context to create.

Returns: a new #FlFramebuffer.

Definition at line 69 of file fl_framebuffer.cc.

72 {
73 FlFramebuffer* self =
74 FL_FRAMEBUFFER(g_object_new(fl_framebuffer_get_type(), nullptr));
75
76 self->width = width;
77 self->height = height;
78
79 glGenTextures(1, &self->texture_id);
80 glGenFramebuffers(1, &self->framebuffer_id);
81
82 glBindFramebuffer(GL_FRAMEBUFFER, self->framebuffer_id);
83
84 glBindTexture(GL_TEXTURE_2D, self->texture_id);
85 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
86 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
87 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
88 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
89 glTexImage2D(GL_TEXTURE_2D, 0, format, width, height, 0, format,
90 GL_UNSIGNED_BYTE, NULL);
91 glBindTexture(GL_TEXTURE_2D, 0);
92
93 if (shareable) {
94 self->image = create_egl_image(self->texture_id);
95 }
96
97 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,
98 self->texture_id, 0);
99
100 glGenRenderbuffers(1, &self->depth_stencil);
101 glBindRenderbuffer(GL_RENDERBUFFER, self->depth_stencil);
102 glRenderbufferStorage(GL_RENDERBUFFER, // target
103 GL_DEPTH24_STENCIL8, // internal format
104 width, // width
105 height // height
106 );
107 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT,
108 GL_RENDERBUFFER, self->depth_stencil);
109 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT,
110 GL_RENDERBUFFER, self->depth_stencil);
111
112 return self;
113 }
shareable
G_BEGIN_DECLS gboolean shareable
Definition: fl_compositor_opengl.h:40
height
self height
Definition: fl_compositor_software.cc:43
width
self width
Definition: fl_compositor_software.cc:42
create_egl_image
static EGLImage create_egl_image(GLuint texture_id)
Definition: fl_framebuffer.cc:34
format
uint32_t uint32_t * format
Definition: fl_texture_registrar_test.cc:42

References create_egl_image(), format, height, self, shareable, and width.

Referenced by create_opengl_backing_store(), fl_compositor_opengl_present_layers(), and TEST().