OSDN Git Service

SurfaceFlinger: Native changes to add blur effect
[android-x86/frameworks-native.git] / include / gui / SurfaceComposerClient.h
1 /*
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
17 #ifndef ANDROID_GUI_SURFACE_COMPOSER_CLIENT_H
18 #define ANDROID_GUI_SURFACE_COMPOSER_CLIENT_H
19
20 #include <stdint.h>
21 #include <sys/types.h>
22
23 #include <binder/IBinder.h>
24 #include <binder/IMemory.h>
25
26 #include <utils/RefBase.h>
27 #include <utils/Singleton.h>
28 #include <utils/SortedVector.h>
29 #include <utils/threads.h>
30
31 #include <ui/FrameStats.h>
32 #include <ui/PixelFormat.h>
33
34 #include <gui/CpuConsumer.h>
35 #include <gui/SurfaceControl.h>
36
37 namespace android {
38
39 // ---------------------------------------------------------------------------
40
41 class DisplayInfo;
42 class Composer;
43 class HdrCapabilities;
44 class ISurfaceComposerClient;
45 class IGraphicBufferProducer;
46 class Region;
47
48 // ---------------------------------------------------------------------------
49
50 class SurfaceComposerClient : public RefBase
51 {
52     friend class Composer;
53 public:
54                 SurfaceComposerClient();
55     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;
62
63     // Forcibly remove connection before all references have gone away.
64     void        dispose();
65
66     // callback when the composer is dies
67     status_t linkToComposerDeath(const sp<IBinder::DeathRecipient>& recipient,
68             void* cookie = NULL, uint32_t flags = 0);
69
70     // 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);
85
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);
88
89     // ------------------------------------------------------------------------
90     // surface creation / destruction
91
92     //! Create a surface
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
99     );
100
101     //! Create a virtual display
102     static sp<IBinder> createDisplay(const String8& displayName, bool secure);
103
104     //! Destroy a virtual display
105     static void destroyDisplay(const sp<IBinder>& display);
106
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);
110
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.
117
118     //! Open a composer transaction on all active SurfaceComposerClients.
119     static void openGlobalTransaction();
120
121     //! Close a composer transaction on all active SurfaceComposerClients.
122     static void closeGlobalTransaction(bool synchronous = false);
123
124     //! Flag the currently open transaction as an animation transaction.
125     static void setAnimationTransaction();
126
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);
145
146     status_t    destroySurface(const sp<IBinder>& id);
147
148     status_t clearLayerFrameStats(const sp<IBinder>& token) const;
149     status_t getLayerFrameStats(const sp<IBinder>& token, FrameStats* outStats) const;
150
151     static status_t clearAnimationFrameStats();
152     static status_t getAnimationFrameStats(FrameStats* outStats);
153
154     static status_t getHdrCapabilities(const sp<IBinder>& display,
155             HdrCapabilities* outCapabilities);
156
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);
162
163     /* setDisplayProjection() defines the projection of layer stacks
164      * to a given display.
165      *
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.
172      */
173     static void setDisplayProjection(const sp<IBinder>& token,
174             uint32_t orientation,
175             const Rect& layerStackRect,
176             const Rect& displayRect);
177
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);
182
183 private:
184     virtual void onFirstRef();
185     Composer& getComposer();
186
187     mutable     Mutex                       mLock;
188                 status_t                    mStatus;
189                 sp<ISurfaceComposerClient>  mClient;
190                 Composer&                   mComposer;
191 };
192
193 // ---------------------------------------------------------------------------
194
195 class ScreenshotClient
196 {
197 public:
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);
206
207 private:
208     mutable sp<CpuConsumer> mCpuConsumer;
209     mutable sp<IGraphicBufferProducer> mProducer;
210     CpuConsumer::LockedBuffer mBuffer;
211     bool mHaveBuffer;
212
213 public:
214     ScreenshotClient();
215     ~ScreenshotClient();
216
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);
233
234     sp<CpuConsumer> getCpuConsumer() const;
235
236     // release memory occupied by the screenshot
237     void release();
238
239     // pixels are valid until this object is freed or
240     // release() or update() is called
241     void const* getPixels() const;
242
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;
249 };
250
251 // ---------------------------------------------------------------------------
252 }; // namespace android
253
254 #endif // ANDROID_GUI_SURFACE_COMPOSER_CLIENT_H