blob: 350b9878c7363a6c0085d0c82a0eb9841daee57b [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
31#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
Mathias Agopian9cce3252010-02-09 17:46:37 -080040class DisplayInfo;
Mathias Agopian698c0872011-06-28 19:09:31 -070041class Composer;
Mathias Agopian41f673c2011-11-17 17:48:35 -080042class ISurfaceComposerClient;
Andy McFadden2adaf042012-12-18 09:49:45 -080043class IGraphicBufferProducer;
Mathias Agopiana67932f2011-04-20 14:20:59 -070044class Region;
Mathias Agopianb7e930d2010-06-01 15:12:58 -070045
46// ---------------------------------------------------------------------------
47
Mathias Agopiand4784a32010-05-27 19:41:15 -070048class SurfaceComposerClient : public RefBase
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080049{
Mathias Agopian698c0872011-06-28 19:09:31 -070050 friend class Composer;
Jesse Hall6c913be2013-08-08 12:15:49 -070051public:
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080052 SurfaceComposerClient();
53 virtual ~SurfaceComposerClient();
54
55 // Always make sure we could initialize
56 status_t initCheck() const;
57
58 // Return the connection of this client
59 sp<IBinder> connection() const;
Jesse Hall6c913be2013-08-08 12:15:49 -070060
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080061 // Forcibly remove connection before all references have gone away.
62 void dispose();
63
Mathias Agopiane57f2922012-08-09 16:29:12 -070064 // callback when the composer is dies
65 status_t linkToComposerDeath(const sp<IBinder::DeathRecipient>& recipient,
66 void* cookie = NULL, uint32_t flags = 0);
67
68 // Get information about a display
Jeff Brown9d4e3d22012-08-24 20:00:51 -070069 static status_t getDisplayInfo(const sp<IBinder>& display, DisplayInfo* info);
Mathias Agopiane57f2922012-08-09 16:29:12 -070070
Jeff Brown2a09bb32012-10-08 19:13:57 -070071 /* triggers screen off and waits for it to complete */
72 static void blankDisplay(const sp<IBinder>& display);
73
74 /* triggers screen on and waits for it to complete */
75 static void unblankDisplay(const sp<IBinder>& display);
76
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080077 // ------------------------------------------------------------------------
78 // surface creation / destruction
79
80 //! Create a surface
Mathias Agopian01b76682009-04-16 20:04:08 -070081 sp<SurfaceControl> createSurface(
Mathias Agopian285dbde2010-03-01 16:09:43 -080082 const String8& name,// name of the surface
Mathias Agopiancbb288b2009-09-07 16:32:45 -070083 uint32_t w, // width in pixel
84 uint32_t h, // height in pixel
85 PixelFormat format, // pixel-format desired
86 uint32_t flags = 0 // usage flags
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080087 );
88
Jesse Hall6c913be2013-08-08 12:15:49 -070089 //! Create a virtual display
Jamie Gennisdd3cb842012-10-19 18:19:11 -070090 static sp<IBinder> createDisplay(const String8& displayName, bool secure);
Mathias Agopian285dbde2010-03-01 16:09:43 -080091
Jesse Hall6c913be2013-08-08 12:15:49 -070092 //! Destroy a virtual display
93 static void destroyDisplay(const sp<IBinder>& display);
94
Jeff Brown9d4e3d22012-08-24 20:00:51 -070095 //! Get the token for the existing default displays.
96 //! Possible values for id are eDisplayIdMain and eDisplayIdHdmi.
97 static sp<IBinder> getBuiltInDisplay(int32_t id);
98
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080099 // ------------------------------------------------------------------------
100 // Composer parameters
101 // All composer parameters must be changed within a transaction
102 // several surfaces can be updated in one transaction, all changes are
103 // committed at once when the transaction is closed.
Mathias Agopiane57f2922012-08-09 16:29:12 -0700104 // closeGlobalTransaction() requires an IPC with the server.
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800105
106 //! Open a composer transaction on all active SurfaceComposerClients.
107 static void openGlobalTransaction();
Jamie Gennis2d5e2302012-10-15 18:24:43 -0700108
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800109 //! Close a composer transaction on all active SurfaceComposerClients.
Jamie Gennis28378392011-10-12 17:39:00 -0700110 static void closeGlobalTransaction(bool synchronous = false);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800111
Jamie Gennis2d5e2302012-10-15 18:24:43 -0700112 //! Flag the currently open transaction as an animation transaction.
113 static void setAnimationTransaction();
114
Mathias Agopianac9fa422013-02-11 16:40:36 -0800115 status_t hide(const sp<IBinder>& id);
116 status_t show(const sp<IBinder>& id);
117 status_t setFlags(const sp<IBinder>& id, uint32_t flags, uint32_t mask);
118 status_t setTransparentRegionHint(const sp<IBinder>& id, const Region& transparent);
119 status_t setLayer(const sp<IBinder>& id, int32_t layer);
120 status_t setAlpha(const sp<IBinder>& id, float alpha=1.0f);
121 status_t setMatrix(const sp<IBinder>& id, float dsdx, float dtdx, float dsdy, float dtdy);
122 status_t setPosition(const sp<IBinder>& id, float x, float y);
123 status_t setSize(const sp<IBinder>& id, uint32_t w, uint32_t h);
124 status_t setCrop(const sp<IBinder>& id, const Rect& crop);
125 status_t setLayerStack(const sp<IBinder>& id, uint32_t layerStack);
126 status_t destroySurface(const sp<IBinder>& id);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800127
Mathias Agopiane57f2922012-08-09 16:29:12 -0700128 static void setDisplaySurface(const sp<IBinder>& token,
Andy McFadden2adaf042012-12-18 09:49:45 -0800129 const sp<IGraphicBufferProducer>& bufferProducer);
Mathias Agopiane57f2922012-08-09 16:29:12 -0700130 static void setDisplayLayerStack(const sp<IBinder>& token,
131 uint32_t layerStack);
Mathias Agopian00e8c7a2012-09-04 19:30:46 -0700132
133 /* setDisplayProjection() defines the projection of layer stacks
134 * to a given display.
135 *
136 * - orientation defines the display's orientation.
137 * - layerStackRect defines which area of the window manager coordinate
138 * space will be used.
139 * - displayRect defines where on the display will layerStackRect be
140 * mapped to. displayRect is specified post-orientation, that is
141 * it uses the orientation seen by the end-user.
142 */
143 static void setDisplayProjection(const sp<IBinder>& token,
144 uint32_t orientation,
145 const Rect& layerStackRect,
146 const Rect& displayRect);
Mathias Agopiane57f2922012-08-09 16:29:12 -0700147
Mathias Agopian631f3582010-05-25 17:51:34 -0700148private:
Mathias Agopiand4784a32010-05-27 19:41:15 -0700149 virtual void onFirstRef();
Mathias Agopian698c0872011-06-28 19:09:31 -0700150 Composer& getComposer();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800151
Mathias Agopian698c0872011-06-28 19:09:31 -0700152 mutable Mutex mLock;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800153 status_t mStatus;
Mathias Agopian7e27f052010-05-28 14:22:23 -0700154 sp<ISurfaceComposerClient> mClient;
Mathias Agopian698c0872011-06-28 19:09:31 -0700155 Composer& mComposer;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800156};
157
Mathias Agopiand4784a32010-05-27 19:41:15 -0700158// ---------------------------------------------------------------------------
Mathias Agopian74c40c02010-09-29 13:02:36 -0700159
160class ScreenshotClient
161{
Mathias Agopian2a9fc492013-03-01 13:42:57 -0800162public:
163 static status_t capture(
164 const sp<IBinder>& display,
165 const sp<IGraphicBufferProducer>& producer,
166 uint32_t reqWidth, uint32_t reqHeight,
Dan Stozac7014012014-02-14 15:03:43 -0800167 uint32_t minLayerZ, uint32_t maxLayerZ,
168 bool useIdentityTransform);
Mathias Agopian2a9fc492013-03-01 13:42:57 -0800169
170private:
Mathias Agopianabe815d2013-03-19 22:22:21 -0700171 mutable sp<CpuConsumer> mCpuConsumer;
Mathias Agopiandb89edc2013-08-02 01:40:18 -0700172 mutable sp<BufferQueue> mBufferQueue;
Mathias Agopianabe815d2013-03-19 22:22:21 -0700173 CpuConsumer::LockedBuffer mBuffer;
174 bool mHaveBuffer;
Mathias Agopian2a9fc492013-03-01 13:42:57 -0800175
Mathias Agopian74c40c02010-09-29 13:02:36 -0700176public:
177 ScreenshotClient();
Mathias Agopian8000d062013-03-26 18:15:35 -0700178 ~ScreenshotClient();
Mathias Agopian74c40c02010-09-29 13:02:36 -0700179
180 // frees the previous screenshot and capture a new one
Dan Stozac7014012014-02-14 15:03:43 -0800181 status_t update(const sp<IBinder>& display, bool useIdentityTransform);
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700182 status_t update(const sp<IBinder>& display,
183 uint32_t reqWidth, uint32_t reqHeight,
Dan Stozac7014012014-02-14 15:03:43 -0800184 bool useIdentityTransform);
185 status_t update(const sp<IBinder>& display,
186 uint32_t reqWidth, uint32_t reqHeight,
187 uint32_t minLayerZ, uint32_t maxLayerZ,
188 bool useIdentityTransform);
Mathias Agopian74c40c02010-09-29 13:02:36 -0700189
Mathias Agopianabe815d2013-03-19 22:22:21 -0700190 sp<CpuConsumer> getCpuConsumer() const;
191
Mathias Agopian74c40c02010-09-29 13:02:36 -0700192 // release memory occupied by the screenshot
193 void release();
194
195 // pixels are valid until this object is freed or
196 // release() or update() is called
197 void const* getPixels() const;
198
199 uint32_t getWidth() const;
200 uint32_t getHeight() const;
201 PixelFormat getFormat() const;
202 uint32_t getStride() const;
203 // size of allocated memory in bytes
204 size_t getSize() const;
205};
206
207// ---------------------------------------------------------------------------
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800208}; // namespace android
209
Mathias Agopian90ac7992012-02-25 18:48:35 -0800210#endif // ANDROID_GUI_SURFACE_COMPOSER_CLIENT_H