1 /****************************************************************************************
3 ** Copyright (C) 2013 Jolla Ltd.
4 ** Contact: Carsten Munk <carsten.munk@jollamobile.com>
5 ** All rights reserved.
7 ** This file is part of Wayland enablement for libhybris
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
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
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.
25 ****************************************************************************************/
36 #include <eglplatformcommon.h>
40 #include <wayland-client.h>
41 #include <wayland-egl.h>
44 #include "wayland_window.h"
46 #include "wayland-egl-priv.h"
48 static int inited
= 0;
49 static gralloc_module_t
*gralloc
= 0;
50 static alloc_device_t
*alloc
= 0;
52 extern "C" int waylandws_IsValidDisplay(EGLNativeDisplayType display
)
55 if ( __sync_fetch_and_add(&inited
,1)==0)
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
);
66 extern "C" EGLNativeWindowType
waylandws_CreateWindow(EGLNativeWindowType win
, EGLNativeDisplayType display
)
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
);
73 extern "C" void waylandws_DestroyWindow(EGLNativeWindowType win
)
75 WaylandNativeWindow
*window
= static_cast<WaylandNativeWindow
*>((struct ANativeWindow
*)win
);
76 window
->common
.decRef(&window
->common
);
79 extern "C" int waylandws_post(EGLNativeWindowType win
, void *buffer
)
81 struct wl_egl_window
*eglwin
= (struct wl_egl_window
*) win
;
83 return ((WaylandNativeWindow
*) eglwin
->nativewindow
)->postBuffer((ANativeWindowBuffer
*) buffer
);
86 extern "C" __eglMustCastToProperFunctionPointerType
waylandws_eglGetProcAddress(const char *procname
)
88 if (strcmp(procname
, "eglHybrisWaylandPostBuffer") == 0)
90 return (__eglMustCastToProperFunctionPointerType
) waylandws_post
;
93 return eglplatformcommon_eglGetProcAddress(procname
);
96 extern "C" void waylandws_passthroughImageKHR(EGLContext
*ctx
, EGLenum
*target
, EGLClientBuffer
*buffer
, const EGLint
**attrib_list
)
98 eglplatformcommon_passthroughImageKHR(ctx
, target
, buffer
, attrib_list
);
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