get rid of Surface identity and token

we use the IBinder instead.

Change-Id: I4aa0b58869ba43f19980013620051e5a261b062d
This commit is contained in:
Mathias Agopian 2013-02-11 16:40:36 -08:00
parent b997f6ef0f
commit ac9fa427d4
15 changed files with 147 additions and 208 deletions

View File

@ -29,8 +29,6 @@
namespace android { namespace android {
typedef int32_t SurfaceID;
class IGraphicBufferProducer; class IGraphicBufferProducer;
class ISurface : public IInterface class ISurface : public IInterface

View File

@ -54,24 +54,17 @@ public:
eFXSurfaceMask = 0x000F0000, eFXSurfaceMask = 0x000F0000,
}; };
struct surface_data_t {
int32_t token;
int32_t identity;
status_t readFromParcel(const Parcel& parcel);
status_t writeToParcel(Parcel* parcel) const;
};
/* /*
* Requires ACCESS_SURFACE_FLINGER permission * Requires ACCESS_SURFACE_FLINGER permission
*/ */
virtual sp<ISurface> createSurface(surface_data_t* data, virtual sp<ISurface> createSurface(
const String8& name, uint32_t w, uint32_t h, const String8& name, uint32_t w, uint32_t h,
PixelFormat format, uint32_t flags) = 0; PixelFormat format, uint32_t flags) = 0;
/* /*
* Requires ACCESS_SURFACE_FLINGER permission * Requires ACCESS_SURFACE_FLINGER permission
*/ */
virtual status_t destroySurface(SurfaceID sid) = 0; virtual status_t destroySurface(const sp<IBinder>& handle) = 0;
}; };
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------

View File

@ -50,13 +50,11 @@ public:
return (surface != 0) && surface->isValid(); return (surface != 0) && surface->isValid();
} }
bool isValid() { bool isValid() {
return mToken>=0 && mClient!=0; return mSurface!=0 && mClient!=0;
} }
static bool isSameSurface( static bool isSameSurface(
const sp<SurfaceControl>& lhs, const sp<SurfaceControl>& rhs); const sp<SurfaceControl>& lhs, const sp<SurfaceControl>& rhs);
uint32_t getIdentity() const { return mIdentity; }
// release surface data from java // release surface data from java
void clear(); void clear();
@ -87,8 +85,7 @@ private:
SurfaceControl( SurfaceControl(
const sp<SurfaceComposerClient>& client, const sp<SurfaceComposerClient>& client,
const sp<ISurface>& surface, const sp<ISurface>& surface);
const ISurfaceComposerClient::surface_data_t& data);
~SurfaceControl(); ~SurfaceControl();
@ -96,11 +93,8 @@ private:
void destroy(); void destroy();
sp<SurfaceComposerClient> mClient; sp<SurfaceComposerClient> mClient;
sp<ISurface> mSurface; sp<IBinder> mSurface;
SurfaceID mToken;
uint32_t mIdentity;
mutable Mutex mLock; mutable Mutex mLock;
mutable sp<Surface> mSurfaceData; mutable sp<Surface> mSurfaceData;
}; };

View File

@ -108,18 +108,18 @@ public:
//! Flag the currently open transaction as an animation transaction. //! Flag the currently open transaction as an animation transaction.
static void setAnimationTransaction(); static void setAnimationTransaction();
status_t hide(SurfaceID id); status_t hide(const sp<IBinder>& id);
status_t show(SurfaceID id); status_t show(const sp<IBinder>& id);
status_t setFlags(SurfaceID id, uint32_t flags, uint32_t mask); status_t setFlags(const sp<IBinder>& id, uint32_t flags, uint32_t mask);
status_t setTransparentRegionHint(SurfaceID id, const Region& transparent); status_t setTransparentRegionHint(const sp<IBinder>& id, const Region& transparent);
status_t setLayer(SurfaceID id, int32_t layer); status_t setLayer(const sp<IBinder>& id, int32_t layer);
status_t setAlpha(SurfaceID id, float alpha=1.0f); status_t setAlpha(const sp<IBinder>& id, float alpha=1.0f);
status_t setMatrix(SurfaceID id, float dsdx, float dtdx, float dsdy, float dtdy); status_t setMatrix(const sp<IBinder>& id, float dsdx, float dtdx, float dsdy, float dtdy);
status_t setPosition(SurfaceID id, float x, float y); status_t setPosition(const sp<IBinder>& id, float x, float y);
status_t setSize(SurfaceID id, uint32_t w, uint32_t h); status_t setSize(const sp<IBinder>& id, uint32_t w, uint32_t h);
status_t setCrop(SurfaceID id, const Rect& crop); status_t setCrop(const sp<IBinder>& id, const Rect& crop);
status_t setLayerStack(SurfaceID id, uint32_t layerStack); status_t setLayerStack(const sp<IBinder>& id, uint32_t layerStack);
status_t destroySurface(SurfaceID sid); status_t destroySurface(const sp<IBinder>& id);
static void setDisplaySurface(const sp<IBinder>& token, static void setDisplaySurface(const sp<IBinder>& token,
const sp<IGraphicBufferProducer>& bufferProducer); const sp<IGraphicBufferProducer>& bufferProducer);

View File

@ -51,7 +51,7 @@ struct layer_state_t {
}; };
layer_state_t() layer_state_t()
: surface(0), what(0), : what(0),
x(0), y(0), z(0), w(0), h(0), layerStack(0), x(0), y(0), z(0), w(0), h(0), layerStack(0),
alpha(0), flags(0), mask(0), alpha(0), flags(0), mask(0),
reserved(0) reserved(0)
@ -70,7 +70,7 @@ struct layer_state_t {
float dsdy; float dsdy;
float dtdy; float dtdy;
}; };
SurfaceID surface; sp<IBinder> surface;
uint32_t what; uint32_t what;
float x; float x;
float y; float y;

View File

