This repository was archived by the owner on Feb 25, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6k
Linux texture support #20714
Closed
Closed
Linux texture support #20714
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
05b183d
Linux texture support
anirudhb 1b77228
Fix clang-tidy errors
anirudhb 013cd2a
Tests (partial)
anirudhb 612995a
Fix nits, finish tests
anirudhb 8a007ba
Change texture_id back to before
anirudhb 051333b
Update golden licenses with new files
anirudhb e2e365f
Oops
anirudhb db16569
Fix nits
anirudhb File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
// Copyright 2013 The Flutter Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "flutter/shell/platform/linux/fl_external_texture_gl.h" | ||
|
||
#include <EGL/egl.h> | ||
#include <GL/gl.h> | ||
#include <gmodule.h> | ||
|
||
typedef struct { | ||
bool valid; | ||
void (*genTextures)(GLsizei n, GLuint* textures); | ||
void (*bindTexture)(GLenum target, GLuint texture); | ||
void (*texParameteri)(GLenum target, GLenum pname, GLenum param); | ||
void (*texImage2D)(GLenum target, | ||
GLint level, | ||
GLint internalformat, | ||
GLsizei width, | ||
GLsizei height, | ||
GLint border, | ||
GLenum format, | ||
GLenum type, | ||
const void* data); | ||
void (*deleteTextures)(GLsizei n, const GLuint* textures); | ||
} glFuncs; | ||
|
||
static glFuncs* load_gl_funcs() { | ||
static glFuncs funcs; | ||
if (!funcs.valid) { | ||
funcs.genTextures = reinterpret_cast<void (*)(GLsizei, GLuint*)>( | ||
eglGetProcAddress("glGenTextures")); | ||
funcs.bindTexture = reinterpret_cast<void (*)(GLenum, GLuint)>( | ||
eglGetProcAddress("glBindTexture")); | ||
funcs.texParameteri = reinterpret_cast<void (*)(GLenum, GLenum, GLenum)>( | ||
eglGetProcAddress("glTexParameteri")); | ||
funcs.texImage2D = | ||
reinterpret_cast<void (*)(GLenum, GLint, GLint, GLsizei, GLsizei, GLint, | ||
GLenum, GLenum, const void*)>( | ||
eglGetProcAddress("glTexImage2D")); | ||
funcs.deleteTextures = reinterpret_cast<void (*)(GLsizei, const GLuint*)>( | ||
eglGetProcAddress("glDeleteTextures")); | ||
funcs.valid = true; | ||
} | ||
return &funcs; | ||
} | ||
|
||
struct _FlExternalTextureGl { | ||
GObject parent_instance; | ||
GLuint gl_texture_id; | ||
anirudhb marked this conversation as resolved.
Show resolved
Hide resolved
|
||
FlTextureCallback callback; | ||
void* user_data; | ||
}; | ||
|
||
G_DEFINE_TYPE(FlExternalTextureGl, fl_external_texture_gl, G_TYPE_OBJECT) | ||
|
||
static void fl_external_texture_gl_dispose(GObject* object) { | ||
FlExternalTextureGl* self = FL_EXTERNAL_TEXTURE_GL(object); | ||
glFuncs* gl = load_gl_funcs(); | ||
gl->deleteTextures(1, &self->gl_texture_id); | ||
|
||
G_OBJECT_CLASS(fl_external_texture_gl_parent_class)->dispose(object); | ||
} | ||
|
||
static void fl_external_texture_gl_class_init(FlExternalTextureGlClass* klass) { | ||
G_OBJECT_CLASS(klass)->dispose = fl_external_texture_gl_dispose; | ||
} | ||
|
||
static void fl_external_texture_gl_init(FlExternalTextureGl* self) {} | ||
|
||
int64_t fl_external_texture_gl_texture_id(FlExternalTextureGl* self) { | ||
g_return_val_if_fail(FL_IS_EXTERNAL_TEXTURE_GL(self), -1); | ||
return reinterpret_cast<int64_t>(self); | ||
robert-ancell marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
gboolean fl_external_texture_gl_populate_texture( | ||
FlExternalTextureGl* self, | ||
size_t width, | ||
size_t height, | ||
FlutterOpenGLTexture* opengl_texture) { | ||
anirudhb marked this conversation as resolved.
Show resolved
Hide resolved
|
||
g_return_val_if_fail(FL_IS_EXTERNAL_TEXTURE_GL(self), FALSE); | ||
|
||
size_t real_width = width, real_height = height; | ||
if (!fl_external_texture_gl_copy_pixel_buffer(self, &real_width, | ||
&real_height)) { | ||
return false; | ||
} | ||
|
||
opengl_texture->target = GL_TEXTURE_2D; | ||
opengl_texture->name = self->gl_texture_id; | ||
opengl_texture->format = GL_RGBA8; | ||
opengl_texture->destruction_callback = nullptr; | ||
opengl_texture->user_data = nullptr; | ||
opengl_texture->width = real_width; | ||
opengl_texture->height = real_height; | ||
|
||
return TRUE; | ||
} | ||
|
||
gboolean fl_external_texture_gl_copy_pixel_buffer(FlExternalTextureGl* self, | ||
size_t* width, | ||
size_t* height) { | ||
g_return_val_if_fail(FL_IS_EXTERNAL_TEXTURE_GL(self), FALSE); | ||
|
||
const uint8_t* buffer; | ||
if (self->callback(width, height, &buffer, self->user_data) != TRUE) { | ||
return FALSE; | ||
} | ||
|
||
glFuncs* gl = load_gl_funcs(); | ||
if (self->gl_texture_id == 0) { | ||
gl->genTextures(1, &self->gl_texture_id); | ||
gl->bindTexture(GL_TEXTURE_2D, self->gl_texture_id); | ||
gl->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER); | ||
gl->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER); | ||
gl->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); | ||
gl->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); | ||
} else { | ||
gl->bindTexture(GL_TEXTURE_2D, self->gl_texture_id); | ||
} | ||
gl->texImage2D(GL_TEXTURE_2D, 0, GL_RGBA, *width, *height, 0, GL_RGBA, | ||
GL_UNSIGNED_BYTE, buffer); | ||
return TRUE; | ||
} | ||
|
||
FlExternalTextureGl* fl_external_texture_gl_new( | ||
FlTextureCallback texture_callback, | ||
void* user_data) { | ||
FlExternalTextureGl* self = FL_EXTERNAL_TEXTURE_GL( | ||
g_object_new(fl_external_texture_gl_get_type(), nullptr)); | ||
|
||
self->callback = texture_callback; | ||
self->user_data = user_data; | ||
|
||
return self; | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.