Switch from GEM to PRIME.
[platform/upstream/libgbm.git] / backend_example.c
1 /*
2  * Copyright (C) 2012 Texas Instruments
3  *
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:
10  *
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
13  * Software.
14  *
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.
23  *
24  * Authors:
25  *    Rob Clark <rob.clark@linaro.org>
26  */
27
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
31  */
32
33 #include <stdio.h>
34 #include <stdlib.h>
35 #include <stddef.h>
36 #include <stdint.h>
37 #include <string.h>
38 #include <limits.h>
39
40 #include <sys/types.h>
41 #include <unistd.h>
42 #include <dlfcn.h>
43
44 #include "gbmint.h"
45 #include "common_drm.h"
46
47 struct gbm_example_device {
48    struct gbm_drm_device base;
49    /* add whatever you need here */
50 };
51
52 struct gbm_example_bo {
53    struct gbm_drm_bo base;
54    /* add whatever you need here */
55 };
56
57
58 static int
59 gles_init(struct gbm_example_device *dev)
60 {
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
63     */
64    return 0;
65 }
66
67 static int
68 gbm_example_is_format_supported(struct gbm_device *gbm,
69       enum gbm_bo_format format, uint32_t usage)
70 {
71    return 0;
72 }
73
74 static void
75 gbm_example_bo_destroy(struct gbm_bo *_bo)
76 {
77 }
78
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)
82 {
83    /* eglimg is created w/  (see weston_buffer_attach()):
84     *
85     *   struct wl_buffer *buffer = ...;
86     *   eglCreateImageKHR(display, NULL, EGL_WAYLAND_BUFFER_WL, buffer, NULL);
87     */
88
89    return NULL;
90 }
91
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)
95 {
96    return NULL;
97 }
98
99 static void
100 gbm_example_destroy(struct gbm_device *gbm)
101 {
102 }
103
104 static struct gbm_device *
105 example_device_create(int fd)
106 {
107    struct gbm_example_device *dev;
108    int ret;
109
110    dev = calloc(1, sizeof *dev);
111
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;
118
119    dev->base.type = GBM_DRM_DRIVER_TYPE_CUSTOM;
120    dev->base.base.name = "example";
121
122    ret = gles_init(dev);
123    if (ret) {
124       free(dev);
125       return NULL;
126    }
127
128    return &dev->base.base;
129 }
130
131 /* backend loader looks for symbol "gbm_backend" */
132 struct gbm_backend gbm_backend = {
133    .backend_name = "example",
134    .create_device = example_device_create,
135 };