blob: f537020b2673ddb1b83ae44ee1abc161f6c5f120 [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>
Mathias Agopian6d9b9df2013-02-13 15:26:48 -080024#include <binder/IMemory.h>
Mathias Agopiandd3423c2009-09-23 15:44:05 -070025
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080026#include <utils/RefBase.h>
Mathias Agopianb7e930d2010-06-01 15:12:58 -070027#include <utils/Singleton.h>
28#include <utils/SortedVector.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080029#include <utils/threads.h>
30
Svetoslavd85084b2014-03-20 10:28:31 -070031#include <ui/FrameStats.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080032#include <ui/PixelFormat.h>
Mathias Agopian9cce3252010-02-09 17:46:37 -080033
Mathias Agopianabe815d2013-03-19 22:22:21 -070034#include <gui/CpuConsumer.h>
Mathias Agopiane3c697f2013-02-14 17:11:02 -080035#include <gui/SurfaceControl.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080036
37namespace android {
38
39// ---------------------------------------------------------------------------
40
Colin Crossa2362b42016-09-26 13:48:25 -070041struct DisplayInfo;
Mathias Agopian698c0872011-06-28 19:09:31 -070042class Composer;
Dan Stozac4f471e2016-03-24 09:31:08 -070043class HdrCapabilities;
Mathias Agopian41f673c2011-11-17 17:48:35 -080044class ISurfaceComposerClient;
Andy McFadden2adaf042012-12-18 09:49:45 -080045class IGraphicBufferProducer;
Mathias Agopiana67932f2011-04-20 14:20:59 -070046class Region;
Mathias Agopianb7e930d2010-06-01 15:12:58 -070047
48// ---------------------------------------------------------------------------
49
Mathias Agopiand4784a32010-05-27 19:41:15 -070050class SurfaceComposerClient : public RefBase
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080051{
Mathias Agopian698c0872011-06-28 19:09:31 -070052 friend class Composer;
Jesse Hall6c913be2013-08-08 12:15:49 -070053public:
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080054 SurfaceComposerClient();
Robert Carr1db73f62016-12-21 12:58:51 -080055 SurfaceComposerClient(const sp<IGraphicBufferProducer>& parent);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080056 virtual ~SurfaceComposerClient();
57
58 // Always make sure we could initialize
59 status_t initCheck() const;
60
61 // Return the connection of this client
62 sp<IBinder> connection() const;
Jesse Hall6c913be2013-08-08 12:15:49 -070063
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080064 // Forcibly remove connection before all references have gone away.
65 void dispose();
66
Mathias Agopiane57f2922012-08-09 16:29:12 -070067 // callback when the composer is dies
68 status_t linkToComposerDeath(const sp<IBinder::DeathRecipient>& recipient,
69 void* cookie = NULL, uint32_t flags = 0);
70
Dan Stoza7f7da322014-05-02 15:26:25 -070071 // Get a list of supported configurations for a given display
72 static status_t getDisplayConfigs(const sp<IBinder>& display,
73 Vector<DisplayInfo>* configs);
74
75 // Get the DisplayInfo for the currently-active configuration
76 static status_t getDisplayInfo(const sp<IBinder>& display,
77 DisplayInfo* info);
78
79 // Get the index of the current active configuration (relative to the list
80 // returned by getDisplayInfo)
81 static int getActiveConfig(const sp<IBinder>& display);
82
83 // Set a new active configuration using an index relative to the list
84 // returned by getDisplayInfo
85 static status_t setActiveConfig(const sp<IBinder>& display, int id);
Mathias Agopiane57f2922012-08-09 16:29:12 -070086
Michael Wright28f24d02016-07-12 13:30:53 -070087 // Gets the list of supported color modes for the given display
88 static status_t getDisplayColorModes(const sp<IBinder>& display,
89 Vector<android_color_mode_t>* outColorModes);
90
91 // Gets the active color mode for the given display
92 static android_color_mode_t getActiveColorMode(const sp<IBinder>& display);
93
94 // Sets the active color mode for the given display
95 static status_t setActiveColorMode(const sp<IBinder>& display, android_color_mode_t colorMode);
96
Prashant Malani2c9b11f2014-05-25 01:36:31 -070097 /* Triggers screen on/off or low power mode and waits for it to complete */
98 static void setDisplayPowerMode(const sp<IBinder>& display, int mode);
Jeff Brown2a09bb32012-10-08 19:13:57 -070099
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800100 // ------------------------------------------------------------------------
101 // surface creation / destruction
102
103 //! Create a surface
Mathias Agopian01b76682009-04-16 20:04:08 -0700104 sp<SurfaceControl> createSurface(
Mathias Agopian285dbde2010-03-01 16:09:43 -0800105 const String8& name,// name of the surface
Mathias Agopiancbb288b2009-09-07 16:32:45 -0700106 uint32_t w, // width in pixel
107 uint32_t h, // height in pixel
108 PixelFormat format, // pixel-format desired
Robert Carr1f0a16a2016-10-24 16:27:39 -0700109 uint32_t flags = 0, // usage flags
110 SurfaceControl* parent = nullptr // parent
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800111 );
112
Jesse Hall6c913be2013-08-08 12:15:49 -0700113 //! Create a virtual display
Jamie Gennisdd3cb842012-10-19 18:19:11 -0700114 static sp<IBinder> createDisplay(const String8& displayName, bool secure);
Mathias Agopian285dbde2010-03-01 16:09:43 -0800115
Jesse Hall6c913be2013-08-08 12:15:49 -0700116 //! Destroy a virtual display
117 static void destroyDisplay(const sp<IBinder>& display);
118
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700119 //! Get the token for the existing default displays.
120 //! Possible values for id are eDisplayIdMain and eDisplayIdHdmi.
121 static sp<IBinder> getBuiltInDisplay(int32_t id);
122
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800123 // ------------------------------------------------------------------------
124 // Composer parameters
125 // All composer parameters must be changed within a transaction
126 // several surfaces can be updated in one transaction, all changes are
127 // committed at once when the transaction is closed.
Mathias Agopiane57f2922012-08-09 16:29:12 -0700128 // closeGlobalTransaction() requires an IPC with the server.
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800129
130 //! Open a composer transaction on all active SurfaceComposerClients.
131 static void openGlobalTransaction();
Jamie Gennis2d5e2302012-10-15 18:24:43 -0700132
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800133 //! Close a composer transaction on all active SurfaceComposerClients.
Jamie Gennis28378392011-10-12 17:39:00 -0700134 static void closeGlobalTransaction(bool synchronous = false);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800135
Sahil Dhanjuc1ba5c42016-06-07 20:09:20 -0700136 static status_t enableVSyncInjections(bool enable);
137
138 static status_t injectVSync(nsecs_t when);
139
Jamie Gennis2d5e2302012-10-15 18:24:43 -0700140 //! Flag the currently open transaction as an animation transaction.
141 static void setAnimationTransaction();
142
Mathias Agopianac9fa422013-02-11 16:40:36 -0800143 status_t hide(const sp<IBinder>& id);
144 status_t show(const sp<IBinder>& id);
145 status_t setFlags(const sp<IBinder>& id, uint32_t flags, uint32_t mask);
146 status_t setTransparentRegionHint(const sp<IBinder>& id, const Region& transparent);
Robert Carrae060832016-11-28 10:51:00 -0800147 status_t setLayer(const sp<IBinder>& id, int32_t layer);
Albert Chaulk6cf6af02016-11-22 13:52:43 -0500148 status_t setLayerInfo(const sp<IBinder>& id, uint32_t type, uint32_t appid);
Mathias Agopianac9fa422013-02-11 16:40:36 -0800149 status_t setAlpha(const sp<IBinder>& id, float alpha=1.0f);
150 status_t setMatrix(const sp<IBinder>& id, float dsdx, float dtdx, float dsdy, float dtdy);
151 status_t setPosition(const sp<IBinder>& id, float x, float y);
152 status_t setSize(const sp<IBinder>& id, uint32_t w, uint32_t h);
153 status_t setCrop(const sp<IBinder>& id, const Rect& crop);
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000154 status_t setFinalCrop(const sp<IBinder>& id, const Rect& crop);
Mathias Agopianac9fa422013-02-11 16:40:36 -0800155 status_t setLayerStack(const sp<IBinder>& id, uint32_t layerStack);
Dan Stoza7dde5992015-05-22 09:51:44 -0700156 status_t deferTransactionUntil(const sp<IBinder>& id,
157 const sp<IBinder>& handle, uint64_t frameNumber);
Robert Carr1db73f62016-12-21 12:58:51 -0800158 status_t reparentChildren(const sp<IBinder>& id,
159 const sp<IBinder>& newParentHandle);
Robert Carrc3574f72016-03-24 12:19:32 -0700160 status_t setOverrideScalingMode(const sp<IBinder>& id,
161 int32_t overrideScalingMode);
Robert Carr99e27f02016-06-16 15:18:02 -0700162 status_t setGeometryAppliesWithResize(const sp<IBinder>& id);
Robert Carr82364e32016-05-15 11:27:47 -0700163
Mathias Agopianac9fa422013-02-11 16:40:36 -0800164 status_t destroySurface(const sp<IBinder>& id);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800165
Svetoslavd85084b2014-03-20 10:28:31 -0700166 status_t clearLayerFrameStats(const sp<IBinder>& token) const;
167 status_t getLayerFrameStats(const sp<IBinder>& token, FrameStats* outStats) const;
168
Robert Carr367c5682016-06-20 11:55:28 -0700169 status_t getTransformToDisplayInverse(const sp<IBinder>& token,
170 bool* outTransformToDisplayInverse) const;
171
Svetoslavd85084b2014-03-20 10:28:31 -0700172 static status_t clearAnimationFrameStats();
173 static status_t getAnimationFrameStats(FrameStats* outStats);
174
Dan Stozac4f471e2016-03-24 09:31:08 -0700175 static status_t getHdrCapabilities(const sp<IBinder>& display,
176 HdrCapabilities* outCapabilities);
177
Pablo Ceballos1aad24c2016-08-04 10:24:22 -0700178 static status_t setDisplaySurface(const sp<IBinder>& token,
179 sp<IGraphicBufferProducer> bufferProducer);
Mathias Agopiane57f2922012-08-09 16:29:12 -0700180 static void setDisplayLayerStack(const sp<IBinder>& token,
181 uint32_t layerStack);
Michael Wright1f6078a2014-06-26 16:01:02 -0700182 static void setDisplaySize(const sp<IBinder>& token, uint32_t width, uint32_t height);
Mathias Agopian00e8c7a2012-09-04 19:30:46 -0700183
184 /* setDisplayProjection() defines the projection of layer stacks
185 * to a given display.
186 *
187 * - orientation defines the display's orientation.
188 * - layerStackRect defines which area of the window manager coordinate
189 * space will be used.
190 * - displayRect defines where on the display will layerStackRect be
191 * mapped to. displayRect is specified post-orientation, that is
192 * it uses the orientation seen by the end-user.
193 */
194 static void setDisplayProjection(const sp<IBinder>& token,
195 uint32_t orientation,
196 const Rect& layerStackRect,
197 const Rect& displayRect);
Mathias Agopiane57f2922012-08-09 16:29:12 -0700198
Mathias Agopian631f3582010-05-25 17:51:34 -0700199private:
Mathias Agopiand4784a32010-05-27 19:41:15 -0700200 virtual void onFirstRef();
Mathias Agopian698c0872011-06-28 19:09:31 -0700201 Composer& getComposer();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800202
Mathias Agopian698c0872011-06-28 19:09:31 -0700203 mutable Mutex mLock;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800204 status_t mStatus;
Mathias Agopian7e27f052010-05-28 14:22:23 -0700205 sp<ISurfaceComposerClient> mClient;
Mathias Agopian698c0872011-06-28 19:09:31 -0700206 Composer& mComposer;
Robert Carr1db73f62016-12-21 12:58:51 -0800207 wp<IGraphicBufferProducer> mParent;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800208};
209
Mathias Agopiand4784a32010-05-27 19:41:15 -0700210// ---------------------------------------------------------------------------
Mathias Agopian74c40c02010-09-29 13:02:36 -0700211
212class ScreenshotClient
213{
Mathias Agopian2a9fc492013-03-01 13:42:57 -0800214public:
Dan Stozac1879002014-05-22 15:59:05 -0700215 // if cropping isn't required, callers may pass in a default Rect, e.g.:
216 // capture(display, producer, Rect(), reqWidth, ...);
Mathias Agopian2a9fc492013-03-01 13:42:57 -0800217 static status_t capture(
218 const sp<IBinder>& display,
219 const sp<IGraphicBufferProducer>& producer,
Dan Stozac1879002014-05-22 15:59:05 -0700220 Rect sourceCrop, uint32_t reqWidth, uint32_t reqHeight,
Robert Carrae060832016-11-28 10:51:00 -0800221 int32_t minLayerZ, int32_t maxLayerZ,
Dan Stozac7014012014-02-14 15:03:43 -0800222 bool useIdentityTransform);
Robert Carr673134e2017-01-09 19:48:38 -0800223 static status_t captureToBuffer(
224 const sp<IBinder>& display,
225 Rect sourceCrop, uint32_t reqWidth, uint32_t reqHeight,
Robert Carrae060832016-11-28 10:51:00 -0800226 int32_t minLayerZ, int32_t maxLayerZ,
Robert Carr673134e2017-01-09 19:48:38 -0800227 bool useIdentityTransform,
228 uint32_t rotation,
229 sp<GraphicBuffer>* outbuffer);
Mathias Agopian2a9fc492013-03-01 13:42:57 -0800230private:
Mathias Agopianabe815d2013-03-19 22:22:21 -0700231 mutable sp<CpuConsumer> mCpuConsumer;
Dan Stoza6d5a7bb2014-03-13 11:39:09 -0700232 mutable sp<IGraphicBufferProducer> mProducer;
Mathias Agopianabe815d2013-03-19 22:22:21 -0700233 CpuConsumer::LockedBuffer mBuffer;
234 bool mHaveBuffer;
Mathias Agopian2a9fc492013-03-01 13:42:57 -0800235
Mathias Agopian74c40c02010-09-29 13:02:36 -0700236public:
237 ScreenshotClient();
Mathias Agopian8000d062013-03-26 18:15:35 -0700238 ~ScreenshotClient();
Mathias Agopian74c40c02010-09-29 13:02:36 -0700239
Dan Stozac1879002014-05-22 15:59:05 -0700240 // frees the previous screenshot and captures a new one
241 // if cropping isn't required, callers may pass in a default Rect, e.g.:
242 // update(display, Rect(), useIdentityTransform);
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700243 status_t update(const sp<IBinder>& display,
Dan Stozac1879002014-05-22 15:59:05 -0700244 Rect sourceCrop, bool useIdentityTransform);
245 status_t update(const sp<IBinder>& display,
246 Rect sourceCrop, uint32_t reqWidth, uint32_t reqHeight,
Dan Stozac7014012014-02-14 15:03:43 -0800247 bool useIdentityTransform);
248 status_t update(const sp<IBinder>& display,
Dan Stozac1879002014-05-22 15:59:05 -0700249 Rect sourceCrop, uint32_t reqWidth, uint32_t reqHeight,
Robert Carrae060832016-11-28 10:51:00 -0800250 int32_t minLayerZ, int32_t maxLayerZ,
Dan Stozac7014012014-02-14 15:03:43 -0800251 bool useIdentityTransform);
Riley Andrewsd15ef272014-09-04 16:19:44 -0700252 status_t update(const sp<IBinder>& display,
253 Rect sourceCrop, uint32_t reqWidth, uint32_t reqHeight,
Robert Carrae060832016-11-28 10:51:00 -0800254 int32_t minLayerZ, int32_t maxLayerZ,
Riley Andrewsd15ef272014-09-04 16:19:44 -0700255 bool useIdentityTransform, uint32_t rotation);
Mathias Agopian74c40c02010-09-29 13:02:36 -0700256
Mathias Agopianabe815d2013-03-19 22:22:21 -0700257 sp<CpuConsumer> getCpuConsumer() const;
258
Mathias Agopian74c40c02010-09-29 13:02:36 -0700259 // release memory occupied by the screenshot
260 void release();
261
262 // pixels are valid until this object is freed or
263 // release() or update() is called
264 void const* getPixels() const;
265
266 uint32_t getWidth() const;
267 uint32_t getHeight() const;
268 PixelFormat getFormat() const;
269 uint32_t getStride() const;
270 // size of allocated memory in bytes
271 size_t getSize() const;
272};
273
274// ---------------------------------------------------------------------------
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800275}; // namespace android
276
Mathias Agopian90ac7992012-02-25 18:48:35 -0800277#endif // ANDROID_GUI_SURFACE_COMPOSER_CLIENT_H