@@ -27,7 +27,9 @@
#include "plugin-api.h"
#include <system/window.h>
+#include <hardware/gralloc.h>
#include <hardware/fb.h>
+#include <hardware/hwcomposer.h>
/* ========================================================================= *
* PROTOTYPES
@@ -40,9 +42,6 @@
bool hybris_plugin_fb_load (void);
void hybris_plugin_fb_unload (void);
-static int hybris_plugin_fb_open_device (struct framebuffer_device_t **pdevice);
-static void hybris_plugin_fb_close_device (struct framebuffer_device_t **pdevice);
-
/* ------------------------------------------------------------------------- *
* FRAMEBUFFER_DEVICE
* ------------------------------------------------------------------------- */
@@ -58,6 +57,9 @@
/** Handle for libhybris framebuffer plugin */
static const struct hw_module_t *hybris_plugin_fb_handle = 0;
+/** Handle for libhybris hw composer plugin */
+static const struct hw_module_t *hybris_plugin_hwc_handle = 0;
+
/** Load libhybris framebuffer plugin
*
* @return true on success, false on failure
@@ -73,19 +75,33 @@
done = true;
- hw_get_module(GRALLOC_HARDWARE_FB0, &hybris_plugin_fb_handle);
-
+ /* Load framebuffer module */
+ hw_get_module(GRALLOC_HARDWARE_MODULE_ID, &hybris_plugin_fb_handle);
if( !hybris_plugin_fb_handle ) {
- mce_log(LL_WARN, "failed to open frame buffer module");
- goto cleanup;
+ mce_log(LL_DEBUG, "failed to open frame buffer module");
}
- mce_log(LL_DEBUG, "hybris_plugin_fb_handle = %p",
- hybris_plugin_fb_handle);
+ /* Load hw composer module */
+#ifdef HWC_DEVICE_API_VERSION_1_0
+ hw_get_module(HWC_HARDWARE_MODULE_ID, &hybris_plugin_hwc_handle);
+ if( !hybris_plugin_hwc_handle ) {
+ mce_log(LL_DEBUG, "failed to open hw composer module");
+ }
+#else
+ /* When compiling with really old hwcompser.h in place, assume
+ * that the target device is not going to have the hwc methods we
+ * are interested in -> skip module load -> hwc device loading and
+ * related cleanup turns into a nop without further #ifdeffing.
+ */
+#endif
+
+ /* Both fb and hwc are optional, but having neither is unexpected */
+ if( !hybris_plugin_fb_handle && !hybris_plugin_hwc_handle ) {
+ mce_log(LL_WARN, "could not open neither fb nor hwc module");
+ }
cleanup:
-
- return hybris_plugin_fb_handle != 0;
+ return hybris_plugin_fb_handle || hybris_plugin_hwc_handle;
}
/** Unload libhybris framebuffer plugin
@@ -93,55 +109,13 @@
void
hybris_plugin_fb_unload(void)
{
- /* Close devices related to the plugin */
+ /* Close open devices */
hybris_device_fb_quit();
- /* actually unload the module */
+ /* Unload modules */
// FIXME: how to unload libhybris modules?
-}
-
-/** Convenience function for opening frame buffer device
- *
- * Similar to what we might or might not have available from hardware/fb.h
- */
-static int
-hybris_plugin_fb_open_device(struct framebuffer_device_t ** pdevice)
-{
- int ack = false;
-
- if( !hybris_plugin_fb_load() ) {
- goto cleanup;
- }
-
- const struct hw_module_t *mod = hybris_plugin_fb_handle;
- const char *id = GRALLOC_HARDWARE_FB0;
- struct hw_device_t *dev = 0;
-
- if( !mod->methods->open(mod, id, &dev) ) {
- goto cleanup;
- }
-
- *pdevice = (struct framebuffer_device_t*)dev;
-
- ack = true;
-
-cleanup:
-
- return ack;
-}
-
-/** Convenience function for closing frame buffer device
- *
- * Similar to what we might or might not have available from hardware/fb.h
- */
-static void
-hybris_plugin_fb_close_device(struct framebuffer_device_t **pdevice)
-{
- struct framebuffer_device_t *device;
-
- if( (device = *pdevice) ) {
- *pdevice = 0, device->common.close(&device->common);
- }
+ hybris_plugin_fb_handle = 0;
+ hybris_plugin_hwc_handle = 0;
}
/* ========================================================================= *
@@ -149,7 +123,14 @@
* ========================================================================= */
/** Pointer to libhybris frame buffer device object */
-static struct framebuffer_device_t *hybris_device_fb_handle = 0;
+static framebuffer_device_t *hybris_device_fb_handle = 0;
+
+/** Pointer to libhybris frame buffer device object */
+#ifdef HWC_DEVICE_API_VERSION_1_0
+static hwc_composer_device_1_t *hybris_device_hwc_handle = 0;
+#else
+static hwc_composer_device_t *hybris_device_hwc_handle = 0;
+#endif
/** Initialize libhybris frame buffer device object
*
@@ -158,6 +139,7 @@
bool
hybris_device_fb_init(void)
{
+ static bool ack = false;
static bool done = false;
if( done ) {
@@ -166,19 +148,70 @@
done = true;
- hybris_plugin_fb_open_device(&hybris_device_fb_handle);
-
- if( !hybris_device_fb_handle ) {
- mce_log(LL_ERR, "failed to open framebuffer device");
+ if( !hybris_plugin_fb_load() ) {
goto cleanup;
}
- mce_log(LL_DEBUG, "hybris_device_fb_handle = %p",
- hybris_device_fb_handle);
+ /* Open frame buffer device */
+ if( hybris_plugin_fb_handle ) {
+ hybris_plugin_fb_handle->methods->open(hybris_plugin_fb_handle,
+ GRALLOC_HARDWARE_FB0,
+ (hw_device_t**)&hybris_device_fb_handle);
+ if( !hybris_device_fb_handle ) {
+ mce_log(LL_WARN, "failed to open frame buffer device");
+ }
+ }
+
+ /* Open hw composer device */
+ if( hybris_plugin_hwc_handle ) {
+ hybris_plugin_hwc_handle->methods->open(hybris_plugin_hwc_handle,
+ HWC_HARDWARE_COMPOSER,
+ (hw_device_t**)&hybris_device_hwc_handle);
+ if( !hybris_device_hwc_handle ) {
+ mce_log(LL_WARN, "failed to open hw composer device");
+ }
+ }
+
+ /* What we'd like to use is:
+ *
+ * 1. hwc_dev->setPowerMode()
+ * 2. hwc_dev->blank()
+ * 2. fb_dev->enableScreen()
+ *
+ * While all are optional, having none available is unexpected.
+ */
+
+#ifdef HWC_DEVICE_API_VERSION_1_0
|