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_SURFACE_COMPOSER_CLIENT_H
18#define ANDROID_SURFACE_COMPOSER_CLIENT_H
19
20#include <stdint.h>
21#include <sys/types.h>
22
23#include <binder/IBinder.h>
24
25#include <utils/SortedVector.h>
26#include <utils/RefBase.h>
27#include <utils/threads.h>
28
29#include <ui/PixelFormat.h>
30#include <ui/ISurfaceComposer.h>
31#include <ui/Region.h>
32#include <ui/Surface.h>
33
34namespace android {
35
36// ---------------------------------------------------------------------------
37
38class Region;
39class SurfaceFlingerSynchro;
40class SharedClient;
41
42class SurfaceComposerClient : virtual public RefBase
43{
44public:
45                SurfaceComposerClient();
46    virtual     ~SurfaceComposerClient();
47
48    // Always make sure we could initialize
49    status_t    initCheck() const;
50
51    // Return the connection of this client
52    sp<IBinder> connection() const;
53
54    // Retrieve a client for an existing connection.
55    static sp<SurfaceComposerClient>
56                clientForConnection(const sp<IBinder>& conn);
57
58    // Forcibly remove connection before all references have gone away.
59    void        dispose();
60
61    // ------------------------------------------------------------------------
62    // surface creation / destruction
63
64    //! Create a surface
65    sp<SurfaceControl> createSurface(
66            int pid,            // pid of the process the surface is for
67            DisplayID display,  // Display to create this surface on
68            uint32_t w,         // width in pixel
69            uint32_t h,         // height in pixel
70            PixelFormat format, // pixel-format desired
71            uint32_t flags = 0  // usage flags
72    );
73
74    // ------------------------------------------------------------------------
75    // Composer parameters
76    // All composer parameters must be changed within a transaction
77    // several surfaces can be updated in one transaction, all changes are
78    // committed at once when the transaction is closed.
79    // CloseTransaction() usually requires an IPC with the server.
80
81    //! Open a composer transaction
82    status_t    openTransaction();
83
84    //! commit the transaction
85    status_t    closeTransaction();
86
87    //! Open a composer transaction on all active SurfaceComposerClients.
88    static void openGlobalTransaction();
89
90    //! Close a composer transaction on all active SurfaceComposerClients.
91    static void closeGlobalTransaction();
92
93    //! Freeze the specified display but not transactions.
94    static status_t freezeDisplay(DisplayID dpy, uint32_t flags = 0);
95
96    //! Resume updates on the specified display.
97    static status_t unfreezeDisplay(DisplayID dpy, uint32_t flags = 0);
98
99    //! Set the orientation of the given display
100    static int setOrientation(DisplayID dpy, int orientation, uint32_t flags);
101
102    // Query the number of displays
103    static ssize_t getNumberOfDisplays();
104
105    // Get information about a display
106    static status_t getDisplayInfo(DisplayID dpy, DisplayInfo* info);
107    static ssize_t getDisplayWidth(DisplayID dpy);
108    static ssize_t getDisplayHeight(DisplayID dpy);
109    static ssize_t getDisplayOrientation(DisplayID dpy);
110
111    status_t linkToComposerDeath(const sp<IBinder::DeathRecipient>& recipient,
112            void* cookie = NULL, uint32_t flags = 0);
113
114private:
115    friend class Surface;
116    friend class SurfaceControl;
117
118    SurfaceComposerClient(const sp<ISurfaceComposer>& sm,
119            const sp<IBinder>& conn);
120
121    status_t    hide(SurfaceID id);
122    status_t    show(SurfaceID id, int32_t layer = -1);
123    status_t    freeze(SurfaceID id);
124    status_t    unfreeze(SurfaceID id);
125    status_t    setFlags(SurfaceID id, uint32_t flags, uint32_t mask);
126    status_t    setTransparentRegionHint(SurfaceID id, const Region& transparent);
127    status_t    setLayer(SurfaceID id, int32_t layer);
128    status_t    setAlpha(SurfaceID id, float alpha=1.0f);
129    status_t    setFreezeTint(SurfaceID id, uint32_t tint);
130    status_t    setMatrix(SurfaceID id, float dsdx, float dtdx, float dsdy, float dtdy);
131    status_t    setPosition(SurfaceID id, int32_t x, int32_t y);
132    status_t    setSize(SurfaceID id, uint32_t w, uint32_t h);
133
134    void        signalServer();
135
136    status_t    destroySurface(SurfaceID sid);
137
138    void        _init(const sp<ISurfaceComposer>& sm,
139                    const sp<ISurfaceFlingerClient>& conn);
140
141    inline layer_state_t*   _get_state_l(SurfaceID id);
142    layer_state_t*          _lockLayerState(SurfaceID id);
143    inline void             _unlockLayerState();
144
145    mutable     Mutex                               mLock;
146                layer_state_t*                      mPrebuiltLayerState;
147                SortedVector<layer_state_t>         mStates;
148                int32_t                             mTransactionOpen;
149
150                // these don't need to be protected because they never change
151                // after assignment
152                status_t                    mStatus;
153                SharedClient*               mControl;
154                sp<IMemoryHeap>             mControlMemory;
155                sp<ISurfaceFlingerClient>   mClient;
156                sp<ISurfaceComposer>        mSignalServer;
157};
158
159}; // namespace android
160
161#endif // ANDROID_SURFACE_COMPOSER_CLIENT_H
162
163