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