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.
|
|
|
|
*/
|
|
|
|
|
2012-02-26 02:48:35 +00:00
|
|
|
#ifndef ANDROID_GUI_SURFACE_COMPOSER_CLIENT_H
|
|
|
|
#define ANDROID_GUI_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>
|
2013-02-13 23:26:48 +00:00
|
|
|
#include <binder/IMemory.h>
|
2009-09-23 22:44:05 +00:00
|
|
|
|
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>
|
2010-02-10 01:46:37 +00:00
|
|
|
|
2013-03-20 05:22:21 +00:00
|
|
|
#include <gui/CpuConsumer.h>
|
2013-02-15 01:11:02 +00:00
|
|
|
#include <gui/SurfaceControl.h>
|
2009-03-04 03:31:44 +00:00
|
|
|
|
|
|
|
namespace android {
|
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
2010-02-10 01:46:37 +00:00
|
|
|
class DisplayInfo;
|
2011-06-29 02:09:31 +00:00
|
|
|
class Composer;
|
2011-11-18 01:48:35 +00:00
|
|
|
class ISurfaceComposerClient;
|
2012-12-18 17:49:45 +00:00
|
|
|
class IGraphicBufferProducer;
|
2011-04-20 21:20:59 +00:00
|
|
|
class Region;
|
2010-06-01 22:12:58 +00:00
|
|
|
|
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
2010-05-28 02:41:15 +00:00
|
|
|
class SurfaceComposerClient : public RefBase
|
2009-03-04 03:31:44 +00:00
|
|
|
{
|
2011-06-29 02:09:31 +00:00
|
|
|
friend class Composer;
|
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();
|
|
|
|
|
2012-08-09 23:29:12 +00:00
|
|
|
// callback when the composer is dies
|
|
|
|
status_t linkToComposerDeath(const sp<IBinder::DeathRecipient>& recipient,
|
|
|
|
void* cookie = NULL, uint32_t flags = 0);
|
|
|
|
|
|
|
|
// Get information about a display
|
2012-08-25 03:00:51 +00:00
|
|
|
static status_t getDisplayInfo(const sp<IBinder>& display, DisplayInfo* info);
|
2012-08-09 23:29:12 +00:00
|
|
|
|
2012-10-09 02:13:57 +00:00
|
|
|
/* triggers screen off and waits for it to complete */
|
|
|
|
static void blankDisplay(const sp<IBinder>& display);
|
|
|
|
|
|
|
|
/* triggers screen on and waits for it to complete */
|
|
|
|
static void unblankDisplay(const sp<IBinder>& display);
|
|
|
|
|
2009-03-04 03:31:44 +00:00
|
|
|
// ------------------------------------------------------------------------
|
|
|
|
// surface creation / destruction
|
|
|
|
|
|
|
|
//! Create a surface
|
2009-04-17 03:04:08 +00:00
|
|
|
sp<SurfaceControl> createSurface(
|
2010-03-02 00:09:43 +00:00
|
|
|
const String8& name,// name of the surface
|
|
|
|
uint32_t w, // width in pixel
|
|
|
|
uint32_t h, // height in pixel
|
|
|
|
PixelFormat format, // pixel-format desired
|
|
|
|
uint32_t flags = 0 // usage flags
|
|
|
|
);
|
|
|
|
|
2012-08-25 03:00:51 +00:00
|
|
|
//! Create a display
|
2012-10-20 01:19:11 +00:00
|
|
|
static sp<IBinder> createDisplay(const String8& displayName, bool secure);
|
2010-03-02 00:09:43 +00:00
|
|
|
|
2012-08-25 03:00:51 +00:00
|
|
|
//! Get the token for the existing default displays.
|
|
|
|
//! Possible values for id are eDisplayIdMain and eDisplayIdHdmi.
|
|
|
|
static sp<IBinder> getBuiltInDisplay(int32_t id);
|
|
|
|
|
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.
|
2012-08-09 23:29:12 +00:00
|
|
|
// closeGlobalTransaction() requires an IPC with the server.
|
2009-03-04 03:31:44 +00:00
|
|
|
|
|
|
|
//! Open a composer transaction on all active SurfaceComposerClients.
|
|
|
|
static void openGlobalTransaction();
|
2012-10-16 01:24:43 +00:00
|
|
|
|
2009-03-04 03:31:44 +00:00
|
|
|
//! Close a composer transaction on all active SurfaceComposerClients.
|
2011-10-13 00:39:00 +00:00
|
|
|
static void closeGlobalTransaction(bool synchronous = false);
|
2009-03-04 03:31:44 +00:00
|
|
|
|
2012-10-16 01:24:43 +00:00
|
|
|
//! Flag the currently open transaction as an animation transaction.
|
|
|
|
static void setAnimationTransaction();
|
|
|
|
|
2013-02-12 00:40:36 +00:00
|
|
|
status_t hide(const sp<IBinder>& id);
|
|
|
|
status_t show(const sp<IBinder>& id);
|
|
|
|
status_t setFlags(const sp<IBinder>& id, uint32_t flags, uint32_t mask);
|
|
|
|
status_t setTransparentRegionHint(const sp<IBinder>& id, const Region& transparent);
|
|
|
|
status_t setLayer(const sp<IBinder>& id, int32_t layer);
|
|
|
|
status_t setAlpha(const sp<IBinder>& id, float alpha=1.0f);
|
|
|
|
status_t setMatrix(const sp<IBinder>& id, float dsdx, float dtdx, float dsdy, float dtdy);
|
|
|
|
status_t setPosition(const sp<IBinder>& id, float x, float y);
|
|
|
|
status_t setSize(const sp<IBinder>& id, uint32_t w, uint32_t h);
|
|
|
|
status_t setCrop(const sp<IBinder>& id, const Rect& crop);
|
|
|
|
status_t setLayerStack(const sp<IBinder>& id, uint32_t layerStack);
|
|
|
|
status_t destroySurface(const sp<IBinder>& id);
|
2009-03-04 03:31:44 +00:00
|
|
|
|
2012-08-09 23:29:12 +00:00
|
|
|
static void setDisplaySurface(const sp<IBinder>& token,
|
2012-12-18 17:49:45 +00:00
|
|
|
const sp<IGraphicBufferProducer>& bufferProducer);
|
2012-08-09 23:29:12 +00:00
|
|
|
static void setDisplayLayerStack(const sp<IBinder>& token,
|
|
|
|
uint32_t layerStack);
|
2012-09-05 02:30:46 +00:00
|
|
|
|
|
|
|
/* setDisplayProjection() defines the projection of layer stacks
|
|
|
|
* to a given display.
|
|
|
|
*
|
|
|
|
* - orientation defines the display's orientation.
|
|
|
|
* - layerStackRect defines which area of the window manager coordinate
|
|
|
|
* space will be used.
|
|
|
|
* - displayRect defines where on the display will layerStackRect be
|
|
|
|
* mapped to. displayRect is specified post-orientation, that is
|
|
|
|
* it uses the orientation seen by the end-user.
|
|
|
|
*/
|
|
|
|
static void setDisplayProjection(const sp<IBinder>& token,
|
|
|
|
uint32_t orientation,
|
|
|
|
const Rect& layerStackRect,
|
|
|
|
const Rect& displayRect);
|
2012-08-09 23:29:12 +00:00
|
|
|
|
2010-05-26 00:51:34 +00:00
|
|
|
private:
|
2010-05-28 02:41:15 +00:00
|
|
|
virtual void onFirstRef();
|
2011-06-29 02:09:31 +00:00
|
|
|
Composer& getComposer();
|
2009-03-04 03:31:44 +00:00
|
|
|
|
2011-06-29 02:09:31 +00:00
|
|
|
mutable Mutex mLock;
|
2009-03-04 03:31:44 +00:00
|
|
|
status_t mStatus;
|
2010-05-28 21:22:23 +00:00
|
|
|
sp<ISurfaceComposerClient> mClient;
|
2011-06-29 02:09:31 +00:00
|
|
|
Composer& mComposer;
|
2009-03-04 03:31:44 +00:00
|
|
|
};
|
|
|
|
|
2010-09-29 20:02:36 +00:00
|
|
|
// ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
class ScreenshotClient
|
|
|
|
{
|
2013-03-01 21:42:57 +00:00
|
|
|
public:
|
|
|
|
static status_t capture(
|
|
|
|
const sp<IBinder>& display,
|
|
|
|
const sp<IGraphicBufferProducer>& producer,
|
|
|
|
uint32_t reqWidth, uint32_t reqHeight,
|
|
|
|
uint32_t minLayerZ, uint32_t maxLayerZ);
|
|
|
|
|
|
|
|
private:
|
2013-03-20 05:22:21 +00:00
|
|
|
mutable sp<CpuConsumer> mCpuConsumer;
|
|
|
|
CpuConsumer::LockedBuffer mBuffer;
|
|
|
|
bool mHaveBuffer;
|
2013-03-01 21:42:57 +00:00
|
|
|
|
2010-09-29 20:02:36 +00:00
|
|
|
public:
|
|
|
|
ScreenshotClient();
|
2013-03-27 01:15:35 +00:00
|
|
|
~ScreenshotClient();
|
2010-09-29 20:02:36 +00:00
|
|
|
|
|
|
|
// frees the previous screenshot and capture a new one
|
2012-08-25 03:00:51 +00:00
|
|
|
status_t update(const sp<IBinder>& display);
|
|
|
|
status_t update(const sp<IBinder>& display,
|
|
|
|
uint32_t reqWidth, uint32_t reqHeight);
|
|
|
|
status_t update(const sp<IBinder>& display,
|
|
|
|
uint32_t reqWidth, uint32_t reqHeight,
|
2010-12-11 00:22:31 +00:00
|
|
|
uint32_t minLayerZ, uint32_t maxLayerZ);
|
2010-09-29 20:02:36 +00:00
|
|
|
|
2013-03-20 05:22:21 +00:00
|
|
|
sp<CpuConsumer> getCpuConsumer() const;
|
|
|
|
|
2010-09-29 20:02:36 +00:00
|
|
|
// 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
|
|
|
|
|
2012-02-26 02:48:35 +00:00
|
|
|
#endif // ANDROID_GUI_SURFACE_COMPOSER_CLIENT_H
|