blob: 777b878dd1386e668efc1083c20ea5ee74401f78 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
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
Mathias Agopianbc726112009-09-23 15:44:05 -070023#include <binder/IBinder.h>
24
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080025#include <utils/SortedVector.h>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080026#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;
Mathias Agopian9779b222009-09-07 16:32:45 -070040class SharedClient;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080041
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
Mathias Agopian17f638b2009-04-16 20:04:08 -070065 sp<SurfaceControl> createSurface(
Mathias Agopian9779b222009-09-07 16:32:45 -070066 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
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080072 );
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
Mathias Agopianeb0c86e2009-03-27 18:11:38 -0700100 static int setOrientation(DisplayID dpy, int orientation, uint32_t flags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800101
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
Mathias Agopianbc726112009-09-23 15:44:05 -0700111 status_t linkToComposerDeath(const sp<IBinder::DeathRecipient>& recipient,
112 void* cookie = NULL, uint32_t flags = 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800113
114private:
115 friend class Surface;
Mathias Agopian6d2c0bc2009-04-16 16:19:50 -0700116 friend class SurfaceControl;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800117
118 SurfaceComposerClient(const sp<ISurfaceComposer>& sm,
119 const sp<IBinder>& conn);
120
Mathias Agopian6d2c0bc2009-04-16 16:19:50 -0700121 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);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800133
Mathias Agopian1473f462009-04-10 14:24:30 -0700134 void signalServer();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800135
136 status_t destroySurface(SurfaceID sid);
137
138 void _init(const sp<ISurfaceComposer>& sm,
139 const sp<ISurfaceFlingerClient>& conn);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800140
Mathias Agopian6d2c0bc2009-04-16 16:19:50 -0700141 inline layer_state_t* _get_state_l(SurfaceID id);
142 layer_state_t* _lockLayerState(SurfaceID id);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800143 inline void _unlockLayerState();
144
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800145 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;
Mathias Agopian9779b222009-09-07 16:32:45 -0700153 SharedClient* mControl;
Mathias Agopiand763b5d2009-07-02 18:11:53 -0700154 sp<IMemoryHeap> mControlMemory;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800155 sp<ISurfaceFlingerClient> mClient;
Mathias Agopiane05f07d2009-10-07 16:44:10 -0700156 sp<ISurfaceComposer> mSignalServer;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800157};
158
159}; // namespace android
160
161#endif // ANDROID_SURFACE_COMPOSER_CLIENT_H
162