2 * Copyright (C) 2012 Texas Instruments
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
25 * Rob Clark <rob.clark@linaro.org>
28 /* This is an example/skeletal backend implementation.. this file isn't
29 * actually built as part of libgbm, but just intended to be a template
30 * to help in creating a new gbm backend
40 #include <sys/types.h>
45 #include "common_drm.h"
47 struct gbm_example_device {
48 struct gbm_drm_device base;
49 /* add whatever you need here */
52 struct gbm_example_bo {
53 struct gbm_drm_bo base;
54 /* add whatever you need here */
59 gles_init(struct gbm_example_device *dev)
61 /* this should open/initialize the GLES stack.. for a DRM driver
62 * at least, dev->base.base.fd will have the already opened device
68 gbm_example_is_format_supported(struct gbm_device *gbm,
69 enum gbm_bo_format format, uint32_t usage)
75 gbm_example_bo_destroy(struct gbm_bo *_bo)
79 static struct gbm_bo *
80 gbm_example_bo_create_from_egl_image(struct gbm_device *gbm, void *egl_dpy,
81 void *egl_img, uint32_t width, uint32_t height, uint32_t usage)
83 /* eglimg is created w/ (see weston_buffer_attach()):
85 * struct wl_buffer *buffer = ...;
86 * eglCreateImageKHR(display, NULL, EGL_WAYLAND_BUFFER_WL, buffer, NULL);
92 static struct gbm_bo *
93 gbm_example_bo_create(struct gbm_device *gbm, uint32_t width, uint32_t height,
94 enum gbm_bo_format format, uint32_t usage)
100 gbm_example_destroy(struct gbm_device *gbm)
104 static struct gbm_device *
105 example_device_create(int fd)
107 struct gbm_example_device *dev;
110 dev = calloc(1, sizeof *dev);
112 dev->base.base.fd = fd;
113 dev->base.base.bo_create = gbm_example_bo_create;
114 dev->base.base.bo_create_from_egl_image = gbm_example_bo_create_from_egl_image;
115 dev->base.base.is_format_supported = gbm_example_is_format_supported;
116 dev->base.base.bo_destroy = gbm_example_bo_destroy;
117 dev->base.base.destroy = gbm_example_destroy;
119 dev->base.type = GBM_DRM_DRIVER_TYPE_CUSTOM;
120 dev->base.base.name = "example";
122 ret = gles_init(dev);
128 return &dev->base.base;
131 /* backend loader looks for symbol "gbm_backend" */
132 struct gbm_backend gbm_backend = {
133 .backend_name = "example",
134 .create_device = example_device_create,