From 951325803874f32582d77fbb53d2d3e97fb3deac Mon Sep 17 00:00:00 2001 From: Miyoung Shin Date: Wed, 17 Apr 2019 22:54:55 +0000 Subject: [PATCH] Use double type to idl files in third_party/blink/renderer/modules/imagecapture This CL updates IDL files to follow spec APIs and changes float type to double type of c++/java implementation using Point2D struct. Bug: 938800 Change-Id: I50064e6530457c9499a21613544579cd0f31cd1e Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1554462 Reviewed-by: Reilly Grant Reviewed-by: Kentaro Hara Reviewed-by: Hitoshi Yoshida Reviewed-by: Richard Coles Reviewed-by: Yuki Shiino Reviewed-by: Kinuko Yasuda Reviewed-by: Guido Urdaneta Reviewed-by: Emircan Uysaler Reviewed-by: Christian Fremerey Commit-Queue: Miyoung Shin Cr-Commit-Position: refs/heads/master@{#651937} --- base/android/jni_array.cc | 19 +++++++++++++++++++ base/android/jni_array.h | 8 ++++++++ media/capture/mojom/image_capture.mojom | 4 ++-- .../src/org/chromium/media/VideoCapture.java | 2 +- .../chromium/media/VideoCaptureCamera.java | 6 +++--- .../chromium/media/VideoCaptureCamera2.java | 12 +++++++----- .../android/video_capture_device_android.cc | 6 +++--- .../video/chromeos/camera_device_delegate.cc | 6 +++--- .../modules/imagecapture/point_2d.idl | 4 ++-- .../resources/chromium/image_capture.mojom.js | 12 ++++++------ 10 files changed, 54 insertions(+), 25 deletions(-) diff --git a/base/android/jni_array.cc b/base/android/jni_array.cc index 0693776a160a9a..054853d994c8c8 100644 --- a/base/android/jni_array.cc +++ b/base/android/jni_array.cc @@ -124,6 +124,25 @@ BASE_EXPORT ScopedJavaLocalRef ToJavaFloatArray( return ToJavaFloatArray(env, floats.data(), floats.size()); } +BASE_EXPORT ScopedJavaLocalRef +ToJavaDoubleArray(JNIEnv* env, const double* doubles, size_t len) { + jdoubleArray double_array = env->NewDoubleArray(len); + CheckException(env); + DCHECK(double_array); + + env->SetDoubleArrayRegion(double_array, 0, len, + reinterpret_cast(doubles)); + CheckException(env); + + return ScopedJavaLocalRef(env, double_array); +} + +BASE_EXPORT ScopedJavaLocalRef ToJavaDoubleArray( + JNIEnv* env, + const std::vector& doubles) { + return ToJavaDoubleArray(env, doubles.data(), doubles.size()); +} + ScopedJavaLocalRef ToJavaArrayOfByteArray( JNIEnv* env, const std::vector& v) { ScopedJavaLocalRef byte_array_clazz = GetClass(env, "[B"); diff --git a/base/android/jni_array.h b/base/android/jni_array.h index c5a1c03686f887..917f1d0126ee25 100644 --- a/base/android/jni_array.h +++ b/base/android/jni_array.h @@ -60,6 +60,14 @@ BASE_EXPORT ScopedJavaLocalRef ToJavaFloatArray( JNIEnv* env, const std::vector& floats); +// Returns a new Java double array converted from the given C++ double array. +BASE_EXPORT ScopedJavaLocalRef +ToJavaDoubleArray(JNIEnv* env, const double* doubles, size_t len); + +BASE_EXPORT ScopedJavaLocalRef ToJavaDoubleArray( + JNIEnv* env, + const std::vector& doubles); + // Returns a array of Java byte array converted from |v|. BASE_EXPORT ScopedJavaLocalRef ToJavaArrayOfByteArray( JNIEnv* env, const std::vector& v); diff --git a/media/capture/mojom/image_capture.mojom b/media/capture/mojom/image_capture.mojom index c780a1df2b1b2e..720faa9b8dd471 100644 --- a/media/capture/mojom/image_capture.mojom +++ b/media/capture/mojom/image_capture.mojom @@ -64,8 +64,8 @@ struct PhotoState { // https://w3c.github.io/mediacapture-image/#point2d-section // TODO(mcasas): use gfx::mojom::PointF after https://crbug.com/640049. struct Point2D { - float x; - float y; + double x; + double y; }; // Equivalent to idl PhotoSettings + MediaTrackSettings/MediaTrackConstraintSet. diff --git a/media/capture/video/android/java/src/org/chromium/media/VideoCapture.java b/media/capture/video/android/java/src/org/chromium/media/VideoCapture.java index 4f346ade5a5495..9853d9c1328a50 100644 --- a/media/capture/video/android/java/src/org/chromium/media/VideoCapture.java +++ b/media/capture/video/android/java/src/org/chromium/media/VideoCapture.java @@ -102,7 +102,7 @@ public abstract boolean allocate( */ @CalledByNative public abstract void setPhotoOptions(double zoom, int focusMode, double focusDistance, - int exposureMode, double width, double height, float[] pointsOfInterest2D, + int exposureMode, double width, double height, double[] pointsOfInterest2D, boolean hasExposureCompensation, double exposureCompensation, double exposureTime, int whiteBalanceMode, double iso, boolean hasRedEyeReduction, boolean redEyeReduction, int fillLightMode, boolean hasTorch, boolean torch, double colorTemperature); diff --git a/media/capture/video/android/java/src/org/chromium/media/VideoCaptureCamera.java b/media/capture/video/android/java/src/org/chromium/media/VideoCaptureCamera.java index 390d21d9cfe1aa..0e725215636832 100644 --- a/media/capture/video/android/java/src/org/chromium/media/VideoCaptureCamera.java +++ b/media/capture/video/android/java/src/org/chromium/media/VideoCaptureCamera.java @@ -663,7 +663,7 @@ public void getPhotoCapabilitiesAsync(long callbackId) { @Override public void setPhotoOptions(double zoom, int focusMode, double focusDistance, int exposureMode, - double width, double height, float[] pointsOfInterest2D, + double width, double height, double[] pointsOfInterest2D, boolean hasExposureCompensation, double exposureCompensation, double exposureTime, int whiteBalanceMode, double iso, boolean hasRedEyeReduction, boolean redEyeReduction, int fillLightMode, boolean hasTorch, boolean torch, double colorTemperature) { @@ -721,8 +721,8 @@ public void setPhotoOptions(double zoom, int focusMode, double focusDistance, in assert pointsOfInterest2D[1] <= 1.0 && pointsOfInterest2D[1] >= 0.0; // Calculate a Rect of 1/8 the canvas, which is fixed to Rect(-1000, -1000, 1000, 1000), // see https://developer.android.com/reference/android/hardware/Camera.Area.html - final int centerX = Math.round(pointsOfInterest2D[0] * 2000) - 1000; - final int centerY = Math.round(pointsOfInterest2D[1] * 2000) - 1000; + final int centerX = (int) (Math.round(pointsOfInterest2D[0] * 2000) - 1000); + final int centerY = (int) (Math.round(pointsOfInterest2D[1] * 2000) - 1000); final int regionWidth = 2000 / 8; final int regionHeight = 2000 / 8; final int weight = 1000; diff --git a/media/capture/video/android/java/src/org/chromium/media/VideoCaptureCamera2.java b/media/capture/video/android/java/src/org/chromium/media/VideoCaptureCamera2.java index 03819bd0e6e7e1..123493dfa36418 100644 --- a/media/capture/video/android/java/src/org/chromium/media/VideoCaptureCamera2.java +++ b/media/capture/video/android/java/src/org/chromium/media/VideoCaptureCamera2.java @@ -686,7 +686,7 @@ private class PhotoOptions { public final int exposureMode; public final double width; public final double height; - public final float[] pointsOfInterest2D; + public final double[] pointsOfInterest2D; public final boolean hasExposureCompensation; public final double exposureCompensation; public final double exposureTime; @@ -700,7 +700,7 @@ private class PhotoOptions { public final double colorTemperature; public PhotoOptions(double zoom, int focusMode, double currentFocusDistance, - int exposureMode, double width, double height, float[] pointsOfInterest2D, + int exposureMode, double width, double height, double[] pointsOfInterest2D, boolean hasExposureCompensation, double exposureCompensation, double exposureTime, int whiteBalanceMode, double iso, boolean hasRedEyeReduction, boolean redEyeReduction, int fillLightMode, boolean hasTorch, boolean torch, @@ -790,8 +790,10 @@ public void run() { // Calculate a Rect of 1/8 the |visibleRect| dimensions, and center it w.r.t. // |canvas|. final Rect visibleRect = (mCropRect.isEmpty()) ? canvas : mCropRect; - int centerX = Math.round(mOptions.pointsOfInterest2D[0] * visibleRect.width()); - int centerY = Math.round(mOptions.pointsOfInterest2D[1] * visibleRect.height()); + int centerX = + (int) Math.round(mOptions.pointsOfInterest2D[0] * visibleRect.width()); + int centerY = + (int) Math.round(mOptions.pointsOfInterest2D[1] * visibleRect.height()); if (visibleRect.equals(mCropRect)) { centerX += (canvas.width() - visibleRect.width()) / 2; centerY += (canvas.height() - visibleRect.height()) / 2; @@ -1541,7 +1543,7 @@ public void getPhotoCapabilitiesAsync(long callbackId) { @Override public void setPhotoOptions(double zoom, int focusMode, double currentFocusDistance, - int exposureMode, double width, double height, float[] pointsOfInterest2D, + int exposureMode, double width, double height, double[] pointsOfInterest2D, boolean hasExposureCompensation, double exposureCompensation, double exposureTime, int whiteBalanceMode, double iso, boolean hasRedEyeReduction, boolean redEyeReduction, int fillLightMode, boolean hasTorch, boolean torch, double colorTemperature) { diff --git a/media/capture/video/android/video_capture_device_android.cc b/media/capture/video/android/video_capture_device_android.cc index 02e4256f57f436..777e8229e3617a 100644 --- a/media/capture/video/android/video_capture_device_android.cc +++ b/media/capture/video/android/video_capture_device_android.cc @@ -736,13 +736,13 @@ void VideoCaptureDeviceAndroid::DoSetPhotoOptions( const double width = settings->has_width ? settings->width : 0.0; const double height = settings->has_height ? settings->height : 0.0; - std::vector points_of_interest_marshalled; + std::vector points_of_interest_marshalled; for (const auto& point : settings->points_of_interest) { points_of_interest_marshalled.push_back(point->x); points_of_interest_marshalled.push_back(point->y); } - ScopedJavaLocalRef points_of_interest = - base::android::ToJavaFloatArray(env, points_of_interest_marshalled); + ScopedJavaLocalRef points_of_interest = + base::android::ToJavaDoubleArray(env, points_of_interest_marshalled); const double exposure_compensation = settings->has_exposure_compensation ? settings->exposure_compensation diff --git a/media/capture/video/chromeos/camera_device_delegate.cc b/media/capture/video/chromeos/camera_device_delegate.cc index 0f17177dffbe3a..3beb0dfe8a80c4 100644 --- a/media/capture/video/chromeos/camera_device_delegate.cc +++ b/media/capture/video/chromeos/camera_device_delegate.cc @@ -820,11 +820,11 @@ bool CameraDeviceDelegate::SetPointsOfInterest( // the closest allowed value. // ref: https://www.w3.org/TR/image-capture/#points-of-interest - float x = base::ClampToRange(points_of_interest[0]->x, 0.0f, 1.0f); - float y = base::ClampToRange(points_of_interest[0]->y, 0.0f, 1.0f); + double x = base::ClampToRange(points_of_interest[0]->x, 0.0, 1.0); + double y = base::ClampToRange(points_of_interest[0]->y, 0.0, 1.0); // Handle rotation, still in normalized square space. - std::tie(x, y) = [&]() -> std::pair { + std::tie(x, y) = [&]() -> std::pair { switch (device_context_->GetCameraFrameOrientation()) { case 0: return {x, y}; diff --git a/third_party/blink/renderer/modules/imagecapture/point_2d.idl b/third_party/blink/renderer/modules/imagecapture/point_2d.idl index b77caf68ad87f5..6efbbd02cdcfdf 100644 --- a/third_party/blink/renderer/modules/imagecapture/point_2d.idl +++ b/third_party/blink/renderer/modules/imagecapture/point_2d.idl @@ -5,6 +5,6 @@ // https://w3c.github.io/mediacapture-image/#point2d-section dictionary Point2D { - float x = 0.0; - float y = 0.0; + double x = 0.0; + double y = 0.0; }; diff --git a/third_party/blink/web_tests/external/wpt/resources/chromium/image_capture.mojom.js b/third_party/blink/web_tests/external/wpt/resources/chromium/image_capture.mojom.js index bf8dd16ca75d4b..50428ffcb80c73 100644 --- a/third_party/blink/web_tests/external/wpt/resources/chromium/image_capture.mojom.js +++ b/third_party/blink/web_tests/external/wpt/resources/chromium/image_capture.mojom.js @@ -434,7 +434,7 @@ return err; var kVersionSizes = [ - {version: 0, numBytes: 16} + {version: 0, numBytes: 24} ]; err = messageValidator.validateStructVersion(offset, kVersionSizes); if (err !== validator.validationError.NONE) @@ -445,15 +445,15 @@ return validator.validationError.NONE; }; - Point2D.encodedSize = codec.kStructHeaderSize + 8; + Point2D.encodedSize = codec.kStructHeaderSize + 16; Point2D.decode = function(decoder) { var packed; var val = new Point2D(); var numberOfBytes = decoder.readUint32(); var version = decoder.readUint32(); - val.x = decoder.decodeStruct(codec.Float); - val.y = decoder.decodeStruct(codec.Float); + val.x = decoder.decodeStruct(codec.Double); + val.y = decoder.decodeStruct(codec.Double); return val; }; @@ -461,8 +461,8 @@ var packed; encoder.writeUint32(Point2D.encodedSize); encoder.writeUint32(0); - encoder.encodeStruct(codec.Float, val.x); - encoder.encodeStruct(codec.Float, val.y); + encoder.encodeStruct(codec.Double, val.x); + encoder.encodeStruct(codec.Double, val.y); }; function PhotoSettings(values) { this.initDefaults_();