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
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef ANDROID_UI_SHARED_BUFFER_STACK_H
|
|
|
|
#define ANDROID_UI_SHARED_BUFFER_STACK_H
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
|
|
|
#include <cutils/compiler.h>
|
|
|
|
|
|
|
|
#include <utils/Debug.h>
|
|
|
|
#include <utils/threads.h>
|
|
|
|
#include <utils/String8.h>
|
|
|
|
|
|
|
|
#include <ui/Rect.h>
|
|
|
|
|
|
|
|
namespace android {
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
/*
|
|
|
|
* These classes manage a stack of buffers in shared memory.
|
|
|
|
*
|
|
|
|
* SharedClient: represents a client with several stacks
|
|
|
|
* SharedBufferStack: represents a stack of buffers
|
|
|
|
* SharedBufferClient: manipulates the SharedBufferStack from the client side
|
|
|
|
* SharedBufferServer: manipulates the SharedBufferStack from the server side
|
|
|
|
*
|
|
|
|
* Buffers can be dequeued until there are none available, they can be locked
|
|
|
|
* unless they are in use by the server, which is only the case for the last
|
|
|
|
* dequeue-able buffer. When these various conditions are not met, the caller
|
|
|
|
* waits until the condition is met.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* CAVEATS:
|
|
|
|
*
|
|
|
|
* In the current implementation there are several limitations:
|
|
|
|
* - buffers must be locked in the same order they've been dequeued
|
|
|
|
* - buffers must be enqueued in the same order they've been locked
|
|
|
|
* - dequeue() is not reentrant
|
|
|
|
* - no error checks are done on the condition above
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
// When changing these values, the COMPILE_TIME_ASSERT at the end of this
|
|
|
|
// file need to be updated.
|
|
|
|
const unsigned int NUM_LAYERS_MAX = 31;
|
|
|
|
const unsigned int NUM_BUFFER_MAX = 4;
|
|
|
|
const unsigned int NUM_DISPLAY_MAX = 4;
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
class Region;
|
|
|
|
class SharedBufferStack;
|
|
|
|
class SharedClient;
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// should be 128 bytes (32 longs)
|
|
|
|
class SharedBufferStack
|
|
|
|
{
|
|
|
|
friend class SharedClient;
|
|
|
|
friend class SharedBufferBase;
|
|
|
|
friend class SharedBufferClient;
|
|
|
|
friend class SharedBufferServer;
|
|
|
|
|
|
|
|
public:
|
2009-09-17 08:35:28 +00:00
|
|
|
struct FlatRegion { // 12 bytes
|
|
|
|
static const unsigned int NUM_RECT_MAX = 1;
|
|
|
|
uint32_t count;
|
|
|
|
uint16_t rects[4*NUM_RECT_MAX];
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Statistics { // 4 longs
|
|
|
|
typedef int32_t usecs_t;
|
|
|
|
usecs_t totalTime;
|
|
|
|
usecs_t reserved[3];
|
|
|
|
};
|
|
|
|
|
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
|
|
|
SharedBufferStack();
|
2009-09-11 02:41:18 +00:00
|
|
|
void init(int32_t identity);
|
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 setDirtyRegion(int buffer, const Region& reg);
|
|
|
|
Region getDirtyRegion(int buffer) const;
|
|
|
|
|
|
|
|
// these attributes are part of the conditions/updates
|
|
|
|
volatile int32_t head; // server's current front buffer
|
|
|
|
volatile int32_t available; // number of dequeue-able buffers
|
|
|
|
volatile int32_t queued; // number of buffers waiting for post
|
|
|
|
volatile int32_t inUse; // buffer currently in use by SF
|
2009-09-10 23:55:13 +00:00
|
|
|
volatile status_t status; // surface's status code
|
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
|
|
|
|
|
|
|
// not part of the conditions
|
|
|
|
volatile int32_t reallocMask;
|
|
|
|
|
|
|
|
int32_t identity; // surface's identity (const)
|
2009-09-17 08:35:28 +00:00
|
|
|
int32_t reserved32[9];
|
|
|
|
Statistics stats;
|
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
|
|
|
FlatRegion dirtyRegion[NUM_BUFFER_MAX]; // 12*4=48 bytes
|
|
|
|
};
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// 4 KB max
|
|
|
|
class SharedClient
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
SharedClient();
|
|
|
|
~SharedClient();
|
|
|
|
|
|
|
|
status_t validate(size_t token) const;
|
|
|
|
uint32_t getIdentity(size_t token) const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
friend class SharedBufferBase;
|
|
|
|
friend class SharedBufferClient;
|
|
|
|
friend class SharedBufferServer;
|
|
|
|
|
|
|
|
// FIXME: this should be replaced by a lock-less primitive
|
|
|
|
Mutex lock;
|
|
|
|
Condition cv;
|
|
|
|
SharedBufferStack surfaces[ NUM_LAYERS_MAX ];
|
|
|
|
};
|
|
|
|
|
|
|
|
// ============================================================================
|
|
|
|
|
|
|
|
class SharedBufferBase
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
SharedBufferBase(SharedClient* sharedClient, int surface, int num);
|
|
|
|
~SharedBufferBase();
|
|
|
|
uint32_t getIdentity();
|
|
|
|
size_t getFrontBuffer() const;
|
|
|
|
String8 dump(char const* prefix) const;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
SharedClient* const mSharedClient;
|
|
|
|
SharedBufferStack* const mSharedStack;
|
|
|
|
const int mNumBuffers;
|
|
|
|
|
|
|
|
friend struct Update;
|
|
|
|
friend struct QueueUpdate;
|
|
|
|
|
|
|
|
struct ConditionBase {
|
|
|
|
SharedBufferStack& stack;
|
|
|
|
inline ConditionBase(SharedBufferBase* sbc)
|
|
|
|
: stack(*sbc->mSharedStack) { }
|
|
|
|
};
|
|
|
|
|
|
|
|
struct UpdateBase {
|
|
|
|
SharedBufferStack& stack;
|
|
|
|
inline UpdateBase(SharedBufferBase* sbb)
|
|
|
|
: stack(*sbb->mSharedStack) { }
|
|
|
|
};
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
status_t waitForCondition(T condition);
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
status_t updateCondition(T update);
|
|
|
|
};
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
status_t SharedBufferBase::waitForCondition(T condition)
|
|
|
|
{
|
2009-09-10 23:55:13 +00:00
|
|
|
const SharedBufferStack& stack( *mSharedStack );
|
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
|
|
|
SharedClient& client( *mSharedClient );
|
|
|
|
const nsecs_t TIMEOUT = s2ns(1);
|
|
|
|
Mutex::Autolock _l(client.lock);
|
2009-09-10 23:55:13 +00:00
|
|
|
while ((condition()==false) && (stack.status == 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
|
|
|
status_t err = client.cv.waitRelative(client.lock, TIMEOUT);
|
|
|
|
|
|
|
|
// handle errors and timeouts
|
|
|
|
if (CC_UNLIKELY(err != NO_ERROR)) {
|
|
|
|
if (err == TIMED_OUT) {
|
|
|
|
if (condition()) {
|
|
|
|
LOGE("waitForCondition(%s) timed out (identity=%d), "
|
|
|
|
"but condition is true! We recovered but it "
|
|
|
|
"shouldn't happen." ,
|
|
|
|
T::name(), mSharedStack->identity);
|
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
LOGW("waitForCondition(%s) timed out (identity=%d). "
|
|
|
|
"CPU may be pegged. trying again.",
|
|
|
|
T::name(), mSharedStack->identity);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
LOGE("waitForCondition(%s) error (%s) ",
|
|
|
|
T::name(), strerror(-err));
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-09-10 23:55:13 +00:00
|
|
|
return stack.status;
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
status_t SharedBufferBase::updateCondition(T update) {
|
|
|
|
SharedClient& client( *mSharedClient );
|
|
|
|
Mutex::Autolock _l(client.lock);
|
|
|
|
ssize_t result = update();
|
|
|
|
client.cv.broadcast();
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
class SharedBufferClient : public SharedBufferBase
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
SharedBufferClient(SharedClient* sharedClient, int surface, int num);
|
|
|
|
|
|
|
|
ssize_t dequeue();
|
|
|
|
status_t undoDequeue(int buf);
|
|
|
|
|
|
|
|
status_t lock(int buf);
|
|
|
|
status_t queue(int buf);
|
|
|
|
bool needNewBuffer(int buffer) const;
|
|
|
|
status_t setDirtyRegion(int buffer, const Region& reg);
|
2009-09-17 08:35:28 +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
|
|
|
private:
|
|
|
|
friend struct Condition;
|
|
|
|
friend struct DequeueCondition;
|
|
|
|
friend struct LockCondition;
|
2009-09-14 22:48:42 +00:00
|
|
|
|
|
|
|
int32_t computeTail() const;
|
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
|
|
|
|
|
|
|
struct QueueUpdate : public UpdateBase {
|
|
|
|
inline QueueUpdate(SharedBufferBase* sbb);
|
|
|
|
inline ssize_t operator()();
|
|
|
|
};
|
|
|
|
|
|
|
|
struct UndoDequeueUpdate : public UpdateBase {
|
|
|
|
inline UndoDequeueUpdate(SharedBufferBase* sbb);
|
|
|
|
inline ssize_t operator()();
|
|
|
|
};
|
|
|
|
|
|
|
|
// --
|
|
|
|
|
|
|
|
struct DequeueCondition : public ConditionBase {
|
|
|
|
inline DequeueCondition(SharedBufferClient* sbc);
|
|
|
|
inline bool operator()();
|
|
|
|
static inline const char* name() { return "DequeueCondition"; }
|
|
|
|
};
|
|
|
|
|
|
|
|
struct LockCondition : public ConditionBase {
|
|
|
|
int buf;
|
|
|
|
inline LockCondition(SharedBufferClient* sbc, int buf);
|
|
|
|
inline bool operator()();
|
|
|
|
static inline const char* name() { return "LockCondition"; }
|
|
|
|
};
|
|
|
|
|
|
|
|
int32_t tail;
|
2009-09-17 08:35:28 +00:00
|
|
|
// statistics...
|
|
|
|
nsecs_t mDequeueTime[NUM_BUFFER_MAX];
|
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
|
|
|
};
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
class SharedBufferServer : public SharedBufferBase
|
|
|
|
{
|
|
|
|
public:
|
2009-09-11 02:41:18 +00:00
|
|
|
SharedBufferServer(SharedClient* sharedClient, int surface, int num,
|
|
|
|
int32_t identity);
|
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 retireAndLock();
|
|
|
|
status_t unlock(int buffer);
|
2009-09-10 23:55:13 +00:00
|
|
|
void setStatus(status_t status);
|
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 reallocate();
|
|
|
|
status_t assertReallocate(int buffer);
|
2009-09-10 23:55:13 +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
|
|
|
Region getDirtyRegion(int buffer) const;
|
|
|
|
|
2009-09-17 08:35:28 +00:00
|
|
|
SharedBufferStack::Statistics getStats() const;
|
|
|
|
|
|
|
|
|
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
|
|
|
private:
|
|
|
|
struct UnlockUpdate : public UpdateBase {
|
|
|
|
const int lockedBuffer;
|
|
|
|
inline UnlockUpdate(SharedBufferBase* sbb, int lockedBuffer);
|
|
|
|
inline ssize_t operator()();
|
|
|
|
};
|
|
|
|
|
|
|
|
struct RetireUpdate : public UpdateBase {
|
|
|
|
const int numBuffers;
|
|
|
|
inline RetireUpdate(SharedBufferBase* sbb, int numBuffers);
|
|
|
|
inline ssize_t operator()();
|
|
|
|
};
|
|
|
|
|
2009-09-10 23:55:13 +00:00
|
|
|
struct StatusUpdate : public UpdateBase {
|
|
|
|
const status_t status;
|
|
|
|
inline StatusUpdate(SharedBufferBase* sbb, status_t status);
|
|
|
|
inline ssize_t operator()();
|
|
|
|
};
|
|
|
|
|
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
|
|
|
struct ReallocateCondition : public ConditionBase {
|
|
|
|
int buf;
|
|
|
|
inline ReallocateCondition(SharedBufferBase* sbb, int buf);
|
|
|
|
inline bool operator()();
|
|
|
|
static inline const char* name() { return "ReallocateCondition"; }
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
// ===========================================================================
|
|
|
|
|
|
|
|
struct display_cblk_t
|
|
|
|
{
|
|
|
|
uint16_t w;
|
|
|
|
uint16_t h;
|
|
|
|
uint8_t format;
|
|
|
|
uint8_t orientation;
|
|
|
|
uint8_t reserved[2];
|
|
|
|
float fps;
|
|
|
|
float density;
|
|
|
|
float xdpi;
|
|
|
|
float ydpi;
|
|
|
|
uint32_t pad[2];
|
|
|
|
};
|
|
|
|
|
|
|
|
struct surface_flinger_cblk_t // 4KB max
|
|
|
|
{
|
|
|
|
uint8_t connected;
|
|
|
|
uint8_t reserved[3];
|
|
|
|
uint32_t pad[7];
|
|
|
|
display_cblk_t displays[NUM_DISPLAY_MAX];
|
|
|
|
};
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
COMPILE_TIME_ASSERT(sizeof(SharedClient) <= 4096)
|
|
|
|
COMPILE_TIME_ASSERT(sizeof(SharedBufferStack) == 128)
|
|
|
|
COMPILE_TIME_ASSERT(sizeof(surface_flinger_cblk_t) <= 4096)
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
}; // namespace android
|
|
|
|
|
|
|
|
#endif /* ANDROID_UI_SHARED_BUFFER_STACK_H */
|