Add USAGE_OEM

Allow OEMs to pass data from other HW blocks via internal
extension.

Change-Id: I78c19f5eec462aff7d8a5408f2f16cfc9b78c036
diff --git a/cpp/Allocation.cpp b/cpp/Allocation.cpp
index cae5191..fcba9e9 100644
--- a/cpp/Allocation.cpp
+++ b/cpp/Allocation.cpp
@@ -49,6 +49,7 @@
                    RS_ALLOCATION_USAGE_GRAPHICS_RENDER_TARGET |
                    RS_ALLOCATION_USAGE_IO_INPUT |
                    RS_ALLOCATION_USAGE_IO_OUTPUT |
+                   RS_ALLOCATION_USAGE_OEM |
                    RS_ALLOCATION_USAGE_SHARED)) != 0) {
         ALOGE("Unknown usage specified.");
     }
diff --git a/driver/rsdCore.cpp b/driver/rsdCore.cpp
index d9b11d2..9c4755c 100644
--- a/driver/rsdCore.cpp
+++ b/driver/rsdCore.cpp
@@ -102,6 +102,8 @@
 
     case RS_HAL_ALLOCATION_INIT:
         fnPtr[0] = (void *)rsdAllocationInit; break;
+    case RS_HAL_ALLOCATION_INIT_OEM:
+        fnPtr[0] = (void *)nullptr; break;
     case RS_HAL_ALLOCATION_INIT_ADAPTER:
         fnPtr[0] = (void *)rsdAllocationAdapterInit; break;
     case RS_HAL_ALLOCATION_DESTROY:
diff --git a/rsAllocation.cpp b/rsAllocation.cpp
index 0e74242..a7601a4 100644
--- a/rsAllocation.cpp
+++ b/rsAllocation.cpp
@@ -70,9 +70,22 @@
         return nullptr;
     }
 
-    Allocation *a = new (allocMem) Allocation(rsc, type, usages, mc, ptr);
+    bool success = false;
+    Allocation *a = nullptr;
+    if (usages & RS_ALLOCATION_USAGE_OEM) {
+        if (rsc->mHal.funcs.allocation.initOem != nullptr) {
+            a = new (allocMem) Allocation(rsc, type, usages, mc, nullptr);
+            success = rsc->mHal.funcs.allocation.initOem(rsc, a, type->getElement()->getHasReferences(), ptr);
+        } else {
+            rsc->setError(RS_ERROR_FATAL_DRIVER, "Allocation Init called with USAGE_OEM but driver does not support it");
+            return nullptr;
+        }
+    } else {
+        a = new (allocMem) Allocation(rsc, type, usages, mc, ptr);
+        success = rsc->mHal.funcs.allocation.init(rsc, a, type->getElement()->getHasReferences());
+    }
 
-    if (!rsc->mHal.funcs.allocation.init(rsc, a, type->getElement()->getHasReferences())) {
+    if (!success) {
         rsc->setError(RS_ERROR_FATAL_DRIVER, "Allocation::Allocation, alloc failure");
         delete a;
         return nullptr;
diff --git a/rsDefines.h b/rsDefines.h
index 9287470..fdb0720 100644
--- a/rsDefines.h
+++ b/rsDefines.h
@@ -96,7 +96,8 @@
     RS_ALLOCATION_USAGE_IO_OUTPUT = 0x0040,
     RS_ALLOCATION_USAGE_SHARED = 0x0080,
 
-    RS_ALLOCATION_USAGE_ALL = 0x00FF
+    RS_ALLOCATION_USAGE_OEM = 0x8000,
+    RS_ALLOCATION_USAGE_ALL = 0x80FF
 };
 
 enum RsAllocationMipmapControl {
diff --git a/rsDriverLoader.cpp b/rsDriverLoader.cpp
index 528af0f..2bc53b6 100644
--- a/rsDriverLoader.cpp
+++ b/rsDriverLoader.cpp
@@ -82,6 +82,7 @@
     ret &= fn(RS_HAL_SCRIPT_UPDATE_CACHED_OBJECT, (void **)&rsc->mHal.funcs.script.updateCachedObject);
 
     ret &= fn(RS_HAL_ALLOCATION_INIT, (void **)&rsc->mHal.funcs.allocation.init);
+    ret &= fn(RS_HAL_ALLOCATION_INIT_OEM, (void **)&rsc->mHal.funcs.allocation.initOem);
     ret &= fn(RS_HAL_ALLOCATION_INIT_ADAPTER, (void **)&rsc->mHal.funcs.allocation.initAdapter);
     ret &= fn(RS_HAL_ALLOCATION_DESTROY, (void **)&rsc->mHal.funcs.allocation.destroy);
     ret &= fn(RS_HAL_ALLOCATION_GET_GRALLOC_BITS, (void **)&rsc->mHal.funcs.allocation.grallocBits);
diff --git a/rs_hal.h b/rs_hal.h
index b4070ac..77c2d26 100644
--- a/rs_hal.h
+++ b/rs_hal.h
@@ -190,6 +190,7 @@
 
     struct {
         bool (*init)(const Context *rsc, Allocation *alloc, bool forceZero);
+        bool (*initOem)(const Context *rsc, Allocation *alloc, bool forceZero, void *usrPtr);
         bool (*initAdapter)(const Context *rsc, Allocation *alloc);
         void (*destroy)(const Context *rsc, Allocation *alloc);
         uint32_t (*grallocBits)(const Context *rsc, Allocation *alloc);
@@ -400,6 +401,7 @@
     RS_HAL_ALLOCATION_GENERATE_MIPMAPS                      = 2023,
     RS_HAL_ALLOCATION_UPDATE_CACHED_OBJECT                  = 2024,
     RS_HAL_ALLOCATION_ADAPTER_OFFSET                        = 2025,
+    RS_HAL_ALLOCATION_INIT_OEM                              = 2026,
 
     RS_HAL_SAMPLER_INIT                                     = 3000,
     RS_HAL_SAMPLER_DESTROY                                  = 3001,