camera: intel: ipu6: Fix the picture shows dark issue during running ITS

BUG=b:149068439, b:149068672
TEST=Full tested pass for camera functions.

Change-Id: I9a9a2b2602f4b129b3f7922fda6ff69d56aa55d0
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform2/+/2596835
Tested-by: Zong Li <zong.li@intel.com>
Reviewed-by: Ren-Pei Zeng <kamesan@chromium.org>
Commit-Queue: Ren-Pei Zeng <kamesan@chromium.org>
diff --git a/camera/hal/intel/ipu6/src/3a/AiqCore.cpp b/camera/hal/intel/ipu6/src/3a/AiqCore.cpp
index 70752c1..5ff54f5 100644
--- a/camera/hal/intel/ipu6/src/3a/AiqCore.cpp
+++ b/camera/hal/intel/ipu6/src/3a/AiqCore.cpp
@@ -42,6 +42,7 @@
     mLastAeResult(nullptr),
     mLastAwbResult(nullptr),
     mLastAfResult(nullptr),
+    mLastGbceResults(nullptr),
     mAeRunTime(0),
     mAwbRunTime(0),
     mAiqState(AIQ_NOT_INIT),
@@ -126,6 +127,7 @@
     mLastAeResult = nullptr;
     mLastAwbResult = nullptr;
     mLastAfResult = nullptr;
+    mLastGbceResults = nullptr;
     mAeRunTime = 0;
     mAwbRunTime = 0;
 
@@ -596,23 +598,31 @@
     LOG3A("%s, gbceResults:%p", __func__, gbceResults);
     CheckError(!gbceResults, BAD_VALUE, "@%s, gbceResults is nullptr", __func__);
 
-    // Don't run gbce if AE lock and ev shift isn't changed
-    if (mAeForceLock && mGbceParams.ev_shift == mLastEvShift) return OK;
+    //reuse the last gbce results when gbceForceRun is false
+    bool gbceForceRun = !mAeForceLock || (mGbceParams.ev_shift != mLastEvShift);
+    int ret = OK;
 
     PERF_CAMERA_ATRACE();
-    ia_aiq_gbce_results *newGbceResults = nullptr;
+    ia_aiq_gbce_results *newGbceResults = mLastGbceResults;
 
-    IntelAiq* intelAiq = mIntelAiqHandle[mTuningMode];
-    CheckError(!intelAiq, UNKNOWN_ERROR, "%s, aiq is nullptr, mode:%d", __func__, mTuningMode);
-    {
-        PERF_CAMERA_ATRACE_PARAM1_IMAGING("intelAiq->gbceRun", 1);
-        ia_err iaErr = intelAiq->gbceRun(&mGbceParams, &newGbceResults);
-        int ret = AiqUtils::convertError(iaErr);
-        CheckError(ret != OK || !newGbceResults, ret, "@%s, gbceRun fails, ret: %d",
-                   __func__, ret);
+    if (gbceForceRun) {
+        IntelAiq* intelAiq = mIntelAiqHandle[mTuningMode];
+        CheckError(!intelAiq, UNKNOWN_ERROR, "%s, aiq is nullptr, mode:%d", __func__, mTuningMode);
+        {
+            PERF_CAMERA_ATRACE_PARAM1_IMAGING("intelAiq->gbceRun", 1);
+            ia_err iaErr = intelAiq->gbceRun(&mGbceParams, &newGbceResults);
+            ret = AiqUtils::convertError(iaErr);
+            CheckError(ret != OK || !newGbceResults, ret, "@%s, gbceRun fails, ret: %d",
+                       __func__, ret);
+        }
     }
 
-    return AiqUtils::deepCopyGbceResults(*newGbceResults, gbceResults);
+    if (newGbceResults) {
+        ret = AiqUtils::deepCopyGbceResults(*newGbceResults, gbceResults);
+    }
+    mLastGbceResults = gbceResults;
+
+    return ret;
 }
 
 int AiqCore::runPa(ia_aiq_pa_results_v1 *paResults,
diff --git a/camera/hal/intel/ipu6/src/3a/AiqCore.h b/camera/hal/intel/ipu6/src/3a/AiqCore.h
index 717760f..73e4c93 100644
--- a/camera/hal/intel/ipu6/src/3a/AiqCore.h
+++ b/camera/hal/intel/ipu6/src/3a/AiqCore.h
@@ -172,6 +172,7 @@
     ia_aiq_ae_results *mLastAeResult;
     ia_aiq_awb_results *mLastAwbResult;
     ia_aiq_af_results *mLastAfResult;
+    ia_aiq_gbce_results *mLastGbceResults;
 
     int mAeRunTime;
     int mAwbRunTime;