opt: hardware accleration texture on Linux
This commit is contained in:
parent
91b1c10758
commit
3d549cb70b
14 changed files with 91 additions and 70 deletions
|
|
@ -3,48 +3,70 @@
|
|||
|
||||
#include <flutter_linux/flutter_linux.h>
|
||||
#include <gtk/gtk.h>
|
||||
#include <epoxy/gl.h>
|
||||
|
||||
#include "texture_rgba_renderer_plugin.h"
|
||||
|
||||
struct _TextureRgbaClass {
|
||||
FlPixelBufferTextureClass parent_class;
|
||||
struct _TextureRgbaClass
|
||||
{
|
||||
FlTextureGLClass parent_class;
|
||||
};
|
||||
|
||||
struct TextureRgbaPrivate
|
||||
{
|
||||
int64_t texture_id = 0;
|
||||
uint8_t* buffer = nullptr;
|
||||
GLuint texture_id = 0;
|
||||
uint8_t *buffer = nullptr;
|
||||
int32_t video_width = 0;
|
||||
int32_t video_height = 0;
|
||||
};
|
||||
|
||||
/// Constructor.
|
||||
G_DECLARE_DERIVABLE_TYPE(TextureRgba, texture_rgba, TEXTURE_RGBA_RENDERER, TEXTURE_RGBA, FlPixelBufferTexture)
|
||||
G_DECLARE_DERIVABLE_TYPE(TextureRgba, texture_rgba, TEXTURE_RGBA_RENDERER, TEXTURE_RGBA, FlTextureGL)
|
||||
/// Add private data.
|
||||
G_DEFINE_TYPE_WITH_CODE(TextureRgba, texture_rgba,
|
||||
fl_pixel_buffer_texture_get_type(),
|
||||
fl_texture_gl_get_type(),
|
||||
G_ADD_PRIVATE(TextureRgba))
|
||||
|
||||
static gboolean texture_rgba_populate(FlTextureGL *texture,
|
||||
uint32_t *target,
|
||||
uint32_t *name,
|
||||
uint32_t *width,
|
||||
uint32_t *height,
|
||||
GError **error)
|
||||
{
|
||||
TextureRgbaPrivate *self = (TextureRgbaPrivate *)
|
||||
texture_rgba_get_instance_private(TEXTURE_RGBA_RENDERER_TEXTURE_RGBA(texture));
|
||||
if (self->texture_id == 0)
|
||||
{
|
||||
glGenTextures(1, &self->texture_id);
|
||||
glBindTexture(GL_TEXTURE_2D, self->texture_id);
|
||||
// further configuration here.
|
||||
}
|
||||
else
|
||||
{
|
||||
glBindTexture(GL_TEXTURE_2D, self->texture_id);
|
||||
}
|
||||
// For example, we render pixel buffer here.
|
||||
// Note that Flutter only accepts textures in GL_RGBA8 format.
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, self->video_width, self->video_height, 0, GL_RGBA,
|
||||
GL_UNSIGNED_BYTE, self->buffer);
|
||||
|
||||
*target = GL_TEXTURE_2D;
|
||||
*name = self->texture_id;
|
||||
*width = self->video_width;
|
||||
*height = self->video_height;
|
||||
|
||||
static gboolean texture_rgba_copy_pixels(FlPixelBufferTexture* texture,
|
||||
const uint8_t** out_buffer,
|
||||
uint32_t* width, uint32_t* height,
|
||||
GError** error) {
|
||||
auto texture_rgba_private =
|
||||
(TextureRgbaPrivate*)texture_rgba_get_instance_private(
|
||||
TEXTURE_RGBA_RENDERER_TEXTURE_RGBA(texture));
|
||||
*out_buffer = texture_rgba_private->buffer;
|
||||
*width = texture_rgba_private->video_width;
|
||||
*height = texture_rgba_private->video_height;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static TextureRgba* texture_rgba_new() {
|
||||
static TextureRgba *texture_rgba_new()
|
||||
{
|
||||
return TEXTURE_RGBA_RENDERER_TEXTURE_RGBA(g_object_new(texture_rgba_get_type(), nullptr));
|
||||
}
|
||||
|
||||
static void texture_rgba_class_init(TextureRgbaClass* klass) {
|
||||
FL_PIXEL_BUFFER_TEXTURE_CLASS(klass)->copy_pixels = texture_rgba_copy_pixels;
|
||||
static void texture_rgba_class_init(TextureRgbaClass *klass)
|
||||
{
|
||||
FL_TEXTURE_GL_GET_CLASS(klass)->populate = texture_rgba_populate;
|
||||
}
|
||||
|
||||
static void texture_rgba_init(TextureRgba* self) {}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue