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>
|
|
|
|
|
|
|
|
#include <utils/Errors.h>
|
|
|
|
#include <utils/threads.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>
|
2010-02-10 01:46:37 +00:00
|
|
|
#include <utils/Log.h>
|
|
|
|
|
2009-05-20 02:08:10 +00:00
|
|
|
#include <binder/IPCThreadState.h>
|
|
|
|
#include <binder/IMemory.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/Surface.h>
|
|
|
|
#include <surfaceflinger/ISurface.h>
|
|
|
|
#include <surfaceflinger/ISurfaceComposer.h>
|
|
|
|
#include <surfaceflinger/SurfaceComposerClient.h>
|
2009-04-10 21:24:30 +00:00
|
|
|
|
2010-02-10 01:46:37 +00:00
|
|
|
#include <private/surfaceflinger/SharedBufferStack.h>
|
|
|
|
#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-10 21:24:30 +00:00
|
|
|
// ----------------------------------------------------------------------
|
|
|
|
|
2009-07-14 01:29:59 +00:00
|
|
|
static status_t copyBlt(
|
2009-10-06 00:07:12 +00:00
|
|
|
const sp<GraphicBuffer>& dst,
|
|
|
|
const sp<GraphicBuffer>& src,
|
2009-05-04 21:17:04 +00:00
|
|
|
const Region& reg)
|
2009-04-10 21:24:30 +00:00
|
|
|
{
|
2010-04-21 22:24:11 +00:00
|
|
|
// src and dst with, height and format must be identical. no verification
|
|
|
|
// is done here.
|
2009-07-14 01:29:59 +00:00
|
|
|
status_t err;
|
|
|
|
uint8_t const * src_bits = NULL;
|
|
|
|
err = src->lock(GRALLOC_USAGE_SW_READ_OFTEN, reg.bounds(), (void**)&src_bits);
|
|
|
|
LOGE_IF(err, "error locking src buffer %s", strerror(-err));
|
2009-05-04 21:17:04 +00:00
|
|
|
|
2009-07-14 01:29:59 +00:00
|
|
|
uint8_t* dst_bits = NULL;
|
|
|
|
err = dst->lock(GRALLOC_USAGE_SW_WRITE_OFTEN, reg.bounds(), (void**)&dst_bits);
|
|
|
|
LOGE_IF(err, "error locking dst buffer %s", strerror(-err));
|
|
|
|
|
|
|
|
Region::const_iterator head(reg.begin());
|
|
|
|
Region::const_iterator tail(reg.end());
|
|
|
|
if (head != tail && src_bits && dst_bits) {
|
2009-04-10 21:24:30 +00:00
|
|
|
const size_t bpp = bytesPerPixel(src->format);
|
|
|
|
const size_t dbpr = dst->stride * bpp;
|
|
|
|
const size_t sbpr = src->stride * bpp;
|
2009-05-04 21:17:04 +00:00
|
|
|
|
2009-07-14 01:29:59 +00:00
|
|
|
while (head != tail) {
|
|
|
|
const Rect& r(*head++);
|
2009-05-04 21:17:04 +00:00
|
|
|
ssize_t h = r.height();
|
|
|
|
if (h <= 0) continue;
|
|
|
|
size_t size = r.width() * bpp;
|
|
|
|
uint8_t const * s = src_bits + (r.left + src->stride * r.top) * bpp;
|
|
|
|
uint8_t * d = dst_bits + (r.left + dst->stride * r.top) * bpp;
|
|
|
|
if (dbpr==sbpr && size==sbpr) {
|
|
|
|
size *= h;
|
|
|
|
h = 1;
|
2009-04-10 21:24:30 +00:00
|
|
|
}
|
2009-05-04 21:17:04 +00:00
|
|
|
do {
|
|
|
|
memcpy(d, s, size);
|
|
|
|
d += dbpr;
|
|
|
|
s += sbpr;
|
|
|
|
} while (--h > 0);
|
2009-04-10 21:24:30 +00:00
|
|
|
}
|
|
|
|
}
|
2009-05-04 21:17:04 +00:00
|
|
|
|
2009-07-14 01:29:59 +00:00
|
|
|
if (src_bits)
|
|
|
|
src->unlock();
|
|
|
|
|
|
|
|
if (dst_bits)
|
|
|
|
dst->unlock();
|
|
|
|
|
|
|
|
return err;
|
2009-04-10 21:24:30 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
class SurfaceClient : public Singleton<SurfaceClient>
|
|
|
|
{
|
|
|
|
// all these attributes are constants
|
|
|
|
sp<ISurfaceComposer> mComposerService;
|
|
|
|
sp<ISurfaceComposerClient> mClient;
|
|
|
|
status_t mStatus;
|
|
|
|
SharedClient* mControl;
|
|
|
|
sp<IMemoryHeap> mControlMemory;
|
|
|
|
|
|
|
|
SurfaceClient()
|
|
|
|
: Singleton<SurfaceClient>(), mStatus(NO_INIT)
|
|
|
|
{
|
|
|
|
sp<ISurfaceComposer> sf(ComposerService::getComposerService());
|
|
|
|
mComposerService = sf;
|
|
|
|
mClient = sf->createClientConnection();
|
|
|
|
if (mClient != NULL) {
|
|
|
|
mControlMemory = mClient->getControlBlock();
|
|
|
|
if (mControlMemory != NULL) {
|
|
|
|
mControl = static_cast<SharedClient *>(
|
|
|
|
mControlMemory->getBase());
|
|
|
|
if (mControl) {
|
|
|
|
mStatus = NO_ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
friend class Singleton<SurfaceClient>;
|
|
|
|
public:
|
|
|
|
status_t initCheck() const {
|
|
|
|
return mStatus;
|
|
|
|
}
|
|
|
|
SharedClient* getSharedClient() const {
|
|
|
|
return mControl;
|
|
|
|
}
|
|
|
|
ssize_t getTokenForSurface(const sp<ISurface>& sur) const {
|
|
|
|
// TODO: we could cache a few tokens here to avoid an IPC
|
|
|
|
return mClient->getTokenForSurface(sur);
|
|
|
|
}
|
|
|
|
void signalServer() const {
|
|
|
|
mComposerService->signal();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
ANDROID_SINGLETON_STATIC_INSTANCE(SurfaceClient);
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
2009-04-17 03:04:08 +00:00
|
|
|
Surface::Surface(const sp<SurfaceControl>& surface)
|
2010-06-01 22:12:58 +00:00
|
|
|
: mBufferMapper(GraphicBufferMapper::get()),
|
|
|
|
mClient(SurfaceClient::getInstance()),
|
|
|
|
mSharedBufferClient(NULL),
|
2010-05-26 00:51:34 +00:00
|
|
|
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)
|
2010-06-01 22:12:58 +00:00
|
|
|
: mBufferMapper(GraphicBufferMapper::get()),
|
|
|
|
mClient(SurfaceClient::getInstance()),
|
|
|
|
mSharedBufferClient(NULL),
|
|
|
|
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()
|
|
|
|
{
|
2010-06-30 20:56:17 +00:00
|
|
|
ANativeWindow::setSwapInterval = setSwapInterval;
|
|
|
|
ANativeWindow::dequeueBuffer = dequeueBuffer;
|
2010-10-01 23:22:41 +00:00
|
|
|
ANativeWindow::cancelBuffer = cancelBuffer;
|
2010-06-30 20:56:17 +00:00
|
|
|
ANativeWindow::lockBuffer = lockBuffer;
|
|
|
|
ANativeWindow::queueBuffer = queueBuffer;
|
|
|
|
ANativeWindow::query = query;
|
|
|
|
ANativeWindow::perform = perform;
|
2010-05-26 00:51:34 +00:00
|
|
|
|
2009-04-10 21:24:30 +00:00
|
|
|
DisplayInfo dinfo;
|
|
|
|
SurfaceComposerClient::getDisplayInfo(0, &dinfo);
|
2010-06-30 20:56:17 +00:00
|
|
|
const_cast<float&>(ANativeWindow::xdpi) = dinfo.xdpi;
|
|
|
|
const_cast<float&>(ANativeWindow::ydpi) = dinfo.ydpi;
|
2009-04-10 21:24:30 +00:00
|
|
|
// FIXME: set real values here
|
2010-06-30 20:56:17 +00:00
|
|
|
const_cast<int&>(ANativeWindow::minSwapInterval) = 1;
|
|
|
|
const_cast<int&>(ANativeWindow::maxSwapInterval) = 1;
|
|
|
|
const_cast<uint32_t&>(ANativeWindow::flags) = 0;
|
2010-05-26 00:51:34 +00:00
|
|
|
|
2010-08-20 00:01:19 +00:00
|
|
|
mNextBufferTransform = 0;
|
2010-03-11 23:06:54 +00:00
|
|
|
mConnected = 0;
|
2010-05-26 00:51:34 +00:00
|
|
|
mSwapRectangle.makeInvalid();
|
2010-08-20 00:01:19 +00:00
|
|
|
mNextBufferCrop = Rect(0,0);
|
2010-05-22 00:24:35 +00:00
|
|
|
// two buffers by default
|
|
|
|
mBuffers.setCapacity(2);
|
|
|
|
mBuffers.insertAt(0, 2);
|
2010-05-26 00:51:34 +00:00
|
|
|
|
2010-06-01 22:12:58 +00:00
|
|
|
if (mSurface != 0 && mClient.initCheck() == NO_ERROR) {
|
2010-06-09 02:54:15 +00:00
|
|
|
int32_t token = mClient.getTokenForSurface(mSurface);
|
|
|
|
if (token >= 0) {
|
2010-06-01 22:12:58 +00:00
|
|
|
mSharedBufferClient = new SharedBufferClient(
|
2010-06-09 02:54:15 +00:00
|
|
|
mClient.getSharedClient(), token, 2, mIdentity);
|
|
|
|
mInitCheck = mClient.getSharedClient()->validate(token);
|
2010-08-10 23:37:53 +00:00
|
|
|
} else {
|
|
|
|
LOGW("Not initializing the shared buffer client because token = %d",
|
|
|
|
token);
|
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.
|
2010-05-22 00:24:35 +00:00
|
|
|
mBuffers.clear();
|
2009-03-04 03:31:44 +00:00
|
|
|
mSurface.clear();
|
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
|
|
|
delete mSharedBufferClient;
|
2009-03-04 03:31:44 +00:00
|
|
|
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
|
|
|
}
|
2010-05-26 00:51:34 +00:00
|
|
|
|
|
|
|
// verify the identity of this surface
|
2010-05-28 21:22:23 +00:00
|
|
|
uint32_t identity = mSharedBufferClient->getIdentity();
|
2010-05-26 00:51:34 +00:00
|
|
|
if (mIdentity != identity) {
|
2010-06-09 02:54:15 +00:00
|
|
|
LOGE("[Surface] using an invalid surface, "
|
2010-05-26 00:51:34 +00:00
|
|
|
"identity=%u should be %d",
|
2010-06-09 02:54:15 +00:00
|
|
|
mIdentity, identity);
|
2010-12-10 23:37:48 +00:00
|
|
|
CallStack stack;
|
|
|
|
stack.update();
|
|
|
|
stack.dump("Surface");
|
2011-01-14 19:04:34 +00:00
|
|
|
return BAD_INDEX;
|
2009-04-10 21:24:30 +00:00
|
|
|
}
|
2010-05-26 00:51:34 +00:00
|
|
|
|
|
|
|
// check the surface didn't become invalid
|
2010-05-28 21:22:23 +00:00
|
|
|
status_t err = mSharedBufferClient->getStatus();
|
2009-04-10 21:24:30 +00:00
|
|
|
if (err != NO_ERROR) {
|
2011-01-14 19:04:34 +00:00
|
|
|
if (!inCancelBuffer) {
|
|
|
|
LOGE("surface (identity=%u) is invalid, err=%d (%s)",
|
|
|
|
mIdentity, err, strerror(-err));
|
|
|
|
CallStack stack;
|
|
|
|
stack.update();
|
|
|
|
stack.dump("Surface");
|
|
|
|
}
|
2009-04-10 21:24:30 +00:00
|
|
|
return err;
|
|
|
|
}
|
2010-05-26 00:51:34 +00:00
|
|
|
|
2009-04-10 21:24:30 +00:00
|
|
|
return NO_ERROR;
|
|
|
|
}
|
|
|
|
|
2010-05-26 00:51:34 +00:00
|
|
|
sp<ISurface> Surface::getISurface() const {
|
|
|
|
return mSurface;
|
|
|
|
}
|
|
|
|
|
2009-04-10 21:24:30 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2010-06-30 20:56:17 +00:00
|
|
|
int Surface::setSwapInterval(ANativeWindow* window, int interval) {
|
2009-04-10 21:24:30 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-06-30 20:56:17 +00:00
|
|
|
int Surface::dequeueBuffer(ANativeWindow* window,
|
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
|
|
|
android_native_buffer_t** buffer) {
|
2009-04-10 21:24:30 +00:00
|
|
|
Surface* self = getSelf(window);
|
|
|
|
return self->dequeueBuffer(buffer);
|
|
|
|
}
|
|
|
|
|
2010-10-01 23:22:41 +00:00
|
|
|
int Surface::cancelBuffer(ANativeWindow* window,
|
|
|
|
android_native_buffer_t* buffer) {
|
|
|
|
Surface* self = getSelf(window);
|
|
|
|
return self->cancelBuffer(buffer);
|
|
|
|
}
|
|
|
|
|
2010-06-30 20:56:17 +00:00
|
|
|
int Surface::lockBuffer(ANativeWindow* window,
|
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
|
|
|
android_native_buffer_t* buffer) {
|
2009-04-10 21:24:30 +00:00
|
|
|
Surface* self = getSelf(window);
|
|
|
|
return self->lockBuffer(buffer);
|
|
|
|
}
|
|
|
|
|
2010-06-30 20:56:17 +00:00
|
|
|
int Surface::queueBuffer(ANativeWindow* window,
|
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
|
|
|
android_native_buffer_t* buffer) {
|
2009-04-10 21:24:30 +00:00
|
|
|
Surface* self = getSelf(window);
|
|
|
|
return self->queueBuffer(buffer);
|
|
|
|
}
|
|
|
|
|
2010-06-30 20:56:17 +00:00
|
|
|
int Surface::query(ANativeWindow* window,
|
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
|
|
|
int what, int* value) {
|
2009-07-31 01:14:56 +00:00
|
|
|
Surface* self = getSelf(window);
|
|
|
|
return self->query(what, value);
|
|
|
|
}
|
|
|
|
|
2010-06-30 20:56:17 +00:00
|
|
|
int Surface::perform(ANativeWindow* window,
|
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
|
|
|
int operation, ...) {
|
2009-08-12 05:34:02 +00:00
|
|
|
va_list args;
|
|
|
|
va_start(args, operation);
|
|
|
|
Surface* self = getSelf(window);
|
|
|
|
int res = self->perform(operation, args);
|
|
|
|
va_end(args);
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2009-04-10 21:24:30 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2010-05-22 00:24:35 +00:00
|
|
|
bool Surface::needNewBuffer(int bufIdx,
|
|
|
|
uint32_t *pWidth, uint32_t *pHeight,
|
|
|
|
uint32_t *pFormat, uint32_t *pUsage) const
|
|
|
|
{
|
|
|
|
Mutex::Autolock _l(mSurfaceLock);
|
|
|
|
|
|
|
|
// Always call needNewBuffer(), since it clears the needed buffers flags
|
|
|
|
bool needNewBuffer = mSharedBufferClient->needNewBuffer(bufIdx);
|
|
|
|
bool validBuffer = mBufferInfo.validateBuffer(mBuffers[bufIdx]);
|
|
|
|
bool newNeewBuffer = needNewBuffer || !validBuffer;
|
|
|
|
if (newNeewBuffer) {
|
|
|
|
mBufferInfo.get(pWidth, pHeight, pFormat, pUsage);
|
|
|
|
}
|
|
|
|
return newNeewBuffer;
|
|
|
|
}
|
|
|
|
|
2009-04-10 21:24:30 +00:00
|
|
|
int Surface::dequeueBuffer(android_native_buffer_t** buffer)
|
|
|
|
{
|
2009-11-13 23:26:29 +00:00
|
|
|
status_t err = validate();
|
2009-04-10 21:24:30 +00:00
|
|
|
if (err != NO_ERROR)
|
|
|
|
return err;
|
|
|
|
|
2010-09-14 05:57:58 +00:00
|
|
|
GraphicLog& logger(GraphicLog::getInstance());
|
|
|
|
logger.log(GraphicLog::SF_APP_DEQUEUE_BEFORE, mIdentity, -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
|
|
|
ssize_t bufIdx = mSharedBufferClient->dequeue();
|
2010-09-14 05:57:58 +00:00
|
|
|
|
|
|
|
logger.log(GraphicLog::SF_APP_DEQUEUE_AFTER, mIdentity, bufIdx);
|
|
|
|
|
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
|
|
|
if (bufIdx < 0) {
|
|
|
|
LOGE("error dequeuing a buffer (%s)", strerror(bufIdx));
|
|
|
|
return bufIdx;
|
2009-08-21 22:44:17 +00:00
|
|
|
}
|
2009-09-16 02:10:47 +00:00
|
|
|
|
2010-05-22 00:24:35 +00:00
|
|
|
// grow the buffer array if needed
|
|
|
|
const size_t size = mBuffers.size();
|
|
|
|
const size_t needed = bufIdx+1;
|
|
|
|
if (size < needed) {
|
|
|
|
mBuffers.insertAt(size, needed-size);
|
|
|
|
}
|
2010-04-09 01:34:07 +00:00
|
|
|
|
2010-05-22 00:24:35 +00:00
|
|
|
uint32_t w, h, format, usage;
|
|
|
|
if (needNewBuffer(bufIdx, &w, &h, &format, &usage)) {
|
|
|
|
err = getBufferLocked(bufIdx, w, h, format, usage);
|
|
|
|
LOGE_IF(err, "getBufferLocked(%ld, %u, %u, %u, %08x) failed (%s)",
|
|
|
|
bufIdx, w, h, format, usage, strerror(-err));
|
2009-08-20 00:10:18 +00:00
|
|
|
if (err == NO_ERROR) {
|
|
|
|
// reset the width/height with the what we get from the buffer
|
2010-05-22 00:24:35 +00:00
|
|
|
const sp<GraphicBuffer>& backBuffer(mBuffers[bufIdx]);
|
2009-08-20 00:10:18 +00:00
|
|
|
mWidth = uint32_t(backBuffer->width);
|
|
|
|
mHeight = uint32_t(backBuffer->height);
|
|
|
|
}
|
2009-04-10 21:24:30 +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
|
|
|
// if we still don't have a buffer here, we probably ran out of memory
|
2010-05-22 00:24:35 +00:00
|
|
|
const sp<GraphicBuffer>& backBuffer(mBuffers[bufIdx]);
|
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
|
|
|
if (!err && backBuffer==0) {
|
|
|
|
err = NO_MEMORY;
|
|
|
|
}
|
|
|
|
|
2009-07-31 21:47:00 +00:00
|
|
|
if (err == NO_ERROR) {
|
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
|
|
|
mDirtyRegion.set(backBuffer->width, backBuffer->height);
|
|
|
|
*buffer = backBuffer.get();
|
|
|
|
} else {
|
|
|
|
mSharedBufferClient->undoDequeue(bufIdx);
|
2009-07-31 21:47:00 +00:00
|
|
|
}
|
2009-08-20 00:10:18 +00:00
|
|
|
|
2009-07-31 21:47:00 +00:00
|
|
|
return err;
|
2009-04-10 21:24:30 +00:00
|
|
|
}
|
|
|
|
|
2010-10-01 23:22:41 +00:00
|
|
|
int Surface::cancelBuffer(android_native_buffer_t* buffer)
|
|
|
|
{
|
2011-01-14 19:04:34 +00:00
|
|
|
status_t err = validate(true);
|
2010-10-01 23:22:41 +00:00
|
|
|
switch (err) {
|
|
|
|
case NO_ERROR:
|
|
|
|
// no error, common case
|
|
|
|
break;
|
2011-01-14 19:04:34 +00:00
|
|
|
case BAD_INDEX:
|
2010-10-01 23:22:41 +00:00
|
|
|
// legitimate errors here
|
|
|
|
return err;
|
|
|
|
default:
|
|
|
|
// other errors happen because the surface is now invalid,
|
|
|
|
// for instance because it has been destroyed. In this case,
|
|
|
|
// we just fail silently (canceling a buffer is not technically
|
|
|
|
// an error at this point)
|
|
|
|
return NO_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t bufIdx = getBufferIndex(GraphicBuffer::getSelf(buffer));
|
|
|
|
|
|
|
|
err = mSharedBufferClient->cancel(bufIdx);
|
|
|
|
|
|
|
|
LOGE_IF(err, "error canceling buffer %d (%s)", bufIdx, strerror(-err));
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-04-10 21:24:30 +00:00
|
|
|
int Surface::lockBuffer(android_native_buffer_t* buffer)
|
|
|
|
{
|
2009-11-13 23:26:29 +00:00
|
|
|
status_t err = validate();
|
2009-04-15 01:21:47 +00:00
|
|
|
if (err != NO_ERROR)
|
|
|
|
return err;
|
|
|
|
|
2010-04-27 23:41:19 +00:00
|
|
|
int32_t bufIdx = getBufferIndex(GraphicBuffer::getSelf(buffer));
|
2010-09-14 05:57:58 +00:00
|
|
|
|
|
|
|
GraphicLog& logger(GraphicLog::getInstance());
|
|
|
|
logger.log(GraphicLog::SF_APP_LOCK_BEFORE, mIdentity, bufIdx);
|
|
|
|
|
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
|
|
|
err = mSharedBufferClient->lock(bufIdx);
|
2010-09-14 05:57:58 +00:00
|
|
|
|
|
|
|
logger.log(GraphicLog::SF_APP_LOCK_AFTER, mIdentity, bufIdx);
|
|
|
|
|
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
|
|
|
LOGE_IF(err, "error locking buffer %d (%s)", bufIdx, strerror(-err));
|
|
|
|
return err;
|
2009-03-04 03:31:44 +00:00
|
|
|
}
|
|
|
|
|
2009-04-10 21:24:30 +00:00
|
|
|
int Surface::queueBuffer(android_native_buffer_t* buffer)
|
2010-09-14 05:57:58 +00:00
|
|
|
{
|
2009-11-13 23:26:29 +00:00
|
|
|
status_t err = validate();
|
2009-04-10 21:24:30 +00:00
|
|
|
if (err != NO_ERROR)
|
|
|
|
return err;
|
|
|
|
|
2009-05-04 21:17:04 +00:00
|
|
|
if (mSwapRectangle.isValid()) {
|
|
|
|
mDirtyRegion.set(mSwapRectangle);
|
|
|
|
}
|
|
|
|
|
2010-04-27 23:41:19 +00:00
|
|
|
int32_t bufIdx = getBufferIndex(GraphicBuffer::getSelf(buffer));
|
2010-09-14 05:57:58 +00:00
|
|
|
|
|
|
|
GraphicLog::getInstance().log(GraphicLog::SF_APP_QUEUE, mIdentity, bufIdx);
|
|
|
|
|
2010-08-20 00:01:19 +00:00
|
|
|
mSharedBufferClient->setTransform(bufIdx, mNextBufferTransform);
|
2010-04-16 01:48:26 +00:00
|
|
|
mSharedBufferClient->setCrop(bufIdx, mNextBufferCrop);
|
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
|
|
|
mSharedBufferClient->setDirtyRegion(bufIdx, mDirtyRegion);
|
|
|
|
err = mSharedBufferClient->queue(bufIdx);
|
|
|
|
LOGE_IF(err, "error queuing buffer %d (%s)", bufIdx, strerror(-err));
|
2009-04-10 21:24:30 +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
|
|
|
if (err == NO_ERROR) {
|
2010-06-01 22:12:58 +00:00
|
|
|
// TODO: can we avoid this IPC if we know there is one pending?
|
|
|
|
mClient.signalServer();
|
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 err;
|
2009-04-10 21:24:30 +00:00
|
|
|
}
|
|
|
|
|
2009-07-31 01:14:56 +00:00
|
|
|
int Surface::query(int what, int* value)
|
|
|
|
{
|
|
|
|
switch (what) {
|
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
|
|
|
case NATIVE_WINDOW_WIDTH:
|
|
|
|
*value = int(mWidth);
|
|
|
|
return NO_ERROR;
|
|
|
|
case NATIVE_WINDOW_HEIGHT:
|
|
|
|
*value = int(mHeight);
|
|
|
|
return NO_ERROR;
|
|
|
|
case NATIVE_WINDOW_FORMAT:
|
|
|
|
*value = int(mFormat);
|
|
|
|
return NO_ERROR;
|
2009-07-31 01:14:56 +00:00
|
|
|
}
|
|
|
|
return BAD_VALUE;
|
|
|
|
}
|
|
|
|
|
2009-08-12 05:34:02 +00:00
|
|
|
int Surface::perform(int operation, va_list args)
|
|
|
|
{
|
2010-04-16 01:48:26 +00:00
|
|
|
status_t err = validate();
|
|
|
|
if (err != NO_ERROR)
|
|
|
|
return err;
|
|
|
|
|
2009-08-12 05:34:02 +00:00
|
|
|
int res = NO_ERROR;
|
|
|
|
switch (operation) {
|
2010-03-11 23:06:54 +00:00
|
|
|
case NATIVE_WINDOW_SET_USAGE:
|
|
|
|
dispatch_setUsage( args );
|
|
|
|
break;
|
|
|
|
case NATIVE_WINDOW_CONNECT:
|
|
|
|
res = dispatch_connect( args );
|
|
|
|
break;
|
|
|
|
case NATIVE_WINDOW_DISCONNECT:
|
|
|
|
res = dispatch_disconnect( args );
|
|
|
|
break;
|
2010-04-16 01:48:26 +00:00
|
|
|
case NATIVE_WINDOW_SET_CROP:
|
|
|
|
res = dispatch_crop( args );
|
|
|
|
break;
|
2010-05-21 21:19:50 +00:00
|
|
|
case NATIVE_WINDOW_SET_BUFFER_COUNT:
|
|
|
|
res = dispatch_set_buffer_count( args );
|
|
|
|
break;
|
2010-05-27 04:31:09 +00:00
|
|
|
case NATIVE_WINDOW_SET_BUFFERS_GEOMETRY:
|
|
|
|
res = dispatch_set_buffers_geometry( args );
|
|
|
|
break;
|
2010-08-20 00:01:19 +00:00
|
|
|
case NATIVE_WINDOW_SET_BUFFERS_TRANSFORM:
|
|
|
|
res = dispatch_set_buffers_transform( args );
|
|
|
|
break;
|
2010-03-11 23:06:54 +00:00
|
|
|
default:
|
|
|
|
res = NAME_NOT_FOUND;
|
|
|
|
break;
|
2009-08-12 05:34:02 +00:00
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2010-03-11 23:06:54 +00:00
|
|
|
void Surface::dispatch_setUsage(va_list args) {
|
|
|
|
int usage = va_arg(args, int);
|
|
|
|
setUsage( usage );
|
|
|
|
}
|
|
|
|
int Surface::dispatch_connect(va_list args) {
|
|
|
|
int api = va_arg(args, int);
|
|
|
|
return connect( api );
|
|
|
|
}
|
|
|
|
int Surface::dispatch_disconnect(va_list args) {
|
|
|
|
int api = va_arg(args, int);
|
|
|
|
return disconnect( api );
|
|
|
|
}
|
2010-04-16 01:48:26 +00:00
|
|
|
int Surface::dispatch_crop(va_list args) {
|
|
|
|
android_native_rect_t const* rect = va_arg(args, android_native_rect_t*);
|
|
|
|
return crop( reinterpret_cast<Rect const*>(rect) );
|
|
|
|
}
|
2010-05-21 21:19:50 +00:00
|
|
|
int Surface::dispatch_set_buffer_count(va_list args) {
|
|
|
|
size_t bufferCount = va_arg(args, size_t);
|
|
|
|
return setBufferCount(bufferCount);
|
|
|
|
}
|
2010-05-22 00:24:35 +00:00
|
|
|
int Surface::dispatch_set_buffers_geometry(va_list args) {
|
|
|
|
int w = va_arg(args, int);
|
|
|
|
int h = va_arg(args, int);
|
|
|
|
int f = va_arg(args, int);
|
|
|
|
return setBuffersGeometry(w, h, f);
|
|
|
|
}
|
2010-03-11 23:06:54 +00:00
|
|
|
|
2010-08-20 00:01:19 +00:00
|
|
|
int Surface::dispatch_set_buffers_transform(va_list args) {
|
|
|
|
int transform = va_arg(args, int);
|
|
|
|
return setBuffersTransform(transform);
|
|
|
|
}
|
|
|
|
|
2009-08-15 01:52:17 +00:00
|
|
|
void Surface::setUsage(uint32_t reqUsage)
|
|
|
|
{
|
|
|
|
Mutex::Autolock _l(mSurfaceLock);
|
2010-05-22 00:24:35 +00:00
|
|
|
mBufferInfo.set(reqUsage);
|
2009-08-15 01:52:17 +00:00
|
|
|
}
|
|
|
|
|
2010-03-11 23:06:54 +00:00
|
|
|
int Surface::connect(int api)
|
|
|
|
{
|
|
|
|
Mutex::Autolock _l(mSurfaceLock);
|
|
|
|
int err = NO_ERROR;
|
|
|
|
switch (api) {
|
|
|
|
case NATIVE_WINDOW_API_EGL:
|
|
|
|
if (mConnected) {
|
|
|
|
err = -EINVAL;
|
|
|
|
} else {
|
|
|
|
mConnected = api;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
err = -EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
int Surface::disconnect(int api)
|
|
|
|
{
|
|
|
|
Mutex::Autolock _l(mSurfaceLock);
|
|
|
|
int err = NO_ERROR;
|
|
|
|
switch (api) {
|
|
|
|
case NATIVE_WINDOW_API_EGL:
|
|
|
|
if (mConnected == api) {
|
|
|
|
mConnected = 0;
|
|
|
|
} else {
|
|
|
|
err = -EINVAL;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
err = -EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2010-04-16 01:48:26 +00:00
|
|
|
int Surface::crop(Rect const* rect)
|
|
|
|
{
|
|
|
|
Mutex::Autolock _l(mSurfaceLock);
|
|
|
|
// TODO: validate rect size
|
2011-01-29 02:21:54 +00:00
|
|
|
|
|
|
|
if (rect == NULL || rect->isEmpty()) {
|
|
|
|
mNextBufferCrop = Rect(0,0);
|
|
|
|
} else {
|
|
|
|
mNextBufferCrop = *rect;
|
|
|
|
}
|
|
|
|
|
2010-04-16 01:48:26 +00:00
|
|
|
return NO_ERROR;
|
|
|
|
}
|
|
|
|
|
2010-05-07 22:58:44 +00:00
|
|
|
int Surface::setBufferCount(int bufferCount)
|
|
|
|
{
|
|
|
|
sp<ISurface> s(mSurface);
|
|
|
|
if (s == 0) return NO_INIT;
|
|
|
|
|
2010-05-19 00:06:55 +00:00
|
|
|
class SetBufferCountIPC : public SharedBufferClient::SetBufferCountCallback {
|
|
|
|
sp<ISurface> surface;
|
|
|
|
virtual status_t operator()(int bufferCount) const {
|
|
|
|
return surface->setBufferCount(bufferCount);
|
|
|
|
}
|
|
|
|
public:
|
|
|
|
SetBufferCountIPC(const sp<ISurface>& surface) : surface(surface) { }
|
|
|
|
} ipc(s);
|
2010-05-07 22:58:44 +00:00
|
|
|
|
2010-05-19 00:06:55 +00:00
|
|
|
status_t err = mSharedBufferClient->setBufferCount(bufferCount, ipc);
|
2010-05-07 22:58:44 +00:00
|
|
|
LOGE_IF(err, "ISurface::setBufferCount(%d) returned %s",
|
|
|
|
bufferCount, strerror(-err));
|
2010-11-02 18:51:32 +00:00
|
|
|
|
|
|
|
if (err == NO_ERROR) {
|
|
|
|
// Clear out any references to the old buffers.
|
|
|
|
mBuffers.clear();
|
|
|
|
}
|
|
|
|
|
2010-05-07 22:58:44 +00:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2010-05-22 00:24:35 +00:00
|
|
|
int Surface::setBuffersGeometry(int w, int h, int format)
|
|
|
|
{
|
|
|
|
if (w<0 || h<0 || format<0)
|
|
|
|
return BAD_VALUE;
|
|
|
|
|
|
|
|
if ((w && !h) || (!w && h))
|
|
|
|
return BAD_VALUE;
|
|
|
|
|
|
|
|
Mutex::Autolock _l(mSurfaceLock);
|
2010-10-25 23:29:24 +00:00
|
|
|
if (mConnected == NATIVE_WINDOW_API_EGL) {
|
|
|
|
return INVALID_OPERATION;
|
|
|
|
}
|
|
|
|
|
2010-05-22 00:24:35 +00:00
|
|
|
mBufferInfo.set(w, h, format);
|
2010-10-25 23:29:24 +00:00
|
|
|
if (format != 0) {
|
|
|
|
// we update the format of the surface as reported by query().
|
|
|
|
// this is to allow applications to change the format of a surface's
|
|
|
|
// buffer, and have it reflected in EGL; which is needed for
|
|
|
|
// EGLConfig validation.
|
|
|
|
mFormat = format;
|
|
|
|
}
|
2011-01-29 02:21:54 +00:00
|
|
|
|
|
|
|
mNextBufferCrop = Rect(0,0);
|
|
|
|
|
2010-05-22 00:24:35 +00:00
|
|
|
return NO_ERROR;
|
|
|
|
}
|
|
|
|
|
2010-08-20 00:01:19 +00:00
|
|
|
int Surface::setBuffersTransform(int transform)
|
|
|
|
{
|
|
|
|
Mutex::Autolock _l(mSurfaceLock);
|
|
|
|
mNextBufferTransform = transform;
|
|
|
|
return NO_ERROR;
|
|
|
|
}
|
|
|
|
|
2010-05-22 00:24:35 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
int Surface::getConnectedApi() const
|
|
|
|
{
|
|
|
|
Mutex::Autolock _l(mSurfaceLock);
|
|
|
|
return mConnected;
|
|
|
|
}
|
2010-03-11 23:06:54 +00:00
|
|
|
|
2009-04-10 21:24:30 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2009-03-04 03:31:44 +00:00
|
|
|
status_t Surface::lock(SurfaceInfo* info, bool blocking) {
|
|
|
|
return Surface::lock(info, NULL, blocking);
|
|
|
|
}
|
|
|
|
|
2009-05-04 21:17:04 +00:00
|
|
|
status_t Surface::lock(SurfaceInfo* other, Region* dirtyIn, bool blocking)
|
2009-04-10 21:24:30 +00:00
|
|
|
{
|
2010-03-11 23:06:54 +00:00
|
|
|
if (getConnectedApi()) {
|
|
|
|
LOGE("Surface::lock(%p) failed. Already connected to another API",
|
2010-06-30 20:56:17 +00:00
|
|
|
(ANativeWindow*)this);
|
2010-03-11 23:06:54 +00:00
|
|
|
CallStack stack;
|
|
|
|
stack.update();
|
|
|
|
stack.dump("");
|
|
|
|
return INVALID_OPERATION;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
if (mApiLock.tryLock() != NO_ERROR) {
|
2010-01-22 19:47:55 +00:00
|
|
|
LOGE("calling Surface::lock from different threads!");
|
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
|
|
|
CallStack stack;
|
|
|
|
stack.update();
|
2010-03-11 23:06:54 +00:00
|
|
|
stack.dump("");
|
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 WOULD_BLOCK;
|
|
|
|
}
|
2010-01-22 19:47:55 +00:00
|
|
|
|
|
|
|
/* Here we're holding mApiLock */
|
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
|
|
|
if (mLockedBuffer != 0) {
|
|
|
|
LOGE("Surface::lock failed, already locked");
|
|
|
|
mApiLock.unlock();
|
|
|
|
return INVALID_OPERATION;
|
|
|
|
}
|
|
|
|
|
2009-08-12 05:34:02 +00:00
|
|
|
// we're intending to do software rendering from this point
|
2009-08-15 01:52:17 +00:00
|
|
|
setUsage(GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN);
|
|
|
|
|
2010-04-27 23:41:19 +00:00
|
|
|
android_native_buffer_t* out;
|
|
|
|
status_t err = dequeueBuffer(&out);
|
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
|
|
|
LOGE_IF(err, "dequeueBuffer failed (%s)", strerror(-err));
|
2009-04-10 21:24:30 +00:00
|
|
|
if (err == NO_ERROR) {
|
2010-04-27 23:41:19 +00:00
|
|
|
sp<GraphicBuffer> backBuffer(GraphicBuffer::getSelf(out));
|
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
|
|
|
err = lockBuffer(backBuffer.get());
|
|
|
|
LOGE_IF(err, "lockBuffer (idx=%d) failed (%s)",
|
2010-04-27 23:41:19 +00:00
|
|
|
getBufferIndex(backBuffer), strerror(-err));
|
2009-04-10 21:24:30 +00:00
|
|
|
if (err == NO_ERROR) {
|
|
|
|
const Rect bounds(backBuffer->width, backBuffer->height);
|
2010-04-21 22:24:11 +00:00
|
|
|
const Region boundsRegion(bounds);
|
|
|
|
Region scratch(boundsRegion);
|
2009-05-04 21:17:04 +00:00
|
|
|
Region& newDirtyRegion(dirtyIn ? *dirtyIn : scratch);
|
2010-04-21 22:24:11 +00:00
|
|
|
newDirtyRegion &= boundsRegion;
|
2009-04-10 21:24:30 +00:00
|
|
|
|
2010-04-21 22:24:11 +00:00
|
|
|
// figure out if we can copy the frontbuffer back
|
2009-10-06 00:07:12 +00:00
|
|
|
const sp<GraphicBuffer>& frontBuffer(mPostedBuffer);
|
2010-04-21 22:24:11 +00:00
|
|
|
const bool canCopyBack = (frontBuffer != 0 &&
|
|
|
|
backBuffer->width == frontBuffer->width &&
|
|
|
|
backBuffer->height == frontBuffer->height &&
|
|
|
|
backBuffer->format == frontBuffer->format &&
|
|
|
|
!(mFlags & ISurfaceComposer::eDestroyBackbuffer));
|
|
|
|
|
|
|
|
// the dirty region we report to surfaceflinger is the one
|
|
|
|
// given by the user (as opposed to the one *we* return to the
|
|
|
|
// user).
|
|
|
|
mDirtyRegion = newDirtyRegion;
|
|
|
|
|
|
|
|
if (canCopyBack) {
|
|
|
|
// copy the area that is invalid and not repainted this round
|
|
|
|
const Region copyback(mOldDirtyRegion.subtract(newDirtyRegion));
|
|
|
|
if (!copyback.isEmpty())
|
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
|
|
|
copyBlt(backBuffer, frontBuffer, copyback);
|
2010-04-21 22:24:11 +00:00
|
|
|
} else {
|
|
|
|
// if we can't copy-back anything, modify the user's dirty
|
|
|
|
// region to make sure they redraw the whole buffer
|
|
|
|
newDirtyRegion = boundsRegion;
|
2009-04-10 21:24:30 +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
|
|
|
|
2010-04-21 22:24:11 +00:00
|
|
|
// keep track of the are of the buffer that is "clean"
|
|
|
|
// (ie: that will be redrawn)
|
2009-05-04 21:17:04 +00:00
|
|
|
mOldDirtyRegion = newDirtyRegion;
|
2009-04-10 21:24:30 +00:00
|
|
|
|
2009-05-05 07:37:46 +00:00
|
|
|
void* vaddr;
|
2009-05-04 21:17:04 +00:00
|
|
|
status_t res = backBuffer->lock(
|
|
|
|
GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN,
|
2009-05-05 07:37:46 +00:00
|
|
|
newDirtyRegion.bounds(), &vaddr);
|
2009-05-04 21:17:04 +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
|
|
|
LOGW_IF(res, "failed locking buffer (handle = %p)",
|
|
|
|
backBuffer->handle);
|
2009-05-04 21:17:04 +00:00
|
|
|
|
|
|
|
mLockedBuffer = backBuffer;
|
|
|
|
other->w = backBuffer->width;
|
|
|
|
other->h = backBuffer->height;
|
|
|
|
other->s = backBuffer->stride;
|
|
|
|
other->usage = backBuffer->usage;
|
|
|
|
other->format = backBuffer->format;
|
2009-05-05 07:37:46 +00:00
|
|
|
other->bits = vaddr;
|
2009-04-10 21:24:30 +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
|
|
|
mApiLock.unlock();
|
2009-04-10 21:24:30 +00:00
|
|
|
return err;
|
2009-03-04 03:31:44 +00:00
|
|
|
}
|
2009-04-10 21:24:30 +00:00
|
|
|
|
|
|
|
status_t Surface::unlockAndPost()
|
|
|
|
{
|
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
|
|
|
if (mLockedBuffer == 0) {
|
2010-01-22 19:47:55 +00:00
|
|
|
LOGE("Surface::unlockAndPost failed, no locked buffer");
|
|
|
|
return INVALID_OPERATION;
|
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
|
|
|
}
|
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
|
|
|
status_t err = mLockedBuffer->unlock();
|
|
|
|
LOGE_IF(err, "failed unlocking buffer (%p)", mLockedBuffer->handle);
|
2009-05-04 21:17:04 +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
|
|
|
err = queueBuffer(mLockedBuffer.get());
|
|
|
|
LOGE_IF(err, "queueBuffer (idx=%d) failed (%s)",
|
2010-04-27 23:41:19 +00:00
|
|
|
getBufferIndex(mLockedBuffer), strerror(-err));
|
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
|
|
|
|
|
|
|
mPostedBuffer = mLockedBuffer;
|
2009-04-10 21:24:30 +00:00
|
|
|
mLockedBuffer = 0;
|
|
|
|
return err;
|
2009-03-04 03:31:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Surface::setSwapRectangle(const Rect& r) {
|
2009-08-15 01:52:17 +00:00
|
|
|
Mutex::Autolock _l(mSurfaceLock);
|
2009-03-04 03:31:44 +00:00
|
|
|
mSwapRectangle = r;
|
|
|
|
}
|
|
|
|
|
2010-04-27 23:41:19 +00:00
|
|
|
int Surface::getBufferIndex(const sp<GraphicBuffer>& buffer) const
|
|
|
|
{
|
2010-10-07 20:46:55 +00:00
|
|
|
int idx = buffer->getIndex();
|
|
|
|
if (idx < 0) {
|
|
|
|
// The buffer doesn't have an index set. See if the handle the same as
|
|
|
|
// one of the buffers for which we do know the index. This can happen
|
|
|
|
// e.g. if GraphicBuffer is used to wrap an android_native_buffer_t that
|
|
|
|
// was dequeued from an ANativeWindow.
|
2010-11-10 02:01:27 +00:00
|
|
|
for (size_t i = 0; i < mBuffers.size(); i++) {
|
2011-02-28 02:40:09 +00:00
|
|
|
if (mBuffers[i] != 0 && buffer->handle == mBuffers[i]->handle) {
|
2010-10-07 20:46:55 +00:00
|
|
|
idx = mBuffers[i]->getIndex();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return idx;
|
2010-04-27 23:41:19 +00:00
|
|
|
}
|
|
|
|
|
2010-05-22 00:24:35 +00:00
|
|
|
status_t Surface::getBufferLocked(int index,
|
|
|
|
uint32_t w, uint32_t h, uint32_t format, uint32_t usage)
|
2009-03-04 03:31:44 +00:00
|
|
|
{
|
2009-08-15 01:52:17 +00:00
|
|
|
sp<ISurface> s(mSurface);
|
|
|
|
if (s == 0) return NO_INIT;
|
|
|
|
|
2009-04-10 21:24:30 +00:00
|
|
|
status_t err = NO_MEMORY;
|
2009-08-20 00:10:18 +00:00
|
|
|
|
|
|
|
// free the current buffer
|
2010-05-22 00:24:35 +00:00
|
|
|
sp<GraphicBuffer>& currentBuffer(mBuffers.editItemAt(index));
|
2009-08-20 00:10:18 +00:00
|
|
|
if (currentBuffer != 0) {
|
|
|
|
currentBuffer.clear();
|
|
|
|
}
|
|
|
|
|
2010-05-22 00:24:35 +00:00
|
|
|
sp<GraphicBuffer> buffer = s->requestBuffer(index, w, h, format, usage);
|
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
|
|
|
LOGE_IF(buffer==0,
|
|
|
|
"ISurface::getBuffer(%d, %08x) returned NULL",
|
|
|
|
index, usage);
|
2010-10-07 20:46:55 +00:00
|
|
|
if (buffer != 0) { // this should always happen by construction
|
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
|
|
|
LOGE_IF(buffer->handle == NULL,
|
2010-05-22 00:24:35 +00:00
|
|
|
"Surface (identity=%d) requestBuffer(%d, %u, %u, %u, %08x) "
|
|
|
|
"returned a buffer with a null handle",
|
|
|
|
mIdentity, index, w, h, format, usage);
|
2009-10-03 01:12:30 +00:00
|
|
|
err = mSharedBufferClient->getStatus();
|
|
|
|
LOGE_IF(err, "Surface (identity=%d) state = %d", mIdentity, err);
|
|
|
|
if (!err && buffer->handle != NULL) {
|
2010-10-07 20:46:55 +00:00
|
|
|
currentBuffer = buffer;
|
|
|
|
currentBuffer->setIndex(index);
|
2009-10-06 22:58:44 +00:00
|
|
|
} else {
|
2010-05-21 21:19:50 +00:00
|
|
|
err = err<0 ? err : status_t(NO_MEMORY);
|
2009-03-04 03:31:44 +00:00
|
|
|
}
|
|
|
|
}
|
2009-04-10 21:24:30 +00:00
|
|
|
return err;
|
2009-03-04 03:31:44 +00:00
|
|
|
}
|
|
|
|
|
2010-05-22 00:24:35 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
Surface::BufferInfo::BufferInfo()
|
|
|
|
: mWidth(0), mHeight(0), mFormat(0),
|
|
|
|
mUsage(GRALLOC_USAGE_HW_RENDER), mDirty(0)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void Surface::BufferInfo::set(uint32_t w, uint32_t h, uint32_t format) {
|
|
|
|
if ((mWidth != w) || (mHeight != h) || (mFormat != format)) {
|
|
|
|
mWidth = w;
|
|
|
|
mHeight = h;
|
|
|
|
mFormat = format;
|
|
|
|
mDirty |= GEOMETRY;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Surface::BufferInfo::set(uint32_t usage) {
|
|
|
|
mUsage = usage;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Surface::BufferInfo::get(uint32_t *pWidth, uint32_t *pHeight,
|
|
|
|
uint32_t *pFormat, uint32_t *pUsage) const {
|
|
|
|
*pWidth = mWidth;
|
|
|
|
*pHeight = mHeight;
|
|
|
|
*pFormat = mFormat;
|
|
|
|
*pUsage = mUsage;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Surface::BufferInfo::validateBuffer(const sp<GraphicBuffer>& buffer) const {
|
|
|
|
// make sure we AT LEAST have the usage flags we want
|
|
|
|
if (mDirty || buffer==0 ||
|
|
|
|
((buffer->usage & mUsage) != mUsage)) {
|
|
|
|
mDirty = 0;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2009-03-04 03:31:44 +00:00
|
|
|
}; // namespace android
|