OSDN Git Service

original
[gb-231r1-is01/Gingerbread_2.3.3_r1_IS01.git] / frameworks / base / include / surfaceflinger / 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_SF_SURFACE_COMPOSER_CLIENT_H
18 #define ANDROID_SF_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 #include <ui/Region.h>
32
33 #include <surfaceflinger/Surface.h>
34
35 namespace android {
36
37 // ---------------------------------------------------------------------------
38
39 class Region;
40 class SharedClient;
41 class ISurfaceComposer;
42 class DisplayInfo;
43 class surface_flinger_cblk_t;
44
45 // ---------------------------------------------------------------------------
46
47 class ComposerService : public Singleton<ComposerService>
48 {
49     // these are constants
50     sp<ISurfaceComposer> mComposerService;
51     sp<IMemoryHeap> mServerCblkMemory;
52     surface_flinger_cblk_t volatile* mServerCblk;
53     ComposerService();
54     friend class Singleton<ComposerService>;
55 public:
56     static sp<ISurfaceComposer> getComposerService();
57     static surface_flinger_cblk_t const volatile * getControlBlock();
58 };
59
60 // ---------------------------------------------------------------------------
61
62 class SurfaceComposerClient : public RefBase
63 {
64 public:    
65                 SurfaceComposerClient();
66     virtual     ~SurfaceComposerClient();
67
68     // Always make sure we could initialize
69     status_t    initCheck() const;
70
71     // Return the connection of this client
72     sp<IBinder> connection() const;
73     
74     // Forcibly remove connection before all references have gone away.
75     void        dispose();
76
77     // ------------------------------------------------------------------------
78     // surface creation / destruction
79
80     //! Create a surface
81     sp<SurfaceControl> createSurface(
82             int pid,            // pid of the process the surface is for
83             const String8& name,// name of the surface
84             DisplayID display,  // Display to create this surface on
85             uint32_t w,         // width in pixel
86             uint32_t h,         // height in pixel
87             PixelFormat format, // pixel-format desired
88             uint32_t flags = 0  // usage flags
89     );
90
91     sp<SurfaceControl> createSurface(
92             int pid,            // pid of the process the surface is for
93             DisplayID display,  // Display to create this surface on
94             uint32_t w,         // width in pixel
95             uint32_t h,         // height in pixel
96             PixelFormat format, // pixel-format desired
97             uint32_t flags = 0  // usage flags
98     );
99
100
101     // ------------------------------------------------------------------------
102     // Composer parameters
103     // All composer parameters must be changed within a transaction
104     // several surfaces can be updated in one transaction, all changes are
105     // committed at once when the transaction is closed.
106     // CloseTransaction() usually requires an IPC with the server.
107     
108     //! Open a composer transaction
109     status_t    openTransaction();
110
111     //! commit the transaction
112     status_t    closeTransaction();
113
114     //! Open a composer transaction on all active SurfaceComposerClients.
115     static void openGlobalTransaction();
116         
117     //! Close a composer transaction on all active SurfaceComposerClients.
118     static void closeGlobalTransaction();
119     
120     //! Freeze the specified display but not transactions.
121     static status_t freezeDisplay(DisplayID dpy, uint32_t flags = 0);
122         
123     //! Resume updates on the specified display.
124     static status_t unfreezeDisplay(DisplayID dpy, uint32_t flags = 0);
125
126     //! Set the orientation of the given display
127     static int setOrientation(DisplayID dpy, int orientation, uint32_t flags);
128
129     // Query the number of displays
130     static ssize_t getNumberOfDisplays();
131
132     // Get information about a display
133     static status_t getDisplayInfo(DisplayID dpy, DisplayInfo* info);
134     static ssize_t getDisplayWidth(DisplayID dpy);
135     static ssize_t getDisplayHeight(DisplayID dpy);
136     static ssize_t getDisplayOrientation(DisplayID dpy);
137
138     status_t linkToComposerDeath(const sp<IBinder::DeathRecipient>& recipient,
139             void* cookie = NULL, uint32_t flags = 0);
140
141     status_t    hide(SurfaceID id);
142     status_t    show(SurfaceID id, int32_t layer = -1);
143     status_t    freeze(SurfaceID id);
144     status_t    unfreeze(SurfaceID id);
145     status_t    setFlags(SurfaceID id, uint32_t flags, uint32_t mask);
146     status_t    setTransparentRegionHint(SurfaceID id, const Region& transparent);
147     status_t    setLayer(SurfaceID id, int32_t layer);
148     status_t    setAlpha(SurfaceID id, float alpha=1.0f);
149     status_t    setFreezeTint(SurfaceID id, uint32_t tint);
150     status_t    setMatrix(SurfaceID id, float dsdx, float dtdx, float dsdy, float dtdy);
151     status_t    setPosition(SurfaceID id, int32_t x, int32_t y);
152     status_t    setSize(SurfaceID id, uint32_t w, uint32_t h);
153     status_t    destroySurface(SurfaceID sid);
154
155 private:
156     virtual void onFirstRef();
157     inline layer_state_t*   get_state_l(SurfaceID id);
158     layer_state_t*          lockLayerState(SurfaceID id);
159     inline void             unlockLayerState();
160
161     mutable     Mutex                               mLock;
162                 SortedVector<layer_state_t>         mStates;
163                 int32_t                             mTransactionOpen;
164                 layer_state_t*                      mPrebuiltLayerState;
165
166                 // these don't need to be protected because they never change
167                 // after assignment
168                 status_t                    mStatus;
169                 sp<ISurfaceComposerClient>  mClient;
170 };
171
172 // ---------------------------------------------------------------------------
173
174 class ScreenshotClient
175 {
176     sp<IMemoryHeap> mHeap;
177     uint32_t mWidth;
178     uint32_t mHeight;
179     PixelFormat mFormat;
180 public:
181     ScreenshotClient();
182
183     // frees the previous screenshot and capture a new one
184     status_t update();
185     status_t update(uint32_t reqWidth, uint32_t reqHeight);
186
187     // release memory occupied by the screenshot
188     void release();
189
190     // pixels are valid until this object is freed or
191     // release() or update() is called
192     void const* getPixels() const;
193
194     uint32_t getWidth() const;
195     uint32_t getHeight() const;
196     PixelFormat getFormat() const;
197     uint32_t getStride() const;
198     // size of allocated memory in bytes
199     size_t getSize() const;
200 };
201
202 // ---------------------------------------------------------------------------
203 }; // namespace android
204
205 #endif // ANDROID_SF_SURFACE_COMPOSER_CLIENT_H
206