Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 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 "Layer.h" |
| 24 | #include "SurfaceTextureLayer.h" |
| 25 | |
| 26 | namespace android { |
| 27 | // --------------------------------------------------------------------------- |
| 28 | |
| 29 | |
Daniel Lam | b267579 | 2012-02-23 14:35:13 -0800 | [diff] [blame^] | 30 | SurfaceTextureLayer::SurfaceTextureLayer() |
| 31 | : BufferQueue(true) { |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 32 | } |
| 33 | |
| 34 | SurfaceTextureLayer::~SurfaceTextureLayer() { |
| 35 | } |
| 36 | |
Mathias Agopian | 5bfc245 | 2011-08-08 19:14:03 -0700 | [diff] [blame] | 37 | status_t SurfaceTextureLayer::connect(int api, |
| 38 | uint32_t* outWidth, uint32_t* outHeight, uint32_t* outTransform) { |
Daniel Lam | b267579 | 2012-02-23 14:35:13 -0800 | [diff] [blame^] | 39 | status_t err = BufferQueue::connect(api, |
Mathias Agopian | 5bfc245 | 2011-08-08 19:14:03 -0700 | [diff] [blame] | 40 | outWidth, outHeight, outTransform); |
Jamie Gennis | cb6c755 | 2011-07-30 15:06:10 -0700 | [diff] [blame] | 41 | if (err == NO_ERROR) { |
| 42 | switch(api) { |
Mathias Agopian | 8aedd47 | 2012-01-24 16:39:14 -0800 | [diff] [blame] | 43 | case NATIVE_WINDOW_API_CPU: |
| 44 | // SurfaceTextureClient supports only 2 buffers for CPU connections |
| 45 | this->setBufferCountServer(2); |
| 46 | break; |
Jamie Gennis | cb6c755 | 2011-07-30 15:06:10 -0700 | [diff] [blame] | 47 | case NATIVE_WINDOW_API_MEDIA: |
| 48 | case NATIVE_WINDOW_API_CAMERA: |
| 49 | // Camera preview and videos are rate-limited on the producer |
| 50 | // side. If enabled for this build, we use async mode to always |
| 51 | // show the most recent frame at the cost of requiring an |
| 52 | // additional buffer. |
| 53 | #ifndef NEVER_DEFAULT_TO_ASYNC_MODE |
| 54 | err = setSynchronousMode(false); |
| 55 | break; |
| 56 | #endif |
| 57 | // fall through to set synchronous mode when not defaulting to |
| 58 | // async mode. |
Daniel Lam | b267579 | 2012-02-23 14:35:13 -0800 | [diff] [blame^] | 59 | default: |
Jamie Gennis | cb6c755 | 2011-07-30 15:06:10 -0700 | [diff] [blame] | 60 | err = setSynchronousMode(true); |
| 61 | break; |
| 62 | } |
| 63 | if (err != NO_ERROR) { |
| 64 | disconnect(api); |
| 65 | } |
| 66 | } |
| 67 | return err; |
| 68 | } |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 69 | |
| 70 | // --------------------------------------------------------------------------- |
| 71 | }; // namespace android |