Initial work to connect gralloc to egl::Image
Change-Id: Ia11a9520bb6525dc367e0b2956850574b29e4796
Reviewed-on: https://swiftshader-review.googlesource.com/2900
Reviewed-by: Nicolas Capens <capn@google.com>
Tested-by: Nicolas Capens <capn@google.com>
diff --git a/src/Common/GrallocAndroid.cpp b/src/Common/GrallocAndroid.cpp
new file mode 100644
index 0000000..307a16f
--- /dev/null
+++ b/src/Common/GrallocAndroid.cpp
@@ -0,0 +1,31 @@
+#include "GrallocAndroid.hpp"
+
+#include <cutils/log.h>
+
+GrallocModule* GrallocModule::getInstance()
+{
+ static GrallocModule instance;
+ return &instance;
+}
+
+GrallocModule::GrallocModule()
+{
+ const hw_module_t* module;
+ hw_get_module("converting_gralloc", &module);
+ if (module)
+ {
+ m_supportsConversion = true;
+ ALOGI("Loaded converting gralloc");
+ }
+ else
+ {
+ m_supportsConversion = false;
+ ALOGE("Falling back to standard gralloc with reduced format support");
+ hw_get_module(GRALLOC_HARDWARE_MODULE_ID, &module);
+ }
+ if (!module)
+ {
+ ALOGE("Failed to load standard gralloc");
+ }
+ m_module = reinterpret_cast<const gralloc_module_t*>(module);
+}
diff --git a/src/Common/GrallocAndroid.hpp b/src/Common/GrallocAndroid.hpp
new file mode 100644
index 0000000..4714d36
--- /dev/null
+++ b/src/Common/GrallocAndroid.hpp
@@ -0,0 +1,27 @@
+#ifndef GRALLOC_ANDROID
+#define GRALLOC_ANDROID
+
+#include <hardware/gralloc.h>
+
+class GrallocModule
+{
+public:
+ static GrallocModule* getInstance();
+ bool supportsConversion() const { return m_supportsConversion; }
+ int lock(
+ buffer_handle_t handle, int usage,
+ int left, int top, int width, int height, void**vaddr) {
+ return m_module->lock(m_module, handle, 0, left, top, width, height, vaddr);
+ }
+
+ int unlock(buffer_handle_t handle) {
+ return m_module->unlock(m_module, handle);
+ }
+
+private:
+ GrallocModule();
+ bool m_supportsConversion;
+ const gralloc_module_t* m_module;
+};
+
+#endif // GRALLOC_ANDROID