2009-03-04 03:31:44 +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 "Surface"
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
|
fix [2068105] implement queueBuffer/lockBuffer/dequeueBuffer properly
Rewrote SurfaceFlinger's buffer management from the ground-up.
The design now support an arbitrary number of buffers per surface, however the current implementation is limited to four. Currently only 2 buffers are used in practice.
The main new feature is to be able to dequeue all buffers at once (very important when there are only two).
A client can dequeue all buffers until there are none available, it can lock all buffers except the last one that is used for composition. The client will block then, until a new buffer is enqueued.
The current implementation requires that buffers are locked in the same order they are dequeued and enqueued in the same order they are locked. Only one buffer can be locked at a time.
eg. Allowed sequence: DQ, DQ, LOCK, Q, LOCK, Q
eg. Forbidden sequence: DQ, DQ, LOCK, LOCK, Q, Q
2009-09-07 23:32:45 +00:00
|
|
|
#include <utils/CallStack.h>
|
2011-04-20 21:20:59 +00:00
|
|
|
#include <utils/Errors.h>
|
2010-02-10 01:46:37 +00:00
|
|
|
#include <utils/Log.h>
|
2011-04-20 21:20:59 +00:00
|
|
|
#include <utils/threads.h>
|
2010-02-10 01:46:37 +00:00
|
|
|
|
2009-05-20 02:08:10 +00:00
|
|
|
#include <binder/IMemory.h>
|
2011-04-20 21:20:59 +00:00
|
|
|
#include <binder/IPCThreadState.h>
|
|
|
|
|
|
|
|
#include <gui/SurfaceTextureClient.h>
|
2009-03-04 03:31:44 +00:00
|
|
|
|
2009-04-10 21:24:30 +00:00
|
|
|
#include <ui/DisplayInfo.h>
|
2009-10-06 00:07:12 +00:00
|
|
|
#include <ui/GraphicBuffer.h>
|
|
|
|
#include <ui/GraphicBufferMapper.h>
|
2010-09-14 05:57:58 +00:00
|
|
|
#include <ui/GraphicLog.h>
|
2009-03-04 03:31:44 +00:00
|
|
|
#include <ui/Rect.h>
|
|
|
|
|
2010-02-10 01:46:37 +00:00
|
|
|
#include <surfaceflinger/ISurface.h>
|
|
|
|
#include <surfaceflinger/ISurfaceComposer.h>
|
2011-04-20 21:20:59 +00:00
|
|
|
#include <surfaceflinger/Surface.h>
|
2010-02-10 01:46:37 +00:00
|
|
|
#include <surfaceflinger/SurfaceComposerClient.h>
|
2009-04-10 21:24:30 +00:00
|
|
|
|
2010-02-10 01:46:37 +00:00
|
|
|
#include <private/surfaceflinger/LayerState.h>
|
2009-04-10 21:24:30 +00:00
|
|
|
|
2009-03-04 03:31:44 +00:00
|
|
|
namespace android {
|
|
|
|
|
2009-04-16 23:19:50 +00:00
|
|
|
// ============================================================================
|
|
|
|
// SurfaceControl
|
|
|
|
// ============================================================================
|
|
|
|
|
2009-04-17 03:04:08 +00:00
|
|
|
SurfaceControl::SurfaceControl(
|
|
|
|
const sp<SurfaceComposerClient>& client,
|
2009-04-16 23:19:50 +00:00
|
|
|
const sp<ISurface>& surface,
|
2010-05-28 21:22:23 +00:00
|
|
|
const ISurfaceComposerClient::surface_data_t& data,
|
2009-04-17 03:30:22 +00:00
|
|
|
uint32_t w, uint32_t h, PixelFormat format, uint32_t flags)
|
2009-04-16 23:19:50 +00:00
|
|
|
: mClient(client), mSurface(surface),
|
|
|
|
mToken(data.token), mIdentity(data.identity),
|
2009-08-20 00:46:26 +00:00
|
|
|
mWidth(data.width), mHeight(data.height), mFormat(data.format),
|
|
|
|
mFlags(flags)
|
2009-04-16 23:19:50 +00:00
|
|
|
{
|
|
|
|
}
|
2009-04-17 03:30:22 +00:00
|
|
|
|
2009-04-16 23:19:50 +00:00
|
|
|
SurfaceControl::~SurfaceControl()
|
|
|
|
{
|
|
|
|
destroy();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SurfaceControl::destroy()
|
|
|
|
{
|
2009-04-17 03:30:22 +00:00
|
|
|
if (isValid()) {
|
2009-04-16 23:19:50 +00:00
|
|
|
mClient->destroySurface(mToken);
|
|
|
|
}
|
|
|
|
|
|
|
|
// clear all references and trigger an IPC now, to make sure things
|
|
|
|
// happen without delay, since these resources are quite heavy.
|
|
|
|
mClient.clear();
|
|
|
|
mSurface.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();
|
|
|
|
}
|
|
|
|
|
2009-04-17 03:04:08 +00:00
|
|
|
bool SurfaceControl::isSameSurface(
|
|
|
|
const sp<SurfaceControl>& lhs, const sp<SurfaceControl>& rhs)
|
|
|
|
{
|
|
|
|
if (lhs == 0 || rhs == 0)
|
|
|
|
return false;
|
|
|
|
return lhs->mSurface->asBinder() == rhs->mSurface->asBinder();
|
|
|
|
}
|
|
|
|
|
2009-04-16 23:19:50 +00:00
|
|
|
status_t SurfaceControl::setLayer(int32_t layer) {
|
2009-11-13 23:26:29 +00:00
|
|
|
status_t err = validate();
|
2009-04-16 23:19:50 +00:00
|
|
|
if (err < 0) return err;
|
2010-05-26 00:51:34 +00:00
|
|
|
const sp<SurfaceComposerClient>& client(mClient);
|
2009-04-16 23:19:50 +00:00
|
|
|
return client->setLayer(mToken, layer);
|
|
|
|
}
|
|
|
|
status_t SurfaceControl::setPosition(int32_t x, int32_t y) {
|
2009-11-13 23:26:29 +00:00
|
|
|
status_t err = validate();
|
2009-04-16 23:19:50 +00:00
|
|
|
if (err < 0) return err;
|
2010-05-26 00:51:34 +00:00
|
|
|
const sp<SurfaceComposerClient>& client(mClient);
|
2009-04-16 23:19:50 +00:00
|
|
|
return client->setPosition(mToken, x, y);
|
|
|
|
}
|
|
|
|
status_t SurfaceControl::setSize(uint32_t w, uint32_t h) {
|
2009-11-13 23:26:29 +00:00
|
|
|
status_t err = validate();
|
2009-04-16 23:19:50 +00:00
|
|
|
if (err < 0) return err;
|
2010-05-26 00:51:34 +00:00
|
|
|
const sp<SurfaceComposerClient>& client(mClient);
|
2009-04-16 23:19:50 +00:00
|
|
|
return client->setSize(mToken, w, h);
|
|
|
|
}
|
|
|
|
status_t SurfaceControl::hide() {
|
2009-11-13 23:26:29 +00:00
|
|
|
status_t err = validate();
|
2009-04-16 23:19:50 +00:00
|
|
|
if (err < 0) return err;
|
2010-05-26 00:51:34 +00:00
|
|
|
const sp<SurfaceComposerClient>& client(mClient);
|
2009-04-16 23:19:50 +00:00
|
|
|
return client->hide(mToken);
|
|
|
|
}
|
|
|
|
status_t SurfaceControl::show(int32_t layer) {
|
2009-11-13 23:26:29 +00:00
|
|
|
status_t err = validate();
|
2009-04-16 23:19:50 +00:00
|
|
|
if (err < 0) return err;
|
2010-05-26 00:51:34 +00:00
|
|
|
const sp<SurfaceComposerClient>& client(mClient);
|
2009-04-16 23:19:50 +00:00
|
|
|
return client->show(mToken, layer);
|
|
|
|
}
|
|
|
|
status_t SurfaceControl::freeze() {
|
2009-11-13 23:26:29 +00:00
|
|
|
status_t err = validate();
|
2009-04-16 23:19:50 +00:00
|
|
|
if (err < 0) return err;
|
2010-05-26 00:51:34 +00:00
|
|
|
const sp<SurfaceComposerClient>& client(mClient);
|
2009-04-16 23:19:50 +00:00
|
|
|
return client->freeze(mToken);
|
|
|
|
}
|
|
|
|
status_t SurfaceControl::unfreeze() {
|
2009-11-13 23:26:29 +00:00
|
|
|
status_t err = validate();
|
2009-04-16 23:19:50 +00:00
|
|
|
if (err < 0) return err;
|
2010-05-26 00:51:34 +00:00
|
|
|
const sp<SurfaceComposerClient>& client(mClient);
|
2009-04-16 23:19:50 +00:00
|
|
|
return client->unfreeze(mToken);
|
|
|
|
}
|
|
|
|
status_t SurfaceControl::setFlags(uint32_t flags, uint32_t mask) {
|
2009-11-13 23:26:29 +00:00
|
|
|
status_t err = validate();
|
2009-04-16 23:19:50 +00:00
|
|
|
if (err < 0) return err;
|
2010-05-26 00:51:34 +00:00
|
|
|
const sp<SurfaceComposerClient>& client(mClient);
|
2009-04-16 23:19:50 +00:00
|
|
|
return client->setFlags(mToken, flags, mask);
|
|
|
|
}
|
|
|
|
status_t SurfaceControl::setTransparentRegionHint(const Region& transparent) {
|
2009-11-13 23:26:29 +00:00
|
|
|
status_t err = validate();
|
2009-04-16 23:19:50 +00:00
|
|
|
if (err < 0) return err;
|
2010-05-26 00:51:34 +00:00
|
|
|
const sp<SurfaceComposerClient>& client(mClient);
|
2009-04-16 23:19:50 +00:00
|
|
|
return client->setTransparentRegionHint(mToken, transparent);
|
|
|
|
}
|
|
|
|
status_t SurfaceControl::setAlpha(float alpha) {
|
2009-11-13 23:26:29 +00:00
|
|
|
status_t err = validate();
|
2009-04-16 23:19:50 +00:00
|
|
|
if (err < 0) return err;
|
2010-05-26 00:51:34 +00:00
|
|
|
const sp<SurfaceComposerClient>& client(mClient);
|
2009-04-16 23:19:50 +00:00
|
|
|
return client->setAlpha(mToken, alpha);
|
|
|
|
}
|
|
|
|
status_t SurfaceControl::setMatrix(float dsdx, float dtdx, float dsdy, float dtdy) {
|
2009-11-13 23:26:29 +00:00
|
|
|
status_t err = validate();
|
2009-04-16 23:19:50 +00:00
|
|
|
if (err < 0) return err;
|
2010-05-26 00:51:34 +00:00
|
|
|
const sp<SurfaceComposerClient>& client(mClient);
|
2009-04-16 23:19:50 +00:00
|
|
|
return client->setMatrix(mToken, dsdx, dtdx, dsdy, dtdy);
|
|
|
|
}
|
|
|
|
status_t SurfaceControl::setFreezeTint(uint32_t tint) {
|
2009-11-13 23:26:29 +00:00
|
|
|
status_t err = validate();
|
2009-04-16 23:19:50 +00:00
|
|
|
if (err < 0) return err;
|
2010-05-26 00:51:34 +00:00
|
|
|
const sp<SurfaceComposerClient>& client(mClient);
|
2009-04-16 23:19:50 +00:00
|
|
|
return client->setFreezeTint(mToken, tint);
|
|
|
|
}
|
|
|
|
|
2009-11-13 23:26:29 +00:00
|
|
|
status_t SurfaceControl::validate() const
|
2009-04-16 23:19:50 +00:00
|
|
|
{
|
|
|
|
if (mToken<0 || mClient==0) {
|
|
|
|
LOGE("invalid token (%d, identity=%u) or client (%p)",
|
|
|
|
mToken, mIdentity, mClient.get());
|
|
|
|
return NO_INIT;
|
|
|
|
}
|
|
|
|
return NO_ERROR;
|
|
|
|
}
|
|
|
|
|
2009-04-17 03:04:08 +00:00
|
|
|
status_t SurfaceControl::writeSurfaceToParcel(
|
|
|
|
const sp<SurfaceControl>& control, Parcel* parcel)
|
|
|
|
{
|
2010-06-09 02:54:15 +00:00
|
|
|
sp<ISurface> sur;
|
2009-04-17 03:04:08 +00:00
|
|
|
uint32_t identity = 0;
|
2009-07-31 01:14:56 +00:00
|
|
|
uint32_t width = 0;
|
|
|
|
uint32_t height = 0;
|
2010-06-09 02:54:15 +00:00
|
|
|
uint32_t format = 0;
|
|
|
|
uint32_t flags = 0;
|
2009-04-17 03:04:08 +00:00
|
|
|
if (SurfaceControl::isValid(control)) {
|
|
|
|
sur = control->mSurface;
|
2010-06-09 02:54:15 +00:00
|
|
|
identity = control->mIdentity;
|
2009-07-31 01:14:56 +00:00
|
|
|
width = control->mWidth;
|
|
|
|
height = control->mHeight;
|
2009-04-17 03:04:08 +00:00
|
|
|
format = control->mFormat;
|
|
|
|
flags = control->mFlags;
|
|
|
|
}
|
2010-06-01 22:12:58 +00:00
|
|
|
parcel->writeStrongBinder(sur!=0 ? sur->asBinder() : NULL);
|
2009-04-17 03:04:08 +00:00
|
|
|
parcel->writeInt32(identity);
|
2009-07-31 01:14:56 +00:00
|
|
|
parcel->writeInt32(width);
|
|
|
|
parcel->writeInt32(height);
|
2009-04-17 03:04:08 +00:00
|
|
|
parcel->writeInt32(format);
|
|
|
|
parcel->writeInt32(flags);
|
|
|
|
return NO_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
sp<Surface> SurfaceControl::getSurface() const
|
|
|
|
{
|
|
|
|
Mutex::Autolock _l(mLock);
|
|
|
|
if (mSurfaceData == 0) {
|
|
|
|
mSurfaceData = new Surface(const_cast<SurfaceControl*>(this));
|
|
|
|
}
|
|
|
|
return mSurfaceData;
|
|
|
|
}
|
|
|
|
|
2009-04-10 21:24:30 +00:00
|
|
|
// ============================================================================
|
|
|
|
// Surface
|
|
|
|
// ============================================================================
|
2009-03-04 03:31:44 +00:00
|
|
|
|
2010-06-01 22:12:58 +00:00
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
2009-04-17 03:04:08 +00:00
|
|
|
Surface::Surface(const sp<SurfaceControl>& surface)
|
2011-07-14 00:39:11 +00:00
|
|
|
: SurfaceTextureClient(),
|
|
|
|
mInitCheck(NO_INIT),
|
2010-06-01 22:12:58 +00:00
|
|
|
mSurface(surface->mSurface),
|
|
|
|
mIdentity(surface->mIdentity),
|
|
|
|
mFormat(surface->mFormat), mFlags(surface->mFlags),
|
2009-08-15 01:52:17 +00:00
|
|
|
mWidth(surface->mWidth), mHeight(surface->mHeight)
|
2009-03-04 03:31:44 +00:00
|
|
|
{
|
2009-04-17 03:04:08 +00:00
|
|
|
init();
|
|
|
|
}
|
2009-04-16 23:19:50 +00:00
|
|
|
|
2010-06-05 01:26:32 +00:00
|
|
|
Surface::Surface(const Parcel& parcel, const sp<IBinder>& ref)
|
2011-07-14 00:39:11 +00:00
|
|
|
: SurfaceTextureClient(),
|
|
|
|
mInitCheck(NO_INIT)
|
2009-04-17 03:04:08 +00:00
|
|
|
{
|
2010-06-05 01:26:32 +00:00
|
|
|
mSurface = interface_cast<ISurface>(ref);
|
2009-04-17 03:04:08 +00:00
|
|
|
mIdentity = parcel.readInt32();
|
2009-07-31 01:14:56 +00:00
|
|
|
mWidth = parcel.readInt32();
|
|
|
|
mHeight = parcel.readInt32();
|
2009-04-17 03:04:08 +00:00
|
|
|
mFormat = parcel.readInt32();
|
|
|
|
mFlags = parcel.readInt32();
|
|
|
|
init();
|
|
|
|
}
|
|
|
|
|
2010-06-09 02:54:15 +00:00
|
|
|
status_t Surface::writeToParcel(
|
|
|
|
const sp<Surface>& surface, Parcel* parcel)
|
|
|
|
{
|
|
|
|
sp<ISurface> sur;
|
|
|
|
uint32_t identity = 0;
|
|
|
|
uint32_t width = 0;
|
|
|
|
uint32_t height = 0;
|
|
|
|
uint32_t format = 0;
|
|
|
|
uint32_t flags = 0;
|
|
|
|
if (Surface::isValid(surface)) {
|
|
|
|
sur = surface->mSurface;
|
|
|
|
identity = surface->mIdentity;
|
|
|
|
width = surface->mWidth;
|
|
|
|
height = surface->mHeight;
|
|
|
|
format = surface->mFormat;
|
|
|
|
flags = surface->mFlags;
|
2010-08-10 23:37:53 +00:00
|
|
|
} else if (surface != 0 && surface->mSurface != 0) {
|
|
|
|
LOGW("Parceling invalid surface with non-NULL ISurface as NULL: "
|
|
|
|
"mSurface = %p, mIdentity = %d, mWidth = %d, mHeight = %d, "
|
|
|
|
"mFormat = %d, mFlags = 0x%08x, mInitCheck = %d",
|
|
|
|
surface->mSurface.get(), surface->mIdentity, surface->mWidth,
|
|
|
|
surface->mHeight, surface->mFormat, surface->mFlags,
|
|
|
|
surface->mInitCheck);
|
2010-06-09 02:54:15 +00:00
|
|
|
}
|
|
|
|
parcel->writeStrongBinder(sur!=0 ? sur->asBinder() : NULL);
|
|
|
|
parcel->writeInt32(identity);
|
|
|
|
parcel->writeInt32(width);
|
|
|
|
parcel->writeInt32(height);
|
|
|
|
parcel->writeInt32(format);
|
|
|
|
parcel->writeInt32(flags);
|
|
|
|
return NO_ERROR;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2010-07-16 00:29:15 +00:00
|
|
|
Mutex Surface::sCachedSurfacesLock;
|
2010-12-14 00:47:31 +00:00
|
|
|
DefaultKeyedVector<wp<IBinder>, wp<Surface> > Surface::sCachedSurfaces;
|
2010-07-16 00:29:15 +00:00
|
|
|
|
|
|
|
sp<Surface> Surface::readFromParcel(const Parcel& data) {
|
|
|
|
Mutex::Autolock _l(sCachedSurfacesLock);
|
2010-06-05 01:26:32 +00:00
|
|
|
sp<IBinder> binder(data.readStrongBinder());
|
2010-07-16 00:29:15 +00:00
|
|
|
sp<Surface> surface = sCachedSurfaces.valueFor(binder).promote();
|
|
|
|
if (surface == 0) {
|
|
|
|
surface = new Surface(data, binder);
|
|
|
|
sCachedSurfaces.add(binder, surface);
|
|
|
|
}
|
|
|
|
if (surface->mSurface == 0) {
|
|
|
|
surface = 0;
|
|
|
|
}
|
2010-12-14 00:47:31 +00:00
|
|
|
cleanCachedSurfacesLocked();
|
2010-07-16 00:29:15 +00:00
|
|
|
return surface;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Remove the stale entries from the surface cache. This should only be called
|
|
|
|
// with sCachedSurfacesLock held.
|
2010-12-14 00:47:31 +00:00
|
|
|
void Surface::cleanCachedSurfacesLocked() {
|
2010-07-16 00:29:15 +00:00
|
|
|
for (int i = sCachedSurfaces.size()-1; i >= 0; --i) {
|
|
|
|
wp<Surface> s(sCachedSurfaces.valueAt(i));
|
|
|
|
if (s == 0 || s.promote() == 0) {
|
|
|
|
sCachedSurfaces.removeItemsAt(i);
|
|
|
|
}
|
2010-06-05 01:26:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-04-17 03:04:08 +00:00
|
|
|
void Surface::init()
|
|
|
|
{
|
2011-04-20 21:20:59 +00:00
|
|
|
if (mSurface != NULL) {
|
|
|
|
sp<ISurfaceTexture> surfaceTexture(mSurface->getSurfaceTexture());
|
|
|
|
LOGE_IF(surfaceTexture==0, "got a NULL ISurfaceTexture from ISurface");
|
|
|
|
if (surfaceTexture != NULL) {
|
2011-07-14 00:39:11 +00:00
|
|
|
setISurfaceTexture(surfaceTexture);
|
|
|
|
setUsage(GraphicBuffer::USAGE_HW_RENDER);
|
2011-04-20 21:20:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
DisplayInfo dinfo;
|
|
|
|
SurfaceComposerClient::getDisplayInfo(0, &dinfo);
|
|
|
|
const_cast<float&>(ANativeWindow::xdpi) = dinfo.xdpi;
|
|
|
|
const_cast<float&>(ANativeWindow::ydpi) = dinfo.ydpi;
|
|
|
|
const_cast<uint32_t&>(ANativeWindow::flags) = 0;
|
|
|
|
|
2011-07-14 00:39:11 +00:00
|
|
|
if (surfaceTexture != NULL) {
|
2011-04-20 21:20:59 +00:00
|
|
|
mInitCheck = NO_ERROR;
|
2010-06-01 22:12:58 +00:00
|
|
|
}
|
2010-05-26 00:51:34 +00:00
|
|
|
}
|
2009-03-04 03:31:44 +00:00
|
|
|
}
|
|
|
|
|
2009-04-15 01:21:47 +00:00
|
|
|
Surface::~Surface()
|
2009-03-04 03:31:44 +00:00
|
|
|
{
|
2009-04-15 01:21:47 +00:00
|
|
|
// clear all references and trigger an IPC now, to make sure things
|
|
|
|
// happen without delay, since these resources are quite heavy.
|
2009-03-04 03:31:44 +00:00
|
|
|
mSurface.clear();
|
|
|
|
IPCThreadState::self()->flushCommands();
|
|
|
|
}
|
|
|
|
|
2009-08-15 01:52:17 +00:00
|
|
|
bool Surface::isValid() {
|
2010-05-26 00:51:34 +00:00
|
|
|
return mInitCheck == NO_ERROR;
|
2009-08-15 01:52:17 +00:00
|
|
|
}
|
|
|
|
|
2011-01-14 19:04:34 +00:00
|
|
|
status_t Surface::validate(bool inCancelBuffer) const
|
2009-04-10 21:24:30 +00:00
|
|
|
{
|
2010-05-26 00:51:34 +00:00
|
|
|
// check that we initialized ourself properly
|
|
|
|
if (mInitCheck != NO_ERROR) {
|
2010-06-09 02:54:15 +00:00
|
|
|
LOGE("invalid token (identity=%u)", mIdentity);
|
2010-05-26 00:51:34 +00:00
|
|
|
return mInitCheck;
|
2009-04-15 01:21:47 +00:00
|
|
|
}
|
2009-04-10 21:24:30 +00:00
|
|
|
return NO_ERROR;
|
|
|
|
}
|
|
|
|
|
2011-06-22 22:52:53 +00:00
|
|
|
sp<ISurfaceTexture> Surface::getSurfaceTexture() {
|
|
|
|
return mSurface != NULL ? mSurface->getSurfaceTexture() : NULL;
|
|
|
|
}
|
|
|
|
|
2011-04-05 22:44:20 +00:00
|
|
|
sp<IBinder> Surface::asBinder() const {
|
|
|
|
return mSurface!=0 ? mSurface->asBinder() : 0;
|
2010-05-26 00:51:34 +00:00
|
|
|
}
|
|
|
|
|
2009-04-10 21:24:30 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2011-04-20 21:20:59 +00:00
|
|
|
int Surface::query(int what, int* value) const {
|
2009-07-31 01:14:56 +00:00
|
|
|
switch (what) {
|
2011-04-20 21:20:59 +00:00
|
|
|
case NATIVE_WINDOW_QUEUES_TO_WINDOW_COMPOSER:
|
|
|
|
// TODO: this is not needed anymore
|
|
|
|
*value = 1;
|
fix [2068105] implement queueBuffer/lockBuffer/dequeueBuffer properly
Rewrote SurfaceFlinger's buffer management from the ground-up.
The design now support an arbitrary number of buffers per surface, however the current implementation is limited to four. Currently only 2 buffers are used in practice.
The main new feature is to be able to dequeue all buffers at once (very important when there are only two).
A client can dequeue all buffers until there are none available, it can lock all buffers except the last one that is used for composition. The client will block then, until a new buffer is enqueued.
The current implementation requires that buffers are locked in the same order they are dequeued and enqueued in the same order they are locked. Only one buffer can be locked at a time.
eg. Allowed sequence: DQ, DQ, LOCK, Q, LOCK, Q
eg. Forbidden sequence: DQ, DQ, LOCK, LOCK, Q, Q
2009-09-07 23:32:45 +00:00
|
|
|
return NO_ERROR;
|
2011-03-14 22:00:06 +00:00
|
|
|
case NATIVE_WINDOW_CONCRETE_TYPE:
|
|
|
|
*value = NATIVE_WINDOW_SURFACE;
|
|
|
|
return NO_ERROR;
|
|
|
|
}
|
2011-07-14 00:39:11 +00:00
|
|
|
return SurfaceTextureClient::query(what, value);
|
2011-02-18 19:02:42 +00:00
|
|
|
}
|
|
|
|
|
2010-05-22 00:24:35 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2011-07-14 00:39:11 +00:00
|
|
|
status_t Surface::lock(SurfaceInfo* other, Region* dirtyIn) {
|
|
|
|
ANativeWindow_Buffer outBuffer;
|
2010-03-11 23:06:54 +00:00
|
|
|
|
2011-07-14 00:39:11 +00:00
|
|
|
ARect temp;
|
|
|
|
ARect* inOutDirtyBounds = NULL;
|
|
|
|
if (dirtyIn) {
|
|
|
|
temp = dirtyIn->getBounds();
|
|
|
|
inOutDirtyBounds = &temp;
|
fix [2068105] implement queueBuffer/lockBuffer/dequeueBuffer properly
Rewrote SurfaceFlinger's buffer management from the ground-up.
The design now support an arbitrary number of buffers per surface, however the current implementation is limited to four. Currently only 2 buffers are used in practice.
The main new feature is to be able to dequeue all buffers at once (very important when there are only two).
A client can dequeue all buffers until there are none available, it can lock all buffers except the last one that is used for composition. The client will block then, until a new buffer is enqueued.
The current implementation requires that buffers are locked in the same order they are dequeued and enqueued in the same order they are locked. Only one buffer can be locked at a time.
eg. Allowed sequence: DQ, DQ, LOCK, Q, LOCK, Q
eg. Forbidden sequence: DQ, DQ, LOCK, LOCK, Q, Q
2009-09-07 23:32:45 +00:00
|
|
|
}
|
2010-01-22 19:47:55 +00:00
|
|
|
|
2011-07-14 00:39:11 +00:00
|
|
|
status_t err = SurfaceTextureClient::lock(&outBuffer, inOutDirtyBounds);
|
2009-08-15 01:52:17 +00:00
|
|
|
|
2009-04-10 21:24:30 +00:00
|
|
|
if (err == NO_ERROR) {
|
2011-07-14 00:39:11 +00:00
|
|
|
other->w = uint32_t(outBuffer.width);
|
|
|
|
other->h = uint32_t(outBuffer.height);
|
|
|
|
other->s = uint32_t(outBuffer.stride);
|
|
|
|
other->usage = GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN;
|
|
|
|
other->format = uint32_t(outBuffer.format);
|
|
|
|
other->bits = outBuffer.bits;
|
2009-04-10 21:24:30 +00:00
|
|
|
}
|
|
|
|
return err;
|
2009-03-04 03:31:44 +00:00
|
|
|
}
|
fix [2068105] implement queueBuffer/lockBuffer/dequeueBuffer properly
Rewrote SurfaceFlinger's buffer management from the ground-up.
The design now support an arbitrary number of buffers per surface, however the current implementation is limited to four. Currently only 2 buffers are used in practice.
The main new feature is to be able to dequeue all buffers at once (very important when there are only two).
A client can dequeue all buffers until there are none available, it can lock all buffers except the last one that is used for composition. The client will block then, until a new buffer is enqueued.
The current implementation requires that buffers are locked in the same order they are dequeued and enqueued in the same order they are locked. Only one buffer can be locked at a time.
eg. Allowed sequence: DQ, DQ, LOCK, Q, LOCK, Q
eg. Forbidden sequence: DQ, DQ, LOCK, LOCK, Q, Q
2009-09-07 23:32:45 +00:00
|
|
|
|
2011-07-14 00:39:11 +00:00
|
|
|
status_t Surface::unlockAndPost() {
|
|
|
|
return SurfaceTextureClient::unlockAndPost();
|
2009-03-04 03:31:44 +00:00
|
|
|
}
|
|
|
|
|
2010-05-22 00:24:35 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
2009-03-04 03:31:44 +00:00
|
|
|
}; // namespace android
|