blob: 102aebc6fb367a6ca8cdd8c80a04975ed94f3acd [file] [log] [blame]
The Android Open Source Projectedbf3b62009-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
Mathias Agopian9cce3252010-02-09 17:46:37 -080017#ifndef ANDROID_SF_SURFACE_COMPOSER_CLIENT_H
18#define ANDROID_SF_SURFACE_COMPOSER_CLIENT_H
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080019
20#include <stdint.h>
21#include <sys/types.h>
22
Mathias Agopiandd3423c2009-09-23 15:44:05 -070023#include <binder/IBinder.h>
24
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080025#include <utils/SortedVector.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080026#include <utils/RefBase.h>
27#include <utils/threads.h>
28
29#include <ui/PixelFormat.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080030#include <ui/Region.h>
Mathias Agopian9cce3252010-02-09 17:46:37 -080031
32#include <surfaceflinger/Surface.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080033
34namespace android {
35
36// ---------------------------------------------------------------------------
37
38class Region;
Mathias Agopiancbb288b2009-09-07 16:32:45 -070039class SharedClient;
Mathias Agopian9cce3252010-02-09 17:46:37 -080040class ISurfaceComposer;
41class DisplayInfo;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080042
Mathias Agopiand4784a32010-05-27 19:41:15 -070043// ---------------------------------------------------------------------------
44
45class SurfaceComposerClient : public RefBase
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080046{
47public:
48 SurfaceComposerClient();
49 virtual ~SurfaceComposerClient();
50
51 // Always make sure we could initialize
52 status_t initCheck() const;
53
54 // Return the connection of this client
55 sp<IBinder> connection() const;
56
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080057 // Forcibly remove connection before all references have gone away.
58 void dispose();
59
60 // ------------------------------------------------------------------------
61 // surface creation / destruction
62
63 //! Create a surface
Mathias Agopian01b76682009-04-16 20:04:08 -070064 sp<SurfaceControl> createSurface(
Mathias Agopiancbb288b2009-09-07 16:32:45 -070065 int pid, // pid of the process the surface is for
Mathias Agopian285dbde2010-03-01 16:09:43 -080066 const String8& name,// name of the surface
Mathias Agopiancbb288b2009-09-07 16:32:45 -070067 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 Projectedbf3b62009-03-03 19:31:44 -080072 );
73
Mathias Agopian285dbde2010-03-01 16:09:43 -080074 sp<SurfaceControl> createSurface(
75 int pid, // pid of the process the surface is for
76 DisplayID display, // Display to create this surface on
77 uint32_t w, // width in pixel
78 uint32_t h, // height in pixel
79 PixelFormat format, // pixel-format desired
80 uint32_t flags = 0 // usage flags
81 );
82
83
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080084 // ------------------------------------------------------------------------
85 // Composer parameters
86 // All composer parameters must be changed within a transaction
87 // several surfaces can be updated in one transaction, all changes are
88 // committed at once when the transaction is closed.
89 // CloseTransaction() usually requires an IPC with the server.
90
91 //! Open a composer transaction
92 status_t openTransaction();
93
94 //! commit the transaction
95 status_t closeTransaction();
96
97 //! Open a composer transaction on all active SurfaceComposerClients.
98 static void openGlobalTransaction();
99
100 //! Close a composer transaction on all active SurfaceComposerClients.
101 static void closeGlobalTransaction();
102
103 //! Freeze the specified display but not transactions.
104 static status_t freezeDisplay(DisplayID dpy, uint32_t flags = 0);
105
106 //! Resume updates on the specified display.
107 static status_t unfreezeDisplay(DisplayID dpy, uint32_t flags = 0);
108
109 //! Set the orientation of the given display
Mathias Agopianc08731e2009-03-27 18:11:38 -0700110 static int setOrientation(DisplayID dpy, int orientation, uint32_t flags);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800111
112 // Query the number of displays
113 static ssize_t getNumberOfDisplays();
114
115 // Get information about a display
116 static status_t getDisplayInfo(DisplayID dpy, DisplayInfo* info);
117 static ssize_t getDisplayWidth(DisplayID dpy);
118 static ssize_t getDisplayHeight(DisplayID dpy);
119 static ssize_t getDisplayOrientation(DisplayID dpy);
120
Mathias Agopiandd3423c2009-09-23 15:44:05 -0700121 status_t linkToComposerDeath(const sp<IBinder::DeathRecipient>& recipient,
122 void* cookie = NULL, uint32_t flags = 0);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800123
Mathias Agopian62185b72009-04-16 16:19:50 -0700124 status_t hide(SurfaceID id);
125 status_t show(SurfaceID id, int32_t layer = -1);
126 status_t freeze(SurfaceID id);
127 status_t unfreeze(SurfaceID id);
128 status_t setFlags(SurfaceID id, uint32_t flags, uint32_t mask);
129 status_t setTransparentRegionHint(SurfaceID id, const Region& transparent);
130 status_t setLayer(SurfaceID id, int32_t layer);
131 status_t setAlpha(SurfaceID id, float alpha=1.0f);
132 status_t setFreezeTint(SurfaceID id, uint32_t tint);
133 status_t setMatrix(SurfaceID id, float dsdx, float dtdx, float dsdy, float dtdy);
134 status_t setPosition(SurfaceID id, int32_t x, int32_t y);
135 status_t setSize(SurfaceID id, uint32_t w, uint32_t h);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800136 status_t destroySurface(SurfaceID sid);
137
Mathias Agopian631f3582010-05-25 17:51:34 -0700138private:
Mathias Agopiand4784a32010-05-27 19:41:15 -0700139 virtual void onFirstRef();
Mathias Agopian631f3582010-05-25 17:51:34 -0700140 inline layer_state_t* get_state_l(SurfaceID id);
141 layer_state_t* lockLayerState(SurfaceID id);
142 inline void unlockLayerState();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800143
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800144 mutable Mutex mLock;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800145 SortedVector<layer_state_t> mStates;
146 int32_t mTransactionOpen;
Mathias Agopiand4784a32010-05-27 19:41:15 -0700147 layer_state_t* mPrebuiltLayerState;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800148
149 // these don't need to be protected because they never change
150 // after assignment
151 status_t mStatus;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800152 sp<ISurfaceFlingerClient> mClient;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800153};
154
Mathias Agopiand4784a32010-05-27 19:41:15 -0700155// ---------------------------------------------------------------------------
156
157class SurfaceClient : public RefBase
158{
159 // all these attributes are constants
160 status_t mStatus;
161 SharedClient* mControl;
162 sp<IMemoryHeap> mControlMemory;
163 sp<IBinder> mConnection;
164 sp<ISurfaceComposer> mSignalServer;
165 void init(const sp<IBinder>& conn);
166public:
167 explicit SurfaceClient(const sp<IBinder>& conn);
168 explicit SurfaceClient(const sp<SurfaceComposerClient>& client);
169 status_t initCheck() const;
170 SharedClient* getSharedClient() const;
171 void signalServer() const;
172};
173
174// ---------------------------------------------------------------------------
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800175}; // namespace android
176
Mathias Agopian9cce3252010-02-09 17:46:37 -0800177#endif // ANDROID_SF_SURFACE_COMPOSER_CLIENT_H
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800178