Skip to content

Commit

Permalink
Use double type to idl files in third_party/blink/renderer/modules/im…
Browse files Browse the repository at this point in the history
…agecapture

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 <reillyg@chromium.org>
Reviewed-by: Kentaro Hara <haraken@chromium.org>
Reviewed-by: Hitoshi Yoshida <peria@chromium.org>
Reviewed-by: Richard Coles <torne@chromium.org>
Reviewed-by: Yuki Shiino <yukishiino@chromium.org>
Reviewed-by: Kinuko Yasuda <kinuko@chromium.org>
Reviewed-by: Guido Urdaneta <guidou@chromium.org>
Reviewed-by: Emircan Uysaler <emircan@chromium.org>
Reviewed-by: Christian Fremerey <chfremer@chromium.org>
Commit-Queue: Miyoung Shin <myid.shin@igalia.com>
Cr-Commit-Position: refs/heads/master@{#651937}
  • Loading branch information
MyidShin authored and Commit Bot committed Apr 17, 2019
1 parent 1a5b2cf commit 9513258
Show file tree
Hide file tree
Showing 10 changed files with 54 additions and 25 deletions.
19 changes: 19 additions & 0 deletions base/android/jni_array.cc
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,25 @@ BASE_EXPORT ScopedJavaLocalRef<jfloatArray> ToJavaFloatArray(
return ToJavaFloatArray(env, floats.data(), floats.size());
}

BASE_EXPORT ScopedJavaLocalRef<jdoubleArray>
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<const jdouble*>(doubles));
CheckException(env);

return ScopedJavaLocalRef<jdoubleArray>(env, double_array);
}

BASE_EXPORT ScopedJavaLocalRef<jdoubleArray> ToJavaDoubleArray(
JNIEnv* env,
const std::vector<double>& doubles) {
return ToJavaDoubleArray(env, doubles.data(), doubles.size());
}

ScopedJavaLocalRef<jobjectArray> ToJavaArrayOfByteArray(
JNIEnv* env, const std::vector<std::string>& v) {
ScopedJavaLocalRef<jclass> byte_array_clazz = GetClass(env, "[B");
Expand Down
8 changes: 8 additions & 0 deletions base/android/jni_array.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,14 @@ BASE_EXPORT ScopedJavaLocalRef<jfloatArray> ToJavaFloatArray(
JNIEnv* env,
const std::vector<float>& floats);

// Returns a new Java double array converted from the given C++ double array.
BASE_EXPORT ScopedJavaLocalRef<jdoubleArray>
ToJavaDoubleArray(JNIEnv* env, const double* doubles, size_t len);

BASE_EXPORT ScopedJavaLocalRef<jdoubleArray> ToJavaDoubleArray(
JNIEnv* env,
const std::vector<double>& doubles);

// Returns a array of Java byte array converted from |v|.
BASE_EXPORT ScopedJavaLocalRef<jobjectArray> ToJavaArrayOfByteArray(
JNIEnv* env, const std::vector<std::string>& v);
Expand Down
4 changes: 2 additions & 2 deletions media/capture/mojom/image_capture.mojom
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
6 changes: 3 additions & 3 deletions media/capture/video/android/video_capture_device_android.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<float> points_of_interest_marshalled;
std::vector<double> 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<jfloatArray> points_of_interest =
base::android::ToJavaFloatArray(env, points_of_interest_marshalled);
ScopedJavaLocalRef<jdoubleArray> points_of_interest =
base::android::ToJavaDoubleArray(env, points_of_interest_marshalled);

const double exposure_compensation = settings->has_exposure_compensation
? settings->exposure_compensation
Expand Down
6 changes: 3 additions & 3 deletions media/capture/video/chromeos/camera_device_delegate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<float, float> {
std::tie(x, y) = [&]() -> std::pair<double, double> {
switch (device_context_->GetCameraFrameOrientation()) {
case 0:
return {x, y};
Expand Down
4 changes: 2 additions & 2 deletions third_party/blink/renderer/modules/imagecapture/point_2d.idl
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -445,24 +445,24 @@
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;
};

Point2D.encode = function(encoder, val) {
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_();
Expand Down

0 comments on commit 9513258

Please sign in to comment.