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