blob: 57c72c9d869c9de305d990c829c01e3485fef7cb [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 Agopian90ac7992012-02-25 18:48:35 -080017#ifndef ANDROID_GUI_SURFACE_COMPOSER_CLIENT_H
18#define ANDROID_GUI_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/RefBase.h>
Mathias Agopianb7e930d2010-06-01 15:12:58 -070026#include <utils/Singleton.h>
27#include <utils/SortedVector.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080028#include <utils/threads.h>
29
30#include <ui/PixelFormat.h>
Mathias Agopian9cce3252010-02-09 17:46:37 -080031
Mathias Agopian90ac7992012-02-25 18:48:35 -080032#include <gui/Surface.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080033
34namespace android {
35
36// ---------------------------------------------------------------------------
37
Mathias Agopian9cce3252010-02-09 17:46:37 -080038class DisplayInfo;
Mathias Agopian698c0872011-06-28 19:09:31 -070039class Composer;
Mathias Agopiana67932f2011-04-20 14:20:59 -070040class IMemoryHeap;
Mathias Agopian41f673c2011-11-17 17:48:35 -080041class ISurfaceComposerClient;
Jeff Brown9d4e3d22012-08-24 20:00:51 -070042class ISurfaceTexture;
Mathias Agopiana67932f2011-04-20 14:20:59 -070043class Region;
Mathias Agopianb7e930d2010-06-01 15:12:58 -070044
45// ---------------------------------------------------------------------------
46
Mathias Agopiand4784a32010-05-27 19:41:15 -070047class SurfaceComposerClient : public RefBase
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080048{
Mathias Agopian698c0872011-06-28 19:09:31 -070049 friend class Composer;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080050public:
51 SurfaceComposerClient();
52 virtual ~SurfaceComposerClient();
53
54 // Always make sure we could initialize
55 status_t initCheck() const;
56
57 // Return the connection of this client
58 sp<IBinder> connection() const;
59
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080060 // Forcibly remove connection before all references have gone away.
61 void dispose();
62
Mathias Agopiane57f2922012-08-09 16:29:12 -070063 // callback when the composer is dies
64 status_t linkToComposerDeath(const sp<IBinder::DeathRecipient>& recipient,
65 void* cookie = NULL, uint32_t flags = 0);
66
67 // Get information about a display
Jeff Brown9d4e3d22012-08-24 20:00:51 -070068 static status_t getDisplayInfo(const sp<IBinder>& display, DisplayInfo* info);
Mathias Agopiane57f2922012-08-09 16:29:12 -070069
Jeff Browna50b51c2012-08-27 17:06:39 -070070 // TODO: Remove me. Do not use.
71 // This is a compatibility shim for one product whose drivers are depending on
72 // this legacy function (when they shouldn't).
73 static status_t getDisplayInfo(int32_t displayId, DisplayInfo* info);
74
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080075 // ------------------------------------------------------------------------
76 // surface creation / destruction
77
78 //! Create a surface
Mathias Agopian01b76682009-04-16 20:04:08 -070079 sp<SurfaceControl> createSurface(
Mathias Agopian285dbde2010-03-01 16:09:43 -080080 const String8& name,// name of the surface
Mathias Agopiancbb288b2009-09-07 16:32:45 -070081 uint32_t w, // width in pixel
82 uint32_t h, // height in pixel
83 PixelFormat format, // pixel-format desired
84 uint32_t flags = 0 // usage flags
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080085 );
86
Jeff Brown9d4e3d22012-08-24 20:00:51 -070087 //! Create a display
Mathias Agopiane57f2922012-08-09 16:29:12 -070088 static sp<IBinder> createDisplay();
Mathias Agopian285dbde2010-03-01 16:09:43 -080089
Jeff Brown9d4e3d22012-08-24 20:00:51 -070090 //! Get the token for the existing default displays.
91 //! Possible values for id are eDisplayIdMain and eDisplayIdHdmi.
92 static sp<IBinder> getBuiltInDisplay(int32_t id);
93
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080094 // ------------------------------------------------------------------------
95 // Composer parameters
96 // All composer parameters must be changed within a transaction
97 // several surfaces can be updated in one transaction, all changes are
98 // committed at once when the transaction is closed.
Mathias Agopiane57f2922012-08-09 16:29:12 -070099 // closeGlobalTransaction() requires an IPC with the server.
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800100
101 //! Open a composer transaction on all active SurfaceComposerClients.
102 static void openGlobalTransaction();
103
104 //! Close a composer transaction on all active SurfaceComposerClients.
Jamie Gennis28378392011-10-12 17:39:00 -0700105 static void closeGlobalTransaction(bool synchronous = false);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800106
Mathias Agopian62185b72009-04-16 16:19:50 -0700107 status_t hide(SurfaceID id);
Jeff Brown380223b2012-08-26 22:49:35 -0700108 status_t show(SurfaceID id);
Mathias Agopian62185b72009-04-16 16:19:50 -0700109 status_t setFlags(SurfaceID id, uint32_t flags, uint32_t mask);
110 status_t setTransparentRegionHint(SurfaceID id, const Region& transparent);
111 status_t setLayer(SurfaceID id, int32_t layer);
112 status_t setAlpha(SurfaceID id, float alpha=1.0f);
Mathias Agopian62185b72009-04-16 16:19:50 -0700113 status_t setMatrix(SurfaceID id, float dsdx, float dtdx, float dsdy, float dtdy);
Mathias Agopian41b6aab2011-08-30 18:51:54 -0700114 status_t setPosition(SurfaceID id, float x, float y);
Mathias Agopian62185b72009-04-16 16:19:50 -0700115 status_t setSize(SurfaceID id, uint32_t w, uint32_t h);
Jamie Gennisf15a83f2012-05-10 20:43:55 -0700116 status_t setCrop(SurfaceID id, const Rect& crop);
Mathias Agopian87855782012-07-24 21:41:09 -0700117 status_t setLayerStack(SurfaceID id, uint32_t layerStack);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800118 status_t destroySurface(SurfaceID sid);
119
Mathias Agopiane57f2922012-08-09 16:29:12 -0700120 static void setDisplaySurface(const sp<IBinder>& token,
121 const sp<ISurfaceTexture>& surface);
122 static void setDisplayLayerStack(const sp<IBinder>& token,
123 uint32_t layerStack);
Mathias Agopian00e8c7a2012-09-04 19:30:46 -0700124
125 /* setDisplayProjection() defines the projection of layer stacks
126 * to a given display.
127 *
128 * - orientation defines the display's orientation.
129 * - layerStackRect defines which area of the window manager coordinate
130 * space will be used.
131 * - displayRect defines where on the display will layerStackRect be
132 * mapped to. displayRect is specified post-orientation, that is
133 * it uses the orientation seen by the end-user.
134 */
135 static void setDisplayProjection(const sp<IBinder>& token,
136 uint32_t orientation,
137 const Rect& layerStackRect,
138 const Rect& displayRect);
Mathias Agopiane57f2922012-08-09 16:29:12 -0700139
Mathias Agopian631f3582010-05-25 17:51:34 -0700140private:
Mathias Agopiand4784a32010-05-27 19:41:15 -0700141 virtual void onFirstRef();
Mathias Agopian698c0872011-06-28 19:09:31 -0700142 Composer& getComposer();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800143
Mathias Agopian698c0872011-06-28 19:09:31 -0700144 mutable Mutex mLock;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800145 status_t mStatus;
Mathias Agopian7e27f052010-05-28 14:22:23 -0700146 sp<ISurfaceComposerClient> mClient;
Mathias Agopian698c0872011-06-28 19:09:31 -0700147 Composer& mComposer;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800148};
149
Mathias Agopiand4784a32010-05-27 19:41:15 -0700150// ---------------------------------------------------------------------------
Mathias Agopian74c40c02010-09-29 13:02:36 -0700151
152class ScreenshotClient
153{
154 sp<IMemoryHeap> mHeap;
155 uint32_t mWidth;
156 uint32_t mHeight;
157 PixelFormat mFormat;
158public:
159 ScreenshotClient();
160
161 // frees the previous screenshot and capture a new one
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700162 status_t update(const sp<IBinder>& display);
163 status_t update(const sp<IBinder>& display,
164 uint32_t reqWidth, uint32_t reqHeight);
165 status_t update(const sp<IBinder>& display,
166 uint32_t reqWidth, uint32_t reqHeight,
Mathias Agopianbf2c6a62010-12-10 16:22:31 -0800167 uint32_t minLayerZ, uint32_t maxLayerZ);
Mathias Agopian74c40c02010-09-29 13:02:36 -0700168
169 // release memory occupied by the screenshot
170 void release();
171
172 // pixels are valid until this object is freed or
173 // release() or update() is called
174 void const* getPixels() const;
175
176 uint32_t getWidth() const;
177 uint32_t getHeight() const;
178 PixelFormat getFormat() const;
179 uint32_t getStride() const;
180 // size of allocated memory in bytes
181 size_t getSize() const;
182};
183
184// ---------------------------------------------------------------------------
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800185}; // namespace android
186
Mathias Agopian90ac7992012-02-25 18:48:35 -0800187#endif // ANDROID_GUI_SURFACE_COMPOSER_CLIENT_H