2 #include "hwcomposer_window.h"
11 #include <eglplatformcommon.h>
16 static int inited
= 0;
17 static gralloc_module_t
*gralloc
= 0;
18 static alloc_device_t
*alloc
= 0;
19 static HWComposerNativeWindow
*_nativewindow
= NULL
;
21 extern "C" int hwcomposerws_IsValidDisplay(EGLNativeDisplayType display
)
23 if (__sync_fetch_and_add(&inited
,1)==0)
26 err
= hw_get_module(GRALLOC_HARDWARE_MODULE_ID
, (const hw_module_t
**) &gralloc
);
28 fprintf(stderr
, "failed to get gralloc module: (%s)\n",strerror(-err
));
32 err
= gralloc_open((const hw_module_t
*) gralloc
, &alloc
);
34 fprintf(stderr
, "ERROR: failed to open gralloc: (%s)\n",strerror(-err
));
37 TRACE("** gralloc_open %p status=%s", gralloc
, strerror(-err
));
38 eglplatformcommon_init(gralloc
, alloc
);
41 return display
== EGL_DEFAULT_DISPLAY
;
44 extern "C" EGLNativeWindowType
hwcomposerws_CreateWindow(EGLNativeWindowType win
, EGLNativeDisplayType display
)
47 assert (_nativewindow
== NULL
);
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
);
56 extern "C" void hwcomposerws_DestroyWindow(EGLNativeWindowType win
)
58 assert (_nativewindow
!= NULL
);
59 assert (static_cast<HWComposerNativeWindow
*>((struct ANativeWindow
*)win
) == _nativewindow
);
61 _nativewindow
->common
.decRef(&_nativewindow
->common
);
62 /* We are done with it, refcounting will delete the window when appropriate */
66 extern "C" __eglMustCastToProperFunctionPointerType
hwcomposerws_eglGetProcAddress(const char *procname
)
68 return eglplatformcommon_eglGetProcAddress(procname
);
71 extern "C" void hwcomposerws_passthroughImageKHR(EGLContext
*ctx
, EGLenum
*target
, EGLClientBuffer
*buffer
, const EGLint
**attrib_list
)
73 eglplatformcommon_passthroughImageKHR(ctx
, target
, buffer
, attrib_list
);
76 struct ws_module ws_module_info
= {
77 hwcomposerws_IsValidDisplay
,
78 hwcomposerws_CreateWindow
,
79 hwcomposerws_DestroyWindow
,
80 hwcomposerws_eglGetProcAddress
,
81 hwcomposerws_passthroughImageKHR
,
82 eglplatformcommon_eglQueryString
85 // vim:ts=4:sw=4:noexpandtab