Jamie Gennis | 8ba32fa | 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 | e5366c5 | 2011-01-12 20:22:41 -0800 | [diff] [blame] | 18 | //#define LOG_NDEBUG 0 |
Jamie Gennis | 8ba32fa | 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 | a5c75c0 | 2011-03-31 19:10:24 -0700 | [diff] [blame] | 28 | mSurfaceTexture(surfaceTexture), mAllocator(0), mReqWidth(0), |
Mathias Agopian | 7a042bf | 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 | 8ba32fa | 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 | 1b20cde | 2011-02-02 15:31:47 -0800 | [diff] [blame] | 41 | |
| 42 | // Get a reference to the allocator. |
| 43 | mAllocator = mSurfaceTexture->getAllocator(); |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 44 | } |
| 45 | |
Jamie Gennis | bae774e | 2011-03-14 15:08:53 -0700 | [diff] [blame] | 46 | sp<ISurfaceTexture> SurfaceTextureClient::getISurfaceTexture() const { |
| 47 | return mSurfaceTexture; |
| 48 | } |
| 49 | |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 50 | int SurfaceTextureClient::setSwapInterval(ANativeWindow* window, int interval) { |
| 51 | SurfaceTextureClient* c = getSelf(window); |
| 52 | return c->setSwapInterval(interval); |
| 53 | } |
| 54 | |
| 55 | int SurfaceTextureClient::dequeueBuffer(ANativeWindow* window, |
| 56 | android_native_buffer_t** buffer) { |
| 57 | SurfaceTextureClient* c = getSelf(window); |
| 58 | return c->dequeueBuffer(buffer); |
| 59 | } |
| 60 | |
| 61 | int SurfaceTextureClient::cancelBuffer(ANativeWindow* window, |
| 62 | android_native_buffer_t* buffer) { |
| 63 | SurfaceTextureClient* c = getSelf(window); |
| 64 | return c->cancelBuffer(buffer); |
| 65 | } |
| 66 | |
| 67 | int SurfaceTextureClient::lockBuffer(ANativeWindow* window, |
| 68 | android_native_buffer_t* buffer) { |
| 69 | SurfaceTextureClient* c = getSelf(window); |
| 70 | return c->lockBuffer(buffer); |
| 71 | } |
| 72 | |
| 73 | int SurfaceTextureClient::queueBuffer(ANativeWindow* window, |
| 74 | android_native_buffer_t* buffer) { |
| 75 | SurfaceTextureClient* c = getSelf(window); |
| 76 | return c->queueBuffer(buffer); |
| 77 | } |
| 78 | |
| 79 | int SurfaceTextureClient::query(ANativeWindow* window, int what, int* value) { |
| 80 | SurfaceTextureClient* c = getSelf(window); |
| 81 | return c->query(what, value); |
| 82 | } |
| 83 | |
| 84 | int SurfaceTextureClient::perform(ANativeWindow* window, int operation, ...) { |
| 85 | va_list args; |
| 86 | va_start(args, operation); |
| 87 | SurfaceTextureClient* c = getSelf(window); |
| 88 | return c->perform(operation, args); |
| 89 | } |
| 90 | |
| 91 | int SurfaceTextureClient::setSwapInterval(int interval) { |
| 92 | return INVALID_OPERATION; |
| 93 | } |
| 94 | |
| 95 | int SurfaceTextureClient::dequeueBuffer(android_native_buffer_t** buffer) { |
Jamie Gennis | e5366c5 | 2011-01-12 20:22:41 -0800 | [diff] [blame] | 96 | LOGV("SurfaceTextureClient::dequeueBuffer"); |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 97 | Mutex::Autolock lock(mMutex); |
| 98 | int buf = -1; |
| 99 | status_t err = mSurfaceTexture->dequeueBuffer(&buf); |
| 100 | if (err < 0) { |
Jamie Gennis | 7491722 | 2011-01-28 12:03:52 -0800 | [diff] [blame] | 101 | LOGV("dequeueBuffer: ISurfaceTexture::dequeueBuffer failed: %d", err); |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 102 | return err; |
| 103 | } |
| 104 | sp<GraphicBuffer>& gbuf(mSlots[buf]); |
Mathias Agopian | a5c75c0 | 2011-03-31 19:10:24 -0700 | [diff] [blame] | 105 | if (err == ISurfaceTexture::BUFFER_NEEDS_REALLOCATION || |
Mathias Agopian | 7a042bf | 2011-04-11 21:19:55 -0700 | [diff] [blame^] | 106 | gbuf == 0 || |
| 107 | (mReqWidth && gbuf->getWidth() != mReqWidth) || |
| 108 | (mReqHeight && gbuf->getHeight() != mReqHeight) || |
| 109 | (mReqFormat && uint32_t(gbuf->getPixelFormat()) != mReqFormat) || |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 110 | (gbuf->getUsage() & mReqUsage) != mReqUsage) { |
| 111 | gbuf = mSurfaceTexture->requestBuffer(buf, mReqWidth, mReqHeight, |
| 112 | mReqFormat, mReqUsage); |
| 113 | if (gbuf == 0) { |
Jamie Gennis | e5366c5 | 2011-01-12 20:22:41 -0800 | [diff] [blame] | 114 | LOGE("dequeueBuffer: ISurfaceTexture::requestBuffer failed"); |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 115 | return NO_MEMORY; |
| 116 | } |
Mathias Agopian | 7a042bf | 2011-04-11 21:19:55 -0700 | [diff] [blame^] | 117 | mQueryWidth = gbuf->width; |
| 118 | mQueryHeight = gbuf->height; |
| 119 | mQueryFormat = gbuf->format; |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 120 | } |
| 121 | *buffer = gbuf.get(); |
| 122 | return OK; |
| 123 | } |
| 124 | |
| 125 | int SurfaceTextureClient::cancelBuffer(android_native_buffer_t* buffer) { |
Jamie Gennis | e5366c5 | 2011-01-12 20:22:41 -0800 | [diff] [blame] | 126 | LOGV("SurfaceTextureClient::cancelBuffer"); |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 127 | Mutex::Autolock lock(mMutex); |
| 128 | for (int i = 0; i < NUM_BUFFER_SLOTS; i++) { |
Jamie Gennis | 73e8b9e | 2011-01-15 13:05:24 -0800 | [diff] [blame] | 129 | if (mSlots[i]->handle == buffer->handle) { |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 130 | mSurfaceTexture->cancelBuffer(i); |
| 131 | return OK; |
| 132 | } |
| 133 | } |
| 134 | return BAD_VALUE; |
| 135 | } |
| 136 | |
| 137 | int SurfaceTextureClient::lockBuffer(android_native_buffer_t* buffer) { |
Jamie Gennis | e5366c5 | 2011-01-12 20:22:41 -0800 | [diff] [blame] | 138 | LOGV("SurfaceTextureClient::lockBuffer"); |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 139 | Mutex::Autolock lock(mMutex); |
| 140 | return OK; |
| 141 | } |
| 142 | |
| 143 | int SurfaceTextureClient::queueBuffer(android_native_buffer_t* buffer) { |
Jamie Gennis | e5366c5 | 2011-01-12 20:22:41 -0800 | [diff] [blame] | 144 | LOGV("SurfaceTextureClient::queueBuffer"); |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 145 | Mutex::Autolock lock(mMutex); |
Eino-Ville Talvala | 1d01a12 | 2011-02-18 11:02:42 -0800 | [diff] [blame] | 146 | int64_t timestamp; |
| 147 | if (mTimestamp == NATIVE_WINDOW_TIMESTAMP_AUTO) { |
| 148 | timestamp = systemTime(SYSTEM_TIME_MONOTONIC); |
| 149 | LOGV("SurfaceTextureClient::queueBuffer making up timestamp: %.2f ms", |
| 150 | timestamp / 1000000.f); |
| 151 | } else { |
| 152 | timestamp = mTimestamp; |
| 153 | } |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 154 | for (int i = 0; i < NUM_BUFFER_SLOTS; i++) { |
Jamie Gennis | 73e8b9e | 2011-01-15 13:05:24 -0800 | [diff] [blame] | 155 | if (mSlots[i]->handle == buffer->handle) { |
Eino-Ville Talvala | 1d01a12 | 2011-02-18 11:02:42 -0800 | [diff] [blame] | 156 | return mSurfaceTexture->queueBuffer(i, timestamp); |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 157 | } |
| 158 | } |
| 159 | LOGE("queueBuffer: unknown buffer queued"); |
| 160 | return BAD_VALUE; |
| 161 | } |
| 162 | |
| 163 | int SurfaceTextureClient::query(int what, int* value) { |
Jamie Gennis | e5366c5 | 2011-01-12 20:22:41 -0800 | [diff] [blame] | 164 | LOGV("SurfaceTextureClient::query"); |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 165 | Mutex::Autolock lock(mMutex); |
Jamie Gennis | 9d4d6c1 | 2011-02-27 14:10:20 -0800 | [diff] [blame] | 166 | switch (what) { |
| 167 | case NATIVE_WINDOW_WIDTH: |
Mathias Agopian | 7a042bf | 2011-04-11 21:19:55 -0700 | [diff] [blame^] | 168 | *value = mQueryWidth ? mQueryWidth : mReqWidth; |
| 169 | return NO_ERROR; |
Jamie Gennis | 9d4d6c1 | 2011-02-27 14:10:20 -0800 | [diff] [blame] | 170 | case NATIVE_WINDOW_HEIGHT: |
Mathias Agopian | 7a042bf | 2011-04-11 21:19:55 -0700 | [diff] [blame^] | 171 | *value = mQueryHeight ? mQueryHeight : mReqHeight; |
Jamie Gennis | 9d4d6c1 | 2011-02-27 14:10:20 -0800 | [diff] [blame] | 172 | return NO_ERROR; |
| 173 | case NATIVE_WINDOW_FORMAT: |
Mathias Agopian | 7a042bf | 2011-04-11 21:19:55 -0700 | [diff] [blame^] | 174 | *value = mQueryFormat ? mQueryFormat : mReqFormat; |
Jamie Gennis | 9d4d6c1 | 2011-02-27 14:10:20 -0800 | [diff] [blame] | 175 | return NO_ERROR; |
| 176 | case NATIVE_WINDOW_MIN_UNDEQUEUED_BUFFERS: |
| 177 | *value = MIN_UNDEQUEUED_BUFFERS; |
| 178 | return NO_ERROR; |
Jamie Gennis | 134f042 | 2011-03-08 12:18:54 -0800 | [diff] [blame] | 179 | case NATIVE_WINDOW_QUEUES_TO_WINDOW_COMPOSER: |
| 180 | // SurfaceTextureClient currently never queues frames to SurfaceFlinger. |
| 181 | *value = 0; |
| 182 | return NO_ERROR; |
Jamie Gennis | 391bbe2 | 2011-03-14 15:00:06 -0700 | [diff] [blame] | 183 | case NATIVE_WINDOW_CONCRETE_TYPE: |
| 184 | *value = NATIVE_WINDOW_SURFACE_TEXTURE_CLIENT; |
| 185 | return NO_ERROR; |
Jamie Gennis | 9d4d6c1 | 2011-02-27 14:10:20 -0800 | [diff] [blame] | 186 | } |
| 187 | return BAD_VALUE; |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 188 | } |
| 189 | |
| 190 | int SurfaceTextureClient::perform(int operation, va_list args) |
| 191 | { |
| 192 | int res = NO_ERROR; |
| 193 | switch (operation) { |
| 194 | case NATIVE_WINDOW_CONNECT: |
| 195 | res = dispatchConnect(args); |
| 196 | break; |
| 197 | case NATIVE_WINDOW_DISCONNECT: |
| 198 | res = dispatchDisconnect(args); |
| 199 | break; |
| 200 | case NATIVE_WINDOW_SET_USAGE: |
| 201 | res = dispatchSetUsage(args); |
| 202 | break; |
| 203 | case NATIVE_WINDOW_SET_CROP: |
| 204 | res = dispatchSetCrop(args); |
| 205 | break; |
| 206 | case NATIVE_WINDOW_SET_BUFFER_COUNT: |
| 207 | res = dispatchSetBufferCount(args); |
| 208 | break; |
| 209 | case NATIVE_WINDOW_SET_BUFFERS_GEOMETRY: |
| 210 | res = dispatchSetBuffersGeometry(args); |
| 211 | break; |
| 212 | case NATIVE_WINDOW_SET_BUFFERS_TRANSFORM: |
| 213 | res = dispatchSetBuffersTransform(args); |
| 214 | break; |
Eino-Ville Talvala | 1d01a12 | 2011-02-18 11:02:42 -0800 | [diff] [blame] | 215 | case NATIVE_WINDOW_SET_BUFFERS_TIMESTAMP: |
| 216 | res = dispatchSetBuffersTimestamp(args); |
| 217 | break; |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 218 | default: |
| 219 | res = NAME_NOT_FOUND; |
| 220 | break; |
| 221 | } |
| 222 | return res; |
| 223 | } |
| 224 | |
| 225 | int SurfaceTextureClient::dispatchConnect(va_list args) { |
| 226 | int api = va_arg(args, int); |
| 227 | return connect(api); |
| 228 | } |
| 229 | |
| 230 | int SurfaceTextureClient::dispatchDisconnect(va_list args) { |
| 231 | int api = va_arg(args, int); |
| 232 | return disconnect(api); |
| 233 | } |
| 234 | |
| 235 | int SurfaceTextureClient::dispatchSetUsage(va_list args) { |
| 236 | int usage = va_arg(args, int); |
| 237 | return setUsage(usage); |
| 238 | } |
| 239 | |
| 240 | int SurfaceTextureClient::dispatchSetCrop(va_list args) { |
| 241 | android_native_rect_t const* rect = va_arg(args, android_native_rect_t*); |
| 242 | return setCrop(reinterpret_cast<Rect const*>(rect)); |
| 243 | } |
| 244 | |
| 245 | int SurfaceTextureClient::dispatchSetBufferCount(va_list args) { |
| 246 | size_t bufferCount = va_arg(args, size_t); |
| 247 | return setBufferCount(bufferCount); |
| 248 | } |
| 249 | |
| 250 | int SurfaceTextureClient::dispatchSetBuffersGeometry(va_list args) { |
| 251 | int w = va_arg(args, int); |
| 252 | int h = va_arg(args, int); |
| 253 | int f = va_arg(args, int); |
| 254 | return setBuffersGeometry(w, h, f); |
| 255 | } |
| 256 | |
| 257 | int SurfaceTextureClient::dispatchSetBuffersTransform(va_list args) { |
| 258 | int transform = va_arg(args, int); |
| 259 | return setBuffersTransform(transform); |
| 260 | } |
| 261 | |
Eino-Ville Talvala | 1d01a12 | 2011-02-18 11:02:42 -0800 | [diff] [blame] | 262 | int SurfaceTextureClient::dispatchSetBuffersTimestamp(va_list args) { |
| 263 | int64_t timestamp = va_arg(args, int64_t); |
| 264 | return setBuffersTimestamp(timestamp); |
| 265 | } |
| 266 | |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 267 | int SurfaceTextureClient::connect(int api) { |
Jamie Gennis | e5366c5 | 2011-01-12 20:22:41 -0800 | [diff] [blame] | 268 | LOGV("SurfaceTextureClient::connect"); |
Mathias Agopian | 7a042bf | 2011-04-11 21:19:55 -0700 | [diff] [blame^] | 269 | Mutex::Autolock lock(mMutex); |
| 270 | int err = NO_ERROR; |
| 271 | switch (api) { |
| 272 | case NATIVE_WINDOW_API_EGL: |
| 273 | if (mConnectedApi) { |
| 274 | err = -EINVAL; |
| 275 | } else { |
| 276 | mConnectedApi = api; |
| 277 | } |
| 278 | break; |
| 279 | default: |
| 280 | err = -EINVAL; |
| 281 | break; |
| 282 | } |
| 283 | return err; |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 284 | } |
| 285 | |
| 286 | int SurfaceTextureClient::disconnect(int api) { |
Jamie Gennis | e5366c5 | 2011-01-12 20:22:41 -0800 | [diff] [blame] | 287 | LOGV("SurfaceTextureClient::disconnect"); |
Mathias Agopian | 7a042bf | 2011-04-11 21:19:55 -0700 | [diff] [blame^] | 288 | Mutex::Autolock lock(mMutex); |
| 289 | int err = NO_ERROR; |
| 290 | switch (api) { |
| 291 | case NATIVE_WINDOW_API_EGL: |
| 292 | if (mConnectedApi == api) { |
| 293 | mConnectedApi = 0; |
| 294 | } else { |
| 295 | err = -EINVAL; |
| 296 | } |
| 297 | break; |
| 298 | default: |
| 299 | err = -EINVAL; |
| 300 | break; |
| 301 | } |
| 302 | return err; |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 303 | } |
| 304 | |
Mathias Agopian | 7a042bf | 2011-04-11 21:19:55 -0700 | [diff] [blame^] | 305 | int SurfaceTextureClient::getConnectedApi() const |
| 306 | { |
| 307 | Mutex::Autolock lock(mMutex); |
| 308 | return mConnectedApi; |
| 309 | } |
| 310 | |
| 311 | |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 312 | int SurfaceTextureClient::setUsage(uint32_t reqUsage) |
| 313 | { |
Jamie Gennis | e5366c5 | 2011-01-12 20:22:41 -0800 | [diff] [blame] | 314 | LOGV("SurfaceTextureClient::setUsage"); |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 315 | Mutex::Autolock lock(mMutex); |
| 316 | mReqUsage = reqUsage; |
| 317 | return OK; |
| 318 | } |
| 319 | |
| 320 | int SurfaceTextureClient::setCrop(Rect const* rect) |
| 321 | { |
Jamie Gennis | e5366c5 | 2011-01-12 20:22:41 -0800 | [diff] [blame] | 322 | LOGV("SurfaceTextureClient::setCrop"); |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 323 | Mutex::Autolock lock(mMutex); |
| 324 | |
Jamie Gennis | 68f9127 | 2011-01-28 18:21:54 -0800 | [diff] [blame] | 325 | Rect realRect; |
| 326 | if (rect == NULL || rect->isEmpty()) { |
| 327 | realRect = Rect(0, 0); |
| 328 | } else { |
| 329 | realRect = *rect; |
| 330 | } |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 331 | |
| 332 | status_t err = mSurfaceTexture->setCrop(*rect); |
Jamie Gennis | 68f9127 | 2011-01-28 18:21:54 -0800 | [diff] [blame] | 333 | LOGE_IF(err, "ISurfaceTexture::setCrop(...) returned %s", strerror(-err)); |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 334 | |
| 335 | return err; |
| 336 | } |
| 337 | |
| 338 | int SurfaceTextureClient::setBufferCount(int bufferCount) |
| 339 | { |
Jamie Gennis | e5366c5 | 2011-01-12 20:22:41 -0800 | [diff] [blame] | 340 | LOGV("SurfaceTextureClient::setBufferCount"); |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 341 | Mutex::Autolock lock(mMutex); |
| 342 | |
| 343 | status_t err = mSurfaceTexture->setBufferCount(bufferCount); |
| 344 | LOGE_IF(err, "ISurfaceTexture::setBufferCount(%d) returned %s", |
| 345 | bufferCount, strerror(-err)); |
| 346 | |
| 347 | if (err == NO_ERROR) { |
| 348 | freeAllBuffers(); |
| 349 | } |
| 350 | |
| 351 | return err; |
| 352 | } |
| 353 | |
| 354 | int SurfaceTextureClient::setBuffersGeometry(int w, int h, int format) |
| 355 | { |
Jamie Gennis | e5366c5 | 2011-01-12 20:22:41 -0800 | [diff] [blame] | 356 | LOGV("SurfaceTextureClient::setBuffersGeometry"); |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 357 | Mutex::Autolock lock(mMutex); |
| 358 | |
| 359 | if (w<0 || h<0 || format<0) |
| 360 | return BAD_VALUE; |
| 361 | |
| 362 | if ((w && !h) || (!w && h)) |
| 363 | return BAD_VALUE; |
| 364 | |
| 365 | mReqWidth = w; |
| 366 | mReqHeight = h; |
| 367 | mReqFormat = format; |
| 368 | |
Jamie Gennis | 68f9127 | 2011-01-28 18:21:54 -0800 | [diff] [blame] | 369 | status_t err = mSurfaceTexture->setCrop(Rect(0, 0)); |
| 370 | LOGE_IF(err, "ISurfaceTexture::setCrop(...) returned %s", strerror(-err)); |
| 371 | |
| 372 | return err; |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 373 | } |
| 374 | |
| 375 | int SurfaceTextureClient::setBuffersTransform(int transform) |
| 376 | { |
Jamie Gennis | e5366c5 | 2011-01-12 20:22:41 -0800 | [diff] [blame] | 377 | LOGV("SurfaceTextureClient::setBuffersTransform"); |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 378 | Mutex::Autolock lock(mMutex); |
| 379 | status_t err = mSurfaceTexture->setTransform(transform); |
| 380 | return err; |
| 381 | } |
| 382 | |
Eino-Ville Talvala | 1d01a12 | 2011-02-18 11:02:42 -0800 | [diff] [blame] | 383 | int SurfaceTextureClient::setBuffersTimestamp(int64_t timestamp) |
| 384 | { |
| 385 | LOGV("SurfaceTextureClient::setBuffersTimestamp"); |
| 386 | Mutex::Autolock lock(mMutex); |
| 387 | mTimestamp = timestamp; |
| 388 | return NO_ERROR; |
| 389 | } |
| 390 | |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 391 | void SurfaceTextureClient::freeAllBuffers() { |
| 392 | for (int i = 0; i < NUM_BUFFER_SLOTS; i++) { |
| 393 | mSlots[i] = 0; |
| 394 | } |
| 395 | } |
| 396 | |
| 397 | }; // namespace android |