OSDN Git Service

395c8c835343f9fc1a1c7a6ff727e07018225993
[android-x86/frameworks-native.git] / services / surfaceflinger / SurfaceTextureLayer.cpp
1 /*
2  * Copyright (C) 2011 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 #include <stdlib.h>
18 #include <stdint.h>
19 #include <sys/types.h>
20
21 #include <utils/Errors.h>
22
23 #include "SurfaceTextureLayer.h"
24
25 namespace android {
26 // ---------------------------------------------------------------------------
27
28
29 SurfaceTextureLayer::SurfaceTextureLayer()
30     : BufferQueue(true) {
31 }
32
33 SurfaceTextureLayer::~SurfaceTextureLayer() {
34 }
35
36 status_t SurfaceTextureLayer::connect(int api, QueueBufferOutput* output) {
37     status_t err = BufferQueue::connect(api, output);
38     if (err == NO_ERROR) {
39         switch(api) {
40             case NATIVE_WINDOW_API_MEDIA:
41             case NATIVE_WINDOW_API_CAMERA:
42                 // Camera preview and videos are rate-limited on the producer
43                 // side.  If enabled for this build, we use async mode to always
44                 // show the most recent frame at the cost of requiring an
45                 // additional buffer.
46 #ifndef NEVER_DEFAULT_TO_ASYNC_MODE
47                 err = setSynchronousMode(false);
48                 break;
49 #endif
50                 // fall through to set synchronous mode when not defaulting to
51                 // async mode.
52             default:
53                 err = setSynchronousMode(true);
54                 break;
55         }
56         if (err != NO_ERROR) {
57             disconnect(api);
58         }
59     }
60     return err;
61 }
62
63 // ---------------------------------------------------------------------------
64 }; // namespace android