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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef ANDROID_LAYER_H
|
|
|
|
#define ANDROID_LAYER_H
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
2009-10-06 00:07:12 +00:00
|
|
|
#include <ui/GraphicBuffer.h>
|
2009-03-04 03:31:44 +00:00
|
|
|
#include <ui/PixelFormat.h>
|
|
|
|
#include <pixelflinger/pixelflinger.h>
|
|
|
|
|
2009-04-10 21:24:30 +00:00
|
|
|
#include <EGL/egl.h>
|
|
|
|
#include <EGL/eglext.h>
|
|
|
|
#include <GLES/gl.h>
|
|
|
|
#include <GLES/glext.h>
|
|
|
|
|
2009-03-04 03:31:44 +00:00
|
|
|
#include "LayerBase.h"
|
|
|
|
#include "Transform.h"
|
2010-05-11 03:06:11 +00:00
|
|
|
#include "TextureManager.h"
|
2009-03-04 03:31:44 +00:00
|
|
|
|
|
|
|
namespace android {
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
2010-06-26 01:02:21 +00:00
|
|
|
class FreezeLock;
|
2009-03-04 03:31:44 +00:00
|
|
|
class Client;
|
2010-06-26 01:02:21 +00:00
|
|
|
class GLExtensions;
|
2010-06-01 22:12:58 +00:00
|
|
|
class UserClient;
|
2009-03-04 03:31:44 +00:00
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
class Layer : public LayerBaseClient
|
|
|
|
{
|
2010-05-11 03:06:11 +00:00
|
|
|
public:
|
2010-06-01 22:12:58 +00:00
|
|
|
Layer(SurfaceFlinger* flinger, DisplayID display,
|
|
|
|
const sp<Client>& client);
|
2010-05-11 03:06:11 +00:00
|
|
|
|
2010-06-01 22:12:58 +00:00
|
|
|
virtual ~Layer();
|
2009-03-04 03:31:44 +00:00
|
|
|
|
2010-06-01 22:12:58 +00:00
|
|
|
virtual const char* getTypeId() const { return "Layer"; }
|
2009-03-04 03:31:44 +00:00
|
|
|
|
2010-06-01 22:12:58 +00:00
|
|
|
// the this layer's size and format
|
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 setBuffers(uint32_t w, uint32_t h,
|
|
|
|
PixelFormat format, uint32_t flags=0);
|
2009-03-04 03:31:44 +00:00
|
|
|
|
2010-06-01 22:12:58 +00:00
|
|
|
// associate a UserClient to this Layer
|
|
|
|
status_t setToken(const sp<UserClient>& uc, SharedClient* sc, int32_t idx);
|
|
|
|
int32_t getToken() const;
|
2010-06-09 02:54:15 +00:00
|
|
|
sp<UserClient> getClient() const;
|
2010-06-01 22:12:58 +00:00
|
|
|
|
|
|
|
// Set this Layer's buffers size
|
2010-05-22 00:24:35 +00:00
|
|
|
void setBufferSize(uint32_t w, uint32_t h);
|
|
|
|
bool isFixedSize() const;
|
2009-03-04 03:31:44 +00:00
|
|
|
|
2010-06-01 22:12:58 +00:00
|
|
|
// LayerBase interface
|
2010-08-11 00:14:02 +00:00
|
|
|
virtual void setGeometry(hwc_layer_t* hwcl);
|
|
|
|
virtual void setPerFrameData(hwc_layer_t* hwcl);
|
2010-09-29 20:02:36 +00:00
|
|
|
virtual void drawForSreenShot() const;
|
2009-03-04 03:31:44 +00:00
|
|
|
virtual void onDraw(const Region& clip) const;
|
|
|
|
virtual uint32_t doTransaction(uint32_t transactionFlags);
|
|
|
|
virtual void lockPageFlip(bool& recomputeVisibleRegions);
|
|
|
|
virtual void unlockPageFlip(const Transform& planeTransform, Region& outDirtyRegion);
|
|
|
|
virtual void finishPageFlip();
|
|
|
|
virtual bool needsBlending() const { return mNeedsBlending; }
|
2009-09-24 02:16:27 +00:00
|
|
|
virtual bool needsDithering() const { return mNeedsDithering; }
|
2010-05-27 05:08:52 +00:00
|
|
|
virtual bool needsFiltering() const;
|
2009-03-04 03:31:44 +00:00
|
|
|
virtual bool isSecure() const { return mSecure; }
|
2009-04-10 21:24:30 +00:00
|
|
|
virtual sp<Surface> createSurface() const;
|
2009-04-18 02:36:26 +00:00
|
|
|
virtual status_t ditch();
|
2010-05-11 03:06:11 +00:00
|
|
|
virtual void onRemoved();
|
2010-06-01 22:12:58 +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
|
|
|
// only for debugging
|
2010-06-01 22:12:58 +00:00
|
|
|
inline sp<GraphicBuffer> getBuffer(int i) const {
|
|
|
|
return mBufferManager.getBuffer(i); }
|
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
|
|
|
// only for debugging
|
2010-06-01 22:12:58 +00:00
|
|
|
inline const sp<FreezeLock>& getFreezeLock() const {
|
|
|
|
return mFreezeLock; }
|
2010-04-21 00:55:49 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual void dump(String8& result, char* scratch, size_t size) const;
|
|
|
|
|
2009-03-04 03:31:44 +00:00
|
|
|
private:
|
|
|
|
void reloadTexture(const Region& dirty);
|
2009-10-06 00:07:12 +00:00
|
|
|
uint32_t getEffectiveUsage(uint32_t usage) const;
|
2010-05-22 00:24:35 +00:00
|
|
|
sp<GraphicBuffer> requestBuffer(int bufferIdx,
|
|
|
|
uint32_t w, uint32_t h, uint32_t format, uint32_t usage);
|
2010-05-07 22:58:44 +00:00
|
|
|
status_t setBufferCount(int bufferCount);
|
2009-04-22 22:23:34 +00:00
|
|
|
|
2010-06-01 22:12:58 +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
|
|
|
class SurfaceLayer : public LayerBaseClient::Surface {
|
2009-04-10 21:24:30 +00:00
|
|
|
public:
|
2010-06-03 06:28:45 +00:00
|
|
|
SurfaceLayer(const sp<SurfaceFlinger>& flinger, const sp<Layer>& owner);
|
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
|
|
|
~SurfaceLayer();
|
2009-04-10 21:24:30 +00:00
|
|
|
private:
|
2010-05-22 00:24:35 +00:00
|
|
|
virtual sp<GraphicBuffer> requestBuffer(int bufferIdx,
|
|
|
|
uint32_t w, uint32_t h, uint32_t format, uint32_t usage);
|
2010-05-07 22:58:44 +00:00
|
|
|
virtual status_t setBufferCount(int bufferCount);
|
2009-04-10 21:24:30 +00:00
|
|
|
sp<Layer> getOwner() const {
|
|
|
|
return static_cast<Layer*>(Surface::getOwner().get());
|
|
|
|
}
|
|
|
|
};
|
|
|
|
friend class SurfaceLayer;
|
2010-06-01 22:12:58 +00:00
|
|
|
|
|
|
|
// -----------------------------------------------------------------------
|
|
|
|
|
|
|
|
class ClientRef {
|
|
|
|
ClientRef(const ClientRef& rhs);
|
|
|
|
ClientRef& operator = (const ClientRef& rhs);
|
|
|
|
mutable Mutex mLock;
|
|
|
|
// binder thread, page-flip thread
|
2010-06-09 02:54:15 +00:00
|
|
|
sp<SharedBufferServer> mControlBlock;
|
2010-06-01 22:12:58 +00:00
|
|
|
wp<UserClient> mUserClient;
|
|
|
|
int32_t mToken;
|
|
|
|
public:
|
|
|
|
ClientRef();
|
|
|
|
~ClientRef();
|
|
|
|
int32_t getToken() const;
|
2010-06-09 02:54:15 +00:00
|
|
|
sp<UserClient> getClient() const;
|
2010-06-01 22:12:58 +00:00
|
|
|
status_t setToken(const sp<UserClient>& uc,
|
2010-06-09 02:54:15 +00:00
|
|
|
const sp<SharedBufferServer>& sharedClient, int32_t token);
|
2010-06-01 22:12:58 +00:00
|
|
|
sp<UserClient> getUserClientUnsafe() const;
|
|
|
|
class Access {
|
|
|
|
Access(const Access& rhs);
|
|
|
|
Access& operator = (const Access& rhs);
|
|
|
|
sp<UserClient> mUserClientStrongRef;
|
2010-06-09 02:54:15 +00:00
|
|
|
sp<SharedBufferServer> mControlBlock;
|
2010-06-01 22:12:58 +00:00
|
|
|
public:
|
|
|
|
Access(const ClientRef& ref);
|
2010-06-09 02:54:15 +00:00
|
|
|
~Access();
|
|
|
|
inline SharedBufferServer* get() const { return mControlBlock.get(); }
|
2010-06-01 22:12:58 +00:00
|
|
|
};
|
|
|
|
friend class Access;
|
|
|
|
};
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------
|
|
|
|
|
|
|
|
class BufferManager {
|
|
|
|
static const size_t NUM_BUFFERS = 2;
|
|
|
|
struct BufferData {
|
|
|
|
sp<GraphicBuffer> buffer;
|
|
|
|
Image texture;
|
|
|
|
};
|
|
|
|
// this lock protect mBufferData[].buffer but since there
|
|
|
|
// is very little contention, we have only one like for
|
|
|
|
// the whole array, we also use it to protect mNumBuffers.
|
|
|
|
mutable Mutex mLock;
|
|
|
|
BufferData mBufferData[SharedBufferStack::NUM_BUFFER_MAX];
|
|
|
|
size_t mNumBuffers;
|
|
|
|
Texture mFailoverTexture;
|
|
|
|
TextureManager& mTextureManager;
|
|
|
|
ssize_t mActiveBuffer;
|
|
|
|
bool mFailover;
|
|
|
|
static status_t destroyTexture(Image* tex, EGLDisplay dpy);
|
|
|
|
|
|
|
|
public:
|
|
|
|
static size_t getDefaultBufferCount() { return NUM_BUFFERS; }
|
|
|
|
BufferManager(TextureManager& tm);
|
|
|
|
~BufferManager();
|
|
|
|
|
|
|
|
// detach/attach buffer from/to given index
|
|
|
|
sp<GraphicBuffer> detachBuffer(size_t index);
|
|
|
|
status_t attachBuffer(size_t index, const sp<GraphicBuffer>& buffer);
|
|
|
|
// resize the number of active buffers
|
2010-11-02 18:51:32 +00:00
|
|
|
status_t resize(size_t size, const sp<SurfaceFlinger>& flinger,
|
|
|
|
EGLDisplay dpy);
|
2010-06-01 22:12:58 +00:00
|
|
|
|
|
|
|
// ----------------------------------------------
|
|
|
|
// must be called from GL thread
|
|
|
|
|
|
|
|
// set/get active buffer index
|
|
|
|
status_t setActiveBufferIndex(size_t index);
|
|
|
|
size_t getActiveBufferIndex() const;
|
|
|
|
// return the active buffer
|
|
|
|
sp<GraphicBuffer> getActiveBuffer() const;
|
2010-12-14 02:51:59 +00:00
|
|
|
// return wether we have an active buffer
|
|
|
|
bool hasActiveBuffer() const;
|
2010-06-01 22:12:58 +00:00
|
|
|
// return the active texture (or fail-over)
|
|
|
|
Texture getActiveTexture() const;
|
|
|
|
// frees resources associated with all buffers
|
|
|
|
status_t destroy(EGLDisplay dpy);
|
|
|
|
// load bitmap data into the active buffer
|
|
|
|
status_t loadTexture(const Region& dirty, const GGLSurface& t);
|
|
|
|
// make active buffer an EGLImage if needed
|
|
|
|
status_t initEglImage(EGLDisplay dpy,
|
|
|
|
const sp<GraphicBuffer>& buffer);
|
|
|
|
|
|
|
|
// ----------------------------------------------
|
|
|
|
// only for debugging
|
|
|
|
sp<GraphicBuffer> getBuffer(size_t index) const;
|
|
|
|
};
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------
|
|
|
|
|
|
|
|
// thread-safe
|
|
|
|
ClientRef mUserClientRef;
|
|
|
|
|
|
|
|
// constants
|
|
|
|
sp<Surface> mSurface;
|
|
|
|
PixelFormat mFormat;
|
2010-06-26 01:02:21 +00:00
|
|
|
const GLExtensions& mGLExtensions;
|
2010-06-01 22:12:58 +00:00
|
|
|
bool mNeedsBlending;
|
|
|
|
bool mNeedsDithering;
|
|
|
|
|
|
|
|
// page-flip thread (currently main thread)
|
|
|
|
bool mSecure;
|
|
|
|
Region mPostedDirtyRegion;
|
|
|
|
|
|
|
|
// page-flip thread and transaction thread (currently main thread)
|
|
|
|
sp<FreezeLock> mFreezeLock;
|
|
|
|
|
|
|
|
// see threading usage in declaration
|
|
|
|
TextureManager mTextureManager;
|
|
|
|
BufferManager mBufferManager;
|
|
|
|
|
|
|
|
// binder thread, transaction thread
|
|
|
|
mutable Mutex mLock;
|
|
|
|
uint32_t mWidth;
|
|
|
|
uint32_t mHeight;
|
|
|
|
uint32_t mReqWidth;
|
|
|
|
uint32_t mReqHeight;
|
|
|
|
uint32_t mReqFormat;
|
2010-12-03 05:32:29 +00:00
|
|
|
bool mNeedsScaling;
|
2010-06-01 22:12:58 +00:00
|
|
|
bool mFixedSize;
|
2009-03-04 03:31:44 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
}; // namespace android
|
|
|
|
|
|
|
|
#endif // ANDROID_LAYER_H
|