The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 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_UI_SURFACE_H |
| 18 | #define ANDROID_UI_SURFACE_H |
| 19 | |
| 20 | #include <stdint.h> |
| 21 | #include <sys/types.h> |
| 22 | |
| 23 | #include <utils/RefBase.h> |
| 24 | #include <utils/threads.h> |
| 25 | |
| 26 | #include <ui/ISurface.h> |
| 27 | #include <ui/PixelFormat.h> |
| 28 | #include <ui/Region.h> |
| 29 | #include <ui/ISurfaceFlingerClient.h> |
| 30 | |
Mathias Agopian | 1473f46 | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 31 | #include <EGL/android_natives.h> |
| 32 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 33 | namespace android { |
| 34 | |
| 35 | // --------------------------------------------------------------------------- |
| 36 | |
| 37 | class Rect; |
| 38 | class SurfaceComposerClient; |
Mathias Agopian | 1473f46 | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 39 | struct per_client_cblk_t; |
| 40 | struct layer_cblk_t; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 41 | |
Mathias Agopian | 1473f46 | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 42 | // --------------------------------------------------------------------------- |
| 43 | |
| 44 | class SurfaceBuffer |
| 45 | : public EGLNativeBase< |
| 46 | android_native_buffer_t, |
| 47 | SurfaceBuffer, |
| 48 | LightRefBase<SurfaceBuffer> > |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 49 | { |
Mathias Agopian | 1473f46 | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 50 | public: |
| 51 | buffer_handle_t getHandle() const { |
| 52 | return handle; |
| 53 | } |
| 54 | |
| 55 | protected: |
| 56 | SurfaceBuffer(); |
| 57 | SurfaceBuffer(const Parcel& reply); |
| 58 | virtual ~SurfaceBuffer(); |
| 59 | buffer_handle_t handle; |
| 60 | bool mOwner; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 61 | |
Mathias Agopian | 1473f46 | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 62 | private: |
| 63 | friend class BpSurface; |
| 64 | friend class BnSurface; |
| 65 | friend class LightRefBase<SurfaceBuffer>; |
| 66 | |
| 67 | SurfaceBuffer& operator = (const SurfaceBuffer& rhs); |
| 68 | const SurfaceBuffer& operator = (const SurfaceBuffer& rhs) const; |
| 69 | |
| 70 | static status_t writeToParcel(Parcel* reply, |
| 71 | android_native_buffer_t const* buffer); |
| 72 | |
| 73 | static int getHandle(android_native_buffer_t const * base, |
| 74 | buffer_handle_t* handle); |
| 75 | }; |
| 76 | |
| 77 | // --------------------------------------------------------------------------- |
| 78 | |
Mathias Agopian | 6d2c0bc | 2009-04-16 16:19:50 -0700 | [diff] [blame^] | 79 | class SurfaceControl : public RefBase |
| 80 | { |
| 81 | public: |
| 82 | static bool isValid(const sp<SurfaceControl>& surface) { |
| 83 | return (surface != 0) && surface->mToken>=0 && surface->mClient!=0; |
| 84 | } |
| 85 | |
| 86 | SurfaceID ID() const { return mToken; } |
| 87 | uint32_t getFlags() const { return mFlags; } |
| 88 | uint32_t getIdentity() const { return mIdentity; } |
| 89 | |
| 90 | // release surface data from java |
| 91 | void clear(); |
| 92 | |
| 93 | static sp<SurfaceControl> readFromParcel(Parcel* parcel); |
| 94 | static status_t writeToParcel(const sp<SurfaceControl>& surface, Parcel* parcel); |
| 95 | static bool isSameSurface(const sp<SurfaceControl>& lhs, const sp<SurfaceControl>& rhs); |
| 96 | |
| 97 | status_t setLayer(int32_t layer); |
| 98 | status_t setPosition(int32_t x, int32_t y); |
| 99 | status_t setSize(uint32_t w, uint32_t h); |
| 100 | status_t hide(); |
| 101 | status_t show(int32_t layer = -1); |
| 102 | status_t freeze(); |
| 103 | status_t unfreeze(); |
| 104 | status_t setFlags(uint32_t flags, uint32_t mask); |
| 105 | status_t setTransparentRegionHint(const Region& transparent); |
| 106 | status_t setAlpha(float alpha=1.0f); |
| 107 | status_t setMatrix(float dsdx, float dtdx, float dsdy, float dtdy); |
| 108 | status_t setFreezeTint(uint32_t tint); |
| 109 | |
| 110 | private: |
| 111 | friend class SurfaceComposerClient; |
| 112 | |
| 113 | // camera and camcorder need access to the ISurface binder interface for preview |
| 114 | friend class Camera; |
| 115 | friend class MediaRecorder; |
| 116 | // mediaplayer needs access to ISurface for display |
| 117 | friend class MediaPlayer; |
| 118 | friend class Test; |
| 119 | const sp<ISurface>& getISurface() const { return mSurface; } |
| 120 | |
| 121 | // can't be copied |
| 122 | SurfaceControl& operator = (SurfaceControl& rhs); |
| 123 | SurfaceControl(const SurfaceControl& rhs); |
| 124 | |
| 125 | friend class Surface; |
| 126 | SurfaceControl(const sp<SurfaceComposerClient>& client, |
| 127 | const sp<ISurface>& surface, |
| 128 | const ISurfaceFlingerClient::surface_data_t& data, |
| 129 | uint32_t w, uint32_t h, PixelFormat format, uint32_t flags, |
| 130 | bool owner = true); |
| 131 | |
| 132 | ~SurfaceControl(); |
| 133 | |
| 134 | status_t validate(per_client_cblk_t const* cblk) const; |
| 135 | void destroy(); |
| 136 | |
| 137 | sp<SurfaceComposerClient> mClient; |
| 138 | sp<ISurface> mSurface; |
| 139 | SurfaceID mToken; |
| 140 | uint32_t mIdentity; |
| 141 | PixelFormat mFormat; |
| 142 | uint32_t mFlags; |
| 143 | const bool mOwner; |
| 144 | mutable Mutex mLock; |
| 145 | }; |
| 146 | |
| 147 | // --------------------------------------------------------------------------- |
| 148 | |
Mathias Agopian | 1473f46 | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 149 | class Surface |
| 150 | : public EGLNativeBase<android_native_window_t, Surface, RefBase> |
| 151 | { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 152 | public: |
| 153 | struct SurfaceInfo { |
| 154 | uint32_t w; |
| 155 | uint32_t h; |
Mathias Agopian | 1473f46 | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 156 | uint32_t s; |
| 157 | uint32_t usage; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 158 | PixelFormat format; |
| 159 | void* bits; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 160 | uint32_t reserved[2]; |
| 161 | }; |
| 162 | |
Mathias Agopian | 402c346 | 2009-04-14 18:21:47 -0700 | [diff] [blame] | 163 | static bool isValid(const sp<Surface>& surface) { |
| 164 | return (surface != 0) && surface->mToken>=0 && surface->mClient!=0; |
| 165 | } |
| 166 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 167 | SurfaceID ID() const { return mToken; } |
| 168 | |
Mathias Agopian | 402c346 | 2009-04-14 18:21:47 -0700 | [diff] [blame] | 169 | // release surface data from java |
| 170 | void clear(); |
| 171 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 172 | status_t lock(SurfaceInfo* info, bool blocking = true); |
| 173 | status_t lock(SurfaceInfo* info, Region* dirty, bool blocking = true); |
| 174 | status_t unlockAndPost(); |
Mathias Agopian | 1473f46 | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 175 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 176 | uint32_t getFlags() const { return mFlags; } |
| 177 | |
| 178 | // setSwapRectangle() is mainly used by EGL |
| 179 | void setSwapRectangle(const Rect& r); |
| 180 | const Rect& swapRectangle() const; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 181 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 182 | static sp<Surface> readFromParcel(Parcel* parcel); |
| 183 | static status_t writeToParcel(const sp<Surface>& surface, Parcel* parcel); |
| 184 | static bool isSameSurface(const sp<Surface>& lhs, const sp<Surface>& rhs); |
| 185 | |
| 186 | status_t setLayer(int32_t layer); |
| 187 | status_t setPosition(int32_t x, int32_t y); |
| 188 | status_t setSize(uint32_t w, uint32_t h); |
| 189 | status_t hide(); |
| 190 | status_t show(int32_t layer = -1); |
| 191 | status_t freeze(); |
| 192 | status_t unfreeze(); |
| 193 | status_t setFlags(uint32_t flags, uint32_t mask); |
| 194 | status_t setTransparentRegionHint(const Region& transparent); |
| 195 | status_t setAlpha(float alpha=1.0f); |
| 196 | status_t setMatrix(float dsdx, float dtdx, float dsdy, float dtdy); |
| 197 | status_t setFreezeTint(uint32_t tint); |
| 198 | |
| 199 | uint32_t getIdentity() const { return mIdentity; } |
| 200 | private: |
| 201 | friend class SurfaceComposerClient; |
| 202 | |
| 203 | // camera and camcorder need access to the ISurface binder interface for preview |
| 204 | friend class Camera; |
| 205 | friend class MediaRecorder; |
| 206 | // mediaplayer needs access to ISurface for display |
| 207 | friend class MediaPlayer; |
| 208 | friend class Test; |
| 209 | const sp<ISurface>& getISurface() const { return mSurface; } |
| 210 | |
Mathias Agopian | 1473f46 | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 211 | status_t getBufferLocked(int index); |
| 212 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 213 | // can't be copied |
| 214 | Surface& operator = (Surface& rhs); |
| 215 | Surface(const Surface& rhs); |
| 216 | |
| 217 | Surface(const sp<SurfaceComposerClient>& client, |
| 218 | const sp<ISurface>& surface, |
| 219 | const ISurfaceFlingerClient::surface_data_t& data, |
| 220 | uint32_t w, uint32_t h, PixelFormat format, uint32_t flags, |
| 221 | bool owner = true); |
| 222 | |
| 223 | Surface(Surface const* rhs); |
| 224 | |
| 225 | ~Surface(); |
Mathias Agopian | 1473f46 | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 226 | |
Mathias Agopian | 402c346 | 2009-04-14 18:21:47 -0700 | [diff] [blame] | 227 | void destroy(); |
| 228 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 229 | Region dirtyRegion() const; |
| 230 | void setDirtyRegion(const Region& region) const; |
| 231 | |
Mathias Agopian | 1473f46 | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 232 | |
| 233 | status_t validate(per_client_cblk_t const* cblk) const; |
| 234 | static void _send_dirty_region(layer_cblk_t* lcblk, const Region& dirty); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 235 | |
Mathias Agopian | 1473f46 | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 236 | |
| 237 | static void connect(android_native_window_t* window); |
| 238 | static void disconnect(android_native_window_t* window); |
| 239 | static int setSwapInterval(android_native_window_t* window, int interval); |
| 240 | static int setSwapRectangle(android_native_window_t* window, |
| 241 | int l, int t, int w, int h); |
| 242 | static int dequeueBuffer(android_native_window_t* window, android_native_buffer_t** buffer); |
| 243 | static int lockBuffer(android_native_window_t* window, android_native_buffer_t* buffer); |
| 244 | static int queueBuffer(android_native_window_t* window, android_native_buffer_t* buffer); |
| 245 | |
| 246 | int dequeueBuffer(android_native_buffer_t** buffer); |
| 247 | int lockBuffer(android_native_buffer_t* buffer); |
| 248 | int queueBuffer(android_native_buffer_t* buffer); |
| 249 | |
| 250 | |
| 251 | alloc_device_t* mAllocDevice; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 252 | sp<SurfaceComposerClient> mClient; |
| 253 | sp<ISurface> mSurface; |
Mathias Agopian | 1473f46 | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 254 | sp<SurfaceBuffer> mBuffers[2]; |
| 255 | android_native_buffer_t* mLockedBuffer; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 256 | SurfaceID mToken; |
| 257 | uint32_t mIdentity; |
| 258 | PixelFormat mFormat; |
| 259 | uint32_t mFlags; |
| 260 | const bool mOwner; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 261 | mutable Region mDirtyRegion; |
| 262 | mutable Rect mSwapRectangle; |
| 263 | mutable uint8_t mBackbufferIndex; |
| 264 | mutable Mutex mSurfaceLock; |
Mathias Agopian | 6d2c0bc | 2009-04-16 16:19:50 -0700 | [diff] [blame^] | 265 | |
| 266 | sp<SurfaceControl> mSurfaceControl; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 267 | }; |
| 268 | |
| 269 | }; // namespace android |
| 270 | |
| 271 | #endif // ANDROID_UI_SURFACE_H |
| 272 | |