• Wayland においてウィンドウの画像は wl_surface.attach によって渡されてきた wl_bufferwl_shm_buffer_get() に渡して wl_shm_buffer を取得することで、これを経由して読み取れる
  • 画像のフォーマット(argb8888 など)は wl_shm_buffer_get_format(wl_shm_buffer*) によって取得できる
    • この値は /usr/include/drm とかに置いてある drm_fourcc.h と同じらしい
  • で、これどうやってOpenGLで使うの?
  • wlroots がどうやっているか調べてみました!

render/gles2/texture.c

wlr_texture* gles2_texture_from_pixels(*wlr_renderer, u32 drm_format, u32 stride, u32 width, u32 height, void* data)

  • glTexImage2D() を呼び出している唯一の場所
  • 第3引数には wlr_gles2_pixel_format* fmtfmt->gl_internalformat を使っているらしい

render/gles2/pixel_format.c

wlr_gles2_pixel_format* get_gles2_format_from_drm(uint32_t fmt)

  • for i in range(formats.len): if (formats[i].drm_format == fmt) return &formats[i]; らしい
    • 力技じゃん!!!
  • ファイル冒頭において static const struct wlr_gles2_pixel_format formats[] が定義されている