• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/PixelFormat.h>
32 
33 #include <gui/CpuConsumer.h>
34 #include <gui/SurfaceControl.h>
35 
36 namespace android {
37 
38 // ---------------------------------------------------------------------------
39 
40 class DisplayInfo;
41 class Composer;
42 class ISurfaceComposerClient;
43 class IGraphicBufferProducer;
44 class Region;
45 
46 // ---------------------------------------------------------------------------
47 
48 class SurfaceComposerClient : public RefBase
49 {
50     friend class Composer;
51 public:
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 
61     // Forcibly remove connection before all references have gone away.
62     void        dispose();
63 
64     // 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
69     static status_t getDisplayInfo(const sp<IBinder>& display, DisplayInfo* info);
70 
71     /* 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 
77     // ------------------------------------------------------------------------
78     // surface creation / destruction
79 
80     //! Create a surface
81     sp<SurfaceControl> createSurface(
82             const String8& name,// name of the surface
83             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
87     );
88 
89     //! Create a display
90     static sp<IBinder> createDisplay(const String8& displayName, bool secure);
91 
92     //! 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 
96     // ------------------------------------------------------------------------
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.
101     // closeGlobalTransaction() requires an IPC with the server.
102 
103     //! Open a composer transaction on all active SurfaceComposerClients.
104     static void openGlobalTransaction();
105 
106     //! Close a composer transaction on all active SurfaceComposerClients.
107     static void closeGlobalTransaction(bool synchronous = false);
108 
109     //! Flag the currently open transaction as an animation transaction.
110     static void setAnimationTransaction();
111 
112     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);
124 
125     static void setDisplaySurface(const sp<IBinder>& token,
126             const sp<IGraphicBufferProducer>& bufferProducer);
127     static void setDisplayLayerStack(const sp<IBinder>& token,
128             uint32_t layerStack);
129 
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);
144 
145 private:
146     virtual void onFirstRef();
147     Composer& getComposer();
148 
149     mutable     Mutex                       mLock;
150                 status_t                    mStatus;
151                 sp<ISurfaceComposerClient>  mClient;
152                 Composer&                   mComposer;
153 };
154 
155 // ---------------------------------------------------------------------------
156 
157 class ScreenshotClient
158 {
159 public:
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 
166 private:
167     mutable sp<CpuConsumer> mCpuConsumer;
168     CpuConsumer::LockedBuffer mBuffer;
169     bool mHaveBuffer;
170 
171 public:
172     ScreenshotClient();
173     ~ScreenshotClient();
174 
175     // frees the previous screenshot and capture a new one
176     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,
181             uint32_t minLayerZ, uint32_t maxLayerZ);
182 
183     sp<CpuConsumer> getCpuConsumer() const;
184 
185     // release memory occupied by the screenshot
186     void release();
187 
188     // pixels are valid until this object is freed or
189     // release() or update() is called
190     void const* getPixels() const;
191 
192     uint32_t getWidth() const;
193     uint32_t getHeight() const;
194     PixelFormat getFormat() const;
195     uint32_t getStride() const;
196     // size of allocated memory in bytes
197     size_t getSize() const;
198 };
199 
200 // ---------------------------------------------------------------------------
201 }; // namespace android
202 
203 #endif // ANDROID_GUI_SURFACE_COMPOSER_CLIENT_H
204