gralloc: Allow devices to opt-in for YCrCb camera preview

* Some stock camera HAL implementations output video
  stream in YCrCb instead of YCbCr.

Change-Id: I562847dfd9bcf796052f6fd7263e2affbd601384
diff --git a/gralloc/Android.mk b/gralloc/Android.mk
index ebb3cd4..2c2382d 100644
--- a/gralloc/Android.mk
+++ b/gralloc/Android.mk
@@ -39,6 +39,11 @@
                                   android.hardware.graphics.mapper@4.0
 LOCAL_CFLAGS                  := $(common_flags) -DLOG_TAG=\"qdgralloc\" -Wno-sign-conversion \
                                  -D__QTI_DISPLAY_GRALLOC__
+
+ifeq ($(TARGET_USES_YCRCB_CAMERA_PREVIEW),true)
+    LOCAL_CFLAGS              += -DUSE_YCRCB_CAMERA_PREVIEW
+endif
+
 LOCAL_ADDITIONAL_DEPENDENCIES := $(common_deps)
 LOCAL_SRC_FILES               := gr_utils.cpp gr_adreno_info.cpp
 include $(BUILD_SHARED_LIBRARY)
diff --git a/gralloc/gr_utils.cpp b/gralloc/gr_utils.cpp
index 98e60e2..ceb5e69 100644
--- a/gralloc/gr_utils.cpp
+++ b/gralloc/gr_utils.cpp
@@ -1335,7 +1335,11 @@
       if (format == HAL_PIXEL_FORMAT_YCbCr_420_888) {
         gr_format = HAL_PIXEL_FORMAT_NV21_ZSL;  // NV21
       } else {
+#ifdef USE_YCRCB_CAMERA_PREVIEW
+        gr_format = HAL_PIXEL_FORMAT_YCrCb_420_SP;  // NV21 preview
+#else
         gr_format = HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS;  // NV12 preview
+#endif
       }
     } else if (usage & BufferUsage::COMPOSER_OVERLAY) {
       // XXX: If we still haven't set a format, default to RGBA8888