blob: 38c931d2301f08e1ee539984db90dddad31d83a6 [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 Agopiane3c697f2013-02-14 17:11:02 -080033#include <gui/SurfaceControl.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080034
35namespace android {
36
37// ---------------------------------------------------------------------------
38
Mathias Agopian9cce3252010-02-09 17:46:37 -080039class DisplayInfo;
Mathias Agopian698c0872011-06-28 19:09:31 -070040class Composer;
Mathias Agopiana67932f2011-04-20 14:20:59 -070041class IMemoryHeap;
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;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080051public:
52 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;
60
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
Jeff Brown9d4e3d22012-08-24 20:00:51 -070089 //! Create a 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
Jeff Brown9d4e3d22012-08-24 20:00:51 -070092 //! Get the token for the existing default displays.
93 //! Possible values for id are eDisplayIdMain and eDisplayIdHdmi.
94 static sp<IBinder> getBuiltInDisplay(int32_t id);
95
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080096 // ------------------------------------------------------------------------
97 // Composer parameters
98 // All composer parameters must be changed within a transaction
99 // several surfaces can be updated in one transaction, all changes are
100 // committed at once when the transaction is closed.
Mathias Agopiane57f2922012-08-09 16:29:12 -0700101 // closeGlobalTransaction() requires an IPC with the server.
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800102
103 //! Open a composer transaction on all active SurfaceComposerClients.
104 static void openGlobalTransaction();
Jamie Gennis2d5e2302012-10-15 18:24:43 -0700105
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800106 //! Close a composer transaction on all active SurfaceComposerClients.
Jamie Gennis28378392011-10-12 17:39:00 -0700107 static void closeGlobalTransaction(bool synchronous = false);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800108
Jamie Gennis2d5e2302012-10-15 18:24:43 -0700109 //! Flag the currently open transaction as an animation transaction.
110 static void setAnimationTransaction();
111
Mathias Agopianac9fa422013-02-11 16:40:36 -0800112 status_t hide(const sp<IBinder>& id);
113 status_t show(const sp<IBinder>& id);
114 status_t setFlags(const sp<IBinder>& id, uint32_t flags, uint32_t mask);
115 status_t setTransparentRegionHint(const sp<IBinder>& id, const Region& transparent);
116 status_t setLayer(const sp<IBinder>& id, int32_t layer);
117 status_t setAlpha(const sp<IBinder>& id, float alpha=1.0f);
118 status_t setMatrix(const sp<IBinder>& id, float dsdx, float dtdx, float dsdy, float dtdy);
119 status_t setPosition(const sp<IBinder>& id, float x, float y);
120 status_t setSize(const sp<IBinder>& id, uint32_t w, uint32_t h);
121 status_t setCrop(const sp<IBinder>& id, const Rect& crop);
122 status_t setLayerStack(const sp<IBinder>& id, uint32_t layerStack);
123 status_t destroySurface(const sp<IBinder>& id);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800124
Mathias Agopiane57f2922012-08-09 16:29:12 -0700125 static void setDisplaySurface(const sp<IBinder>& token,
Andy McFadden2adaf042012-12-18 09:49:45 -0800126 const sp<IGraphicBufferProducer>& bufferProducer);
Mathias Agopiane57f2922012-08-09 16:29:12 -0700127 static void setDisplayLayerStack(const sp<IBinder>& token,
128 uint32_t layerStack);
Mathias Agopian00e8c7a2012-09-04 19:30:46 -0700129
130 /* setDisplayProjection() defines the projection of layer stacks
131 * to a given display.
132 *
133 * - orientation defines the display's orientation.
134 * - layerStackRect defines which area of the window manager coordinate
135 * space will be used.
136 * - displayRect defines where on the display will layerStackRect be
137 * mapped to. displayRect is specified post-orientation, that is
138 * it uses the orientation seen by the end-user.
139 */
140 static void setDisplayProjection(const sp<IBinder>& token,
141 uint32_t orientation,
142 const Rect& layerStackRect,
143 const Rect& displayRect);
Mathias Agopiane57f2922012-08-09 16:29:12 -0700144
Mathias Agopian631f3582010-05-25 17:51:34 -0700145private:
Mathias Agopiand4784a32010-05-27 19:41:15 -0700146 virtual void onFirstRef();
Mathias Agopian698c0872011-06-28 19:09:31 -0700147 Composer& getComposer();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800148
Mathias Agopian698c0872011-06-28 19:09:31 -0700149 mutable Mutex mLock;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800150 status_t mStatus;
Mathias Agopian7e27f052010-05-28 14:22:23 -0700151 sp<ISurfaceComposerClient> mClient;
Mathias Agopian698c0872011-06-28 19:09:31 -0700152 Composer& mComposer;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800153};
154
Mathias Agopiand4784a32010-05-27 19:41:15 -0700155// ---------------------------------------------------------------------------
Mathias Agopian74c40c02010-09-29 13:02:36 -0700156
157class ScreenshotClient
158{
Mathias Agopian2a9fc492013-03-01 13:42:57 -0800159public:
160 static status_t capture(
161 const sp<IBinder>& display,
162 const sp<IGraphicBufferProducer>& producer,
163 uint32_t reqWidth, uint32_t reqHeight,
164 uint32_t minLayerZ, uint32_t maxLayerZ);
165
166private:
Mathias Agopian74c40c02010-09-29 13:02:36 -0700167 sp<IMemoryHeap> mHeap;
168 uint32_t mWidth;
169 uint32_t mHeight;
170 PixelFormat mFormat;
Mathias Agopian2a9fc492013-03-01 13:42:57 -0800171
Mathias Agopian74c40c02010-09-29 13:02:36 -0700172public:
173 ScreenshotClient();
174
175 // frees the previous screenshot and capture a new one
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700176 status_t update(const sp<IBinder>& display);
177 status_t update(const sp<IBinder>& display,
178 uint32_t reqWidth, uint32_t reqHeight);
179 status_t update(const sp<IBinder>& display,
180 uint32_t reqWidth, uint32_t reqHeight,
Mathias Agopianbf2c6a62010-12-10 16:22:31 -0800181 uint32_t minLayerZ, uint32_t maxLayerZ);
Mathias Agopian74c40c02010-09-29 13:02:36 -0700182
183 // release memory occupied by the screenshot
184 void release();
185
186 // pixels are valid until this object is freed or
187 // release() or update() is called
188 void const* getPixels() const;
189
190 uint32_t getWidth() const;
191 uint32_t getHeight() const;
192 PixelFormat getFormat() const;
193 uint32_t getStride() const;
194 // size of allocated memory in bytes
195 size_t getSize() const;
196};
197
198// ---------------------------------------------------------------------------
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800199}; // namespace android
200
Mathias Agopian90ac7992012-02-25 18:48:35 -0800201#endif // ANDROID_GUI_SURFACE_COMPOSER_CLIENT_H