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;
42 class ISurfaceTexture;
45 // ---------------------------------------------------------------------------
47 class SurfaceComposerClient : public RefBase
49 friend class Composer;
51 SurfaceComposerClient();
52 virtual ~SurfaceComposerClient();
54 // Always make sure we could initialize
55 status_t initCheck() const;
57 // Return the connection of this client
58 sp<IBinder> connection() const;
60 // Forcibly remove connection before all references have gone away.
63 // callback when the composer is dies
64 status_t linkToComposerDeath(const sp<IBinder::DeathRecipient>& recipient,
65 void* cookie = NULL, uint32_t flags = 0);
67 // Get information about a display
68 static status_t getDisplayInfo(const sp<IBinder>& display, DisplayInfo* info);
70 // TODO: Remove me. Do not use.
71 // This is a compatibility shim for one product whose drivers are depending on
72 // this legacy function (when they shouldn't).
73 static status_t getDisplayInfo(int32_t displayId, DisplayInfo* info);
75 // ------------------------------------------------------------------------
76 // surface creation / destruction
79 sp<SurfaceControl> createSurface(
80 const String8& name,// name of the surface
81 uint32_t w, // width in pixel
82 uint32_t h, // height in pixel
83 PixelFormat format, // pixel-format desired
84 uint32_t flags = 0 // usage flags
88 static sp<IBinder> createDisplay();
90 //! Get the token for the existing default displays.
91 //! Possible values for id are eDisplayIdMain and eDisplayIdHdmi.
92 static sp<IBinder> getBuiltInDisplay(int32_t id);
94 // ------------------------------------------------------------------------
95 // Composer parameters
96 // All composer parameters must be changed within a transaction
97 // several surfaces can be updated in one transaction, all changes are
98 // committed at once when the transaction is closed.
99 // closeGlobalTransaction() requires an IPC with the server.
101 //! Open a composer transaction on all active SurfaceComposerClients.
102 static void openGlobalTransaction();
104 //! Close a composer transaction on all active SurfaceComposerClients.
105 static void closeGlobalTransaction(bool synchronous = false);
107 status_t hide(SurfaceID id);
108 status_t show(SurfaceID id);
109 status_t setFlags(SurfaceID id, uint32_t flags, uint32_t mask);
110 status_t setTransparentRegionHint(SurfaceID id, const Region& transparent);
111 status_t setLayer(SurfaceID id, int32_t layer);
112 status_t setAlpha(SurfaceID id, float alpha=1.0f);
113 status_t setMatrix(SurfaceID id, float dsdx, float dtdx, float dsdy, float dtdy);
114 status_t setPosition(SurfaceID id, float x, float y);
115 status_t setSize(SurfaceID id, uint32_t w, uint32_t h);
116 status_t setCrop(SurfaceID id, const Rect& crop);
117 status_t setLayerStack(SurfaceID id, uint32_t layerStack);
118 status_t destroySurface(SurfaceID sid);
120 static void setDisplaySurface(const sp<IBinder>& token,
121 const sp<ISurfaceTexture>& surface);
122 static void setDisplayLayerStack(const sp<IBinder>& token,
123 uint32_t layerStack);
125 /* setDisplayProjection() defines the projection of layer stacks
126 * to a given display.
128 * - orientation defines the display's orientation.
129 * - layerStackRect defines which area of the window manager coordinate
130 * space will be used.
131 * - displayRect defines where on the display will layerStackRect be
132 * mapped to. displayRect is specified post-orientation, that is
133 * it uses the orientation seen by the end-user.
135 static void setDisplayProjection(const sp<IBinder>& token,
136 uint32_t orientation,
137 const Rect& layerStackRect,
138 const Rect& displayRect);
141 virtual void onFirstRef();
142 Composer& getComposer();
146 sp<ISurfaceComposerClient> mClient;
150 // ---------------------------------------------------------------------------
152 class ScreenshotClient
154 sp<IMemoryHeap> mHeap;
161 // frees the previous screenshot and capture a new one
162 status_t update(const sp<IBinder>& display);
163 status_t update(const sp<IBinder>& display,
164 uint32_t reqWidth, uint32_t reqHeight);
165 status_t update(const sp<IBinder>& display,
166 uint32_t reqWidth, uint32_t reqHeight,
167 uint32_t minLayerZ, uint32_t maxLayerZ);
169 // release memory occupied by the screenshot
172 // pixels are valid until this object is freed or
173 // release() or update() is called
174 void const* getPixels() const;
176 uint32_t getWidth() const;
177 uint32_t getHeight() const;
178 PixelFormat getFormat() const;
179 uint32_t getStride() const;
180 // size of allocated memory in bytes
181 size_t getSize() const;
184 // ---------------------------------------------------------------------------
185 }; // namespace android
187 #endif // ANDROID_GUI_SURFACE_COMPOSER_CLIENT_H