-
Notifications
You must be signed in to change notification settings - Fork 3.4k
[camerax] Implements setFocusPoint
, setExposurePoint
, setExposureOffset
#6059
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 12 commits
b6729ac
14d1024
975806b
a7181b2
ea5f15f
5fe2976
e41a825
9736287
38e88a8
2843626
35ebf13
c2f75ec
b8526e1
928b4cd
3527d9e
1d4d37e
35ab369
0de865a
bb13a35
1a601a4
2c3c9ab
6652171
a08eed6
c35fa15
fac3ff6
077ee37
ff3fc39
fc60e77
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -90,7 +90,7 @@ private CameraStateType(final int index) { | |
* | ||
* <p>On the native side, ensure the following is done: | ||
* | ||
* <p>* Update `LiveDataHostApiImpl#getValue` is updated to properly return identifiers for | ||
* <p>* Make sure `LiveDataHostApiImpl#getValue` is updated to properly return identifiers for | ||
* instances of type S. * Update `ObserverFlutterApiWrapper#onChanged` to properly handle | ||
* receiving calls with instances of type S if a LiveData<S> instance is observed. | ||
*/ | ||
|
@@ -146,6 +146,24 @@ private VideoResolutionFallbackRule(final int index) { | |
} | ||
} | ||
|
||
/** | ||
* The types of capture request options this plugin currently supports. | ||
* | ||
* <p>If you need to add another option to support, ensure the following is done on the Dart side: | ||
* | ||
* <p>* In `../lib/src/capture_request_options.dart`, add new cases for this option in | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: make the path absolute from the base of the plugin, or correct from the current location. |
||
* `_CaptureRequestOptionsHostApiImpl#createFromInstances` to create the expected Map entry of | ||
* option key index and value to send to the native side. | ||
* | ||
* <p>On the native side, ensure the following is done: | ||
* | ||
* <p>* Update `CaptureRequestOptionsHostApiImpl#create` to set the correct `CaptureRequest` key | ||
* with a valid value type for this option. | ||
* | ||
* <p>See https://developer.android.com/reference/android/hardware/camera2/CaptureRequest for the | ||
* sorts of capture request options that can be supported via CameraX's interoperability with | ||
* Camera2. | ||
*/ | ||
public enum CaptureRequestKeySupportedType { | ||
CONTROL_AE_LOCK(0); | ||
|
||
|
@@ -3899,7 +3917,11 @@ public void create(@NonNull Long identifierArg, @NonNull Reply<Void> callback) { | |
public interface MeteringPointHostApi { | ||
|
||
void create( | ||
@NonNull Long identifier, @NonNull Double x, @NonNull Double y, @Nullable Double size); | ||
@NonNull Long identifier, | ||
@NonNull Double x, | ||
@NonNull Double y, | ||
@Nullable Double size, | ||
@NonNull Long cameraInfoId); | ||
|
||
@NonNull | ||
Double getDefaultPointSize(); | ||
|
@@ -3927,12 +3949,14 @@ static void setup( | |
Double xArg = (Double) args.get(1); | ||
Double yArg = (Double) args.get(2); | ||
Double sizeArg = (Double) args.get(3); | ||
Number cameraInfoIdArg = (Number) args.get(4); | ||
try { | ||
api.create( | ||
(identifierArg == null) ? null : identifierArg.longValue(), | ||
xArg, | ||
yArg, | ||
sizeArg); | ||
sizeArg, | ||
(cameraInfoIdArg == null) ? null : cameraInfoIdArg.longValue()); | ||
wrapped.add(0, null); | ||
} catch (Throwable exception) { | ||
ArrayList<Object> wrappedError = wrapError(exception); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,13 +4,20 @@ | |
|
||
package io.flutter.plugins.camerax; | ||
|
||
import android.app.Activity; | ||
import android.content.Context; | ||
import android.os.Build; | ||
import android.view.Display; | ||
import android.view.WindowManager; | ||
import androidx.annotation.NonNull; | ||
import androidx.annotation.Nullable; | ||
import androidx.annotation.VisibleForTesting; | ||
import androidx.camera.core.CameraInfo; | ||
import androidx.camera.core.DisplayOrientedMeteringPointFactory; | ||
import androidx.camera.core.MeteringPoint; | ||
import androidx.camera.core.MeteringPointFactory; | ||
import androidx.camera.core.SurfaceOrientedMeteringPointFactory; | ||
import io.flutter.plugins.camerax.GeneratedCameraXLibrary.MeteringPointHostApi; | ||
import java.util.Objects; | ||
|
||
/** | ||
* Host API implementation for {@link MeteringPoint}. | ||
|
@@ -25,17 +32,34 @@ public class MeteringPointHostApiImpl implements MeteringPointHostApi { | |
/** Proxy for constructor and static methods of {@link MeteringPoint}. */ | ||
@VisibleForTesting | ||
public static class MeteringPointProxy { | ||
Activity activity; | ||
|
||
/** | ||
* Creates a surface oriented {@link MeteringPoint} with the specified x, y, and size. | ||
* | ||
* <p>A {@link SurfaceOrientedMeteringPointFactory} is used to construct the {@link | ||
* MeteringPoint} because underlying the camera preview that this plugin uses is a Flutter | ||
* texture that is backed by a {@link Surface} created by the Flutter Android embedding. | ||
* <p>A {@link DisplayOrientedMeteringPointFactory} is used to construct the {@link | ||
* MeteringPoint} because this factory handles the transformation of specified coordinates based | ||
* on camera information and the device orientation automatically. | ||
*/ | ||
@NonNull | ||
public MeteringPoint create(@NonNull Double x, @NonNull Double y, @Nullable Double size) { | ||
SurfaceOrientedMeteringPointFactory factory = getSurfaceOrientedMeteringPointFactory(1f, 1f); | ||
@SuppressWarnings("deprecation") | ||
gmackall marked this conversation as resolved.
Show resolved
Hide resolved
|
||
public MeteringPoint create( | ||
@NonNull Double x, | ||
@NonNull Double y, | ||
@Nullable Double size, | ||
@NonNull CameraInfo cameraInfo) { | ||
Display display = null; | ||
|
||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { | ||
display = activity.getDisplay(); | ||
} else { | ||
display = | ||
((WindowManager) activity.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay(); | ||
} | ||
|
||
DisplayOrientedMeteringPointFactory factory = | ||
getDisplayOrientedMeteringPointFactory(display, 1f, 1f, cameraInfo); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A slightly larger fix: I originally implemented this host API with a different |
||
|
||
if (size == null) { | ||
return factory.createPoint(x.floatValue(), y.floatValue()); | ||
} else { | ||
|
@@ -45,9 +69,9 @@ public MeteringPoint create(@NonNull Double x, @NonNull Double y, @Nullable Doub | |
|
||
@VisibleForTesting | ||
@NonNull | ||
public SurfaceOrientedMeteringPointFactory getSurfaceOrientedMeteringPointFactory( | ||
float width, float height) { | ||
return new SurfaceOrientedMeteringPointFactory(width, height); | ||
public DisplayOrientedMeteringPointFactory getDisplayOrientedMeteringPointFactory( | ||
Display display, float width, float height, CameraInfo cameraInfo) { | ||
return new DisplayOrientedMeteringPointFactory(display, cameraInfo, width, height); | ||
} | ||
|
||
/** | ||
|
@@ -81,10 +105,23 @@ public MeteringPointHostApiImpl(@NonNull InstanceManager instanceManager) { | |
this.proxy = proxy; | ||
} | ||
|
||
public void setActivity(@NonNull Activity activity) { | ||
this.proxy.activity = activity; | ||
} | ||
|
||
@Override | ||
public void create( | ||
@NonNull Long identifier, @NonNull Double x, @NonNull Double y, @Nullable Double size) { | ||
MeteringPoint meteringPoint = proxy.create(x, y, size); | ||
@NonNull Long identifier, | ||
@NonNull Double x, | ||
@NonNull Double y, | ||
@Nullable Double size, | ||
@NonNull Long cameraInfoId) { | ||
MeteringPoint meteringPoint = | ||
proxy.create( | ||
x, | ||
y, | ||
size, | ||
(CameraInfo) Objects.requireNonNull(instanceManager.getInstance(cameraInfoId))); | ||
instanceManager.addDartCreatedInstance(meteringPoint, identifier); | ||
} | ||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.