OSDN Git Service

cf585f3820fbe03fa77057291c3cedafaac56919
[android-x86/packages-apps-Camera2.git] / src / com / android / camera / one / v2 / photo / PictureTakerFactory.java
1 /*
2  * Copyright (C) 2014 The Android Open Source Project
3  *
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
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 package com.android.camera.one.v2.photo;
18
19 import android.hardware.camera2.CameraDevice;
20
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;
30
31 import java.util.Arrays;
32
33 public final class PictureTakerFactory {
34     private final PictureTakerImpl mPictureTaker;
35
36     private PictureTakerFactory(PictureTakerImpl pictureTaker) {
37         mPictureTaker = pictureTaker;
38     }
39
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 */);
53
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 */);
60
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 */);
68
69         ImageCaptureCommand flashBasedCommand = new FlashBasedPhotoCommand(logFactory, flashMode,
70                 flashOnCommand, flashAutoCommand, flashOffCommand);
71         return new PictureTakerFactory(new PictureTakerImpl(mainExecutor, commandExecutor,
72                 imageSaverBuilder, flashBasedCommand));
73     }
74
75     public PictureTaker providePictureTaker() {
76         return mPictureTaker;
77     }
78 }