mirror of
				https://gitlab.freedesktop.org/wayland/wayland.git
				synced 2025-11-03 09:01:42 -05:00 
			
		
		
		
	shm: Add request for resizing pools
This commit is contained in:
		
							parent
							
								
									35a92ef83b
								
							
						
					
					
						commit
						ff0d745674
					
				
					 2 changed files with 40 additions and 5 deletions
				
			
		| 
						 | 
					@ -173,6 +173,16 @@
 | 
				
			||||||
	Destroy the pool.
 | 
						Destroy the pool.
 | 
				
			||||||
      </description>
 | 
					      </description>
 | 
				
			||||||
    </request>
 | 
					    </request>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    <request name="resize">
 | 
				
			||||||
 | 
					      <description summary="change the size of the pool mapping">
 | 
				
			||||||
 | 
						This request will cause the server to remap the backing memory
 | 
				
			||||||
 | 
						for the pool from the fd passed when the pool was creating but
 | 
				
			||||||
 | 
						using the new size.
 | 
				
			||||||
 | 
					      </description>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      <arg name="size" type="int"/>
 | 
				
			||||||
 | 
					    </request>
 | 
				
			||||||
  </interface>
 | 
					  </interface>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  <interface name="wl_shm" version="1">
 | 
					  <interface name="wl_shm" version="1">
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -38,13 +38,14 @@ struct wl_shm_pool {
 | 
				
			||||||
	int refcount;
 | 
						int refcount;
 | 
				
			||||||
	char *data;
 | 
						char *data;
 | 
				
			||||||
	int size;
 | 
						int size;
 | 
				
			||||||
 | 
						int fd;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct wl_shm_buffer {
 | 
					struct wl_shm_buffer {
 | 
				
			||||||
	struct wl_buffer buffer;
 | 
						struct wl_buffer buffer;
 | 
				
			||||||
	int32_t stride;
 | 
						int32_t stride;
 | 
				
			||||||
	uint32_t format;
 | 
						uint32_t format;
 | 
				
			||||||
	void *data;
 | 
						int offset;
 | 
				
			||||||
	struct wl_shm_pool *pool;
 | 
						struct wl_shm_pool *pool;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -56,6 +57,7 @@ shm_pool_unref(struct wl_shm_pool *pool)
 | 
				
			||||||
		return;
 | 
							return;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	munmap(pool->data, pool->size);
 | 
						munmap(pool->data, pool->size);
 | 
				
			||||||
 | 
						close(pool->fd);
 | 
				
			||||||
	free(pool);
 | 
						free(pool);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -120,7 +122,7 @@ shm_pool_create_buffer(struct wl_client *client, struct wl_resource *resource,
 | 
				
			||||||
	buffer->buffer.height = height;
 | 
						buffer->buffer.height = height;
 | 
				
			||||||
	buffer->format = format;
 | 
						buffer->format = format;
 | 
				
			||||||
	buffer->stride = stride;
 | 
						buffer->stride = stride;
 | 
				
			||||||
	buffer->data = pool->data + offset;
 | 
						buffer->offset = offset;
 | 
				
			||||||
	buffer->pool = pool;
 | 
						buffer->pool = pool;
 | 
				
			||||||
	pool->refcount++;
 | 
						pool->refcount++;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -150,9 +152,32 @@ shm_pool_destroy(struct wl_client *client, struct wl_resource *resource)
 | 
				
			||||||
	wl_resource_destroy(resource);
 | 
						wl_resource_destroy(resource);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static void
 | 
				
			||||||
 | 
					shm_pool_resize(struct wl_client *client, struct wl_resource *resource,
 | 
				
			||||||
 | 
							int32_t size)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						struct wl_shm_pool *pool = resource->data;
 | 
				
			||||||
 | 
						void *data;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						data = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED,
 | 
				
			||||||
 | 
							    pool->fd, 0);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (data == MAP_FAILED) {
 | 
				
			||||||
 | 
							wl_resource_post_error(resource,
 | 
				
			||||||
 | 
									       WL_SHM_ERROR_INVALID_FD,
 | 
				
			||||||
 | 
									       "failed mmap fd %d", pool->fd);
 | 
				
			||||||
 | 
							return;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						munmap(pool->data, pool->size);
 | 
				
			||||||
 | 
						pool->data = data;
 | 
				
			||||||
 | 
						pool->size = size;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct wl_shm_pool_interface shm_pool_interface = {
 | 
					struct wl_shm_pool_interface shm_pool_interface = {
 | 
				
			||||||
	shm_pool_create_buffer,
 | 
						shm_pool_create_buffer,
 | 
				
			||||||
	shm_pool_destroy
 | 
						shm_pool_destroy,
 | 
				
			||||||
 | 
						shm_pool_resize
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void
 | 
					static void
 | 
				
			||||||
| 
						 | 
					@ -177,10 +202,10 @@ shm_create_pool(struct wl_client *client, struct wl_resource *resource,
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	pool->refcount = 1;
 | 
						pool->refcount = 1;
 | 
				
			||||||
 | 
						pool->fd = fd;
 | 
				
			||||||
	pool->size = size;
 | 
						pool->size = size;
 | 
				
			||||||
	pool->data = mmap(NULL, size,
 | 
						pool->data = mmap(NULL, size,
 | 
				
			||||||
			  PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
 | 
								  PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
 | 
				
			||||||
	close(fd);
 | 
					 | 
				
			||||||
	if (pool->data == MAP_FAILED) {
 | 
						if (pool->data == MAP_FAILED) {
 | 
				
			||||||
		wl_resource_post_error(resource,
 | 
							wl_resource_post_error(resource,
 | 
				
			||||||
				       WL_SHM_ERROR_INVALID_FD,
 | 
									       WL_SHM_ERROR_INVALID_FD,
 | 
				
			||||||
| 
						 | 
					@ -252,7 +277,7 @@ wl_shm_buffer_get_data(struct wl_buffer *buffer_base)
 | 
				
			||||||
	if (!wl_buffer_is_shm(buffer_base))
 | 
						if (!wl_buffer_is_shm(buffer_base))
 | 
				
			||||||
		return NULL;
 | 
							return NULL;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return buffer->data;
 | 
						return buffer->pool->data + buffer->offset;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
WL_EXPORT uint32_t
 | 
					WL_EXPORT uint32_t
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue