Camera2: Fix metering regions to take into account the current zoom/crop region

Also adds a quirk to disable this fix to work around for incompliant HALs

Bug: 7246065
Change-Id: I80bad25e56ba59149270238e5639bb33cae495ae
diff --git a/services/camera/libcameraservice/camera2/Parameters.h b/services/camera/libcameraservice/camera2/Parameters.h
index cb9738b..daae7c4 100644
--- a/services/camera/libcameraservice/camera2/Parameters.h
+++ b/services/camera/libcameraservice/camera2/Parameters.h
@@ -186,6 +186,7 @@
     struct Quirks {
         bool triggerAfWithAuto;
         bool useZslFormat;
+        bool meteringCropRegion;
     } quirks;
 
     /**
@@ -228,8 +229,15 @@
         float top;
         float width;
         float height;
+
+        enum Outputs {
+            OUTPUT_PREVIEW         = 0x01,
+            OUTPUT_VIDEO           = 0x02,
+            OUTPUT_JPEG_THUMBNAIL  = 0x04,
+            OUTPUT_PICTURE         = 0x08,
+        };
     };
-    CropRegion calculateCropRegion(void) const;
+    CropRegion calculateCropRegion(CropRegion::Outputs outputs) const;
 
     // Static methods for debugging and converting between camera1 and camera2
     // parameters
@@ -275,6 +283,21 @@
 
     int32_t fpsFromRange(int32_t min, int32_t max) const;
 
+private:
+
+    // Convert between HAL2 sensor array coordinates and
+    // viewfinder crop-region relative array coordinates
+    int cropXToArray(int x) const;
+    int cropYToArray(int y) const;
+    int arrayXToCrop(int x) const;
+    int arrayYToCrop(int y) const;
+
+    // Convert between viewfinder crop-region relative array coordinates
+    // and camera API (-1000,1000)-(1000,1000) normalized coords
+    int cropXToNormalized(int x) const;
+    int cropYToNormalized(int y) const;
+    int normalizedXToCrop(int x) const;
+    int normalizedYToCrop(int y) const;
 };
 
 // This class encapsulates the Parameters class so that it can only be accessed