2 #include "fbdev_window.h"
11 #include <eglplatformcommon.h>
16 static int inited
= 0;
17 static gralloc_module_t
*gralloc
= 0;
18 static framebuffer_device_t
*framebuffer
= 0;
19 static alloc_device_t
*alloc
= 0;
20 static FbDevNativeWindow
*_nativewindow
= NULL
;
22 extern "C" int fbdevws_IsValidDisplay(EGLNativeDisplayType display
)
24 if (__sync_fetch_and_add(&inited
,1)==0)
27 err
= hw_get_module(GRALLOC_HARDWARE_MODULE_ID
, (const hw_module_t
**) &gralloc
);
29 fprintf(stderr
, "failed to get gralloc module: (%s)\n",strerror(-err
));
33 err
= framebuffer_open((hw_module_t
*) gralloc
, &framebuffer
);
35 fprintf(stderr
, "ERROR: failed to open framebuffer: (%s)\n",strerror(-err
));
38 TRACE("** framebuffer_open: status=(%s) format=x%x", strerror(-err
), framebuffer
->format
);
40 err
= gralloc_open((const hw_module_t
*) gralloc
, &alloc
);
42 fprintf(stderr
, "ERROR: failed to open gralloc: (%s)\n",strerror(-err
));
45 TRACE("** gralloc_open %p status=%s", gralloc
, strerror(-err
));
46 eglplatformcommon_init(gralloc
, alloc
);
49 return display
== EGL_DEFAULT_DISPLAY
;
52 extern "C" EGLNativeWindowType
fbdevws_CreateWindow(EGLNativeWindowType win
, EGLNativeDisplayType display
)
55 assert (_nativewindow
== NULL
);
57 _nativewindow
= new FbDevNativeWindow(gralloc
, alloc
, framebuffer
);
58 _nativewindow
->common
.incRef(&_nativewindow
->common
);
59 return (EGLNativeWindowType
) static_cast<struct ANativeWindow
*>(_nativewindow
);
62 extern "C" void fbdevws_DestroyWindow(EGLNativeWindowType win
)
64 assert (_nativewindow
!= NULL
);
65 assert (static_cast<FbDevNativeWindow
*>((struct ANativeWindow
*)win
) == _nativewindow
);
67 _nativewindow
->common
.decRef(&_nativewindow
->common
);
68 /* We are done with it, refcounting will delete the window when appropriate */
72 extern "C" __eglMustCastToProperFunctionPointerType
fbdevws_eglGetProcAddress(const char *procname
)
74 return eglplatformcommon_eglGetProcAddress(procname
);
77 extern "C" void fbdevws_passthroughImageKHR(EGLContext
*ctx
, EGLenum
*target
, EGLClientBuffer
*buffer
, const EGLint
**attrib_list
)
79 eglplatformcommon_passthroughImageKHR(ctx
, target
, buffer
, attrib_list
);
82 struct ws_module ws_module_info
= {
83 fbdevws_IsValidDisplay
,
85 fbdevws_DestroyWindow
,
86 fbdevws_eglGetProcAddress
,
87 fbdevws_passthroughImageKHR
,
88 eglplatformcommon_eglQueryString
91 // vim:ts=4:sw=4:noexpandtab