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>
25 #include <utils/RefBase.h>
26 #include <utils/Singleton.h>
27 #include <utils/SortedVector.h>
28 #include <utils/threads.h>
30 #include <ui/PixelFormat.h>
32 #include <gui/Surface.h>
36 // ---------------------------------------------------------------------------
41 class ISurfaceComposerClient;
44 // ---------------------------------------------------------------------------
46 class SurfaceComposerClient : public RefBase
48 friend class Composer;
50 SurfaceComposerClient();
51 virtual ~SurfaceComposerClient();
53 // Always make sure we could initialize
54 status_t initCheck() const;
56 // Return the connection of this client
57 sp<IBinder> connection() const;
59 // Forcibly remove connection before all references have gone away.
62 // callback when the composer is dies
63 status_t linkToComposerDeath(const sp<IBinder::DeathRecipient>& recipient,
64 void* cookie = NULL, uint32_t flags = 0);
66 // Get information about a display
67 static status_t getDisplayInfo(DisplayID dpy, DisplayInfo* info);
69 // ------------------------------------------------------------------------
70 // surface creation / destruction
73 sp<SurfaceControl> createSurface(
74 const String8& name,// name of the surface
75 DisplayID display, // Display to create this surface on
76 uint32_t w, // width in pixel
77 uint32_t h, // height in pixel
78 PixelFormat format, // pixel-format desired
79 uint32_t flags = 0 // usage flags
82 sp<SurfaceControl> createSurface(
83 DisplayID display, // Display to create this surface on
84 uint32_t w, // width in pixel
85 uint32_t h, // height in pixel
86 PixelFormat format, // pixel-format desired
87 uint32_t flags = 0 // usage flags
90 static sp<IBinder> createDisplay();
92 // ------------------------------------------------------------------------
93 // Composer parameters
94 // All composer parameters must be changed within a transaction
95 // several surfaces can be updated in one transaction, all changes are
96 // committed at once when the transaction is closed.
97 // closeGlobalTransaction() requires an IPC with the server.
99 //! Open a composer transaction on all active SurfaceComposerClients.
100 static void openGlobalTransaction();
102 //! Close a composer transaction on all active SurfaceComposerClients.
103 static void closeGlobalTransaction(bool synchronous = false);
105 //! Set the orientation of the given display
106 static int setOrientation(DisplayID dpy, int orientation, uint32_t flags);
108 status_t hide(SurfaceID id);
109 status_t show(SurfaceID id, int32_t layer = -1);
110 status_t setFlags(SurfaceID id, uint32_t flags, uint32_t mask);
111 status_t setTransparentRegionHint(SurfaceID id, const Region& transparent);
112 status_t setLayer(SurfaceID id, int32_t layer);
113 status_t setAlpha(SurfaceID id, float alpha=1.0f);
114 status_t setMatrix(SurfaceID id, float dsdx, float dtdx, float dsdy, float dtdy);
115 status_t setPosition(SurfaceID id, float x, float y);
116 status_t setSize(SurfaceID id, uint32_t w, uint32_t h);
117 status_t setCrop(SurfaceID id, const Rect& crop);
118 status_t setLayerStack(SurfaceID id, uint32_t layerStack);
119 status_t destroySurface(SurfaceID sid);
121 static void setDisplaySurface(const sp<IBinder>& token,
122 const sp<ISurfaceTexture>& surface);
123 static void setDisplayLayerStack(const sp<IBinder>& token,
124 uint32_t layerStack);
125 static void setDisplayOrientation(const sp<IBinder>& token,
126 uint32_t orientation);
127 static void setDisplayViewport(const sp<IBinder>& token,
128 const Rect& viewport);
129 static void setDisplayFrame(const sp<IBinder>& token, const Rect& frame);
132 virtual void onFirstRef();
133 Composer& getComposer();
137 sp<ISurfaceComposerClient> mClient;
141 // ---------------------------------------------------------------------------
143 class ScreenshotClient
145 sp<IMemoryHeap> mHeap;
152 // frees the previous screenshot and capture a new one
154 status_t update(uint32_t reqWidth, uint32_t reqHeight);
155 status_t update(uint32_t reqWidth, uint32_t reqHeight,
156 uint32_t minLayerZ, uint32_t maxLayerZ);
158 // release memory occupied by the screenshot
161 // pixels are valid until this object is freed or
162 // release() or update() is called
163 void const* getPixels() const;
165 uint32_t getWidth() const;
166 uint32_t getHeight() const;
167 PixelFormat getFormat() const;
168 uint32_t getStride() const;
169 // size of allocated memory in bytes
170 size_t getSize() const;
173 // ---------------------------------------------------------------------------
174 }; // namespace android
176 #endif // ANDROID_GUI_SURFACE_COMPOSER_CLIENT_H