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_SURFACE_FLINGER_H
|
|
|
|
#define ANDROID_SURFACE_FLINGER_H
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
|
|
|
#include <utils/SortedVector.h>
|
|
|
|
#include <utils/KeyedVector.h>
|
|
|
|
#include <utils/threads.h>
|
|
|
|
#include <utils/Atomic.h>
|
|
|
|
#include <utils/Errors.h>
|
2009-04-10 21:24:30 +00:00
|
|
|
#include <utils/RefBase.h>
|
2009-03-04 03:31:44 +00:00
|
|
|
|
2009-07-03 01:11:53 +00:00
|
|
|
#include <binder/IMemory.h>
|
2009-06-16 01:24:59 +00:00
|
|
|
#include <binder/Permission.h>
|
|
|
|
|
2009-03-04 03:31:44 +00:00
|
|
|
#include <ui/PixelFormat.h>
|
|
|
|
#include <ui/ISurfaceComposer.h>
|
|
|
|
#include <ui/ISurfaceFlingerClient.h>
|
|
|
|
|
|
|
|
#include <private/ui/SharedState.h>
|
|
|
|
#include <private/ui/LayerState.h>
|
|
|
|
|
|
|
|
#include "Barrier.h"
|
|
|
|
#include "Layer.h"
|
|
|
|
#include "Tokenizer.h"
|
|
|
|
|
2009-04-21 02:39:12 +00:00
|
|
|
#include "MessageQueue.h"
|
|
|
|
|
2009-03-04 03:31:44 +00:00
|
|
|
struct copybit_device_t;
|
|
|
|
struct overlay_device_t;
|
|
|
|
|
|
|
|
namespace android {
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
class Client;
|
|
|
|
class BClient;
|
|
|
|
class DisplayHardware;
|
|
|
|
class FreezeLock;
|
|
|
|
class Layer;
|
|
|
|
class LayerBuffer;
|
|
|
|
|
|
|
|
typedef int32_t ClientID;
|
|
|
|
|
|
|
|
#define LIKELY( exp ) (__builtin_expect( (exp) != 0, true ))
|
|
|
|
#define UNLIKELY( exp ) (__builtin_expect( (exp) != 0, false ))
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
2009-06-20 00:00:27 +00:00
|
|
|
class Client : public RefBase
|
2009-03-04 03:31:44 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
Client(ClientID cid, const sp<SurfaceFlinger>& flinger);
|
|
|
|
~Client();
|
|
|
|
|
|
|
|
int32_t generateId(int pid);
|
|
|
|
void free(int32_t id);
|
2009-04-10 21:24:30 +00:00
|
|
|
status_t bindLayer(const sp<LayerBaseClient>& layer, int32_t id);
|
2009-03-04 03:31:44 +00:00
|
|
|
|
|
|
|
inline bool isValid(int32_t i) const;
|
2009-04-10 21:24:30 +00:00
|
|
|
sp<LayerBaseClient> getLayerUser(int32_t i) const;
|
2009-03-04 03:31:44 +00:00
|
|
|
void dump(const char* what);
|
|
|
|
|
2009-07-03 01:11:53 +00:00
|
|
|
const Vector< wp<LayerBaseClient> >& getLayers() const {
|
|
|
|
return mLayers;
|
|
|
|
}
|
|
|
|
|
|
|
|
const sp<IMemoryHeap>& getControlBlockMemory() const {
|
|
|
|
return mCblkHeap;
|
|
|
|
}
|
|
|
|
|
2009-03-04 03:31:44 +00:00
|
|
|
// pointer to this client's control block
|
|
|
|
per_client_cblk_t* ctrlblk;
|
|
|
|
ClientID cid;
|
|
|
|
|
|
|
|
|
|
|
|
private:
|
2009-07-03 01:11:53 +00:00
|
|
|
int getClientPid() const { return mPid; }
|
2009-03-04 03:31:44 +00:00
|
|
|
|
2009-04-10 21:24:30 +00:00
|
|
|
int mPid;
|
|
|
|
uint32_t mBitmap;
|
|
|
|
SortedVector<uint8_t> mInUse;
|
|
|
|
Vector< wp<LayerBaseClient> > mLayers;
|
2009-07-03 01:11:53 +00:00
|
|
|
sp<IMemoryHeap> mCblkHeap;
|
2009-04-10 21:24:30 +00:00
|
|
|
sp<SurfaceFlinger> mFlinger;
|
2009-03-04 03:31:44 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
class GraphicPlane
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
static status_t orientationToTransfrom(int orientation, int w, int h,
|
|
|
|
Transform* tr);
|
|
|
|
|
|
|
|
GraphicPlane();
|
|
|
|
~GraphicPlane();
|
|
|
|
|
|
|
|
bool initialized() const;
|
|
|
|
|
|
|
|
void setDisplayHardware(DisplayHardware *);
|
|
|
|
void setTransform(const Transform& tr);
|
|
|
|
status_t setOrientation(int orientation);
|
2009-03-28 00:58:20 +00:00
|
|
|
int getOrientation() const { return mOrientation; }
|
2009-03-04 03:31:44 +00:00
|
|
|
|
|
|
|
const DisplayHardware& displayHardware() const;
|
|
|
|
const Transform& transform() const;
|
2009-04-10 21:24:30 +00:00
|
|
|
EGLDisplay getEGLDisplay() const;
|
|
|
|
|
2009-03-04 03:31:44 +00:00
|
|
|
private:
|
|
|
|
GraphicPlane(const GraphicPlane&);
|
|
|
|
GraphicPlane operator = (const GraphicPlane&);
|
|
|
|
|
|
|
|
DisplayHardware* mHw;
|
|
|
|
Transform mTransform;
|
|
|
|
Transform mOrientationTransform;
|
|
|
|
Transform mGlobalTransform;
|
2009-03-28 00:58:20 +00:00
|
|
|
int mOrientation;
|
2009-03-04 03:31:44 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
enum {
|
|
|
|
eTransactionNeeded = 0x01,
|
|
|
|
eTraversalNeeded = 0x02
|
|
|
|
};
|
|
|
|
|
|
|
|
class SurfaceFlinger : public BnSurfaceComposer, protected Thread
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
static void instantiate();
|
|
|
|
static void shutdown();
|
|
|
|
|
|
|
|
SurfaceFlinger();
|
|
|
|
virtual ~SurfaceFlinger();
|
|
|
|
void init();
|
|
|
|
|
|
|
|
virtual status_t onTransact(
|
|
|
|
uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags);
|
|
|
|
|
|
|
|
virtual status_t dump(int fd, const Vector<String16>& args);
|
|
|
|
|
|
|
|
// ISurfaceComposer interface
|
|
|
|
virtual sp<ISurfaceFlingerClient> createConnection();
|
2009-07-03 01:11:53 +00:00
|
|
|
virtual sp<IMemoryHeap> getCblk() const;
|
2009-03-04 03:31:44 +00:00
|
|
|
virtual void bootFinished();
|
|
|
|
virtual void openGlobalTransaction();
|
|
|
|
virtual void closeGlobalTransaction();
|
|
|
|
virtual status_t freezeDisplay(DisplayID dpy, uint32_t flags);
|
|
|
|
virtual status_t unfreezeDisplay(DisplayID dpy, uint32_t flags);
|
2009-03-28 01:11:38 +00:00
|
|
|
virtual int setOrientation(DisplayID dpy, int orientation, uint32_t flags);
|
2009-03-04 03:31:44 +00:00
|
|
|
virtual void signal() const;
|
|
|
|
|
|
|
|
void screenReleased(DisplayID dpy);
|
|
|
|
void screenAcquired(DisplayID dpy);
|
|
|
|
|
|
|
|
overlay_control_device_t* getOverlayEngine() const;
|
|
|
|
|
|
|
|
|
2009-04-10 21:24:30 +00:00
|
|
|
status_t removeLayer(const sp<LayerBase>& layer);
|
|
|
|
status_t addLayer(const sp<LayerBase>& layer);
|
|
|
|
status_t invalidateLayerVisibility(const sp<LayerBase>& layer);
|
2009-03-04 03:31:44 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
friend class BClient;
|
|
|
|
friend class LayerBase;
|
|
|
|
friend class LayerBuffer;
|
|
|
|
friend class LayerBaseClient;
|
2009-07-07 02:04:03 +00:00
|
|
|
friend class LayerBaseClient::Surface;
|
2009-03-04 03:31:44 +00:00
|
|
|
friend class Layer;
|
|
|
|
friend class LayerBlur;
|
2009-06-19 01:48:39 +00:00
|
|
|
friend class LayerDim;
|
2009-03-04 03:31:44 +00:00
|
|
|
|
|
|
|
sp<ISurface> createSurface(ClientID client, int pid,
|
|
|
|
ISurfaceFlingerClient::surface_data_t* params,
|
|
|
|
DisplayID display, uint32_t w, uint32_t h, PixelFormat format,
|
|
|
|
uint32_t flags);
|
|
|
|
|
2009-04-10 21:24:30 +00:00
|
|
|
sp<LayerBaseClient> createNormalSurfaceLocked(
|
2009-06-20 00:00:27 +00:00
|
|
|
const sp<Client>& client, DisplayID display,
|
2009-08-20 00:46:26 +00:00
|
|
|
int32_t id, uint32_t w, uint32_t h, uint32_t flags,
|
|
|
|
PixelFormat& format);
|
2009-03-04 03:31:44 +00:00
|
|
|
|
2009-04-10 21:24:30 +00:00
|
|
|
sp<LayerBaseClient> createBlurSurfaceLocked(
|
2009-06-20 00:00:27 +00:00
|
|
|
const sp<Client>& client, DisplayID display,
|
2009-03-04 03:31:44 +00:00
|
|
|
int32_t id, uint32_t w, uint32_t h, uint32_t flags);
|
|
|
|
|
2009-04-10 21:24:30 +00:00
|
|
|
sp<LayerBaseClient> createDimSurfaceLocked(
|
2009-06-20 00:00:27 +00:00
|
|
|
const sp<Client>& client, DisplayID display,
|
2009-03-04 03:31:44 +00:00
|
|
|
int32_t id, uint32_t w, uint32_t h, uint32_t flags);
|
|
|
|
|
2009-04-10 21:24:30 +00:00
|
|
|
sp<LayerBaseClient> createPushBuffersSurfaceLocked(
|
2009-06-20 00:00:27 +00:00
|
|
|
const sp<Client>& client, DisplayID display,
|
2009-03-04 03:31:44 +00:00
|
|
|
int32_t id, uint32_t w, uint32_t h, uint32_t flags);
|
|
|
|
|
2009-04-18 02:36:26 +00:00
|
|
|
status_t removeSurface(SurfaceID surface_id);
|
|
|
|
status_t destroySurface(const sp<LayerBaseClient>& layer);
|
2009-04-10 21:24:30 +00:00
|
|
|
status_t setClientState(ClientID cid, int32_t count, const layer_state_t* states);
|
2009-03-04 03:31:44 +00:00
|
|
|
|
|
|
|
|
|
|
|
class LayerVector {
|
|
|
|
public:
|
|
|
|
inline LayerVector() { }
|
|
|
|
LayerVector(const LayerVector&);
|
|
|
|
inline size_t size() const { return layers.size(); }
|
2009-04-10 21:24:30 +00:00
|
|
|
inline sp<LayerBase> const* array() const { return layers.array(); }
|
|
|
|
ssize_t add(const sp<LayerBase>&, Vector< sp<LayerBase> >::compar_t);
|
|
|
|
ssize_t remove(const sp<LayerBase>&);
|
|
|
|
ssize_t reorder(const sp<LayerBase>&, Vector< sp<LayerBase> >::compar_t);
|
|
|
|
ssize_t indexOf(const sp<LayerBase>& key, size_t guess=0) const;
|
|
|
|
inline sp<LayerBase> operator [] (size_t i) const { return layers[i]; }
|
2009-03-04 03:31:44 +00:00
|
|
|
private:
|
2009-04-10 21:24:30 +00:00
|
|
|
KeyedVector< sp<LayerBase> , size_t> lookup;
|
|
|
|
Vector< sp<LayerBase> > layers;
|
2009-03-04 03:31:44 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct State {
|
|
|
|
State() {
|
|
|
|
orientation = ISurfaceComposer::eOrientationDefault;
|
|
|
|
freezeDisplay = 0;
|
|
|
|
}
|
|
|
|
LayerVector layersSortedByZ;
|
|
|
|
uint8_t orientation;
|
2009-03-28 01:11:38 +00:00
|
|
|
uint8_t orientationType;
|
2009-03-04 03:31:44 +00:00
|
|
|
uint8_t freezeDisplay;
|
|
|
|
};
|
|
|
|
|
|
|
|
virtual bool threadLoop();
|
|
|
|
virtual status_t readyToRun();
|
|
|
|
virtual void onFirstRef();
|
|
|
|
|
|
|
|
const GraphicPlane& graphicPlane(int dpy) const;
|
|
|
|
GraphicPlane& graphicPlane(int dpy);
|
|
|
|
|
|
|
|
void waitForEvent();
|
|
|
|
void signalEvent();
|
|
|
|
void signalDelayedEvent(nsecs_t delay);
|
|
|
|
|
|
|
|
void handleConsoleEvents();
|
|
|
|
void handleTransaction(uint32_t transactionFlags);
|
2009-06-05 01:46:21 +00:00
|
|
|
void handleTransactionLocked(
|
|
|
|
uint32_t transactionFlags,
|
|
|
|
Vector< sp<LayerBase> >& ditchedLayers);
|
2009-03-04 03:31:44 +00:00
|
|
|
|
|
|
|
void computeVisibleRegions(
|
|
|
|
LayerVector& currentLayers,
|
|
|
|
Region& dirtyRegion,
|
|
|
|
Region& wormholeRegion);
|
|
|
|
|
|
|
|
void handlePageFlip();
|
|
|
|
bool lockPageFlip(const LayerVector& currentLayers);
|
|
|
|
void unlockPageFlip(const LayerVector& currentLayers);
|
|
|
|
void handleRepaint();
|
2009-06-20 00:00:27 +00:00
|
|
|
void scheduleBroadcast(const sp<Client>& client);
|
2009-03-04 03:31:44 +00:00
|
|
|
void executeScheduledBroadcasts();
|
|
|
|
void postFramebuffer();
|
|
|
|
void composeSurfaces(const Region& dirty);
|
|
|
|
void unlockClients();
|
|
|
|
|
|
|
|
|
|
|
|
void destroyConnection(ClientID cid);
|
2009-04-10 21:24:30 +00:00
|
|
|
sp<LayerBaseClient> getLayerUser_l(SurfaceID index) const;
|
|
|
|
status_t addLayer_l(const sp<LayerBase>& layer);
|
|
|
|
status_t removeLayer_l(const sp<LayerBase>& layer);
|
2009-04-18 02:36:26 +00:00
|
|
|
status_t purgatorizeLayer_l(const sp<LayerBase>& layer);
|
2009-03-04 03:31:44 +00:00
|
|
|
void free_resources_l();
|
|
|
|
|
|
|
|
uint32_t getTransactionFlags(uint32_t flags);
|
|
|
|
uint32_t setTransactionFlags(uint32_t flags, nsecs_t delay = 0);
|
|
|
|
void commitTransaction();
|
|
|
|
|
|
|
|
|
|
|
|
friend class FreezeLock;
|
|
|
|
sp<FreezeLock> getFreezeLock() const;
|
|
|
|
inline void incFreezeCount() { mFreezeCount++; }
|
|
|
|
inline void decFreezeCount() { if (mFreezeCount > 0) mFreezeCount--; }
|
|
|
|
inline bool hasFreezeRequest() const { return mFreezeDisplay; }
|
|
|
|
inline bool isFrozen() const {
|
|
|
|
return mFreezeDisplay || mFreezeCount>0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void debugFlashRegions();
|
|
|
|
void debugShowFPS() const;
|
|
|
|
void drawWormhole() const;
|
|
|
|
|
2009-04-21 02:39:12 +00:00
|
|
|
|
|
|
|
mutable MessageQueue mEventQueue;
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-03-04 03:31:44 +00:00
|
|
|
// access must be protected by mStateLock
|
|
|
|
mutable Mutex mStateLock;
|
|
|
|
State mCurrentState;
|
|
|
|
State mDrawingState;
|
|
|
|
volatile int32_t mTransactionFlags;
|
|
|
|
volatile int32_t mTransactionCount;
|
|
|
|
Condition mTransactionCV;
|
2009-04-18 02:36:26 +00:00
|
|
|
|
2009-03-04 03:31:44 +00:00
|
|
|
// protected by mStateLock (but we could use another lock)
|
|
|
|
Tokenizer mTokens;
|
2009-06-20 00:00:27 +00:00
|
|
|
DefaultKeyedVector<ClientID, sp<Client> > mClientsMap;
|
2009-04-10 21:24:30 +00:00
|
|
|
DefaultKeyedVector<SurfaceID, sp<LayerBaseClient> > mLayerMap;
|
2009-03-04 03:31:44 +00:00
|
|
|
GraphicPlane mGraphicPlanes[1];
|
2009-04-10 21:24:30 +00:00
|
|
|
bool mLayersRemoved;
|
2009-06-20 00:00:27 +00:00
|
|
|
Vector< sp<Client> > mDisconnectedClients;
|
2009-03-04 03:31:44 +00:00
|
|
|
|
|
|
|
// constant members (no synchronization needed for access)
|
2009-07-03 01:11:53 +00:00
|
|
|
sp<IMemoryHeap> mServerHeap;
|
2009-03-04 03:31:44 +00:00
|
|
|
surface_flinger_cblk_t* mServerCblk;
|
|
|
|
GLuint mWormholeTexName;
|
|
|
|
nsecs_t mBootTime;
|
2009-06-16 01:24:59 +00:00
|
|
|
Permission mHardwareTest;
|
|
|
|
Permission mAccessSurfaceFlinger;
|
|
|
|
Permission mDump;
|
2009-03-04 03:31:44 +00:00
|
|
|
|
|
|
|
// Can only accessed from the main thread, these members
|
|
|
|
// don't need synchronization
|
|
|
|
Region mDirtyRegion;
|
2009-07-28 17:57:27 +00:00
|
|
|
Region mDirtyRegionRemovedLayer;
|
2009-03-04 03:31:44 +00:00
|
|
|
Region mInvalidRegion;
|
|
|
|
Region mWormholeRegion;
|
2009-06-20 00:00:27 +00:00
|
|
|
wp<Client> mLastScheduledBroadcast;
|
|
|
|
SortedVector< wp<Client> > mScheduledBroadcasts;
|
2009-03-04 03:31:44 +00:00
|
|
|
bool mVisibleRegionsDirty;
|
|
|
|
bool mDeferReleaseConsole;
|
|
|
|
bool mFreezeDisplay;
|
|
|
|
int32_t mFreezeCount;
|
|
|
|
nsecs_t mFreezeDisplayTime;
|
|
|
|
|
|
|
|
// don't use a lock for these, we don't care
|
|
|
|
int mDebugRegion;
|
|
|
|
int mDebugBackground;
|
|
|
|
|
|
|
|
// these are thread safe
|
|
|
|
mutable Barrier mReadyToRunBarrier;
|
|
|
|
|
|
|
|
// atomic variables
|
|
|
|
enum {
|
|
|
|
eConsoleReleased = 1,
|
|
|
|
eConsoleAcquired = 2
|
|
|
|
};
|
|
|
|
volatile int32_t mConsoleSignals;
|
|
|
|
|
|
|
|
// only written in the main thread, only read in other threads
|
|
|
|
volatile int32_t mSecureFrameBuffer;
|
|
|
|
};
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
class FreezeLock : public LightRefBase<FreezeLock> {
|
|
|
|
SurfaceFlinger* mFlinger;
|
|
|
|
public:
|
|
|
|
FreezeLock(SurfaceFlinger* flinger)
|
|
|
|
: mFlinger(flinger) {
|
|
|
|
mFlinger->incFreezeCount();
|
|
|
|
}
|
|
|
|
~FreezeLock() {
|
|
|
|
mFlinger->decFreezeCount();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
class BClient : public BnSurfaceFlingerClient
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
BClient(SurfaceFlinger *flinger, ClientID cid,
|
2009-07-03 01:11:53 +00:00
|
|
|
const sp<IMemoryHeap>& cblk);
|
2009-03-04 03:31:44 +00:00
|
|
|
~BClient();
|
|
|
|
|
|
|
|
// ISurfaceFlingerClient interface
|
2009-07-03 01:11:53 +00:00
|
|
|
virtual sp<IMemoryHeap> getControlBlock() const;
|
2009-03-04 03:31:44 +00:00
|
|
|
|
|
|
|
virtual sp<ISurface> createSurface(
|
|
|
|
surface_data_t* params, int pid,
|
|
|
|
DisplayID display, uint32_t w, uint32_t h,PixelFormat format,
|
|
|
|
uint32_t flags);
|
|
|
|
|
|
|
|
virtual status_t destroySurface(SurfaceID surfaceId);
|
|
|
|
virtual status_t setState(int32_t count, const layer_state_t* states);
|
|
|
|
|
|
|
|
private:
|
|
|
|
ClientID mId;
|
|
|
|
SurfaceFlinger* mFlinger;
|
2009-07-03 01:11:53 +00:00
|
|
|
sp<IMemoryHeap> mCblk;
|
2009-03-04 03:31:44 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
}; // namespace android
|
|
|
|
|
|
|
|
#endif // ANDROID_SURFACE_FLINGER_H
|