diff options
author | TreeHugger Robot <treehugger-gerrit@google.com> | 2020-06-05 20:23:51 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2020-06-05 20:23:51 +0000 |
commit | dda422308e60a97b806fee516c35584f795b69f4 (patch) | |
tree | 16917591b171fc20ca016a39dddce3c90e926b9f /src | |
parent | c2933d97e2d55c194d29b728f72de94482fdbc3e (diff) | |
parent | 6b473ff950120fd1194a4efb9d479f58b2aec766 (diff) | |
download | Camera2-dda422308e60a97b806fee516c35584f795b69f4.tar.gz |
Merge "Camera: Check for fixed focus devices during touch AF"
Diffstat (limited to 'src')
3 files changed, 98 insertions, 8 deletions
diff --git a/src/com/android/camera/one/v2/autofocus/ManualAutoFocusFactory.java b/src/com/android/camera/one/v2/autofocus/ManualAutoFocusFactory.java index 1681ddbc8..690058acf 100644 --- a/src/com/android/camera/one/v2/autofocus/ManualAutoFocusFactory.java +++ b/src/com/android/camera/one/v2/autofocus/ManualAutoFocusFactory.java @@ -27,6 +27,7 @@ import com.android.camera.one.Settings3A; import com.android.camera.one.v2.commands.CameraCommand; import com.android.camera.one.v2.commands.CameraCommandExecutor; import com.android.camera.one.v2.commands.ResettingRunnableCameraCommand; +import com.android.camera.one.v2.commands.UpdateRequestCommand; import com.android.camera.one.v2.core.FrameServer; import com.android.camera.one.v2.core.RequestBuilder; import com.android.camera.one.v2.core.RequestTemplate; @@ -65,6 +66,8 @@ public class ManualAutoFocusFactory { * @param threadPool The executor on which to schedule delayed tasks. * @param afHoldSeconds The number of seconds to hold AF after a manual AF * sweep is triggered. + * @param aeSupport Camera device supports AE metering regions + * @param afSupport Camera device supports AF and AF metering regions */ public static ManualAutoFocusFactory create(Lifetime lifetime, FrameServer frameServer, CameraCommandExecutor commandExecutor, Supplier<Rect> cropRegion, @@ -72,7 +75,7 @@ public class ManualAutoFocusFactory { Runnable previewRunner, RequestBuilder.Factory rootBuilder, int templateType, Settings3A settings3A, ScheduledExecutorService threadPool, - int afHoldSeconds) { + int afHoldSeconds, boolean aeSupport, boolean afSupport) { ConcurrentState<MeteringParameters> currentMeteringParameters = new ConcurrentState<>( GlobalMeteringParameters.create()); AEMeteringRegion aeMeteringRegion = new AEMeteringRegion(currentMeteringParameters, @@ -81,17 +84,27 @@ public class ManualAutoFocusFactory { cropRegion); RequestTemplate afScanRequestBuilder = new RequestTemplate(rootBuilder); - afScanRequestBuilder.setParam(CaptureRequest.CONTROL_AE_REGIONS, aeMeteringRegion); - afScanRequestBuilder.setParam(CaptureRequest.CONTROL_AF_REGIONS, afMeteringRegion); - - CameraCommand afScanCommand = new FullAFScanCommand(frameServer, afScanRequestBuilder, - templateType); + if (aeSupport) { + afScanRequestBuilder.setParam(CaptureRequest.CONTROL_AE_REGIONS, aeMeteringRegion); + } + if (afSupport) { + afScanRequestBuilder.setParam(CaptureRequest.CONTROL_AF_REGIONS, afMeteringRegion); + } + + CameraCommand initialCommand; + if (afSupport) { + initialCommand = new FullAFScanCommand(frameServer, afScanRequestBuilder, + templateType); + } else { + initialCommand = new UpdateRequestCommand(frameServer, afScanRequestBuilder, + templateType); + } ResettingDelayedExecutor afHoldDelayedExecutor = new ResettingDelayedExecutor( threadPool, afHoldSeconds, TimeUnit.SECONDS); lifetime.add(afHoldDelayedExecutor); - CameraCommand afScanHoldResetCommand = new AFScanHoldResetCommand(afScanCommand, + CameraCommand afScanHoldResetCommand = new AFScanHoldResetCommand(initialCommand, afHoldDelayedExecutor, previewRunner, currentMeteringParameters); Runnable afRunner = new ResettingRunnableCameraCommand(commandExecutor, diff --git a/src/com/android/camera/one/v2/commands/UpdateRequestCommand.java b/src/com/android/camera/one/v2/commands/UpdateRequestCommand.java new file mode 100644 index 000000000..9c15248df --- /dev/null +++ b/src/com/android/camera/one/v2/commands/UpdateRequestCommand.java @@ -0,0 +1,76 @@ +/* + * Copyright (C) 2020 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.camera.one.v2.commands; + +import android.hardware.camera2.CameraAccessException; +import android.hardware.camera2.CaptureRequest; + +import com.android.camera.one.v2.camera2proxy.CameraCaptureSessionClosedException; +import com.android.camera.one.v2.commands.CameraCommand; +import com.android.camera.one.v2.core.FrameServer; +import com.android.camera.one.v2.core.RequestBuilder; +import com.android.camera.one.v2.core.ResourceAcquisitionFailedException; + +import java.util.Arrays; + +import javax.annotation.Nullable; +import javax.annotation.ParametersAreNonnullByDefault; + +/** + * Update repeating request. + */ +@ParametersAreNonnullByDefault +public final class UpdateRequestCommand implements CameraCommand { + private final FrameServer mFrameServer; + private final RequestBuilder.Factory mBuilderFactory; + private final int mTemplateType; + + /** + * @param frameServer Used for sending requests to the camera. + * @param builder Used for building requests. + * @param templateType See + * {@link android.hardware.camera2.CameraDevice#createCaptureRequest} + */ + public UpdateRequestCommand(FrameServer frameServer, RequestBuilder.Factory builder, int + templateType) { + mFrameServer = frameServer; + mBuilderFactory = builder; + mTemplateType = templateType; + } + + /** + * Update repeating request. + */ + @Override + public void run() throws InterruptedException, CameraAccessException, + CameraCaptureSessionClosedException, ResourceAcquisitionFailedException { + FrameServer.Session session = mFrameServer.tryCreateExclusiveSession(); + if (session == null) { + // If there are already other commands interacting with the + // FrameServer just abort. + return; + } + + try { + RequestBuilder builder = mBuilderFactory.create(mTemplateType); + session.submitRequest(Arrays.asList(builder.build()), + FrameServer.RequestType.REPEATING); + } finally { + session.close(); + } + } +} diff --git a/src/com/android/camera/one/v2/common/BasicCameraFactory.java b/src/com/android/camera/one/v2/common/BasicCameraFactory.java index 44883eade..c42f447ca 100644 --- a/src/com/android/camera/one/v2/common/BasicCameraFactory.java +++ b/src/com/android/camera/one/v2/common/BasicCameraFactory.java @@ -148,7 +148,8 @@ public class BasicCameraFactory { Lifetime(lifetime), frameServer, cameraCommandExecutor, cropRegion, sensorOrientation, mPreviewUpdater, requestTemplate, templateType, new Settings3A(), Executors.newScheduledThreadPool(1), - 3 /* afHoldSeconds */); + 3 /* afHoldSeconds */, cameraCharacteristics.isAutoExposureSupported(), + cameraCharacteristics.isAutoFocusSupported()); mManualAutoFocus = manualAutoFocusFactory.provideManualAutoFocus(); Supplier<MeteringRectangle[]> aeRegions = manualAutoFocusFactory.provideAEMeteringRegion(); |