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.
|
|
|
|
*/
|
|
|
|
|
2010-02-10 01:46:37 +00:00
|
|
|
#ifndef ANDROID_SF_SURFACE_COMPOSER_CLIENT_H
|
|
|
|
#define ANDROID_SF_SURFACE_COMPOSER_CLIENT_H
|
2009-03-04 03:31:44 +00:00
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
2009-09-23 22:44:05 +00:00
|
|
|
#include <binder/IBinder.h>
|
|
|
|
|
2009-03-04 03:31:44 +00:00
|
|
|
#include <utils/RefBase.h>
|
2010-06-01 22:12:58 +00:00
|
|
|
#include <utils/Singleton.h>
|
|
|
|
#include <utils/SortedVector.h>
|
2009-03-04 03:31:44 +00:00
|
|
|
#include <utils/threads.h>
|
|
|
|
|
|
|
|
#include <ui/PixelFormat.h>
|
|
|
|
#include <ui/Region.h>
|
2010-02-10 01:46:37 +00:00
|
|
|
|
|
|
|
#include <surfaceflinger/Surface.h>
|
2009-03-04 03:31:44 +00:00
|
|
|
|
|
|
|
namespace android {
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
class Region;
|
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;
|
2010-02-10 01:46:37 +00:00
|
|
|
class ISurfaceComposer;
|
|
|
|
class DisplayInfo;
|
2010-06-01 22:12:58 +00:00
|
|
|
class surface_flinger_cblk_t;
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
class ComposerService : public Singleton<ComposerService>
|
|
|
|
{
|
|
|
|
// these are constants
|
|
|
|
sp<ISurfaceComposer> mComposerService;
|
|
|
|
sp<IMemoryHeap> mServerCblkMemory;
|
|
|
|
surface_flinger_cblk_t volatile* mServerCblk;
|
|
|
|
ComposerService();
|
|
|
|
friend class Singleton<ComposerService>;
|
|
|
|
public:
|
|
|
|
static sp<ISurfaceComposer> getComposerService();
|
|
|
|
static surface_flinger_cblk_t const volatile * getControlBlock();
|
|
|
|
};
|
2009-03-04 03:31:44 +00:00
|
|
|
|
2010-05-28 02:41:15 +00:00
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
class SurfaceComposerClient : public RefBase
|
2009-03-04 03:31:44 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
SurfaceComposerClient();
|
|
|
|
virtual ~SurfaceComposerClient();
|
|
|
|
|
|
|
|
// Always make sure we could initialize
|
|
|
|
status_t initCheck() const;
|
|
|
|
|
|
|
|
// Return the connection of this client
|
|
|
|
sp<IBinder> connection() const;
|
|
|
|
|
|
|
|
// Forcibly remove connection before all references have gone away.
|
|
|
|
void dispose();
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------
|
|
|
|
// surface creation / destruction
|
|
|
|
|
|
|
|
//! Create a surface
|
2009-04-17 03:04:08 +00:00
|
|
|
sp<SurfaceControl> createSurface(
|
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
|
|
|
int pid, // pid of the process the surface is for
|
2010-03-02 00:09:43 +00:00
|
|
|
const String8& name,// name of the surface
|
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
|
|
|
DisplayID display, // Display to create this surface on
|
|
|
|
uint32_t w, // width in pixel
|
|
|
|
uint32_t h, // height in pixel
|
|
|
|
PixelFormat format, // pixel-format desired
|
|
|
|
uint32_t flags = 0 // usage flags
|
2009-03-04 03:31:44 +00:00
|
|
|
);
|
|
|
|
|
2010-03-02 00:09:43 +00:00
|
|
|
sp<SurfaceControl> createSurface(
|
|
|
|
int pid, // pid of the process the surface is for
|
|
|
|
DisplayID display, // Display to create this surface on
|
|
|
|
uint32_t w, // width in pixel
|
|
|
|
uint32_t h, // height in pixel
|
|
|
|
PixelFormat format, // pixel-format desired
|
|
|
|
uint32_t flags = 0 // usage flags
|
|
|
|
);
|
|
|
|
|
|
|
|
|
2009-03-04 03:31:44 +00:00
|
|
|
// ------------------------------------------------------------------------
|
|
|
|
// Composer parameters
|
|
|
|
// All composer parameters must be changed within a transaction
|
|
|
|
// several surfaces can be updated in one transaction, all changes are
|
|
|
|
// committed at once when the transaction is closed.
|
|
|
|
// CloseTransaction() usually requires an IPC with the server.
|
|
|
|
|
|
|
|
//! Open a composer transaction
|
|
|
|
status_t openTransaction();
|
|
|
|
|
|
|
|
//! commit the transaction
|
|
|
|
status_t closeTransaction();
|
|
|
|
|
|
|
|
//! Open a composer transaction on all active SurfaceComposerClients.
|
|
|
|
static void openGlobalTransaction();
|
|
|
|
|
|
|
|
//! Close a composer transaction on all active SurfaceComposerClients.
|
|
|
|
static void closeGlobalTransaction();
|
|
|
|
|
|
|
|
//! Freeze the specified display but not transactions.
|
|
|
|
static status_t freezeDisplay(DisplayID dpy, uint32_t flags = 0);
|
|
|
|
|
|
|
|
//! Resume updates on the specified display.
|
|
|
|
static status_t unfreezeDisplay(DisplayID dpy, uint32_t flags = 0);
|
|
|
|
|
|
|
|
//! Set the orientation of the given display
|
2009-03-28 01:11:38 +00:00
|
|
|
static int setOrientation(DisplayID dpy, int orientation, uint32_t flags);
|
2009-03-04 03:31:44 +00:00
|
|
|
|
|
|
|
// Query the number of displays
|
|
|
|
static ssize_t getNumberOfDisplays();
|
|
|
|
|
|
|
|
// Get information about a display
|
|
|
|
static status_t getDisplayInfo(DisplayID dpy, DisplayInfo* info);
|
|
|
|
static ssize_t getDisplayWidth(DisplayID dpy);
|
|
|
|
static ssize_t getDisplayHeight(DisplayID dpy);
|
|
|
|
static ssize_t getDisplayOrientation(DisplayID dpy);
|
|
|
|
|
2009-09-23 22:44:05 +00:00
|
|
|
status_t linkToComposerDeath(const sp<IBinder::DeathRecipient>& recipient,
|
|
|
|
void* cookie = NULL, uint32_t flags = 0);
|
2009-03-04 03:31:44 +00:00
|
|
|
|
2009-04-16 23:19:50 +00:00
|
|
|
status_t hide(SurfaceID id);
|
|
|
|
status_t show(SurfaceID id, int32_t layer = -1);
|
|
|
|
status_t freeze(SurfaceID id);
|
|
|
|
status_t unfreeze(SurfaceID id);
|
|
|
|
status_t setFlags(SurfaceID id, uint32_t flags, uint32_t mask);
|
|
|
|
status_t setTransparentRegionHint(SurfaceID id, const Region& transparent);
|
|
|
|
status_t setLayer(SurfaceID id, int32_t layer);
|
|
|
|
status_t setAlpha(SurfaceID id, float alpha=1.0f);
|
|
|
|
status_t setFreezeTint(SurfaceID id, uint32_t tint);
|
|
|
|
status_t setMatrix(SurfaceID id, float dsdx, float dtdx, float dsdy, float dtdy);
|
|
|
|
status_t setPosition(SurfaceID id, int32_t x, int32_t y);
|
|
|
|
status_t setSize(SurfaceID id, uint32_t w, uint32_t h);
|
2009-03-04 03:31:44 +00:00
|
|
|
status_t destroySurface(SurfaceID sid);
|
|
|
|
|
2010-05-26 00:51:34 +00:00
|
|
|
private:
|
2010-05-28 02:41:15 +00:00
|
|
|
virtual void onFirstRef();
|
2010-05-26 00:51:34 +00:00
|
|
|
inline layer_state_t* get_state_l(SurfaceID id);
|
|
|
|
layer_state_t* lockLayerState(SurfaceID id);
|
|
|
|
inline void unlockLayerState();
|
2009-03-04 03:31:44 +00:00
|
|
|
|
|
|
|
mutable Mutex mLock;
|
|
|
|
SortedVector<layer_state_t> mStates;
|
|
|
|
int32_t mTransactionOpen;
|
2010-05-28 02:41:15 +00:00
|
|
|
layer_state_t* mPrebuiltLayerState;
|
2009-03-04 03:31:44 +00:00
|
|
|
|
|
|
|
// these don't need to be protected because they never change
|
|
|
|
// after assignment
|
|
|
|
status_t mStatus;
|
2010-05-28 21:22:23 +00:00
|
|
|
sp<ISurfaceComposerClient> mClient;
|
2009-03-04 03:31:44 +00:00
|
|
|
};
|
|
|
|
|
2010-09-29 20:02:36 +00:00
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
class ScreenshotClient
|
|
|
|
{
|
|
|
|
sp<IMemoryHeap> mHeap;
|
|
|
|
uint32_t mWidth;
|
|
|
|
uint32_t mHeight;
|
|
|
|
PixelFormat mFormat;
|
|
|
|
public:
|
|
|
|
ScreenshotClient();
|
|
|
|
|
|
|
|
// frees the previous screenshot and capture a new one
|
|
|
|
status_t update();
|
|
|
|
status_t update(uint32_t reqWidth, uint32_t reqHeight);
|
|
|
|
|
|
|
|
// release memory occupied by the screenshot
|
|
|
|
void release();
|
|
|
|
|
|
|
|
// pixels are valid until this object is freed or
|
|
|
|
// release() or update() is called
|
|
|
|
void const* getPixels() const;
|
|
|
|
|
|
|
|
uint32_t getWidth() const;
|
|
|
|
uint32_t getHeight() const;
|
|
|
|
PixelFormat getFormat() const;
|
|
|
|
uint32_t getStride() const;
|
|
|
|
// size of allocated memory in bytes
|
|
|
|
size_t getSize() const;
|
|
|
|
};
|
|
|
|
|
2010-05-28 02:41:15 +00:00
|
|
|
// ---------------------------------------------------------------------------
|
2009-03-04 03:31:44 +00:00
|
|
|
}; // namespace android
|
|
|
|
|
2010-02-10 01:46:37 +00:00
|
|
|
#endif // ANDROID_SF_SURFACE_COMPOSER_CLIENT_H
|
2009-03-04 03:31:44 +00:00
|
|
|
|