Imported Upstream version 0.1.0+git20131207+e452e83
[deb_libhybris.git] / hybris / egl / platforms / wayland / eglplatform_wayland.cpp
1 /****************************************************************************************
2 **
3 ** Copyright (C) 2013 Jolla Ltd.
4 ** Contact: Carsten Munk <carsten.munk@jollamobile.com>
5 ** All rights reserved.
6 **
7 ** This file is part of Wayland enablement for libhybris
8 **
9 ** You may use this file under the terms of the GNU Lesser General
10 ** Public License version 2.1 as published by the Free Software Foundation
11 ** and appearing in the file license.lgpl included in the packaging
12 ** of this file.
13 **
14 ** This library is free software; you can redistribute it and/or
15 ** modify it under the terms of the GNU Lesser General Public
16 ** License version 2.1 as published by the Free Software Foundation
17 ** and appearing in the file license.lgpl included in the packaging
18 ** of this file.
19 **
20 ** This library is distributed in the hope that it will be useful,
21 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
22 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23 ** Lesser General Public License for more details.
24 **
25 ****************************************************************************************/
26
27 #include <ws.h>
28 #include <malloc.h>
29 #include <assert.h>
30 #include <fcntl.h>
31 #include <stdio.h>
32 #include <sys/stat.h>
33 #include <unistd.h>
34 #include <assert.h>
35 extern "C" {
36 #include <eglplatformcommon.h>
37 };
38
39 extern "C" {
40 #include <wayland-client.h>
41 #include <wayland-egl.h>
42 }
43
44 #include "wayland_window.h"
45 #include "logging.h"
46 #include "wayland-egl-priv.h"
47
48 static int inited = 0;
49 static gralloc_module_t *gralloc = 0;
50 static alloc_device_t *alloc = 0;
51
52 extern "C" int waylandws_IsValidDisplay(EGLNativeDisplayType display)
53 {
54 int err;
55 if ( __sync_fetch_and_add(&inited,1)==0)
56 {
57 hw_get_module(GRALLOC_HARDWARE_MODULE_ID, (const hw_module_t **) &gralloc);
58 err = gralloc_open((const hw_module_t *) gralloc, &alloc);
59 TRACE("++ %lu wayland: got gralloc %p err:%s", pthread_self(), gralloc, strerror(-err));
60 eglplatformcommon_init(gralloc, alloc);
61 }
62
63 return 1;
64 }
65
66 extern "C" EGLNativeWindowType waylandws_CreateWindow(EGLNativeWindowType win, EGLNativeDisplayType display)
67 {
68 WaylandNativeWindow *window = new WaylandNativeWindow((struct wl_egl_window *) win, (struct wl_display *) display, gralloc, alloc);
69 window->common.incRef(&window->common);
70 return (EGLNativeWindowType) static_cast<struct ANativeWindow *>(window);
71 }
72
73 extern "C" void waylandws_DestroyWindow(EGLNativeWindowType win)
74 {
75 WaylandNativeWindow *window = static_cast<WaylandNativeWindow *>((struct ANativeWindow *)win);
76 window->common.decRef(&window->common);
77 }
78
79 extern "C" int waylandws_post(EGLNativeWindowType win, void *buffer)
80 {
81 struct wl_egl_window *eglwin = (struct wl_egl_window *) win;
82
83 return ((WaylandNativeWindow *) eglwin->nativewindow)->postBuffer((ANativeWindowBuffer *) buffer);
84 }
85
86 extern "C" __eglMustCastToProperFunctionPointerType waylandws_eglGetProcAddress(const char *procname)
87 {
88 if (strcmp(procname, "eglHybrisWaylandPostBuffer") == 0)
89 {
90 return (__eglMustCastToProperFunctionPointerType) waylandws_post;
91 }
92 else
93 return eglplatformcommon_eglGetProcAddress(procname);
94 }
95
96 extern "C" void waylandws_passthroughImageKHR(EGLContext *ctx, EGLenum *target, EGLClientBuffer *buffer, const EGLint **attrib_list)
97 {
98 eglplatformcommon_passthroughImageKHR(ctx, target, buffer, attrib_list);
99 }
100
101 struct ws_module ws_module_info = {
102 waylandws_IsValidDisplay,
103 waylandws_CreateWindow,
104 waylandws_DestroyWindow,
105 waylandws_eglGetProcAddress,
106 waylandws_passthroughImageKHR,
107 eglplatformcommon_eglQueryString
108 };
109
110
111
112
113
114
115