Jamie Gennis | 68e4a7a | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 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 | #define LOG_TAG "SurfaceTextureClient" |
Jamie Gennis | e8d0e8a | 2011-01-12 20:22:41 -0800 | [diff] [blame] | 18 | //#define LOG_NDEBUG 0 |
Jamie Gennis | 68e4a7a | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 19 | |
| 20 | #include <gui/SurfaceTextureClient.h> |
| 21 | |
| 22 | #include <utils/Log.h> |
| 23 | |
| 24 | namespace android { |
| 25 | |
| 26 | SurfaceTextureClient::SurfaceTextureClient( |
| 27 | const sp<ISurfaceTexture>& surfaceTexture): |
Mathias Agopian | e5a1bff | 2011-03-31 19:10:24 -0700 | [diff] [blame] | 28 | mSurfaceTexture(surfaceTexture), mAllocator(0), mReqWidth(0), |
Mathias Agopian | 27cd07c | 2011-04-11 21:19:55 -0700 | [diff] [blame] | 29 | mReqHeight(0), mReqFormat(0), mReqUsage(0), |
| 30 | mTimestamp(NATIVE_WINDOW_TIMESTAMP_AUTO), mConnectedApi(0), |
| 31 | mQueryWidth(0), mQueryHeight(0), mQueryFormat(0), |
| 32 | mMutex() { |
Jamie Gennis | 68e4a7a | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 33 | // Initialize the ANativeWindow function pointers. |
| 34 | ANativeWindow::setSwapInterval = setSwapInterval; |
| 35 | ANativeWindow::dequeueBuffer = dequeueBuffer; |
| 36 | ANativeWindow::cancelBuffer = cancelBuffer; |
| 37 | ANativeWindow::lockBuffer = lockBuffer; |
| 38 | ANativeWindow::queueBuffer = queueBuffer; |
| 39 | ANativeWindow::query = query; |
| 40 | ANativeWindow::perform = perform; |
Jamie Gennis | 83bac21 | 2011-02-02 15:31:47 -0800 | [diff] [blame] | 41 | |
Mathias Agopian | 402ff24 | 2011-05-02 19:51:12 -0700 | [diff] [blame] | 42 | const_cast<int&>(ANativeWindow::minSwapInterval) = 0; |
| 43 | const_cast<int&>(ANativeWindow::maxSwapInterval) = 1; |
| 44 | |
Jamie Gennis | 83bac21 | 2011-02-02 15:31:47 -0800 | [diff] [blame] | 45 | // Get a reference to the allocator. |
| 46 | mAllocator = mSurfaceTexture->getAllocator(); |
Jamie Gennis | 68e4a7a | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 47 | } |
| 48 | |
Jamie Gennis | f95a9f0 | 2011-03-14 15:08:53 -0700 | [diff] [blame] | 49 | sp<ISurfaceTexture> SurfaceTextureClient::getISurfaceTexture() const { |
| 50 | return mSurfaceTexture; |
| 51 | } |
| 52 | |
Jamie Gennis | 68e4a7a | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 53 | int SurfaceTextureClient::setSwapInterval(ANativeWindow* window, int interval) { |
| 54 | SurfaceTextureClient* c = getSelf(window); |
| 55 | return c->setSwapInterval(interval); |
| 56 | } |
| 57 | |
| 58 | int SurfaceTextureClient::dequeueBuffer(ANativeWindow* window, |
Iliyan Malchev | b2a153a | 2011-05-01 11:33:26 -0700 | [diff] [blame] | 59 | ANativeWindowBuffer** buffer) { |
Jamie Gennis | 68e4a7a | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 60 | SurfaceTextureClient* c = getSelf(window); |
| 61 | return c->dequeueBuffer(buffer); |
| 62 | } |
| 63 | |
| 64 | int SurfaceTextureClient::cancelBuffer(ANativeWindow* window, |
Iliyan Malchev | b2a153a | 2011-05-01 11:33:26 -0700 | [diff] [blame] | 65 | ANativeWindowBuffer* buffer) { |
Jamie Gennis | 68e4a7a | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 66 | SurfaceTextureClient* c = getSelf(window); |
| 67 | return c->cancelBuffer(buffer); |
| 68 | } |
| 69 | |
| 70 | int SurfaceTextureClient::lockBuffer(ANativeWindow* window, |
Iliyan Malchev | b2a153a | 2011-05-01 11:33:26 -0700 | [diff] [blame] | 71 | ANativeWindowBuffer* buffer) { |
Jamie Gennis | 68e4a7a | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 72 | SurfaceTextureClient* c = getSelf(window); |
| 73 | return c->lockBuffer(buffer); |
| 74 | } |
| 75 | |
| 76 | int SurfaceTextureClient::queueBuffer(ANativeWindow* window, |
Iliyan Malchev | b2a153a | 2011-05-01 11:33:26 -0700 | [diff] [blame] | 77 | ANativeWindowBuffer* buffer) { |
Jamie Gennis | 68e4a7a | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 78 | SurfaceTextureClient* c = getSelf(window); |
| 79 | return c->queueBuffer(buffer); |
| 80 | } |
| 81 | |
Iliyan Malchev | 4d7c1ce | 2011-04-14 16:54:38 -0700 | [diff] [blame] | 82 | int SurfaceTextureClient::query(const ANativeWindow* window, |
| 83 | int what, int* value) { |
| 84 | const SurfaceTextureClient* c = getSelf(window); |
Jamie Gennis | 68e4a7a | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 85 | return c->query(what, value); |
| 86 | } |
| 87 | |
| 88 | int SurfaceTextureClient::perform(ANativeWindow* window, int operation, ...) { |
| 89 | va_list args; |
| 90 | va_start(args, operation); |
| 91 | SurfaceTextureClient* c = getSelf(window); |
| 92 | return c->perform(operation, args); |
| 93 | } |
| 94 | |
| 95 | int SurfaceTextureClient::setSwapInterval(int interval) { |
Mathias Agopian | 402ff24 | 2011-05-02 19:51:12 -0700 | [diff] [blame] | 96 | // EGL specification states: |
| 97 | // interval is silently clamped to minimum and maximum implementation |
| 98 | // dependent values before being stored. |
| 99 | // Although we don't have to, we apply the same logic here. |
| 100 | |
| 101 | if (interval < minSwapInterval) |
| 102 | interval = minSwapInterval; |
| 103 | |
| 104 | if (interval > maxSwapInterval) |
| 105 | interval = maxSwapInterval; |
| 106 | |
| 107 | status_t res = mSurfaceTexture->setSynchronousMode(interval ? true : false); |
| 108 | |
| 109 | return res; |
Jamie Gennis | 68e4a7a | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 110 | } |
| 111 | |
| 112 | int SurfaceTextureClient::dequeueBuffer(android_native_buffer_t** buffer) { |
Jamie Gennis | e8d0e8a | 2011-01-12 20:22:41 -0800 | [diff] [blame] | 113 | LOGV("SurfaceTextureClient::dequeueBuffer"); |
Jamie Gennis | 68e4a7a | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 114 | Mutex::Autolock lock(mMutex); |
| 115 | int buf = -1; |
Mathias Agopian | 402ff24 | 2011-05-02 19:51:12 -0700 | [diff] [blame] | 116 | status_t result = mSurfaceTexture->dequeueBuffer(&buf, mReqWidth, mReqHeight, |
Mathias Agopian | 0297dca | 2011-04-25 20:22:14 -0700 | [diff] [blame] | 117 | mReqFormat, mReqUsage); |
Mathias Agopian | 402ff24 | 2011-05-02 19:51:12 -0700 | [diff] [blame] | 118 | if (result < 0) { |
Mathias Agopian | 0297dca | 2011-04-25 20:22:14 -0700 | [diff] [blame] | 119 | LOGV("dequeueBuffer: ISurfaceTexture::dequeueBuffer(%d, %d, %d, %d)" |
Jamie Gennis | a218715 | 2011-05-19 13:33:00 -0700 | [diff] [blame] | 120 | "failed: %d", mReqWidth, mReqHeight, mReqFormat, mReqUsage, |
| 121 | result); |
Mathias Agopian | 402ff24 | 2011-05-02 19:51:12 -0700 | [diff] [blame] | 122 | return result; |
Jamie Gennis | 68e4a7a | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 123 | } |
| 124 | sp<GraphicBuffer>& gbuf(mSlots[buf]); |
Mathias Agopian | 402ff24 | 2011-05-02 19:51:12 -0700 | [diff] [blame] | 125 | if (result & ISurfaceTexture::RELEASE_ALL_BUFFERS) { |
| 126 | freeAllBuffers(); |
| 127 | } |
| 128 | |
| 129 | if ((result & ISurfaceTexture::BUFFER_NEEDS_REALLOCATION) || gbuf == 0) { |
Mathias Agopian | 0297dca | 2011-04-25 20:22:14 -0700 | [diff] [blame] | 130 | gbuf = mSurfaceTexture->requestBuffer(buf); |
Jamie Gennis | 68e4a7a | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 131 | if (gbuf == 0) { |
Jamie Gennis | e8d0e8a | 2011-01-12 20:22:41 -0800 | [diff] [blame] | 132 | LOGE("dequeueBuffer: ISurfaceTexture::requestBuffer failed"); |
Jamie Gennis | 68e4a7a | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 133 | return NO_MEMORY; |
| 134 | } |
Mathias Agopian | 27cd07c | 2011-04-11 21:19:55 -0700 | [diff] [blame] | 135 | mQueryWidth = gbuf->width; |
| 136 | mQueryHeight = gbuf->height; |
| 137 | mQueryFormat = gbuf->format; |
Jamie Gennis | 68e4a7a | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 138 | } |
| 139 | *buffer = gbuf.get(); |
| 140 | return OK; |
| 141 | } |
| 142 | |
| 143 | int SurfaceTextureClient::cancelBuffer(android_native_buffer_t* buffer) { |
Jamie Gennis | e8d0e8a | 2011-01-12 20:22:41 -0800 | [diff] [blame] | 144 | LOGV("SurfaceTextureClient::cancelBuffer"); |
Jamie Gennis | 68e4a7a | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 145 | Mutex::Autolock lock(mMutex); |
Jamie Gennis | aff7405 | 2011-06-20 12:04:09 -0700 | [diff] [blame] | 146 | int i = getSlotFromBufferLocked(buffer); |
| 147 | if (i < 0) { |
| 148 | return i; |
| 149 | } |
| 150 | mSurfaceTexture->cancelBuffer(i); |
| 151 | return OK; |
| 152 | } |
| 153 | |
| 154 | int SurfaceTextureClient::getSlotFromBufferLocked( |
| 155 | android_native_buffer_t* buffer) const { |
| 156 | bool dumpedState = false; |
Jamie Gennis | 68e4a7a | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 157 | for (int i = 0; i < NUM_BUFFER_SLOTS; i++) { |
Jamie Gennis | aff7405 | 2011-06-20 12:04:09 -0700 | [diff] [blame] | 158 | // XXX: Dump the slots whenever we hit a NULL entry while searching for |
| 159 | // a buffer. |
| 160 | if (mSlots[i] == NULL) { |
| 161 | if (!dumpedState) { |
| 162 | LOGD("getSlotFromBufferLocked: encountered NULL buffer in slot %d " |
| 163 | "looking for buffer %p", i, buffer->handle); |
| 164 | for (int j = 0; j < NUM_BUFFER_SLOTS; j++) { |
| 165 | if (mSlots[j] == NULL) { |
| 166 | LOGD("getSlotFromBufferLocked: %02d: NULL", j); |
| 167 | } else { |
| 168 | LOGD("getSlotFromBufferLocked: %02d: %p", j, mSlots[j]->handle); |
| 169 | } |
| 170 | } |
| 171 | dumpedState = true; |
| 172 | } |
| 173 | } |
| 174 | |
| 175 | if (mSlots[i] != NULL && mSlots[i]->handle == buffer->handle) { |
| 176 | return i; |
Jamie Gennis | 68e4a7a | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 177 | } |
| 178 | } |
Jamie Gennis | aff7405 | 2011-06-20 12:04:09 -0700 | [diff] [blame] | 179 | LOGE("getSlotFromBufferLocked: unknown buffer: %p", buffer->handle); |
Jamie Gennis | 68e4a7a | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 180 | return BAD_VALUE; |
| 181 | } |
| 182 | |
| 183 | int SurfaceTextureClient::lockBuffer(android_native_buffer_t* buffer) { |
Jamie Gennis | e8d0e8a | 2011-01-12 20:22:41 -0800 | [diff] [blame] | 184 | LOGV("SurfaceTextureClient::lockBuffer"); |
Jamie Gennis | 68e4a7a | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 185 | Mutex::Autolock lock(mMutex); |
| 186 | return OK; |
| 187 | } |
| 188 | |
| 189 | int SurfaceTextureClient::queueBuffer(android_native_buffer_t* buffer) { |
Jamie Gennis | e8d0e8a | 2011-01-12 20:22:41 -0800 | [diff] [blame] | 190 | LOGV("SurfaceTextureClient::queueBuffer"); |
Jamie Gennis | 68e4a7a | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 191 | Mutex::Autolock lock(mMutex); |
Eino-Ville Talvala | c5f94d8 | 2011-02-18 11:02:42 -0800 | [diff] [blame] | 192 | int64_t timestamp; |
| 193 | if (mTimestamp == NATIVE_WINDOW_TIMESTAMP_AUTO) { |
| 194 | timestamp = systemTime(SYSTEM_TIME_MONOTONIC); |
| 195 | LOGV("SurfaceTextureClient::queueBuffer making up timestamp: %.2f ms", |
| 196 | timestamp / 1000000.f); |
| 197 | } else { |
| 198 | timestamp = mTimestamp; |
| 199 | } |
Jamie Gennis | aff7405 | 2011-06-20 12:04:09 -0700 | [diff] [blame] | 200 | int i = getSlotFromBufferLocked(buffer); |
| 201 | if (i < 0) { |
| 202 | return i; |
Jamie Gennis | 68e4a7a | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 203 | } |
Jamie Gennis | aff7405 | 2011-06-20 12:04:09 -0700 | [diff] [blame] | 204 | mSurfaceTexture->queueBuffer(i, timestamp); |
| 205 | return OK; |
Jamie Gennis | 68e4a7a | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 206 | } |
| 207 | |
Iliyan Malchev | 4d7c1ce | 2011-04-14 16:54:38 -0700 | [diff] [blame] | 208 | int SurfaceTextureClient::query(int what, int* value) const { |
Jamie Gennis | e8d0e8a | 2011-01-12 20:22:41 -0800 | [diff] [blame] | 209 | LOGV("SurfaceTextureClient::query"); |
Jamie Gennis | 96dcc97 | 2011-02-27 14:10:20 -0800 | [diff] [blame] | 210 | switch (what) { |
Mathias Agopian | 7bb843c | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 211 | case NATIVE_WINDOW_FORMAT: |
| 212 | if (mReqFormat) { |
| 213 | *value = mReqFormat; |
| 214 | return NO_ERROR; |
| 215 | } |
| 216 | break; |
Jamie Gennis | d2acedf | 2011-03-08 12:18:54 -0800 | [diff] [blame] | 217 | case NATIVE_WINDOW_QUEUES_TO_WINDOW_COMPOSER: |
Mathias Agopian | ed3894c | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 218 | // TODO: this is not needed anymore |
Jamie Gennis | d2acedf | 2011-03-08 12:18:54 -0800 | [diff] [blame] | 219 | *value = 0; |
| 220 | return NO_ERROR; |
Jamie Gennis | c4ca7c5 | 2011-03-14 15:00:06 -0700 | [diff] [blame] | 221 | case NATIVE_WINDOW_CONCRETE_TYPE: |
Mathias Agopian | ed3894c | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 222 | // TODO: this is not needed anymore |
Jamie Gennis | c4ca7c5 | 2011-03-14 15:00:06 -0700 | [diff] [blame] | 223 | *value = NATIVE_WINDOW_SURFACE_TEXTURE_CLIENT; |
| 224 | return NO_ERROR; |
Jamie Gennis | 96dcc97 | 2011-02-27 14:10:20 -0800 | [diff] [blame] | 225 | } |
Mathias Agopian | ed3894c | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 226 | return mSurfaceTexture->query(what, value); |
Jamie Gennis | 68e4a7a | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 227 | } |
| 228 | |
| 229 | int SurfaceTextureClient::perform(int operation, va_list args) |
| 230 | { |
| 231 | int res = NO_ERROR; |
| 232 | switch (operation) { |
| 233 | case NATIVE_WINDOW_CONNECT: |
| 234 | res = dispatchConnect(args); |
| 235 | break; |
| 236 | case NATIVE_WINDOW_DISCONNECT: |
| 237 | res = dispatchDisconnect(args); |
| 238 | break; |
| 239 | case NATIVE_WINDOW_SET_USAGE: |
| 240 | res = dispatchSetUsage(args); |
| 241 | break; |
| 242 | case NATIVE_WINDOW_SET_CROP: |
| 243 | res = dispatchSetCrop(args); |
| 244 | break; |
| 245 | case NATIVE_WINDOW_SET_BUFFER_COUNT: |
| 246 | res = dispatchSetBufferCount(args); |
| 247 | break; |
| 248 | case NATIVE_WINDOW_SET_BUFFERS_GEOMETRY: |
| 249 | res = dispatchSetBuffersGeometry(args); |
| 250 | break; |
| 251 | case NATIVE_WINDOW_SET_BUFFERS_TRANSFORM: |
| 252 | res = dispatchSetBuffersTransform(args); |
| 253 | break; |
Eino-Ville Talvala | c5f94d8 | 2011-02-18 11:02:42 -0800 | [diff] [blame] | 254 | case NATIVE_WINDOW_SET_BUFFERS_TIMESTAMP: |
| 255 | res = dispatchSetBuffersTimestamp(args); |
| 256 | break; |
Jamie Gennis | 68e4a7a | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 257 | default: |
| 258 | res = NAME_NOT_FOUND; |
| 259 | break; |
| 260 | } |
| 261 | return res; |
| 262 | } |
| 263 | |
| 264 | int SurfaceTextureClient::dispatchConnect(va_list args) { |
| 265 | int api = va_arg(args, int); |
| 266 | return connect(api); |
| 267 | } |
| 268 | |
| 269 | int SurfaceTextureClient::dispatchDisconnect(va_list args) { |
| 270 | int api = va_arg(args, int); |
| 271 | return disconnect(api); |
| 272 | } |
| 273 | |
| 274 | int SurfaceTextureClient::dispatchSetUsage(va_list args) { |
| 275 | int usage = va_arg(args, int); |
| 276 | return setUsage(usage); |
| 277 | } |
| 278 | |
| 279 | int SurfaceTextureClient::dispatchSetCrop(va_list args) { |
| 280 | android_native_rect_t const* rect = va_arg(args, android_native_rect_t*); |
| 281 | return setCrop(reinterpret_cast<Rect const*>(rect)); |
| 282 | } |
| 283 | |
| 284 | int SurfaceTextureClient::dispatchSetBufferCount(va_list args) { |
| 285 | size_t bufferCount = va_arg(args, size_t); |
| 286 | return setBufferCount(bufferCount); |
| 287 | } |
| 288 | |
| 289 | int SurfaceTextureClient::dispatchSetBuffersGeometry(va_list args) { |
| 290 | int w = va_arg(args, int); |
| 291 | int h = va_arg(args, int); |
| 292 | int f = va_arg(args, int); |
| 293 | return setBuffersGeometry(w, h, f); |
| 294 | } |
| 295 | |
| 296 | int SurfaceTextureClient::dispatchSetBuffersTransform(va_list args) { |
| 297 | int transform = va_arg(args, int); |
| 298 | return setBuffersTransform(transform); |
| 299 | } |
| 300 | |
Eino-Ville Talvala | c5f94d8 | 2011-02-18 11:02:42 -0800 | [diff] [blame] | 301 | int SurfaceTextureClient::dispatchSetBuffersTimestamp(va_list args) { |
| 302 | int64_t timestamp = va_arg(args, int64_t); |
| 303 | return setBuffersTimestamp(timestamp); |
| 304 | } |
| 305 | |
Jamie Gennis | 68e4a7a | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 306 | int SurfaceTextureClient::connect(int api) { |
Jamie Gennis | e8d0e8a | 2011-01-12 20:22:41 -0800 | [diff] [blame] | 307 | LOGV("SurfaceTextureClient::connect"); |
Mathias Agopian | 27cd07c | 2011-04-11 21:19:55 -0700 | [diff] [blame] | 308 | Mutex::Autolock lock(mMutex); |
| 309 | int err = NO_ERROR; |
| 310 | switch (api) { |
| 311 | case NATIVE_WINDOW_API_EGL: |
| 312 | if (mConnectedApi) { |
| 313 | err = -EINVAL; |
| 314 | } else { |
| 315 | mConnectedApi = api; |
| 316 | } |
| 317 | break; |
| 318 | default: |
| 319 | err = -EINVAL; |
| 320 | break; |
| 321 | } |
| 322 | return err; |
Jamie Gennis | 68e4a7a | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 323 | } |
| 324 | |
| 325 | int SurfaceTextureClient::disconnect(int api) { |
Jamie Gennis | e8d0e8a | 2011-01-12 20:22:41 -0800 | [diff] [blame] | 326 | LOGV("SurfaceTextureClient::disconnect"); |
Mathias Agopian | 27cd07c | 2011-04-11 21:19:55 -0700 | [diff] [blame] | 327 | Mutex::Autolock lock(mMutex); |
| 328 | int err = NO_ERROR; |
| 329 | switch (api) { |
| 330 | case NATIVE_WINDOW_API_EGL: |
| 331 | if (mConnectedApi == api) { |
| 332 | mConnectedApi = 0; |
| 333 | } else { |
| 334 | err = -EINVAL; |
| 335 | } |
| 336 | break; |
| 337 | default: |
| 338 | err = -EINVAL; |
| 339 | break; |
| 340 | } |
| 341 | return err; |
Jamie Gennis | 68e4a7a | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 342 | } |
| 343 | |
Mathias Agopian | 27cd07c | 2011-04-11 21:19:55 -0700 | [diff] [blame] | 344 | int SurfaceTextureClient::getConnectedApi() const |
| 345 | { |
| 346 | Mutex::Autolock lock(mMutex); |
| 347 | return mConnectedApi; |
| 348 | } |
| 349 | |
| 350 | |
Jamie Gennis | 68e4a7a | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 351 | int SurfaceTextureClient::setUsage(uint32_t reqUsage) |
| 352 | { |
Jamie Gennis | e8d0e8a | 2011-01-12 20:22:41 -0800 | [diff] [blame] | 353 | LOGV("SurfaceTextureClient::setUsage"); |
Jamie Gennis | 68e4a7a | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 354 | Mutex::Autolock lock(mMutex); |
| 355 | mReqUsage = reqUsage; |
| 356 | return OK; |
| 357 | } |
| 358 | |
| 359 | int SurfaceTextureClient::setCrop(Rect const* rect) |
| 360 | { |
Jamie Gennis | e8d0e8a | 2011-01-12 20:22:41 -0800 | [diff] [blame] | 361 | LOGV("SurfaceTextureClient::setCrop"); |
Jamie Gennis | 68e4a7a | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 362 | Mutex::Autolock lock(mMutex); |
| 363 | |
Jamie Gennis | 2ece4cd | 2011-01-28 18:21:54 -0800 | [diff] [blame] | 364 | Rect realRect; |
| 365 | if (rect == NULL || rect->isEmpty()) { |
| 366 | realRect = Rect(0, 0); |
| 367 | } else { |
| 368 | realRect = *rect; |
| 369 | } |
Jamie Gennis | 68e4a7a | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 370 | |
| 371 | status_t err = mSurfaceTexture->setCrop(*rect); |
Jamie Gennis | 2ece4cd | 2011-01-28 18:21:54 -0800 | [diff] [blame] | 372 | LOGE_IF(err, "ISurfaceTexture::setCrop(...) returned %s", strerror(-err)); |
Jamie Gennis | 68e4a7a | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 373 | |
| 374 | return err; |
| 375 | } |
| 376 | |
| 377 | int SurfaceTextureClient::setBufferCount(int bufferCount) |
| 378 | { |
Jamie Gennis | e8d0e8a | 2011-01-12 20:22:41 -0800 | [diff] [blame] | 379 | LOGV("SurfaceTextureClient::setBufferCount"); |
Jamie Gennis | 68e4a7a | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 380 | Mutex::Autolock lock(mMutex); |
| 381 | |
| 382 | status_t err = mSurfaceTexture->setBufferCount(bufferCount); |
| 383 | LOGE_IF(err, "ISurfaceTexture::setBufferCount(%d) returned %s", |
| 384 | bufferCount, strerror(-err)); |
| 385 | |
| 386 | if (err == NO_ERROR) { |
| 387 | freeAllBuffers(); |
| 388 | } |
| 389 | |
| 390 | return err; |
| 391 | } |
| 392 | |
| 393 | int SurfaceTextureClient::setBuffersGeometry(int w, int h, int format) |
| 394 | { |
Jamie Gennis | e8d0e8a | 2011-01-12 20:22:41 -0800 | [diff] [blame] | 395 | LOGV("SurfaceTextureClient::setBuffersGeometry"); |
Jamie Gennis | 68e4a7a | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 396 | Mutex::Autolock lock(mMutex); |
| 397 | |
| 398 | if (w<0 || h<0 || format<0) |
| 399 | return BAD_VALUE; |
| 400 | |
| 401 | if ((w && !h) || (!w && h)) |
| 402 | return BAD_VALUE; |
| 403 | |
| 404 | mReqWidth = w; |
| 405 | mReqHeight = h; |
| 406 | mReqFormat = format; |
| 407 | |
Jamie Gennis | 2ece4cd | 2011-01-28 18:21:54 -0800 | [diff] [blame] | 408 | status_t err = mSurfaceTexture->setCrop(Rect(0, 0)); |
| 409 | LOGE_IF(err, "ISurfaceTexture::setCrop(...) returned %s", strerror(-err)); |
| 410 | |
| 411 | return err; |
Jamie Gennis | 68e4a7a | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 412 | } |
| 413 | |
| 414 | int SurfaceTextureClient::setBuffersTransform(int transform) |
| 415 | { |
Jamie Gennis | e8d0e8a | 2011-01-12 20:22:41 -0800 | [diff] [blame] | 416 | LOGV("SurfaceTextureClient::setBuffersTransform"); |
Jamie Gennis | 68e4a7a | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 417 | Mutex::Autolock lock(mMutex); |
| 418 | status_t err = mSurfaceTexture->setTransform(transform); |
| 419 | return err; |
| 420 | } |
| 421 | |
Eino-Ville Talvala | c5f94d8 | 2011-02-18 11:02:42 -0800 | [diff] [blame] | 422 | int SurfaceTextureClient::setBuffersTimestamp(int64_t timestamp) |
| 423 | { |
| 424 | LOGV("SurfaceTextureClient::setBuffersTimestamp"); |
| 425 | Mutex::Autolock lock(mMutex); |
| 426 | mTimestamp = timestamp; |
| 427 | return NO_ERROR; |
| 428 | } |
| 429 | |
Jamie Gennis | 68e4a7a | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 430 | void SurfaceTextureClient::freeAllBuffers() { |
| 431 | for (int i = 0; i < NUM_BUFFER_SLOTS; i++) { |
| 432 | mSlots[i] = 0; |
| 433 | } |
| 434 | } |
| 435 | |
| 436 | }; // namespace android |