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.
|
|
|
|
*/
|
|
|
|
|
2010-02-10 01:46:37 +00:00
|
|
|
#ifndef ANDROID_SF_SHARED_BUFFER_STACK_H
|
|
|
|
#define ANDROID_SF_SHARED_BUFFER_STACK_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 <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.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
class Region;
|
|
|
|
class SharedBufferStack;
|
|
|
|
class SharedClient;
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
class SharedBufferStack
|
|
|
|
{
|
|
|
|
friend class SharedClient;
|
|
|
|
friend class SharedBufferBase;
|
|
|
|
friend class SharedBufferClient;
|
|
|
|
friend class SharedBufferServer;
|
|
|
|
|
|
|
|
public:
|
2010-05-19 00:06:55 +00:00
|
|
|
// When changing these values, the COMPILE_TIME_ASSERT at the end of this
|
|
|
|
// file need to be updated.
|
|
|
|
static const unsigned int NUM_LAYERS_MAX = 31;
|
|
|
|
static const unsigned int NUM_BUFFER_MAX = 16;
|
2010-05-21 21:19:50 +00:00
|
|
|
static const unsigned int NUM_BUFFER_MIN = 2;
|
2010-05-19 00:06:55 +00:00
|
|
|
static const unsigned int NUM_DISPLAY_MAX = 4;
|
|
|
|
|
2010-04-16 01:48:26 +00:00
|
|
|
struct Statistics { // 4 longs
|
|
|
|
typedef int32_t usecs_t;
|
|
|
|
usecs_t totalTime;
|
|
|
|
usecs_t reserved[3];
|
|
|
|
};
|
|
|
|
|
|
|
|
struct SmallRect {
|
|
|
|
uint16_t l, t, r, b;
|
|
|
|
};
|
|
|
|
|
2010-04-05 23:21:53 +00:00
|
|
|
struct FlatRegion { // 52 bytes = 4 * (1 + 2*N)
|
2010-08-20 00:01:19 +00:00
|
|
|
static const unsigned int NUM_RECT_MAX = 5;
|
2009-09-17 08:35:28 +00:00
|
|
|
uint32_t count;
|
2010-04-16 01:48:26 +00:00
|
|
|
SmallRect rects[NUM_RECT_MAX];
|
2009-09-17 08:35:28 +00:00
|
|
|
};
|
|
|
|
|
2010-04-16 01:48:26 +00:00
|
|
|
struct BufferData {
|
|
|
|
FlatRegion dirtyRegion;
|
|
|
|
SmallRect crop;
|
2010-08-20 00:01:19 +00:00
|
|
|
uint8_t transform;
|
|
|
|
uint8_t reserved[3];
|
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
|
|
|
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);
|
2010-04-16 01:48:26 +00:00
|
|
|
status_t setCrop(int buffer, const Rect& reg);
|
2010-08-20 00:01:19 +00:00
|
|
|
status_t setTransform(int buffer, uint8_t transform);
|
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;
|
2010-08-20 00:01:19 +00:00
|
|
|
Rect getCrop(int buffer) const;
|
|
|
|
uint32_t getTransform(int buffer) 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
|
|
|
|
|
|
|
// 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;
|
2010-04-28 04:08:20 +00:00
|
|
|
volatile int8_t index[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
|
|
|
|
|
|
|
int32_t identity; // surface's identity (const)
|
2010-06-01 22:12:58 +00:00
|
|
|
int32_t token; // surface's token (for debugging)
|
|
|
|
int32_t reserved32[1];
|
2009-09-17 08:35:28 +00:00
|
|
|
Statistics stats;
|
2010-04-05 23:21:53 +00:00
|
|
|
int32_t reserved;
|
2010-08-20 00:01:19 +00:00
|
|
|
BufferData buffers[NUM_BUFFER_MAX]; // 1024 bytes
|
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-05-07 22:58:44 +00:00
|
|
|
// 32 KB 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 SharedClient
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
SharedClient();
|
|
|
|
~SharedClient();
|
|
|
|
status_t validate(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;
|
2010-05-19 00:06:55 +00:00
|
|
|
SharedBufferStack surfaces[ SharedBufferStack::NUM_LAYERS_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 SharedBufferBase
|
|
|
|
{
|
|
|
|
public:
|
2010-05-19 00:06:55 +00:00
|
|
|
SharedBufferBase(SharedClient* sharedClient, int surface,
|
2009-10-07 02:00:57 +00:00
|
|
|
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
|
|
|
~SharedBufferBase();
|
2009-10-03 01:12:30 +00:00
|
|
|
status_t getStatus() const;
|
2010-05-28 21:22:23 +00:00
|
|
|
int32_t getIdentity() 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
|
|
|
String8 dump(char const* prefix) const;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
SharedClient* const mSharedClient;
|
|
|
|
SharedBufferStack* const mSharedStack;
|
2009-10-07 02:00:57 +00:00
|
|
|
const int mIdentity;
|
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
|
|
|
|
|
|
|
friend struct Update;
|
|
|
|
friend struct QueueUpdate;
|
|
|
|
|
|
|
|
struct ConditionBase {
|
|
|
|
SharedBufferStack& stack;
|
|
|
|
inline ConditionBase(SharedBufferBase* sbc)
|
|
|
|
: stack(*sbc->mSharedStack) { }
|
2010-04-27 23:41:19 +00:00
|
|
|
virtual ~ConditionBase() { };
|
|
|
|
virtual bool operator()() const = 0;
|
|
|
|
virtual const char* name() const = 0;
|
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-27 23:41:19 +00:00
|
|
|
status_t waitForCondition(const ConditionBase& condition);
|
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 UpdateBase {
|
|
|
|
SharedBufferStack& stack;
|
|
|
|
inline UpdateBase(SharedBufferBase* sbb)
|
|
|
|
: stack(*sbb->mSharedStack) { }
|
|
|
|
};
|
|
|
|
template <typename T>
|
|
|
|
status_t updateCondition(T update);
|
|
|
|
};
|
|
|
|
|
|
|
|
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:
|
2009-10-07 02:00:57 +00:00
|
|
|
SharedBufferClient(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 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);
|
2010-04-16 01:48:26 +00:00
|
|
|
status_t setCrop(int buffer, const Rect& reg);
|
2010-08-20 00:01:19 +00:00
|
|
|
status_t setTransform(int buffer, uint32_t transform);
|
2010-05-19 00:06:55 +00:00
|
|
|
|
|
|
|
class SetBufferCountCallback {
|
|
|
|
friend class SharedBufferClient;
|
|
|
|
virtual status_t operator()(int bufferCount) const = 0;
|
|
|
|
protected:
|
|
|
|
virtual ~SetBufferCountCallback() { }
|
|
|
|
};
|
|
|
|
status_t setBufferCount(int bufferCount, const SetBufferCountCallback& ipc);
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
struct QueueUpdate : public UpdateBase {
|
|
|
|
inline QueueUpdate(SharedBufferBase* sbb);
|
|
|
|
inline ssize_t operator()();
|
|
|
|
};
|
|
|
|
|
2010-08-27 00:42:27 +00:00
|
|
|
struct DequeueUpdate : public UpdateBase {
|
|
|
|
inline DequeueUpdate(SharedBufferBase* sbb);
|
|
|
|
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 UndoDequeueUpdate : public UpdateBase {
|
|
|
|
inline UndoDequeueUpdate(SharedBufferBase* sbb);
|
|
|
|
inline ssize_t operator()();
|
|
|
|
};
|
|
|
|
|
|
|
|
// --
|
|
|
|
|
|
|
|
struct DequeueCondition : public ConditionBase {
|
|
|
|
inline DequeueCondition(SharedBufferClient* sbc);
|
2010-04-27 23:41:19 +00:00
|
|
|
inline bool operator()() const;
|
|
|
|
inline const char* name() const { return "DequeueCondition"; }
|
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 LockCondition : public ConditionBase {
|
|
|
|
int buf;
|
|
|
|
inline LockCondition(SharedBufferClient* sbc, int buf);
|
2010-04-27 23:41:19 +00:00
|
|
|
inline bool operator()() const;
|
|
|
|
inline const char* name() const { return "LockCondition"; }
|
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-05-19 00:06:55 +00:00
|
|
|
int32_t computeTail() const;
|
|
|
|
|
|
|
|
mutable RWLock mLock;
|
|
|
|
int mNumBuffers;
|
|
|
|
|
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
|
|
|
int32_t tail;
|
2010-04-27 23:11:38 +00:00
|
|
|
int32_t undoDequeueTail;
|
2010-04-28 04:08:20 +00:00
|
|
|
int32_t queued_head;
|
2009-09-17 08:35:28 +00:00
|
|
|
// statistics...
|
2010-05-19 00:06:55 +00:00
|
|
|
nsecs_t mDequeueTime[SharedBufferStack::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
|
|
|
};
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2010-06-09 02:54:15 +00:00
|
|
|
class SharedBufferServer
|
|
|
|
: public SharedBufferBase,
|
|
|
|
public LightRefBase<SharedBufferServer>
|
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
|
|
|
{
|
|
|
|
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);
|
2010-05-22 00:24:35 +00:00
|
|
|
status_t reallocateAll();
|
|
|
|
status_t reallocateAllExcept(int buffer);
|
2009-10-07 23:44:10 +00:00
|
|
|
int32_t getQueuedCount() 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
|
|
|
Region getDirtyRegion(int buffer) const;
|
2010-08-20 00:01:19 +00:00
|
|
|
Rect getCrop(int buffer) const;
|
|
|
|
uint32_t getTransform(int buffer) 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
|
|
|
|
2010-05-07 22:58:44 +00:00
|
|
|
status_t resize(int newNumBuffers);
|
|
|
|
|
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:
|
2010-06-09 02:54:15 +00:00
|
|
|
friend class LightRefBase<SharedBufferServer>;
|
|
|
|
~SharedBufferServer();
|
|
|
|
|
2010-05-07 22:58:44 +00:00
|
|
|
/*
|
|
|
|
* BufferList is basically a fixed-capacity sorted-vector of
|
|
|
|
* unsigned 5-bits ints using a 32-bits int as storage.
|
|
|
|
* it has efficient iterators to find items in the list and not in the list.
|
|
|
|
*/
|
|
|
|
class BufferList {
|
|
|
|
size_t mCapacity;
|
|
|
|
uint32_t mList;
|
|
|
|
public:
|
2010-05-19 00:06:55 +00:00
|
|
|
BufferList(size_t c = SharedBufferStack::NUM_BUFFER_MAX)
|
|
|
|
: mCapacity(c), mList(0) { }
|
2010-05-07 22:58:44 +00:00
|
|
|
status_t add(int value);
|
|
|
|
status_t remove(int value);
|
2010-05-21 21:51:33 +00:00
|
|
|
uint32_t getMask() const { return mList; }
|
2010-05-07 22:58:44 +00:00
|
|
|
|
|
|
|
class const_iterator {
|
|
|
|
friend class BufferList;
|
|
|
|
uint32_t mask, curr;
|
|
|
|
const_iterator(uint32_t mask) :
|
2010-05-18 00:27:26 +00:00
|
|
|
mask(mask), curr(__builtin_clz(mask)) {
|
|
|
|
}
|
2010-05-07 22:58:44 +00:00
|
|
|
public:
|
|
|
|
inline bool operator == (const const_iterator& rhs) const {
|
|
|
|
return mask == rhs.mask;
|
|
|
|
}
|
|
|
|
inline bool operator != (const const_iterator& rhs) const {
|
|
|
|
return mask != rhs.mask;
|
|
|
|
}
|
|
|
|
inline int operator *() const { return curr; }
|
2010-05-18 00:27:26 +00:00
|
|
|
inline const const_iterator& operator ++() {
|
|
|
|
mask &= ~(1<<(31-curr));
|
|
|
|
curr = __builtin_clz(mask);
|
2010-05-07 22:58:44 +00:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
inline const_iterator begin() const {
|
|
|
|
return const_iterator(mList);
|
|
|
|
}
|
|
|
|
inline const_iterator end() const {
|
|
|
|
return const_iterator(0);
|
|
|
|
}
|
|
|
|
inline const_iterator free_begin() const {
|
|
|
|
uint32_t mask = (1 << (32-mCapacity)) - 1;
|
|
|
|
return const_iterator( ~(mList | mask) );
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2010-05-19 00:06:55 +00:00
|
|
|
// this protects mNumBuffers and mBufferList
|
|
|
|
mutable RWLock mLock;
|
|
|
|
int mNumBuffers;
|
2010-05-07 22:58:44 +00:00
|
|
|
BufferList mBufferList;
|
|
|
|
|
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 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 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];
|
2010-05-19 00:06:55 +00:00
|
|
|
display_cblk_t displays[SharedBufferStack::NUM_DISPLAY_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
|
|
|
};
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
2010-04-05 23:21:53 +00:00
|
|
|
COMPILE_TIME_ASSERT(sizeof(SharedClient) <= 32768)
|
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
|
|
|
COMPILE_TIME_ASSERT(sizeof(surface_flinger_cblk_t) <= 4096)
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
}; // namespace android
|
|
|
|
|
2010-02-10 01:46:37 +00:00
|
|
|
#endif /* ANDROID_SF_SHARED_BUFFER_STACK_H */
|