Flutter Linux Embedder
fl_framebuffer.h File Reference
#include <epoxy/gl.h>
#include <glib-object.h>

Go to the source code of this file.

Functions

G_BEGIN_DECLS FlFramebuffer * fl_framebuffer_new (GLint format, size_t width, size_t height, gboolean shareable)
 
gboolean fl_framebuffer_get_shareable (FlFramebuffer *framebuffer)
 
FlFramebuffer * fl_framebuffer_create_sibling (FlFramebuffer *framebuffer)
 
GLuint fl_framebuffer_get_id (FlFramebuffer *framebuffer)
 
GLuint fl_framebuffer_get_texture_id (FlFramebuffer *framebuffer)
 
size_t fl_framebuffer_get_width (FlFramebuffer *framebuffer)
 
size_t fl_framebuffer_get_height (FlFramebuffer *framebuffer)
 

Function Documentation

◆ 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 104 of file fl_framebuffer.cc.

104  {
105  g_return_val_if_fail(FL_IS_FRAMEBUFFER(self), nullptr);
106  g_return_val_if_fail(self->image != nullptr, nullptr);
107 
108  FlFramebuffer* sibling =
109  FL_FRAMEBUFFER(g_object_new(fl_framebuffer_get_type(), nullptr));
110 
111  sibling->width = self->width;
112  sibling->height = self->height;
113  sibling->image = FL_EGL_IMAGE(g_object_ref(self->image));
114 
115  // Make texture from existing image.
116  glGenTextures(1, &sibling->texture_id);
117  glBindTexture(GL_TEXTURE_2D, sibling->texture_id);
118  glEGLImageTargetTexture2DOES(GL_TEXTURE_2D,
119  fl_egl_image_get_image(self->image));
120 
121  // Make framebuffer that uses this texture.
122  glGenFramebuffers(1, &sibling->framebuffer_id);
123  GLint saved_framebuffer_binding;
124  glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, &saved_framebuffer_binding);
125  glBindFramebuffer(GL_DRAW_FRAMEBUFFER, sibling->framebuffer_id);
126  glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,
127  sibling->texture_id, 0);
128  glBindFramebuffer(GL_DRAW_FRAMEBUFFER, saved_framebuffer_binding);
129 
130  return sibling;
131 }
EGLImage fl_egl_image_get_image(FlEGLImage *image)
Definition: fl_egl_image.cc:68

References fl_egl_image_get_image().

Referenced by fl_compositor_opengl_render(), and TEST().

◆ 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 145 of file fl_framebuffer.cc.

145  {
146  return self->height;
147 }

Referenced by composite_layer(), fl_compositor_opengl_get_frame_size(), 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 133 of file fl_framebuffer.cc.

133  {
134  return self->framebuffer_id;
135 }

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 99 of file fl_framebuffer.cc.

99  {
100  g_return_val_if_fail(FL_IS_FRAMEBUFFER(self), FALSE);
101  return self->image != nullptr;
102 }

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 137 of file fl_framebuffer.cc.

137  {
138  return self->texture_id;
139 }

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 141 of file fl_framebuffer.cc.

141  {
142  return self->width;
143 }

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

◆ fl_framebuffer_new()

G_BEGIN_DECLS 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 53 of file fl_framebuffer.cc.

56  {
57  FlFramebuffer* self =
58  FL_FRAMEBUFFER(g_object_new(fl_framebuffer_get_type(), nullptr));
59 
60  self->width = width;
61  self->height = height;
62 
63  glGenTextures(1, &self->texture_id);
64  glGenFramebuffers(1, &self->framebuffer_id);
65 
66  glBindFramebuffer(GL_FRAMEBUFFER, self->framebuffer_id);
67 
68  glBindTexture(GL_TEXTURE_2D, self->texture_id);
69  glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
70  glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
71  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
72  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
73  glTexImage2D(GL_TEXTURE_2D, 0, format, width, height, 0, format,
74  GL_UNSIGNED_BYTE, NULL);
75  glBindTexture(GL_TEXTURE_2D, 0);
76 
77  if (shareable) {
78  self->image = fl_egl_image_new(self->texture_id);
79  }
80 
81  glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,
82  self->texture_id, 0);
83 
84  glGenRenderbuffers(1, &self->depth_stencil);
85  glBindRenderbuffer(GL_RENDERBUFFER, self->depth_stencil);
86  glRenderbufferStorage(GL_RENDERBUFFER, // target
87  GL_DEPTH24_STENCIL8, // internal format
88  width, // width
89  height // height
90  );
91  glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT,
92  GL_RENDERBUFFER, self->depth_stencil);
93  glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT,
94  GL_RENDERBUFFER, self->depth_stencil);
95 
96  return self;
97 }
G_BEGIN_DECLS FlOpenGLManager gboolean shareable
self height
self width
FlEGLImage * fl_egl_image_new(GLuint texture)
Definition: fl_egl_image.cc:59
uint32_t uint32_t * format

References fl_egl_image_new(), format, height, shareable, and width.

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