blob: 49e83c0f24e7842f8f85a8d66a2d64b354641e59 [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
68 DisplayID display, // Display to create this surface on
69 uint32_t w, // width in pixel
70 uint32_t h, // height in pixel
71 PixelFormat format, // pixel-format desired
72 uint32_t flags = 0 // usage flags
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080073 );
74
75 // ------------------------------------------------------------------------
76 // Composer parameters
77 // All composer parameters must be changed within a transaction
78 // several surfaces can be updated in one transaction, all changes are
79 // committed at once when the transaction is closed.
80 // CloseTransaction() usually requires an IPC with the server.
81
82 //! Open a composer transaction
83 status_t openTransaction();
84
85 //! commit the transaction
86 status_t closeTransaction();
87
88 //! Open a composer transaction on all active SurfaceComposerClients.
89 static void openGlobalTransaction();
90
91 //! Close a composer transaction on all active SurfaceComposerClients.
92 static void closeGlobalTransaction();
93
94 //! Freeze the specified display but not transactions.
95 static status_t freezeDisplay(DisplayID dpy, uint32_t flags = 0);
96
97 //! Resume updates on the specified display.
98 static status_t unfreezeDisplay(DisplayID dpy, uint32_t flags = 0);
99
100 //! Set the orientation of the given display
Mathias Agopianc08731e2009-03-27 18:11:38 -0700101 static int setOrientation(DisplayID dpy, int orientation, uint32_t flags);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800102
103 // Query the number of displays
104 static ssize_t getNumberOfDisplays();
105
106 // Get information about a display
107 static status_t getDisplayInfo(DisplayID dpy, DisplayInfo* info);
108 static ssize_t getDisplayWidth(DisplayID dpy);
109 static ssize_t getDisplayHeight(DisplayID dpy);
110 static ssize_t getDisplayOrientation(DisplayID dpy);
111
Mathias Agopiandd3423c2009-09-23 15:44:05 -0700112 status_t linkToComposerDeath(const sp<IBinder::DeathRecipient>& recipient,
113 void* cookie = NULL, uint32_t flags = 0);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800114
115private:
116 friend class Surface;
Mathias Agopian62185b72009-04-16 16:19:50 -0700117 friend class SurfaceControl;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800118
119 SurfaceComposerClient(const sp<ISurfaceComposer>& sm,
120 const sp<IBinder>& conn);
121
Mathias Agopian62185b72009-04-16 16:19:50 -0700122 status_t hide(SurfaceID id);
123 status_t show(SurfaceID id, int32_t layer = -1);
124 status_t freeze(SurfaceID id);
125 status_t unfreeze(SurfaceID id);
126 status_t setFlags(SurfaceID id, uint32_t flags, uint32_t mask);
127 status_t setTransparentRegionHint(SurfaceID id, const Region& transparent);
128 status_t setLayer(SurfaceID id, int32_t layer);
129 status_t setAlpha(SurfaceID id, float alpha=1.0f);
130 status_t setFreezeTint(SurfaceID id, uint32_t tint);
131 status_t setMatrix(SurfaceID id, float dsdx, float dtdx, float dsdy, float dtdy);
132 status_t setPosition(SurfaceID id, int32_t x, int32_t y);
133 status_t setSize(SurfaceID id, uint32_t w, uint32_t h);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800134
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700135 void signalServer();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800136
137 status_t destroySurface(SurfaceID sid);
138
139 void _init(const sp<ISurfaceComposer>& sm,
140 const sp<ISurfaceFlingerClient>& conn);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800141
Mathias Agopian62185b72009-04-16 16:19:50 -0700142 inline layer_state_t* _get_state_l(SurfaceID id);
143 layer_state_t* _lockLayerState(SurfaceID id);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800144 inline void _unlockLayerState();
145
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800146 mutable Mutex mLock;
147 layer_state_t* mPrebuiltLayerState;
148 SortedVector<layer_state_t> mStates;
149 int32_t mTransactionOpen;
150
151 // these don't need to be protected because they never change
152 // after assignment
153 status_t mStatus;
Mathias Agopiancbb288b2009-09-07 16:32:45 -0700154 SharedClient* mControl;
Mathias Agopian7303c6b2009-07-02 18:11:53 -0700155 sp<IMemoryHeap> mControlMemory;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800156 sp<ISurfaceFlingerClient> mClient;
Mathias Agopiane7005012009-10-07 16:44:10 -0700157 sp<ISurfaceComposer> mSignalServer;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800158};
159
160}; // namespace android
161
Mathias Agopian9cce3252010-02-09 17:46:37 -0800162#endif // ANDROID_SF_SURFACE_COMPOSER_CLIENT_H
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800163