mirror of
				https://gitlab.freedesktop.org/wlroots/wlroots.git
				synced 2025-11-03 09:01:40 -05:00 
			
		
		
		
	ext-image-capture-source-v1: add wlr_ext_image_capture_source_v1_set_constraints_from_swapchain()
This commit is contained in:
		
							parent
							
								
									c24efad6df
								
							
						
					
					
						commit
						855b3fd607
					
				
					 2 changed files with 75 additions and 0 deletions
				
			
		| 
						 | 
					@ -13,6 +13,8 @@
 | 
				
			||||||
#include <wlr/types/wlr_ext_image_capture_source_v1.h>
 | 
					#include <wlr/types/wlr_ext_image_capture_source_v1.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct wlr_ext_image_copy_capture_frame_v1;
 | 
					struct wlr_ext_image_copy_capture_frame_v1;
 | 
				
			||||||
 | 
					struct wlr_swapchain;
 | 
				
			||||||
 | 
					struct wlr_renderer;
 | 
				
			||||||
struct wlr_seat;
 | 
					struct wlr_seat;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct wlr_ext_image_capture_source_v1_interface {
 | 
					struct wlr_ext_image_capture_source_v1_interface {
 | 
				
			||||||
| 
						 | 
					@ -29,6 +31,9 @@ void wlr_ext_image_capture_source_v1_init(struct wlr_ext_image_capture_source_v1
 | 
				
			||||||
void wlr_ext_image_capture_source_v1_finish(struct wlr_ext_image_capture_source_v1 *source);
 | 
					void wlr_ext_image_capture_source_v1_finish(struct wlr_ext_image_capture_source_v1 *source);
 | 
				
			||||||
bool wlr_ext_image_capture_source_v1_create_resource(struct wlr_ext_image_capture_source_v1 *source,
 | 
					bool wlr_ext_image_capture_source_v1_create_resource(struct wlr_ext_image_capture_source_v1 *source,
 | 
				
			||||||
	struct wl_client *client, uint32_t new_id);
 | 
						struct wl_client *client, uint32_t new_id);
 | 
				
			||||||
 | 
					bool wlr_ext_image_capture_source_v1_set_constraints_from_swapchain(
 | 
				
			||||||
 | 
						struct wlr_ext_image_capture_source_v1 *source,
 | 
				
			||||||
 | 
						struct wlr_swapchain *swapchain, struct wlr_renderer *renderer);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void wlr_ext_image_capture_source_v1_cursor_init(struct wlr_ext_image_capture_source_v1_cursor *source_cursor,
 | 
					void wlr_ext_image_capture_source_v1_cursor_init(struct wlr_ext_image_capture_source_v1_cursor *source_cursor,
 | 
				
			||||||
		const struct wlr_ext_image_capture_source_v1_interface *impl);
 | 
							const struct wlr_ext_image_capture_source_v1_interface *impl);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,7 +1,14 @@
 | 
				
			||||||
#include <assert.h>
 | 
					#include <assert.h>
 | 
				
			||||||
 | 
					#include <drm_fourcc.h>
 | 
				
			||||||
#include <stdlib.h>
 | 
					#include <stdlib.h>
 | 
				
			||||||
 | 
					#include <sys/stat.h>
 | 
				
			||||||
#include <wlr/interfaces/wlr_ext_image_capture_source_v1.h>
 | 
					#include <wlr/interfaces/wlr_ext_image_capture_source_v1.h>
 | 
				
			||||||
 | 
					#include <wlr/render/allocator.h>
 | 
				
			||||||
 | 
					#include <wlr/render/swapchain.h>
 | 
				
			||||||
 | 
					#include <wlr/render/wlr_renderer.h>
 | 
				
			||||||
 | 
					#include <wlr/types/wlr_buffer.h>
 | 
				
			||||||
#include <wlr/types/wlr_ext_image_capture_source_v1.h>
 | 
					#include <wlr/types/wlr_ext_image_capture_source_v1.h>
 | 
				
			||||||
 | 
					#include <wlr/util/log.h>
 | 
				
			||||||
#include "ext-image-capture-source-v1-protocol.h"
 | 
					#include "ext-image-capture-source-v1-protocol.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void source_handle_destroy(struct wl_client *client,
 | 
					static void source_handle_destroy(struct wl_client *client,
 | 
				
			||||||
| 
						 | 
					@ -70,6 +77,69 @@ bool wlr_ext_image_capture_source_v1_create_resource(struct wlr_ext_image_captur
 | 
				
			||||||
	return true;
 | 
						return true;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static uint32_t get_swapchain_shm_format(struct wlr_swapchain *swapchain,
 | 
				
			||||||
 | 
							struct wlr_renderer *renderer) {
 | 
				
			||||||
 | 
						struct wlr_buffer *buffer = wlr_swapchain_acquire(swapchain);
 | 
				
			||||||
 | 
						if (buffer == NULL) {
 | 
				
			||||||
 | 
							return DRM_FORMAT_INVALID;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						struct wlr_texture *texture = wlr_texture_from_buffer(renderer, buffer);
 | 
				
			||||||
 | 
						wlr_buffer_unlock(buffer);
 | 
				
			||||||
 | 
						if (texture == NULL) {
 | 
				
			||||||
 | 
							return DRM_FORMAT_INVALID;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						uint32_t format = wlr_texture_preferred_read_format(texture);
 | 
				
			||||||
 | 
						wlr_texture_destroy(texture);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return format;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					bool wlr_ext_image_capture_source_v1_set_constraints_from_swapchain(struct wlr_ext_image_capture_source_v1 *source,
 | 
				
			||||||
 | 
							struct wlr_swapchain *swapchain, struct wlr_renderer *renderer) {
 | 
				
			||||||
 | 
						source->width = swapchain->width;
 | 
				
			||||||
 | 
						source->height = swapchain->height;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						uint32_t shm_format = get_swapchain_shm_format(swapchain, renderer);
 | 
				
			||||||
 | 
						if (shm_format != DRM_FORMAT_INVALID) {
 | 
				
			||||||
 | 
							uint32_t *shm_formats = calloc(1, sizeof(shm_formats[0]));
 | 
				
			||||||
 | 
							if (shm_formats == NULL) {
 | 
				
			||||||
 | 
								wlr_log(WLR_ERROR, "Allocation failed");
 | 
				
			||||||
 | 
								return false;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							shm_formats[0] = shm_format;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							source->shm_formats_len = 1;
 | 
				
			||||||
 | 
							free(source->shm_formats);
 | 
				
			||||||
 | 
							source->shm_formats = shm_formats;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						int drm_fd = wlr_renderer_get_drm_fd(renderer);
 | 
				
			||||||
 | 
						if (swapchain->allocator != NULL &&
 | 
				
			||||||
 | 
								(swapchain->allocator->buffer_caps & WLR_BUFFER_CAP_DMABUF) &&
 | 
				
			||||||
 | 
								drm_fd >= 0) {
 | 
				
			||||||
 | 
							struct stat dev_stat;
 | 
				
			||||||
 | 
							if (fstat(drm_fd, &dev_stat) != 0) {
 | 
				
			||||||
 | 
								wlr_log_errno(WLR_ERROR, "fstat() failed");
 | 
				
			||||||
 | 
								return false;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							source->dmabuf_device = dev_stat.st_rdev;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							wlr_drm_format_set_finish(&source->dmabuf_formats);
 | 
				
			||||||
 | 
							source->dmabuf_formats = (struct wlr_drm_format_set){0};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							for (size_t i = 0; i < swapchain->format.len; i++) {
 | 
				
			||||||
 | 
								wlr_drm_format_set_add(&source->dmabuf_formats,
 | 
				
			||||||
 | 
									swapchain->format.format, swapchain->format.modifiers[i]);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						wl_signal_emit_mutable(&source->events.constraints_update, NULL);
 | 
				
			||||||
 | 
						return true;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void wlr_ext_image_capture_source_v1_cursor_init(struct wlr_ext_image_capture_source_v1_cursor *source_cursor,
 | 
					void wlr_ext_image_capture_source_v1_cursor_init(struct wlr_ext_image_capture_source_v1_cursor *source_cursor,
 | 
				
			||||||
		const struct wlr_ext_image_capture_source_v1_interface *impl) {
 | 
							const struct wlr_ext_image_capture_source_v1_interface *impl) {
 | 
				
			||||||
	*source_cursor = (struct wlr_ext_image_capture_source_v1_cursor){0};
 | 
						*source_cursor = (struct wlr_ext_image_capture_source_v1_cursor){0};
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue