csc: allow compiling with multiple HW types

Once G2D support is added, the same binary should be usable for either
Gscaler or G2D.  The HW type is controlled through the new property
CSC_HW_PROPERTY_HW_TYPE.

Also return an error if any hardware properties are set after the device
is already opened.  This didn't work before and should never happen, but
it's worth adding a check just in case.

Change-Id: I6d3fab4e777395a7e14a1f54353100902c76f75e
Signed-off-by: Greg Hackmann <ghackmann@google.com>
diff --git a/libcsc/csc.c b/libcsc/csc.c
index 385223c..11c5b1c 100644
--- a/libcsc/csc.c
+++ b/libcsc/csc.c
@@ -64,11 +64,6 @@
     CSC_V_PLANE = 2
 } CSC_PLANE;
 
-typedef enum _CSC_HW_TYPE {
-    CSC_HW_TYPE_FIMC = 0,
-    CSC_HW_TYPE_GSCALER
-} CSC_HW_TYPE;
-
 typedef struct _CSC_FORMAT {
     unsigned int width;
     unsigned int height;
@@ -331,12 +326,6 @@
 
     csc_handle = (CSC_HANDLE *)handle;
     if (csc_handle->csc_method == CSC_METHOD_HW) {
-#ifdef ENABLE_FIMC
-        csc_handle->csc_hw_type = CSC_HW_TYPE_FIMC;
-#endif
-#ifdef ENABLE_GSCALER
-        csc_handle->csc_hw_type = CSC_HW_TYPE_GSCALER;
-#endif
         switch (csc_handle->csc_hw_type) {
 #ifdef ENABLE_FIMC
         case CSC_HW_TYPE_FIMC:
@@ -545,6 +534,12 @@
         return CSC_ErrorNotInit;
 
     csc_handle = (CSC_HANDLE *)handle;
+
+    if (csc_handle->csc_hw_handle) {
+        ALOGE("%s:: cannot set hw property after hw is already initialized", __func__);
+        return CSC_ErrorUnsupportFormat;
+    }
+
     switch (property) {
     case CSC_HW_PROPERTY_FIXED_NODE:
         csc_handle->hw_property.fixed_node = value;
@@ -552,6 +547,9 @@
     case CSC_HW_PROPERTY_MODE_DRM:
         csc_handle->hw_property.mode_drm = value;
         break;
+    case CSC_HW_PROPERTY_HW_TYPE:
+        csc_handle->csc_hw_type = value;
+        break;
     default:
         ALOGE("%s:: not supported hw property", __func__);
         ret = CSC_ErrorUnsupportFormat;