Exemple #1
0
Fichier : drm.c Projet : ibab/swc
static void create_prime_buffer(struct wl_client * client,
                                struct wl_resource * resource, uint32_t id,
                                int32_t fd, int32_t width, int32_t height,
                                uint32_t format,
                                int32_t offset0, int32_t stride0,
                                int32_t offset1, int32_t stride1,
                                int32_t offset2, int32_t stride2)
{
    struct wld_buffer * buffer;
    struct wl_resource * buffer_resource;
    union wld_object object = { .i = fd };

    buffer = wld_import_buffer(swc.drm->context, WLD_DRM_OBJECT_PRIME_FD,
                               object, width, height, format, stride0);
    close(fd);

    if (!buffer)
        goto error0;

    buffer_resource = swc_wayland_buffer_create_resource
        (client, wl_resource_get_version(resource), id, buffer);

    if (!buffer_resource)
        goto error1;

    return;

  error1:
    wld_buffer_unreference(buffer);
  error0:
    wl_resource_post_no_memory(resource);
}
Exemple #2
0
static void create_buffer(struct wl_client * client,
                          struct wl_resource * resource, uint32_t id,
                          int32_t offset, int32_t width, int32_t height,
                          int32_t stride, uint32_t format)
{
    struct pool * pool = wl_resource_get_user_data(resource);
    struct pool_reference * reference;
    struct wld_buffer * buffer;
    struct wl_resource * buffer_resource;
    union wld_object object;

    if (offset > pool->size || offset < 0)
    {
        wl_resource_post_error(resource, WL_SHM_ERROR_INVALID_STRIDE,
                               "offset is too big or negative");
        return;
    }

    object.ptr = (void *)((uintptr_t) pool->data + offset);
    buffer = wld_import_buffer(swc.shm->context, WLD_OBJECT_DATA, object,
                               width, height, format_shm_to_wld(format),
                               stride);

    if (!buffer)
        goto error0;

    buffer_resource = wayland_buffer_create_resource
        (client, wl_resource_get_version(resource), id, buffer);

    if (!buffer_resource)
        goto error1;

    if (!(reference = malloc(sizeof *reference)))
        goto error2;

    reference->pool = pool;
    reference->destructor.destroy = &handle_buffer_destroy;
    wld_buffer_add_destructor(buffer, &reference->destructor);
    ++pool->references;

    return;

  error2:
    wl_resource_destroy(buffer_resource);
  error1:
    wld_buffer_unreference(buffer);
  error0:
    wl_resource_post_no_memory(resource);
}
Exemple #3
0
static void destroy_buffer(struct wl_resource * resource)
{
    struct wld_buffer * buffer = wl_resource_get_user_data(resource);

    wld_buffer_unreference(buffer);
}