blob: 2b647bb8a11fa00d48e31a10b5df5d8abd13cea0 [file] [log] [blame]
Mathias Agopiana67932f2011-04-20 14:20:59 -07001/*
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 "Layer.h"
24#include "SurfaceTextureLayer.h"
25
26namespace android {
27// ---------------------------------------------------------------------------
28
29
Daniel Lamb2675792012-02-23 14:35:13 -080030SurfaceTextureLayer::SurfaceTextureLayer()
31 : BufferQueue(true) {
Mathias Agopiana67932f2011-04-20 14:20:59 -070032}
33
34SurfaceTextureLayer::~SurfaceTextureLayer() {
35}
36
Mathias Agopian5bfc2452011-08-08 19:14:03 -070037status_t SurfaceTextureLayer::connect(int api,
38 uint32_t* outWidth, uint32_t* outHeight, uint32_t* outTransform) {
Daniel Lamb2675792012-02-23 14:35:13 -080039 status_t err = BufferQueue::connect(api,
Mathias Agopian5bfc2452011-08-08 19:14:03 -070040 outWidth, outHeight, outTransform);
Jamie Genniscb6c7552011-07-30 15:06:10 -070041 if (err == NO_ERROR) {
42 switch(api) {
43 case NATIVE_WINDOW_API_MEDIA:
44 case NATIVE_WINDOW_API_CAMERA:
45 // Camera preview and videos are rate-limited on the producer
46 // side. If enabled for this build, we use async mode to always
47 // show the most recent frame at the cost of requiring an
48 // additional buffer.
49#ifndef NEVER_DEFAULT_TO_ASYNC_MODE
50 err = setSynchronousMode(false);
51 break;
52#endif
53 // fall through to set synchronous mode when not defaulting to
54 // async mode.
Daniel Lamb2675792012-02-23 14:35:13 -080055 default:
Jamie Genniscb6c7552011-07-30 15:06:10 -070056 err = setSynchronousMode(true);
57 break;
58 }
59 if (err != NO_ERROR) {
60 disconnect(api);
61 }
62 }
63 return err;
64}
Mathias Agopiana67932f2011-04-20 14:20:59 -070065
66// ---------------------------------------------------------------------------
67}; // namespace android