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