2014-06-12 18:26:49 +04:00
|
|
|
/*
|
|
|
|
* Copyright © 2011 Benjamin Franzke
|
|
|
|
* Copyright © 2010 Intel Corporation
|
|
|
|
* Copyright © 2014 Collabora Ltd.
|
|
|
|
*
|
2017-01-23 17:17:44 +03:00
|
|
|
* 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:
|
2014-06-12 18:26:49 +04:00
|
|
|
*
|
2017-01-23 17:17:44 +03:00
|
|
|
* 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.
|
2014-06-12 18:26:49 +04:00
|
|
|
*/
|
|
|
|
|
2016-06-16 04:13:07 +03:00
|
|
|
#include "config.h"
|
2016-11-23 11:33:21 +03:00
|
|
|
#include "simple-dmabuf-drm-data.h"
|
2014-06-12 18:26:49 +04:00
|
|
|
|
2016-07-19 14:16:27 +03:00
|
|
|
#include <stdint.h>
|
2014-06-12 18:26:49 +04:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <assert.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <sys/mman.h>
|
|
|
|
#include <signal.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
|
|
|
|
#include <xf86drm.h>
|
2017-04-26 16:47:18 +03:00
|
|
|
|
|
|
|
#ifdef HAVE_LIBDRM_INTEL
|
2016-01-11 22:04:37 +03:00
|
|
|
#include <i915_drm.h>
|
|
|
|
#include <intel_bufmgr.h>
|
2017-04-26 16:47:18 +03:00
|
|
|
#elif HAVE_LIBDRM_FREEDRENO
|
|
|
|
#include <freedreno/freedreno_drmif.h>
|
|
|
|
#endif
|
2016-01-11 22:04:37 +03:00
|
|
|
#include <drm_fourcc.h>
|
2014-06-12 18:26:49 +04:00
|
|
|
|
|
|
|
#include <wayland-client.h>
|
2016-02-12 03:42:49 +03:00
|
|
|
#include "shared/zalloc.h"
|
2016-11-23 11:33:21 +03:00
|
|
|
#include "shared/platform.h"
|
2016-08-11 18:44:41 +03:00
|
|
|
#include "xdg-shell-unstable-v6-client-protocol.h"
|
2015-11-17 11:00:27 +03:00
|
|
|
#include "fullscreen-shell-unstable-v1-client-protocol.h"
|
2015-11-17 11:00:28 +03:00
|
|
|
#include "linux-dmabuf-unstable-v1-client-protocol.h"
|
2014-06-12 18:26:49 +04:00
|
|
|
|
2016-11-23 11:33:21 +03:00
|
|
|
extern const unsigned nv12_tiled[];
|
2017-04-26 16:47:18 +03:00
|
|
|
struct buffer;
|
|
|
|
|
2014-06-12 18:26:49 +04:00
|
|
|
struct display {
|
|
|
|
struct wl_display *display;
|
|
|
|
struct wl_registry *registry;
|
|
|
|
struct wl_compositor *compositor;
|
2016-08-11 18:44:41 +03:00
|
|
|
struct zxdg_shell_v6 *shell;
|
2015-11-17 11:00:27 +03:00
|
|
|
struct zwp_fullscreen_shell_v1 *fshell;
|
2015-11-17 11:00:28 +03:00
|
|
|
struct zwp_linux_dmabuf_v1 *dmabuf;
|
2014-06-12 18:26:49 +04:00
|
|
|
int xrgb8888_format_found;
|
2016-11-23 11:33:21 +03:00
|
|
|
int nv12_format_found;
|
|
|
|
int nv12_modifier_found;
|
2017-04-26 16:46:00 +03:00
|
|
|
int req_dmabuf_immediate;
|
2016-11-23 11:33:21 +03:00
|
|
|
int req_dmabuf_modifiers;
|
2014-06-12 18:26:49 +04:00
|
|
|
};
|
|
|
|
|
2017-04-26 16:47:18 +03:00
|
|
|
struct drm_device {
|
|
|
|
int fd;
|
|
|
|
char *name;
|
|
|
|
|
|
|
|
int (*alloc_bo)(struct buffer *buf);
|
|
|
|
void (*free_bo)(struct buffer *buf);
|
|
|
|
int (*export_bo_to_prime)(struct buffer *buf);
|
|
|
|
int (*map_bo)(struct buffer *buf);
|
|
|
|
void (*unmap_bo)(struct buffer *buf);
|
|
|
|
};
|
|
|
|
|
2014-06-12 18:26:49 +04:00
|
|
|
struct buffer {
|
|
|
|
struct wl_buffer *buffer;
|
|
|
|
int busy;
|
|
|
|
|
2017-04-26 16:47:18 +03:00
|
|
|
struct drm_device *dev;
|
2014-06-12 18:26:49 +04:00
|
|
|
int drm_fd;
|
|
|
|
|
2017-04-26 16:47:18 +03:00
|
|
|
#ifdef HAVE_LIBDRM_INTEL
|
2014-06-12 18:26:49 +04:00
|
|
|
drm_intel_bufmgr *bufmgr;
|
|
|
|
drm_intel_bo *bo;
|
2017-04-26 16:47:18 +03:00
|
|
|
#elif HAVE_LIBDRM_FREEDRENO
|
|
|
|
struct fd_device *fd_dev;
|
|
|
|
struct fd_bo *bo;
|
|
|
|
#endif /* HAVE_LIBDRM_FREEDRENO */
|
2014-06-12 18:26:49 +04:00
|
|
|
|
|
|
|
uint32_t gem_handle;
|
|
|
|
int dmabuf_fd;
|
|
|
|
uint8_t *mmap;
|
|
|
|
|
|
|
|
int width;
|
|
|
|
int height;
|
|
|
|
int bpp;
|
|
|
|
unsigned long stride;
|
2016-11-23 11:33:21 +03:00
|
|
|
int format;
|
2014-06-12 18:26:49 +04:00
|
|
|
};
|
|
|
|
|
2016-06-10 13:13:01 +03:00
|
|
|
#define NUM_BUFFERS 3
|
|
|
|
|
2014-06-12 18:26:49 +04:00
|
|
|
struct window {
|
|
|
|
struct display *display;
|
|
|
|
int width, height;
|
|
|
|
struct wl_surface *surface;
|
2016-08-11 18:44:41 +03:00
|
|
|
struct zxdg_surface_v6 *xdg_surface;
|
|
|
|
struct zxdg_toplevel_v6 *xdg_toplevel;
|
2016-06-10 13:13:01 +03:00
|
|
|
struct buffer buffers[NUM_BUFFERS];
|
2014-06-12 18:26:49 +04:00
|
|
|
struct buffer *prev_buffer;
|
|
|
|
struct wl_callback *callback;
|
2016-08-11 18:44:41 +03:00
|
|
|
bool initialized;
|
|
|
|
bool wait_for_configure;
|
2014-06-12 18:26:49 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
static int running = 1;
|
|
|
|
|
2016-08-11 18:44:41 +03:00
|
|
|
static void
|
|
|
|
redraw(void *data, struct wl_callback *callback, uint32_t time);
|
|
|
|
|
2014-06-12 18:26:49 +04:00
|
|
|
static void
|
|
|
|
buffer_release(void *data, struct wl_buffer *buffer)
|
|
|
|
{
|
|
|
|
struct buffer *mybuf = data;
|
|
|
|
|
|
|
|
mybuf->busy = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct wl_buffer_listener buffer_listener = {
|
|
|
|
buffer_release
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2017-04-26 16:47:18 +03:00
|
|
|
#ifdef HAVE_LIBDRM_INTEL
|
2014-06-12 18:26:49 +04:00
|
|
|
static int
|
2017-04-26 16:47:18 +03:00
|
|
|
intel_alloc_bo(struct buffer *my_buf)
|
2014-06-12 18:26:49 +04:00
|
|
|
{
|
|
|
|
/* XXX: try different tiling modes for testing FB modifiers. */
|
|
|
|
uint32_t tiling = I915_TILING_NONE;
|
|
|
|
|
|
|
|
assert(my_buf->bufmgr);
|
|
|
|
|
|
|
|
my_buf->bo = drm_intel_bo_alloc_tiled(my_buf->bufmgr, "test",
|
|
|
|
my_buf->width, my_buf->height,
|
|
|
|
(my_buf->bpp / 8), &tiling,
|
|
|
|
&my_buf->stride, 0);
|
|
|
|
|
|
|
|
printf("buffer allocated w %d, h %d, stride %lu, size %lu\n",
|
|
|
|
my_buf->width, my_buf->height, my_buf->stride, my_buf->bo->size);
|
|
|
|
|
|
|
|
if (!my_buf->bo)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (tiling != I915_TILING_NONE)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2017-04-26 16:47:18 +03:00
|
|
|
intel_free_bo(struct buffer *my_buf)
|
2014-06-12 18:26:49 +04:00
|
|
|
{
|
|
|
|
drm_intel_bo_unreference(my_buf->bo);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2017-04-26 16:47:18 +03:00
|
|
|
intel_map_bo(struct buffer *my_buf)
|
2014-06-12 18:26:49 +04:00
|
|
|
{
|
|
|
|
if (drm_intel_gem_bo_map_gtt(my_buf->bo) != 0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
my_buf->mmap = my_buf->bo->virtual;
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2017-04-26 16:47:18 +03:00
|
|
|
static int
|
|
|
|
intel_bo_export_to_prime(struct buffer *buffer)
|
|
|
|
{
|
|
|
|
return drm_intel_bo_gem_export_to_prime(buffer->bo, &buffer->dmabuf_fd);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
intel_unmap_bo(struct buffer *my_buf)
|
|
|
|
{
|
|
|
|
drm_intel_gem_bo_unmap_gtt(my_buf->bo);
|
|
|
|
}
|
|
|
|
#elif HAVE_LIBDRM_FREEDRENO
|
|
|
|
#define ALIGN(v, a) ((v + a - 1) & ~(a - 1))
|
|
|
|
|
|
|
|
static
|
|
|
|
int fd_alloc_bo(struct buffer *buf)
|
|
|
|
{
|
|
|
|
int flags = DRM_FREEDRENO_GEM_CACHE_WCOMBINE;
|
|
|
|
int size = buf->width * buf->height * buf->bpp / 8;
|
|
|
|
buf->fd_dev = fd_device_new(buf->drm_fd);
|
|
|
|
|
|
|
|
buf->bo = fd_bo_new(buf->fd_dev, size, flags);
|
|
|
|
|
|
|
|
if (!buf->bo)
|
|
|
|
return 0;
|
|
|
|
buf->stride = ALIGN(buf->width, 32) * buf->bpp / 8;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static
|
|
|
|
void fd_free_bo(struct buffer *buf)
|
|
|
|
{
|
|
|
|
fd_bo_del(buf->bo);
|
|
|
|
}
|
|
|
|
|
|
|
|
static
|
|
|
|
int fd_bo_export_to_prime(struct buffer *buf)
|
|
|
|
{
|
|
|
|
buf->dmabuf_fd = fd_bo_dmabuf(buf->bo);
|
|
|
|
if (buf->dmabuf_fd > 0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static
|
|
|
|
int fd_map_bo(struct buffer *buf)
|
|
|
|
{
|
|
|
|
buf->mmap = fd_bo_map(buf->bo);
|
|
|
|
|
|
|
|
if (buf->mmap != NULL)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static
|
|
|
|
void fd_unmap_bo(struct buffer *buf)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2014-06-12 18:26:49 +04:00
|
|
|
static void
|
|
|
|
fill_content(struct buffer *my_buf)
|
|
|
|
{
|
|
|
|
int x = 0, y = 0;
|
|
|
|
uint32_t *pix;
|
|
|
|
|
|
|
|
assert(my_buf->mmap);
|
|
|
|
|
2016-11-23 11:33:21 +03:00
|
|
|
if (my_buf->format == DRM_FORMAT_NV12) {
|
|
|
|
pix = (uint32_t *) my_buf->mmap;
|
|
|
|
for (y = 0; y < my_buf->height; y++)
|
|
|
|
memcpy(&pix[y * my_buf->width / 4],
|
|
|
|
&nv12_tiled[my_buf->width * y / 4],
|
|
|
|
my_buf->width);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
for (y = 0; y < my_buf->height; y++) {
|
|
|
|
pix = (uint32_t *)(my_buf->mmap + y * my_buf->stride);
|
|
|
|
for (x = 0; x < my_buf->width; x++)
|
|
|
|
*pix++ = (0xff << 24) | ((x % 256) << 16) |
|
|
|
|
((y % 256) << 8) | 0xf0;
|
2014-06-12 18:26:49 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2017-04-26 16:47:18 +03:00
|
|
|
drm_device_destroy(struct buffer *buf)
|
2014-06-12 18:26:49 +04:00
|
|
|
{
|
2017-04-26 16:47:18 +03:00
|
|
|
#ifdef HAVE_LIBDRM_INTEL
|
|
|
|
drm_intel_bufmgr_destroy(buf->bufmgr);
|
|
|
|
#elif HAVE_LIBDRM_FREEDRENO
|
|
|
|
fd_device_del(buf->fd_dev);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
close(buf->drm_fd);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
drm_device_init(struct buffer *buf)
|
|
|
|
{
|
|
|
|
struct drm_device *dev = calloc(1, sizeof(struct drm_device));
|
|
|
|
|
|
|
|
drmVersionPtr version = drmGetVersion(buf->drm_fd);
|
|
|
|
|
|
|
|
dev->fd = buf->drm_fd;
|
|
|
|
dev->name = strdup(version->name);
|
|
|
|
if (0) {
|
|
|
|
/* nothing */
|
|
|
|
}
|
|
|
|
#ifdef HAVE_LIBDRM_INTEL
|
|
|
|
else if (!strcmp(dev->name, "i915")) {
|
|
|
|
buf->bufmgr = drm_intel_bufmgr_gem_init(buf->drm_fd, 32);
|
|
|
|
if (!buf->bufmgr)
|
|
|
|
return 0;
|
|
|
|
dev->alloc_bo = intel_alloc_bo;
|
|
|
|
dev->free_bo = intel_free_bo;
|
|
|
|
dev->export_bo_to_prime = intel_bo_export_to_prime;
|
|
|
|
dev->map_bo = intel_map_bo;
|
|
|
|
dev->unmap_bo = intel_unmap_bo;
|
|
|
|
}
|
|
|
|
#elif HAVE_LIBDRM_FREEDRENO
|
|
|
|
else if (!strcmp(dev->name, "msm")) {
|
|
|
|
dev->alloc_bo = fd_alloc_bo;
|
|
|
|
dev->free_bo = fd_free_bo;
|
|
|
|
dev->export_bo_to_prime = fd_bo_export_to_prime;
|
|
|
|
dev->map_bo = fd_map_bo;
|
|
|
|
dev->unmap_bo = fd_unmap_bo;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
else {
|
|
|
|
fprintf(stderr, "Error: drm device %s unsupported.\n",
|
|
|
|
dev->name);
|
|
|
|
free(dev);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
buf->dev = dev;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
drm_connect(struct buffer *my_buf)
|
|
|
|
{
|
|
|
|
/* This won't work with card0 as we need to be authenticated; instead,
|
|
|
|
* boot with drm.rnodes=1 and use that. */
|
|
|
|
my_buf->drm_fd = open("/dev/dri/renderD128", O_RDWR);
|
|
|
|
if (my_buf->drm_fd < 0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return drm_device_init(my_buf);
|
2014-06-12 18:26:49 +04:00
|
|
|
}
|
|
|
|
|
2017-04-26 16:47:18 +03:00
|
|
|
static void
|
|
|
|
drm_shutdown(struct buffer *my_buf)
|
|
|
|
{
|
|
|
|
drm_device_destroy(my_buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-06-12 18:26:49 +04:00
|
|
|
static void
|
|
|
|
create_succeeded(void *data,
|
2015-11-17 11:00:28 +03:00
|
|
|
struct zwp_linux_buffer_params_v1 *params,
|
2014-06-12 18:26:49 +04:00
|
|
|
struct wl_buffer *new_buffer)
|
|
|
|
{
|
|
|
|
struct buffer *buffer = data;
|
|
|
|
|
|
|
|
buffer->buffer = new_buffer;
|
|
|
|
wl_buffer_add_listener(buffer->buffer, &buffer_listener, buffer);
|
|
|
|
|
2015-11-17 11:00:28 +03:00
|
|
|
zwp_linux_buffer_params_v1_destroy(params);
|
2014-06-12 18:26:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2015-11-17 11:00:28 +03:00
|
|
|
create_failed(void *data, struct zwp_linux_buffer_params_v1 *params)
|
2014-06-12 18:26:49 +04:00
|
|
|
{
|
|
|
|
struct buffer *buffer = data;
|
|
|
|
|
|
|
|
buffer->buffer = NULL;
|
2016-01-11 22:04:37 +03:00
|
|
|
running = 0;
|
2014-06-12 18:26:49 +04:00
|
|
|
|
2015-11-17 11:00:28 +03:00
|
|
|
zwp_linux_buffer_params_v1_destroy(params);
|
2014-06-12 18:26:49 +04:00
|
|
|
|
2015-11-17 11:00:28 +03:00
|
|
|
fprintf(stderr, "Error: zwp_linux_buffer_params.create failed.\n");
|
2014-06-12 18:26:49 +04:00
|
|
|
}
|
|
|
|
|
2015-11-17 11:00:28 +03:00
|
|
|
static const struct zwp_linux_buffer_params_v1_listener params_listener = {
|
2014-06-12 18:26:49 +04:00
|
|
|
create_succeeded,
|
|
|
|
create_failed
|
|
|
|
};
|
|
|
|
|
|
|
|
static int
|
|
|
|
create_dmabuf_buffer(struct display *display, struct buffer *buffer,
|
2016-11-23 11:33:21 +03:00
|
|
|
int width, int height, int format)
|
2014-06-12 18:26:49 +04:00
|
|
|
{
|
2015-11-17 11:00:28 +03:00
|
|
|
struct zwp_linux_buffer_params_v1 *params;
|
2016-11-23 11:33:21 +03:00
|
|
|
uint64_t modifier = 0;
|
2014-06-12 18:26:49 +04:00
|
|
|
uint32_t flags;
|
2017-04-26 16:47:18 +03:00
|
|
|
struct drm_device *drm_dev;
|
2014-06-12 18:26:49 +04:00
|
|
|
|
|
|
|
if (!drm_connect(buffer)) {
|
|
|
|
fprintf(stderr, "drm_connect failed\n");
|
|
|
|
goto error;
|
|
|
|
}
|
2017-04-26 16:47:18 +03:00
|
|
|
drm_dev = buffer->dev;
|
2014-06-12 18:26:49 +04:00
|
|
|
|
|
|
|
buffer->width = width;
|
2016-11-23 11:33:21 +03:00
|
|
|
switch (format) {
|
|
|
|
case DRM_FORMAT_NV12:
|
|
|
|
/* adjust height for allocation of NV12 Y and UV planes */
|
|
|
|
buffer->height = height * 3 / 2;
|
|
|
|
buffer->bpp = 8;
|
|
|
|
modifier = DRM_FORMAT_MOD_SAMSUNG_64_32_TILE;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
buffer->height = height;
|
|
|
|
buffer->bpp = 32;
|
|
|
|
}
|
|
|
|
buffer->format = format;
|
2014-06-12 18:26:49 +04:00
|
|
|
|
2017-04-26 16:47:18 +03:00
|
|
|
if (!drm_dev->alloc_bo(buffer)) {
|
2014-06-12 18:26:49 +04:00
|
|
|
fprintf(stderr, "alloc_bo failed\n");
|
|
|
|
goto error1;
|
|
|
|
}
|
|
|
|
|
2017-04-26 16:47:18 +03:00
|
|
|
if (!drm_dev->map_bo(buffer)) {
|
2014-06-12 18:26:49 +04:00
|
|
|
fprintf(stderr, "map_bo failed\n");
|
|
|
|
goto error2;
|
|
|
|
}
|
|
|
|
fill_content(buffer);
|
2017-04-26 16:47:18 +03:00
|
|
|
drm_dev->unmap_bo(buffer);
|
2014-06-12 18:26:49 +04:00
|
|
|
|
2017-04-26 16:47:18 +03:00
|
|
|
if (drm_dev->export_bo_to_prime(buffer) != 0) {
|
|
|
|
fprintf(stderr, "gem_export_to_prime failed\n");
|
2014-06-12 18:26:49 +04:00
|
|
|
goto error2;
|
|
|
|
}
|
|
|
|
if (buffer->dmabuf_fd < 0) {
|
|
|
|
fprintf(stderr, "error: dmabuf_fd < 0\n");
|
|
|
|
goto error2;
|
|
|
|
}
|
|
|
|
|
2016-11-23 11:33:21 +03:00
|
|
|
/* We now have a dmabuf! For format XRGB8888, it should contain 2x2
|
|
|
|
* tiles (i.e. each tile is 256x256) of misc colours, and be mappable,
|
|
|
|
* either as ARGB8888, or XRGB8888. For format NV12, it should contain
|
|
|
|
* the Y and UV components, and needs to be re-adjusted for passing the
|
|
|
|
* correct height to the compositor.
|
|
|
|
*/
|
|
|
|
buffer->height = height;
|
2014-06-12 18:26:49 +04:00
|
|
|
flags = 0;
|
|
|
|
|
2015-11-17 11:00:28 +03:00
|
|
|
params = zwp_linux_dmabuf_v1_create_params(display->dmabuf);
|
|
|
|
zwp_linux_buffer_params_v1_add(params,
|
|
|
|
buffer->dmabuf_fd,
|
|
|
|
0, /* plane_idx */
|
|
|
|
0, /* offset */
|
|
|
|
buffer->stride,
|
|
|
|
modifier >> 32,
|
|
|
|
modifier & 0xffffffff);
|
2016-11-23 11:33:21 +03:00
|
|
|
|
|
|
|
if (format == DRM_FORMAT_NV12) {
|
|
|
|
/* add the second plane params */
|
|
|
|
zwp_linux_buffer_params_v1_add(params,
|
|
|
|
buffer->dmabuf_fd,
|
|
|
|
1,
|
|
|
|
buffer->width * buffer->height,
|
|
|
|
buffer->stride,
|
|
|
|
modifier >> 32,
|
|
|
|
modifier & 0xffffffff);
|
|
|
|
}
|
2015-11-17 11:00:28 +03:00
|
|
|
zwp_linux_buffer_params_v1_add_listener(params, ¶ms_listener, buffer);
|
2017-04-26 16:46:00 +03:00
|
|
|
if (display->req_dmabuf_immediate) {
|
|
|
|
buffer->buffer = zwp_linux_buffer_params_v1_create_immed(params,
|
|
|
|
buffer->width,
|
|
|
|
buffer->height,
|
2016-11-23 11:33:21 +03:00
|
|
|
format,
|
2017-04-26 16:46:00 +03:00
|
|
|
flags);
|
|
|
|
wl_buffer_add_listener(buffer->buffer, &buffer_listener, buffer);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
zwp_linux_buffer_params_v1_create(params,
|
2015-11-17 11:00:28 +03:00
|
|
|
buffer->width,
|
|
|
|
buffer->height,
|
2016-11-23 11:33:21 +03:00
|
|
|
format,
|
2015-11-17 11:00:28 +03:00
|
|
|
flags);
|
2014-06-12 18:26:49 +04:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
error2:
|
2017-04-26 16:47:18 +03:00
|
|
|
drm_dev->free_bo(buffer);
|
2014-06-12 18:26:49 +04:00
|
|
|
error1:
|
|
|
|
drm_shutdown(buffer);
|
|
|
|
error:
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2016-08-11 18:44:41 +03:00
|
|
|
xdg_surface_handle_configure(void *data, struct zxdg_surface_v6 *surface,
|
|
|
|
uint32_t serial)
|
2014-06-12 18:26:49 +04:00
|
|
|
{
|
2016-08-11 18:44:41 +03:00
|
|
|
struct window *window = data;
|
|
|
|
|
|
|
|
zxdg_surface_v6_ack_configure(surface, serial);
|
|
|
|
|
|
|
|
if (window->initialized && window->wait_for_configure)
|
|
|
|
redraw(window, NULL, 0);
|
|
|
|
window->wait_for_configure = false;
|
2014-06-12 18:26:49 +04:00
|
|
|
}
|
|
|
|
|
2016-08-11 18:44:41 +03:00
|
|
|
static const struct zxdg_surface_v6_listener xdg_surface_listener = {
|
|
|
|
xdg_surface_handle_configure,
|
|
|
|
};
|
|
|
|
|
2014-06-12 18:26:49 +04:00
|
|
|
static void
|
2016-08-11 18:44:41 +03:00
|
|
|
xdg_toplevel_handle_configure(void *data, struct zxdg_toplevel_v6 *toplevel,
|
|
|
|
int32_t width, int32_t height,
|
|
|
|
struct wl_array *states)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
xdg_toplevel_handle_close(void *data, struct zxdg_toplevel_v6 *xdg_toplevel)
|
2014-06-12 18:26:49 +04:00
|
|
|
{
|
|
|
|
running = 0;
|
|
|
|
}
|
|
|
|
|
2016-08-11 18:44:41 +03:00
|
|
|
static const struct zxdg_toplevel_v6_listener xdg_toplevel_listener = {
|
|
|
|
xdg_toplevel_handle_configure,
|
|
|
|
xdg_toplevel_handle_close,
|
2014-06-12 18:26:49 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
static struct window *
|
2016-11-23 11:33:21 +03:00
|
|
|
create_window(struct display *display, int width, int height, int format)
|
2014-06-12 18:26:49 +04:00
|
|
|
{
|
|
|
|
struct window *window;
|
2016-01-11 22:04:37 +03:00
|
|
|
int i;
|
|
|
|
int ret;
|
2014-06-12 18:26:49 +04:00
|
|
|
|
2016-02-12 03:42:49 +03:00
|
|
|
window = zalloc(sizeof *window);
|
2014-06-12 18:26:49 +04:00
|
|
|
if (!window)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
window->callback = NULL;
|
|
|
|
window->display = display;
|
|
|
|
window->width = width;
|
|
|
|
window->height = height;
|
|
|
|
window->surface = wl_compositor_create_surface(display->compositor);
|
|
|
|
|
|
|
|
if (display->shell) {
|
|
|
|
window->xdg_surface =
|
2016-08-11 18:44:41 +03:00
|
|
|
zxdg_shell_v6_get_xdg_surface(display->shell,
|
|
|
|
window->surface);
|
2014-06-12 18:26:49 +04:00
|
|
|
|
|
|
|
assert(window->xdg_surface);
|
|
|
|
|
2016-08-11 18:44:41 +03:00
|
|
|
zxdg_surface_v6_add_listener(window->xdg_surface,
|
|
|
|
&xdg_surface_listener, window);
|
|
|
|
|
|
|
|
window->xdg_toplevel =
|
|
|
|
zxdg_surface_v6_get_toplevel(window->xdg_surface);
|
|
|
|
|
|
|
|
assert(window->xdg_toplevel);
|
2014-06-12 18:26:49 +04:00
|
|
|
|
2016-08-11 18:44:41 +03:00
|
|
|
zxdg_toplevel_v6_add_listener(window->xdg_toplevel,
|
|
|
|
&xdg_toplevel_listener, window);
|
|
|
|
|
|
|
|
zxdg_toplevel_v6_set_title(window->xdg_toplevel, "simple-dmabuf");
|
|
|
|
|
|
|
|
window->wait_for_configure = true;
|
|
|
|
wl_surface_commit(window->surface);
|
2014-06-12 18:26:49 +04:00
|
|
|
} else if (display->fshell) {
|
2015-11-17 11:00:27 +03:00
|
|
|
zwp_fullscreen_shell_v1_present_surface(display->fshell,
|
|
|
|
window->surface,
|
|
|
|
ZWP_FULLSCREEN_SHELL_V1_PRESENT_METHOD_DEFAULT,
|
|
|
|
NULL);
|
2014-06-12 18:26:49 +04:00
|
|
|
} else {
|
|
|
|
assert(0);
|
|
|
|
}
|
|
|
|
|
2016-06-10 13:13:01 +03:00
|
|
|
for (i = 0; i < NUM_BUFFERS; ++i) {
|
2016-01-11 22:04:37 +03:00
|
|
|
ret = create_dmabuf_buffer(display, &window->buffers[i],
|
2016-11-23 11:33:21 +03:00
|
|
|
width, height, format);
|
2016-01-11 22:04:37 +03:00
|
|
|
|
|
|
|
if (ret < 0)
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2014-06-12 18:26:49 +04:00
|
|
|
return window;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
destroy_window(struct window *window)
|
|
|
|
{
|
2017-04-26 16:47:18 +03:00
|
|
|
struct drm_device* dev;
|
2014-06-12 18:26:49 +04:00
|
|
|
int i;
|
|
|
|
|
|
|
|
if (window->callback)
|
|
|
|
wl_callback_destroy(window->callback);
|
|
|
|
|
2016-06-10 13:13:01 +03:00
|
|
|
for (i = 0; i < NUM_BUFFERS; i++) {
|
2014-06-12 18:26:49 +04:00
|
|
|
if (!window->buffers[i].buffer)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
wl_buffer_destroy(window->buffers[i].buffer);
|
2017-04-26 16:47:18 +03:00
|
|
|
dev = window->buffers[i].dev;
|
|
|
|
dev->free_bo(&window->buffers[i]);
|
2014-06-12 18:26:49 +04:00
|
|
|
close(window->buffers[i].dmabuf_fd);
|
|
|
|
drm_shutdown(&window->buffers[i]);
|
|
|
|
}
|
|
|
|
|
2016-08-11 18:44:41 +03:00
|
|
|
if (window->xdg_toplevel)
|
|
|
|
zxdg_toplevel_v6_destroy(window->xdg_toplevel);
|
2014-06-12 18:26:49 +04:00
|
|
|
if (window->xdg_surface)
|
2016-08-11 18:44:41 +03:00
|
|
|
zxdg_surface_v6_destroy(window->xdg_surface);
|
2014-06-12 18:26:49 +04:00
|
|
|
wl_surface_destroy(window->surface);
|
|
|
|
free(window);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct buffer *
|
|
|
|
window_next_buffer(struct window *window)
|
|
|
|
{
|
2016-06-10 13:13:01 +03:00
|
|
|
int i;
|
2014-06-12 18:26:49 +04:00
|
|
|
|
2016-06-10 13:13:01 +03:00
|
|
|
for (i = 0; i < NUM_BUFFERS; i++)
|
|
|
|
if (!window->buffers[i].busy)
|
|
|
|
return &window->buffers[i];
|
2014-06-12 18:26:49 +04:00
|
|
|
|
2016-06-10 13:13:01 +03:00
|
|
|
return NULL;
|
2014-06-12 18:26:49 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static const struct wl_callback_listener frame_listener;
|
|
|
|
|
|
|
|
static void
|
|
|
|
redraw(void *data, struct wl_callback *callback, uint32_t time)
|
|
|
|
{
|
|
|
|
struct window *window = data;
|
|
|
|
struct buffer *buffer;
|
|
|
|
|
|
|
|
buffer = window_next_buffer(window);
|
|
|
|
if (!buffer) {
|
|
|
|
fprintf(stderr,
|
|
|
|
!callback ? "Failed to create the first buffer.\n" :
|
2016-06-10 13:13:01 +03:00
|
|
|
"All buffers busy at redraw(). Server bug?\n");
|
2014-06-12 18:26:49 +04:00
|
|
|
abort();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* XXX: would be nice to draw something that changes here... */
|
|
|
|
|
|
|
|
wl_surface_attach(window->surface, buffer->buffer, 0, 0);
|
|
|
|
wl_surface_damage(window->surface, 0, 0, window->width, window->height);
|
|
|
|
|
|
|
|
if (callback)
|
|
|
|
wl_callback_destroy(callback);
|
|
|
|
|
|
|
|
window->callback = wl_surface_frame(window->surface);
|
|
|
|
wl_callback_add_listener(window->callback, &frame_listener, window);
|
|
|
|
wl_surface_commit(window->surface);
|
|
|
|
buffer->busy = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct wl_callback_listener frame_listener = {
|
|
|
|
redraw
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
2017-04-26 16:47:18 +03:00
|
|
|
dmabuf_modifiers(void *data, struct zwp_linux_dmabuf_v1 *zwp_linux_dmabuf,
|
|
|
|
uint32_t format, uint32_t modifier_hi, uint32_t modifier_lo)
|
2014-06-12 18:26:49 +04:00
|
|
|
{
|
|
|
|
struct display *d = data;
|
2016-11-23 11:33:21 +03:00
|
|
|
uint64_t modifier = ((uint64_t) modifier_hi << 32) | modifier_lo;
|
2014-06-12 18:26:49 +04:00
|
|
|
|
2016-11-23 11:33:21 +03:00
|
|
|
switch (format) {
|
|
|
|
case DRM_FORMAT_XRGB8888:
|
2014-06-12 18:26:49 +04:00
|
|
|
d->xrgb8888_format_found = 1;
|
2016-11-23 11:33:21 +03:00
|
|
|
break;
|
|
|
|
case DRM_FORMAT_NV12:
|
|
|
|
d->nv12_format_found = 1;
|
|
|
|
if (modifier == DRM_FORMAT_MOD_SAMSUNG_64_32_TILE)
|
|
|
|
d->nv12_modifier_found = 1;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2017-04-26 16:47:18 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
dmabuf_format(void *data, struct zwp_linux_dmabuf_v1 *zwp_linux_dmabuf, uint32_t format)
|
|
|
|
{
|
2016-11-23 11:33:21 +03:00
|
|
|
/* XXX: deprecated */
|
2014-06-12 18:26:49 +04:00
|
|
|
}
|
|
|
|
|
2015-11-17 11:00:28 +03:00
|
|
|
static const struct zwp_linux_dmabuf_v1_listener dmabuf_listener = {
|
2017-04-26 16:47:18 +03:00
|
|
|
dmabuf_format,
|
|
|
|
dmabuf_modifiers
|
2014-06-12 18:26:49 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
2016-08-11 18:44:41 +03:00
|
|
|
xdg_shell_ping(void *data, struct zxdg_shell_v6 *shell, uint32_t serial)
|
2014-06-12 18:26:49 +04:00
|
|
|
{
|
2016-08-11 18:44:41 +03:00
|
|
|
zxdg_shell_v6_pong(shell, serial);
|
2014-06-12 18:26:49 +04:00
|
|
|
}
|
|
|
|
|
2016-08-11 18:44:41 +03:00
|
|
|
static const struct zxdg_shell_v6_listener xdg_shell_listener = {
|
2014-06-12 18:26:49 +04:00
|
|
|
xdg_shell_ping,
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
registry_handle_global(void *data, struct wl_registry *registry,
|
|
|
|
uint32_t id, const char *interface, uint32_t version)
|
|
|
|
{
|
|
|
|
struct display *d = data;
|
|
|
|
|
|
|
|
if (strcmp(interface, "wl_compositor") == 0) {
|
|
|
|
d->compositor =
|
|
|
|
wl_registry_bind(registry,
|
|
|
|
id, &wl_compositor_interface, 1);
|
2016-08-11 18:44:41 +03:00
|
|
|
} else if (strcmp(interface, "zxdg_shell_v6") == 0) {
|
2014-06-12 18:26:49 +04:00
|
|
|
d->shell = wl_registry_bind(registry,
|
2016-08-11 18:44:41 +03:00
|
|
|
id, &zxdg_shell_v6_interface, 1);
|
|
|
|
zxdg_shell_v6_add_listener(d->shell, &xdg_shell_listener, d);
|
2015-11-17 11:00:27 +03:00
|
|
|
} else if (strcmp(interface, "zwp_fullscreen_shell_v1") == 0) {
|
2014-06-12 18:26:49 +04:00
|
|
|
d->fshell = wl_registry_bind(registry,
|
2015-11-17 11:00:27 +03:00
|
|
|
id, &zwp_fullscreen_shell_v1_interface, 1);
|
2015-11-17 11:00:28 +03:00
|
|
|
} else if (strcmp(interface, "zwp_linux_dmabuf_v1") == 0) {
|
2016-11-23 11:33:21 +03:00
|
|
|
int ver;
|
|
|
|
if (d->req_dmabuf_modifiers)
|
|
|
|
ver = 3;
|
|
|
|
else if (d->req_dmabuf_immediate)
|
|
|
|
ver = 2;
|
|
|
|
else
|
|
|
|
ver = 1;
|
2014-06-12 18:26:49 +04:00
|
|
|
d->dmabuf = wl_registry_bind(registry,
|
2017-04-26 16:46:00 +03:00
|
|
|
id, &zwp_linux_dmabuf_v1_interface,
|
2016-11-23 11:33:21 +03:00
|
|
|
ver);
|
2015-11-17 11:00:28 +03:00
|
|
|
zwp_linux_dmabuf_v1_add_listener(d->dmabuf, &dmabuf_listener, d);
|
2014-06-12 18:26:49 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
registry_handle_global_remove(void *data, struct wl_registry *registry,
|
|
|
|
uint32_t name)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct wl_registry_listener registry_listener = {
|
|
|
|
registry_handle_global,
|
|
|
|
registry_handle_global_remove
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct display *
|
2016-11-23 11:33:21 +03:00
|
|
|
create_display(int is_immediate, int format)
|
2014-06-12 18:26:49 +04:00
|
|
|
{
|
|
|
|
struct display *display;
|
2016-11-23 11:33:21 +03:00
|
|
|
const char *extensions;
|
2014-06-12 18:26:49 +04:00
|
|
|
|
|
|
|
display = malloc(sizeof *display);
|
|
|
|
if (display == NULL) {
|
|
|
|
fprintf(stderr, "out of memory\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
display->display = wl_display_connect(NULL);
|
|
|
|
assert(display->display);
|
|
|
|
|
2017-04-26 16:46:00 +03:00
|
|
|
display->req_dmabuf_immediate = is_immediate;
|
2016-11-23 11:33:21 +03:00
|
|
|
display->req_dmabuf_modifiers = (format == DRM_FORMAT_NV12);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* hard code format if the platform egl doesn't support format
|
|
|
|
* querying / advertising.
|
|
|
|
*/
|
|
|
|
extensions = eglQueryString(EGL_NO_DISPLAY, EGL_EXTENSIONS);
|
|
|
|
if (extensions && !weston_check_egl_extension(extensions,
|
|
|
|
"EGL_EXT_image_dma_buf_import_modifiers"))
|
|
|
|
display->xrgb8888_format_found = 1;
|
2014-06-12 18:26:49 +04:00
|
|
|
|
|
|
|
display->registry = wl_display_get_registry(display->display);
|
|
|
|
wl_registry_add_listener(display->registry,
|
|
|
|
®istry_listener, display);
|
|
|
|
wl_display_roundtrip(display->display);
|
|
|
|
if (display->dmabuf == NULL) {
|
2015-11-17 11:00:28 +03:00
|
|
|
fprintf(stderr, "No zwp_linux_dmabuf global\n");
|
2014-06-12 18:26:49 +04:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
wl_display_roundtrip(display->display);
|
|
|
|
|
2016-11-23 11:33:21 +03:00
|
|
|
if ((format == DRM_FORMAT_XRGB8888 && !display->xrgb8888_format_found) ||
|
|
|
|
(format == DRM_FORMAT_NV12 && (!display->nv12_format_found ||
|
|
|
|
!display->nv12_modifier_found))) {
|
|
|
|
fprintf(stderr, "requested format is not available\n");
|
2014-06-12 18:26:49 +04:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
return display;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
destroy_display(struct display *display)
|
|
|
|
{
|
|
|
|
if (display->dmabuf)
|
2015-11-17 11:00:28 +03:00
|
|
|
zwp_linux_dmabuf_v1_destroy(display->dmabuf);
|
2014-06-12 18:26:49 +04:00
|
|
|
|
|
|
|
if (display->shell)
|
2016-08-11 18:44:41 +03:00
|
|
|
zxdg_shell_v6_destroy(display->shell);
|
2014-06-12 18:26:49 +04:00
|
|
|
|
|
|
|
if (display->fshell)
|
2015-11-17 11:00:27 +03:00
|
|
|
zwp_fullscreen_shell_v1_release(display->fshell);
|
2014-06-12 18:26:49 +04:00
|
|
|
|
|
|
|
if (display->compositor)
|
|
|
|
wl_compositor_destroy(display->compositor);
|
|
|
|
|
|
|
|
wl_registry_destroy(display->registry);
|
|
|
|
wl_display_flush(display->display);
|
|
|
|
wl_display_disconnect(display->display);
|
|
|
|
free(display);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
signal_int(int signum)
|
|
|
|
{
|
|
|
|
running = 0;
|
|
|
|
}
|
|
|
|
|
2016-11-23 11:33:21 +03:00
|
|
|
static void
|
|
|
|
print_usage_and_exit(void)
|
|
|
|
{
|
|
|
|
printf("usage flags:\n"
|
|
|
|
"\t'--import-immediate=<>'\n\t\t0 to import dmabuf via roundtrip,"
|
|
|
|
"\n\t\t1 to enable import without roundtrip\n"
|
|
|
|
"\t'--import-format=<>'\n\t\tXRGB to import dmabuf as XRGB8888,"
|
|
|
|
"\n\t\tNV12 to import as multi plane NV12 with tiling modifier\n");
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
is_import_mode_immediate(const char* c)
|
|
|
|
{
|
|
|
|
if (!strcmp(c, "1"))
|
|
|
|
return 1;
|
|
|
|
else if (!strcmp(c, "0"))
|
|
|
|
return 0;
|
|
|
|
else
|
|
|
|
print_usage_and_exit();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
parse_import_format(const char* c)
|
|
|
|
{
|
|
|
|
if (!strcmp(c, "NV12"))
|
|
|
|
return DRM_FORMAT_NV12;
|
|
|
|
else if (!strcmp(c, "XRGB"))
|
|
|
|
return DRM_FORMAT_XRGB8888;
|
|
|
|
else
|
|
|
|
print_usage_and_exit();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-06-12 18:26:49 +04:00
|
|
|
int
|
|
|
|
main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
struct sigaction sigint;
|
|
|
|
struct display *display;
|
|
|
|
struct window *window;
|
2017-04-26 16:46:00 +03:00
|
|
|
int is_immediate = 0;
|
2016-11-23 11:33:21 +03:00
|
|
|
int import_format = DRM_FORMAT_XRGB8888;
|
|
|
|
int ret = 0, i = 0;
|
2014-06-12 18:26:49 +04:00
|
|
|
|
2017-04-26 16:46:00 +03:00
|
|
|
if (argc > 1) {
|
2016-11-23 11:33:21 +03:00
|
|
|
static const char import_mode[] = "--import-immediate=";
|
|
|
|
static const char format[] = "--import-format=";
|
|
|
|
for (i = 1; i < argc; i++) {
|
|
|
|
if (!strncmp(argv[i], import_mode,
|
|
|
|
sizeof(import_mode) - 1)) {
|
|
|
|
is_immediate = is_import_mode_immediate(argv[i]
|
|
|
|
+ sizeof(import_mode) - 1);
|
|
|
|
}
|
|
|
|
else if (!strncmp(argv[i], format, sizeof(format) - 1)) {
|
|
|
|
import_format = parse_import_format(argv[i]
|
|
|
|
+ sizeof(format) - 1);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
print_usage_and_exit();
|
|
|
|
}
|
2017-04-26 16:46:00 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-23 11:33:21 +03:00
|
|
|
display = create_display(is_immediate, import_format);
|
|
|
|
window = create_window(display, 256, 256, import_format);
|
2014-06-12 18:26:49 +04:00
|
|
|
if (!window)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
sigint.sa_handler = signal_int;
|
|
|
|
sigemptyset(&sigint.sa_mask);
|
|
|
|
sigint.sa_flags = SA_RESETHAND;
|
|
|
|
sigaction(SIGINT, &sigint, NULL);
|
|
|
|
|
2017-04-26 16:46:00 +03:00
|
|
|
/* Here we retrieve the linux-dmabuf objects if executed without immed,
|
|
|
|
* or error */
|
2016-01-11 22:04:37 +03:00
|
|
|
wl_display_roundtrip(display->display);
|
|
|
|
|
|
|
|
if (!running)
|
|
|
|
return 1;
|
2014-06-12 18:26:49 +04:00
|
|
|
|
2016-08-11 18:44:41 +03:00
|
|
|
window->initialized = true;
|
|
|
|
|
|
|
|
if (!window->wait_for_configure)
|
|
|
|
redraw(window, NULL, 0);
|
2014-06-12 18:26:49 +04:00
|
|
|
|
|
|
|
while (running && ret != -1)
|
|
|
|
ret = wl_display_dispatch(display->display);
|
|
|
|
|
|
|
|
fprintf(stderr, "simple-dmabuf exiting\n");
|
|
|
|
destroy_window(window);
|
|
|
|
destroy_display(display);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|