blob: 839603824f9c13a4d951ad8cbe4533c71398c32c [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
43class SurfaceComposerClient : virtual public RefBase
44{
45public:
46 SurfaceComposerClient();
47 virtual ~SurfaceComposerClient();
48
49 // Always make sure we could initialize
50 status_t initCheck() const;
51
52 // Return the connection of this client
53 sp<IBinder> connection() const;
54
55 // Retrieve a client for an existing connection.
56 static sp<SurfaceComposerClient>
57 clientForConnection(const sp<IBinder>& conn);
58
59 // Forcibly remove connection before all references have gone away.
60 void dispose();
61
62 // ------------------------------------------------------------------------
63 // surface creation / destruction
64
65 //! Create a surface
Mathias Agopian01b76682009-04-16 20:04:08 -070066 sp<SurfaceControl> createSurface(
Mathias Agopiancbb288b2009-09-07 16:32:45 -070067 int pid, // pid of the process the surface is for
Mathias Agopian285dbde2010-03-01 16:09:43 -080068 const String8& name,// name of the surface
Mathias Agopiancbb288b2009-09-07 16:32:45 -070069 DisplayID display, // Display to create this surface on
70 uint32_t w, // width in pixel
71 uint32_t h, // height in pixel
72 PixelFormat format, // pixel-format desired
73 uint32_t flags = 0 // usage flags
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080074 );
75
Mathias Agopian285dbde2010-03-01 16:09:43 -080076 sp<SurfaceControl> createSurface(
77 int pid, // pid of the process the surface is for
78 DisplayID display, // Display to create this surface on
79 uint32_t w, // width in pixel
80 uint32_t h, // height in pixel
81 PixelFormat format, // pixel-format desired
82 uint32_t flags = 0 // usage flags
83 );
84
85
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080086 // ------------------------------------------------------------------------
87 // Composer parameters
88 // All composer parameters must be changed within a transaction
89 // several surfaces can be updated in one transaction, all changes are
90 // committed at once when the transaction is closed.
91 // CloseTransaction() usually requires an IPC with the server.
92
93 //! Open a composer transaction
94 status_t openTransaction();
95
96 //! commit the transaction
97 status_t closeTransaction();
98
99 //! Open a composer transaction on all active SurfaceComposerClients.
100 static void openGlobalTransaction();
101
102 //! Close a composer transaction on all active SurfaceComposerClients.
103 static void closeGlobalTransaction();
104
105 //! Freeze the specified display but not transactions.
106 static status_t freezeDisplay(DisplayID dpy, uint32_t flags = 0);
107
108 //! Resume updates on the specified display.
109 static status_t unfreezeDisplay(DisplayID dpy, uint32_t flags = 0);
110
111 //! Set the orientation of the given display
Mathias Agopianc08731e2009-03-27 18:11:38 -0700112 static int setOrientation(DisplayID dpy, int orientation, uint32_t flags);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800113
114 // Query the number of displays
115 static ssize_t getNumberOfDisplays();
116
117 // Get information about a display
118 static status_t getDisplayInfo(DisplayID dpy, DisplayInfo* info);
119 static ssize_t getDisplayWidth(DisplayID dpy);
120 static ssize_t getDisplayHeight(DisplayID dpy);
121 static ssize_t getDisplayOrientation(DisplayID dpy);
122
Mathias Agopiandd3423c2009-09-23 15:44:05 -0700123 status_t linkToComposerDeath(const sp<IBinder::DeathRecipient>& recipient,
124 void* cookie = NULL, uint32_t flags = 0);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800125
Mathias Agopian62185b72009-04-16 16:19:50 -0700126 status_t hide(SurfaceID id);
127 status_t show(SurfaceID id, int32_t layer = -1);
128 status_t freeze(SurfaceID id);
129 status_t unfreeze(SurfaceID id);
130 status_t setFlags(SurfaceID id, uint32_t flags, uint32_t mask);
131 status_t setTransparentRegionHint(SurfaceID id, const Region& transparent);
132 status_t setLayer(SurfaceID id, int32_t layer);
133 status_t setAlpha(SurfaceID id, float alpha=1.0f);
134 status_t setFreezeTint(SurfaceID id, uint32_t tint);
135 status_t setMatrix(SurfaceID id, float dsdx, float dtdx, float dsdy, float dtdy);
136 status_t setPosition(SurfaceID id, int32_t x, int32_t y);
137 status_t setSize(SurfaceID id, uint32_t w, uint32_t h);
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700138 void signalServer();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800139 status_t destroySurface(SurfaceID sid);
140
Mathias Agopian631f3582010-05-25 17:51:34 -0700141 SharedClient* getSharedClient() const;
142
143private:
144 SurfaceComposerClient(const sp<ISurfaceComposer>& sm,
145 const sp<IBinder>& conn);
146
147 void init(const sp<ISurfaceComposer>& sm,
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800148 const sp<ISurfaceFlingerClient>& conn);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800149
Mathias Agopian631f3582010-05-25 17:51:34 -0700150 inline layer_state_t* get_state_l(SurfaceID id);
151 layer_state_t* lockLayerState(SurfaceID id);
152 inline void unlockLayerState();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800153
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800154 mutable Mutex mLock;
155 layer_state_t* mPrebuiltLayerState;
156 SortedVector<layer_state_t> mStates;
157 int32_t mTransactionOpen;
158
159 // these don't need to be protected because they never change
160 // after assignment
161 status_t mStatus;
Mathias Agopiancbb288b2009-09-07 16:32:45 -0700162 SharedClient* mControl;
Mathias Agopian7303c6b2009-07-02 18:11:53 -0700163 sp<IMemoryHeap> mControlMemory;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800164 sp<ISurfaceFlingerClient> mClient;
Mathias Agopiane7005012009-10-07 16:44:10 -0700165 sp<ISurfaceComposer> mSignalServer;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800166};
167
168}; // namespace android
169
Mathias Agopian9cce3252010-02-09 17:46:37 -0800170#endif // ANDROID_SF_SURFACE_COMPOSER_CLIENT_H
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800171