4 * Copyright (c) 2012 Samsung Electronics Co., Ltd. All rights reserved.
7 * Stanislav Vorobiov <s.vorobiov@samsung.com>
8 * Jinhyung Jo <jinhyung.jo@samsung.com>
9 * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
11 * Permission is hereby granted, free of charge, to any person obtaining a copy
12 * of this software and associated documentation files (the "Software"), to deal
13 * in the Software without restriction, including without limitation the rights
14 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15 * copies of the Software, and to permit persons to whom the Software is
16 * furnished to do so, subject to the following conditions:
18 * The above copyright notice and this permission notice shall be included in
19 * all copies or substantial portions of the Software.
21 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
34 #include "yagl_native_display.h"
36 #include "yagl_backend.h"
37 #ifdef YAGL_PLATFORM_WAYLAND
38 #include "wayland-drm.h"
41 #include "EGL/eglext.h"
42 #include "EGL/eglmesaext.h"
46 void yagl_native_display_init(struct yagl_native_display *dpy,
47 struct yagl_native_platform *platform,
48 yagl_os_display os_dpy,
49 struct vigs_drm_device *drm_dev,
50 const char *drm_dev_name)
52 dpy->platform = platform;
54 dpy->drm_dev = drm_dev;
56 dpy->drm_dev_name = strdup(drm_dev_name);
58 dpy->drm_dev_name = NULL;
60 #ifdef YAGL_PLATFORM_WAYLAND
61 dpy->WL_bind_wayland_display_supported = (drm_dev ? 1 : 0);
63 dpy->WL_bind_wayland_display_supported = 0;
67 void yagl_native_display_cleanup(struct yagl_native_display *dpy)
70 free(dpy->drm_dev_name);
71 dpy->drm_dev_name = NULL;
74 #ifdef YAGL_PLATFORM_WAYLAND
75 static int yagl_native_display_wl_authenticate(void *user_data,
78 struct yagl_native_display *dpy = user_data;
80 return dpy->authenticate(dpy, id);
83 static struct vigs_drm_surface
84 *yagl_native_display_wl_acquire_buffer(void *user_data, uint32_t name)
86 struct yagl_native_display *dpy = user_data;
87 struct vigs_drm_surface *drm_sfc;
90 YAGL_LOG_FUNC_SET(yagl_native_display_wl_acquire_buffer);
92 ret = vigs_drm_surface_open(dpy->drm_dev, name, &drm_sfc);
95 YAGL_LOG_ERROR("vigs_drm_surface_open failed for name %u: %s",
104 static struct wayland_drm_callbacks wl_drm_callbacks =
106 .authenticate = yagl_native_display_wl_authenticate,
107 .acquire_buffer = yagl_native_display_wl_acquire_buffer,
110 int yagl_native_display_bind_wl_display(struct yagl_native_display *dpy,
111 struct wl_display *wl_dpy)
113 if (dpy->wl_server_drm) {
117 dpy->wl_server_drm = wayland_drm_create(wl_dpy,
122 return dpy->wl_server_drm ? 1 : 0;
125 int yagl_native_display_unbind_wl_display(struct yagl_native_display *dpy)
127 if (!dpy->wl_server_drm) {
131 wayland_drm_destroy(dpy->wl_server_drm);
132 dpy->wl_server_drm = NULL;
137 int yagl_native_display_query_wl_buffer(struct yagl_native_display *dpy,
138 struct wl_resource *buffer,
142 struct wl_drm_buffer *drm_buffer = wayland_drm_get_buffer(buffer);
143 struct vigs_drm_surface *drm_sfc;
149 drm_sfc = wayland_drm_buffer_get_sfc(drm_buffer);
152 case EGL_TEXTURE_FORMAT:
153 switch (drm_sfc->format) {
154 case vigs_drm_surface_bgrx8888:
155 *value = EGL_TEXTURE_RGB;
157 case vigs_drm_surface_bgra8888:
158 *value = EGL_TEXTURE_RGBA;
165 *value = drm_sfc->width;
168 *value = drm_sfc->height;
170 case EGL_WAYLAND_Y_INVERTED_WL:
171 *value = yagl_get_backend()->y_inverted;