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