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 | |
Mathias Agopian | 9cce325 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 17 | #ifndef ANDROID_SF_SURFACE_H |
| 18 | #define ANDROID_SF_SURFACE_H |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 19 | |
| 20 | #include <stdint.h> |
| 21 | #include <sys/types.h> |
| 22 | |
Jamie Gennis | aca4e22 | 2010-07-15 17:29:15 -0700 | [diff] [blame] | 23 | #include <utils/KeyedVector.h> |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 24 | #include <utils/RefBase.h> |
| 25 | #include <utils/threads.h> |
| 26 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 27 | #include <ui/PixelFormat.h> |
| 28 | #include <ui/Region.h> |
Mathias Agopian | 7189c00 | 2009-05-05 18:11:11 -0700 | [diff] [blame] | 29 | #include <ui/egl/android_natives.h> |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 30 | |
Mathias Agopian | 8f9dbf9 | 2011-07-13 17:39:11 -0700 | [diff] [blame^] | 31 | #include <gui/SurfaceTextureClient.h> |
| 32 | |
Mathias Agopian | 9cce325 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 33 | #include <surfaceflinger/ISurface.h> |
Mathias Agopian | 7e27f05 | 2010-05-28 14:22:23 -0700 | [diff] [blame] | 34 | #include <surfaceflinger/ISurfaceComposerClient.h> |
Mathias Agopian | 9cce325 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 35 | |
Mathias Agopian | e4e8cf1 | 2010-04-12 16:22:15 -0700 | [diff] [blame] | 36 | #define ANDROID_VIEW_SURFACE_JNI_ID "mNativeSurface" |
| 37 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 38 | namespace android { |
| 39 | |
| 40 | // --------------------------------------------------------------------------- |
| 41 | |
tedbo | 1e7fa9e | 2011-06-22 15:52:53 -0700 | [diff] [blame] | 42 | class ISurfaceTexture; |
Mathias Agopian | 0926f50 | 2009-05-04 14:17:04 -0700 | [diff] [blame] | 43 | class Surface; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 44 | class SurfaceComposerClient; |
| 45 | |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 46 | // --------------------------------------------------------------------------- |
| 47 | |
Mathias Agopian | 62185b7 | 2009-04-16 16:19:50 -0700 | [diff] [blame] | 48 | class SurfaceControl : public RefBase |
| 49 | { |
| 50 | public: |
| 51 | static bool isValid(const sp<SurfaceControl>& surface) { |
Mathias Agopian | 01b7668 | 2009-04-16 20:04:08 -0700 | [diff] [blame] | 52 | return (surface != 0) && surface->isValid(); |
Mathias Agopian | 62185b7 | 2009-04-16 16:19:50 -0700 | [diff] [blame] | 53 | } |
Mathias Agopian | 01b7668 | 2009-04-16 20:04:08 -0700 | [diff] [blame] | 54 | bool isValid() { |
| 55 | return mToken>=0 && mClient!=0; |
| 56 | } |
| 57 | static bool isSameSurface( |
| 58 | const sp<SurfaceControl>& lhs, const sp<SurfaceControl>& rhs); |
Mathias Agopian | 62185b7 | 2009-04-16 16:19:50 -0700 | [diff] [blame] | 59 | |
Mathias Agopian | 62185b7 | 2009-04-16 16:19:50 -0700 | [diff] [blame] | 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 | 62185b7 | 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 | 01b7668 | 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 | 62185b7 | 2009-04-16 16:19:50 -0700 | [diff] [blame] | 84 | private: |
Mathias Agopian | 01b7668 | 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 | 62185b7 | 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 |
Jamie Gennis | 89c2dd2 | 2010-08-10 16:37:53 -0700 | [diff] [blame] | 93 | friend class CameraService; |
Mathias Agopian | 62185b7 | 2009-04-16 16:19:50 -0700 | [diff] [blame] | 94 | friend class MediaRecorder; |
| 95 | // mediaplayer needs access to ISurface for display |
| 96 | friend class MediaPlayer; |
Mathias Agopian | 01b7668 | 2009-04-16 20:04:08 -0700 | [diff] [blame] | 97 | // for testing |
Mathias Agopian | 62185b7 | 2009-04-16 16:19:50 -0700 | [diff] [blame] | 98 | friend class Test; |
Dharmaray Kundargi | b678316 | 2011-01-16 16:43:20 -0800 | [diff] [blame] | 99 | // videoEditor preview classes |
| 100 | friend class VideoEditorPreviewController; |
Mathias Agopian | 62185b7 | 2009-04-16 16:19:50 -0700 | [diff] [blame] | 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, |
Mathias Agopian | 7e27f05 | 2010-05-28 14:22:23 -0700 | [diff] [blame] | 106 | const ISurfaceComposerClient::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 | 963abad | 2009-11-13 15:26:29 -0800 | [diff] [blame] | 111 | status_t validate() const; |
Mathias Agopian | 62185b7 | 2009-04-16 16:19:50 -0700 | [diff] [blame] | 112 | void destroy(); |
| 113 | |
| 114 | sp<SurfaceComposerClient> mClient; |
| 115 | sp<ISurface> mSurface; |
| 116 | SurfaceID mToken; |
| 117 | uint32_t mIdentity; |
Mathias Agopian | cb6b904 | 2009-07-30 18:14:56 -0700 | [diff] [blame] | 118 | uint32_t mWidth; |
| 119 | uint32_t mHeight; |
Mathias Agopian | 62185b7 | 2009-04-16 16:19:50 -0700 | [diff] [blame] | 120 | PixelFormat mFormat; |
| 121 | uint32_t mFlags; |
Mathias Agopian | 62185b7 | 2009-04-16 16:19:50 -0700 | [diff] [blame] | 122 | mutable Mutex mLock; |
Mathias Agopian | 01b7668 | 2009-04-16 20:04:08 -0700 | [diff] [blame] | 123 | |
| 124 | mutable sp<Surface> mSurfaceData; |
Mathias Agopian | 62185b7 | 2009-04-16 16:19:50 -0700 | [diff] [blame] | 125 | }; |
| 126 | |
| 127 | // --------------------------------------------------------------------------- |
| 128 | |
Mathias Agopian | 8f9dbf9 | 2011-07-13 17:39:11 -0700 | [diff] [blame^] | 129 | class Surface : public SurfaceTextureClient |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 130 | { |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 131 | public: |
| 132 | struct SurfaceInfo { |
| 133 | uint32_t w; |
| 134 | uint32_t h; |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 135 | uint32_t s; |
| 136 | uint32_t usage; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 137 | PixelFormat format; |
| 138 | void* bits; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 139 | uint32_t reserved[2]; |
| 140 | }; |
| 141 | |
Mathias Agopian | 579b3f8 | 2010-06-08 19:54:15 -0700 | [diff] [blame] | 142 | static status_t writeToParcel( |
| 143 | const sp<Surface>& control, Parcel* parcel); |
| 144 | |
Jamie Gennis | aca4e22 | 2010-07-15 17:29:15 -0700 | [diff] [blame] | 145 | static sp<Surface> readFromParcel(const Parcel& data); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 146 | |
Mathias Agopian | 01b7668 | 2009-04-16 20:04:08 -0700 | [diff] [blame] | 147 | static bool isValid(const sp<Surface>& surface) { |
| 148 | return (surface != 0) && surface->isValid(); |
| 149 | } |
Mathias Agopian | ba5972f | 2009-08-14 18:52:17 -0700 | [diff] [blame] | 150 | |
Mathias Agopian | ba5972f | 2009-08-14 18:52:17 -0700 | [diff] [blame] | 151 | bool isValid(); |
Mathias Agopian | ba5972f | 2009-08-14 18:52:17 -0700 | [diff] [blame] | 152 | uint32_t getFlags() const { return mFlags; } |
Mathias Agopian | 01b7668 | 2009-04-16 20:04:08 -0700 | [diff] [blame] | 153 | uint32_t getIdentity() const { return mIdentity; } |
tedbo | 1e7fa9e | 2011-06-22 15:52:53 -0700 | [diff] [blame] | 154 | sp<ISurfaceTexture> getSurfaceTexture(); |
Mathias Agopian | 01b7668 | 2009-04-16 20:04:08 -0700 | [diff] [blame] | 155 | |
Mathias Agopian | ba5972f | 2009-08-14 18:52:17 -0700 | [diff] [blame] | 156 | // the lock/unlock APIs must be used from the same thread |
Mathias Agopian | 8f9dbf9 | 2011-07-13 17:39:11 -0700 | [diff] [blame^] | 157 | status_t lock(SurfaceInfo* info, Region* dirty = NULL); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 158 | status_t unlockAndPost(); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 159 | |
Mathias Agopian | 47d8730 | 2011-04-05 15:44:20 -0700 | [diff] [blame] | 160 | sp<IBinder> asBinder() const; |
Mathias Agopian | b296533 | 2010-04-27 16:41:19 -0700 | [diff] [blame] | 161 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 162 | private: |
Mathias Agopian | ba5972f | 2009-08-14 18:52:17 -0700 | [diff] [blame] | 163 | // this is just to be able to write some unit tests |
| 164 | friend class Test; |
Mathias Agopian | b296533 | 2010-04-27 16:41:19 -0700 | [diff] [blame] | 165 | friend class SurfaceControl; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 166 | |
Mathias Agopian | b296533 | 2010-04-27 16:41:19 -0700 | [diff] [blame] | 167 | // can't be copied |
| 168 | Surface& operator = (Surface& rhs); |
| 169 | Surface(const Surface& rhs); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 170 | |
Mathias Agopian | b296533 | 2010-04-27 16:41:19 -0700 | [diff] [blame] | 171 | Surface(const sp<SurfaceControl>& control); |
Mathias Agopian | a0c30e9 | 2010-06-04 18:26:32 -0700 | [diff] [blame] | 172 | Surface(const Parcel& data, const sp<IBinder>& ref); |
Mathias Agopian | b296533 | 2010-04-27 16:41:19 -0700 | [diff] [blame] | 173 | ~Surface(); |
| 174 | |
Mathias Agopian | b296533 | 2010-04-27 16:41:19 -0700 | [diff] [blame] | 175 | /* |
| 176 | * private stuff... |
| 177 | */ |
| 178 | void init(); |
Mathias Agopian | a317f1b | 2011-01-14 11:04:34 -0800 | [diff] [blame] | 179 | status_t validate(bool inCancelBuffer = false) const; |
Mathias Agopian | b296533 | 2010-04-27 16:41:19 -0700 | [diff] [blame] | 180 | |
Mathias Agopian | 455d18d | 2010-12-13 16:47:31 -0800 | [diff] [blame] | 181 | static void cleanCachedSurfacesLocked(); |
Jamie Gennis | aca4e22 | 2010-07-15 17:29:15 -0700 | [diff] [blame] | 182 | |
Mathias Agopian | 8f9dbf9 | 2011-07-13 17:39:11 -0700 | [diff] [blame^] | 183 | virtual int query(int what, int* value) const; |
| 184 | |
Mathias Agopian | ba5972f | 2009-08-14 18:52:17 -0700 | [diff] [blame] | 185 | // constants |
Mathias Agopian | b7e930d | 2010-06-01 15:12:58 -0700 | [diff] [blame] | 186 | status_t mInitCheck; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 187 | sp<ISurface> mSurface; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 188 | uint32_t mIdentity; |
| 189 | PixelFormat mFormat; |
| 190 | uint32_t mFlags; |
Mathias Agopian | ba5972f | 2009-08-14 18:52:17 -0700 | [diff] [blame] | 191 | |
| 192 | // query() must be called from dequeueBuffer() thread |
| 193 | uint32_t mWidth; |
| 194 | uint32_t mHeight; |
| 195 | |
Jamie Gennis | aca4e22 | 2010-07-15 17:29:15 -0700 | [diff] [blame] | 196 | // A cache of Surface objects that have been deserialized into this process. |
| 197 | static Mutex sCachedSurfacesLock; |
| 198 | static DefaultKeyedVector<wp<IBinder>, wp<Surface> > sCachedSurfaces; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 199 | }; |
| 200 | |
| 201 | }; // namespace android |
| 202 | |
Mathias Agopian | 9cce325 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 203 | #endif // ANDROID_SF_SURFACE_H |