summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorfjhenigman@chromium.org <fjhenigman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-05-05 17:32:48 +0000
committerfjhenigman@chromium.org <fjhenigman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-05-05 17:32:48 +0000
commit00d3f3934100b2045ad70ada2c56b8f29828f955 (patch)
treeea5a290beb06fcdcbccd97e7bce5f93de5f11ccc
parent0c751467fbfb1b4d7e540476ff58d13eb7ee57d8 (diff)
downloadchromium_src-00d3f3934100b2045ad70ada2c56b8f29828f955.zip
chromium_src-00d3f3934100b2045ad70ada2c56b8f29828f955.tar.gz
chromium_src-00d3f3934100b2045ad70ada2c56b8f29828f955.tar.bz2
Re-land: Make it possible to build libhardware.
Fix up some include files, supply some functions, and make the hardware module search path configurable at compile time and run time. TBR=dalecurtis@chromium.org BUG=358029 Review URL: https://codereview.chromium.org/252583002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@268211 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--third_party/hwcplus/include/cutils/properties.h9
-rw-r--r--third_party/hwcplus/include/hardware/hardware.h6
-rw-r--r--third_party/hwcplus/include/log/log.h4
-rw-r--r--third_party/hwcplus/include/system/graphics.h3
-rw-r--r--third_party/hwcplus/src/hardware.c30
-rw-r--r--third_party/hwcplus/src/hwcplus_util.c75
6 files changed, 122 insertions, 5 deletions
diff --git a/third_party/hwcplus/include/cutils/properties.h b/third_party/hwcplus/include/cutils/properties.h
index 2c70165..66a9c5b 100644
--- a/third_party/hwcplus/include/cutils/properties.h
+++ b/third_party/hwcplus/include/cutils/properties.h
@@ -19,7 +19,16 @@
#include <sys/cdefs.h>
#include <stddef.h>
+#ifdef ANDROID
#include <sys/system_properties.h>
+#else
+#ifndef PROP_NAME_MAX
+#define PROP_NAME_MAX 32
+#endif
+#ifndef PROP_VALUE_MAX
+#define PROP_VALUE_MAX 92
+#endif
+#endif
#ifdef __cplusplus
extern "C" {
diff --git a/third_party/hwcplus/include/hardware/hardware.h b/third_party/hwcplus/include/hardware/hardware.h
index 416ae39..9466537 100644
--- a/third_party/hwcplus/include/hardware/hardware.h
+++ b/third_party/hwcplus/include/hardware/hardware.h
@@ -225,6 +225,12 @@ int hw_get_module(const char *id, const struct hw_module_t **module);
int hw_get_module_by_class(const char *class_id, const char *inst,
const struct hw_module_t **module);
+/**
+ * Provide a function to handle log messages.
+ */
+typedef int (*hwcplus_log_fn_t)(int prio, const char* tag, const char* msg);
+void hwcplus_set_log_fn(hwcplus_log_fn_t fn);
+
__END_DECLS
#endif /* ANDROID_INCLUDE_HARDWARE_HARDWARE_H */
diff --git a/third_party/hwcplus/include/log/log.h b/third_party/hwcplus/include/log/log.h
index 7faddea..4677ed4 100644
--- a/third_party/hwcplus/include/log/log.h
+++ b/third_party/hwcplus/include/log/log.h
@@ -37,8 +37,12 @@
#endif
#include <stdarg.h>
+#ifdef ANDROID
#include <log/uio.h>
#include <log/logd.h>
+#else
+#include <android/log.h>
+#endif
#ifdef __cplusplus
extern "C" {
diff --git a/third_party/hwcplus/include/system/graphics.h b/third_party/hwcplus/include/system/graphics.h
index be86ae4..4ba6a9e 100644
--- a/third_party/hwcplus/include/system/graphics.h
+++ b/third_party/hwcplus/include/system/graphics.h
@@ -18,6 +18,9 @@
#define SYSTEM_CORE_INCLUDE_ANDROID_GRAPHICS_H
#include <stdint.h>
+#ifndef ANDROID
+#include <stddef.h>
+#endif
#ifdef __cplusplus
extern "C" {
diff --git a/third_party/hwcplus/src/hardware.c b/third_party/hwcplus/src/hardware.c
index 6713ea0..4ff293d 100644
--- a/third_party/hwcplus/src/hardware.c
+++ b/third_party/hwcplus/src/hardware.c
@@ -23,17 +23,29 @@
#include <pthread.h>
#include <errno.h>
#include <limits.h>
+#include <stdlib.h>
#define LOG_TAG "HAL"
+#ifdef ANDROID
#include <utils/Log.h>
+#else
+#include <stdio.h>
+#include <unistd.h>
+#include <log/log.h>
+#endif
-/** Base path of the hal modules */
#if defined(__LP64__)
-#define HAL_LIBRARY_PATH1 "/system/lib64/hw"
-#define HAL_LIBRARY_PATH2 "/vendor/lib64/hw"
+#define _64 "64"
#else
-#define HAL_LIBRARY_PATH1 "/system/lib/hw"
-#define HAL_LIBRARY_PATH2 "/vendor/lib/hw"
+#define _64 ""
+#endif
+
+/** Base path of the hal modules */
+#ifndef HAL_LIBRARY_PATH1
+#define HAL_LIBRARY_PATH1 "/system/lib" _64 "/hw"
+#endif
+#ifndef HAL_LIBRARY_PATH2
+#define HAL_LIBRARY_PATH2 "/vendor/lib" _64 "/hw"
#endif
/**
@@ -129,6 +141,14 @@ static int load(const char *id,
static int hw_module_exists(char *path, size_t path_len, const char *name,
const char *subname)
{
+ char *hal_library_path = getenv("HAL_LIBRARY_PATH");
+ if (hal_library_path) {
+ snprintf(path, path_len, "%s/%s.%s.so",
+ hal_library_path, name, subname);
+ if (access(path, R_OK) == 0)
+ return 0;
+ }
+
snprintf(path, path_len, "%s/%s.%s.so",
HAL_LIBRARY_PATH2, name, subname);
if (access(path, R_OK) == 0)
diff --git a/third_party/hwcplus/src/hwcplus_util.c b/third_party/hwcplus/src/hwcplus_util.c
new file mode 100644
index 0000000..57c4519
--- /dev/null
+++ b/third_party/hwcplus/src/hwcplus_util.c
@@ -0,0 +1,75 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include <stdarg.h>
+#include <stdio.h>
+#include <string.h>
+
+#include <hardware/hardware.h>
+#include <cutils/properties.h>
+
+#define LOG_BUF_SIZE 1024
+
+static int default_log_fn(int prio, const char* tag, const char* msg);
+
+static hwcplus_log_fn_t hwcplus_log_fn = default_log_fn;
+
+void hwcplus_set_log_fn(hwcplus_log_fn_t fn) {
+ hwcplus_log_fn = fn;
+}
+
+#ifndef HAVE_STRLCPY
+size_t strlcpy(char* dst, const char* src, size_t siz) {
+ char* d = dst;
+ const char* s = src;
+ size_t n = siz;
+
+ /* Copy as many bytes as will fit */
+ if (n != 0) {
+ while (--n != 0) {
+ if ((*d++ = *s++) == '\0')
+ break;
+ }
+ }
+
+ /* Not enough room in dst, add NUL and traverse rest of src */
+ if (n == 0) {
+ if (siz != 0)
+ *d = '\0'; /* NUL-terminate dst */
+ while (*s++) {
+ }
+ }
+
+ return(s - src - 1); /* count does not include NUL */
+}
+#endif
+
+static int default_log_fn(int prio, const char* tag, const char* msg) {
+ fprintf(stderr, "<%d> %s %s\n", prio, tag, msg);
+}
+
+int __android_log_write(int prio, const char* tag, const char* msg) {
+ hwcplus_log_fn(prio, tag, msg);
+}
+
+int __android_log_print(int prio, const char* tag, const char* fmt, ...) {
+ va_list ap;
+ char buf[LOG_BUF_SIZE];
+
+ va_start(ap, fmt);
+ vsnprintf(buf, LOG_BUF_SIZE, fmt, ap);
+ va_end(ap);
+
+ return __android_log_write(prio, tag, buf);
+}
+
+int property_get(const char* key, char* value, const char* default_value) {
+ printf("property_get %s\n", key);
+ const char* r = default_value;
+ if (!r)
+ r = "";
+ strncpy(value, r, PROPERTY_VALUE_MAX);
+ return strlen(r);
+}
+