2012-06-18 23:47:56 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2012 The Android Open Source Project
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
|
|
|
#include <binder/PermissionCache.h>
|
|
|
|
|
|
|
|
#include <private/android_filesystem_config.h>
|
|
|
|
|
|
|
|
#include "Client.h"
|
2012-07-24 06:11:29 +00:00
|
|
|
#include "Layer.h"
|
2012-06-18 23:47:56 +00:00
|
|
|
#include "SurfaceFlinger.h"
|
|
|
|
|
|
|
|
namespace android {
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
const String16 sAccessSurfaceFlinger("android.permission.ACCESS_SURFACE_FLINGER");
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
Client::Client(const sp<SurfaceFlinger>& flinger)
|
2013-02-12 00:40:36 +00:00
|
|
|
: mFlinger(flinger)
|
2012-06-18 23:47:56 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
Client::~Client()
|
|
|
|
{
|
|
|
|
const size_t count = mLayers.size();
|
|
|
|
for (size_t i=0 ; i<count ; i++) {
|
2013-03-06 01:47:11 +00:00
|
|
|
sp<Layer> layer(mLayers.valueAt(i).promote());
|
2012-06-18 23:47:56 +00:00
|
|
|
if (layer != 0) {
|
|
|
|
mFlinger->removeLayer(layer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
status_t Client::initCheck() const {
|
|
|
|
return NO_ERROR;
|
|
|
|
}
|
|
|
|
|
2013-03-06 01:47:11 +00:00
|
|
|
void Client::attachLayer(const sp<IBinder>& handle, const sp<Layer>& layer)
|
2012-06-18 23:47:56 +00:00
|
|
|
{
|
|
|
|
Mutex::Autolock _l(mLock);
|
2013-02-12 00:40:36 +00:00
|
|
|
mLayers.add(handle, layer);
|
2012-06-18 23:47:56 +00:00
|
|
|
}
|
|
|
|
|
2013-03-06 01:47:11 +00:00
|
|
|
void Client::detachLayer(const Layer* layer)
|
2012-06-18 23:47:56 +00:00
|
|
|
{
|
|
|
|
Mutex::Autolock _l(mLock);
|
|
|
|
// we do a linear search here, because this doesn't happen often
|
|
|
|
const size_t count = mLayers.size();
|
|
|
|
for (size_t i=0 ; i<count ; i++) {
|
|
|
|
if (mLayers.valueAt(i) == layer) {
|
|
|
|
mLayers.removeItemsAt(i, 1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-03-06 01:47:11 +00:00
|
|
|
sp<Layer> Client::getLayerUser(const sp<IBinder>& handle) const
|
2012-06-18 23:47:56 +00:00
|
|
|
{
|
|
|
|
Mutex::Autolock _l(mLock);
|
2013-03-06 01:47:11 +00:00
|
|
|
sp<Layer> lbc;
|
|
|
|
wp<Layer> layer(mLayers.valueFor(handle));
|
2012-06-18 23:47:56 +00:00
|
|
|
if (layer != 0) {
|
|
|
|
lbc = layer.promote();
|
2013-02-12 00:40:36 +00:00
|
|
|
ALOGE_IF(lbc==0, "getLayerUser(name=%p) is dead", handle.get());
|
2012-06-18 23:47:56 +00:00
|
|
|
}
|
|
|
|
return lbc;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
status_t Client::onTransact(
|
|
|
|
uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
|
|
|
|
{
|
|
|
|
// these must be checked
|
|
|
|
IPCThreadState* ipc = IPCThreadState::self();
|
|
|
|
const int pid = ipc->getCallingPid();
|
|
|
|
const int uid = ipc->getCallingUid();
|
|
|
|
const int self_pid = getpid();
|
|
|
|
if (CC_UNLIKELY(pid != self_pid && uid != AID_GRAPHICS && uid != 0)) {
|
|
|
|
// we're called from a different process, do the real check
|
|
|
|
if (!PermissionCache::checkCallingPermission(sAccessSurfaceFlinger))
|
|
|
|
{
|
|
|
|
ALOGE("Permission Denial: "
|
|
|
|
"can't openGlobalTransaction pid=%d, uid=%d", pid, uid);
|
|
|
|
return PERMISSION_DENIED;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return BnSurfaceComposerClient::onTransact(code, data, reply, flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
sp<ISurface> Client::createSurface(
|
|
|
|
const String8& name,
|
2012-08-25 03:00:51 +00:00
|
|
|
uint32_t w, uint32_t h, PixelFormat format,
|
2012-06-18 23:47:56 +00:00
|
|
|
uint32_t flags)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* createSurface must be called from the GL thread so that it can
|
|
|
|
* have access to the GL context.
|
|
|
|
*/
|
|
|
|
|
2012-07-24 06:11:29 +00:00
|
|
|
class MessageCreateLayer : public MessageBase {
|
2012-06-18 23:47:56 +00:00
|
|
|
sp<ISurface> result;
|
|
|
|
SurfaceFlinger* flinger;
|
|
|
|
Client* client;
|
|
|
|
const String8& name;
|
|
|
|
uint32_t w, h;
|
|
|
|
PixelFormat format;
|
|
|
|
uint32_t flags;
|
|
|
|
public:
|
2012-07-24 06:11:29 +00:00
|
|
|
MessageCreateLayer(SurfaceFlinger* flinger,
|
2012-06-18 23:47:56 +00:00
|
|
|
const String8& name, Client* client,
|
2012-08-25 03:00:51 +00:00
|
|
|
uint32_t w, uint32_t h, PixelFormat format,
|
2012-06-18 23:47:56 +00:00
|
|
|
uint32_t flags)
|
2013-02-12 00:40:36 +00:00
|
|
|
: flinger(flinger), client(client), name(name),
|
2012-08-25 03:00:51 +00:00
|
|
|
w(w), h(h), format(format), flags(flags)
|
2012-06-18 23:47:56 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
sp<ISurface> getResult() const { return result; }
|
|
|
|
virtual bool handler() {
|
2013-02-12 00:40:36 +00:00
|
|
|
result = flinger->createLayer(name, client, w, h, format, flags);
|
2012-06-18 23:47:56 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-07-24 06:11:29 +00:00
|
|
|
sp<MessageBase> msg = new MessageCreateLayer(mFlinger.get(),
|
2013-02-12 00:40:36 +00:00
|
|
|
name, this, w, h, format, flags);
|
2012-06-18 23:47:56 +00:00
|
|
|
mFlinger->postMessageSync(msg);
|
2012-07-24 06:11:29 +00:00
|
|
|
return static_cast<MessageCreateLayer*>( msg.get() )->getResult();
|
2012-06-18 23:47:56 +00:00
|
|
|
}
|
2013-02-12 00:40:36 +00:00
|
|
|
|
|
|
|
status_t Client::destroySurface(const sp<IBinder>& handle) {
|
|
|
|
return mFlinger->onLayerRemoved(this, handle);
|
2012-06-18 23:47:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
}; // namespace android
|