am e7d3ee9d
: Revert "merge various SF fixes from gingerbread to honeycomb-mr2" (DO NOT MERGE)
* commit 'e7d3ee9d81de13e992c7d063ca472d480956b0c6': Revert "merge various SF fixes from gingerbread to honeycomb-mr2" (DO NOT MERGE)
This commit is contained in:
@ -120,7 +120,7 @@ public:
|
|||||||
protected:
|
protected:
|
||||||
RefBase();
|
RefBase();
|
||||||
virtual ~RefBase();
|
virtual ~RefBase();
|
||||||
|
|
||||||
//! Flags for extendObjectLifetime()
|
//! Flags for extendObjectLifetime()
|
||||||
enum {
|
enum {
|
||||||
OBJECT_LIFETIME_WEAK = 0x0001,
|
OBJECT_LIFETIME_WEAK = 0x0001,
|
||||||
|
@ -145,6 +145,18 @@ sp<LayerBaseClient::Surface> Layer::createSurface() const
|
|||||||
return sur;
|
return sur;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
status_t Layer::ditch()
|
||||||
|
{
|
||||||
|
// NOTE: Called from the main UI thread
|
||||||
|
|
||||||
|
// the layer is not on screen anymore. free as much resources as possible
|
||||||
|
mFreezeLock.clear();
|
||||||
|
|
||||||
|
Mutex::Autolock _l(mLock);
|
||||||
|
mWidth = mHeight = 0;
|
||||||
|
return NO_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
status_t Layer::setBuffers( uint32_t w, uint32_t h,
|
status_t Layer::setBuffers( uint32_t w, uint32_t h,
|
||||||
PixelFormat format, uint32_t flags)
|
PixelFormat format, uint32_t flags)
|
||||||
{
|
{
|
||||||
|
@ -82,6 +82,7 @@ public:
|
|||||||
virtual bool isSecure() const { return mSecure; }
|
virtual bool isSecure() const { return mSecure; }
|
||||||
virtual bool isProtected() const;
|
virtual bool isProtected() const;
|
||||||
virtual sp<Surface> createSurface() const;
|
virtual sp<Surface> createSurface() const;
|
||||||
|
virtual status_t ditch();
|
||||||
virtual void onRemoved();
|
virtual void onRemoved();
|
||||||
|
|
||||||
// only for debugging
|
// only for debugging
|
||||||
|
@ -616,7 +616,10 @@ LayerBaseClient::Surface::~Surface()
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
// destroy client resources
|
// destroy client resources
|
||||||
mFlinger->destroySurface(mOwner);
|
sp<LayerBaseClient> layer = getOwner();
|
||||||
|
if (layer != 0) {
|
||||||
|
mFlinger->destroySurface(layer);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sp<LayerBaseClient> LayerBaseClient::Surface::getOwner() const {
|
sp<LayerBaseClient> LayerBaseClient::Surface::getOwner() const {
|
||||||
|
@ -202,6 +202,10 @@ public:
|
|||||||
*/
|
*/
|
||||||
virtual bool isProtected() const { return false; }
|
virtual bool isProtected() const { return false; }
|
||||||
|
|
||||||
|
/** Called from the main thread, when the surface is removed from the
|
||||||
|
* draw list */
|
||||||
|
virtual status_t ditch() { return NO_ERROR; }
|
||||||
|
|
||||||
/** called with the state lock when the surface is removed from the
|
/** called with the state lock when the surface is removed from the
|
||||||
* current list */
|
* current list */
|
||||||
virtual void onRemoved() { };
|
virtual void onRemoved() { };
|
||||||
@ -267,8 +271,7 @@ protected:
|
|||||||
volatile int32_t mInvalidate;
|
volatile int32_t mInvalidate;
|
||||||
|
|
||||||
|
|
||||||
public:
|
protected:
|
||||||
// called from class SurfaceFlinger
|
|
||||||
virtual ~LayerBase();
|
virtual ~LayerBase();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -395,7 +395,7 @@ bool SurfaceFlinger::threadLoop()
|
|||||||
if (LIKELY(mTransactionCount == 0)) {
|
if (LIKELY(mTransactionCount == 0)) {
|
||||||
// if we're in a global transaction, don't do anything.
|
// if we're in a global transaction, don't do anything.
|
||||||
const uint32_t mask = eTransactionNeeded | eTraversalNeeded;
|
const uint32_t mask = eTransactionNeeded | eTraversalNeeded;
|
||||||
uint32_t transactionFlags = peekTransactionFlags(mask);
|
uint32_t transactionFlags = getTransactionFlags(mask);
|
||||||
if (LIKELY(transactionFlags)) {
|
if (LIKELY(transactionFlags)) {
|
||||||
handleTransaction(transactionFlags);
|
handleTransaction(transactionFlags);
|
||||||
}
|
}
|
||||||
@ -480,26 +480,39 @@ void SurfaceFlinger::handleConsoleEvents()
|
|||||||
|
|
||||||
void SurfaceFlinger::handleTransaction(uint32_t transactionFlags)
|
void SurfaceFlinger::handleTransaction(uint32_t transactionFlags)
|
||||||
{
|
{
|
||||||
Mutex::Autolock _l(mStateLock);
|
Vector< sp<LayerBase> > ditchedLayers;
|
||||||
const nsecs_t now = systemTime();
|
|
||||||
mDebugInTransaction = now;
|
|
||||||
|
|
||||||
// Here we're guaranteed that some transaction flags are set
|
/*
|
||||||
// so we can call handleTransactionLocked() unconditionally.
|
* Perform and commit the transaction
|
||||||
// We call getTransactionFlags(), which will also clear the flags,
|
*/
|
||||||
// with mStateLock held to guarantee that mCurrentState won't change
|
|
||||||
// until the transaction is committed.
|
|
||||||
|
|
||||||
const uint32_t mask = eTransactionNeeded | eTraversalNeeded;
|
{ // scope for the lock
|
||||||
transactionFlags = getTransactionFlags(mask);
|
Mutex::Autolock _l(mStateLock);
|
||||||
handleTransactionLocked(transactionFlags);
|
const nsecs_t now = systemTime();
|
||||||
|
mDebugInTransaction = now;
|
||||||
|
handleTransactionLocked(transactionFlags, ditchedLayers);
|
||||||
|
mLastTransactionTime = systemTime() - now;
|
||||||
|
mDebugInTransaction = 0;
|
||||||
|
invalidateHwcGeometry();
|
||||||
|
// here the transaction has been committed
|
||||||
|
}
|
||||||
|
|
||||||
mLastTransactionTime = systemTime() - now;
|
/*
|
||||||
mDebugInTransaction = 0;
|
* Clean-up all layers that went away
|
||||||
// here the transaction has been committed
|
* (do this without the lock held)
|
||||||
|
*/
|
||||||
|
|
||||||
|
const size_t count = ditchedLayers.size();
|
||||||
|
for (size_t i=0 ; i<count ; i++) {
|
||||||
|
if (ditchedLayers[i] != 0) {
|
||||||
|
//LOGD("ditching layer %p", ditchedLayers[i].get());
|
||||||
|
ditchedLayers[i]->ditch();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SurfaceFlinger::handleTransactionLocked(uint32_t transactionFlags)
|
void SurfaceFlinger::handleTransactionLocked(
|
||||||
|
uint32_t transactionFlags, Vector< sp<LayerBase> >& ditchedLayers)
|
||||||
{
|
{
|
||||||
const LayerVector& currentLayers(mCurrentState.layersSortedByZ);
|
const LayerVector& currentLayers(mCurrentState.layersSortedByZ);
|
||||||
const size_t count = currentLayers.size();
|
const size_t count = currentLayers.size();
|
||||||
@ -571,6 +584,7 @@ void SurfaceFlinger::handleTransactionLocked(uint32_t transactionFlags)
|
|||||||
const sp<LayerBase>& layer(previousLayers[i]);
|
const sp<LayerBase>& layer(previousLayers[i]);
|
||||||
if (currentLayers.indexOf( layer ) < 0) {
|
if (currentLayers.indexOf( layer ) < 0) {
|
||||||
// this layer is not visible anymore
|
// this layer is not visible anymore
|
||||||
|
ditchedLayers.add(layer);
|
||||||
mDirtyRegionRemovedLayer.orSelf(layer->visibleRegionScreen);
|
mDirtyRegionRemovedLayer.orSelf(layer->visibleRegionScreen);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1082,15 +1096,15 @@ status_t SurfaceFlinger::addLayer_l(const sp<LayerBase>& layer)
|
|||||||
ssize_t SurfaceFlinger::addClientLayer(const sp<Client>& client,
|
ssize_t SurfaceFlinger::addClientLayer(const sp<Client>& client,
|
||||||
const sp<LayerBaseClient>& lbc)
|
const sp<LayerBaseClient>& lbc)
|
||||||
{
|
{
|
||||||
// attach this layer to the client
|
|
||||||
size_t name = client->attachLayer(lbc);
|
|
||||||
|
|
||||||
Mutex::Autolock _l(mStateLock);
|
Mutex::Autolock _l(mStateLock);
|
||||||
|
|
||||||
|
// attach this layer to the client
|
||||||
|
ssize_t name = client->attachLayer(lbc);
|
||||||
|
|
||||||
// add this layer to the current state list
|
// add this layer to the current state list
|
||||||
addLayer_l(lbc);
|
addLayer_l(lbc);
|
||||||
|
|
||||||
return ssize_t(name);
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
status_t SurfaceFlinger::removeLayer(const sp<LayerBase>& layer)
|
status_t SurfaceFlinger::removeLayer(const sp<LayerBase>& layer)
|
||||||
@ -1141,11 +1155,6 @@ status_t SurfaceFlinger::invalidateLayerVisibility(const sp<LayerBase>& layer)
|
|||||||
return NO_ERROR;
|
return NO_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t SurfaceFlinger::peekTransactionFlags(uint32_t flags)
|
|
||||||
{
|
|
||||||
return android_atomic_release_load(&mTransactionFlags);
|
|
||||||
}
|
|
||||||
|
|
||||||
uint32_t SurfaceFlinger::getTransactionFlags(uint32_t flags)
|
uint32_t SurfaceFlinger::getTransactionFlags(uint32_t flags)
|
||||||
{
|
{
|
||||||
return android_atomic_and(~flags, &mTransactionFlags) & flags;
|
return android_atomic_and(~flags, &mTransactionFlags) & flags;
|
||||||
@ -1353,26 +1362,51 @@ status_t SurfaceFlinger::removeSurface(const sp<Client>& client, SurfaceID sid)
|
|||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
status_t SurfaceFlinger::destroySurface(const wp<LayerBaseClient>& layer)
|
status_t SurfaceFlinger::destroySurface(const sp<LayerBaseClient>& layer)
|
||||||
{
|
{
|
||||||
// called by ~ISurface() when all references are gone
|
// called by ~ISurface() when all references are gone
|
||||||
status_t err = NO_ERROR;
|
|
||||||
sp<LayerBaseClient> l(layer.promote());
|
class MessageDestroySurface : public MessageBase {
|
||||||
if (l != NULL) {
|
SurfaceFlinger* flinger;
|
||||||
Mutex::Autolock _l(mStateLock);
|
sp<LayerBaseClient> layer;
|
||||||
err = removeLayer_l(l);
|
public:
|
||||||
if (err == NAME_NOT_FOUND) {
|
MessageDestroySurface(
|
||||||
// The surface wasn't in the current list, which means it was
|
SurfaceFlinger* flinger, const sp<LayerBaseClient>& layer)
|
||||||
// removed already, which means it is in the purgatory,
|
: flinger(flinger), layer(layer) { }
|
||||||
// and need to be removed from there.
|
virtual bool handler() {
|
||||||
ssize_t idx = mLayerPurgatory.remove(l);
|
sp<LayerBaseClient> l(layer);
|
||||||
LOGE_IF(idx < 0,
|
layer.clear(); // clear it outside of the lock;
|
||||||
"layer=%p is not in the purgatory list", l.get());
|
Mutex::Autolock _l(flinger->mStateLock);
|
||||||
|
/*
|
||||||
|
* remove the layer from the current list -- chances are that it's
|
||||||
|
* not in the list anyway, because it should have been removed
|
||||||
|
* already upon request of the client (eg: window manager).
|
||||||
|
* However, a buggy client could have not done that.
|
||||||
|
* Since we know we don't have any more clients, we don't need
|
||||||
|
* to use the purgatory.
|
||||||
|
*/
|
||||||
|
status_t err = flinger->removeLayer_l(l);
|
||||||
|
if (err == NAME_NOT_FOUND) {
|
||||||
|
// The surface wasn't in the current list, which means it was
|
||||||
|
// removed already, which means it is in the purgatory,
|
||||||
|
// and need to be removed from there.
|
||||||
|
// This needs to happen from the main thread since its dtor
|
||||||
|
// must run from there (b/c of OpenGL ES). Additionally, we
|
||||||
|
// can't really acquire our internal lock from
|
||||||
|
// destroySurface() -- see postMessage() below.
|
||||||
|
ssize_t idx = flinger->mLayerPurgatory.remove(l);
|
||||||
|
LOGE_IF(idx < 0,
|
||||||
|
"layer=%p is not in the purgatory list", l.get());
|
||||||
|
}
|
||||||
|
|
||||||
|
LOGE_IF(err<0 && err != NAME_NOT_FOUND,
|
||||||
|
"error removing layer=%p (%s)", l.get(), strerror(-err));
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
LOGE_IF(err<0 && err != NAME_NOT_FOUND,
|
};
|
||||||
"error removing layer=%p (%s)", l.get(), strerror(-err));
|
|
||||||
}
|
postMessageAsync( new MessageDestroySurface(this, layer) );
|
||||||
return err;
|
return NO_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
status_t SurfaceFlinger::setClientState(
|
status_t SurfaceFlinger::setClientState(
|
||||||
@ -2347,17 +2381,15 @@ status_t Client::initCheck() const {
|
|||||||
return NO_ERROR;
|
return NO_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Client::attachLayer(const sp<LayerBaseClient>& layer)
|
ssize_t Client::attachLayer(const sp<LayerBaseClient>& layer)
|
||||||
{
|
{
|
||||||
Mutex::Autolock _l(mLock);
|
int32_t name = android_atomic_inc(&mNameGenerator);
|
||||||
size_t name = mNameGenerator++;
|
|
||||||
mLayers.add(name, layer);
|
mLayers.add(name, layer);
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Client::detachLayer(const LayerBaseClient* layer)
|
void Client::detachLayer(const LayerBaseClient* layer)
|
||||||
{
|
{
|
||||||
Mutex::Autolock _l(mLock);
|
|
||||||
// we do a linear search here, because this doesn't happen often
|
// we do a linear search here, because this doesn't happen often
|
||||||
const size_t count = mLayers.size();
|
const size_t count = mLayers.size();
|
||||||
for (size_t i=0 ; i<count ; i++) {
|
for (size_t i=0 ; i<count ; i++) {
|
||||||
@ -2367,11 +2399,9 @@ void Client::detachLayer(const LayerBaseClient* layer)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sp<LayerBaseClient> Client::getLayerUser(int32_t i) const
|
sp<LayerBaseClient> Client::getLayerUser(int32_t i) const {
|
||||||
{
|
|
||||||
Mutex::Autolock _l(mLock);
|
|
||||||
sp<LayerBaseClient> lbc;
|
sp<LayerBaseClient> lbc;
|
||||||
wp<LayerBaseClient> layer(mLayers.valueFor(i));
|
const wp<LayerBaseClient>& layer(mLayers.valueFor(i));
|
||||||
if (layer != 0) {
|
if (layer != 0) {
|
||||||
lbc = layer.promote();
|
lbc = layer.promote();
|
||||||
LOGE_IF(lbc==0, "getLayerUser(name=%d) is dead", int(i));
|
LOGE_IF(lbc==0, "getLayerUser(name=%d) is dead", int(i));
|
||||||
|
@ -65,7 +65,7 @@ public:
|
|||||||
status_t initCheck() const;
|
status_t initCheck() const;
|
||||||
|
|
||||||
// protected by SurfaceFlinger::mStateLock
|
// protected by SurfaceFlinger::mStateLock
|
||||||
size_t attachLayer(const sp<LayerBaseClient>& layer);
|
ssize_t attachLayer(const sp<LayerBaseClient>& layer);
|
||||||
void detachLayer(const LayerBaseClient* layer);
|
void detachLayer(const LayerBaseClient* layer);
|
||||||
sp<LayerBaseClient> getLayerUser(int32_t i) const;
|
sp<LayerBaseClient> getLayerUser(int32_t i) const;
|
||||||
|
|
||||||
@ -81,15 +81,9 @@ private:
|
|||||||
virtual status_t destroySurface(SurfaceID surfaceId);
|
virtual status_t destroySurface(SurfaceID surfaceId);
|
||||||
virtual status_t setState(int32_t count, const layer_state_t* states);
|
virtual status_t setState(int32_t count, const layer_state_t* states);
|
||||||
|
|
||||||
// constant
|
|
||||||
sp<SurfaceFlinger> mFlinger;
|
|
||||||
|
|
||||||
// protected by mLock
|
|
||||||
DefaultKeyedVector< size_t, wp<LayerBaseClient> > mLayers;
|
DefaultKeyedVector< size_t, wp<LayerBaseClient> > mLayers;
|
||||||
size_t mNameGenerator;
|
sp<SurfaceFlinger> mFlinger;
|
||||||
|
int32_t mNameGenerator;
|
||||||
// thread-safe
|
|
||||||
mutable Mutex mLock;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class UserClient : public BnSurfaceComposerClient
|
class UserClient : public BnSurfaceComposerClient
|
||||||
@ -260,7 +254,7 @@ private:
|
|||||||
uint32_t w, uint32_t h, uint32_t flags);
|
uint32_t w, uint32_t h, uint32_t flags);
|
||||||
|
|
||||||
status_t removeSurface(const sp<Client>& client, SurfaceID sid);
|
status_t removeSurface(const sp<Client>& client, SurfaceID sid);
|
||||||
status_t destroySurface(const wp<LayerBaseClient>& layer);
|
status_t destroySurface(const sp<LayerBaseClient>& layer);
|
||||||
status_t setClientState(const sp<Client>& client,
|
status_t setClientState(const sp<Client>& client,
|
||||||
int32_t count, const layer_state_t* states);
|
int32_t count, const layer_state_t* states);
|
||||||
|
|
||||||
@ -305,7 +299,9 @@ public: // hack to work around gcc 4.0.3 bug
|
|||||||
private:
|
private:
|
||||||
void handleConsoleEvents();
|
void handleConsoleEvents();
|
||||||
void handleTransaction(uint32_t transactionFlags);
|
void handleTransaction(uint32_t transactionFlags);
|
||||||
void handleTransactionLocked(uint32_t transactionFlags);
|
void handleTransactionLocked(
|
||||||
|
uint32_t transactionFlags,
|
||||||
|
Vector< sp<LayerBase> >& ditchedLayers);
|
||||||
|
|
||||||
void computeVisibleRegions(
|
void computeVisibleRegions(
|
||||||
LayerVector& currentLayers,
|
LayerVector& currentLayers,
|
||||||
@ -328,7 +324,6 @@ private:
|
|||||||
status_t purgatorizeLayer_l(const sp<LayerBase>& layer);
|
status_t purgatorizeLayer_l(const sp<LayerBase>& layer);
|
||||||
|
|
||||||
uint32_t getTransactionFlags(uint32_t flags);
|
uint32_t getTransactionFlags(uint32_t flags);
|
||||||
uint32_t peekTransactionFlags(uint32_t flags);
|
|
||||||
uint32_t setTransactionFlags(uint32_t flags);
|
uint32_t setTransactionFlags(uint32_t flags);
|
||||||
void commitTransaction();
|
void commitTransaction();
|
||||||
|
|
||||||
@ -427,7 +422,6 @@ private:
|
|||||||
// these are thread safe
|
// these are thread safe
|
||||||
mutable Barrier mReadyToRunBarrier;
|
mutable Barrier mReadyToRunBarrier;
|
||||||
|
|
||||||
|
|
||||||
// atomic variables
|
// atomic variables
|
||||||
enum {
|
enum {
|
||||||
eConsoleReleased = 1,
|
eConsoleReleased = 1,
|
||||||
|
Reference in New Issue
Block a user