@ -50,8 +50,7 @@ public:
{ {
} }
virtual sp<ISurface> createSurface( surface_data_t* params, virtual sp<ISurface> createSurface( const String8& name,
const String8& name,
uint32_t w, uint32_t w,
uint32_t h, uint32_t h,
PixelFormat format, PixelFormat format,
@ -65,15 +64,14 @@ public:
data.writeInt32(format); data.writeInt32(format);
data.writeInt32(flags); data.writeInt32(flags);
remote()->transact(CREATE_SURFACE, data, &reply); remote()->transact(CREATE_SURFACE, data, &reply);
params->readFromParcel(reply);
return interface_cast<ISurface>(reply.readStrongBinder()); return interface_cast<ISurface>(reply.readStrongBinder());
} }
virtual status_t destroySurface(SurfaceID sid) virtual status_t destroySurface(const sp<IBinder>& handle)
{ {
Parcel data, reply; Parcel data, reply;
data.writeInterfaceToken(ISurfaceComposerClient::getInterfaceDescriptor()); data.writeInterfaceToken(ISurfaceComposerClient::getInterfaceDescriptor());
data.writeInt32(sid); data.writeStrongBinder(handle);
remote()->transact(DESTROY_SURFACE, data, &reply); remote()->transact(DESTROY_SURFACE, data, &reply);
return reply.readInt32(); return reply.readInt32();
} }
@ -89,21 +87,18 @@ status_t BnSurfaceComposerClient::onTransact(
switch(code) { switch(code) {
case CREATE_SURFACE: { case CREATE_SURFACE: {
CHECK_INTERFACE(ISurfaceComposerClient, data, reply); CHECK_INTERFACE(ISurfaceComposerClient, data, reply);
surface_data_t params;
String8 name = data.readString8(); String8 name = data.readString8();
uint32_t w = data.readInt32(); uint32_t w = data.readInt32();
uint32_t h = data.readInt32(); uint32_t h = data.readInt32();
PixelFormat format = data.readInt32(); PixelFormat format = data.readInt32();
uint32_t flags = data.readInt32(); uint32_t flags = data.readInt32();
sp<ISurface> s = createSurface(&params, name, w, h, sp<ISurface> s = createSurface(name, w, h, format, flags);
format, flags);
params.writeToParcel(reply);
reply->writeStrongBinder(s->asBinder()); reply->writeStrongBinder(s->asBinder());
return NO_ERROR; return NO_ERROR;
} break; } break;
case DESTROY_SURFACE: { case DESTROY_SURFACE: {
CHECK_INTERFACE(ISurfaceComposerClient, data, reply); CHECK_INTERFACE(ISurfaceComposerClient, data, reply);
reply->writeInt32( destroySurface( data.readInt32() ) ); reply->writeInt32( destroySurface( data.readStrongBinder() ) );
return NO_ERROR; return NO_ERROR;
} break; } break;
default: default:
@ -111,20 +106,4 @@ status_t BnSurfaceComposerClient::onTransact(
} }
} }
// ----------------------------------------------------------------------
status_t ISurfaceComposerClient::surface_data_t::readFromParcel(const Parcel& parcel)
{
token = parcel.readInt32();
identity = parcel.readInt32();
return NO_ERROR;
}
status_t ISurfaceComposerClient::surface_data_t::writeToParcel(Parcel* parcel) const
{
parcel->writeInt32(token);
parcel->writeInt32(identity);
return NO_ERROR;
}
}; // namespace android }; // namespace android

View File

