SurfaceComposerClient.h revision 9d4e3d2f42e93e2d12bacabe97d307d30c3c20dd
1/*
2 * Copyright (C) 2007 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef ANDROID_GUI_SURFACE_COMPOSER_CLIENT_H
18#define ANDROID_GUI_SURFACE_COMPOSER_CLIENT_H
19
20#include <stdint.h>
21#include <sys/types.h>
22
23#include <binder/IBinder.h>
24
25#include <utils/RefBase.h>
26#include <utils/Singleton.h>
27#include <utils/SortedVector.h>
28#include <utils/threads.h>
29
30#include <ui/PixelFormat.h>
31
32#include <gui/Surface.h>
33
34namespace android {
35
36// ---------------------------------------------------------------------------
37
38class DisplayInfo;
39class Composer;
40class IMemoryHeap;
41class ISurfaceComposerClient;
42class ISurfaceTexture;
43class Region;
44
45// ---------------------------------------------------------------------------
46
47class SurfaceComposerClient : public RefBase
48{
49    friend class Composer;
50public:
51                SurfaceComposerClient();
52    virtual     ~SurfaceComposerClient();
53
54    // Always make sure we could initialize
55    status_t    initCheck() const;
56
57    // Return the connection of this client
58    sp<IBinder> connection() const;
59
60    // Forcibly remove connection before all references have gone away.
61    void        dispose();
62
63    // callback when the composer is dies
64    status_t linkToComposerDeath(const sp<IBinder::DeathRecipient>& recipient,
65            void* cookie = NULL, uint32_t flags = 0);
66
67    // Get information about a display
68    static status_t getDisplayInfo(const sp<IBinder>& display, DisplayInfo* info);
69
70    // ------------------------------------------------------------------------
71    // surface creation / destruction
72
73    //! Create a surface
74    sp<SurfaceControl> createSurface(
75            const String8& name,// name of the surface
76            uint32_t w,         // width in pixel
77            uint32_t h,         // height in pixel
78            PixelFormat format, // pixel-format desired
79            uint32_t flags = 0  // usage flags
80    );
81
82    //! Create a display
83    static sp<IBinder> createDisplay();
84
85    //! Get the token for the existing default displays.
86    //! Possible values for id are eDisplayIdMain and eDisplayIdHdmi.
87    static sp<IBinder> getBuiltInDisplay(int32_t id);
88
89    // ------------------------------------------------------------------------
90    // Composer parameters
91    // All composer parameters must be changed within a transaction
92    // several surfaces can be updated in one transaction, all changes are
93    // committed at once when the transaction is closed.
94    // closeGlobalTransaction() requires an IPC with the server.
95
96    //! Open a composer transaction on all active SurfaceComposerClients.
97    static void openGlobalTransaction();
98
99    //! Close a composer transaction on all active SurfaceComposerClients.
100    static void closeGlobalTransaction(bool synchronous = false);
101
102    status_t    hide(SurfaceID id);
103    status_t    show(SurfaceID id, int32_t layer = -1);
104    status_t    setFlags(SurfaceID id, uint32_t flags, uint32_t mask);
105    status_t    setTransparentRegionHint(SurfaceID id, const Region& transparent);
106    status_t    setLayer(SurfaceID id, int32_t layer);
107    status_t    setAlpha(SurfaceID id, float alpha=1.0f);
108    status_t    setMatrix(SurfaceID id, float dsdx, float dtdx, float dsdy, float dtdy);
109    status_t    setPosition(SurfaceID id, float x, float y);
110    status_t    setSize(SurfaceID id, uint32_t w, uint32_t h);
111    status_t    setCrop(SurfaceID id, const Rect& crop);
112    status_t    setLayerStack(SurfaceID id, uint32_t layerStack);
113    status_t    destroySurface(SurfaceID sid);
114
115    static void setDisplaySurface(const sp<IBinder>& token,
116            const sp<ISurfaceTexture>& surface);
117    static void setDisplayLayerStack(const sp<IBinder>& token,
118            uint32_t layerStack);
119    static void setDisplayOrientation(const sp<IBinder>& token,
120            uint32_t orientation);
121    static void setDisplayViewport(const sp<IBinder>& token,
122            const Rect& viewport);
123    static void setDisplayFrame(const sp<IBinder>& token, const Rect& frame);
124
125private:
126    virtual void onFirstRef();
127    Composer& getComposer();
128
129    mutable     Mutex                       mLock;
130                status_t                    mStatus;
131                sp<ISurfaceComposerClient>  mClient;
132                Composer&                   mComposer;
133};
134
135// ---------------------------------------------------------------------------
136
137class ScreenshotClient
138{
139    sp<IMemoryHeap> mHeap;
140    uint32_t mWidth;
141    uint32_t mHeight;
142    PixelFormat mFormat;
143public:
144    ScreenshotClient();
145
146    // frees the previous screenshot and capture a new one
147    status_t update(const sp<IBinder>& display);
148    status_t update(const sp<IBinder>& display,
149            uint32_t reqWidth, uint32_t reqHeight);
150    status_t update(const sp<IBinder>& display,
151            uint32_t reqWidth, uint32_t reqHeight,
152            uint32_t minLayerZ, uint32_t maxLayerZ);
153
154    // release memory occupied by the screenshot
155    void release();
156
157    // pixels are valid until this object is freed or
158    // release() or update() is called
159    void const* getPixels() const;
160
161    uint32_t getWidth() const;
162    uint32_t getHeight() const;
163    PixelFormat getFormat() const;
164    uint32_t getStride() const;
165    // size of allocated memory in bytes
166    size_t getSize() const;
167};
168
169// ---------------------------------------------------------------------------
170}; // namespace android
171
172#endif // ANDROID_GUI_SURFACE_COMPOSER_CLIENT_H
173