blob: 6a53ccbea654f81699d02284efdf37d144f06b94 [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
Mathias Agopian9cce3252010-02-09 17:46:37 -080041class DisplayInfo;
Mathias Agopian698c0872011-06-28 19:09:31 -070042class Composer;
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();
54 virtual ~SurfaceComposerClient();
55
56 // Always make sure we could initialize
57 status_t initCheck() const;
58
59 // Return the connection of this client
60 sp<IBinder> connection() const;
Jesse Hall6c913be2013-08-08 12:15:49 -070061
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080062 // Forcibly remove connection before all references have gone away.
63 void dispose();
64
Mathias Agopiane57f2922012-08-09 16:29:12 -070065 // callback when the composer is dies
66 status_t linkToComposerDeath(const sp<IBinder::DeathRecipient>& recipient,
67 void* cookie = NULL, uint32_t flags = 0);
68
69 // Get information about a display
Jeff Brown9d4e3d22012-08-24 20:00:51 -070070 static status_t getDisplayInfo(const sp<IBinder>& display, DisplayInfo* info);
Mathias Agopiane57f2922012-08-09 16:29:12 -070071
Jeff Brown2a09bb32012-10-08 19:13:57 -070072 /* triggers screen off and waits for it to complete */
73 static void blankDisplay(const sp<IBinder>& display);
74
75 /* triggers screen on and waits for it to complete */
76 static void unblankDisplay(const sp<IBinder>& display);
77
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080078 // ------------------------------------------------------------------------
79 // surface creation / destruction
80
81 //! Create a surface
Mathias Agopian01b76682009-04-16 20:04:08 -070082 sp<SurfaceControl> createSurface(
Mathias Agopian285dbde2010-03-01 16:09:43 -080083 const String8& name,// name of the surface
Mathias Agopiancbb288b2009-09-07 16:32:45 -070084 uint32_t w, // width in pixel
85 uint32_t h, // height in pixel
86 PixelFormat format, // pixel-format desired
87 uint32_t flags = 0 // usage flags
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080088 );
89
Jesse Hall6c913be2013-08-08 12:15:49 -070090 //! Create a virtual display
Jamie Gennisdd3cb842012-10-19 18:19:11 -070091 static sp<IBinder> createDisplay(const String8& displayName, bool secure);
Mathias Agopian285dbde2010-03-01 16:09:43 -080092
Jesse Hall6c913be2013-08-08 12:15:49 -070093 //! Destroy a virtual display
94 static void destroyDisplay(const sp<IBinder>& display);
95
Jeff Brown9d4e3d22012-08-24 20:00:51 -070096 //! Get the token for the existing default displays.
97 //! Possible values for id are eDisplayIdMain and eDisplayIdHdmi.
98 static sp<IBinder> getBuiltInDisplay(int32_t id);
99
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800100 // ------------------------------------------------------------------------
101 // Composer parameters
102 // All composer parameters must be changed within a transaction
103 // several surfaces can be updated in one transaction, all changes are
104 // committed at once when the transaction is closed.
Mathias Agopiane57f2922012-08-09 16:29:12 -0700105 // closeGlobalTransaction() requires an IPC with the server.
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800106
107 //! Open a composer transaction on all active SurfaceComposerClients.
108 static void openGlobalTransaction();
Jamie Gennis2d5e2302012-10-15 18:24:43 -0700109
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800110 //! Close a composer transaction on all active SurfaceComposerClients.
Jamie Gennis28378392011-10-12 17:39:00 -0700111 static void closeGlobalTransaction(bool synchronous = false);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800112
Jamie Gennis2d5e2302012-10-15 18:24:43 -0700113 //! Flag the currently open transaction as an animation transaction.
114 static void setAnimationTransaction();
115
Mathias Agopianac9fa422013-02-11 16:40:36 -0800116 status_t hide(const sp<IBinder>& id);
117 status_t show(const sp<IBinder>& id);
118 status_t setFlags(const sp<IBinder>& id, uint32_t flags, uint32_t mask);
119 status_t setTransparentRegionHint(const sp<IBinder>& id, const Region& transparent);
120 status_t setLayer(const sp<IBinder>& id, int32_t layer);
121 status_t setAlpha(const sp<IBinder>& id, float alpha=1.0f);
122 status_t setMatrix(const sp<IBinder>& id, float dsdx, float dtdx, float dsdy, float dtdy);
123 status_t setPosition(const sp<IBinder>& id, float x, float y);
124 status_t setSize(const sp<IBinder>& id, uint32_t w, uint32_t h);
125 status_t setCrop(const sp<IBinder>& id, const Rect& crop);
126 status_t setLayerStack(const sp<IBinder>& id, uint32_t layerStack);
127 status_t destroySurface(const sp<IBinder>& id);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800128
Svetoslavd85084b2014-03-20 10:28:31 -0700129 status_t clearLayerFrameStats(const sp<IBinder>& token) const;
130 status_t getLayerFrameStats(const sp<IBinder>& token, FrameStats* outStats) const;
131
132 static status_t clearAnimationFrameStats();
133 static status_t getAnimationFrameStats(FrameStats* outStats);
134
Mathias Agopiane57f2922012-08-09 16:29:12 -0700135 static void setDisplaySurface(const sp<IBinder>& token,
Andy McFadden2adaf042012-12-18 09:49:45 -0800136 const sp<IGraphicBufferProducer>& bufferProducer);
Mathias Agopiane57f2922012-08-09 16:29:12 -0700137 static void setDisplayLayerStack(const sp<IBinder>& token,
138 uint32_t layerStack);
Mathias Agopian00e8c7a2012-09-04 19:30:46 -0700139
140 /* setDisplayProjection() defines the projection of layer stacks
141 * to a given display.
142 *
143 * - orientation defines the display's orientation.
144 * - layerStackRect defines which area of the window manager coordinate
145 * space will be used.
146 * - displayRect defines where on the display will layerStackRect be
147 * mapped to. displayRect is specified post-orientation, that is
148 * it uses the orientation seen by the end-user.
149 */
150 static void setDisplayProjection(const sp<IBinder>& token,
151 uint32_t orientation,
152 const Rect& layerStackRect,
153 const Rect& displayRect);
Mathias Agopiane57f2922012-08-09 16:29:12 -0700154
Mathias Agopian631f3582010-05-25 17:51:34 -0700155private:
Mathias Agopiand4784a32010-05-27 19:41:15 -0700156 virtual void onFirstRef();
Mathias Agopian698c0872011-06-28 19:09:31 -0700157 Composer& getComposer();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800158
Mathias Agopian698c0872011-06-28 19:09:31 -0700159 mutable Mutex mLock;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800160 status_t mStatus;
Mathias Agopian7e27f052010-05-28 14:22:23 -0700161 sp<ISurfaceComposerClient> mClient;
Mathias Agopian698c0872011-06-28 19:09:31 -0700162 Composer& mComposer;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800163};
164
Mathias Agopiand4784a32010-05-27 19:41:15 -0700165// ---------------------------------------------------------------------------
Mathias Agopian74c40c02010-09-29 13:02:36 -0700166
167class ScreenshotClient
168{
Mathias Agopian2a9fc492013-03-01 13:42:57 -0800169public:
170 static status_t capture(
171 const sp<IBinder>& display,
172 const sp<IGraphicBufferProducer>& producer,
173 uint32_t reqWidth, uint32_t reqHeight,
Dan Stozac7014012014-02-14 15:03:43 -0800174 uint32_t minLayerZ, uint32_t maxLayerZ,
175 bool useIdentityTransform);
Mathias Agopian2a9fc492013-03-01 13:42:57 -0800176
177private:
Mathias Agopianabe815d2013-03-19 22:22:21 -0700178 mutable sp<CpuConsumer> mCpuConsumer;
Dan Stoza6d5a7bb2014-03-13 11:39:09 -0700179 mutable sp<IGraphicBufferProducer> mProducer;
Mathias Agopianabe815d2013-03-19 22:22:21 -0700180 CpuConsumer::LockedBuffer mBuffer;
181 bool mHaveBuffer;
Mathias Agopian2a9fc492013-03-01 13:42:57 -0800182
Mathias Agopian74c40c02010-09-29 13:02:36 -0700183public:
184 ScreenshotClient();
Mathias Agopian8000d062013-03-26 18:15:35 -0700185 ~ScreenshotClient();
Mathias Agopian74c40c02010-09-29 13:02:36 -0700186
187 // frees the previous screenshot and capture a new one
Dan Stozac7014012014-02-14 15:03:43 -0800188 status_t update(const sp<IBinder>& display, bool useIdentityTransform);
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700189 status_t update(const sp<IBinder>& display,
190 uint32_t reqWidth, uint32_t reqHeight,
Dan Stozac7014012014-02-14 15:03:43 -0800191 bool useIdentityTransform);
192 status_t update(const sp<IBinder>& display,
193 uint32_t reqWidth, uint32_t reqHeight,
194 uint32_t minLayerZ, uint32_t maxLayerZ,
195 bool useIdentityTransform);
Mathias Agopian74c40c02010-09-29 13:02:36 -0700196
Mathias Agopianabe815d2013-03-19 22:22:21 -0700197 sp<CpuConsumer> getCpuConsumer() const;
198
Mathias Agopian74c40c02010-09-29 13:02:36 -0700199 // release memory occupied by the screenshot
200 void release();
201
202 // pixels are valid until this object is freed or
203 // release() or update() is called
204 void const* getPixels() const;
205
206 uint32_t getWidth() const;
207 uint32_t getHeight() const;
208 PixelFormat getFormat() const;
209 uint32_t getStride() const;
210 // size of allocated memory in bytes
211 size_t getSize() const;
212};
213
214// ---------------------------------------------------------------------------
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800215}; // namespace android
216
Mathias Agopian90ac7992012-02-25 18:48:35 -0800217#endif // ANDROID_GUI_SURFACE_COMPOSER_CLIENT_H