• 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 
25 #include <utils/RefBase.h>
26 #include <utils/Singleton.h>
27 #include <utils/SortedVector.h>
28 #include <utils/threads.h>
29 
30 #include <ui/PixelFormat.h>
31 
32 #include <gui/Surface.h>
33 
34 namespace android {
35 
36 // ---------------------------------------------------------------------------
37 
38 class DisplayInfo;
39 class Composer;
40 class IMemoryHeap;
41 class ISurfaceComposerClient;
42 class ISurfaceTexture;
43 class Region;
44 
45 // ---------------------------------------------------------------------------
46 
47 class SurfaceComposerClient : public RefBase
48 {
49     friend class Composer;
50 public:
51                 SurfaceComposerClient();
52     virtual     ~SurfaceComposerClient();
53 
54     // Always make sure we could initialize
55     status_t    initCheck() const;
56 
57     // Return the connection of this client
58     sp<IBinder> connection() const;
59 
60     // Forcibly remove connection before all references have gone away.
61     void        dispose();
62 
63     // callback when the composer is dies
64     status_t linkToComposerDeath(const sp<IBinder::DeathRecipient>& recipient,
65             void* cookie = NULL, uint32_t flags = 0);
66 
67     // Get information about a display
68     static status_t getDisplayInfo(const sp<IBinder>& display, DisplayInfo* info);
69 
70     /* triggers screen off and waits for it to complete */
71     static void blankDisplay(const sp<IBinder>& display);
72 
73     /* triggers screen on and waits for it to complete */
74     static void unblankDisplay(const sp<IBinder>& display);
75 
76     // ------------------------------------------------------------------------
77     // surface creation / destruction
78 
79     //! Create a surface
80     sp<SurfaceControl> createSurface(
81             const String8& name,// name of the surface
82             uint32_t w,         // width in pixel
83             uint32_t h,         // height in pixel
84             PixelFormat format, // pixel-format desired
85             uint32_t flags = 0  // usage flags
86     );
87 
88     //! Create a display
89     static sp<IBinder> createDisplay(const String8& displayName, bool secure);
90 
91     //! Get the token for the existing default displays.
92     //! Possible values for id are eDisplayIdMain and eDisplayIdHdmi.
93     static sp<IBinder> getBuiltInDisplay(int32_t id);
94 
95     // ------------------------------------------------------------------------
96     // Composer parameters
97     // All composer parameters must be changed within a transaction
98     // several surfaces can be updated in one transaction, all changes are
99     // committed at once when the transaction is closed.
100     // closeGlobalTransaction() requires an IPC with the server.
101 
102     //! Open a composer transaction on all active SurfaceComposerClients.
103     static void openGlobalTransaction();
104 
105     //! Close a composer transaction on all active SurfaceComposerClients.
106     static void closeGlobalTransaction(bool synchronous = false);
107 
108     //! Flag the currently open transaction as an animation transaction.
109     static void setAnimationTransaction();
110 
111     status_t    hide(SurfaceID id);
112     status_t    show(SurfaceID id);
113     status_t    setFlags(SurfaceID id, uint32_t flags, uint32_t mask);
114     status_t    setTransparentRegionHint(SurfaceID id, const Region& transparent);
115     status_t    setLayer(SurfaceID id, int32_t layer);
116     status_t    setAlpha(SurfaceID id, float alpha=1.0f);
117     status_t    setMatrix(SurfaceID id, float dsdx, float dtdx, float dsdy, float dtdy);
118     status_t    setPosition(SurfaceID id, float x, float y);
119     status_t    setSize(SurfaceID id, uint32_t w, uint32_t h);
120     status_t    setCrop(SurfaceID id, const Rect& crop);
121     status_t    setLayerStack(SurfaceID id, uint32_t layerStack);
122     status_t    destroySurface(SurfaceID sid);
123 
124     static void setDisplaySurface(const sp<IBinder>& token,
125             const sp<ISurfaceTexture>& surface);
126     static void setDisplayLayerStack(const sp<IBinder>& token,
127             uint32_t layerStack);
128 
129     /* setDisplayProjection() defines the projection of layer stacks
130      * to a given display.
131      *
132      * - orientation defines the display's orientation.
133      * - layerStackRect defines which area of the window manager coordinate
134      * space will be used.
135      * - displayRect defines where on the display will layerStackRect be
136      * mapped to. displayRect is specified post-orientation, that is
137      * it uses the orientation seen by the end-user.
138      */
139     static void setDisplayProjection(const sp<IBinder>& token,
140             uint32_t orientation,
141             const Rect& layerStackRect,
142             const Rect& displayRect);
143 
144 private:
145     virtual void onFirstRef();
146     Composer& getComposer();
147 
148     mutable     Mutex                       mLock;
149                 status_t                    mStatus;
150                 sp<ISurfaceComposerClient>  mClient;
151                 Composer&                   mComposer;
152 };
153 
154 // ---------------------------------------------------------------------------
155 
156 class ScreenshotClient
157 {
158     sp<IMemoryHeap> mHeap;
159     uint32_t mWidth;
160     uint32_t mHeight;
161     PixelFormat mFormat;
162 public:
163     ScreenshotClient();
164 
165     // frees the previous screenshot and capture a new one
166     status_t update(const sp<IBinder>& display);
167     status_t update(const sp<IBinder>& display,
168             uint32_t reqWidth, uint32_t reqHeight);
169     status_t update(const sp<IBinder>& display,
170             uint32_t reqWidth, uint32_t reqHeight,
171             uint32_t minLayerZ, uint32_t maxLayerZ);
172 
173     // release memory occupied by the screenshot
174     void release();
175 
176     // pixels are valid until this object is freed or
177     // release() or update() is called
178     void const* getPixels() const;
179 
180     uint32_t getWidth() const;
181     uint32_t getHeight() const;
182     PixelFormat getFormat() const;
183     uint32_t getStride() const;
184     // size of allocated memory in bytes
185     size_t getSize() const;
186 };
187 
188 // ---------------------------------------------------------------------------
189 }; // namespace android
190 
191 #endif // ANDROID_GUI_SURFACE_COMPOSER_CLIENT_H
192