Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Make fl_compositor_setup a vfunc
  • Loading branch information
robert-ancell committed Apr 2, 2025
commit 5f94d825c8e516230535b4921e0ddd7e36abaad0
5 changes: 5 additions & 0 deletions engine/src/flutter/shell/platform/linux/fl_compositor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ FlutterRendererType fl_compositor_get_renderer_type(FlCompositor* self) {
return FL_COMPOSITOR_GET_CLASS(self)->get_renderer_type(self);
}

void fl_compositor_setup(FlCompositor* self) {
g_return_if_fail(FL_IS_COMPOSITOR(self));
FL_COMPOSITOR_GET_CLASS(self)->setup(self);
}

gboolean fl_compositor_create_backing_store(
FlCompositor* self,
const FlutterBackingStoreConfig* config,
Expand Down
10 changes: 10 additions & 0 deletions engine/src/flutter/shell/platform/linux/fl_compositor.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ struct _FlCompositorClass {

FlutterRendererType (*get_renderer_type)(FlCompositor* compositor);

void (*setup)(FlCompositor* compositor);

gboolean (*create_backing_store)(FlCompositor* compositor,
const FlutterBackingStoreConfig* config,
FlutterBackingStore* backing_store_out);
Expand Down Expand Up @@ -51,6 +53,14 @@ struct _FlCompositorClass {
*/
FlutterRendererType fl_compositor_get_renderer_type(FlCompositor* compositor);

/**
* fl_compositor_setup:
* @compositor: an #FlCompositor.
*
* Creates resources required before rendering.
*/
void fl_compositor_setup(FlCompositor* compositor);

/**
* fl_compositor_create_backing_store:
* @compositor: an #FlCompositor.
Expand Down
33 changes: 18 additions & 15 deletions engine/src/flutter/shell/platform/linux/fl_compositor_opengl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,23 @@ static FlutterRendererType fl_compositor_opengl_get_renderer_type(
return kOpenGL;
}

static void fl_compositor_opengl_setup(FlCompositor* compositor) {
FlCompositorOpenGL* self = FL_COMPOSITOR_OPENGL(compositor);

fl_opengl_manager_make_current(self->opengl_manager);

// Note: NVIDIA and Vivante are temporarily disabled due to
// https://github.com/flutter/flutter/issues/152099
self->has_gl_framebuffer_blit =
!is_nvidia() && !is_vivante() &&
(epoxy_gl_version() >= 30 ||
epoxy_has_gl_extension("GL_EXT_framebuffer_blit"));

if (!self->has_gl_framebuffer_blit) {
setup_shader(self);
}
}

static gboolean fl_compositor_opengl_create_backing_store(
FlCompositor* compositor,
const FlutterBackingStoreConfig* config,
Expand Down Expand Up @@ -555,6 +572,7 @@ static void fl_compositor_opengl_dispose(GObject* object) {
static void fl_compositor_opengl_class_init(FlCompositorOpenGLClass* klass) {
FL_COMPOSITOR_CLASS(klass)->get_renderer_type =
fl_compositor_opengl_get_renderer_type;
FL_COMPOSITOR_CLASS(klass)->setup = fl_compositor_opengl_setup;
FL_COMPOSITOR_CLASS(klass)->create_backing_store =
fl_compositor_opengl_create_backing_store;
FL_COMPOSITOR_CLASS(klass)->collect_backing_store =
Expand Down Expand Up @@ -586,21 +604,6 @@ FlCompositorOpenGL* fl_compositor_opengl_new(FlEngine* engine) {
return self;
}

void fl_compositor_opengl_setup(FlCompositorOpenGL* self) {
g_return_if_fail(FL_IS_COMPOSITOR_OPENGL(self));

// Note: NVIDIA and Vivante are temporarily disabled due to
// https://github.com/flutter/flutter/issues/152099
self->has_gl_framebuffer_blit =
!is_nvidia() && !is_vivante() &&
(epoxy_gl_version() >= 30 ||
epoxy_has_gl_extension("GL_EXT_framebuffer_blit"));

if (!self->has_gl_framebuffer_blit) {
setup_shader(self);
}
}

void fl_compositor_opengl_render(FlCompositorOpenGL* self,
FlutterViewId view_id,
int width,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,6 @@ G_DECLARE_FINAL_TYPE(FlCompositorOpenGL,
*/
FlCompositorOpenGL* fl_compositor_opengl_new(FlEngine* engine);

/**
* fl_compositor_opengl_setup:
* @compositor: an #FlCompositorOpenGL.
*
* Creates OpenGL resources required before rendering. Requires an active
* context.
*/
void fl_compositor_opengl_setup(FlCompositorOpenGL* compositor);

/**
* fl_compositor_opengl_render:
* @compositor: an #FlCompositorOpenGL.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ TEST(FlCompositorOpenGLTest, BackgroundColor) {

g_autoptr(FlMockRenderable) renderable = fl_mock_renderable_new();
g_autoptr(FlCompositorOpenGL) compositor = fl_compositor_opengl_new(engine);
fl_compositor_opengl_setup(compositor);
fl_compositor_setup(FL_COMPOSITOR(compositor));
fl_engine_set_implicit_view(engine, FL_RENDERABLE(renderable));
fl_compositor_wait_for_frame(FL_COMPOSITOR(compositor), 1024, 1024);
FlutterBackingStoreConfig config = {
Expand Down Expand Up @@ -145,7 +145,7 @@ TEST(FlCompositorOpenGLTest, BlitFramebuffer) {

g_autoptr(FlMockRenderable) renderable = fl_mock_renderable_new();
g_autoptr(FlCompositorOpenGL) compositor = fl_compositor_opengl_new(engine);
fl_compositor_opengl_setup(compositor);
fl_compositor_setup(FL_COMPOSITOR(compositor));
fl_engine_set_implicit_view(engine, FL_RENDERABLE(renderable));
fl_compositor_wait_for_frame(FL_COMPOSITOR(compositor), 1024, 1024);
FlutterBackingStoreConfig config = {
Expand Down Expand Up @@ -202,7 +202,7 @@ TEST(FlCompositorOpenGLTest, BlitFramebufferExtension) {

g_autoptr(FlMockRenderable) renderable = fl_mock_renderable_new();
g_autoptr(FlCompositorOpenGL) compositor = fl_compositor_opengl_new(engine);
fl_compositor_opengl_setup(compositor);
fl_compositor_setup(FL_COMPOSITOR(compositor));
fl_engine_set_implicit_view(engine, FL_RENDERABLE(renderable));
fl_compositor_wait_for_frame(FL_COMPOSITOR(compositor), 1024, 1024);
FlutterBackingStoreConfig config = {
Expand Down Expand Up @@ -252,7 +252,7 @@ TEST(FlCompositorOpenGLTest, NoBlitFramebuffer) {

g_autoptr(FlMockRenderable) renderable = fl_mock_renderable_new();
g_autoptr(FlCompositorOpenGL) compositor = fl_compositor_opengl_new(engine);
fl_compositor_opengl_setup(compositor);
fl_compositor_setup(FL_COMPOSITOR(compositor));
fl_engine_set_implicit_view(engine, FL_RENDERABLE(renderable));
fl_compositor_wait_for_frame(FL_COMPOSITOR(compositor), 1024, 1024);
FlutterBackingStoreConfig config = {
Expand Down Expand Up @@ -305,7 +305,7 @@ TEST(FlCompositorOpenGLTest, BlitFramebufferNvidia) {

g_autoptr(FlMockRenderable) renderable = fl_mock_renderable_new();
g_autoptr(FlCompositorOpenGL) compositor = fl_compositor_opengl_new(engine);
fl_compositor_opengl_setup(compositor);
fl_compositor_setup(FL_COMPOSITOR(compositor));
fl_engine_set_implicit_view(engine, FL_RENDERABLE(renderable));
fl_compositor_wait_for_frame(FL_COMPOSITOR(compositor), 1024, 1024);
FlutterBackingStoreConfig config = {
Expand Down Expand Up @@ -359,7 +359,7 @@ TEST(FlCompositorOpenGLTest, MultiView) {
g_autoptr(FlMockRenderable) secondary_renderable = fl_mock_renderable_new();

g_autoptr(FlCompositorOpenGL) compositor = fl_compositor_opengl_new(engine);
fl_compositor_opengl_setup(compositor);
fl_compositor_setup(FL_COMPOSITOR(compositor));
fl_engine_set_implicit_view(engine, FL_RENDERABLE(renderable));
FlutterViewId view_id =
fl_engine_add_view(engine, FL_RENDERABLE(secondary_renderable), 1024, 768,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ static FlutterRendererType fl_compositor_software_get_renderer_type(
return kSoftware;
}

static void fl_compositor_software_setup(FlCompositor* compositor) {
// No special work required.
}

static gboolean fl_compositor_software_create_backing_store(
FlCompositor* compositor,
const FlutterBackingStoreConfig* config,
Expand Down Expand Up @@ -135,6 +139,7 @@ static void fl_compositor_software_class_init(
FlCompositorSoftwareClass* klass) {
FL_COMPOSITOR_CLASS(klass)->get_renderer_type =
fl_compositor_software_get_renderer_type;
FL_COMPOSITOR_CLASS(klass)->setup = fl_compositor_software_setup;
FL_COMPOSITOR_CLASS(klass)->create_backing_store =
fl_compositor_software_create_backing_store;
FL_COMPOSITOR_CLASS(klass)->collect_backing_store =
Expand Down
14 changes: 1 addition & 13 deletions engine/src/flutter/shell/platform/linux/fl_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -456,19 +456,7 @@ static GdkGLContext* create_context_cb(FlView* self) {
}

static void realize_cb(FlView* self) {
if (fl_compositor_get_renderer_type(fl_engine_get_compositor(self->engine)) ==
kOpenGL) {
fl_opengl_manager_make_current(fl_engine_get_opengl_manager(self->engine));

GError* gl_error = gtk_gl_area_get_error(GTK_GL_AREA(self->render_area));
if (gl_error != NULL) {
g_warning("Failed to initialize GLArea: %s", gl_error->message);
return;
}

fl_compositor_opengl_setup(
FL_COMPOSITOR_OPENGL(fl_engine_get_compositor(self->engine)));
}
fl_compositor_setup(fl_engine_get_compositor(self->engine));

GtkWidget* toplevel_window = gtk_widget_get_toplevel(GTK_WIDGET(self));

Expand Down