1a67932fe6864ac346e7f78b86df11cf6c5344137Mathias Agopian/* 2a67932fe6864ac346e7f78b86df11cf6c5344137Mathias Agopian * Copyright (C) 2011 The Android Open Source Project 3a67932fe6864ac346e7f78b86df11cf6c5344137Mathias Agopian * 4a67932fe6864ac346e7f78b86df11cf6c5344137Mathias Agopian * Licensed under the Apache License, Version 2.0 (the "License"); 5a67932fe6864ac346e7f78b86df11cf6c5344137Mathias Agopian * you may not use this file except in compliance with the License. 6a67932fe6864ac346e7f78b86df11cf6c5344137Mathias Agopian * You may obtain a copy of the License at 7a67932fe6864ac346e7f78b86df11cf6c5344137Mathias Agopian * 8a67932fe6864ac346e7f78b86df11cf6c5344137Mathias Agopian * http://www.apache.org/licenses/LICENSE-2.0 9a67932fe6864ac346e7f78b86df11cf6c5344137Mathias Agopian * 10a67932fe6864ac346e7f78b86df11cf6c5344137Mathias Agopian * Unless required by applicable law or agreed to in writing, software 11a67932fe6864ac346e7f78b86df11cf6c5344137Mathias Agopian * distributed under the License is distributed on an "AS IS" BASIS, 12a67932fe6864ac346e7f78b86df11cf6c5344137Mathias Agopian * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13a67932fe6864ac346e7f78b86df11cf6c5344137Mathias Agopian * See the License for the specific language governing permissions and 14a67932fe6864ac346e7f78b86df11cf6c5344137Mathias Agopian * limitations under the License. 15a67932fe6864ac346e7f78b86df11cf6c5344137Mathias Agopian */ 16a67932fe6864ac346e7f78b86df11cf6c5344137Mathias Agopian 17a67932fe6864ac346e7f78b86df11cf6c5344137Mathias Agopian#include <stdlib.h> 18a67932fe6864ac346e7f78b86df11cf6c5344137Mathias Agopian#include <stdint.h> 19a67932fe6864ac346e7f78b86df11cf6c5344137Mathias Agopian#include <sys/types.h> 20a67932fe6864ac346e7f78b86df11cf6c5344137Mathias Agopian 21a67932fe6864ac346e7f78b86df11cf6c5344137Mathias Agopian#include <utils/Errors.h> 22a67932fe6864ac346e7f78b86df11cf6c5344137Mathias Agopian 236710604286401d4205c27235a252dd0e5008cc08Mathias Agopian#include "SurfaceFlinger.h" 24a67932fe6864ac346e7f78b86df11cf6c5344137Mathias Agopian#include "SurfaceTextureLayer.h" 25a67932fe6864ac346e7f78b86df11cf6c5344137Mathias Agopian 26a67932fe6864ac346e7f78b86df11cf6c5344137Mathias Agopiannamespace android { 27a67932fe6864ac346e7f78b86df11cf6c5344137Mathias Agopian// --------------------------------------------------------------------------- 28a67932fe6864ac346e7f78b86df11cf6c5344137Mathias Agopian 29a67932fe6864ac346e7f78b86df11cf6c5344137Mathias Agopian 306710604286401d4205c27235a252dd0e5008cc08Mathias AgopianSurfaceTextureLayer::SurfaceTextureLayer(const sp<SurfaceFlinger>& flinger) 31595264f1af12e25dce57d7c5b1d52ed86ac0d0c9Mathias Agopian : BufferQueue(), flinger(flinger) { 32a67932fe6864ac346e7f78b86df11cf6c5344137Mathias Agopian} 33a67932fe6864ac346e7f78b86df11cf6c5344137Mathias Agopian 34a67932fe6864ac346e7f78b86df11cf6c5344137Mathias AgopianSurfaceTextureLayer::~SurfaceTextureLayer() { 356710604286401d4205c27235a252dd0e5008cc08Mathias Agopian // remove ourselves from SurfaceFlinger's list. We do this asynchronously 366710604286401d4205c27235a252dd0e5008cc08Mathias Agopian // because we don't know where this dtor is called from, it could be 376710604286401d4205c27235a252dd0e5008cc08Mathias Agopian // called with the mStateLock held, leading to a dead-lock (it actually 386710604286401d4205c27235a252dd0e5008cc08Mathias Agopian // happens). 396710604286401d4205c27235a252dd0e5008cc08Mathias Agopian class MessageCleanUpList : public MessageBase { 406710604286401d4205c27235a252dd0e5008cc08Mathias Agopian sp<SurfaceFlinger> flinger; 416710604286401d4205c27235a252dd0e5008cc08Mathias Agopian wp<IBinder> gbp; 426710604286401d4205c27235a252dd0e5008cc08Mathias Agopian public: 436710604286401d4205c27235a252dd0e5008cc08Mathias Agopian MessageCleanUpList(const sp<SurfaceFlinger>& flinger, const wp<IBinder>& gbp) 446710604286401d4205c27235a252dd0e5008cc08Mathias Agopian : flinger(flinger), gbp(gbp) { } 456710604286401d4205c27235a252dd0e5008cc08Mathias Agopian virtual bool handler() { 466710604286401d4205c27235a252dd0e5008cc08Mathias Agopian Mutex::Autolock _l(flinger->mStateLock); 476710604286401d4205c27235a252dd0e5008cc08Mathias Agopian flinger->mGraphicBufferProducerList.remove(gbp); 486710604286401d4205c27235a252dd0e5008cc08Mathias Agopian return true; 496710604286401d4205c27235a252dd0e5008cc08Mathias Agopian } 506710604286401d4205c27235a252dd0e5008cc08Mathias Agopian }; 51a4e19521ac4563f2ff6517bcfd63d9b8d33a6d0bMathias Agopian flinger->postMessageAsync( 52a4e19521ac4563f2ff6517bcfd63d9b8d33a6d0bMathias Agopian new MessageCleanUpList(flinger, static_cast<BnGraphicBufferProducer*>(this)) ); 53a67932fe6864ac346e7f78b86df11cf6c5344137Mathias Agopian} 54a67932fe6864ac346e7f78b86df11cf6c5344137Mathias Agopian 55a67932fe6864ac346e7f78b86df11cf6c5344137Mathias Agopian// --------------------------------------------------------------------------- 56a67932fe6864ac346e7f78b86df11cf6c5344137Mathias Agopian}; // namespace android 57