@ -24,29 +24,41 @@ namespace android {
status_t layer_state_t::write(Parcel& output) const status_t layer_state_t::write(Parcel& output) const
{ {
status_t err; output.writeStrongBinder(surface);
output.writeInt32(what);
err = output.write(transparentRegion); output.writeFloat(x);
if (err < NO_ERROR) return err; output.writeFloat(y);
output.writeInt32(z);
// NOTE: regions are at the end of the structure output.writeInt32(w);
size_t size = sizeof(layer_state_t); output.writeInt32(h);
size -= sizeof(transparentRegion); output.writeInt32(layerStack);
err = output.write(this, size); output.writeFloat(alpha);
return err; output.writeInt32(flags);
output.writeInt32(mask);
*reinterpret_cast<layer_state_t::matrix22_t *>(
output.writeInplace(sizeof(layer_state_t::matrix22_t))) = matrix;
output.write(crop);
output.write(transparentRegion);
return NO_ERROR;
} }
status_t layer_state_t::read(const Parcel& input) status_t layer_state_t::read(const Parcel& input)
{ {
status_t err; surface = input.readStrongBinder();
what = input.readInt32();
err = input.read(transparentRegion); x = input.readFloat();
if (err < NO_ERROR) return err; y = input.readFloat();
z = input.readInt32();
// NOTE: regions are at the end of the structure w = input.readInt32();
size_t size = sizeof(layer_state_t); h = input.readInt32();
size -= sizeof(transparentRegion); layerStack = input.readInt32();
input.read(this, size); alpha = input.readFloat();
flags = input.readInt32();
mask = input.readInt32();
matrix = *reinterpret_cast<layer_state_t::matrix22_t const *>(
input.readInplace(sizeof(layer_state_t::matrix22_t)));
input.read(crop);
input.read(transparentRegion);
return NO_ERROR; return NO_ERROR;
} }

View File

@ -48,11 +48,12 @@ namespace android {
SurfaceControl::SurfaceControl( SurfaceControl::SurfaceControl(
const sp<SurfaceComposerClient>& client, const sp<SurfaceComposerClient>& client,
const sp<ISurface>& surface, const sp<ISurface>& surface)
const ISurfaceComposerClient::surface_data_t& data) : mClient(client)
: mClient(client), mSurface(surface),
mToken(data.token), mIdentity(data.identity)
{ {
if (surface != 0) {
mSurface = surface->asBinder();
}
} }
SurfaceControl::~SurfaceControl() SurfaceControl::~SurfaceControl()
@ -63,9 +64,8 @@ SurfaceControl::~SurfaceControl()
void SurfaceControl::destroy() void SurfaceControl::destroy()
{ {
if (isValid()) { if (isValid()) {
mClient->destroySurface(mToken); mClient->destroySurface(mSurface);
} }
// clear all references and trigger an IPC now, to make sure things // clear all references and trigger an IPC now, to make sure things
// happen without delay, since these resources are quite heavy. // happen without delay, since these resources are quite heavy.
mClient.clear(); mClient.clear();
@ -89,81 +89,81 @@ bool SurfaceControl::isSameSurface(
{ {
if (lhs == 0 || rhs == 0) if (lhs == 0 || rhs == 0)
return false; return false;
return lhs->mSurface->asBinder() == rhs->mSurface->asBinder(); return lhs->mSurface == rhs->mSurface;
} }
status_t SurfaceControl::setLayerStack(int32_t layerStack) { status_t SurfaceControl::setLayerStack(int32_t layerStack) {
status_t err = validate(); status_t err = validate();
if (err < 0) return err; if (err < 0) return err;
const sp<SurfaceComposerClient>& client(mClient); const sp<SurfaceComposerClient>& client(mClient);
return client->setLayerStack(mToken, layerStack); return client->setLayerStack(mSurface, layerStack);
} }
status_t SurfaceControl::setLayer(int32_t layer) { status_t SurfaceControl::setLayer(int32_t layer) {
status_t err = validate(); status_t err = validate();
if (err < 0) return err; if (err < 0) return err;
const sp<SurfaceComposerClient>& client(mClient); const sp<SurfaceComposerClient>& client(mClient);
return client->setLayer(mToken, layer); return client->setLayer(mSurface, layer);
} }
status_t SurfaceControl::setPosition(int32_t x, int32_t y) { status_t SurfaceControl::setPosition(int32_t x, int32_t y) {
status_t err = validate(); status_t err = validate();
if (err < 0) return err; if (err < 0) return err;
const sp<SurfaceComposerClient>& client(mClient); const sp<SurfaceComposerClient>& client(mClient);
return client->setPosition(mToken, x, y); return client->setPosition(mSurface, x, y);
} }
status_t SurfaceControl::setSize(uint32_t w, uint32_t h) { status_t SurfaceControl::setSize(uint32_t w, uint32_t h) {
status_t err = validate(); status_t err = validate();
if (err < 0) return err; if (err < 0) return err;
const sp<SurfaceComposerClient>& client(mClient); const sp<SurfaceComposerClient>& client(mClient);
return client->setSize(mToken, w, h); return client->setSize(mSurface, w, h);
} }
status_t SurfaceControl::hide() { status_t SurfaceControl::hide() {
status_t err = validate(); status_t err = validate();
if (err < 0) return err; if (err < 0) return err;
const sp<SurfaceComposerClient>& client(mClient); const sp<SurfaceComposerClient>& client(mClient);
return client->hide(mToken); return client->hide(mSurface);
} }
status_t SurfaceControl::show() { status_t SurfaceControl::show() {
status_t err = validate(); status_t err = validate();
if (err < 0) return err; if (err < 0) return err;
const sp<SurfaceComposerClient>& client(mClient); const sp<SurfaceComposerClient>& client(mClient);
return client->show(mToken); return client->show(mSurface);
} }
status_t SurfaceControl::setFlags(uint32_t flags, uint32_t mask) { status_t SurfaceControl::setFlags(uint32_t flags, uint32_t mask) {
status_t err = validate(); status_t err = validate();
if (err < 0) return err; if (err < 0) return err;
const sp<SurfaceComposerClient>& client(mClient); const sp<SurfaceComposerClient>& client(mClient);
return client->setFlags(mToken, flags, mask); return client->setFlags(mSurface, flags, mask);
} }
status_t SurfaceControl::setTransparentRegionHint(const Region& transparent) { status_t SurfaceControl::setTransparentRegionHint(const Region& transparent) {
status_t err = validate(); status_t err = validate();
if (err < 0) return err; if (err < 0) return err;
const sp<SurfaceComposerClient>& client(mClient); const sp<SurfaceComposerClient>& client(mClient);
return client->setTransparentRegionHint(mToken, transparent); return client->setTransparentRegionHint(mSurface, transparent);
} }
status_t SurfaceControl::setAlpha(float alpha) { status_t SurfaceControl::setAlpha(float alpha) {
status_t err = validate(); status_t err = validate();
if (err < 0) return err; if (err < 0) return err;
const sp<SurfaceComposerClient>& client(mClient); const sp<SurfaceComposerClient>& client(mClient);
return client->setAlpha(mToken, alpha); return client->setAlpha(mSurface, alpha);
} }
status_t SurfaceControl::setMatrix(float dsdx, float dtdx, float dsdy, float dtdy) { status_t SurfaceControl::setMatrix(float dsdx, float dtdx, float dsdy, float dtdy) {
status_t err = validate(); status_t err = validate();
if (err < 0) return err; if (err < 0) return err;
const sp<SurfaceComposerClient>& client(mClient); const sp<SurfaceComposerClient>& client(mClient);
return client->setMatrix(mToken, dsdx, dtdx, dsdy, dtdy); return client->setMatrix(mSurface, dsdx, dtdx, dsdy, dtdy);
} }
status_t SurfaceControl::setCrop(const Rect& crop) { status_t SurfaceControl::setCrop(const Rect& crop) {
status_t err = validate(); status_t err = validate();
if (err < 0) return err; if (err < 0) return err;
const sp<SurfaceComposerClient>& client(mClient); const sp<SurfaceComposerClient>& client(mClient);
return client->setCrop(mToken, crop); return client->setCrop(mSurface, crop);
} }
status_t SurfaceControl::validate() const status_t SurfaceControl::validate() const
{ {
if (mToken<0 || mClient==0) { if (mSurface==0 || mClient==0) {
ALOGE("invalid token (%d, identity=%u) or client (%p)", ALOGE("invalid ISurface (%p) or client (%p)",
mToken, mIdentity, mClient.get()); mSurface.get(), mClient.get());
return NO_INIT; return NO_INIT;
} }
return NO_ERROR; return NO_ERROR;
@ -172,15 +172,12 @@ status_t SurfaceControl::validate() const
status_t SurfaceControl::writeSurfaceToParcel( status_t SurfaceControl::writeSurfaceToParcel(
const sp<SurfaceControl>& control, Parcel* parcel) const sp<SurfaceControl>& control, Parcel* parcel)
{ {
sp<ISurface> sur; sp<IBinder> sur;
uint32_t identity = 0;
if (SurfaceControl::isValid(control)) { if (SurfaceControl::isValid(control)) {
sur = control->mSurface; sur = control->mSurface;
identity = control->mIdentity;
} }
parcel->writeStrongBinder(sur!=0 ? sur->asBinder() : NULL); parcel->writeStrongBinder(sur);
parcel->writeStrongBinder(NULL); // NULL IGraphicBufferProducer in this case. parcel->writeStrongBinder(NULL); // NULL IGraphicBufferProducer in this case.
parcel->writeInt32(identity);
return NO_ERROR; return NO_ERROR;
} }
@ -198,13 +195,10 @@ sp<Surface> SurfaceControl::getSurface() const
// Surface // Surface
// ============================================================================ // ============================================================================
// ---------------------------------------------------------------------------
Surface::Surface(const sp<SurfaceControl>& surface) Surface::Surface(const sp<SurfaceControl>& surface)
: SurfaceTextureClient(), : SurfaceTextureClient()
mSurface(surface->mSurface),
mIdentity(surface->mIdentity)
{ {
mSurface = interface_cast<ISurface>(surface->mSurface);
sp<IGraphicBufferProducer> st; sp<IGraphicBufferProducer> st;
if (mSurface != NULL) { if (mSurface != NULL) {
st = mSurface->getSurfaceTexture(); st = mSurface->getSurfaceTexture();
@ -223,15 +217,12 @@ Surface::Surface(const Parcel& parcel, const sp<IBinder>& ref)
} else if (mSurface != NULL) { } else if (mSurface != NULL) {
st = mSurface->getSurfaceTexture(); st = mSurface->getSurfaceTexture();
} }
mIdentity = parcel.readInt32();
init(st); init(st);
} }
Surface::Surface(const sp<IGraphicBufferProducer>& st) Surface::Surface(const sp<IGraphicBufferProducer>& st)
: SurfaceTextureClient(), : SurfaceTextureClient(),
mSurface(NULL), mSurface(NULL)
mIdentity(0)
{ {
init(st); init(st);
} }
@ -245,19 +236,16 @@ status_t Surface::writeToParcel(
if (Surface::isValid(surface)) { if (Surface::isValid(surface)) {
sur = surface->mSurface; sur = surface->mSurface;
st = surface->getISurfaceTexture(); st = surface->getISurfaceTexture();
identity = surface->mIdentity;
} else if (surface != 0 && } else if (surface != 0 &&
(surface->mSurface != NULL || (surface->mSurface != NULL ||
surface->getISurfaceTexture() != NULL)) { surface->getISurfaceTexture() != NULL)) {
ALOGE("Parceling invalid surface with non-NULL ISurface/IGraphicBufferProducer " ALOGE("Parceling invalid surface with non-NULL ISurface/IGraphicBufferProducer "
"as NULL: mSurface = %p, bufferProducer = %p, mIdentity = %d, ", "as NULL: mSurface = %p, bufferProducer = %p ",
surface->mSurface.get(), surface->getISurfaceTexture().get(), surface->mSurface.get(), surface->getISurfaceTexture().get());
surface->mIdentity);
} }
parcel->writeStrongBinder(sur != NULL ? sur->asBinder() : NULL); parcel->writeStrongBinder(sur != NULL ? sur->asBinder() : NULL);
parcel->writeStrongBinder(st != NULL ? st->asBinder() : NULL); parcel->writeStrongBinder(st != NULL ? st->asBinder() : NULL);
parcel->writeInt32(identity);
return NO_ERROR; return NO_ERROR;
} }

View File

@ -128,7 +128,7 @@ class Composer : public Singleton<Composer>
void setAnimationTransactionImpl(); void setAnimationTransactionImpl();
layer_state_t* getLayerStateLocked( layer_state_t* getLayerStateLocked(
const sp<SurfaceComposerClient>& client, SurfaceID id); const sp<SurfaceComposerClient>& client, const sp<IBinder>& id);
DisplayState& getDisplayStateLocked(const sp<IBinder>& token); DisplayState& getDisplayStateLocked(const sp<IBinder>& token);
@ -136,26 +136,26 @@ public:
sp<IBinder> createDisplay(const String8& displayName, bool secure); sp<IBinder> createDisplay(const String8& displayName, bool secure);
sp<IBinder> getBuiltInDisplay(int32_t id); sp<IBinder> getBuiltInDisplay(int32_t id);
status_t setPosition(const sp<SurfaceComposerClient>& client, SurfaceID id, status_t setPosition(const sp<SurfaceComposerClient>& client, const sp<IBinder>& id,
float x, float y); float x, float y);
status_t setSize(const sp<SurfaceComposerClient>& client, SurfaceID id, status_t setSize(const sp<SurfaceComposerClient>& client, const sp<IBinder>& id,
uint32_t w, uint32_t h); uint32_t w, uint32_t h);
status_t setLayer(const sp<SurfaceComposerClient>& client, SurfaceID id, status_t setLayer(const sp<SurfaceComposerClient>& client, const sp<IBinder>& id,
int32_t z); int32_t z);
status_t setFlags(const sp<SurfaceComposerClient>& client, SurfaceID id, status_t setFlags(const sp<SurfaceComposerClient>& client, const sp<IBinder>& id,
uint32_t flags, uint32_t mask); uint32_t flags, uint32_t mask);
status_t setTransparentRegionHint( status_t setTransparentRegionHint(
const sp<SurfaceComposerClient>& client, SurfaceID id, const sp<SurfaceComposerClient>& client, const sp<IBinder>& id,
const Region& transparentRegion); const Region& transparentRegion);
status_t setAlpha(const sp<SurfaceComposerClient>& client, SurfaceID id, status_t setAlpha(const sp<SurfaceComposerClient>& client, const sp<IBinder>& id,
float alpha); float alpha);
status_t setMatrix(const sp<SurfaceComposerClient>& client, SurfaceID id, status_t setMatrix(const sp<SurfaceComposerClient>& client, const sp<IBinder>& id,
float dsdx, float dtdx, float dsdy, float dtdy); float dsdx, float dtdx, float dsdy, float dtdy);
status_t setOrientation(int orientation); status_t setOrientation(int orientation);
status_t setCrop(const sp<SurfaceComposerClient>& client, SurfaceID id, status_t setCrop(const sp<SurfaceComposerClient>& client, const sp<IBinder>& id,
const Rect& crop); const Rect& crop);
status_t setLayerStack(const sp<SurfaceComposerClient>& client, status_t setLayerStack(const sp<SurfaceComposerClient>& client,
SurfaceID id, uint32_t layerStack); const sp<IBinder>& id, uint32_t layerStack);
void setDisplaySurface(const sp<IBinder>& token, void setDisplaySurface(const sp<IBinder>& token,
const sp<IGraphicBufferProducer>& bufferProducer); const sp<IGraphicBufferProducer>& bufferProducer);
@ -241,7 +241,7 @@ void Composer::setAnimationTransactionImpl() {
} }
layer_state_t* Composer::getLayerStateLocked( layer_state_t* Composer::getLayerStateLocked(
const sp<SurfaceComposerClient>& client, SurfaceID id) { const sp<SurfaceComposerClient>& client, const sp<IBinder>& id) {
ComposerState s; ComposerState s;
s.client = client->mClient; s.client = client->mClient;
@ -258,7 +258,7 @@ layer_state_t* Composer::getLayerStateLocked(
} }
status_t Composer::setPosition(const sp<SurfaceComposerClient>& client, status_t Composer::setPosition(const sp<SurfaceComposerClient>& client,
SurfaceID id, float x, float y) { const sp<IBinder>& id, float x, float y) {
Mutex::Autolock _l(mLock); Mutex::Autolock _l(mLock);
layer_state_t* s = getLayerStateLocked(client, id); layer_state_t* s = getLayerStateLocked(client, id);
if (!s) if (!s)
@ -270,7 +270,7 @@ status_t Composer::setPosition(const sp<SurfaceComposerClient>& client,
} }
status_t Composer::setSize(const sp<SurfaceComposerClient>& client, status_t Composer::setSize(const sp<SurfaceComposerClient>& client,
SurfaceID id, uint32_t w, uint32_t h) { const sp<IBinder>& id, uint32_t w, uint32_t h) {
Mutex::Autolock _l(mLock); Mutex::Autolock _l(mLock);
layer_state_t* s = getLayerStateLocked(client, id); layer_state_t* s = getLayerStateLocked(client, id);
if (!s) if (!s)
@ -286,7 +286,7 @@ status_t Composer::setSize(const sp<SurfaceComposerClient>& client,
} }
status_t Composer::setLayer(const sp<SurfaceComposerClient>& client, status_t Composer::setLayer(const sp<SurfaceComposerClient>& client,
SurfaceID id, int32_t z) { const sp<IBinder>& id, int32_t z) {
Mutex::Autolock _l(mLock); Mutex::Autolock _l(mLock);
layer_state_t* s = getLayerStateLocked(client, id); layer_state_t* s = getLayerStateLocked(client, id);
if (!s) if (!s)
@ -297,7 +297,7 @@ status_t Composer::setLayer(const sp<SurfaceComposerClient>& client,
} }
status_t Composer::setFlags(const sp<SurfaceComposerClient>& client, status_t Composer::setFlags(const sp<SurfaceComposerClient>& client,
SurfaceID id, uint32_t flags, const sp<IBinder>& id, uint32_t flags,
uint32_t mask) { uint32_t mask) {
Mutex::Autolock _l(mLock); Mutex::Autolock _l(mLock);
layer_state_t* s = getLayerStateLocked(client, id); layer_state_t* s = getLayerStateLocked(client, id);
@ -311,7 +311,7 @@ status_t Composer::setFlags(const sp<SurfaceComposerClient>& client,
} }
status_t Composer::setTransparentRegionHint( status_t Composer::setTransparentRegionHint(
const sp<SurfaceComposerClient>& client, SurfaceID id, const sp<SurfaceComposerClient>& client, const sp<IBinder>& id,
const Region& transparentRegion) { const Region& transparentRegion) {
Mutex::Autolock _l(mLock); Mutex::Autolock _l(mLock);
layer_state_t* s = getLayerStateLocked(client, id); layer_state_t* s = getLayerStateLocked(client, id);
@ -323,7 +323,7 @@ status_t Composer::setTransparentRegionHint(
} }
status_t Composer::setAlpha(const sp<SurfaceComposerClient>& client, status_t Composer::setAlpha(const sp<SurfaceComposerClient>& client,
SurfaceID id, float alpha) { const sp<IBinder>& id, float alpha) {
Mutex::Autolock _l(mLock); Mutex::Autolock _l(mLock);
layer_state_t* s = getLayerStateLocked(client, id); layer_state_t* s = getLayerStateLocked(client, id);
if (!s) if (!s)
@ -334,7 +334,7 @@ status_t Composer::setAlpha(const sp<SurfaceComposerClient>& client,
} }
status_t Composer::setLayerStack(const sp<SurfaceComposerClient>& client, status_t Composer::setLayerStack(const sp<SurfaceComposerClient>& client,
SurfaceID id, uint32_t layerStack) { const sp<IBinder>& id, uint32_t layerStack) {
Mutex::Autolock _l(mLock); Mutex::Autolock _l(mLock);
layer_state_t* s = getLayerStateLocked(client, id); layer_state_t* s = getLayerStateLocked(client, id);
if (!s) if (!s)
@ -345,7 +345,7 @@ status_t Composer::setLayerStack(const sp<SurfaceComposerClient>& client,
} }
status_t Composer::setMatrix(const sp<SurfaceComposerClient>& client, status_t Composer::setMatrix(const sp<SurfaceComposerClient>& client,
SurfaceID id, float dsdx, float dtdx, const sp<IBinder>& id, float dsdx, float dtdx,
float dsdy, float dtdy) { float dsdy, float dtdy) {
Mutex::Autolock _l(mLock); Mutex::Autolock _l(mLock);
layer_state_t* s = getLayerStateLocked(client, id); layer_state_t* s = getLayerStateLocked(client, id);
@ -362,7 +362,7 @@ status_t Composer::setMatrix(const sp<SurfaceComposerClient>& client,
} }
status_t Composer::setCrop(const sp<SurfaceComposerClient>& client, status_t Composer::setCrop(const sp<SurfaceComposerClient>& client,
SurfaceID id, const Rect& crop) { const sp<IBinder>& id, const Rect& crop) {
Mutex::Autolock _l(mLock); Mutex::Autolock _l(mLock);
layer_state_t* s = getLayerStateLocked(client, id); layer_state_t* s = getLayerStateLocked(client, id);
if (!s) if (!s)
@ -472,11 +472,9 @@ sp<SurfaceControl> SurfaceComposerClient::createSurface(
{ {
sp<SurfaceControl> result; sp<SurfaceControl> result;
if (mStatus == NO_ERROR) { if (mStatus == NO_ERROR) {
ISurfaceComposerClient::surface_data_t data; sp<ISurface> surface = mClient->createSurface(name, w, h, format, flags);
sp<ISurface> surface = mClient->createSurface(&data, name,
w, h, format, flags);
if (surface != 0) { if (surface != 0) {
result = new SurfaceControl(this, surface, data); result = new SurfaceControl(this, surface);
} }
} }
return result; return result;
@ -491,7 +489,7 @@ sp<IBinder> SurfaceComposerClient::getBuiltInDisplay(int32_t id) {
return Composer::getInstance().getBuiltInDisplay(id); return Composer::getInstance().getBuiltInDisplay(id);
} }
status_t SurfaceComposerClient::destroySurface(SurfaceID sid) { status_t SurfaceComposerClient::destroySurface(const sp<IBinder>& sid) {
if (mStatus != NO_ERROR) if (mStatus != NO_ERROR)
return mStatus; return mStatus;
status_t err = mClient->destroySurface(sid); status_t err = mClient->destroySurface(sid);
@ -518,53 +516,53 @@ void SurfaceComposerClient::setAnimationTransaction() {
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
status_t SurfaceComposerClient::setCrop(SurfaceID id, const Rect& crop) { status_t SurfaceComposerClient::setCrop(const sp<IBinder>& id, const Rect& crop) {
return getComposer().setCrop(this, id, crop); return getComposer().setCrop(this, id, crop);
} }
status_t SurfaceComposerClient::setPosition(SurfaceID id, float x, float y) { status_t SurfaceComposerClient::setPosition(const sp<IBinder>& id, float x, float y) {
return getComposer().setPosition(this, id, x, y); return getComposer().setPosition(this, id, x, y);
} }
status_t SurfaceComposerClient::setSize(SurfaceID id, uint32_t w, uint32_t h) { status_t SurfaceComposerClient::setSize(const sp<IBinder>& id, uint32_t w, uint32_t h) {
return getComposer().setSize(this, id, w, h); return getComposer().setSize(this, id, w, h);
} }
status_t SurfaceComposerClient::setLayer(SurfaceID id, int32_t z) { status_t SurfaceComposerClient::setLayer(const sp<IBinder>& id, int32_t z) {
return getComposer().setLayer(this, id, z); return getComposer().setLayer(this, id, z);
} }
status_t SurfaceComposerClient::hide(SurfaceID id) { status_t SurfaceComposerClient::hide(const sp<IBinder>& id) {
return getComposer().setFlags(this, id, return getComposer().setFlags(this, id,
layer_state_t::eLayerHidden, layer_state_t::eLayerHidden,
layer_state_t::eLayerHidden); layer_state_t::eLayerHidden);
} }
status_t SurfaceComposerClient::show(SurfaceID id) { status_t SurfaceComposerClient::show(const sp<IBinder>& id) {
return getComposer().setFlags(this, id, return getComposer().setFlags(this, id,
0, 0,
layer_state_t::eLayerHidden); layer_state_t::eLayerHidden);
} }
status_t SurfaceComposerClient::setFlags(SurfaceID id, uint32_t flags, status_t SurfaceComposerClient::setFlags(const sp<IBinder>& id, uint32_t flags,
uint32_t mask) { uint32_t mask) {
return getComposer().setFlags(this, id, flags, mask); return getComposer().setFlags(this, id, flags, mask);
} }
status_t SurfaceComposerClient::setTransparentRegionHint(SurfaceID id, status_t SurfaceComposerClient::setTransparentRegionHint(const sp<IBinder>& id,
const Region& transparentRegion) { const Region& transparentRegion) {
return getComposer().setTransparentRegionHint(this, id, transparentRegion); return getComposer().setTransparentRegionHint(this, id, transparentRegion);
} }
status_t SurfaceComposerClient::setAlpha(SurfaceID id, float alpha) { status_t SurfaceComposerClient::setAlpha(const sp<IBinder>& id, float alpha) {
return getComposer().setAlpha(this, id, alpha); return getComposer().setAlpha(this, id, alpha);
} }
status_t SurfaceComposerClient::setLayerStack(SurfaceID id, uint32_t layerStack) { status_t SurfaceComposerClient::setLayerStack(const sp<IBinder>& id, uint32_t layerStack) {
return getComposer().setLayerStack(this, id, layerStack); return getComposer().setLayerStack(this, id, layerStack);
} }
status_t SurfaceComposerClient::setMatrix(SurfaceID id, float dsdx, float dtdx, status_t SurfaceComposerClient::setMatrix(const sp<IBinder>& id, float dsdx, float dtdx,
float dsdy, float dtdy) { float dsdy, float dtdy) {
return getComposer().setMatrix(this, id, dsdx, dtdx, dsdy, dtdy); return getComposer().setMatrix(this, id, dsdx, dtdx, dsdy, dtdy);
} }

View File

@ -35,7 +35,7 @@ const String16 sAccessSurfaceFlinger("android.permission.ACCESS_SURFACE_FLINGER"
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
Client::Client(const sp<SurfaceFlinger>& flinger) Client::Client(const sp<SurfaceFlinger>& flinger)
: mFlinger(flinger), mNameGenerator(1) : mFlinger(flinger)
{ {
} }
@ -54,12 +54,10 @@ status_t Client::initCheck() const {
return NO_ERROR; return NO_ERROR;
} }
size_t Client::attachLayer(const sp<LayerBaseClient>& layer) void Client::attachLayer(const sp<IBinder>& handle, const sp<LayerBaseClient>& layer)
{ {
Mutex::Autolock _l(mLock); Mutex::Autolock _l(mLock);
size_t name = mNameGenerator++; mLayers.add(handle, layer);
mLayers.add(name, layer);
return name;
} }
void Client::detachLayer(const LayerBaseClient* layer) void Client::detachLayer(const LayerBaseClient* layer)
@ -74,14 +72,14 @@ void Client::detachLayer(const LayerBaseClient* layer)
} }
} }
} }
sp<LayerBaseClient> Client::getLayerUser(int32_t i) const sp<LayerBaseClient> Client::getLayerUser(const sp<IBinder>& handle) const
{ {
Mutex::Autolock _l(mLock); Mutex::Autolock _l(mLock);
sp<LayerBaseClient> lbc; sp<LayerBaseClient> lbc;
wp<LayerBaseClient> layer(mLayers.valueFor(i)); wp<LayerBaseClient> layer(mLayers.valueFor(handle));
if (layer != 0) { if (layer != 0) {
lbc = layer.promote(); lbc = layer.promote();
ALOGE_IF(lbc==0, "getLayerUser(name=%d) is dead", int(i)); ALOGE_IF(lbc==0, "getLayerUser(name=%p) is dead", handle.get());
} }
return lbc; return lbc;
} }
@ -109,7 +107,6 @@ status_t Client::onTransact(
sp<ISurface> Client::createSurface( sp<ISurface> Client::createSurface(
ISurfaceComposerClient::surface_data_t* params,
const String8& name, const String8& name,
uint32_t w, uint32_t h, PixelFormat format, uint32_t w, uint32_t h, PixelFormat format,
uint32_t flags) uint32_t flags)
@ -122,7 +119,6 @@ sp<ISurface> Client::createSurface(
class MessageCreateLayer : public MessageBase { class MessageCreateLayer : public MessageBase {
sp<ISurface> result; sp<ISurface> result;
SurfaceFlinger* flinger; SurfaceFlinger* flinger;
ISurfaceComposerClient::surface_data_t* params;
Client* client; Client* client;
const String8& name; const String8& name;
uint32_t w, h; uint32_t w, h;
@ -130,29 +126,28 @@ sp<ISurface> Client::createSurface(
uint32_t flags; uint32_t flags;
public: public:
MessageCreateLayer(SurfaceFlinger* flinger, MessageCreateLayer(SurfaceFlinger* flinger,
ISurfaceComposerClient::surface_data_t* params,
const String8& name, Client* client, const String8& name, Client* client,
uint32_t w, uint32_t h, PixelFormat format, uint32_t w, uint32_t h, PixelFormat format,
uint32_t flags) uint32_t flags)
: flinger(flinger), params(params), client(client), name(name), : flinger(flinger), client(client), name(name),
w(w), h(h), format(format), flags(flags) w(w), h(h), format(format), flags(flags)
{ {
} }
sp<ISurface> getResult() const { return result; } sp<ISurface> getResult() const { return result; }
virtual bool handler() { virtual bool handler() {
result = flinger->createLayer(params, name, client, result = flinger->createLayer(name, client, w, h, format, flags);
w, h, format, flags);
return true; return true;
} }
}; };
sp<MessageBase> msg = new MessageCreateLayer(mFlinger.get(), sp<MessageBase> msg = new MessageCreateLayer(mFlinger.get(),
params, name, this, w, h, format, flags); name, this, w, h, format, flags);
mFlinger->postMessageSync(msg); mFlinger->postMessageSync(msg);
return static_cast<MessageCreateLayer*>( msg.get() )->getResult(); return static_cast<MessageCreateLayer*>( msg.get() )->getResult();
} }
status_t Client::destroySurface(SurfaceID sid) {
return mFlinger->onLayerRemoved(this, sid); status_t Client::destroySurface(const sp<IBinder>& handle) {
return mFlinger->onLayerRemoved(this, handle);
} }
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------

View File

@ -44,20 +44,20 @@ public:
status_t initCheck() const; status_t initCheck() const;
// protected by SurfaceFlinger::mStateLock // protected by SurfaceFlinger::mStateLock
size_t attachLayer(const sp<LayerBaseClient>& layer); void attachLayer(const sp<IBinder>& handle, const sp<LayerBaseClient>& layer);
void detachLayer(const LayerBaseClient* layer); void detachLayer(const LayerBaseClient* layer);
sp<LayerBaseClient> getLayerUser(int32_t i) const; sp<LayerBaseClient> getLayerUser(const sp<IBinder>& handle) const;
private: private:
// ISurfaceComposerClient interface // ISurfaceComposerClient interface
virtual sp<ISurface> createSurface( virtual sp<ISurface> createSurface(
surface_data_t* params, const String8& name, const String8& name,
uint32_t w, uint32_t h,PixelFormat format, uint32_t w, uint32_t h,PixelFormat format,
uint32_t flags); uint32_t flags);
virtual status_t destroySurface(SurfaceID surfaceId); virtual status_t destroySurface(const sp<IBinder>& handle);
virtual status_t onTransact( virtual status_t onTransact(
uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags); uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags);
@ -66,8 +66,7 @@ private:
sp<SurfaceFlinger> mFlinger; sp<SurfaceFlinger> mFlinger;
// protected by mLock // protected by mLock
DefaultKeyedVector< size_t, wp<LayerBaseClient> > mLayers; DefaultKeyedVector< wp<IBinder>, wp<LayerBaseClient> > mLayers;
size_t mNameGenerator;
// thread-safe // thread-safe
mutable Mutex mLock; mutable Mutex mLock;

View File

@ -483,14 +483,11 @@ sp<Layer> LayerBase::getLayer() const {
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
int32_t LayerBaseClient::sIdentity = 1;
LayerBaseClient::LayerBaseClient(SurfaceFlinger* flinger, LayerBaseClient::LayerBaseClient(SurfaceFlinger* flinger,
const sp<Client>& client) const sp<Client>& client)
: LayerBase(flinger), : LayerBase(flinger),
mHasSurface(false), mHasSurface(false),
mClientRef(client), mClientRef(client)
mIdentity(uint32_t(android_atomic_inc(&sIdentity)))
{ {
} }
@ -540,12 +537,8 @@ wp<IBinder> LayerBaseClient::getSurfaceTextureBinder() const {
void LayerBaseClient::dump(String8& result, char* buffer, size_t SIZE) const void LayerBaseClient::dump(String8& result, char* buffer, size_t SIZE) const
{ {
LayerBase::dump(result, buffer, SIZE); LayerBase::dump(result, buffer, SIZE);
sp<Client> client(mClientRef.promote()); sp<Client> client(mClientRef.promote());
snprintf(buffer, SIZE, snprintf(buffer, SIZE, " client=%p\n", client.get());
" client=%p, identity=%u\n",
client.get(), getIdentity());
result.append(buffer); result.append(buffer);
} }

View File

@ -347,8 +347,6 @@ public:
virtual const char* getTypeId() const { return "LayerBaseClient"; } virtual const char* getTypeId() const { return "LayerBaseClient"; }
uint32_t getIdentity() const { return mIdentity; }
protected: protected:
virtual void dump(String8& result, char* scratch, size_t size) const; virtual void dump(String8& result, char* scratch, size_t size) const;
virtual void shortDump(String8& result, char* scratch, size_t size) const; virtual void shortDump(String8& result, char* scratch, size_t size) const;
@ -379,9 +377,6 @@ private:
wp<IBinder> mClientSurfaceBinder; wp<IBinder> mClientSurfaceBinder;
const wp<Client> mClientRef; const wp<Client> mClientRef;
// only read
const uint32_t mIdentity;
static int32_t sIdentity;
}; };
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------

View File

@ -1682,17 +1682,16 @@ void SurfaceFlinger::drawWormhole(const sp<const DisplayDevice>& hw,
} }
} }
ssize_t SurfaceFlinger::addClientLayer(const sp<Client>& client, void SurfaceFlinger::addClientLayer(const sp<Client>& client,
const sp<IBinder>& handle,
const sp<LayerBaseClient>& lbc) const sp<LayerBaseClient>& lbc)
{ {
// attach this layer to the client // attach this layer to the client
size_t name = client->attachLayer(lbc); client->attachLayer(handle, lbc);
// add this layer to the current state list // add this layer to the current state list
Mutex::Autolock _l(mStateLock); Mutex::Autolock _l(mStateLock);
mCurrentState.layersSortedByZ.add(lbc); mCurrentState.layersSortedByZ.add(lbc);
return ssize_t(name);
} }
status_t SurfaceFlinger::removeLayer(const sp<LayerBase>& layer) status_t SurfaceFlinger::removeLayer(const sp<LayerBase>& layer)
@ -1933,10 +1932,9 @@ uint32_t SurfaceFlinger::setClientStateLocked(
} }
sp<ISurface> SurfaceFlinger::createLayer( sp<ISurface> SurfaceFlinger::createLayer(
ISurfaceComposerClient::surface_data_t* params,
const String8& name, const String8& name,
const sp<Client>& client, const sp<Client>& client,
uint32_t w, uint32_t h, PixelFormat format, uint32_t w, uint32_t h, PixelFormat format,
uint32_t flags) uint32_t flags)
{ {
sp<LayerBaseClient> layer; sp<LayerBaseClient> layer;
@ -1965,11 +1963,9 @@ sp<ISurface> SurfaceFlinger::createLayer(
if (layer != 0) { if (layer != 0) {
layer->initStates(w, h, flags); layer->initStates(w, h, flags);
layer->setName(name); layer->setName(name);
ssize_t token = addClientLayer(client, layer);
surfaceHandle = layer->getSurface(); surfaceHandle = layer->getSurface();
if (surfaceHandle != 0) { if (surfaceHandle != 0) {
params->token = token; addClientLayer(client, surfaceHandle->asBinder(), layer);
params->identity = layer->getIdentity();
} }
setTransactionFlags(eTransactionNeeded); setTransactionFlags(eTransactionNeeded);
} }
@ -2027,7 +2023,7 @@ sp<LayerScreenshot> SurfaceFlinger::createScreenshotLayer(
return layer; return layer;
} }
status_t SurfaceFlinger::onLayerRemoved(const sp<Client>& client, SurfaceID sid) status_t SurfaceFlinger::onLayerRemoved(const sp<Client>& client, const sp<IBinder>& handle)
{ {
/* /*
* called by the window manager, when a surface should be marked for * called by the window manager, when a surface should be marked for
@ -2040,7 +2036,7 @@ status_t SurfaceFlinger::onLayerRemoved(const sp<Client>& client, SurfaceID sid)
status_t err = NAME_NOT_FOUND; status_t err = NAME_NOT_FOUND;
Mutex::Autolock _l(mStateLock); Mutex::Autolock _l(mStateLock);
sp<LayerBaseClient> layer = client->getLayerUser(sid); sp<LayerBaseClient> layer = client->getLayerUser(handle);
if (layer != 0) { if (layer != 0) {
err = purgatorizeLayer_l(layer); err = purgatorizeLayer_l(layer);

View File

@ -267,8 +267,7 @@ private:
/* ------------------------------------------------------------------------ /* ------------------------------------------------------------------------
* Layer management * Layer management
*/ */
sp<ISurface> createLayer(ISurfaceComposerClient::surface_data_t* params, sp<ISurface> createLayer(const String8& name, const sp<Client>& client,
const String8& name, const sp<Client>& client,
uint32_t w, uint32_t h, PixelFormat format, uint32_t flags); uint32_t w, uint32_t h, PixelFormat format, uint32_t flags);
sp<Layer> createNormalLayer(const sp<Client>& client, sp<Layer> createNormalLayer(const sp<Client>& client,
@ -284,7 +283,7 @@ private:
// ISurfaceComposerClient::destroySurface() // ISurfaceComposerClient::destroySurface()
// The specified layer is first placed in a purgatory list // The specified layer is first placed in a purgatory list
// until all references from the client are released. // until all references from the client are released.
status_t onLayerRemoved(const sp<Client>& client, SurfaceID sid); status_t onLayerRemoved(const sp<Client>& client, const sp<IBinder>& handle);
// called when all clients have released all their references to // called when all clients have released all their references to
// this layer meaning it is entirely safe to destroy all // this layer meaning it is entirely safe to destroy all
@ -295,7 +294,7 @@ private:
status_t removeLayer(const sp<LayerBase>& layer); status_t removeLayer(const sp<LayerBase>& layer);
// add a layer to SurfaceFlinger // add a layer to SurfaceFlinger
ssize_t addClientLayer(const sp<Client>& client, void addClientLayer(const sp<Client>& client, const sp<IBinder>& handle,
const sp<LayerBaseClient>& lbc); const sp<LayerBaseClient>& lbc);
status_t removeLayer_l(const sp<LayerBase>& layer); status_t removeLayer_l(const sp<LayerBase>& layer);