blob: ec310cf6f9c397c3e9480e0f2f973c28175b8bef [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
Svetoslavd85084b2014-03-20 10:28:31 -070030#include <ui/FrameStats.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080031#include <ui/PixelFormat.h>
Mathias Agopian9cce3252010-02-09 17:46:37 -080032
Mathias Agopianabe815d2013-03-19 22:22:21 -070033#include <gui/CpuConsumer.h>
Mathias Agopiane3c697f2013-02-14 17:11:02 -080034#include <gui/SurfaceControl.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080035
36namespace android {
37
38// ---------------------------------------------------------------------------
39
Colin Crossa2362b42016-09-26 13:48:25 -070040struct DisplayInfo;
Mathias Agopian698c0872011-06-28 19:09:31 -070041class Composer;
Dan Stozac4f471e2016-03-24 09:31:08 -070042class HdrCapabilities;
Mathias Agopian41f673c2011-11-17 17:48:35 -080043class ISurfaceComposerClient;
Andy McFadden2adaf042012-12-18 09:49:45 -080044class IGraphicBufferProducer;
Mathias Agopiana67932f2011-04-20 14:20:59 -070045class Region;
Mathias Agopianb7e930d2010-06-01 15:12:58 -070046
47// ---------------------------------------------------------------------------
48
Mathias Agopiand4784a32010-05-27 19:41:15 -070049class SurfaceComposerClient : public RefBase
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080050{
Mathias Agopian698c0872011-06-28 19:09:31 -070051 friend class Composer;
Jesse Hall6c913be2013-08-08 12:15:49 -070052public:
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080053 SurfaceComposerClient();
Robert Carr1db73f62016-12-21 12:58:51 -080054 SurfaceComposerClient(const sp<IGraphicBufferProducer>& parent);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080055 virtual ~SurfaceComposerClient();
56
57 // Always make sure we could initialize
58 status_t initCheck() const;
59
60 // Return the connection of this client
61 sp<IBinder> connection() const;
Jesse Hall6c913be2013-08-08 12:15:49 -070062
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080063 // Forcibly remove connection before all references have gone away.
64 void dispose();
65
Mathias Agopiane57f2922012-08-09 16:29:12 -070066 // callback when the composer is dies
67 status_t linkToComposerDeath(const sp<IBinder::DeathRecipient>& recipient,
68 void* cookie = NULL, uint32_t flags = 0);
69
Dan Stoza7f7da322014-05-02 15:26:25 -070070 // Get a list of supported configurations for a given display
71 static status_t getDisplayConfigs(const sp<IBinder>& display,
72 Vector<DisplayInfo>* configs);
73
74 // Get the DisplayInfo for the currently-active configuration
75 static status_t getDisplayInfo(const sp<IBinder>& display,
76 DisplayInfo* info);
77
78 // Get the index of the current active configuration (relative to the list
79 // returned by getDisplayInfo)
80 static int getActiveConfig(const sp<IBinder>& display);
81
82 // Set a new active configuration using an index relative to the list
83 // returned by getDisplayInfo
84 static status_t setActiveConfig(const sp<IBinder>& display, int id);
Mathias Agopiane57f2922012-08-09 16:29:12 -070085
Michael Wright28f24d02016-07-12 13:30:53 -070086 // Gets the list of supported color modes for the given display
87 static status_t getDisplayColorModes(const sp<IBinder>& display,
88 Vector<android_color_mode_t>* outColorModes);
89
90 // Gets the active color mode for the given display
91 static android_color_mode_t getActiveColorMode(const sp<IBinder>& display);
92
93 // Sets the active color mode for the given display
94 static status_t setActiveColorMode(const sp<IBinder>& display, android_color_mode_t colorMode);
95
Prashant Malani2c9b11f2014-05-25 01:36:31 -070096 /* Triggers screen on/off or low power mode and waits for it to complete */
97 static void setDisplayPowerMode(const sp<IBinder>& display, int mode);
Jeff Brown2a09bb32012-10-08 19:13:57 -070098
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080099 // ------------------------------------------------------------------------
100 // surface creation / destruction
101
102 //! Create a surface
Mathias Agopian01b76682009-04-16 20:04:08 -0700103 sp<SurfaceControl> createSurface(
Mathias Agopian285dbde2010-03-01 16:09:43 -0800104 const String8& name,// name of the surface
Mathias Agopiancbb288b2009-09-07 16:32:45 -0700105 uint32_t w, // width in pixel
106 uint32_t h, // height in pixel
107 PixelFormat format, // pixel-format desired
Albert Chaulk479c60c2017-01-27 14:21:34 -0500108 uint32_t flags = 0, // usage flags
109 SurfaceControl* parent = nullptr, // parent
110 uint32_t windowType = 0, // from WindowManager.java (STATUS_BAR, INPUT_METHOD, etc.)
111 uint32_t ownerUid = 0 // UID of the task
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800112 );
113
Jesse Hall6c913be2013-08-08 12:15:49 -0700114 //! Create a virtual display
Jamie Gennisdd3cb842012-10-19 18:19:11 -0700115 static sp<IBinder> createDisplay(const String8& displayName, bool secure);
Mathias Agopian285dbde2010-03-01 16:09:43 -0800116
Jesse Hall6c913be2013-08-08 12:15:49 -0700117 //! Destroy a virtual display
118 static void destroyDisplay(const sp<IBinder>& display);
119
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700120 //! Get the token for the existing default displays.
121 //! Possible values for id are eDisplayIdMain and eDisplayIdHdmi.
122 static sp<IBinder> getBuiltInDisplay(int32_t id);
123
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800124 // ------------------------------------------------------------------------
125 // Composer parameters
126 // All composer parameters must be changed within a transaction
127 // several surfaces can be updated in one transaction, all changes are
128 // committed at once when the transaction is closed.
Mathias Agopiane57f2922012-08-09 16:29:12 -0700129 // closeGlobalTransaction() requires an IPC with the server.
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800130
131 //! Open a composer transaction on all active SurfaceComposerClients.
132 static void openGlobalTransaction();
Jamie Gennis2d5e2302012-10-15 18:24:43 -0700133
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800134 //! Close a composer transaction on all active SurfaceComposerClients.
Jamie Gennis28378392011-10-12 17:39:00 -0700135 static void closeGlobalTransaction(bool synchronous = false);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800136
Sahil Dhanjuc1ba5c42016-06-07 20:09:20 -0700137 static status_t enableVSyncInjections(bool enable);
138
139 static status_t injectVSync(nsecs_t when);
140
Jamie Gennis2d5e2302012-10-15 18:24:43 -0700141 //! Flag the currently open transaction as an animation transaction.
142 static void setAnimationTransaction();
143
Mathias Agopianac9fa422013-02-11 16:40:36 -0800144 status_t hide(const sp<IBinder>& id);
145 status_t show(const sp<IBinder>& id);
146 status_t setFlags(const sp<IBinder>& id, uint32_t flags, uint32_t mask);
147 status_t setTransparentRegionHint(const sp<IBinder>& id, const Region& transparent);
Robert Carrae060832016-11-28 10:51:00 -0800148 status_t setLayer(const sp<IBinder>& id, int32_t layer);
Robert Carrdb66e622017-04-10 16:55:57 -0700149 status_t setRelativeLayer(const sp<IBinder>& id,
150 const sp<IBinder>& relativeTo, int32_t layer);
Mathias Agopianac9fa422013-02-11 16:40:36 -0800151 status_t setAlpha(const sp<IBinder>& id, float alpha=1.0f);
Robert Carrcb6e1e32017-02-21 19:48:26 -0800152 status_t setMatrix(const sp<IBinder>& id, float dsdx, float dtdx, float dtdy, float dsdy);
Mathias Agopianac9fa422013-02-11 16:40:36 -0800153 status_t setPosition(const sp<IBinder>& id, float x, float y);
154 status_t setSize(const sp<IBinder>& id, uint32_t w, uint32_t h);
155 status_t setCrop(const sp<IBinder>& id, const Rect& crop);
Pablo Ceballosacbe6782016-03-04 17:54:21 +0000156 status_t setFinalCrop(const sp<IBinder>& id, const Rect& crop);
Mathias Agopianac9fa422013-02-11 16:40:36 -0800157 status_t setLayerStack(const sp<IBinder>& id, uint32_t layerStack);
Dan Stoza7dde5992015-05-22 09:51:44 -0700158 status_t deferTransactionUntil(const sp<IBinder>& id,
159 const sp<IBinder>& handle, uint64_t frameNumber);
Robert Carr0d480722017-01-10 16:42:54 -0800160 status_t deferTransactionUntil(const sp<IBinder>& id,
161 const sp<Surface>& handle, uint64_t frameNumber);
Robert Carr1db73f62016-12-21 12:58:51 -0800162 status_t reparentChildren(const sp<IBinder>& id,
163 const sp<IBinder>& newParentHandle);
Robert Carr9524cb32017-02-13 11:32:32 -0800164 status_t detachChildren(const sp<IBinder>& id);
Robert Carrc3574f72016-03-24 12:19:32 -0700165 status_t setOverrideScalingMode(const sp<IBinder>& id,
166 int32_t overrideScalingMode);
Robert Carr99e27f02016-06-16 15:18:02 -0700167 status_t setGeometryAppliesWithResize(const sp<IBinder>& id);
Robert Carr82364e32016-05-15 11:27:47 -0700168
Mathias Agopianac9fa422013-02-11 16:40:36 -0800169 status_t destroySurface(const sp<IBinder>& id);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800170
Svetoslavd85084b2014-03-20 10:28:31 -0700171 status_t clearLayerFrameStats(const sp<IBinder>& token) const;
172 status_t getLayerFrameStats(const sp<IBinder>& token, FrameStats* outStats) const;
173
174 static status_t clearAnimationFrameStats();
175 static status_t getAnimationFrameStats(FrameStats* outStats);
176
Dan Stozac4f471e2016-03-24 09:31:08 -0700177 static status_t getHdrCapabilities(const sp<IBinder>& display,
178 HdrCapabilities* outCapabilities);
179
Pablo Ceballos1aad24c2016-08-04 10:24:22 -0700180 static status_t setDisplaySurface(const sp<IBinder>& token,
181 sp<IGraphicBufferProducer> bufferProducer);
Mathias Agopiane57f2922012-08-09 16:29:12 -0700182 static void setDisplayLayerStack(const sp<IBinder>& token,
183 uint32_t layerStack);
Michael Wright1f6078a2014-06-26 16:01:02 -0700184 static void setDisplaySize(const sp<IBinder>& token, uint32_t width, uint32_t height);
Mathias Agopian00e8c7a2012-09-04 19:30:46 -0700185
186 /* setDisplayProjection() defines the projection of layer stacks
187 * to a given display.
188 *
189 * - orientation defines the display's orientation.
190 * - layerStackRect defines which area of the window manager coordinate
191 * space will be used.
192 * - displayRect defines where on the display will layerStackRect be
193 * mapped to. displayRect is specified post-orientation, that is
194 * it uses the orientation seen by the end-user.
195 */
196 static void setDisplayProjection(const sp<IBinder>& token,
197 uint32_t orientation,
198 const Rect& layerStackRect,
199 const Rect& displayRect);
Mathias Agopiane57f2922012-08-09 16:29:12 -0700200
Mathias Agopian631f3582010-05-25 17:51:34 -0700201private:
Mathias Agopiand4784a32010-05-27 19:41:15 -0700202 virtual void onFirstRef();
Mathias Agopian698c0872011-06-28 19:09:31 -0700203 Composer& getComposer();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800204
Mathias Agopian698c0872011-06-28 19:09:31 -0700205 mutable Mutex mLock;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800206 status_t mStatus;
Mathias Agopian7e27f052010-05-28 14:22:23 -0700207 sp<ISurfaceComposerClient> mClient;
Mathias Agopian698c0872011-06-28 19:09:31 -0700208 Composer& mComposer;
Robert Carr1db73f62016-12-21 12:58:51 -0800209 wp<IGraphicBufferProducer> mParent;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800210};
211
Mathias Agopiand4784a32010-05-27 19:41:15 -0700212// ---------------------------------------------------------------------------
Mathias Agopian74c40c02010-09-29 13:02:36 -0700213
214class ScreenshotClient
215{
Mathias Agopian2a9fc492013-03-01 13:42:57 -0800216public:
Dan Stozac1879002014-05-22 15:59:05 -0700217 // if cropping isn't required, callers may pass in a default Rect, e.g.:
218 // capture(display, producer, Rect(), reqWidth, ...);
Mathias Agopian2a9fc492013-03-01 13:42:57 -0800219 static status_t capture(
220 const sp<IBinder>& display,
221 const sp<IGraphicBufferProducer>& producer,
Dan Stozac1879002014-05-22 15:59:05 -0700222 Rect sourceCrop, uint32_t reqWidth, uint32_t reqHeight,
Robert Carrae060832016-11-28 10:51:00 -0800223 int32_t minLayerZ, int32_t maxLayerZ,
Dan Stozac7014012014-02-14 15:03:43 -0800224 bool useIdentityTransform);
Robert Carr673134e2017-01-09 19:48:38 -0800225 static status_t captureToBuffer(
226 const sp<IBinder>& display,
227 Rect sourceCrop, uint32_t reqWidth, uint32_t reqHeight,
Robert Carrae060832016-11-28 10:51:00 -0800228 int32_t minLayerZ, int32_t maxLayerZ,
Robert Carr673134e2017-01-09 19:48:38 -0800229 bool useIdentityTransform,
230 uint32_t rotation,
231 sp<GraphicBuffer>* outbuffer);
Mathias Agopian2a9fc492013-03-01 13:42:57 -0800232private:
Mathias Agopianabe815d2013-03-19 22:22:21 -0700233 mutable sp<CpuConsumer> mCpuConsumer;
Dan Stoza6d5a7bb2014-03-13 11:39:09 -0700234 mutable sp<IGraphicBufferProducer> mProducer;
Mathias Agopianabe815d2013-03-19 22:22:21 -0700235 CpuConsumer::LockedBuffer mBuffer;
236 bool mHaveBuffer;
Mathias Agopian2a9fc492013-03-01 13:42:57 -0800237
Mathias Agopian74c40c02010-09-29 13:02:36 -0700238public:
239 ScreenshotClient();
Mathias Agopian8000d062013-03-26 18:15:35 -0700240 ~ScreenshotClient();
Mathias Agopian74c40c02010-09-29 13:02:36 -0700241
Dan Stozac1879002014-05-22 15:59:05 -0700242 // frees the previous screenshot and captures a new one
243 // if cropping isn't required, callers may pass in a default Rect, e.g.:
244 // update(display, Rect(), useIdentityTransform);
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700245 status_t update(const sp<IBinder>& display,
Dan Stozac1879002014-05-22 15:59:05 -0700246 Rect sourceCrop, bool useIdentityTransform);
247 status_t update(const sp<IBinder>& display,
248 Rect sourceCrop, uint32_t reqWidth, uint32_t reqHeight,
Dan Stozac7014012014-02-14 15:03:43 -0800249 bool useIdentityTransform);
250 status_t update(const sp<IBinder>& display,
Dan Stozac1879002014-05-22 15:59:05 -0700251 Rect sourceCrop, uint32_t reqWidth, uint32_t reqHeight,
Robert Carrae060832016-11-28 10:51:00 -0800252 int32_t minLayerZ, int32_t maxLayerZ,
Dan Stozac7014012014-02-14 15:03:43 -0800253 bool useIdentityTransform);
Riley Andrewsd15ef272014-09-04 16:19:44 -0700254 status_t update(const sp<IBinder>& display,
255 Rect sourceCrop, uint32_t reqWidth, uint32_t reqHeight,
Robert Carrae060832016-11-28 10:51:00 -0800256 int32_t minLayerZ, int32_t maxLayerZ,
Riley Andrewsd15ef272014-09-04 16:19:44 -0700257 bool useIdentityTransform, uint32_t rotation);
Mathias Agopian74c40c02010-09-29 13:02:36 -0700258
Mathias Agopianabe815d2013-03-19 22:22:21 -0700259 sp<CpuConsumer> getCpuConsumer() const;
260
Mathias Agopian74c40c02010-09-29 13:02:36 -0700261 // release memory occupied by the screenshot
262 void release();
263
264 // pixels are valid until this object is freed or
265 // release() or update() is called
266 void const* getPixels() const;
267
268 uint32_t getWidth() const;
269 uint32_t getHeight() const;
270 PixelFormat getFormat() const;
271 uint32_t getStride() const;
272 // size of allocated memory in bytes
273 size_t getSize() const;
274};
275
276// ---------------------------------------------------------------------------
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800277}; // namespace android
278
Mathias Agopian90ac7992012-02-25 18:48:35 -0800279#endif // ANDROID_GUI_SURFACE_COMPOSER_CLIENT_H