blob: 286f8850fd93cc10ff8bc935958ca64269c6f45e [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
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
Mathias Agopian01b76682009-04-16 20:04:08 -070065 sp<SurfaceControl> createSurface(
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080066 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 // ------------------------------------------------------------------------
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 Agopianc08731e2009-03-27 18:11:38 -0700100 static int setOrientation(DisplayID dpy, int orientation, uint32_t flags);
The Android Open Source Projectedbf3b62009-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
111
112private:
113 friend class Surface;
Mathias Agopian62185b72009-04-16 16:19:50 -0700114 friend class SurfaceControl;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800115
116 SurfaceComposerClient(const sp<ISurfaceComposer>& sm,
117 const sp<IBinder>& conn);
118
Mathias Agopian62185b72009-04-16 16:19:50 -0700119 status_t hide(SurfaceID id);
120 status_t show(SurfaceID id, int32_t layer = -1);
121 status_t freeze(SurfaceID id);
122 status_t unfreeze(SurfaceID id);
123 status_t setFlags(SurfaceID id, uint32_t flags, uint32_t mask);
124 status_t setTransparentRegionHint(SurfaceID id, const Region& transparent);
125 status_t setLayer(SurfaceID id, int32_t layer);
126 status_t setAlpha(SurfaceID id, float alpha=1.0f);
127 status_t setFreezeTint(SurfaceID id, uint32_t tint);
128 status_t setMatrix(SurfaceID id, float dsdx, float dtdx, float dsdy, float dtdy);
129 status_t setPosition(SurfaceID id, int32_t x, int32_t y);
130 status_t setSize(SurfaceID id, uint32_t w, uint32_t h);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800131
Mathias Agopian076b1cc2009-04-10 14:24:30 -0700132 void signalServer();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800133
134 status_t destroySurface(SurfaceID sid);
135
136 void _init(const sp<ISurfaceComposer>& sm,
137 const sp<ISurfaceFlingerClient>& conn);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800138
Mathias Agopian62185b72009-04-16 16:19:50 -0700139 inline layer_state_t* _get_state_l(SurfaceID id);
140 layer_state_t* _lockLayerState(SurfaceID id);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800141 inline void _unlockLayerState();
142
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800143 mutable Mutex mLock;
144 layer_state_t* mPrebuiltLayerState;
145 SortedVector<layer_state_t> mStates;
146 int32_t mTransactionOpen;
147
148 // these don't need to be protected because they never change
149 // after assignment
150 status_t mStatus;
151 per_client_cblk_t* mControl;
Mathias Agopian7303c6b2009-07-02 18:11:53 -0700152 sp<IMemoryHeap> mControlMemory;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800153 sp<ISurfaceFlingerClient> mClient;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800154 SurfaceFlingerSynchro* mSignalServer;
155};
156
157}; // namespace android
158
159#endif // ANDROID_SURFACE_COMPOSER_CLIENT_H
160