2 * Copyright (C) 2014 The Android Open Source Project
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package com.android.camera.one.v2.photo;
19 import android.hardware.camera2.CameraDevice;
21 import com.android.camera.async.MainThread;
22 import com.android.camera.debug.Logger;
23 import com.android.camera.one.OneCamera;
24 import com.android.camera.one.v2.commands.CameraCommandExecutor;
25 import com.android.camera.one.v2.core.FrameServer;
26 import com.android.camera.one.v2.core.RequestBuilder;
27 import com.android.camera.one.v2.imagesaver.ImageSaver;
28 import com.android.camera.one.v2.sharedimagereader.ManagedImageReader;
29 import com.google.common.base.Supplier;
31 import java.util.Arrays;
33 public final class PictureTakerFactory {
34 private final PictureTakerImpl mPictureTaker;
36 private PictureTakerFactory(PictureTakerImpl pictureTaker) {
37 mPictureTaker = pictureTaker;
40 public static PictureTakerFactory create(Logger.Factory logFactory, MainThread mainExecutor,
41 CameraCommandExecutor commandExecutor,
42 ImageSaver.Builder imageSaverBuilder,
43 FrameServer frameServer,
44 RequestBuilder.Factory rootRequestBuilder,
45 ManagedImageReader sharedImageReader,
46 Supplier<OneCamera.PhotoCaptureParameters.Flash> flashMode) {
47 // When flash is ON, always use the ConvergedImageCaptureCommand which
48 // performs the AF & AE precapture sequence.
49 ImageCaptureCommand flashOnCommand = new ConvergedImageCaptureCommand(
50 sharedImageReader, frameServer, rootRequestBuilder,
51 CameraDevice.TEMPLATE_ZERO_SHUTTER_LAG, CameraDevice.TEMPLATE_ZERO_SHUTTER_LAG,
52 Arrays.asList(rootRequestBuilder), true /* ae */, true /* af */);
54 // When flash is OFF, wait for AF convergence, but not AE convergence
55 // (which can be very slow).
56 ImageCaptureCommand flashOffCommand = new ConvergedImageCaptureCommand(
57 sharedImageReader, frameServer, rootRequestBuilder,
58 CameraDevice.TEMPLATE_ZERO_SHUTTER_LAG, CameraDevice.TEMPLATE_ZERO_SHUTTER_LAG,
59 Arrays.asList(rootRequestBuilder), false /* ae */, true /* af */);
61 // When flash is AUTO, wait for AF & AE.
62 // TODO OPTIMIZE If the last converged-AE state indicates that flash is
63 // not necessary, then this could skip waiting for AE convergence.
64 ImageCaptureCommand flashAutoCommand = new ConvergedImageCaptureCommand(
65 sharedImageReader, frameServer, rootRequestBuilder,
66 CameraDevice.TEMPLATE_ZERO_SHUTTER_LAG, CameraDevice.TEMPLATE_ZERO_SHUTTER_LAG,
67 Arrays.asList(rootRequestBuilder), true /* ae */, true /* af */);
69 ImageCaptureCommand flashBasedCommand = new FlashBasedPhotoCommand(logFactory, flashMode,
70 flashOnCommand, flashAutoCommand, flashOffCommand);
71 return new PictureTakerFactory(new PictureTakerImpl(mainExecutor, commandExecutor,
72 imageSaverBuilder, flashBasedCommand));
75 public PictureTaker providePictureTaker() {