2013-02-15 01:11:02 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2007 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define LOG_TAG "SurfaceControl"
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
|
|
|
|
#include <android/native_window.h>
|
|
|
|
|
|
|
|
#include <utils/CallStack.h>
|
|
|
|
#include <utils/Errors.h>
|
|
|
|
#include <utils/Log.h>
|
|
|
|
#include <utils/threads.h>
|
|
|
|
|
|
|
|
#include <binder/IPCThreadState.h>
|
|
|
|
|
|
|
|
#include <ui/DisplayInfo.h>
|
|
|
|
#include <ui/GraphicBuffer.h>
|
|
|
|
#include <ui/Rect.h>
|
|
|
|
|
|
|
|
#include <gui/ISurfaceComposer.h>
|
|
|
|
#include <gui/Surface.h>
|
|
|
|
#include <gui/SurfaceComposerClient.h>
|
|
|
|
#include <gui/SurfaceControl.h>
|
|
|
|
|
|
|
|
namespace android {
|
|
|
|
|
|
|
|
// ============================================================================
|
|
|
|
// SurfaceControl
|
|
|
|
// ============================================================================
|
|
|
|
|
|
|
|
SurfaceControl::SurfaceControl(
|
|
|
|
const sp<SurfaceComposerClient>& client,
|
2013-03-13 00:11:48 +00:00
|
|
|
const sp<IBinder>& handle,
|
|
|
|
const sp<IGraphicBufferProducer>& gbp)
|
|
|
|
: mClient(client), mHandle(handle), mGraphicBufferProducer(gbp)
|
2013-02-15 01:11:02 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
SurfaceControl::~SurfaceControl()
|
|
|
|
{
|
|
|
|
destroy();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SurfaceControl::destroy()
|
|
|
|
{
|
|
|
|
if (isValid()) {
|
2013-03-13 00:11:48 +00:00
|
|
|
mClient->destroySurface(mHandle);
|
2013-02-15 01:11:02 +00:00
|
|
|
}
|
|
|
|
// clear all references and trigger an IPC now, to make sure things
|
|
|
|
// happen without delay, since these resources are quite heavy.
|
|
|
|
mClient.clear();
|
2013-03-13 00:11:48 +00:00
|
|
|
mHandle.clear();
|
2013-02-15 01:11:02 +00:00
|
|
|
mGraphicBufferProducer.clear();
|
|
|
|
IPCThreadState::self()->flushCommands();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SurfaceControl::clear()
|
|
|
|
{
|
|
|
|
// here, the window manager tells us explicitly that we should destroy
|
|
|
|
// the surface's resource. Soon after this call, it will also release
|
|
|
|
// its last reference (which will call the dtor); however, it is possible
|
|
|
|
// that a client living in the same process still holds references which
|
|
|
|
// would delay the call to the dtor -- that is why we need this explicit
|
|
|
|
// "clear()" call.
|
|
|
|
destroy();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SurfaceControl::isSameSurface(
|
|
|
|
const sp<SurfaceControl>& lhs, const sp<SurfaceControl>& rhs)
|
|
|
|
{
|
|
|
|
if (lhs == 0 || rhs == 0)
|
|
|
|
return false;
|
2013-03-13 00:11:48 +00:00
|
|
|
return lhs->mHandle == rhs->mHandle;
|
2013-02-15 01:11:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
status_t SurfaceControl::setLayerStack(int32_t layerStack) {
|
|
|
|
status_t err = validate();
|
|
|
|
if (err < 0) return err;
|
|
|
|
const sp<SurfaceComposerClient>& client(mClient);
|
2013-03-13 00:11:48 +00:00
|
|
|
return client->setLayerStack(mHandle, layerStack);
|
2013-02-15 01:11:02 +00:00
|
|
|
}
|
|
|
|
status_t SurfaceControl::setLayer(int32_t layer) {
|
|
|
|
status_t err = validate();
|
|
|
|
if (err < 0) return err;
|
|
|
|
const sp<SurfaceComposerClient>& client(mClient);
|
2013-03-13 00:11:48 +00:00
|
|
|
return client->setLayer(mHandle, layer);
|
2013-02-15 01:11:02 +00:00
|
|
|
}
|
2013-03-21 15:49:59 +00:00
|
|
|
status_t SurfaceControl::setPosition(float x, float y) {
|
2013-02-15 01:11:02 +00:00
|
|
|
status_t err = validate();
|
|
|
|
if (err < 0) return err;
|
|
|
|
const sp<SurfaceComposerClient>& client(mClient);
|
2013-03-13 00:11:48 +00:00
|
|
|
return client->setPosition(mHandle, x, y);
|
2013-02-15 01:11:02 +00:00
|
|
|
}
|
|
|
|
status_t SurfaceControl::setSize(uint32_t w, uint32_t h) {
|
|
|
|
status_t err = validate();
|
|
|
|
if (err < 0) return err;
|
|
|
|
const sp<SurfaceComposerClient>& client(mClient);
|
2013-03-13 00:11:48 +00:00
|
|
|
return client->setSize(mHandle, w, h);
|
2013-02-15 01:11:02 +00:00
|
|
|
}
|
|
|
|
status_t SurfaceControl::hide() {
|
|
|
|
status_t err = validate();
|
|
|
|
if (err < 0) return err;
|
|
|
|
const sp<SurfaceComposerClient>& client(mClient);
|
2013-03-13 00:11:48 +00:00
|
|
|
return client->hide(mHandle);
|
2013-02-15 01:11:02 +00:00
|
|
|
}
|
|
|
|
status_t SurfaceControl::show() {
|
|
|
|
status_t err = validate();
|
|
|
|
if (err < 0) return err;
|
|
|
|
const sp<SurfaceComposerClient>& client(mClient);
|
2013-03-13 00:11:48 +00:00
|
|
|
return client->show(mHandle);
|
2013-02-15 01:11:02 +00:00
|
|
|
}
|
|
|
|
status_t SurfaceControl::setFlags(uint32_t flags, uint32_t mask) {
|
|
|
|
status_t err = validate();
|
|
|
|
if (err < 0) return err;
|
|
|
|
const sp<SurfaceComposerClient>& client(mClient);
|
2013-03-13 00:11:48 +00:00
|
|
|
return client->setFlags(mHandle, flags, mask);
|
2013-02-15 01:11:02 +00:00
|
|
|
}
|
|
|
|
status_t SurfaceControl::setTransparentRegionHint(const Region& transparent) {
|
|
|
|
status_t err = validate();
|
|
|
|
if (err < 0) return err;
|
|
|
|
const sp<SurfaceComposerClient>& client(mClient);
|
2013-03-13 00:11:48 +00:00
|
|
|
return client->setTransparentRegionHint(mHandle, transparent);
|
2013-02-15 01:11:02 +00:00
|
|
|
}
|
|
|
|
status_t SurfaceControl::setAlpha(float alpha) {
|
|
|
|
status_t err = validate();
|
|
|
|
if (err < 0) return err;
|
|
|
|
const sp<SurfaceComposerClient>& client(mClient);
|
2013-03-13 00:11:48 +00:00
|
|
|
return client->setAlpha(mHandle, alpha);
|
2013-02-15 01:11:02 +00:00
|
|
|
}
|
|
|
|
status_t SurfaceControl::setMatrix(float dsdx, float dtdx, float dsdy, float dtdy) {
|
|
|
|
status_t err = validate();
|
|
|
|
if (err < 0) return err;
|
|
|
|
const sp<SurfaceComposerClient>& client(mClient);
|
2013-03-13 00:11:48 +00:00
|
|
|
return client->setMatrix(mHandle, dsdx, dtdx, dsdy, dtdy);
|
2013-02-15 01:11:02 +00:00
|
|
|
}
|
|
|
|
status_t SurfaceControl::setCrop(const Rect& crop) {
|
|
|
|
status_t err = validate();
|
|
|
|
if (err < 0) return err;
|
|
|
|
const sp<SurfaceComposerClient>& client(mClient);
|
2013-03-13 00:11:48 +00:00
|
|
|
return client->setCrop(mHandle, crop);
|
2013-02-15 01:11:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
status_t SurfaceControl::validate() const
|
|
|
|
{
|
2013-03-13 00:11:48 +00:00
|
|
|
if (mHandle==0 || mClient==0) {
|
|
|
|
ALOGE("invalid handle (%p) or client (%p)",
|
|
|
|
mHandle.get(), mClient.get());
|
2013-02-15 01:11:02 +00:00
|
|
|
return NO_INIT;
|
|
|
|
}
|
|
|
|
return NO_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
status_t SurfaceControl::writeSurfaceToParcel(
|
|
|
|
const sp<SurfaceControl>& control, Parcel* parcel)
|
|
|
|
{
|
|
|
|
sp<IGraphicBufferProducer> bp;
|
|
|
|
if (control != NULL) {
|
|
|
|
bp = control->mGraphicBufferProducer;
|
|
|
|
}
|
|
|
|
return parcel->writeStrongBinder(bp->asBinder());
|
|
|
|
}
|
|
|
|
|
|
|
|
sp<Surface> SurfaceControl::getSurface() const
|
|
|
|
{
|
|
|
|
Mutex::Autolock _l(mLock);
|
|
|
|
if (mSurfaceData == 0) {
|
|
|
|
mSurfaceData = new Surface(mGraphicBufferProducer);
|
|
|
|
}
|
|
|
|
return mSurfaceData;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
}; // namespace android
|