Imported Upstream version 0.1.0+git20131207+e452e83
[deb_libhybris.git] / hybris / egl / platforms / hwcomposer / eglplatform_hwcomposer.cpp
CommitLineData
d42e7319
JB
1#include <ws.h>
2#include "hwcomposer_window.h"
3#include <malloc.h>
4#include <assert.h>
5#include <fcntl.h>
6#include <stdio.h>
7#include <sys/stat.h>
8#include <unistd.h>
9#include <assert.h>
10extern "C" {
11#include <eglplatformcommon.h>
12};
13
14#include "logging.h"
15
16static int inited = 0;
17static gralloc_module_t *gralloc = 0;
18static alloc_device_t *alloc = 0;
19static HWComposerNativeWindow *_nativewindow = NULL;
20
21extern "C" int hwcomposerws_IsValidDisplay(EGLNativeDisplayType display)
22{
23 if (__sync_fetch_and_add(&inited,1)==0)
24 {
25 int err;
26 err = hw_get_module(GRALLOC_HARDWARE_MODULE_ID, (const hw_module_t **) &gralloc);
27 if (gralloc==NULL) {
28 fprintf(stderr, "failed to get gralloc module: (%s)\n",strerror(-err));
29 assert(0);
30 }
31
32 err = gralloc_open((const hw_module_t *) gralloc, &alloc);
33 if (err) {
34 fprintf(stderr, "ERROR: failed to open gralloc: (%s)\n",strerror(-err));
35 assert(0);
36 }
37 TRACE("** gralloc_open %p status=%s", gralloc, strerror(-err));
38 eglplatformcommon_init(gralloc, alloc);
39 }
40
41 return display == EGL_DEFAULT_DISPLAY;
42}
43
44extern "C" EGLNativeWindowType hwcomposerws_CreateWindow(EGLNativeWindowType win, EGLNativeDisplayType display)
45{
46 assert (inited >= 1);
47 assert (_nativewindow == NULL);
48
49 HWComposerNativeWindow *window = static_cast<HWComposerNativeWindow *>((ANativeWindow *) win);
50 window->setup(gralloc, alloc);
51 _nativewindow = window;
52 _nativewindow->common.incRef(&_nativewindow->common);
53 return (EGLNativeWindowType) static_cast<struct ANativeWindow *>(_nativewindow);
54}
55
56extern "C" void hwcomposerws_DestroyWindow(EGLNativeWindowType win)
57{
58 assert (_nativewindow != NULL);
59 assert (static_cast<HWComposerNativeWindow *>((struct ANativeWindow *)win) == _nativewindow);
60
61 _nativewindow->common.decRef(&_nativewindow->common);
62 /* We are done with it, refcounting will delete the window when appropriate */
63 _nativewindow = NULL;
64}
65
66extern "C" __eglMustCastToProperFunctionPointerType hwcomposerws_eglGetProcAddress(const char *procname)
67{
68 return eglplatformcommon_eglGetProcAddress(procname);
69}
70
71extern "C" void hwcomposerws_passthroughImageKHR(EGLContext *ctx, EGLenum *target, EGLClientBuffer *buffer, const EGLint **attrib_list)
72{
73 eglplatformcommon_passthroughImageKHR(ctx, target, buffer, attrib_list);
74}
75
76struct ws_module ws_module_info = {
77 hwcomposerws_IsValidDisplay,
78 hwcomposerws_CreateWindow,
79 hwcomposerws_DestroyWindow,
80 hwcomposerws_eglGetProcAddress,
81 hwcomposerws_passthroughImageKHR,
82 eglplatformcommon_eglQueryString
83};
84
85// vim:ts=4:sw=4:noexpandtab