From 2bc2c0a0ecd852f574427ca5e01c8a7a03d539e8 Mon Sep 17 00:00:00 2001 From: edde746 <86283021+edde746@users.noreply.github.com> Date: Tue, 17 Feb 2026 08:55:29 +0100 Subject: [PATCH] feat: use FlTextureGL for Linux mpv video rendering --- lib/mpv/player/platform/player_linux.dart | 9 +- lib/mpv/player/player_native.dart | 20 +- lib/mpv/video.dart | 9 +- linux/CMakeLists.txt | 4 - linux/runner/CMakeLists.txt | 1 + linux/runner/mpv/mpv_player.cc | 111 +++------ linux/runner/mpv/mpv_player.h | 53 ++-- linux/runner/mpv/mpv_plugin.cc | 285 +++++----------------- linux/runner/mpv/mpv_plugin.h | 19 +- linux/runner/mpv/mpv_texture.cc | 182 ++++++++++++++ linux/runner/mpv/mpv_texture.h | 30 +++ linux/runner/my_application.cc | 89 +------ 12 files changed, 376 insertions(+), 436 deletions(-) create mode 100644 linux/runner/mpv/mpv_texture.cc create mode 100644 linux/runner/mpv/mpv_texture.h diff --git a/lib/mpv/player/platform/player_linux.dart b/lib/mpv/player/platform/player_linux.dart index ae0c5737..c18c97bd 100644 --- a/lib/mpv/player/platform/player_linux.dart +++ b/lib/mpv/player/platform/player_linux.dart @@ -2,11 +2,8 @@ import '../player_native.dart'; /// Linux implementation of [Player]. /// -/// Uses libmpv with OpenGL rendering via GtkGLArea. -/// The mpv video is rendered to a GtkGLArea positioned behind -/// the Flutter view using a GtkOverlay, with transparent regions -/// in the Flutter UI allowing the video to show through. +/// Uses libmpv with FlTextureGL — video is rendered to an offscreen FBO +/// and composited GPU-side via Flutter's Texture widget. class PlayerLinux extends PlayerNative { - @override - int? get textureId => null; // Uses GtkGLArea, not Flutter texture + // textureId is set during initialize() via PlayerNative } diff --git a/lib/mpv/player/player_native.dart b/lib/mpv/player/player_native.dart index 5c570c9f..b5e61824 100644 --- a/lib/mpv/player/player_native.dart +++ b/lib/mpv/player/player_native.dart @@ -6,9 +6,15 @@ import '../font_loader.dart'; import '../models.dart'; import 'player_base.dart'; -/// Shared native implementation of [Player] for iOS, macOS, and Android (MPV fallback). -/// Uses MPVKit via platform channels with Metal rendering (Apple) or native window (Android). +/// Shared native implementation of [Player] for iOS, macOS, Android (MPV fallback), and Linux. +/// Uses MPVKit via platform channels with Metal rendering (Apple), native window (Android), +/// or FlTextureGL (Linux). class PlayerNative extends PlayerBase { + int? _textureIdValue; + + @override + int? get textureId => _textureIdValue; + static const _methodChannel = MethodChannel('com.plezy/mpv_player'); static const _eventChannel = EventChannel('com.plezy/mpv_player/events'); @@ -32,8 +38,14 @@ class PlayerNative extends PlayerBase { if (initialized) return; try { - final result = await methodChannel.invokeMethod('initialize'); - initialized = result == true; + final result = await methodChannel.invokeMethod('initialize'); + if (result is int) { + // Linux: initialize returns the texture ID + _textureIdValue = result; + initialized = true; + } else { + initialized = result == true; + } if (!initialized) { throw Exception('Failed to initialize player'); } diff --git a/lib/mpv/video.dart b/lib/mpv/video.dart index 5389f9a0..f2cd2b09 100644 --- a/lib/mpv/video.dart +++ b/lib/mpv/video.dart @@ -74,7 +74,14 @@ class _VideoState extends State