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>
|
|
|
|
|
2012-03-23 21:15:44 +00:00
|
|
|
#include <android/native_window.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
|
|
|
|
2011-04-20 21:20:59 +00:00
|
|
|
#include <binder/IPCThreadState.h>
|
|
|
|
|
2009-04-10 21:24:30 +00:00
|
|
|
#include <ui/DisplayInfo.h>
|
2009-10-06 00:07:12 +00:00
|
|
|
#include <ui/GraphicBuffer.h>
|
2009-03-04 03:31:44 +00:00
|
|
|
#include <ui/Rect.h>
|
|
|
|
|
2012-02-26 02:48:35 +00:00
|
|
|
#include <gui/ISurface.h>
|
|
|
|
#include <gui/ISurfaceComposer.h>
|
|
|
|
#include <gui/Surface.h>
|
|
|
|
#include <gui/SurfaceComposerClient.h>
|
|
|
|
#include <gui/SurfaceTextureClient.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,
|
2011-07-20 23:46:11 +00:00
|
|
|
const ISurfaceComposerClient::surface_data_t& data)
|
2009-04-16 23:19:50 +00:00
|
|
|
: mClient(client), mSurface(surface),
|
2011-07-20 23:46:11 +00:00
|
|
|
mToken(data.token), mIdentity(data.identity)
|
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::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);
|
|
|
|
}
|
2012-05-11 03:43:55 +00:00
|
|
|
status_t SurfaceControl::setCrop(const Rect& crop) {
|
|
|
|
status_t err = validate();
|
|
|
|
if (err < 0) return err;
|
|
|
|
const sp<SurfaceComposerClient>& client(mClient);
|
|
|
|
return client->setCrop(mToken, crop);
|
|
|
|
}
|
2009-04-16 23:19:50 +00:00
|
|
|
|
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) {
|
2012-01-06 19:20:56 +00:00
|
|
|
ALOGE("invalid token (%d, identity=%u) or client (%p)",
|
2009-04-16 23:19:50 +00:00
|
|
|
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;
|
|
|
|
if (SurfaceControl::isValid(control)) {
|
|
|
|
sur = control->mSurface;
|
2010-06-09 02:54:15 +00:00
|
|
|
identity = control->mIdentity;
|
2009-04-17 03:04:08 +00:00
|
|
|
}
|
2010-06-01 22:12:58 +00:00
|
|
|
parcel->writeStrongBinder(sur!=0 ? sur->asBinder() : NULL);
|
2011-07-15 22:10:10 +00:00
|
|
|
parcel->writeStrongBinder(NULL); // NULL ISurfaceTexture in this case.
|
2009-04-17 03:04:08 +00:00
|
|
|
parcel->writeInt32(identity);
|
|
|
|
return NO_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
sp<Surface> SurfaceControl::getSurface() const
|
|
|
|
{
|
|
|
|
Mutex::Autolock _l(mLock);
|
|
|
|
if (mSurfaceData == 0) {
|
2011-07-15 22:10:10 +00:00
|
|
|
sp<SurfaceControl> surface_control(const_cast<SurfaceControl*>(this));
|
|
|
|
mSurfaceData = new Surface(surface_control);
|
2009-04-17 03:04:08 +00:00
|
|
|
}
|
|
|
|
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(),
|
2010-06-01 22:12:58 +00:00
|
|
|
mSurface(surface->mSurface),
|
2011-07-20 23:46:11 +00:00
|
|
|
mIdentity(surface->mIdentity)
|
2009-03-04 03:31:44 +00:00
|
|
|
{
|
2011-07-15 22:10:10 +00:00
|
|
|
sp<ISurfaceTexture> st;
|
|
|
|
if (mSurface != NULL) {
|
|
|
|
st = mSurface->getSurfaceTexture();
|
|
|
|
}
|
|
|
|
init(st);
|
2009-04-17 03:04:08 +00:00
|
|
|
}
|
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-20 23:46:11 +00:00
|
|
|
: SurfaceTextureClient()
|
2009-04-17 03:04:08 +00:00
|
|
|
{
|
2011-07-15 22:10:10 +00:00
|
|
|
mSurface = interface_cast<ISurface>(ref);
|
|
|
|
sp<IBinder> st_binder(parcel.readStrongBinder());
|
|
|
|
sp<ISurfaceTexture> st;
|
|
|
|
if (st_binder != NULL) {
|
|
|
|
st = interface_cast<ISurfaceTexture>(st_binder);
|
|
|
|
} else if (mSurface != NULL) {
|
|
|
|
st = mSurface->getSurfaceTexture();
|
|
|
|
}
|
|
|
|
|
2009-04-17 03:04:08 +00:00
|
|
|
mIdentity = parcel.readInt32();
|
2011-07-15 22:10:10 +00:00
|
|
|
init(st);
|
|
|
|
}
|
|
|
|
|
|
|
|
Surface::Surface(const sp<ISurfaceTexture>& st)
|
|
|
|
: SurfaceTextureClient(),
|
|
|
|
mSurface(NULL),
|
|
|
|
mIdentity(0)
|
|
|
|
{
|
|
|
|
init(st);
|
2009-04-17 03:04:08 +00:00
|
|
|
}
|
|
|
|
|
2010-06-09 02:54:15 +00:00
|
|
|
status_t Surface::writeToParcel(
|
|
|
|
const sp<Surface>& surface, Parcel* parcel)
|
|
|
|
{
|
|
|
|
sp<ISurface> sur;
|
2011-07-15 22:10:10 +00:00
|
|
|
sp<ISurfaceTexture> st;
|
2010-06-09 02:54:15 +00:00
|
|
|
uint32_t identity = 0;
|
|
|
|
if (Surface::isValid(surface)) {
|
|
|
|
sur = surface->mSurface;
|
2011-07-15 22:10:10 +00:00
|
|
|
st = surface->getISurfaceTexture();
|
2010-06-09 02:54:15 +00:00
|
|
|
identity = surface->mIdentity;
|
2011-07-15 22:10:10 +00:00
|
|
|
} else if (surface != 0 &&
|
|
|
|
(surface->mSurface != NULL ||
|
|
|
|
surface->getISurfaceTexture() != NULL)) {
|
2012-01-06 19:20:56 +00:00
|
|
|
ALOGE("Parceling invalid surface with non-NULL ISurface/ISurfaceTexture as NULL: "
|
2011-07-15 22:10:10 +00:00
|
|
|
"mSurface = %p, surfaceTexture = %p, mIdentity = %d, ",
|
|
|
|
surface->mSurface.get(), surface->getISurfaceTexture().get(),
|
|
|
|
surface->mIdentity);
|
2010-06-09 02:54:15 +00:00
|
|
|
}
|
2011-07-15 22:10:10 +00:00
|
|
|
|
|
|
|
parcel->writeStrongBinder(sur != NULL ? sur->asBinder() : NULL);
|
|
|
|
parcel->writeStrongBinder(st != NULL ? st->asBinder() : NULL);
|
2010-06-09 02:54:15 +00:00
|
|
|
parcel->writeInt32(identity);
|
|
|
|
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);
|
2011-08-10 05:38:41 +00:00
|
|
|
} else {
|
|
|
|
// The Surface was found in the cache, but we still should clear any
|
|
|
|
// remaining data from the parcel.
|
|
|
|
data.readStrongBinder(); // ISurfaceTexture
|
|
|
|
data.readInt32(); // identity
|
2010-07-16 00:29:15 +00:00
|
|
|
}
|
2011-07-15 22:10:10 +00:00
|
|
|
if (surface->mSurface == NULL && surface->getISurfaceTexture() == NULL) {
|
|
|
|
surface = 0;
|
2010-07-16 00:29:15 +00:00
|
|
|
}
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-15 22:10:10 +00:00
|
|
|
void Surface::init(const sp<ISurfaceTexture>& surfaceTexture)
|
2009-04-17 03:04:08 +00:00
|
|
|
{
|
2011-07-15 22:10:10 +00:00
|
|
|
if (mSurface != NULL || surfaceTexture != NULL) {
|
2012-01-06 19:20:56 +00:00
|
|
|
ALOGE_IF(surfaceTexture==0, "got a NULL ISurfaceTexture from ISurface");
|
2011-04-20 21:20:59 +00:00
|
|
|
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;
|
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() {
|
2011-07-20 23:46:11 +00:00
|
|
|
return getISurfaceTexture() != NULL;
|
2009-04-10 21:24:30 +00:00
|
|
|
}
|
|
|
|
|
2011-06-22 22:52:53 +00:00
|
|
|
sp<ISurfaceTexture> Surface::getSurfaceTexture() {
|
2011-07-20 23:46:11 +00:00
|
|
|
return getISurfaceTexture();
|
2011-06-22 22:52:53 +00:00
|
|
|
}
|
|
|
|
|
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-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-08-24 04:09:41 +00:00
|
|
|
status_t Surface::lock(SurfaceInfo* other, Region* inOutDirtyRegion) {
|
2011-07-14 00:39:11 +00:00
|
|
|
ANativeWindow_Buffer outBuffer;
|
2010-03-11 23:06:54 +00:00
|
|
|
|
2011-07-14 00:39:11 +00:00
|
|
|
ARect temp;
|
|
|
|
ARect* inOutDirtyBounds = NULL;
|
2011-08-24 04:09:41 +00:00
|
|
|
if (inOutDirtyRegion) {
|
|
|
|
temp = inOutDirtyRegion->getBounds();
|
2011-07-14 00:39:11 +00:00
|
|
|
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
|
|
|
}
|
2011-08-24 04:09:41 +00:00
|
|
|
|
|
|
|
if (inOutDirtyRegion) {
|
|
|
|
inOutDirtyRegion->set( static_cast<Rect const&>(temp) );
|
|
|
|
}
|
|
|
|
|
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
|