blob: 9d79ce20e2ffc5c4d936c0faf8196ea14b57e7b0 [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
Mathias Agopian67106042013-03-14 19:18:13 -070023#include "SurfaceFlinger.h"
Mathias Agopiana67932f2011-04-20 14:20:59 -070024#include "SurfaceTextureLayer.h"
25
26namespace android {
27// ---------------------------------------------------------------------------
28
29
Mathias Agopian67106042013-03-14 19:18:13 -070030SurfaceTextureLayer::SurfaceTextureLayer(const sp<SurfaceFlinger>& flinger)
Mathias Agopian595264f2013-07-16 22:56:09 -070031 : BufferQueue(), flinger(flinger) {
Mathias Agopiana67932f2011-04-20 14:20:59 -070032}
33
34SurfaceTextureLayer::~SurfaceTextureLayer() {
Mathias Agopian67106042013-03-14 19:18:13 -070035 // 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 };
Mathias Agopiana4e19522013-07-31 20:09:53 -070051 flinger->postMessageAsync(
52 new MessageCleanUpList(flinger, static_cast<BnGraphicBufferProducer*>(this)) );
Mathias Agopiana67932f2011-04-20 14:20:59 -070053}
54
Mathias Agopiana67932f2011-04-20 14:20:59 -070055// ---------------------------------------------------------------------------
56}; // namespace android