GTK embedder: Failed to create OpenGL context on Wayland + NVIDIA Optimus, results in black screen
- Dominant language
- Dart
- Stars
- 179k
- Forks
- 31.1k
- PR merge metrics
- PR metrics pending
Description
## Steps to Reproduce
1. Download any Flutter Linux app with GTK embedder (e.g. FlClash)
2. Run on a system with:
- Wayland session (KDE Plasma 6)
- NVIDIA Optimus dual-GPU: Intel UHD 630 + NVIDIA GTX 1660 Ti
- Mesa 26.1.3 + NVIDIA 610.43.02 (proprietary)
3. Launch without any environment variables.
```bash
./FlClash-0.8.93-linux-amd64.AppImage
```
AppImage download: https://github.com/chen08209/FlClash/releases/download/v0.8.93/FlClash-0.8.93-linux-amd64.AppImage
## Expected Results
Application window renders normally.
## Actual Results
Window opens with a black screen. The following errors are logged:
```
Failed to create OpenGL context: No GL implementation available
[ERROR:flutter/shell/platform/embedder/embedder_surface_gl_skia.cc(121)]
Could not create a resource context for async texture uploads.
[ERROR:flutter/shell/gpu/gpu_surface_gl_skia.cc(46)]
Could not make the context current to set up the Gr context.
[ERROR:flutter/shell/gpu/gpu_surface_gl_skia.cc(83)]
Could not make the context current to set up the Gr context.
[ERROR:flutter/shell/common/platform_view.cc(76)]
Failed to create platform view rendering surface
```
The app process stays alive (IPC works, network requests succeed), only rendering fails.
## Root Cause
On Optimus systems, NVIDIA's EGL ICD (`10_nvidia.json`) takes priority over Mesa's (`50_mesa.json`) in glvnd dispatch. Under Wayland, the GTK embedder uses EGL, so NVIDIA's EGL is selected. But the display is connected to the Intel GPU, and NVIDIA EGL cannot create a rendering surface on Intel's display, causing context creation failure.
Note: A minimal GtkGLArea test (`gcc $(pkg-config --cflags --libs gtk+-3.0 epoxy)`) works fine in all modes. The issue is specific to the Flutter embedder's GL initialization path, which differs from GtkGLArea.
## Failed Workarounds
1. `GDK_BACKEND=x11` — still black screen
2. `LIBGL_ALWAYS_SOFTWARE=1` — still black screen
3. `__EGL_VENDOR_LIBRARY_FILENAMES=.../50_mesa.json` — crashes with `No provider of eglGetPlatformDisplayEXT found`
## Successful Workaround
```
__NV_PRIME_RENDER_OFFLOAD=1 __GLX_VENDOR_LIBRARY_NAME=nvidia
```
This forces PRIME render offload through NVIDIA, which works.
## Expected Behavior from Embedder
The GTK embedder should:
1. Detect GPU vendor mismatch on Optimus and fall back to a matching vendor
2. Fall back to software rendering instead of a black screen
3. At minimum, log a diagnostic message identifying the GPU mismatch
## System Info
```
OS: Arch Linux, kernel 7.0.14
Display: Wayland (KDE Plasma 6.7.2)
GPU 1: Intel UHD Graphics 630 (CoffeeLake-H GT2)
GPU 2: NVIDIA GeForce GTX 1660 Ti Mobile
Mesa: 26.1.3 / NVIDIA: 610.43.02
Flutter app: FlClash 0.8.93 (GTK embedder, Impeller + Skia)
```
## EGL Vendor Configuration
```
$ ls /usr/share/glvnd/egl_vendor.d/
10_nvidia.json 50_mesa.json
$ eglinfo -B | grep "EGL vendor"
EGL vendor string: NVIDIA
$ glxinfo | grep "OpenGL renderer"
OpenGL renderer string: Mesa Intel(R) UHD Graphics 630 (CFL GT2)
```
NVIDIA's EGL takes priority even though display is on Intel GPU.
Contributor guide
Research direction
Reproduce the failure with the FlClash AppImage under the stated Wayland and NVIDIA Optimus setup, then inspect the GTK embedder GL initialization around embedder_surface_gl_skia.cc and gpu_surface_gl_skia.cc. Compare the failing EGL path with the working GtkGLArea test and verify that the completed behavior avoids the black screen or reports the GPU mismatch clearly.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp, flutter, linux
- Domain
- computer-graphics, desktop
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100