blob: c015b812f018b253bda4d56340798c49eb66446f [file] [log] [blame]
Jamie Gennis8ba32fa2010-12-20 11:27:26 -08001/*
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 Gennis1c8e95c2012-02-23 19:27:23 -080018#define ATRACE_TAG ATRACE_TAG_GRAPHICS
Jamie Gennise5366c52011-01-12 20:22:41 -080019//#define LOG_NDEBUG 0
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080020
Mathias Agopianb0e76f42012-03-23 14:15:44 -070021#include <android/native_window.h>
22
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080023#include <utils/Log.h>
Jamie Gennis1c8e95c2012-02-23 19:27:23 -080024#include <utils/Trace.h>
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080025
Jamie Gennisd8e812c2012-06-13 16:32:25 -070026#include <ui/Fence.h>
27
Mathias Agopian90ac7992012-02-25 18:48:35 -080028#include <gui/ISurfaceComposer.h>
29#include <gui/SurfaceComposerClient.h>
Andy McFadden2adaf042012-12-18 09:49:45 -080030#include <gui/GLConsumer.h>
Mathias Agopian90ac7992012-02-25 18:48:35 -080031#include <gui/SurfaceTextureClient.h>
32
Mathias Agopian41f673c2011-11-17 17:48:35 -080033#include <private/gui/ComposerService.h>
34
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080035namespace android {
36
37SurfaceTextureClient::SurfaceTextureClient(
Andy McFadden2adaf042012-12-18 09:49:45 -080038 const sp<IGraphicBufferProducer>& bufferProducer)
Mathias Agopian8f9dbf92011-07-13 17:39:11 -070039{
40 SurfaceTextureClient::init();
Andy McFadden2adaf042012-12-18 09:49:45 -080041 SurfaceTextureClient::setISurfaceTexture(bufferProducer);
Mathias Agopian8f9dbf92011-07-13 17:39:11 -070042}
43
44SurfaceTextureClient::SurfaceTextureClient() {
45 SurfaceTextureClient::init();
46}
47
Mathias Agopiana36bcd52011-11-17 18:46:09 -080048SurfaceTextureClient::~SurfaceTextureClient() {
49 if (mConnectedToCpu) {
50 SurfaceTextureClient::disconnect(NATIVE_WINDOW_API_CPU);
51 }
52}
53
Mathias Agopian8f9dbf92011-07-13 17:39:11 -070054void SurfaceTextureClient::init() {
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080055 // Initialize the ANativeWindow function pointers.
Mathias Agopian8f9dbf92011-07-13 17:39:11 -070056 ANativeWindow::setSwapInterval = hook_setSwapInterval;
57 ANativeWindow::dequeueBuffer = hook_dequeueBuffer;
58 ANativeWindow::cancelBuffer = hook_cancelBuffer;
Mathias Agopian8f9dbf92011-07-13 17:39:11 -070059 ANativeWindow::queueBuffer = hook_queueBuffer;
60 ANativeWindow::query = hook_query;
61 ANativeWindow::perform = hook_perform;
Jamie Gennis1b20cde2011-02-02 15:31:47 -080062
Jamie Gennisd8e812c2012-06-13 16:32:25 -070063 ANativeWindow::dequeueBuffer_DEPRECATED = hook_dequeueBuffer_DEPRECATED;
64 ANativeWindow::cancelBuffer_DEPRECATED = hook_cancelBuffer_DEPRECATED;
65 ANativeWindow::lockBuffer_DEPRECATED = hook_lockBuffer_DEPRECATED;
66 ANativeWindow::queueBuffer_DEPRECATED = hook_queueBuffer_DEPRECATED;
67
Mathias Agopian80727112011-05-02 19:51:12 -070068 const_cast<int&>(ANativeWindow::minSwapInterval) = 0;
69 const_cast<int&>(ANativeWindow::maxSwapInterval) = 1;
70
Mathias Agopian8f9dbf92011-07-13 17:39:11 -070071 mReqWidth = 0;
72 mReqHeight = 0;
73 mReqFormat = 0;
74 mReqUsage = 0;
75 mTimestamp = NATIVE_WINDOW_TIMESTAMP_AUTO;
Mathias Agopian851ef8f2012-03-29 17:10:08 -070076 mCrop.clear();
77 mScalingMode = NATIVE_WINDOW_SCALING_MODE_FREEZE;
78 mTransform = 0;
Mathias Agopianbb66c9b2011-07-21 14:50:29 -070079 mDefaultWidth = 0;
80 mDefaultHeight = 0;
Michael I. Gold55a70142012-04-09 19:46:29 -070081 mUserWidth = 0;
82 mUserHeight = 0;
Mathias Agopianbb66c9b2011-07-21 14:50:29 -070083 mTransformHint = 0;
Mathias Agopian2488b202012-04-20 17:19:28 -070084 mConsumerRunningBehind = false;
Mathias Agopian8f9dbf92011-07-13 17:39:11 -070085 mConnectedToCpu = false;
86}
87
88void SurfaceTextureClient::setISurfaceTexture(
Andy McFadden2adaf042012-12-18 09:49:45 -080089 const sp<IGraphicBufferProducer>& bufferProducer)
Mathias Agopian8f9dbf92011-07-13 17:39:11 -070090{
Andy McFadden2adaf042012-12-18 09:49:45 -080091 mSurfaceTexture = bufferProducer;
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080092}
93
Andy McFadden2adaf042012-12-18 09:49:45 -080094sp<IGraphicBufferProducer> SurfaceTextureClient::getISurfaceTexture() const {
Jamie Gennisbae774e2011-03-14 15:08:53 -070095 return mSurfaceTexture;
96}
97
Mathias Agopian8f9dbf92011-07-13 17:39:11 -070098int SurfaceTextureClient::hook_setSwapInterval(ANativeWindow* window, int interval) {
Jamie Gennis8ba32fa2010-12-20 11:27:26 -080099 SurfaceTextureClient* c = getSelf(window);
100 return c->setSwapInterval(interval);
101}
102
Mathias Agopian8f9dbf92011-07-13 17:39:11 -0700103int SurfaceTextureClient::hook_dequeueBuffer(ANativeWindow* window,
Jamie Gennisd8e812c2012-06-13 16:32:25 -0700104 ANativeWindowBuffer** buffer, int* fenceFd) {
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800105 SurfaceTextureClient* c = getSelf(window);
Jamie Gennisd8e812c2012-06-13 16:32:25 -0700106 return c->dequeueBuffer(buffer, fenceFd);
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800107}
108
Mathias Agopian8f9dbf92011-07-13 17:39:11 -0700109int SurfaceTextureClient::hook_cancelBuffer(ANativeWindow* window,
Jamie Gennisd8e812c2012-06-13 16:32:25 -0700110 ANativeWindowBuffer* buffer, int fenceFd) {
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800111 SurfaceTextureClient* c = getSelf(window);
Jamie Gennisd8e812c2012-06-13 16:32:25 -0700112 return c->cancelBuffer(buffer, fenceFd);
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800113}
114
Mathias Agopian8f9dbf92011-07-13 17:39:11 -0700115int SurfaceTextureClient::hook_queueBuffer(ANativeWindow* window,
Jamie Gennisd8e812c2012-06-13 16:32:25 -0700116 ANativeWindowBuffer* buffer, int fenceFd) {
117 SurfaceTextureClient* c = getSelf(window);
118 return c->queueBuffer(buffer, fenceFd);
119}
120
121int SurfaceTextureClient::hook_dequeueBuffer_DEPRECATED(ANativeWindow* window,
122 ANativeWindowBuffer** buffer) {
123 SurfaceTextureClient* c = getSelf(window);
Jesse Hallba607d52012-10-01 14:05:20 -0700124 ANativeWindowBuffer* buf;
Jamie Gennisd8e812c2012-06-13 16:32:25 -0700125 int fenceFd = -1;
Jesse Hallba607d52012-10-01 14:05:20 -0700126 int result = c->dequeueBuffer(&buf, &fenceFd);
Jamie Gennisd8e812c2012-06-13 16:32:25 -0700127 sp<Fence> fence(new Fence(fenceFd));
Jesse Hallba607d52012-10-01 14:05:20 -0700128 int waitResult = fence->waitForever(1000, "dequeueBuffer_DEPRECATED");
Jamie Gennisd8e812c2012-06-13 16:32:25 -0700129 if (waitResult != OK) {
Jesse Hallba607d52012-10-01 14:05:20 -0700130 ALOGE("dequeueBuffer_DEPRECATED: Fence::wait returned an error: %d",
131 waitResult);
132 c->cancelBuffer(buf, -1);
Jamie Gennisd8e812c2012-06-13 16:32:25 -0700133 return waitResult;
134 }
Jesse Hallba607d52012-10-01 14:05:20 -0700135 *buffer = buf;
Jamie Gennisd8e812c2012-06-13 16:32:25 -0700136 return result;
137}
138
139int SurfaceTextureClient::hook_cancelBuffer_DEPRECATED(ANativeWindow* window,
Iliyan Malchev697526b2011-05-01 11:33:26 -0700140 ANativeWindowBuffer* buffer) {
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800141 SurfaceTextureClient* c = getSelf(window);
Jamie Gennisd8e812c2012-06-13 16:32:25 -0700142 return c->cancelBuffer(buffer, -1);
143}
144
145int SurfaceTextureClient::hook_lockBuffer_DEPRECATED(ANativeWindow* window,
146 ANativeWindowBuffer* buffer) {
147 SurfaceTextureClient* c = getSelf(window);
148 return c->lockBuffer_DEPRECATED(buffer);
149}
150
151int SurfaceTextureClient::hook_queueBuffer_DEPRECATED(ANativeWindow* window,
152 ANativeWindowBuffer* buffer) {
153 SurfaceTextureClient* c = getSelf(window);
154 return c->queueBuffer(buffer, -1);
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800155}
156
Mathias Agopian8f9dbf92011-07-13 17:39:11 -0700157int SurfaceTextureClient::hook_query(const ANativeWindow* window,
Iliyan Malchev41abd672011-04-14 16:54:38 -0700158 int what, int* value) {
159 const SurfaceTextureClient* c = getSelf(window);
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800160 return c->query(what, value);
161}
162
Mathias Agopian8f9dbf92011-07-13 17:39:11 -0700163int SurfaceTextureClient::hook_perform(ANativeWindow* window, int operation, ...) {
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800164 va_list args;
165 va_start(args, operation);
166 SurfaceTextureClient* c = getSelf(window);
167 return c->perform(operation, args);
168}
169
170int SurfaceTextureClient::setSwapInterval(int interval) {
Jamie Gennis1c8e95c2012-02-23 19:27:23 -0800171 ATRACE_CALL();
Mathias Agopian80727112011-05-02 19:51:12 -0700172 // EGL specification states:
173 // interval is silently clamped to minimum and maximum implementation
174 // dependent values before being stored.
175 // Although we don't have to, we apply the same logic here.
176
177 if (interval < minSwapInterval)
178 interval = minSwapInterval;
179
180 if (interval > maxSwapInterval)
181 interval = maxSwapInterval;
182
183 status_t res = mSurfaceTexture->setSynchronousMode(interval ? true : false);
184
185 return res;
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800186}
187
Jamie Gennisd8e812c2012-06-13 16:32:25 -0700188int SurfaceTextureClient::dequeueBuffer(android_native_buffer_t** buffer,
189 int* fenceFd) {
Jamie Gennis1c8e95c2012-02-23 19:27:23 -0800190 ATRACE_CALL();
Steve Block6807e592011-10-20 11:56:00 +0100191 ALOGV("SurfaceTextureClient::dequeueBuffer");
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800192 Mutex::Autolock lock(mMutex);
193 int buf = -1;
Michael I. Gold55a70142012-04-09 19:46:29 -0700194 int reqW = mReqWidth ? mReqWidth : mUserWidth;
195 int reqH = mReqHeight ? mReqHeight : mUserHeight;
Jesse Hallf7857542012-06-14 15:26:33 -0700196 sp<Fence> fence;
197 status_t result = mSurfaceTexture->dequeueBuffer(&buf, fence, reqW, reqH,
Mathias Agopianc04f1532011-04-25 20:22:14 -0700198 mReqFormat, mReqUsage);
Mathias Agopian80727112011-05-02 19:51:12 -0700199 if (result < 0) {
Andy McFadden2adaf042012-12-18 09:49:45 -0800200 ALOGV("dequeueBuffer: IGraphicBufferProducer::dequeueBuffer(%d, %d, %d, %d)"
Jamie Gennis8cd5ba42011-05-19 13:33:00 -0700201 "failed: %d", mReqWidth, mReqHeight, mReqFormat, mReqUsage,
202 result);
Mathias Agopian80727112011-05-02 19:51:12 -0700203 return result;
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800204 }
Mathias Agopianac6035a2012-04-12 16:32:37 -0700205 sp<GraphicBuffer>& gbuf(mSlots[buf].buffer);
Andy McFadden2adaf042012-12-18 09:49:45 -0800206 if (result & IGraphicBufferProducer::RELEASE_ALL_BUFFERS) {
Mathias Agopian80727112011-05-02 19:51:12 -0700207 freeAllBuffers();
208 }
209
Andy McFadden2adaf042012-12-18 09:49:45 -0800210 if ((result & IGraphicBufferProducer::BUFFER_NEEDS_REALLOCATION) || gbuf == 0) {
Jamie Gennis7b305ff2011-07-19 12:08:33 -0700211 result = mSurfaceTexture->requestBuffer(buf, &gbuf);
212 if (result != NO_ERROR) {
Andy McFadden2adaf042012-12-18 09:49:45 -0800213 ALOGE("dequeueBuffer: IGraphicBufferProducer::requestBuffer failed: %d",
Jamie Gennis7b305ff2011-07-19 12:08:33 -0700214 result);
215 return result;
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800216 }
217 }
Jesse Hallf7857542012-06-14 15:26:33 -0700218
219 if (fence.get()) {
Jesse Hallf9783af2012-06-25 13:54:23 -0700220 *fenceFd = fence->dup();
221 if (*fenceFd == -1) {
222 ALOGE("dequeueBuffer: error duping fence: %d", errno);
223 // dup() should never fail; something is badly wrong. Soldier on
224 // and hope for the best; the worst that should happen is some
225 // visible corruption that lasts until the next frame.
Jesse Hallf7857542012-06-14 15:26:33 -0700226 }
Jesse Hallf9783af2012-06-25 13:54:23 -0700227 } else {
228 *fenceFd = -1;
Jesse Hallf7857542012-06-14 15:26:33 -0700229 }
230
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800231 *buffer = gbuf.get();
232 return OK;
233}
234
Jesse Hallc777b0b2012-06-28 12:52:05 -0700235int SurfaceTextureClient::cancelBuffer(android_native_buffer_t* buffer,
236 int fenceFd) {
Jamie Gennis1c8e95c2012-02-23 19:27:23 -0800237 ATRACE_CALL();
Steve Block6807e592011-10-20 11:56:00 +0100238 ALOGV("SurfaceTextureClient::cancelBuffer");
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800239 Mutex::Autolock lock(mMutex);
Jamie Gennis1c441402011-06-20 12:04:09 -0700240 int i = getSlotFromBufferLocked(buffer);
241 if (i < 0) {
242 return i;
243 }
Jesse Hallc777b0b2012-06-28 12:52:05 -0700244 sp<Fence> fence(fenceFd >= 0 ? new Fence(fenceFd) : NULL);
245 mSurfaceTexture->cancelBuffer(i, fence);
Jamie Gennis1c441402011-06-20 12:04:09 -0700246 return OK;
247}
248
249int SurfaceTextureClient::getSlotFromBufferLocked(
250 android_native_buffer_t* buffer) const {
251 bool dumpedState = false;
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800252 for (int i = 0; i < NUM_BUFFER_SLOTS; i++) {
Mathias Agopianac6035a2012-04-12 16:32:37 -0700253 if (mSlots[i].buffer != NULL &&
254 mSlots[i].buffer->handle == buffer->handle) {
Jamie Gennis1c441402011-06-20 12:04:09 -0700255 return i;
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800256 }
257 }
Steve Blocke6f43dd2012-01-06 19:20:56 +0000258 ALOGE("getSlotFromBufferLocked: unknown buffer: %p", buffer->handle);
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800259 return BAD_VALUE;
260}
261
Jamie Gennisd8e812c2012-06-13 16:32:25 -0700262int SurfaceTextureClient::lockBuffer_DEPRECATED(android_native_buffer_t* buffer) {
Steve Block6807e592011-10-20 11:56:00 +0100263 ALOGV("SurfaceTextureClient::lockBuffer");
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800264 Mutex::Autolock lock(mMutex);
265 return OK;
266}
267
Jamie Gennisd8e812c2012-06-13 16:32:25 -0700268int SurfaceTextureClient::queueBuffer(android_native_buffer_t* buffer, int fenceFd) {
Jamie Gennis1c8e95c2012-02-23 19:27:23 -0800269 ATRACE_CALL();
Steve Block6807e592011-10-20 11:56:00 +0100270 ALOGV("SurfaceTextureClient::queueBuffer");
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800271 Mutex::Autolock lock(mMutex);
Eino-Ville Talvala1d01a122011-02-18 11:02:42 -0800272 int64_t timestamp;
273 if (mTimestamp == NATIVE_WINDOW_TIMESTAMP_AUTO) {
274 timestamp = systemTime(SYSTEM_TIME_MONOTONIC);
Steve Block6807e592011-10-20 11:56:00 +0100275 ALOGV("SurfaceTextureClient::queueBuffer making up timestamp: %.2f ms",
Eino-Ville Talvala1d01a122011-02-18 11:02:42 -0800276 timestamp / 1000000.f);
277 } else {
278 timestamp = mTimestamp;
279 }
Jamie Gennis1c441402011-06-20 12:04:09 -0700280 int i = getSlotFromBufferLocked(buffer);
281 if (i < 0) {
282 return i;
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800283 }
Mathias Agopianf0bc2f12012-04-09 16:14:01 -0700284
Jamie Gennisd8e812c2012-06-13 16:32:25 -0700285
Jamie Gennisd72f2332012-05-07 13:50:11 -0700286 // Make sure the crop rectangle is entirely inside the buffer.
Jamie Gennisb7a6b962012-05-13 19:41:35 -0700287 Rect crop;
288 mCrop.intersect(Rect(buffer->width, buffer->height), &crop);
Jamie Gennisd72f2332012-05-07 13:50:11 -0700289
Jesse Hallc777b0b2012-06-28 12:52:05 -0700290 sp<Fence> fence(fenceFd >= 0 ? new Fence(fenceFd) : NULL);
Andy McFadden2adaf042012-12-18 09:49:45 -0800291 IGraphicBufferProducer::QueueBufferOutput output;
292 IGraphicBufferProducer::QueueBufferInput input(timestamp, crop, mScalingMode,
Jesse Hallc777b0b2012-06-28 12:52:05 -0700293 mTransform, fence);
294 status_t err = mSurfaceTexture->queueBuffer(i, input, &output);
Pannag Sanketi66378c62011-09-02 17:37:29 -0700295 if (err != OK) {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000296 ALOGE("queueBuffer: error queuing buffer to SurfaceTexture, %d", err);
Pannag Sanketi66378c62011-09-02 17:37:29 -0700297 }
Mathias Agopian2488b202012-04-20 17:19:28 -0700298 uint32_t numPendingBuffers = 0;
299 output.deflate(&mDefaultWidth, &mDefaultHeight, &mTransformHint,
300 &numPendingBuffers);
301
302 mConsumerRunningBehind = (numPendingBuffers >= 2);
303
Pannag Sanketi66378c62011-09-02 17:37:29 -0700304 return err;
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800305}
306
Iliyan Malchev41abd672011-04-14 16:54:38 -0700307int SurfaceTextureClient::query(int what, int* value) const {
Jamie Gennis1c8e95c2012-02-23 19:27:23 -0800308 ATRACE_CALL();
Steve Block6807e592011-10-20 11:56:00 +0100309 ALOGV("SurfaceTextureClient::query");
Mathias Agopian97c602c2011-07-19 15:24:46 -0700310 { // scope for the lock
311 Mutex::Autolock lock(mMutex);
312 switch (what) {
313 case NATIVE_WINDOW_FORMAT:
314 if (mReqFormat) {
315 *value = mReqFormat;
316 return NO_ERROR;
317 }
318 break;
Mathias Agopian2488b202012-04-20 17:19:28 -0700319 case NATIVE_WINDOW_QUEUES_TO_WINDOW_COMPOSER: {
320 sp<ISurfaceComposer> composer(
321 ComposerService::getComposerService());
322 if (composer->authenticateSurfaceTexture(mSurfaceTexture)) {
323 *value = 1;
324 } else {
325 *value = 0;
Jamie Gennis582270d2011-08-17 18:19:00 -0700326 }
Mathias Agopian97c602c2011-07-19 15:24:46 -0700327 return NO_ERROR;
Mathias Agopian2488b202012-04-20 17:19:28 -0700328 }
Mathias Agopian97c602c2011-07-19 15:24:46 -0700329 case NATIVE_WINDOW_CONCRETE_TYPE:
330 *value = NATIVE_WINDOW_SURFACE_TEXTURE_CLIENT;
331 return NO_ERROR;
332 case NATIVE_WINDOW_DEFAULT_WIDTH:
Michael I. Gold55a70142012-04-09 19:46:29 -0700333 *value = mUserWidth ? mUserWidth : mDefaultWidth;
Mathias Agopian97c602c2011-07-19 15:24:46 -0700334 return NO_ERROR;
335 case NATIVE_WINDOW_DEFAULT_HEIGHT:
Michael I. Gold55a70142012-04-09 19:46:29 -0700336 *value = mUserHeight ? mUserHeight : mDefaultHeight;
Mathias Agopian97c602c2011-07-19 15:24:46 -0700337 return NO_ERROR;
338 case NATIVE_WINDOW_TRANSFORM_HINT:
339 *value = mTransformHint;
340 return NO_ERROR;
Mathias Agopian2488b202012-04-20 17:19:28 -0700341 case NATIVE_WINDOW_CONSUMER_RUNNING_BEHIND: {
342 status_t err = NO_ERROR;
343 if (!mConsumerRunningBehind) {
344 *value = 0;
345 } else {
346 err = mSurfaceTexture->query(what, value);
347 if (err == NO_ERROR) {
348 mConsumerRunningBehind = *value;
349 }
350 }
351 return err;
352 }
Mathias Agopiana67932f2011-04-20 14:20:59 -0700353 }
Jamie Gennis9d4d6c12011-02-27 14:10:20 -0800354 }
Mathias Agopianeafabcd2011-04-20 14:20:59 -0700355 return mSurfaceTexture->query(what, value);
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800356}
357
358int SurfaceTextureClient::perform(int operation, va_list args)
359{
360 int res = NO_ERROR;
361 switch (operation) {
362 case NATIVE_WINDOW_CONNECT:
Mathias Agopian81a63352011-07-29 17:55:48 -0700363 // deprecated. must return NO_ERROR.
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800364 break;
365 case NATIVE_WINDOW_DISCONNECT:
Mathias Agopian81a63352011-07-29 17:55:48 -0700366 // deprecated. must return NO_ERROR.
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800367 break;
368 case NATIVE_WINDOW_SET_USAGE:
369 res = dispatchSetUsage(args);
370 break;
371 case NATIVE_WINDOW_SET_CROP:
372 res = dispatchSetCrop(args);
373 break;
374 case NATIVE_WINDOW_SET_BUFFER_COUNT:
375 res = dispatchSetBufferCount(args);
376 break;
377 case NATIVE_WINDOW_SET_BUFFERS_GEOMETRY:
378 res = dispatchSetBuffersGeometry(args);
379 break;
380 case NATIVE_WINDOW_SET_BUFFERS_TRANSFORM:
381 res = dispatchSetBuffersTransform(args);
382 break;
Eino-Ville Talvala1d01a122011-02-18 11:02:42 -0800383 case NATIVE_WINDOW_SET_BUFFERS_TIMESTAMP:
384 res = dispatchSetBuffersTimestamp(args);
385 break;
Jamie Gennisbee205f2011-07-01 13:12:07 -0700386 case NATIVE_WINDOW_SET_BUFFERS_DIMENSIONS:
387 res = dispatchSetBuffersDimensions(args);
388 break;
Michael I. Gold55a70142012-04-09 19:46:29 -0700389 case NATIVE_WINDOW_SET_BUFFERS_USER_DIMENSIONS:
390 res = dispatchSetBuffersUserDimensions(args);
391 break;
Jamie Gennisbee205f2011-07-01 13:12:07 -0700392 case NATIVE_WINDOW_SET_BUFFERS_FORMAT:
393 res = dispatchSetBuffersFormat(args);
394 break;
Mathias Agopian8f9dbf92011-07-13 17:39:11 -0700395 case NATIVE_WINDOW_LOCK:
396 res = dispatchLock(args);
397 break;
398 case NATIVE_WINDOW_UNLOCK_AND_POST:
399 res = dispatchUnlockAndPost(args);
400 break;
Mathias Agopian7734ebf2011-07-13 15:24:42 -0700401 case NATIVE_WINDOW_SET_SCALING_MODE:
402 res = dispatchSetScalingMode(args);
403 break;
Mathias Agopian81a63352011-07-29 17:55:48 -0700404 case NATIVE_WINDOW_API_CONNECT:
405 res = dispatchConnect(args);
406 break;
407 case NATIVE_WINDOW_API_DISCONNECT:
408 res = dispatchDisconnect(args);
409 break;
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800410 default:
411 res = NAME_NOT_FOUND;
412 break;
413 }
414 return res;
415}
416
417int SurfaceTextureClient::dispatchConnect(va_list args) {
418 int api = va_arg(args, int);
419 return connect(api);
420}
421
422int SurfaceTextureClient::dispatchDisconnect(va_list args) {
423 int api = va_arg(args, int);
424 return disconnect(api);
425}
426
427int SurfaceTextureClient::dispatchSetUsage(va_list args) {
428 int usage = va_arg(args, int);
429 return setUsage(usage);
430}
431
432int SurfaceTextureClient::dispatchSetCrop(va_list args) {
433 android_native_rect_t const* rect = va_arg(args, android_native_rect_t*);
434 return setCrop(reinterpret_cast<Rect const*>(rect));
435}
436
437int SurfaceTextureClient::dispatchSetBufferCount(va_list args) {
438 size_t bufferCount = va_arg(args, size_t);
439 return setBufferCount(bufferCount);
440}
441
442int SurfaceTextureClient::dispatchSetBuffersGeometry(va_list args) {
443 int w = va_arg(args, int);
444 int h = va_arg(args, int);
445 int f = va_arg(args, int);
Jamie Gennisbee205f2011-07-01 13:12:07 -0700446 int err = setBuffersDimensions(w, h);
447 if (err != 0) {
448 return err;
449 }
450 return setBuffersFormat(f);
451}
452
453int SurfaceTextureClient::dispatchSetBuffersDimensions(va_list args) {
454 int w = va_arg(args, int);
455 int h = va_arg(args, int);
456 return setBuffersDimensions(w, h);
457}
458
Michael I. Gold55a70142012-04-09 19:46:29 -0700459int SurfaceTextureClient::dispatchSetBuffersUserDimensions(va_list args) {
460 int w = va_arg(args, int);
461 int h = va_arg(args, int);
462 return setBuffersUserDimensions(w, h);
463}
464
Jamie Gennisbee205f2011-07-01 13:12:07 -0700465int SurfaceTextureClient::dispatchSetBuffersFormat(va_list args) {
466 int f = va_arg(args, int);
467 return setBuffersFormat(f);
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800468}
469
Mathias Agopian7734ebf2011-07-13 15:24:42 -0700470int SurfaceTextureClient::dispatchSetScalingMode(va_list args) {
471 int m = va_arg(args, int);
472 return setScalingMode(m);
473}
474
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800475int SurfaceTextureClient::dispatchSetBuffersTransform(va_list args) {
476 int transform = va_arg(args, int);
477 return setBuffersTransform(transform);
478}
479
Eino-Ville Talvala1d01a122011-02-18 11:02:42 -0800480int SurfaceTextureClient::dispatchSetBuffersTimestamp(va_list args) {
481 int64_t timestamp = va_arg(args, int64_t);
482 return setBuffersTimestamp(timestamp);
483}
484
Mathias Agopian8f9dbf92011-07-13 17:39:11 -0700485int SurfaceTextureClient::dispatchLock(va_list args) {
486 ANativeWindow_Buffer* outBuffer = va_arg(args, ANativeWindow_Buffer*);
487 ARect* inOutDirtyBounds = va_arg(args, ARect*);
488 return lock(outBuffer, inOutDirtyBounds);
489}
490
491int SurfaceTextureClient::dispatchUnlockAndPost(va_list args) {
492 return unlockAndPost();
493}
494
495
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800496int SurfaceTextureClient::connect(int api) {
Jamie Gennis1c8e95c2012-02-23 19:27:23 -0800497 ATRACE_CALL();
Steve Block6807e592011-10-20 11:56:00 +0100498 ALOGV("SurfaceTextureClient::connect");
Mathias Agopian7a042bf2011-04-11 21:19:55 -0700499 Mutex::Autolock lock(mMutex);
Andy McFadden2adaf042012-12-18 09:49:45 -0800500 IGraphicBufferProducer::QueueBufferOutput output;
Mathias Agopian24202f52012-04-23 14:28:58 -0700501 int err = mSurfaceTexture->connect(api, &output);
Mathias Agopian2488b202012-04-20 17:19:28 -0700502 if (err == NO_ERROR) {
503 uint32_t numPendingBuffers = 0;
504 output.deflate(&mDefaultWidth, &mDefaultHeight, &mTransformHint,
505 &numPendingBuffers);
506 mConsumerRunningBehind = (numPendingBuffers >= 2);
507 }
Mathias Agopian8f9dbf92011-07-13 17:39:11 -0700508 if (!err && api == NATIVE_WINDOW_API_CPU) {
509 mConnectedToCpu = true;
510 }
511 return err;
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800512}
513
514int SurfaceTextureClient::disconnect(int api) {
Jamie Gennis1c8e95c2012-02-23 19:27:23 -0800515 ATRACE_CALL();
Steve Block6807e592011-10-20 11:56:00 +0100516 ALOGV("SurfaceTextureClient::disconnect");
Mathias Agopian7a042bf2011-04-11 21:19:55 -0700517 Mutex::Autolock lock(mMutex);
Jamie Gennis13c5ca32011-10-18 17:14:33 -0700518 freeAllBuffers();
Mathias Agopian8f9dbf92011-07-13 17:39:11 -0700519 int err = mSurfaceTexture->disconnect(api);
Mathias Agopian70e3f812011-08-25 17:03:30 -0700520 if (!err) {
Mathias Agopian70e3f812011-08-25 17:03:30 -0700521 mReqFormat = 0;
522 mReqWidth = 0;
523 mReqHeight = 0;
524 mReqUsage = 0;
Mathias Agopian851ef8f2012-03-29 17:10:08 -0700525 mCrop.clear();
526 mScalingMode = NATIVE_WINDOW_SCALING_MODE_FREEZE;
527 mTransform = 0;
Mathias Agopian70e3f812011-08-25 17:03:30 -0700528 if (api == NATIVE_WINDOW_API_CPU) {
529 mConnectedToCpu = false;
530 }
Mathias Agopian8f9dbf92011-07-13 17:39:11 -0700531 }
532 return err;
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800533}
534
535int SurfaceTextureClient::setUsage(uint32_t reqUsage)
536{
Steve Block6807e592011-10-20 11:56:00 +0100537 ALOGV("SurfaceTextureClient::setUsage");
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800538 Mutex::Autolock lock(mMutex);
539 mReqUsage = reqUsage;
540 return OK;
541}
542
543int SurfaceTextureClient::setCrop(Rect const* rect)
544{
Jamie Gennis1c8e95c2012-02-23 19:27:23 -0800545 ATRACE_CALL();
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800546
Jamie Gennis68f91272011-01-28 18:21:54 -0800547 Rect realRect;
548 if (rect == NULL || rect->isEmpty()) {
Mathias Agopian851ef8f2012-03-29 17:10:08 -0700549 realRect.clear();
Jamie Gennis68f91272011-01-28 18:21:54 -0800550 } else {
551 realRect = *rect;
552 }
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800553
Jamie Genniscd1806e2012-05-10 02:22:33 -0700554 ALOGV("SurfaceTextureClient::setCrop rect=[%d %d %d %d]",
555 realRect.left, realRect.top, realRect.right, realRect.bottom);
556
Mathias Agopian851ef8f2012-03-29 17:10:08 -0700557 Mutex::Autolock lock(mMutex);
Jamie Gennisefc7ab62012-04-17 19:36:18 -0700558 mCrop = realRect;
Mathias Agopian851ef8f2012-03-29 17:10:08 -0700559 return NO_ERROR;
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800560}
561
562int SurfaceTextureClient::setBufferCount(int bufferCount)
563{
Jamie Gennis1c8e95c2012-02-23 19:27:23 -0800564 ATRACE_CALL();
Steve Block6807e592011-10-20 11:56:00 +0100565 ALOGV("SurfaceTextureClient::setBufferCount");
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800566 Mutex::Autolock lock(mMutex);
567
568 status_t err = mSurfaceTexture->setBufferCount(bufferCount);
Andy McFadden2adaf042012-12-18 09:49:45 -0800569 ALOGE_IF(err, "IGraphicBufferProducer::setBufferCount(%d) returned %s",
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800570 bufferCount, strerror(-err));
571
572 if (err == NO_ERROR) {
573 freeAllBuffers();
574 }
575
576 return err;
577}
578
Jamie Gennisbee205f2011-07-01 13:12:07 -0700579int SurfaceTextureClient::setBuffersDimensions(int w, int h)
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800580{
Jamie Gennis1c8e95c2012-02-23 19:27:23 -0800581 ATRACE_CALL();
Steve Block6807e592011-10-20 11:56:00 +0100582 ALOGV("SurfaceTextureClient::setBuffersDimensions");
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800583
Jamie Gennisbee205f2011-07-01 13:12:07 -0700584 if (w<0 || h<0)
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800585 return BAD_VALUE;
586
587 if ((w && !h) || (!w && h))
588 return BAD_VALUE;
589
Mathias Agopian851ef8f2012-03-29 17:10:08 -0700590 Mutex::Autolock lock(mMutex);
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800591 mReqWidth = w;
592 mReqHeight = h;
Mathias Agopian851ef8f2012-03-29 17:10:08 -0700593 return NO_ERROR;
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800594}
595
Michael I. Gold55a70142012-04-09 19:46:29 -0700596int SurfaceTextureClient::setBuffersUserDimensions(int w, int h)
597{
598 ATRACE_CALL();
599 ALOGV("SurfaceTextureClient::setBuffersUserDimensions");
600
601 if (w<0 || h<0)
602 return BAD_VALUE;
603
604 if ((w && !h) || (!w && h))
605 return BAD_VALUE;
606
607 Mutex::Autolock lock(mMutex);
608 mUserWidth = w;
609 mUserHeight = h;
Michael I. Gold55a70142012-04-09 19:46:29 -0700610 return NO_ERROR;
611}
612
Jamie Gennisbee205f2011-07-01 13:12:07 -0700613int SurfaceTextureClient::setBuffersFormat(int format)
614{
Steve Block6807e592011-10-20 11:56:00 +0100615 ALOGV("SurfaceTextureClient::setBuffersFormat");
Jamie Gennisbee205f2011-07-01 13:12:07 -0700616
617 if (format<0)
618 return BAD_VALUE;
619
Mathias Agopian851ef8f2012-03-29 17:10:08 -0700620 Mutex::Autolock lock(mMutex);
Jamie Gennisbee205f2011-07-01 13:12:07 -0700621 mReqFormat = format;
Jamie Gennisbee205f2011-07-01 13:12:07 -0700622 return NO_ERROR;
623}
624
Mathias Agopian7734ebf2011-07-13 15:24:42 -0700625int SurfaceTextureClient::setScalingMode(int mode)
626{
Jamie Gennis1c8e95c2012-02-23 19:27:23 -0800627 ATRACE_CALL();
Steve Block6807e592011-10-20 11:56:00 +0100628 ALOGV("SurfaceTextureClient::setScalingMode(%d)", mode);
Mathias Agopian7734ebf2011-07-13 15:24:42 -0700629
Mathias Agopian851ef8f2012-03-29 17:10:08 -0700630 switch (mode) {
631 case NATIVE_WINDOW_SCALING_MODE_FREEZE:
632 case NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW:
Daniel Lam016c8cb2012-04-03 15:54:58 -0700633 case NATIVE_WINDOW_SCALING_MODE_SCALE_CROP:
Mathias Agopian851ef8f2012-03-29 17:10:08 -0700634 break;
635 default:
636 ALOGE("unknown scaling mode: %d", mode);
637 return BAD_VALUE;
638 }
639
640 Mutex::Autolock lock(mMutex);
641 mScalingMode = mode;
642 return NO_ERROR;
Mathias Agopian7734ebf2011-07-13 15:24:42 -0700643}
644
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800645int SurfaceTextureClient::setBuffersTransform(int transform)
646{
Jamie Gennis1c8e95c2012-02-23 19:27:23 -0800647 ATRACE_CALL();
Steve Block6807e592011-10-20 11:56:00 +0100648 ALOGV("SurfaceTextureClient::setBuffersTransform");
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800649 Mutex::Autolock lock(mMutex);
Mathias Agopian851ef8f2012-03-29 17:10:08 -0700650 mTransform = transform;
651 return NO_ERROR;
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800652}
653
Eino-Ville Talvala1d01a122011-02-18 11:02:42 -0800654int SurfaceTextureClient::setBuffersTimestamp(int64_t timestamp)
655{
Steve Block6807e592011-10-20 11:56:00 +0100656 ALOGV("SurfaceTextureClient::setBuffersTimestamp");
Eino-Ville Talvala1d01a122011-02-18 11:02:42 -0800657 Mutex::Autolock lock(mMutex);
658 mTimestamp = timestamp;
659 return NO_ERROR;
660}
661
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800662void SurfaceTextureClient::freeAllBuffers() {
663 for (int i = 0; i < NUM_BUFFER_SLOTS; i++) {
Mathias Agopianac6035a2012-04-12 16:32:37 -0700664 mSlots[i].buffer = 0;
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800665 }
666}
667
Mathias Agopian8f9dbf92011-07-13 17:39:11 -0700668// ----------------------------------------------------------------------
669// the lock/unlock APIs must be used from the same thread
670
671static status_t copyBlt(
672 const sp<GraphicBuffer>& dst,
673 const sp<GraphicBuffer>& src,
674 const Region& reg)
675{
676 // src and dst with, height and format must be identical. no verification
677 // is done here.
678 status_t err;
679 uint8_t const * src_bits = NULL;
680 err = src->lock(GRALLOC_USAGE_SW_READ_OFTEN, reg.bounds(), (void**)&src_bits);
Steve Blocke6f43dd2012-01-06 19:20:56 +0000681 ALOGE_IF(err, "error locking src buffer %s", strerror(-err));
Mathias Agopian8f9dbf92011-07-13 17:39:11 -0700682
683 uint8_t* dst_bits = NULL;
684 err = dst->lock(GRALLOC_USAGE_SW_WRITE_OFTEN, reg.bounds(), (void**)&dst_bits);
Steve Blocke6f43dd2012-01-06 19:20:56 +0000685 ALOGE_IF(err, "error locking dst buffer %s", strerror(-err));
Mathias Agopian8f9dbf92011-07-13 17:39:11 -0700686
687 Region::const_iterator head(reg.begin());
688 Region::const_iterator tail(reg.end());
689 if (head != tail && src_bits && dst_bits) {
690 const size_t bpp = bytesPerPixel(src->format);
691 const size_t dbpr = dst->stride * bpp;
692 const size_t sbpr = src->stride * bpp;
693
694 while (head != tail) {
695 const Rect& r(*head++);
696 ssize_t h = r.height();
697 if (h <= 0) continue;
698 size_t size = r.width() * bpp;
699 uint8_t const * s = src_bits + (r.left + src->stride * r.top) * bpp;
700 uint8_t * d = dst_bits + (r.left + dst->stride * r.top) * bpp;
701 if (dbpr==sbpr && size==sbpr) {
702 size *= h;
703 h = 1;
704 }
705 do {
706 memcpy(d, s, size);
707 d += dbpr;
708 s += sbpr;
709 } while (--h > 0);
710 }
711 }
712
713 if (src_bits)
714 src->unlock();
715
716 if (dst_bits)
717 dst->unlock();
718
719 return err;
720}
721
722// ----------------------------------------------------------------------------
723
724status_t SurfaceTextureClient::lock(
725 ANativeWindow_Buffer* outBuffer, ARect* inOutDirtyBounds)
726{
727 if (mLockedBuffer != 0) {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000728 ALOGE("Surface::lock failed, already locked");
Mathias Agopian8f9dbf92011-07-13 17:39:11 -0700729 return INVALID_OPERATION;
730 }
731
732 if (!mConnectedToCpu) {
733 int err = SurfaceTextureClient::connect(NATIVE_WINDOW_API_CPU);
734 if (err) {
735 return err;
736 }
737 // we're intending to do software rendering from this point
738 setUsage(GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN);
739 }
740
741 ANativeWindowBuffer* out;
Jamie Gennisd8e812c2012-06-13 16:32:25 -0700742 int fenceFd = -1;
743 status_t err = dequeueBuffer(&out, &fenceFd);
Steve Blocke6f43dd2012-01-06 19:20:56 +0000744 ALOGE_IF(err, "dequeueBuffer failed (%s)", strerror(-err));
Mathias Agopian8f9dbf92011-07-13 17:39:11 -0700745 if (err == NO_ERROR) {
746 sp<GraphicBuffer> backBuffer(GraphicBuffer::getSelf(out));
Jamie Gennisd8e812c2012-06-13 16:32:25 -0700747 sp<Fence> fence(new Fence(fenceFd));
Mathias Agopian8f9dbf92011-07-13 17:39:11 -0700748
Jesse Hallba607d52012-10-01 14:05:20 -0700749 err = fence->waitForever(1000, "SurfaceTextureClient::lock");
Jamie Gennisd8e812c2012-06-13 16:32:25 -0700750 if (err != OK) {
751 ALOGE("Fence::wait failed (%s)", strerror(-err));
752 cancelBuffer(out, fenceFd);
753 return err;
Mathias Agopian8f9dbf92011-07-13 17:39:11 -0700754 }
Jamie Gennisd8e812c2012-06-13 16:32:25 -0700755
756 const Rect bounds(backBuffer->width, backBuffer->height);
757
758 Region newDirtyRegion;
759 if (inOutDirtyBounds) {
760 newDirtyRegion.set(static_cast<Rect const&>(*inOutDirtyBounds));
761 newDirtyRegion.andSelf(bounds);
762 } else {
763 newDirtyRegion.set(bounds);
764 }
765
766 // figure out if we can copy the frontbuffer back
767 const sp<GraphicBuffer>& frontBuffer(mPostedBuffer);
768 const bool canCopyBack = (frontBuffer != 0 &&
769 backBuffer->width == frontBuffer->width &&
770 backBuffer->height == frontBuffer->height &&
771 backBuffer->format == frontBuffer->format);
772
773 if (canCopyBack) {
774 // copy the area that is invalid and not repainted this round
775 const Region copyback(mDirtyRegion.subtract(newDirtyRegion));
776 if (!copyback.isEmpty())
777 copyBlt(backBuffer, frontBuffer, copyback);
778 } else {
779 // if we can't copy-back anything, modify the user's dirty
780 // region to make sure they redraw the whole buffer
781 newDirtyRegion.set(bounds);
782 mDirtyRegion.clear();
783 Mutex::Autolock lock(mMutex);
784 for (size_t i=0 ; i<NUM_BUFFER_SLOTS ; i++) {
785 mSlots[i].dirtyRegion.clear();
786 }
787 }
788
789
790 { // scope for the lock
791 Mutex::Autolock lock(mMutex);
792 int backBufferSlot(getSlotFromBufferLocked(backBuffer.get()));
793 if (backBufferSlot >= 0) {
794 Region& dirtyRegion(mSlots[backBufferSlot].dirtyRegion);
795 mDirtyRegion.subtract(dirtyRegion);
796 dirtyRegion = newDirtyRegion;
797 }
798 }
799
800 mDirtyRegion.orSelf(newDirtyRegion);
801 if (inOutDirtyBounds) {
802 *inOutDirtyBounds = newDirtyRegion.getBounds();
803 }
804
805 void* vaddr;
806 status_t res = backBuffer->lock(
807 GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN,
808 newDirtyRegion.bounds(), &vaddr);
809
810 ALOGW_IF(res, "failed locking buffer (handle = %p)",
811 backBuffer->handle);
812
Jean-Baptiste Querud3bbcaf2012-08-20 10:22:33 -0700813 if (res != 0) {
814 err = INVALID_OPERATION;
815 } else {
816 mLockedBuffer = backBuffer;
817 outBuffer->width = backBuffer->width;
818 outBuffer->height = backBuffer->height;
819 outBuffer->stride = backBuffer->stride;
820 outBuffer->format = backBuffer->format;
821 outBuffer->bits = vaddr;
Mathias Agopian8f9dbf92011-07-13 17:39:11 -0700822 }
823 }
824 return err;
825}
826
827status_t SurfaceTextureClient::unlockAndPost()
828{
829 if (mLockedBuffer == 0) {
Steve Blocke6f43dd2012-01-06 19:20:56 +0000830 ALOGE("Surface::unlockAndPost failed, no locked buffer");
Mathias Agopian8f9dbf92011-07-13 17:39:11 -0700831 return INVALID_OPERATION;
832 }
833
834 status_t err = mLockedBuffer->unlock();
Steve Blocke6f43dd2012-01-06 19:20:56 +0000835 ALOGE_IF(err, "failed unlocking buffer (%p)", mLockedBuffer->handle);
Mathias Agopian8f9dbf92011-07-13 17:39:11 -0700836
Jamie Gennisd8e812c2012-06-13 16:32:25 -0700837 err = queueBuffer(mLockedBuffer.get(), -1);
Steve Blocke6f43dd2012-01-06 19:20:56 +0000838 ALOGE_IF(err, "queueBuffer (handle=%p) failed (%s)",
Mathias Agopian8f9dbf92011-07-13 17:39:11 -0700839 mLockedBuffer->handle, strerror(-err));
840
841 mPostedBuffer = mLockedBuffer;
842 mLockedBuffer = 0;
843 return err;
844}
845
Jamie Gennis8ba32fa2010-12-20 11:27:26 -0800846}; // namespace android