Imported Debian patch 0.1.0+git20131207+e452e83-0ubuntu12
[deb_libhybris.git] / server_wlegl_buffer.cpp
... / ...
CommitLineData
1/*
2 * Copyright © 2012 Collabora, Ltd.
3 *
4 * Permission to use, copy, modify, distribute, and sell this software and
5 * its documentation for any purpose is hereby granted without fee, provided
6 * that the above copyright notice appear in all copies and that both that
7 * copyright notice and this permission notice appear in supporting
8 * documentation, and that the name of the copyright holders not be used in
9 * advertising or publicity pertaining to distribution of the software
10 * without specific, written prior permission. The copyright holders make
11 * no representations about the suitability of this software for any
12 * purpose. It is provided "as is" without express or implied warranty.
13 *
14 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
15 * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
16 * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
17 * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
18 * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
19 * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
20 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
21 */
22
23#include <cstring>
24#include <cassert>
25
26#include "server_wlegl_buffer.h"
27#include "server_wlegl_private.h"
28
29static void
30destroy(struct wl_client *client, struct wl_resource *resource)
31{
32 wl_resource_destroy(resource);
33}
34
35static const struct wl_buffer_interface server_wlegl_buffer_impl = {
36 destroy
37};
38
39server_wlegl_buffer *
40server_wlegl_buffer_from(struct wl_buffer *buffer)
41{
42 if (buffer->resource.object.implementation !=
43 (void (**)(void)) &server_wlegl_buffer_impl)
44 return NULL;
45
46 return container_of(buffer, server_wlegl_buffer, base);
47}
48
49static void
50server_wlegl_buffer_dtor(struct wl_resource *resource)
51{
52 struct wl_buffer *base =
53 reinterpret_cast<struct wl_buffer*>(resource->data);
54 server_wlegl_buffer *buffer = server_wlegl_buffer_from(base);
55 buffer->buf->common.decRef(&buffer->buf->common);
56 delete buffer;
57}
58
59server_wlegl_buffer *
60server_wlegl_buffer_create(uint32_t id,
61 int32_t width,
62 int32_t height,
63 int32_t stride,
64 int32_t format,
65 int32_t usage,
66 buffer_handle_t handle,
67 server_wlegl *wlegl)
68{
69 server_wlegl_buffer *buffer = new server_wlegl_buffer;
70 int ret;
71
72 memset(buffer, 0, sizeof(*buffer));
73
74 buffer->wlegl = wlegl;
75
76 buffer->base.resource.object.id = id;
77 buffer->base.resource.object.interface = &wl_buffer_interface;
78 buffer->base.resource.object.implementation =
79 (void (**)(void)) &server_wlegl_buffer_impl;
80
81 buffer->base.resource.data = &buffer->base;
82 buffer->base.resource.destroy = server_wlegl_buffer_dtor;
83
84 buffer->base.width = width;
85 buffer->base.height = height;
86
87 ret = wlegl->gralloc->registerBuffer(wlegl->gralloc, handle);
88 if (ret) {
89 delete buffer;
90 return NULL;
91 }
92
93 buffer->buf = new RemoteWindowBuffer(
94 width, height, stride, format, usage, handle, wlegl->gralloc);
95 buffer->buf->common.incRef(&buffer->buf->common);
96 return buffer;
97}
98