SurfaceComposerClient.h revision 6d9b9dfd555ee2bc1dd8381dde95d45f9500b3ca
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#include <binder/IMemory.h>
25
26#include <utils/RefBase.h>
27#include <utils/Singleton.h>
28#include <utils/SortedVector.h>
29#include <utils/threads.h>
30
31#include <ui/PixelFormat.h>
32
33#include <gui/Surface.h>
34
35namespace android {
36
37// ---------------------------------------------------------------------------
38
39class DisplayInfo;
40class Composer;
41class IMemoryHeap;
42class ISurfaceComposerClient;
43class IGraphicBufferProducer;
44class Region;
45
46// ---------------------------------------------------------------------------
47
48class SurfaceComposerClient : public RefBase
49{
50    friend class Composer;
51public:
52                SurfaceComposerClient();
53    virtual     ~SurfaceComposerClient();
54
55    // Always make sure we could initialize
56    status_t    initCheck() const;
57
58    // Return the connection of this client
59    sp<IBinder> connection() const;
60
61    // Forcibly remove connection before all references have gone away.
62    void        dispose();
63
64    // callback when the composer is dies
65    status_t linkToComposerDeath(const sp<IBinder::DeathRecipient>& recipient,
66            void* cookie = NULL, uint32_t flags = 0);
67
68    // Get information about a display
69    static status_t getDisplayInfo(const sp<IBinder>& display, DisplayInfo* info);
70
71    /* triggers screen off and waits for it to complete */
72    static void blankDisplay(const sp<IBinder>& display);
73
74    /* triggers screen on and waits for it to complete */
75    static void unblankDisplay(const sp<IBinder>& display);
76
77    // ------------------------------------------------------------------------
78    // surface creation / destruction
79
80    //! Create a surface
81    sp<SurfaceControl> createSurface(
82            const String8& name,// name of the surface
83            uint32_t w,         // width in pixel
84            uint32_t h,         // height in pixel
85            PixelFormat format, // pixel-format desired
86            uint32_t flags = 0  // usage flags
87    );
88
89    //! Create a display
90    static sp<IBinder> createDisplay(const String8& displayName, bool secure);
91
92    //! Get the token for the existing default displays.
93    //! Possible values for id are eDisplayIdMain and eDisplayIdHdmi.
94    static sp<IBinder> getBuiltInDisplay(int32_t id);
95
96    // ------------------------------------------------------------------------
97    // Composer parameters
98    // All composer parameters must be changed within a transaction
99    // several surfaces can be updated in one transaction, all changes are
100    // committed at once when the transaction is closed.
101    // closeGlobalTransaction() requires an IPC with the server.
102
103    //! Open a composer transaction on all active SurfaceComposerClients.
104    static void openGlobalTransaction();
105
106    //! Close a composer transaction on all active SurfaceComposerClients.
107    static void closeGlobalTransaction(bool synchronous = false);
108
109    //! Flag the currently open transaction as an animation transaction.
110    static void setAnimationTransaction();
111
112    status_t    hide(const sp<IBinder>& id);
113    status_t    show(const sp<IBinder>& id);
114    status_t    setFlags(const sp<IBinder>& id, uint32_t flags, uint32_t mask);
115    status_t    setTransparentRegionHint(const sp<IBinder>& id, const Region& transparent);
116    status_t    setLayer(const sp<IBinder>& id, int32_t layer);
117    status_t    setAlpha(const sp<IBinder>& id, float alpha=1.0f);
118    status_t    setMatrix(const sp<IBinder>& id, float dsdx, float dtdx, float dsdy, float dtdy);
119    status_t    setPosition(const sp<IBinder>& id, float x, float y);
120    status_t    setSize(const sp<IBinder>& id, uint32_t w, uint32_t h);
121    status_t    setCrop(const sp<IBinder>& id, const Rect& crop);
122    status_t    setLayerStack(const sp<IBinder>& id, uint32_t layerStack);
123    status_t    destroySurface(const sp<IBinder>& id);
124
125    static void setDisplaySurface(const sp<IBinder>& token,
126            const sp<IGraphicBufferProducer>& bufferProducer);
127    static void setDisplayLayerStack(const sp<IBinder>& token,
128            uint32_t layerStack);
129
130    /* setDisplayProjection() defines the projection of layer stacks
131     * to a given display.
132     *
133     * - orientation defines the display's orientation.
134     * - layerStackRect defines which area of the window manager coordinate
135     * space will be used.
136     * - displayRect defines where on the display will layerStackRect be
137     * mapped to. displayRect is specified post-orientation, that is
138     * it uses the orientation seen by the end-user.
139     */
140    static void setDisplayProjection(const sp<IBinder>& token,
141            uint32_t orientation,
142            const Rect& layerStackRect,
143            const Rect& displayRect);
144
145private:
146    virtual void onFirstRef();
147    Composer& getComposer();
148
149    mutable     Mutex                       mLock;
150                status_t                    mStatus;
151                sp<ISurfaceComposerClient>  mClient;
152                Composer&                   mComposer;
153};
154
155// ---------------------------------------------------------------------------
156
157class ScreenshotClient
158{
159    sp<IMemoryHeap> mHeap;
160    uint32_t mWidth;
161    uint32_t mHeight;
162    PixelFormat mFormat;
163public:
164    ScreenshotClient();
165
166    // frees the previous screenshot and capture a new one
167    status_t update(const sp<IBinder>& display);
168    status_t update(const sp<IBinder>& display,
169            uint32_t reqWidth, uint32_t reqHeight);
170    status_t update(const sp<IBinder>& display,
171            uint32_t reqWidth, uint32_t reqHeight,
172            uint32_t minLayerZ, uint32_t maxLayerZ);
173
174    // release memory occupied by the screenshot
175    void release();
176
177    // pixels are valid until this object is freed or
178    // release() or update() is called
179    void const* getPixels() const;
180
181    uint32_t getWidth() const;
182    uint32_t getHeight() const;
183    PixelFormat getFormat() const;
184    uint32_t getStride() const;
185    // size of allocated memory in bytes
186    size_t getSize() const;
187};
188
189// ---------------------------------------------------------------------------
190}; // namespace android
191
192#endif // ANDROID_GUI_SURFACE_COMPOSER_CLIENT_H
193