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 | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 162 | Mutex::Autolock lock(mMutex); |
Jamie Gennis | 9d4d6c1 | 2011-02-27 14:10:20 -0800 | [diff] [blame] | 163 | switch (what) { |
| 164 | case NATIVE_WINDOW_WIDTH: |
Mathias Agopian | 7a042bf | 2011-04-11 21:19:55 -0700 | [diff] [blame] | 165 | *value = mQueryWidth ? mQueryWidth : mReqWidth; |
| 166 | return NO_ERROR; |
Jamie Gennis | 9d4d6c1 | 2011-02-27 14:10:20 -0800 | [diff] [blame] | 167 | case NATIVE_WINDOW_HEIGHT: |
Mathias Agopian | 7a042bf | 2011-04-11 21:19:55 -0700 | [diff] [blame] | 168 | *value = mQueryHeight ? mQueryHeight : mReqHeight; |
Jamie Gennis | 9d4d6c1 | 2011-02-27 14:10:20 -0800 | [diff] [blame] | 169 | return NO_ERROR; |
| 170 | case NATIVE_WINDOW_FORMAT: |
Mathias Agopian | 7a042bf | 2011-04-11 21:19:55 -0700 | [diff] [blame] | 171 | *value = mQueryFormat ? mQueryFormat : mReqFormat; |
Jamie Gennis | 9d4d6c1 | 2011-02-27 14:10:20 -0800 | [diff] [blame] | 172 | return NO_ERROR; |
| 173 | case NATIVE_WINDOW_MIN_UNDEQUEUED_BUFFERS: |
| 174 | *value = MIN_UNDEQUEUED_BUFFERS; |
| 175 | return NO_ERROR; |
Jamie Gennis | 134f042 | 2011-03-08 12:18:54 -0800 | [diff] [blame] | 176 | case NATIVE_WINDOW_QUEUES_TO_WINDOW_COMPOSER: |
| 177 | // SurfaceTextureClient currently never queues frames to SurfaceFlinger. |
| 178 | *value = 0; |
| 179 | return NO_ERROR; |
Jamie Gennis | 391bbe2 | 2011-03-14 15:00:06 -0700 | [diff] [blame] | 180 | case NATIVE_WINDOW_CONCRETE_TYPE: |
| 181 | *value = NATIVE_WINDOW_SURFACE_TEXTURE_CLIENT; |
| 182 | return NO_ERROR; |
Jamie Gennis | 9d4d6c1 | 2011-02-27 14:10:20 -0800 | [diff] [blame] | 183 | } |
| 184 | return BAD_VALUE; |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 185 | } |
| 186 | |
| 187 | int SurfaceTextureClient::perform(int operation, va_list args) |
| 188 | { |
| 189 | int res = NO_ERROR; |
| 190 | switch (operation) { |
| 191 | case NATIVE_WINDOW_CONNECT: |
| 192 | res = dispatchConnect(args); |
| 193 | break; |
| 194 | case NATIVE_WINDOW_DISCONNECT: |
| 195 | res = dispatchDisconnect(args); |
| 196 | break; |
| 197 | case NATIVE_WINDOW_SET_USAGE: |
| 198 | res = dispatchSetUsage(args); |
| 199 | break; |
| 200 | case NATIVE_WINDOW_SET_CROP: |
| 201 | res = dispatchSetCrop(args); |
| 202 | break; |
| 203 | case NATIVE_WINDOW_SET_BUFFER_COUNT: |
| 204 | res = dispatchSetBufferCount(args); |
| 205 | break; |
| 206 | case NATIVE_WINDOW_SET_BUFFERS_GEOMETRY: |
| 207 | res = dispatchSetBuffersGeometry(args); |
| 208 | break; |
| 209 | case NATIVE_WINDOW_SET_BUFFERS_TRANSFORM: |
| 210 | res = dispatchSetBuffersTransform(args); |
| 211 | break; |
Eino-Ville Talvala | 1d01a12 | 2011-02-18 11:02:42 -0800 | [diff] [blame] | 212 | case NATIVE_WINDOW_SET_BUFFERS_TIMESTAMP: |
| 213 | res = dispatchSetBuffersTimestamp(args); |
| 214 | break; |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 215 | default: |
| 216 | res = NAME_NOT_FOUND; |
| 217 | break; |
| 218 | } |
| 219 | return res; |
| 220 | } |
| 221 | |
| 222 | int SurfaceTextureClient::dispatchConnect(va_list args) { |
| 223 | int api = va_arg(args, int); |
| 224 | return connect(api); |
| 225 | } |
| 226 | |
| 227 | int SurfaceTextureClient::dispatchDisconnect(va_list args) { |
| 228 | int api = va_arg(args, int); |
| 229 | return disconnect(api); |
| 230 | } |
| 231 | |
| 232 | int SurfaceTextureClient::dispatchSetUsage(va_list args) { |
| 233 | int usage = va_arg(args, int); |
| 234 | return setUsage(usage); |
| 235 | } |
| 236 | |
| 237 | int SurfaceTextureClient::dispatchSetCrop(va_list args) { |
| 238 | android_native_rect_t const* rect = va_arg(args, android_native_rect_t*); |
| 239 | return setCrop(reinterpret_cast<Rect const*>(rect)); |
| 240 | } |
| 241 | |
| 242 | int SurfaceTextureClient::dispatchSetBufferCount(va_list args) { |
| 243 | size_t bufferCount = va_arg(args, size_t); |
| 244 | return setBufferCount(bufferCount); |
| 245 | } |
| 246 | |
| 247 | int SurfaceTextureClient::dispatchSetBuffersGeometry(va_list args) { |
| 248 | int w = va_arg(args, int); |
| 249 | int h = va_arg(args, int); |
| 250 | int f = va_arg(args, int); |
| 251 | return setBuffersGeometry(w, h, f); |
| 252 | } |
| 253 | |
| 254 | int SurfaceTextureClient::dispatchSetBuffersTransform(va_list args) { |
| 255 | int transform = va_arg(args, int); |
| 256 | return setBuffersTransform(transform); |
| 257 | } |
| 258 | |
Eino-Ville Talvala | 1d01a12 | 2011-02-18 11:02:42 -0800 | [diff] [blame] | 259 | int SurfaceTextureClient::dispatchSetBuffersTimestamp(va_list args) { |
| 260 | int64_t timestamp = va_arg(args, int64_t); |
| 261 | return setBuffersTimestamp(timestamp); |
| 262 | } |
| 263 | |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 264 | int SurfaceTextureClient::connect(int api) { |
Jamie Gennis | e5366c5 | 2011-01-12 20:22:41 -0800 | [diff] [blame] | 265 | LOGV("SurfaceTextureClient::connect"); |
Mathias Agopian | 7a042bf | 2011-04-11 21:19:55 -0700 | [diff] [blame] | 266 | Mutex::Autolock lock(mMutex); |
| 267 | int err = NO_ERROR; |
| 268 | switch (api) { |
| 269 | case NATIVE_WINDOW_API_EGL: |
| 270 | if (mConnectedApi) { |
| 271 | err = -EINVAL; |
| 272 | } else { |
| 273 | mConnectedApi = api; |
| 274 | } |
| 275 | break; |
| 276 | default: |
| 277 | err = -EINVAL; |
| 278 | break; |
| 279 | } |
| 280 | return err; |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 281 | } |
| 282 | |
| 283 | int SurfaceTextureClient::disconnect(int api) { |
Jamie Gennis | e5366c5 | 2011-01-12 20:22:41 -0800 | [diff] [blame] | 284 | LOGV("SurfaceTextureClient::disconnect"); |
Mathias Agopian | 7a042bf | 2011-04-11 21:19:55 -0700 | [diff] [blame] | 285 | Mutex::Autolock lock(mMutex); |
| 286 | int err = NO_ERROR; |
| 287 | switch (api) { |
| 288 | case NATIVE_WINDOW_API_EGL: |
| 289 | if (mConnectedApi == api) { |
| 290 | mConnectedApi = 0; |
| 291 | } else { |
| 292 | err = -EINVAL; |
| 293 | } |
| 294 | break; |
| 295 | default: |
| 296 | err = -EINVAL; |
| 297 | break; |
| 298 | } |
| 299 | return err; |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 300 | } |
| 301 | |
Mathias Agopian | 7a042bf | 2011-04-11 21:19:55 -0700 | [diff] [blame] | 302 | int SurfaceTextureClient::getConnectedApi() const |
| 303 | { |
| 304 | Mutex::Autolock lock(mMutex); |
| 305 | return mConnectedApi; |
| 306 | } |
| 307 | |
| 308 | |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 309 | int SurfaceTextureClient::setUsage(uint32_t reqUsage) |
| 310 | { |
Jamie Gennis | e5366c5 | 2011-01-12 20:22:41 -0800 | [diff] [blame] | 311 | LOGV("SurfaceTextureClient::setUsage"); |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 312 | Mutex::Autolock lock(mMutex); |
| 313 | mReqUsage = reqUsage; |
| 314 | return OK; |
| 315 | } |
| 316 | |
| 317 | int SurfaceTextureClient::setCrop(Rect const* rect) |
| 318 | { |
Jamie Gennis | e5366c5 | 2011-01-12 20:22:41 -0800 | [diff] [blame] | 319 | LOGV("SurfaceTextureClient::setCrop"); |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 320 | Mutex::Autolock lock(mMutex); |
| 321 | |
Jamie Gennis | 68f9127 | 2011-01-28 18:21:54 -0800 | [diff] [blame] | 322 | Rect realRect; |
| 323 | if (rect == NULL || rect->isEmpty()) { |
| 324 | realRect = Rect(0, 0); |
| 325 | } else { |
| 326 | realRect = *rect; |
| 327 | } |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 328 | |
| 329 | status_t err = mSurfaceTexture->setCrop(*rect); |
Jamie Gennis | 68f9127 | 2011-01-28 18:21:54 -0800 | [diff] [blame] | 330 | LOGE_IF(err, "ISurfaceTexture::setCrop(...) returned %s", strerror(-err)); |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 331 | |
| 332 | return err; |
| 333 | } |
| 334 | |
| 335 | int SurfaceTextureClient::setBufferCount(int bufferCount) |
| 336 | { |
Jamie Gennis | e5366c5 | 2011-01-12 20:22:41 -0800 | [diff] [blame] | 337 | LOGV("SurfaceTextureClient::setBufferCount"); |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 338 | Mutex::Autolock lock(mMutex); |
| 339 | |
| 340 | status_t err = mSurfaceTexture->setBufferCount(bufferCount); |
| 341 | LOGE_IF(err, "ISurfaceTexture::setBufferCount(%d) returned %s", |
| 342 | bufferCount, strerror(-err)); |
| 343 | |
| 344 | if (err == NO_ERROR) { |
| 345 | freeAllBuffers(); |
| 346 | } |
| 347 | |
| 348 | return err; |
| 349 | } |
| 350 | |
| 351 | int SurfaceTextureClient::setBuffersGeometry(int w, int h, int format) |
| 352 | { |
Jamie Gennis | e5366c5 | 2011-01-12 20:22:41 -0800 | [diff] [blame] | 353 | LOGV("SurfaceTextureClient::setBuffersGeometry"); |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 354 | Mutex::Autolock lock(mMutex); |
| 355 | |
| 356 | if (w<0 || h<0 || format<0) |
| 357 | return BAD_VALUE; |
| 358 | |
| 359 | if ((w && !h) || (!w && h)) |
| 360 | return BAD_VALUE; |
| 361 | |
| 362 | mReqWidth = w; |
| 363 | mReqHeight = h; |
| 364 | mReqFormat = format; |
| 365 | |
Jamie Gennis | 68f9127 | 2011-01-28 18:21:54 -0800 | [diff] [blame] | 366 | status_t err = mSurfaceTexture->setCrop(Rect(0, 0)); |
| 367 | LOGE_IF(err, "ISurfaceTexture::setCrop(...) returned %s", strerror(-err)); |
| 368 | |
| 369 | return err; |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 370 | } |
| 371 | |
| 372 | int SurfaceTextureClient::setBuffersTransform(int transform) |
| 373 | { |
Jamie Gennis | e5366c5 | 2011-01-12 20:22:41 -0800 | [diff] [blame] | 374 | LOGV("SurfaceTextureClient::setBuffersTransform"); |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 375 | Mutex::Autolock lock(mMutex); |
| 376 | status_t err = mSurfaceTexture->setTransform(transform); |
| 377 | return err; |
| 378 | } |
| 379 | |
Eino-Ville Talvala | 1d01a12 | 2011-02-18 11:02:42 -0800 | [diff] [blame] | 380 | int SurfaceTextureClient::setBuffersTimestamp(int64_t timestamp) |
| 381 | { |
| 382 | LOGV("SurfaceTextureClient::setBuffersTimestamp"); |
| 383 | Mutex::Autolock lock(mMutex); |
| 384 | mTimestamp = timestamp; |
| 385 | return NO_ERROR; |
| 386 | } |
| 387 | |
Jamie Gennis | 8ba32fa | 2010-12-20 11:27:26 -0800 | [diff] [blame] | 388 | void SurfaceTextureClient::freeAllBuffers() { |
| 389 | for (int i = 0; i < NUM_BUFFER_SLOTS; i++) { |
| 390 | mSlots[i] = 0; |
| 391 | } |
| 392 | } |
| 393 | |
| 394 | }; // namespace android |