Imported Upstream version 0.1.0+git20131207+e452e83
[deb_libhybris.git] / hybris / egl / platforms / fbdev / eglplatform_fbdev.cpp
CommitLineData
d42e7319
JB
1#include <ws.h>
2#include "fbdev_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 framebuffer_device_t *framebuffer = 0;
19static alloc_device_t *alloc = 0;
20static FbDevNativeWindow *_nativewindow = NULL;
21
22extern "C" int fbdevws_IsValidDisplay(EGLNativeDisplayType display)
23{
24 if (__sync_fetch_and_add(&inited,1)==0)
25 {
26 int err;
27 err = hw_get_module(GRALLOC_HARDWARE_MODULE_ID, (const hw_module_t **) &gralloc);
28 if (gralloc==NULL) {
29 fprintf(stderr, "failed to get gralloc module: (%s)\n",strerror(-err));
30 assert(0);
31 }
32
33 err = framebuffer_open((hw_module_t *) gralloc, &framebuffer);
34 if (err) {
35 fprintf(stderr, "ERROR: failed to open framebuffer: (%s)\n",strerror(-err));
36 assert(0);
37 }
38 TRACE("** framebuffer_open: status=(%s) format=x%x", strerror(-err), framebuffer->format);
39
40 err = gralloc_open((const hw_module_t *) gralloc, &alloc);
41 if (err) {
42 fprintf(stderr, "ERROR: failed to open gralloc: (%s)\n",strerror(-err));
43 assert(0);
44 }
45 TRACE("** gralloc_open %p status=%s", gralloc, strerror(-err));
46 eglplatformcommon_init(gralloc, alloc);
47 }
48
49 return display == EGL_DEFAULT_DISPLAY;
50}
51
52extern "C" EGLNativeWindowType fbdevws_CreateWindow(EGLNativeWindowType win, EGLNativeDisplayType display)
53{
54 assert (inited >= 1);
55 assert (_nativewindow == NULL);
56
57 _nativewindow = new FbDevNativeWindow(gralloc, alloc, framebuffer);
58 _nativewindow->common.incRef(&_nativewindow->common);
59 return (EGLNativeWindowType) static_cast<struct ANativeWindow *>(_nativewindow);
60}
61
62extern "C" void fbdevws_DestroyWindow(EGLNativeWindowType win)
63{
64 assert (_nativewindow != NULL);
65 assert (static_cast<FbDevNativeWindow *>((struct ANativeWindow *)win) == _nativewindow);
66
67 _nativewindow->common.decRef(&_nativewindow->common);
68 /* We are done with it, refcounting will delete the window when appropriate */
69 _nativewindow = NULL;
70}
71
72extern "C" __eglMustCastToProperFunctionPointerType fbdevws_eglGetProcAddress(const char *procname)
73{
74 return eglplatformcommon_eglGetProcAddress(procname);
75}
76
77extern "C" void fbdevws_passthroughImageKHR(EGLContext *ctx, EGLenum *target, EGLClientBuffer *buffer, const EGLint **attrib_list)
78{
79 eglplatformcommon_passthroughImageKHR(ctx, target, buffer, attrib_list);
80}
81
82struct ws_module ws_module_info = {
83 fbdevws_IsValidDisplay,
84 fbdevws_CreateWindow,
85 fbdevws_DestroyWindow,
86 fbdevws_eglGetProcAddress,
87 fbdevws_passthroughImageKHR,
88 eglplatformcommon_eglQueryString
89};
90
91// vim:ts=4:sw=4:noexpandtab