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 | |
Mathias Agopian | 6710604 | 2013-03-14 19:18:13 -0700 | [diff] [blame] | 23 | #include "SurfaceFlinger.h" |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 24 | #include "SurfaceTextureLayer.h" |
| 25 | |
| 26 | namespace android { |
| 27 | // --------------------------------------------------------------------------- |
| 28 | |
| 29 | |
Mathias Agopian | 6710604 | 2013-03-14 19:18:13 -0700 | [diff] [blame] | 30 | SurfaceTextureLayer::SurfaceTextureLayer(const sp<SurfaceFlinger>& flinger) |
| 31 | : BufferQueue(true), flinger(flinger) { |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 32 | } |
| 33 | |
| 34 | SurfaceTextureLayer::~SurfaceTextureLayer() { |
Mathias Agopian | 6710604 | 2013-03-14 19:18:13 -0700 | [diff] [blame] | 35 | // remove ourselves from SurfaceFlinger's list. We do this asynchronously |
| 36 | // because we don't know where this dtor is called from, it could be |
| 37 | // called with the mStateLock held, leading to a dead-lock (it actually |
| 38 | // happens). |
| 39 | class MessageCleanUpList : public MessageBase { |
| 40 | sp<SurfaceFlinger> flinger; |
| 41 | wp<IBinder> gbp; |
| 42 | public: |
| 43 | MessageCleanUpList(const sp<SurfaceFlinger>& flinger, const wp<IBinder>& gbp) |
| 44 | : flinger(flinger), gbp(gbp) { } |
| 45 | virtual bool handler() { |
| 46 | Mutex::Autolock _l(flinger->mStateLock); |
| 47 | flinger->mGraphicBufferProducerList.remove(gbp); |
| 48 | return true; |
| 49 | } |
| 50 | }; |
| 51 | flinger->postMessageAsync( new MessageCleanUpList(flinger, this) ); |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 52 | } |
| 53 | |
Mathias Agopian | 24202f5 | 2012-04-23 14:28:58 -0700 | [diff] [blame] | 54 | status_t SurfaceTextureLayer::connect(int api, QueueBufferOutput* output) { |
| 55 | status_t err = BufferQueue::connect(api, output); |
Jamie Gennis | cb6c755 | 2011-07-30 15:06:10 -0700 | [diff] [blame] | 56 | if (err == NO_ERROR) { |
| 57 | switch(api) { |
| 58 | case NATIVE_WINDOW_API_MEDIA: |
| 59 | case NATIVE_WINDOW_API_CAMERA: |
| 60 | // Camera preview and videos are rate-limited on the producer |
| 61 | // side. If enabled for this build, we use async mode to always |
| 62 | // show the most recent frame at the cost of requiring an |
| 63 | // additional buffer. |
| 64 | #ifndef NEVER_DEFAULT_TO_ASYNC_MODE |
| 65 | err = setSynchronousMode(false); |
| 66 | break; |
| 67 | #endif |
| 68 | // fall through to set synchronous mode when not defaulting to |
| 69 | // async mode. |
Daniel Lam | b267579 | 2012-02-23 14:35:13 -0800 | [diff] [blame] | 70 | default: |
Jamie Gennis | cb6c755 | 2011-07-30 15:06:10 -0700 | [diff] [blame] | 71 | err = setSynchronousMode(true); |
| 72 | break; |
| 73 | } |
| 74 | if (err != NO_ERROR) { |
| 75 | disconnect(api); |
| 76 | } |
| 77 | } |
| 78 | return err; |
| 79 | } |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 80 | |
| 81 | // --------------------------------------------------------------------------- |
| 82 | }; // namespace android |