2 * Copyright (C) 2007 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #ifndef ANDROID_GUI_SURFACE_COMPOSER_CLIENT_H
18 #define ANDROID_GUI_SURFACE_COMPOSER_CLIENT_H
21 #include <sys/types.h>
23 #include <binder/IBinder.h>
24 #include <binder/IMemory.h>
26 #include <utils/RefBase.h>
27 #include <utils/Singleton.h>
28 #include <utils/SortedVector.h>
29 #include <utils/threads.h>
31 #include <ui/FrameStats.h>
32 #include <ui/PixelFormat.h>
34 #include <gui/CpuConsumer.h>
35 #include <gui/SurfaceControl.h>
39 // ---------------------------------------------------------------------------
43 class HdrCapabilities;
44 class ISurfaceComposerClient;
45 class IGraphicBufferProducer;
48 // ---------------------------------------------------------------------------
50 class SurfaceComposerClient : public RefBase
52 friend class Composer;
54 SurfaceComposerClient();
55 virtual ~SurfaceComposerClient();
57 // Always make sure we could initialize
58 status_t initCheck() const;
60 // Return the connection of this client
61 sp<IBinder> connection() const;
63 // Forcibly remove connection before all references have gone away.
66 // callback when the composer is dies
67 status_t linkToComposerDeath(const sp<IBinder::DeathRecipient>& recipient,
68 void* cookie = NULL, uint32_t flags = 0);
70 // Get a list of supported configurations for a given display
71 static status_t getDisplayConfigs(const sp<IBinder>& display,
72 Vector<DisplayInfo>* configs);
74 // Get the DisplayInfo for the currently-active configuration
75 static status_t getDisplayInfo(const sp<IBinder>& display,
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);
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);
86 /* Triggers screen on/off or low power mode and waits for it to complete */
87 static void setDisplayPowerMode(const sp<IBinder>& display, int mode);
89 // ------------------------------------------------------------------------
90 // surface creation / destruction
93 sp<SurfaceControl> createSurface(
94 const String8& name,// name of the surface
95 uint32_t w, // width in pixel
96 uint32_t h, // height in pixel
97 PixelFormat format, // pixel-format desired
98 uint32_t flags = 0 // usage flags
101 //! Create a virtual display
102 static sp<IBinder> createDisplay(const String8& displayName, bool secure);
104 //! Destroy a virtual display
105 static void destroyDisplay(const sp<IBinder>& display);
107 //! Get the token for the existing default displays.
108 //! Possible values for id are eDisplayIdMain and eDisplayIdHdmi.
109 static sp<IBinder> getBuiltInDisplay(int32_t id);
111 // ------------------------------------------------------------------------
112 // Composer parameters
113 // All composer parameters must be changed within a transaction
114 // several surfaces can be updated in one transaction, all changes are
115 // committed at once when the transaction is closed.
116 // closeGlobalTransaction() requires an IPC with the server.
118 //! Open a composer transaction on all active SurfaceComposerClients.
119 static void openGlobalTransaction();
121 //! Close a composer transaction on all active SurfaceComposerClients.
122 static void closeGlobalTransaction(bool synchronous = false);
124 //! Flag the currently open transaction as an animation transaction.
125 static void setAnimationTransaction();
127 status_t hide(const sp<IBinder>& id);
128 status_t show(const sp<IBinder>& id);
129 status_t setFlags(const sp<IBinder>& id, uint32_t flags, uint32_t mask);
130 status_t setTransparentRegionHint(const sp<IBinder>& id, const Region& transparent);
131 status_t setLayer(const sp<IBinder>& id, uint32_t layer);
132 status_t setAlpha(const sp<IBinder>& id, float alpha=1.0f);
133 status_t setMatrix(const sp<IBinder>& id, float dsdx, float dtdx, float dsdy, float dtdy);
134 status_t setPosition(const sp<IBinder>& id, float x, float y);
135 status_t setSize(const sp<IBinder>& id, uint32_t w, uint32_t h);
136 status_t setCrop(const sp<IBinder>& id, const Rect& crop);
137 status_t setFinalCrop(const sp<IBinder>& id, const Rect& crop);
138 status_t setColor(const sp<IBinder>& id, uint32_t color);
139 status_t setLayerStack(const sp<IBinder>& id, uint32_t layerStack);
140 status_t deferTransactionUntil(const sp<IBinder>& id,
141 const sp<IBinder>& handle, uint64_t frameNumber);
142 status_t setOverrideScalingMode(const sp<IBinder>& id,
143 int32_t overrideScalingMode);
144 status_t setPositionAppliesWithResize(const sp<IBinder>& id);
146 status_t destroySurface(const sp<IBinder>& id);
148 status_t clearLayerFrameStats(const sp<IBinder>& token) const;
149 status_t getLayerFrameStats(const sp<IBinder>& token, FrameStats* outStats) const;
151 static status_t clearAnimationFrameStats();
152 static status_t getAnimationFrameStats(FrameStats* outStats);
154 static status_t getHdrCapabilities(const sp<IBinder>& display,
155 HdrCapabilities* outCapabilities);
157 static void setDisplaySurface(const sp<IBinder>& token,
158 const sp<IGraphicBufferProducer>& bufferProducer);
159 static void setDisplayLayerStack(const sp<IBinder>& token,
160 uint32_t layerStack);
161 static void setDisplaySize(const sp<IBinder>& token, uint32_t width, uint32_t height);
163 /* setDisplayProjection() defines the projection of layer stacks
164 * to a given display.
166 * - orientation defines the display's orientation.
167 * - layerStackRect defines which area of the window manager coordinate
168 * space will be used.
169 * - displayRect defines where on the display will layerStackRect be
170 * mapped to. displayRect is specified post-orientation, that is
171 * it uses the orientation seen by the end-user.
173 static void setDisplayProjection(const sp<IBinder>& token,
174 uint32_t orientation,
175 const Rect& layerStackRect,
176 const Rect& displayRect);
178 status_t setBlur(const sp<IBinder>& id, float blur);
179 status_t setBlurMaskSurface(const sp<IBinder>& id, const sp<IBinder>& maskSurfaceId);
180 status_t setBlurMaskSampling(const sp<IBinder>& id, uint32_t blurMaskSampling);
181 status_t setBlurMaskAlphaThreshold(const sp<IBinder>& id, float alpha);
184 virtual void onFirstRef();
185 Composer& getComposer();
189 sp<ISurfaceComposerClient> mClient;
193 // ---------------------------------------------------------------------------
195 class ScreenshotClient
198 // if cropping isn't required, callers may pass in a default Rect, e.g.:
199 // capture(display, producer, Rect(), reqWidth, ...);
200 static status_t capture(
201 const sp<IBinder>& display,
202 const sp<IGraphicBufferProducer>& producer,
203 Rect sourceCrop, uint32_t reqWidth, uint32_t reqHeight,
204 uint32_t minLayerZ, uint32_t maxLayerZ,
205 bool useIdentityTransform);
208 mutable sp<CpuConsumer> mCpuConsumer;
209 mutable sp<IGraphicBufferProducer> mProducer;
210 CpuConsumer::LockedBuffer mBuffer;
217 // frees the previous screenshot and captures a new one
218 // if cropping isn't required, callers may pass in a default Rect, e.g.:
219 // update(display, Rect(), useIdentityTransform);
220 status_t update(const sp<IBinder>& display,
221 Rect sourceCrop, bool useIdentityTransform);
222 status_t update(const sp<IBinder>& display,
223 Rect sourceCrop, uint32_t reqWidth, uint32_t reqHeight,
224 bool useIdentityTransform);
225 status_t update(const sp<IBinder>& display,
226 Rect sourceCrop, uint32_t reqWidth, uint32_t reqHeight,
227 uint32_t minLayerZ, uint32_t maxLayerZ,
228 bool useIdentityTransform);
229 status_t update(const sp<IBinder>& display,
230 Rect sourceCrop, uint32_t reqWidth, uint32_t reqHeight,
231 uint32_t minLayerZ, uint32_t maxLayerZ,
232 bool useIdentityTransform, uint32_t rotation);
234 sp<CpuConsumer> getCpuConsumer() const;
236 // release memory occupied by the screenshot
239 // pixels are valid until this object is freed or
240 // release() or update() is called
241 void const* getPixels() const;
243 uint32_t getWidth() const;
244 uint32_t getHeight() const;
245 PixelFormat getFormat() const;
246 uint32_t getStride() const;
247 // size of allocated memory in bytes
248 size_t getSize() const;
251 // ---------------------------------------------------------------------------
252 }; // namespace android
254 #endif // ANDROID_GUI_SURFACE_COMPOSER_CLIENT_H