blob: 5d9222d851932c3299cc9fe62b90bb5c8d7a6d2a [file] [log] [blame]
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -07001/*
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 <utils/SortedVector.h>
24#include <utils/KeyedVector.h>
25#include <utils/RefBase.h>
26#include <utils/threads.h>
27
28#include <ui/PixelFormat.h>
29#include <ui/ISurfaceComposer.h>
30#include <ui/Region.h>
31#include <ui/Surface.h>
32
33namespace android {
34
35// ---------------------------------------------------------------------------
36
37class Region;
38class SurfaceFlingerSynchro;
39struct per_client_cblk_t;
40struct layer_cblk_t;
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<Surface> createSurface(
66 int pid, //!< pid of the process the surfacec 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 // ------------------------------------------------------------------------
The Android Open Source Project8a7a6752009-01-15 16:12:10 -080075 // Composer parameters
The Android Open Source Project7c1b96a2008-10-21 07:00:00 -070076 // 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);
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
112private:
113 friend class Surface;
114
115 SurfaceComposerClient(const sp<ISurfaceComposer>& sm,
116 const sp<IBinder>& conn);
117
118 status_t hide(Surface* surface);
119 status_t show(Surface* surface, int32_t layer = -1);
120 status_t freeze(Surface* surface);
121 status_t unfreeze(Surface* surface);
122 status_t setFlags(Surface* surface, uint32_t flags, uint32_t mask);
123 status_t setTransparentRegionHint(Surface* surface, const Region& transparent);
124 status_t setLayer(Surface* surface, int32_t layer);
125 status_t setAlpha(Surface* surface, float alpha=1.0f);
126 status_t setFreezeTint(Surface* surface, uint32_t tint);
127 status_t setMatrix(Surface* surface, float dsdx, float dtdx, float dsdy, float dtdy);
128 status_t setPosition(Surface* surface, int32_t x, int32_t y);
129 status_t setSize(Surface* surface, uint32_t w, uint32_t h);
130
131 //! Unlock the surface, and specify the dirty region if any
132 status_t unlockAndPostSurface(Surface* surface);
133 status_t unlockSurface(Surface* surface);
134
135 status_t lockSurface(Surface* surface,
136 Surface::SurfaceInfo* info,
137 Region* dirty,
138 bool blocking = true);
139
140 status_t nextBuffer(Surface* surface,
141 Surface::SurfaceInfo* info);
142
143 status_t destroySurface(SurfaceID sid);
144
145 void _init(const sp<ISurfaceComposer>& sm,
146 const sp<ISurfaceFlingerClient>& conn);
147 void _signal_server();
148 static void _send_dirty_region(layer_cblk_t* lcblk, const Region& dirty);
149
150 inline layer_state_t* _get_state_l(const sp<Surface>& surface);
151 layer_state_t* _lockLayerState(const sp<Surface>& surface);
152 inline void _unlockLayerState();
153
154 status_t validateSurface(
155 per_client_cblk_t const* cblk, Surface const * surface);
156
157 void pinHeap(const sp<IMemoryHeap>& heap);
158
159 mutable Mutex mLock;
160 layer_state_t* mPrebuiltLayerState;
161 SortedVector<layer_state_t> mStates;
162 int32_t mTransactionOpen;
163
164 // these don't need to be protected because they never change
165 // after assignment
166 status_t mStatus;
167 per_client_cblk_t* mControl;
168 sp<IMemory> mControlMemory;
169 sp<ISurfaceFlingerClient> mClient;
170 sp<IMemoryHeap> mSurfaceHeap;
171 uint8_t* mSurfaceHeapBase;
172 void* mGL;
173 SurfaceFlingerSynchro* mSignalServer;
174};
175
176}; // namespace android
177
178#endif // ANDROID_SURFACE_COMPOSER_CLIENT_H
179