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 | ac2523b | 2009-05-05 18:11:11 -0700 | [diff] [blame] | 31 | #include <ui/egl/android_natives.h> |
Mathias Agopian | 1473f46 | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 32 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 33 | namespace android { |
| 34 | |
| 35 | // --------------------------------------------------------------------------- |
| 36 | |
Mathias Agopian | dff8e58 | 2009-05-04 14:17:04 -0700 | [diff] [blame] | 37 | class BufferMapper; |
Andreas Huber | ccf8b94 | 2009-08-07 12:01:29 -0700 | [diff] [blame^] | 38 | class IOMX; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 39 | class Rect; |
Mathias Agopian | dff8e58 | 2009-05-04 14:17:04 -0700 | [diff] [blame] | 40 | class Surface; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 41 | class SurfaceComposerClient; |
Mathias Agopian | 1473f46 | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 42 | struct per_client_cblk_t; |
| 43 | struct layer_cblk_t; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 44 | |
Mathias Agopian | 1473f46 | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 45 | // --------------------------------------------------------------------------- |
| 46 | |
Mathias Agopian | 6d2c0bc | 2009-04-16 16:19:50 -0700 | [diff] [blame] | 47 | class SurfaceControl : public RefBase |
| 48 | { |
| 49 | public: |
| 50 | static bool isValid(const sp<SurfaceControl>& surface) { |
Mathias Agopian | 17f638b | 2009-04-16 20:04:08 -0700 | [diff] [blame] | 51 | return (surface != 0) && surface->isValid(); |
Mathias Agopian | 6d2c0bc | 2009-04-16 16:19:50 -0700 | [diff] [blame] | 52 | } |
Mathias Agopian | 17f638b | 2009-04-16 20:04:08 -0700 | [diff] [blame] | 53 | bool isValid() { |
| 54 | return mToken>=0 && mClient!=0; |
| 55 | } |
| 56 | static bool isSameSurface( |
| 57 | const sp<SurfaceControl>& lhs, const sp<SurfaceControl>& rhs); |
Mathias Agopian | 6d2c0bc | 2009-04-16 16:19:50 -0700 | [diff] [blame] | 58 | |
| 59 | SurfaceID ID() const { return mToken; } |
| 60 | uint32_t getFlags() const { return mFlags; } |
| 61 | uint32_t getIdentity() const { return mIdentity; } |
| 62 | |
| 63 | // release surface data from java |
| 64 | void clear(); |
| 65 | |
Mathias Agopian | 6d2c0bc | 2009-04-16 16:19:50 -0700 | [diff] [blame] | 66 | status_t setLayer(int32_t layer); |
| 67 | status_t setPosition(int32_t x, int32_t y); |
| 68 | status_t setSize(uint32_t w, uint32_t h); |
| 69 | status_t hide(); |
| 70 | status_t show(int32_t layer = -1); |
| 71 | status_t freeze(); |
| 72 | status_t unfreeze(); |
| 73 | status_t setFlags(uint32_t flags, uint32_t mask); |
| 74 | status_t setTransparentRegionHint(const Region& transparent); |
| 75 | status_t setAlpha(float alpha=1.0f); |
| 76 | status_t setMatrix(float dsdx, float dtdx, float dsdy, float dtdy); |
| 77 | status_t setFreezeTint(uint32_t tint); |
| 78 | |
Mathias Agopian | 17f638b | 2009-04-16 20:04:08 -0700 | [diff] [blame] | 79 | static status_t writeSurfaceToParcel( |
| 80 | const sp<SurfaceControl>& control, Parcel* parcel); |
| 81 | |
| 82 | sp<Surface> getSurface() const; |
| 83 | |
Mathias Agopian | 6d2c0bc | 2009-04-16 16:19:50 -0700 | [diff] [blame] | 84 | private: |
Mathias Agopian | 17f638b | 2009-04-16 20:04:08 -0700 | [diff] [blame] | 85 | // can't be copied |
| 86 | SurfaceControl& operator = (SurfaceControl& rhs); |
| 87 | SurfaceControl(const SurfaceControl& rhs); |
| 88 | |
| 89 | |
Mathias Agopian | 6d2c0bc | 2009-04-16 16:19:50 -0700 | [diff] [blame] | 90 | friend class SurfaceComposerClient; |
| 91 | |
| 92 | // camera and camcorder need access to the ISurface binder interface for preview |
| 93 | friend class Camera; |
| 94 | friend class MediaRecorder; |
| 95 | // mediaplayer needs access to ISurface for display |
| 96 | friend class MediaPlayer; |
Mathias Agopian | 17f638b | 2009-04-16 20:04:08 -0700 | [diff] [blame] | 97 | // for testing |
Mathias Agopian | 6d2c0bc | 2009-04-16 16:19:50 -0700 | [diff] [blame] | 98 | friend class Test; |
| 99 | const sp<ISurface>& getISurface() const { return mSurface; } |
| 100 | |
Mathias Agopian | 6d2c0bc | 2009-04-16 16:19:50 -0700 | [diff] [blame] | 101 | |
| 102 | friend class Surface; |
Mathias Agopian | 17f638b | 2009-04-16 20:04:08 -0700 | [diff] [blame] | 103 | |
| 104 | SurfaceControl( |
| 105 | const sp<SurfaceComposerClient>& client, |
Mathias Agopian | 6d2c0bc | 2009-04-16 16:19:50 -0700 | [diff] [blame] | 106 | const sp<ISurface>& surface, |
| 107 | const ISurfaceFlingerClient::surface_data_t& data, |
Mathias Agopian | 69d6209 | 2009-04-16 20:30:22 -0700 | [diff] [blame] | 108 | uint32_t w, uint32_t h, PixelFormat format, uint32_t flags); |
Mathias Agopian | 6d2c0bc | 2009-04-16 16:19:50 -0700 | [diff] [blame] | 109 | |
| 110 | ~SurfaceControl(); |
Mathias Agopian | 17f638b | 2009-04-16 20:04:08 -0700 | [diff] [blame] | 111 | |
Mathias Agopian | 6d2c0bc | 2009-04-16 16:19:50 -0700 | [diff] [blame] | 112 | status_t validate(per_client_cblk_t const* cblk) const; |
| 113 | void destroy(); |
| 114 | |
| 115 | sp<SurfaceComposerClient> mClient; |
| 116 | sp<ISurface> mSurface; |
| 117 | SurfaceID mToken; |
| 118 | uint32_t mIdentity; |
Mathias Agopian | 5b5c914 | 2009-07-30 18:14:56 -0700 | [diff] [blame] | 119 | uint32_t mWidth; |
| 120 | uint32_t mHeight; |
Mathias Agopian | 6d2c0bc | 2009-04-16 16:19:50 -0700 | [diff] [blame] | 121 | PixelFormat mFormat; |
| 122 | uint32_t mFlags; |
Mathias Agopian | 6d2c0bc | 2009-04-16 16:19:50 -0700 | [diff] [blame] | 123 | mutable Mutex mLock; |
Mathias Agopian | 17f638b | 2009-04-16 20:04:08 -0700 | [diff] [blame] | 124 | |
| 125 | mutable sp<Surface> mSurfaceData; |
Mathias Agopian | 6d2c0bc | 2009-04-16 16:19:50 -0700 | [diff] [blame] | 126 | }; |
| 127 | |
| 128 | // --------------------------------------------------------------------------- |
| 129 | |
Mathias Agopian | 1473f46 | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 130 | class Surface |
| 131 | : public EGLNativeBase<android_native_window_t, Surface, RefBase> |
| 132 | { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 133 | public: |
| 134 | struct SurfaceInfo { |
| 135 | uint32_t w; |
| 136 | uint32_t h; |
Mathias Agopian | 1473f46 | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 137 | uint32_t s; |
| 138 | uint32_t usage; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 139 | PixelFormat format; |
| 140 | void* bits; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 141 | uint32_t reserved[2]; |
| 142 | }; |
| 143 | |
Mathias Agopian | 17f638b | 2009-04-16 20:04:08 -0700 | [diff] [blame] | 144 | Surface(const Parcel& data); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 145 | |
Mathias Agopian | 17f638b | 2009-04-16 20:04:08 -0700 | [diff] [blame] | 146 | static bool isValid(const sp<Surface>& surface) { |
| 147 | return (surface != 0) && surface->isValid(); |
| 148 | } |
| 149 | bool isValid() { |
| 150 | return mToken>=0 && mClient!=0; |
| 151 | } |
| 152 | static bool isSameSurface( |
| 153 | const sp<Surface>& lhs, const sp<Surface>& rhs); |
| 154 | SurfaceID ID() const { return mToken; } |
| 155 | uint32_t getFlags() const { return mFlags; } |
| 156 | uint32_t getIdentity() const { return mIdentity; } |
| 157 | |
Mathias Agopian | 402c346 | 2009-04-14 18:21:47 -0700 | [diff] [blame] | 158 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 159 | status_t lock(SurfaceInfo* info, bool blocking = true); |
| 160 | status_t lock(SurfaceInfo* info, Region* dirty, bool blocking = true); |
| 161 | status_t unlockAndPost(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 162 | |
Mathias Agopian | dff8e58 | 2009-05-04 14:17:04 -0700 | [diff] [blame] | 163 | // setSwapRectangle() is intended to be used by GL ES clients |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 164 | void setSwapRectangle(const Rect& r); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 165 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 166 | private: |
Mathias Agopian | 17f638b | 2009-04-16 20:04:08 -0700 | [diff] [blame] | 167 | // can't be copied |
| 168 | Surface& operator = (Surface& rhs); |
| 169 | Surface(const Surface& rhs); |
| 170 | |
| 171 | Surface(const sp<SurfaceControl>& control); |
| 172 | void init(); |
| 173 | ~Surface(); |
| 174 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 175 | friend class SurfaceComposerClient; |
Mathias Agopian | 17f638b | 2009-04-16 20:04:08 -0700 | [diff] [blame] | 176 | friend class SurfaceControl; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 177 | |
| 178 | // camera and camcorder need access to the ISurface binder interface for preview |
| 179 | friend class Camera; |
| 180 | friend class MediaRecorder; |
| 181 | // mediaplayer needs access to ISurface for display |
| 182 | friend class MediaPlayer; |
| 183 | friend class Test; |
Andreas Huber | ccf8b94 | 2009-08-07 12:01:29 -0700 | [diff] [blame^] | 184 | friend class IOMX; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 185 | const sp<ISurface>& getISurface() const { return mSurface; } |
| 186 | |
Mathias Agopian | 1473f46 | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 187 | status_t getBufferLocked(int index); |
Mathias Agopian | 1473f46 | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 188 | |
| 189 | status_t validate(per_client_cblk_t const* cblk) const; |
| 190 | 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] | 191 | |
Mathias Agopian | dff8e58 | 2009-05-04 14:17:04 -0700 | [diff] [blame] | 192 | inline const BufferMapper& getBufferMapper() const { return mBufferMapper; } |
| 193 | inline BufferMapper& getBufferMapper() { return mBufferMapper; } |
Mathias Agopian | 1473f46 | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 194 | |
Mathias Agopian | 1473f46 | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 195 | static int setSwapInterval(android_native_window_t* window, int interval); |
Mathias Agopian | 1473f46 | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 196 | static int dequeueBuffer(android_native_window_t* window, android_native_buffer_t** buffer); |
| 197 | static int lockBuffer(android_native_window_t* window, android_native_buffer_t* buffer); |
| 198 | static int queueBuffer(android_native_window_t* window, android_native_buffer_t* buffer); |
Mathias Agopian | 5b5c914 | 2009-07-30 18:14:56 -0700 | [diff] [blame] | 199 | static int query(android_native_window_t* window, int what, int* value); |
Mathias Agopian | 1473f46 | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 200 | |
| 201 | int dequeueBuffer(android_native_buffer_t** buffer); |
| 202 | int lockBuffer(android_native_buffer_t* buffer); |
| 203 | int queueBuffer(android_native_buffer_t* buffer); |
Mathias Agopian | 5b5c914 | 2009-07-30 18:14:56 -0700 | [diff] [blame] | 204 | int query(int what, int* value); |
Mathias Agopian | dff8e58 | 2009-05-04 14:17:04 -0700 | [diff] [blame] | 205 | |
| 206 | status_t dequeueBuffer(sp<SurfaceBuffer>* buffer); |
| 207 | status_t lockBuffer(const sp<SurfaceBuffer>& buffer); |
| 208 | status_t queueBuffer(const sp<SurfaceBuffer>& buffer); |
| 209 | |
Mathias Agopian | 1473f46 | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 210 | |
| 211 | alloc_device_t* mAllocDevice; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 212 | sp<SurfaceComposerClient> mClient; |
| 213 | sp<ISurface> mSurface; |
Mathias Agopian | 1473f46 | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 214 | sp<SurfaceBuffer> mBuffers[2]; |
Mathias Agopian | dff8e58 | 2009-05-04 14:17:04 -0700 | [diff] [blame] | 215 | sp<SurfaceBuffer> mLockedBuffer; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 216 | SurfaceID mToken; |
| 217 | uint32_t mIdentity; |
Mathias Agopian | 5b5c914 | 2009-07-30 18:14:56 -0700 | [diff] [blame] | 218 | uint32_t mWidth; |
| 219 | uint32_t mHeight; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 220 | PixelFormat mFormat; |
| 221 | uint32_t mFlags; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 222 | mutable Region mDirtyRegion; |
Mathias Agopian | dff8e58 | 2009-05-04 14:17:04 -0700 | [diff] [blame] | 223 | mutable Region mOldDirtyRegion; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 224 | mutable uint8_t mBackbufferIndex; |
| 225 | mutable Mutex mSurfaceLock; |
Mathias Agopian | dff8e58 | 2009-05-04 14:17:04 -0700 | [diff] [blame] | 226 | Rect mSwapRectangle; |
| 227 | BufferMapper& mBufferMapper; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 228 | }; |
| 229 | |
| 230 | }; // namespace android |
| 231 | |
| 232 | #endif // ANDROID_UI_SURFACE_H |
| 233 | |