diff --git a/.gitignore b/.gitignore index 84cfed500c9e..d3470d8fa617 100644 --- a/.gitignore +++ b/.gitignore @@ -237,6 +237,8 @@ gfx/common/wayland/tablet-unstable-v2.h gfx/common/wayland/tablet-unstable-v2.c gfx/common/wayland/content-type-v1.h gfx/common/wayland/content-type-v1.c +gfx/common/wayland/single-pixel-buffer-v1.h +gfx/common/wayland/single-pixel-buffer-v1.c # libretro-common samples libretro-common/samples/streams/rzip/rzip diff --git a/Makefile.common b/Makefile.common index 70914d4b5cce..01bae782ee5a 100644 --- a/Makefile.common +++ b/Makefile.common @@ -1278,7 +1278,8 @@ ifeq ($(HAVE_WAYLAND), 1) gfx/common/wayland/relative-pointer-unstable-v1.o \ gfx/common/wayland/cursor-shape-v1.o \ gfx/common/wayland/tablet-unstable-v2.o \ - gfx/common/wayland/content-type-v1.o + gfx/common/wayland/content-type-v1.o \ + gfx/common/wayland/single-pixel-buffer-v1.o ifeq ($(HAVE_VULKAN), 1) OBJ += gfx/drivers_context/wayland_vk_ctx.o diff --git a/deps/wayland-protocols/staging/single-pixel-buffer/README b/deps/wayland-protocols/staging/single-pixel-buffer/README new file mode 100644 index 000000000000..b3a1b8687289 --- /dev/null +++ b/deps/wayland-protocols/staging/single-pixel-buffer/README @@ -0,0 +1,4 @@ +Single-pixel buffer protocol + +Maintainers: +Simon Ser (@emersion) diff --git a/deps/wayland-protocols/staging/single-pixel-buffer/single-pixel-buffer-v1.xml b/deps/wayland-protocols/staging/single-pixel-buffer/single-pixel-buffer-v1.xml new file mode 100644 index 000000000000..b15715578145 --- /dev/null +++ b/deps/wayland-protocols/staging/single-pixel-buffer/single-pixel-buffer-v1.xml @@ -0,0 +1,69 @@ + + + + Copyright © 2022 Simon Ser + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice (including the next + paragraph) shall be included in all copies or substantial portions of the + Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. + + + + This protocol extension allows clients to create single-pixel buffers. + + Compositors supporting this protocol extension should also support the + viewporter protocol extension. Clients may use viewporter to scale a + single-pixel buffer to a desired size. + + Warning! The protocol described in this file is currently in the testing + phase. Backward compatible changes may be added together with the + corresponding interface version bump. Backward incompatible changes can + only be done by creating a new major version of the extension. + + + + + The wp_single_pixel_buffer_manager_v1 interface is a factory for + single-pixel buffers. + + + + + Destroy the wp_single_pixel_buffer_manager_v1 object. + + The child objects created via this interface are unaffected. + + + + + + Create a single-pixel buffer from four 32-bit RGBA values. + + Unless specified in another protocol extension, the RGBA values use + pre-multiplied alpha. + + The width and height of the buffer are 1. + + + + + + + + + diff --git a/gfx/common/wayland/generate_wayland_protos.sh b/gfx/common/wayland/generate_wayland_protos.sh index a0fc857d424d..c26b3cbbc672 100755 --- a/gfx/common/wayland/generate_wayland_protos.sh +++ b/gfx/common/wayland/generate_wayland_protos.sh @@ -69,6 +69,7 @@ generate_source 'unstable/pointer-constraints' 'pointer-constraints-unstable-v1' generate_source 'unstable/relative-pointer' 'relative-pointer-unstable-v1' generate_source 'staging/fractional-scale' 'fractional-scale-v1' generate_source 'staging/cursor-shape' 'cursor-shape-v1' -# Required by cursor-shape-v1 +# tablet-unstable-v1 is required by cursor-shape-v1 generate_source 'unstable/tablet' 'tablet-unstable-v2' generate_source 'staging/content-type' 'content-type-v1' +generate_source 'staging/single-pixel-buffer' 'single-pixel-buffer-v1' diff --git a/gfx/common/wayland_common.c b/gfx/common/wayland_common.c index e98eed58be8d..97090034dca8 100644 --- a/gfx/common/wayland_common.c +++ b/gfx/common/wayland_common.c @@ -319,6 +319,8 @@ void gfx_ctx_wl_destroy_resources_common(gfx_ctx_wayland_data_t *wl) wp_cursor_shape_manager_v1_destroy (wl->cursor_shape_manager); if (wl->cursor_shape_device) wp_cursor_shape_device_v1_destroy (wl->cursor_shape_device); + if (wl->single_pixel_manager) + wp_single_pixel_buffer_manager_v1_destroy (wl->single_pixel_manager); if (wl->seat) wl_seat_destroy(wl->seat); if (wl->xdg_shell) @@ -372,6 +374,7 @@ void gfx_ctx_wl_destroy_resources_common(gfx_ctx_wayland_data_t *wl) wl->cursor_shape_device = NULL; wl->idle_inhibit_manager = NULL; wl->deco_manager = NULL; + wl->single_pixel_manager = NULL; wl->surface = NULL; wl->xdg_surface = NULL; wl->xdg_toplevel = NULL; @@ -544,7 +547,7 @@ static shm_buffer_t *create_shm_buffer(gfx_ctx_wayland_data_t *wl, int width, buffer->data = data; buffer->data_size = size; - return buffer; + return buffer; } static void shm_buffer_paint_icon( @@ -610,22 +613,37 @@ static void shm_buffer_paint_checkerboard( static bool wl_draw_splash_screen(gfx_ctx_wayland_data_t *wl) { - shm_buffer_t *buffer = create_shm_buffer(wl, - wl->buffer_width, - wl->buffer_height, - WL_SHM_FORMAT_XRGB8888); - - if (!buffer) - return false; - - shm_buffer_paint_checkerboard(buffer, wl->buffer_width, - wl->buffer_height, 1, - 8, 0xffbcbcbc, 0xff8e8e8e); - shm_buffer_paint_icon(buffer, wl->buffer_width, - wl->buffer_height, 1, - 16); - - wl_surface_attach(wl->surface, buffer->wl_buffer, 0, 0); + if (wl->single_pixel_manager) + { + struct wl_buffer *buffer = NULL; + buffer = wp_single_pixel_buffer_manager_v1_create_u32_rgba_buffer( + wl->single_pixel_manager, 0, 0, 0, UINT32_MAX); + + if (!buffer) + return false; + + wl_surface_attach(wl->surface, buffer, 0, 0); + } + else + { + shm_buffer_t *buffer = create_shm_buffer(wl, + wl->buffer_width, + wl->buffer_height, + WL_SHM_FORMAT_XRGB8888); + + if (!buffer) + return false; + + shm_buffer_paint_checkerboard(buffer, wl->buffer_width, + wl->buffer_height, 1, + 8, 0xffbcbcbc, 0xff8e8e8e); + shm_buffer_paint_icon(buffer, wl->buffer_width, + wl->buffer_height, 1, + 16); + + wl_surface_attach(wl->surface, buffer->wl_buffer, 0, 0); + } + if (wl_surface_get_version(wl->surface) >= WL_SURFACE_DAMAGE_BUFFER_SINCE_VERSION) wl_surface_damage_buffer(wl->surface, 0, 0, wl->buffer_width, @@ -746,6 +764,11 @@ bool gfx_ctx_wl_init_common( RARCH_LOG("[Wayland]: Compositor doesn't support the %s protocol!\n", zwp_relative_pointer_manager_v1_interface.name); } + if (!wl->single_pixel_manager) + { + RARCH_LOG("[Wayland]: Compositor doesn't support the %s protocol!\n", wp_single_pixel_buffer_manager_v1_interface.name); + } + wl->surface = wl_compositor_create_surface(wl->compositor); if (wl->viewporter) wl->viewport = wp_viewporter_get_viewport(wl->viewporter, wl->surface); diff --git a/input/common/wayland_common.c b/input/common/wayland_common.c index 54893943615d..9f5d27373580 100644 --- a/input/common/wayland_common.c +++ b/input/common/wayland_common.c @@ -802,6 +802,10 @@ static void wl_registry_handle_global(void *data, struct wl_registry *reg, wl->content_type_manager = (struct wp_content_type_manager_v1*) wl_registry_bind( reg, id, &wp_content_type_manager_v1_interface, MIN(version, 1)); + else if (string_is_equal(interface, wp_single_pixel_buffer_manager_v1_interface.name) && found++) + wl->single_pixel_manager = (struct wp_single_pixel_buffer_manager_v1*) + wl_registry_bind( + reg, id, &wp_single_pixel_buffer_manager_v1_interface, MIN(version, 1)); if (found > 1) RARCH_LOG("[Wayland]: Registered interface %s at version %u\n", diff --git a/input/common/wayland_common.h b/input/common/wayland_common.h index 9b7a143f0b13..8ccae5f2fda2 100644 --- a/input/common/wayland_common.h +++ b/input/common/wayland_common.h @@ -37,12 +37,13 @@ #include "../../gfx/common/wayland/content-type-v1.h" #include "../../gfx/common/wayland/cursor-shape-v1.h" #include "../../gfx/common/wayland/fractional-scale-v1.h" -#include "../../gfx/common/wayland/viewporter.h" #include "../../gfx/common/wayland/idle-inhibit-unstable-v1.h" -#include "../../gfx/common/wayland/xdg-shell.h" -#include "../../gfx/common/wayland/xdg-decoration-unstable-v1.h" #include "../../gfx/common/wayland/pointer-constraints-unstable-v1.h" #include "../../gfx/common/wayland/relative-pointer-unstable-v1.h" +#include "../../gfx/common/wayland/single-pixel-buffer-v1.h" +#include "../../gfx/common/wayland/viewporter.h" +#include "../../gfx/common/wayland/xdg-decoration-unstable-v1.h" +#include "../../gfx/common/wayland/xdg-shell.h" #define FRACTIONAL_SCALE_V1_DEN 120 #define FRACTIONAL_SCALE_MULT(v, scale_num) \ @@ -187,6 +188,7 @@ typedef struct gfx_ctx_wayland_data struct wp_cursor_shape_device_v1 *cursor_shape_device; struct wp_content_type_manager_v1 *content_type_manager; struct wp_content_type_v1 *content_type; + struct wp_single_pixel_buffer_manager_v1 *single_pixel_manager; output_info_t *current_output; #ifdef HAVE_VULKAN gfx_ctx_vulkan_data_t vk;