2010-12-20 19:27:26 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2010 The Android Open Source Project
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define LOG_TAG "SurfaceTextureClient"
|
2012-02-24 03:27:23 +00:00
|
|
|
#define ATRACE_TAG ATRACE_TAG_GRAPHICS
|
2011-01-13 04:22:41 +00:00
|
|
|
//#define LOG_NDEBUG 0
|
2010-12-20 19:27:26 +00:00
|
|
|
|
2012-03-23 21:15:44 +00:00
|
|
|
#include <android/native_window.h>
|
|
|
|
|
2010-12-20 19:27:26 +00:00
|
|
|
#include <utils/Log.h>
|
2012-02-24 03:27:23 +00:00
|
|
|
#include <utils/Trace.h>
|
2010-12-20 19:27:26 +00:00
|
|
|
|
2012-06-13 23:32:25 +00:00
|
|
|
#include <ui/Fence.h>
|
|
|
|
|
2012-02-26 02:48:35 +00:00
|
|
|
#include <gui/ISurfaceComposer.h>
|
|
|
|
#include <gui/SurfaceComposerClient.h>
|
2012-03-23 21:15:44 +00:00
|
|
|
#include <gui/SurfaceTexture.h>
|
2012-02-26 02:48:35 +00:00
|
|
|
#include <gui/SurfaceTextureClient.h>
|
|
|
|
|
2011-11-18 01:48:35 +00:00
|
|
|
#include <private/gui/ComposerService.h>
|
|
|
|
|
2010-12-20 19:27:26 +00:00
|
|
|
namespace android {
|
|
|
|
|
|
|
|
SurfaceTextureClient::SurfaceTextureClient(
|
2011-07-14 00:39:11 +00:00
|
|
|
const sp<ISurfaceTexture>& surfaceTexture)
|
|
|
|
{
|
|
|
|
SurfaceTextureClient::init();
|
|
|
|
SurfaceTextureClient::setISurfaceTexture(surfaceTexture);
|
|
|
|
}
|
|
|
|
|
2012-02-23 22:35:13 +00:00
|
|
|
// see SurfaceTextureClient.h
|
|
|
|
SurfaceTextureClient::SurfaceTextureClient(const
|
|
|
|
sp<SurfaceTexture>& surfaceTexture)
|
|
|
|
{
|
|
|
|
SurfaceTextureClient::init();
|
|
|
|
SurfaceTextureClient::setISurfaceTexture(surfaceTexture->getBufferQueue());
|
|
|
|
}
|
|
|
|
|
2011-07-14 00:39:11 +00:00
|
|
|
SurfaceTextureClient::SurfaceTextureClient() {
|
|
|
|
SurfaceTextureClient::init();
|
|
|
|
}
|
|
|
|
|
2011-11-18 02:46:09 +00:00
|
|
|
SurfaceTextureClient::~SurfaceTextureClient() {
|
|
|
|
if (mConnectedToCpu) {
|
|
|
|
SurfaceTextureClient::disconnect(NATIVE_WINDOW_API_CPU);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-14 00:39:11 +00:00
|
|
|
void SurfaceTextureClient::init() {
|
2010-12-20 19:27:26 +00:00
|
|
|
// Initialize the ANativeWindow function pointers.
|
2011-07-14 00:39:11 +00:00
|
|
|
ANativeWindow::setSwapInterval = hook_setSwapInterval;
|
|
|
|
ANativeWindow::dequeueBuffer = hook_dequeueBuffer;
|
|
|
|
ANativeWindow::cancelBuffer = hook_cancelBuffer;
|
|
|
|
ANativeWindow::queueBuffer = hook_queueBuffer;
|
|
|
|
ANativeWindow::query = hook_query;
|
|
|
|
ANativeWindow::perform = hook_perform;
|
2011-02-02 23:31:47 +00:00
|
|
|
|
2012-06-13 23:32:25 +00:00
|
|
|
ANativeWindow::dequeueBuffer_DEPRECATED = hook_dequeueBuffer_DEPRECATED;
|
|
|
|
ANativeWindow::cancelBuffer_DEPRECATED = hook_cancelBuffer_DEPRECATED;
|
|
|
|
ANativeWindow::lockBuffer_DEPRECATED = hook_lockBuffer_DEPRECATED;
|
|
|
|
ANativeWindow::queueBuffer_DEPRECATED = hook_queueBuffer_DEPRECATED;
|
|
|
|
|
2011-05-03 02:51:12 +00:00
|
|
|
const_cast<int&>(ANativeWindow::minSwapInterval) = 0;
|
|
|
|
const_cast<int&>(ANativeWindow::maxSwapInterval) = 1;
|
|
|
|
|
2011-07-14 00:39:11 +00:00
|
|
|
mReqWidth = 0;
|
|
|
|
mReqHeight = 0;
|
|
|
|
mReqFormat = 0;
|
|
|
|
mReqUsage = 0;
|
|
|
|
mTimestamp = NATIVE_WINDOW_TIMESTAMP_AUTO;
|
2012-03-30 00:10:08 +00:00
|
|
|
mCrop.clear();
|
|
|
|
mScalingMode = NATIVE_WINDOW_SCALING_MODE_FREEZE;
|
|
|
|
mTransform = 0;
|
2011-07-21 21:50:29 +00:00
|
|
|
mDefaultWidth = 0;
|
|
|
|
mDefaultHeight = 0;
|
2012-04-10 02:46:29 +00:00
|
|
|
mUserWidth = 0;
|
|
|
|
mUserHeight = 0;
|
2011-07-21 21:50:29 +00:00
|
|
|
mTransformHint = 0;
|
2012-04-21 00:19:28 +00:00
|
|
|
mConsumerRunningBehind = false;
|
2011-07-14 00:39:11 +00:00
|
|
|
mConnectedToCpu = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SurfaceTextureClient::setISurfaceTexture(
|
|
|
|
const sp<ISurfaceTexture>& surfaceTexture)
|
|
|
|
{
|
|
|
|
mSurfaceTexture = surfaceTexture;
|
2010-12-20 19:27:26 +00:00
|
|
|
}
|
|
|
|
|
2011-03-14 22:08:53 +00:00
|
|
|
sp<ISurfaceTexture> SurfaceTextureClient::getISurfaceTexture() const {
|
|
|
|
return mSurfaceTexture;
|
|
|
|
}
|
|
|
|
|
2011-07-14 00:39:11 +00:00
|
|
|
int SurfaceTextureClient::hook_setSwapInterval(ANativeWindow* window, int interval) {
|
2010-12-20 19:27:26 +00:00
|
|
|
SurfaceTextureClient* c = getSelf(window);
|
|
|
|
return c->setSwapInterval(interval);
|
|
|
|
}
|
|
|
|
|
2011-07-14 00:39:11 +00:00
|
|
|
int SurfaceTextureClient::hook_dequeueBuffer(ANativeWindow* window,
|
2012-06-13 23:32:25 +00:00
|
|
|
ANativeWindowBuffer** buffer, int* fenceFd) {
|
2010-12-20 19:27:26 +00:00
|
|
|
SurfaceTextureClient* c = getSelf(window);
|
2012-06-13 23:32:25 +00:00
|
|
|
return c->dequeueBuffer(buffer, fenceFd);
|
2010-12-20 19:27:26 +00:00
|
|
|
}
|
|
|
|
|
2011-07-14 00:39:11 +00:00
|
|
|
int SurfaceTextureClient::hook_cancelBuffer(ANativeWindow* window,
|
2012-06-13 23:32:25 +00:00
|
|
|
ANativeWindowBuffer* buffer, int fenceFd) {
|
|
|
|
SurfaceTextureClient* c = getSelf(window);
|
|
|
|
return c->cancelBuffer(buffer, fenceFd);
|
|
|
|
}
|
|
|
|
|
|
|
|
int SurfaceTextureClient::hook_queueBuffer(ANativeWindow* window,
|
|
|
|
ANativeWindowBuffer* buffer, int fenceFd) {
|
|
|
|
SurfaceTextureClient* c = getSelf(window);
|
|
|
|
return c->queueBuffer(buffer, fenceFd);
|
|
|
|
}
|
|
|
|
|
|
|
|
int SurfaceTextureClient::hook_dequeueBuffer_DEPRECATED(ANativeWindow* window,
|
|
|
|
ANativeWindowBuffer** buffer) {
|
|
|
|
SurfaceTextureClient* c = getSelf(window);
|
|
|
|
int fenceFd = -1;
|
|
|
|
int result = c->dequeueBuffer(buffer, &fenceFd);
|
|
|
|
sp<Fence> fence(new Fence(fenceFd));
|
|
|
|
int waitResult = fence->wait(Fence::TIMEOUT_NEVER);
|
|
|
|
if (waitResult != OK) {
|
|
|
|
ALOGE("hook_dequeueBuffer_DEPRECATED: Fence::wait returned an "
|
|
|
|
"error: %d", waitResult);
|
|
|
|
return waitResult;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
int SurfaceTextureClient::hook_cancelBuffer_DEPRECATED(ANativeWindow* window,
|
2011-05-01 18:33:26 +00:00
|
|
|
ANativeWindowBuffer* buffer) {
|
2010-12-20 19:27:26 +00:00
|
|
|
SurfaceTextureClient* c = getSelf(window);
|
2012-06-13 23:32:25 +00:00
|
|
|
return c->cancelBuffer(buffer, -1);
|
2010-12-20 19:27:26 +00:00
|
|
|
}
|
|
|
|
|
2012-06-13 23:32:25 +00:00
|
|
|
int SurfaceTextureClient::hook_lockBuffer_DEPRECATED(ANativeWindow* window,
|
2011-05-01 18:33:26 +00:00
|
|
|
ANativeWindowBuffer* buffer) {
|
2010-12-20 19:27:26 +00:00
|
|
|
SurfaceTextureClient* c = getSelf(window);
|
2012-06-13 23:32:25 +00:00
|
|
|
return c->lockBuffer_DEPRECATED(buffer);
|
2010-12-20 19:27:26 +00:00
|
|
|
}
|
|
|
|
|
2012-06-13 23:32:25 +00:00
|
|
|
int SurfaceTextureClient::hook_queueBuffer_DEPRECATED(ANativeWindow* window,
|
2011-05-01 18:33:26 +00:00
|
|
|
ANativeWindowBuffer* buffer) {
|
2010-12-20 19:27:26 +00:00
|
|
|
SurfaceTextureClient* c = getSelf(window);
|
2012-06-13 23:32:25 +00:00
|
|
|
return c->queueBuffer(buffer, -1);
|
2010-12-20 19:27:26 +00:00
|
|
|
}
|
|
|
|
|
2011-07-14 00:39:11 +00:00
|
|
|
int SurfaceTextureClient::hook_query(const ANativeWindow* window,
|
2011-04-14 23:54:38 +00:00
|
|
|
int what, int* value) {
|
|
|
|
const SurfaceTextureClient* c = getSelf(window);
|
2010-12-20 19:27:26 +00:00
|
|
|
return c->query(what, value);
|
|
|
|
}
|
|
|
|
|
2011-07-14 00:39:11 +00:00
|
|
|
int SurfaceTextureClient::hook_perform(ANativeWindow* window, int operation, ...) {
|
2010-12-20 19:27:26 +00:00
|
|
|
va_list args;
|
|
|
|
va_start(args, operation);
|
|
|
|
SurfaceTextureClient* c = getSelf(window);
|
|
|
|
return c->perform(operation, args);
|
|
|
|
}
|
|
|
|
|
|
|
|
int SurfaceTextureClient::setSwapInterval(int interval) {
|
2012-02-24 03:27:23 +00:00
|
|
|
ATRACE_CALL();
|
2011-05-03 02:51:12 +00:00
|
|
|
// EGL specification states:
|
|
|
|
// interval is silently clamped to minimum and maximum implementation
|
|
|
|
// dependent values before being stored.
|
|
|
|
// Although we don't have to, we apply the same logic here.
|
|
|
|
|
|
|
|
if (interval < minSwapInterval)
|
|
|
|
interval = minSwapInterval;
|
|
|
|
|
|
|
|
if (interval > maxSwapInterval)
|
|
|
|
interval = maxSwapInterval;
|
|
|
|
|
|
|
|
status_t res = mSurfaceTexture->setSynchronousMode(interval ? true : false);
|
|
|
|
|
|
|
|
return res;
|
2010-12-20 19:27:26 +00:00
|
|
|
}
|
|
|
|
|
2012-06-13 23:32:25 +00:00
|
|
|
int SurfaceTextureClient::dequeueBuffer(android_native_buffer_t** buffer,
|
|
|
|
int* fenceFd) {
|
2012-02-24 03:27:23 +00:00
|
|
|
ATRACE_CALL();
|
2011-10-20 10:56:00 +00:00
|
|
|
ALOGV("SurfaceTextureClient::dequeueBuffer");
|
2010-12-20 19:27:26 +00:00
|
|
|
Mutex::Autolock lock(mMutex);
|
|
|
|
int buf = -1;
|
2012-04-10 02:46:29 +00:00
|
|
|
int reqW = mReqWidth ? mReqWidth : mUserWidth;
|
|
|
|
int reqH = mReqHeight ? mReqHeight : mUserHeight;
|
2012-06-14 22:26:33 +00:00
|
|
|
sp<Fence> fence;
|
|
|
|
status_t result = mSurfaceTexture->dequeueBuffer(&buf, fence, reqW, reqH,
|
2011-04-26 03:22:14 +00:00
|
|
|
mReqFormat, mReqUsage);
|
2011-05-03 02:51:12 +00:00
|
|
|
if (result < 0) {
|
2011-10-20 10:56:00 +00:00
|
|
|
ALOGV("dequeueBuffer: ISurfaceTexture::dequeueBuffer(%d, %d, %d, %d)"
|
2011-05-19 20:33:00 +00:00
|
|
|
"failed: %d", mReqWidth, mReqHeight, mReqFormat, mReqUsage,
|
|
|
|
result);
|
2011-05-03 02:51:12 +00:00
|
|
|
return result;
|
2010-12-20 19:27:26 +00:00
|
|
|
}
|
2012-04-12 23:32:37 +00:00
|
|
|
sp<GraphicBuffer>& gbuf(mSlots[buf].buffer);
|
2011-05-03 02:51:12 +00:00
|
|
|
if (result & ISurfaceTexture::RELEASE_ALL_BUFFERS) {
|
|
|
|
freeAllBuffers();
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((result & ISurfaceTexture::BUFFER_NEEDS_REALLOCATION) || gbuf == 0) {
|
2011-07-19 19:08:33 +00:00
|
|
|
result = mSurfaceTexture->requestBuffer(buf, &gbuf);
|
|
|
|
if (result != NO_ERROR) {
|
2012-01-06 19:20:56 +00:00
|
|
|
ALOGE("dequeueBuffer: ISurfaceTexture::requestBuffer failed: %d",
|
2011-07-19 19:08:33 +00:00
|
|
|
result);
|
|
|
|
return result;
|
2010-12-20 19:27:26 +00:00
|
|
|
}
|
|
|
|
}
|
2012-06-14 22:26:33 +00:00
|
|
|
|
|
|
|
if (fence.get()) {
|
|
|
|
status_t err = fence->wait(Fence::TIMEOUT_NEVER);
|
|
|
|
if (err != OK) {
|
|
|
|
ALOGE("dequeueBuffer: error waiting for fence: %d", err);
|
|
|
|
}
|
|
|
|
fence.clear();
|
|
|
|
}
|
|
|
|
|
2010-12-20 19:27:26 +00:00
|
|
|
*buffer = gbuf.get();
|
2012-06-13 23:32:25 +00:00
|
|
|
*fenceFd = -1;
|
2010-12-20 19:27:26 +00:00
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
2012-06-13 23:32:25 +00:00
|
|
|
int SurfaceTextureClient::cancelBuffer(android_native_buffer_t* buffer, int fenceFd) {
|
2012-02-24 03:27:23 +00:00
|
|
|
ATRACE_CALL();
|
2011-10-20 10:56:00 +00:00
|
|
|
ALOGV("SurfaceTextureClient::cancelBuffer");
|
2010-12-20 19:27:26 +00:00
|
|
|
Mutex::Autolock lock(mMutex);
|
2011-06-20 19:04:09 +00:00
|
|
|
int i = getSlotFromBufferLocked(buffer);
|
|
|
|
if (i < 0) {
|
|
|
|
return i;
|
|
|
|
}
|
2012-06-13 23:32:25 +00:00
|
|
|
sp<Fence> fence(new Fence(fenceFd));
|
|
|
|
status_t err = fence->wait(Fence::TIMEOUT_NEVER);
|
|
|
|
if (err != OK) {
|
|
|
|
ALOGE("queueBuffer: Fence::wait returned an error: %d", err);
|
|
|
|
return err;
|
|
|
|
}
|
2011-06-20 19:04:09 +00:00
|
|
|
mSurfaceTexture->cancelBuffer(i);
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
int SurfaceTextureClient::getSlotFromBufferLocked(
|
|
|
|
android_native_buffer_t* buffer) const {
|
|
|
|
bool dumpedState = false;
|
2010-12-20 19:27:26 +00:00
|
|
|
for (int i = 0; i < NUM_BUFFER_SLOTS; i++) {
|
2012-04-12 23:32:37 +00:00
|
|
|
if (mSlots[i].buffer != NULL &&
|
|
|
|
mSlots[i].buffer->handle == buffer->handle) {
|
2011-06-20 19:04:09 +00:00
|
|
|
return i;
|
2010-12-20 19:27:26 +00:00
|
|
|
}
|
|
|
|
}
|
2012-01-06 19:20:56 +00:00
|
|
|
ALOGE("getSlotFromBufferLocked: unknown buffer: %p", buffer->handle);
|
2010-12-20 19:27:26 +00:00
|
|
|
return BAD_VALUE;
|
|
|
|
}
|
|
|
|
|
2012-06-13 23:32:25 +00:00
|
|
|
int SurfaceTextureClient::lockBuffer_DEPRECATED(android_native_buffer_t* buffer) {
|
2011-10-20 10:56:00 +00:00
|
|
|
ALOGV("SurfaceTextureClient::lockBuffer");
|
2010-12-20 19:27:26 +00:00
|
|
|
Mutex::Autolock lock(mMutex);
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
2012-06-13 23:32:25 +00:00
|
|
|
int SurfaceTextureClient::queueBuffer(android_native_buffer_t* buffer, int fenceFd) {
|
2012-02-24 03:27:23 +00:00
|
|
|
ATRACE_CALL();
|
2011-10-20 10:56:00 +00:00
|
|
|
ALOGV("SurfaceTextureClient::queueBuffer");
|
2010-12-20 19:27:26 +00:00
|
|
|
Mutex::Autolock lock(mMutex);
|
2011-02-18 19:02:42 +00:00
|
|
|
int64_t timestamp;
|
|
|
|
if (mTimestamp == NATIVE_WINDOW_TIMESTAMP_AUTO) {
|
|
|
|
timestamp = systemTime(SYSTEM_TIME_MONOTONIC);
|
2011-10-20 10:56:00 +00:00
|
|
|
ALOGV("SurfaceTextureClient::queueBuffer making up timestamp: %.2f ms",
|
2011-02-18 19:02:42 +00:00
|
|
|
timestamp / 1000000.f);
|
|
|
|
} else {
|
|
|
|
timestamp = mTimestamp;
|
|
|
|
}
|
2011-06-20 19:04:09 +00:00
|
|
|
int i = getSlotFromBufferLocked(buffer);
|
|
|
|
if (i < 0) {
|
|
|
|
return i;
|
2010-12-20 19:27:26 +00:00
|
|
|
}
|
2012-04-09 23:14:01 +00:00
|
|
|
|
2012-06-13 23:32:25 +00:00
|
|
|
sp<Fence> fence(new Fence(fenceFd));
|
|
|
|
status_t err = fence->wait(Fence::TIMEOUT_NEVER);
|
|
|
|
if (err != OK) {
|
|
|
|
ALOGE("queueBuffer: Fence::wait returned an error: %d", err);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2012-05-07 20:50:11 +00:00
|
|
|
// Make sure the crop rectangle is entirely inside the buffer.
|
2012-05-14 02:41:35 +00:00
|
|
|
Rect crop;
|
|
|
|
mCrop.intersect(Rect(buffer->width, buffer->height), &crop);
|
2012-05-07 20:50:11 +00:00
|
|
|
|
2012-04-09 23:14:01 +00:00
|
|
|
ISurfaceTexture::QueueBufferOutput output;
|
2012-05-07 20:50:11 +00:00
|
|
|
ISurfaceTexture::QueueBufferInput input(timestamp, crop, mScalingMode,
|
|
|
|
mTransform);
|
2012-06-13 23:32:25 +00:00
|
|
|
err = mSurfaceTexture->queueBuffer(i, input, &output);
|
2011-09-03 00:37:29 +00:00
|
|
|
if (err != OK) {
|
2012-01-06 19:20:56 +00:00
|
|
|
ALOGE("queueBuffer: error queuing buffer to SurfaceTexture, %d", err);
|
2011-09-03 00:37:29 +00:00
|
|
|
}
|
2012-04-21 00:19:28 +00:00
|
|
|
uint32_t numPendingBuffers = 0;
|
|
|
|
output.deflate(&mDefaultWidth, &mDefaultHeight, &mTransformHint,
|
|
|
|
&numPendingBuffers);
|
|
|
|
|
|
|
|
mConsumerRunningBehind = (numPendingBuffers >= 2);
|
|
|
|
|
2011-09-03 00:37:29 +00:00
|
|
|
return err;
|
2010-12-20 19:27:26 +00:00
|
|
|
}
|
|
|
|
|
2011-04-14 23:54:38 +00:00
|
|
|
int SurfaceTextureClient::query(int what, int* value) const {
|
2012-02-24 03:27:23 +00:00
|
|
|
ATRACE_CALL();
|
2011-10-20 10:56:00 +00:00
|
|
|
ALOGV("SurfaceTextureClient::query");
|
2011-07-19 22:24:46 +00:00
|
|
|
{ // scope for the lock
|
|
|
|
Mutex::Autolock lock(mMutex);
|
|
|
|
switch (what) {
|
|
|
|
case NATIVE_WINDOW_FORMAT:
|
|
|
|
if (mReqFormat) {
|
|
|
|
*value = mReqFormat;
|
|
|
|
return NO_ERROR;
|
|
|
|
}
|
|
|
|
break;
|
2012-04-21 00:19:28 +00:00
|
|
|
case NATIVE_WINDOW_QUEUES_TO_WINDOW_COMPOSER: {
|
|
|
|
sp<ISurfaceComposer> composer(
|
|
|
|
ComposerService::getComposerService());
|
|
|
|
if (composer->authenticateSurfaceTexture(mSurfaceTexture)) {
|
|
|
|
*value = 1;
|
|
|
|
} else {
|
|
|
|
*value = 0;
|
2011-08-18 01:19:00 +00:00
|
|
|
}
|
2011-07-19 22:24:46 +00:00
|
|
|
return NO_ERROR;
|
2012-04-21 00:19:28 +00:00
|
|
|
}
|
2011-07-19 22:24:46 +00:00
|
|
|
case NATIVE_WINDOW_CONCRETE_TYPE:
|
|
|
|
*value = NATIVE_WINDOW_SURFACE_TEXTURE_CLIENT;
|
|
|
|
return NO_ERROR;
|
|
|
|
case NATIVE_WINDOW_DEFAULT_WIDTH:
|
2012-04-10 02:46:29 +00:00
|
|
|
*value = mUserWidth ? mUserWidth : mDefaultWidth;
|
2011-07-19 22:24:46 +00:00
|
|
|
return NO_ERROR;
|
|
|
|
case NATIVE_WINDOW_DEFAULT_HEIGHT:
|
2012-04-10 02:46:29 +00:00
|
|
|
*value = mUserHeight ? mUserHeight : mDefaultHeight;
|
2011-07-19 22:24:46 +00:00
|
|
|
return NO_ERROR;
|
|
|
|
case NATIVE_WINDOW_TRANSFORM_HINT:
|
|
|
|
*value = mTransformHint;
|
|
|
|
return NO_ERROR;
|
2012-04-21 00:19:28 +00:00
|
|
|
case NATIVE_WINDOW_CONSUMER_RUNNING_BEHIND: {
|
|
|
|
status_t err = NO_ERROR;
|
|
|
|
if (!mConsumerRunningBehind) {
|
|
|
|
*value = 0;
|
|
|
|
} else {
|
|
|
|
err = mSurfaceTexture->query(what, value);
|
|
|
|
if (err == NO_ERROR) {
|
|
|
|
mConsumerRunningBehind = *value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return err;
|
|
|
|
}
|
2011-04-20 21:20:59 +00:00
|
|
|
}
|
2011-02-27 22:10:20 +00:00
|
|
|
}
|
2011-04-20 21:20:59 +00:00
|
|
|
return mSurfaceTexture->query(what, value);
|
2010-12-20 19:27:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int SurfaceTextureClient::perform(int operation, va_list args)
|
|
|
|
{
|
|
|
|
int res = NO_ERROR;
|
|
|
|
switch (operation) {
|
|
|
|
case NATIVE_WINDOW_CONNECT:
|
2011-07-30 00:55:48 +00:00
|
|
|
// deprecated. must return NO_ERROR.
|
2010-12-20 19:27:26 +00:00
|
|
|
break;
|
|
|
|
case NATIVE_WINDOW_DISCONNECT:
|
2011-07-30 00:55:48 +00:00
|
|
|
// deprecated. must return NO_ERROR.
|
2010-12-20 19:27:26 +00:00
|
|
|
break;
|
|
|
|
case NATIVE_WINDOW_SET_USAGE:
|
|
|
|
res = dispatchSetUsage(args);
|
|
|
|
break;
|
|
|
|
case NATIVE_WINDOW_SET_CROP:
|
|
|
|
res = dispatchSetCrop(args);
|
|
|
|
break;
|
|
|
|
case NATIVE_WINDOW_SET_BUFFER_COUNT:
|
|
|
|
res = dispatchSetBufferCount(args);
|
|
|
|
break;
|
|
|
|
case NATIVE_WINDOW_SET_BUFFERS_GEOMETRY:
|
|
|
|
res = dispatchSetBuffersGeometry(args);
|
|
|
|
break;
|
|
|
|
case NATIVE_WINDOW_SET_BUFFERS_TRANSFORM:
|
|
|
|
res = dispatchSetBuffersTransform(args);
|
|
|
|
break;
|
2011-02-18 19:02:42 +00:00
|
|
|
case NATIVE_WINDOW_SET_BUFFERS_TIMESTAMP:
|
|
|
|
res = dispatchSetBuffersTimestamp(args);
|
|
|
|
break;
|
2011-07-01 20:12:07 +00:00
|
|
|
case NATIVE_WINDOW_SET_BUFFERS_DIMENSIONS:
|
|
|
|
res = dispatchSetBuffersDimensions(args);
|
|
|
|
break;
|
2012-04-10 02:46:29 +00:00
|
|
|
case NATIVE_WINDOW_SET_BUFFERS_USER_DIMENSIONS:
|
|
|
|
res = dispatchSetBuffersUserDimensions(args);
|
|
|
|
break;
|
2011-07-01 20:12:07 +00:00
|
|
|
case NATIVE_WINDOW_SET_BUFFERS_FORMAT:
|
|
|
|
res = dispatchSetBuffersFormat(args);
|
|
|
|
break;
|
2011-07-14 00:39:11 +00:00
|
|
|
case NATIVE_WINDOW_LOCK:
|
|
|
|
res = dispatchLock(args);
|
|
|
|
break;
|
|
|
|
case NATIVE_WINDOW_UNLOCK_AND_POST:
|
|
|
|
res = dispatchUnlockAndPost(args);
|
|
|
|
break;
|
2011-07-13 22:24:42 +00:00
|
|
|
case NATIVE_WINDOW_SET_SCALING_MODE:
|
|
|
|
res = dispatchSetScalingMode(args);
|
|
|
|
break;
|
2011-07-30 00:55:48 +00:00
|
|
|
case NATIVE_WINDOW_API_CONNECT:
|
|
|
|
res = dispatchConnect(args);
|
|
|
|
break;
|
|
|
|
case NATIVE_WINDOW_API_DISCONNECT:
|
|
|
|
res = dispatchDisconnect(args);
|
|
|
|
break;
|
2010-12-20 19:27:26 +00:00
|
|
|
default:
|
|
|
|
res = NAME_NOT_FOUND;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
int SurfaceTextureClient::dispatchConnect(va_list args) {
|
|
|
|
int api = va_arg(args, int);
|
|
|
|
return connect(api);
|
|
|
|
}
|
|
|
|
|
|
|
|
int SurfaceTextureClient::dispatchDisconnect(va_list args) {
|
|
|
|
int api = va_arg(args, int);
|
|
|
|
return disconnect(api);
|
|
|
|
}
|
|
|
|
|
|
|
|
int SurfaceTextureClient::dispatchSetUsage(va_list args) {
|
|
|
|
int usage = va_arg(args, int);
|
|
|
|
return setUsage(usage);
|
|
|
|
}
|
|
|
|
|
|
|
|
int SurfaceTextureClient::dispatchSetCrop(va_list args) {
|
|
|
|
android_native_rect_t const* rect = va_arg(args, android_native_rect_t*);
|
|
|
|
return setCrop(reinterpret_cast<Rect const*>(rect));
|
|
|
|
}
|
|
|
|
|
|
|
|
int SurfaceTextureClient::dispatchSetBufferCount(va_list args) {
|
|
|
|
size_t bufferCount = va_arg(args, size_t);
|
|
|
|
return setBufferCount(bufferCount);
|
|
|
|
}
|
|
|
|
|
|
|
|
int SurfaceTextureClient::dispatchSetBuffersGeometry(va_list args) {
|
|
|
|
int w = va_arg(args, int);
|
|
|
|
int h = va_arg(args, int);
|
|
|
|
int f = va_arg(args, int);
|
2011-07-01 20:12:07 +00:00
|
|
|
int err = setBuffersDimensions(w, h);
|
|
|
|
if (err != 0) {
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
return setBuffersFormat(f);
|
|
|
|
}
|
|
|
|
|
|
|
|
int SurfaceTextureClient::dispatchSetBuffersDimensions(va_list args) {
|
|
|
|
int w = va_arg(args, int);
|
|
|
|
int h = va_arg(args, int);
|
|
|
|
return setBuffersDimensions(w, h);
|
|
|
|
}
|
|
|
|
|
2012-04-10 02:46:29 +00:00
|
|
|
int SurfaceTextureClient::dispatchSetBuffersUserDimensions(va_list args) {
|
|
|
|
int w = va_arg(args, int);
|
|
|
|
int h = va_arg(args, int);
|
|
|
|
return setBuffersUserDimensions(w, h);
|
|
|
|
}
|
|
|
|
|
2011-07-01 20:12:07 +00:00
|
|
|
int SurfaceTextureClient::dispatchSetBuffersFormat(va_list args) {
|
|
|
|
int f = va_arg(args, int);
|
|
|
|
return setBuffersFormat(f);
|
2010-12-20 19:27:26 +00:00
|
|
|
}
|
|
|
|
|
2011-07-13 22:24:42 +00:00
|
|
|
int SurfaceTextureClient::dispatchSetScalingMode(va_list args) {
|
|
|
|
int m = va_arg(args, int);
|
|
|
|
return setScalingMode(m);
|
|
|
|
}
|
|
|
|
|
2010-12-20 19:27:26 +00:00
|
|
|
int SurfaceTextureClient::dispatchSetBuffersTransform(va_list args) {
|
|
|
|
int transform = va_arg(args, int);
|
|
|
|
return setBuffersTransform(transform);
|
|
|
|
}
|
|
|
|
|
2011-02-18 19:02:42 +00:00
|
|
|
int SurfaceTextureClient::dispatchSetBuffersTimestamp(va_list args) {
|
|
|
|
int64_t timestamp = va_arg(args, int64_t);
|
|
|
|
return setBuffersTimestamp(timestamp);
|
|
|
|
}
|
|
|
|
|
2011-07-14 00:39:11 +00:00
|
|
|
int SurfaceTextureClient::dispatchLock(va_list args) {
|
|
|
|
ANativeWindow_Buffer* outBuffer = va_arg(args, ANativeWindow_Buffer*);
|
|
|
|
ARect* inOutDirtyBounds = va_arg(args, ARect*);
|
|
|
|
return lock(outBuffer, inOutDirtyBounds);
|
|
|
|
}
|
|
|
|
|
|
|
|
int SurfaceTextureClient::dispatchUnlockAndPost(va_list args) {
|
|
|
|
return unlockAndPost();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-12-20 19:27:26 +00:00
|
|
|
int SurfaceTextureClient::connect(int api) {
|
2012-02-24 03:27:23 +00:00
|
|
|
ATRACE_CALL();
|
2011-10-20 10:56:00 +00:00
|
|
|
ALOGV("SurfaceTextureClient::connect");
|
2011-04-12 04:19:55 +00:00
|
|
|
Mutex::Autolock lock(mMutex);
|
2012-04-23 21:28:58 +00:00
|
|
|
ISurfaceTexture::QueueBufferOutput output;
|
|
|
|
int err = mSurfaceTexture->connect(api, &output);
|
2012-04-21 00:19:28 +00:00
|
|
|
if (err == NO_ERROR) {
|
|
|
|
uint32_t numPendingBuffers = 0;
|
|
|
|
output.deflate(&mDefaultWidth, &mDefaultHeight, &mTransformHint,
|
|
|
|
&numPendingBuffers);
|
|
|
|
mConsumerRunningBehind = (numPendingBuffers >= 2);
|
|
|
|
}
|
2011-07-14 00:39:11 +00:00
|
|
|
if (!err && api == NATIVE_WINDOW_API_CPU) {
|
|
|
|
mConnectedToCpu = true;
|
|
|
|
}
|
|
|
|
return err;
|
2010-12-20 19:27:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int SurfaceTextureClient::disconnect(int api) {
|
2012-02-24 03:27:23 +00:00
|
|
|
ATRACE_CALL();
|
2011-10-20 10:56:00 +00:00
|
|
|
ALOGV("SurfaceTextureClient::disconnect");
|
2011-04-12 04:19:55 +00:00
|
|
|
Mutex::Autolock lock(mMutex);
|
2011-10-19 00:14:33 +00:00
|
|
|
freeAllBuffers();
|
2011-07-14 00:39:11 +00:00
|
|
|
int err = mSurfaceTexture->disconnect(api);
|
2011-08-26 00:03:30 +00:00
|
|
|
if (!err) {
|
|
|
|
mReqFormat = 0;
|
|
|
|
mReqWidth = 0;
|
|
|
|
mReqHeight = 0;
|
|
|
|
mReqUsage = 0;
|
2012-03-30 00:10:08 +00:00
|
|
|
mCrop.clear();
|
|
|
|
mScalingMode = NATIVE_WINDOW_SCALING_MODE_FREEZE;
|
|
|
|
mTransform = 0;
|
2011-08-26 00:03:30 +00:00
|
|
|
if (api == NATIVE_WINDOW_API_CPU) {
|
|
|
|
mConnectedToCpu = false;
|
|
|
|
}
|
2011-07-14 00:39:11 +00:00
|
|
|
}
|
|
|
|
return err;
|
2010-12-20 19:27:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int SurfaceTextureClient::setUsage(uint32_t reqUsage)
|
|
|
|
{
|
2011-10-20 10:56:00 +00:00
|
|
|
ALOGV("SurfaceTextureClient::setUsage");
|
2010-12-20 19:27:26 +00:00
|
|
|
Mutex::Autolock lock(mMutex);
|
|
|
|
mReqUsage = reqUsage;
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
int SurfaceTextureClient::setCrop(Rect const* rect)
|
|
|
|
{
|
2012-02-24 03:27:23 +00:00
|
|
|
ATRACE_CALL();
|
2010-12-20 19:27:26 +00:00
|
|
|
|
2011-01-29 02:21:54 +00:00
|
|
|
Rect realRect;
|
|
|
|
if (rect == NULL || rect->isEmpty()) {
|
2012-03-30 00:10:08 +00:00
|
|
|
realRect.clear();
|
2011-01-29 02:21:54 +00:00
|
|
|
} else {
|
|
|
|
realRect = *rect;
|
|
|
|
}
|
2010-12-20 19:27:26 +00:00
|
|
|
|
2012-05-10 09:22:33 +00:00
|
|
|
ALOGV("SurfaceTextureClient::setCrop rect=[%d %d %d %d]",
|
|
|
|
realRect.left, realRect.top, realRect.right, realRect.bottom);
|
|
|
|
|
2012-03-30 00:10:08 +00:00
|
|
|
Mutex::Autolock lock(mMutex);
|
2012-04-18 02:36:18 +00:00
|
|
|
mCrop = realRect;
|
2012-03-30 00:10:08 +00:00
|
|
|
return NO_ERROR;
|
2010-12-20 19:27:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int SurfaceTextureClient::setBufferCount(int bufferCount)
|
|
|
|
{
|
2012-02-24 03:27:23 +00:00
|
|
|
ATRACE_CALL();
|
2011-10-20 10:56:00 +00:00
|
|
|
ALOGV("SurfaceTextureClient::setBufferCount");
|
2010-12-20 19:27:26 +00:00
|
|
|
Mutex::Autolock lock(mMutex);
|
|
|
|
|
|
|
|
status_t err = mSurfaceTexture->setBufferCount(bufferCount);
|
2012-01-06 19:20:56 +00:00
|
|
|
ALOGE_IF(err, "ISurfaceTexture::setBufferCount(%d) returned %s",
|
2010-12-20 19:27:26 +00:00
|
|
|
bufferCount, strerror(-err));
|
|
|
|
|
|
|
|
if (err == NO_ERROR) {
|
|
|
|
freeAllBuffers();
|
|
|
|
}
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2011-07-01 20:12:07 +00:00
|
|
|
int SurfaceTextureClient::setBuffersDimensions(int w, int h)
|
2010-12-20 19:27:26 +00:00
|
|
|
{
|
2012-02-24 03:27:23 +00:00
|
|
|
ATRACE_CALL();
|
2011-10-20 10:56:00 +00:00
|
|
|
ALOGV("SurfaceTextureClient::setBuffersDimensions");
|
2010-12-20 19:27:26 +00:00
|
|
|
|
2011-07-01 20:12:07 +00:00
|
|
|
if (w<0 || h<0)
|
2010-12-20 19:27:26 +00:00
|
|
|
return BAD_VALUE;
|
|
|
|
|
|
|
|
if ((w && !h) || (!w && h))
|
|
|
|
return BAD_VALUE;
|
|
|
|
|
2012-03-30 00:10:08 +00:00
|
|
|
Mutex::Autolock lock(mMutex);
|
2010-12-20 19:27:26 +00:00
|
|
|
mReqWidth = w;
|
|
|
|
mReqHeight = h;
|
2012-03-30 00:10:08 +00:00
|
|
|
return NO_ERROR;
|
2010-12-20 19:27:26 +00:00
|
|
|
}
|
|
|
|
|
2012-04-10 02:46:29 +00:00
|
|
|
int SurfaceTextureClient::setBuffersUserDimensions(int w, int h)
|
|
|
|
{
|
|
|
|
ATRACE_CALL();
|
|
|
|
ALOGV("SurfaceTextureClient::setBuffersUserDimensions");
|
|
|
|
|
|
|
|
if (w<0 || h<0)
|
|
|
|
return BAD_VALUE;
|
|
|
|
|
|
|
|
if ((w && !h) || (!w && h))
|
|
|
|
return BAD_VALUE;
|
|
|
|
|
|
|
|
Mutex::Autolock lock(mMutex);
|
|
|
|
mUserWidth = w;
|
|
|
|
mUserHeight = h;
|
|
|
|
return NO_ERROR;
|
|
|
|
}
|
|
|
|
|
2011-07-01 20:12:07 +00:00
|
|
|
int SurfaceTextureClient::setBuffersFormat(int format)
|
|
|
|
{
|
2011-10-20 10:56:00 +00:00
|
|
|
ALOGV("SurfaceTextureClient::setBuffersFormat");
|
2011-07-01 20:12:07 +00:00
|
|
|
|
|
|
|
if (format<0)
|
|
|
|
return BAD_VALUE;
|
|
|
|
|
2012-03-30 00:10:08 +00:00
|
|
|
Mutex::Autolock lock(mMutex);
|
2011-07-01 20:12:07 +00:00
|
|
|
mReqFormat = format;
|
|
|
|
return NO_ERROR;
|
|
|
|
}
|
|
|
|
|
2011-07-13 22:24:42 +00:00
|
|
|
int SurfaceTextureClient::setScalingMode(int mode)
|
|
|
|
{
|
2012-02-24 03:27:23 +00:00
|
|
|
ATRACE_CALL();
|
2011-10-20 10:56:00 +00:00
|
|
|
ALOGV("SurfaceTextureClient::setScalingMode(%d)", mode);
|
2011-07-13 22:24:42 +00:00
|
|
|
|
2012-03-30 00:10:08 +00:00
|
|
|
switch (mode) {
|
|
|
|
case NATIVE_WINDOW_SCALING_MODE_FREEZE:
|
|
|
|
case NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW:
|
2012-04-03 22:54:58 +00:00
|
|
|
case NATIVE_WINDOW_SCALING_MODE_SCALE_CROP:
|
2012-03-30 00:10:08 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ALOGE("unknown scaling mode: %d", mode);
|
|
|
|
return BAD_VALUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
Mutex::Autolock lock(mMutex);
|
|
|
|
mScalingMode = mode;
|
|
|
|
return NO_ERROR;
|
2011-07-13 22:24:42 +00:00
|
|
|
}
|
|
|
|
|
2010-12-20 19:27:26 +00:00
|
|
|
int SurfaceTextureClient::setBuffersTransform(int transform)
|
|
|
|
{
|
2012-02-24 03:27:23 +00:00
|
|
|
ATRACE_CALL();
|
2011-10-20 10:56:00 +00:00
|
|
|
ALOGV("SurfaceTextureClient::setBuffersTransform");
|
2010-12-20 19:27:26 +00:00
|
|
|
Mutex::Autolock lock(mMutex);
|
2012-03-30 00:10:08 +00:00
|
|
|
mTransform = transform;
|
|
|
|
return NO_ERROR;
|
2010-12-20 19:27:26 +00:00
|
|
|
}
|
|
|
|
|
2011-02-18 19:02:42 +00:00
|
|
|
int SurfaceTextureClient::setBuffersTimestamp(int64_t timestamp)
|
|
|
|
{
|
2011-10-20 10:56:00 +00:00
|
|
|
ALOGV("SurfaceTextureClient::setBuffersTimestamp");
|
2011-02-18 19:02:42 +00:00
|
|
|
Mutex::Autolock lock(mMutex);
|
|
|
|
mTimestamp = timestamp;
|
|
|
|
return NO_ERROR;
|
|
|
|
}
|
|
|
|
|
2010-12-20 19:27:26 +00:00
|
|
|
void SurfaceTextureClient::freeAllBuffers() {
|
|
|
|
for (int i = 0; i < NUM_BUFFER_SLOTS; i++) {
|
2012-04-12 23:32:37 +00:00
|
|
|
mSlots[i].buffer = 0;
|
2010-12-20 19:27:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-14 00:39:11 +00:00
|
|
|
// ----------------------------------------------------------------------
|
|
|
|
// the lock/unlock APIs must be used from the same thread
|
|
|
|
|
|
|
|
static status_t copyBlt(
|
|
|
|
const sp<GraphicBuffer>& dst,
|
|
|
|
const sp<GraphicBuffer>& src,
|
|
|
|
const Region& reg)
|
|
|
|
{
|
|
|
|
// src and dst with, height and format must be identical. no verification
|
|
|
|
// is done here.
|
|
|
|
status_t err;
|
|
|
|
uint8_t const * src_bits = NULL;
|
|
|
|
err = src->lock(GRALLOC_USAGE_SW_READ_OFTEN, reg.bounds(), (void**)&src_bits);
|
2012-01-06 19:20:56 +00:00
|
|
|
ALOGE_IF(err, "error locking src buffer %s", strerror(-err));
|
2011-07-14 00:39:11 +00:00
|
|
|
|
|
|
|
uint8_t* dst_bits = NULL;
|
|
|
|
err = dst->lock(GRALLOC_USAGE_SW_WRITE_OFTEN, reg.bounds(), (void**)&dst_bits);
|
2012-01-06 19:20:56 +00:00
|
|
|
ALOGE_IF(err, "error locking dst buffer %s", strerror(-err));
|
2011-07-14 00:39:11 +00:00
|
|
|
|
|
|
|
Region::const_iterator head(reg.begin());
|
|
|
|
Region::const_iterator tail(reg.end());
|
|
|
|
if (head != tail && src_bits && dst_bits) {
|
|
|
|
const size_t bpp = bytesPerPixel(src->format);
|
|
|
|
const size_t dbpr = dst->stride * bpp;
|
|
|
|
const size_t sbpr = src->stride * bpp;
|
|
|
|
|
|
|
|
while (head != tail) {
|
|
|
|
const Rect& r(*head++);
|
|
|
|
ssize_t h = r.height();
|
|
|
|
if (h <= 0) continue;
|
|
|
|
size_t size = r.width() * bpp;
|
|
|
|
uint8_t const * s = src_bits + (r.left + src->stride * r.top) * bpp;
|
|
|
|
uint8_t * d = dst_bits + (r.left + dst->stride * r.top) * bpp;
|
|
|
|
if (dbpr==sbpr && size==sbpr) {
|
|
|
|
size *= h;
|
|
|
|
h = 1;
|
|
|
|
}
|
|
|
|
do {
|
|
|
|
memcpy(d, s, size);
|
|
|
|
d += dbpr;
|
|
|
|
s += sbpr;
|
|
|
|
} while (--h > 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (src_bits)
|
|
|
|
src->unlock();
|
|
|
|
|
|
|
|
if (dst_bits)
|
|
|
|
dst->unlock();
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
status_t SurfaceTextureClient::lock(
|
|
|
|
ANativeWindow_Buffer* outBuffer, ARect* inOutDirtyBounds)
|
|
|
|
{
|
|
|
|
if (mLockedBuffer != 0) {
|
2012-01-06 19:20:56 +00:00
|
|
|
ALOGE("Surface::lock failed, already locked");
|
2011-07-14 00:39:11 +00:00
|
|
|
return INVALID_OPERATION;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mConnectedToCpu) {
|
|
|
|
int err = SurfaceTextureClient::connect(NATIVE_WINDOW_API_CPU);
|
|
|
|
if (err) {
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
// we're intending to do software rendering from this point
|
|
|
|
setUsage(GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN);
|
|
|
|
}
|
|
|
|
|
|
|
|
ANativeWindowBuffer* out;
|
2012-06-13 23:32:25 +00:00
|
|
|
int fenceFd = -1;
|
|
|
|
status_t err = dequeueBuffer(&out, &fenceFd);
|
2012-01-06 19:20:56 +00:00
|
|
|
ALOGE_IF(err, "dequeueBuffer failed (%s)", strerror(-err));
|
2011-07-14 00:39:11 +00:00
|
|
|
if (err == NO_ERROR) {
|
|
|
|
sp<GraphicBuffer> backBuffer(GraphicBuffer::getSelf(out));
|
2012-06-13 23:32:25 +00:00
|
|
|
sp<Fence> fence(new Fence(fenceFd));
|
2011-07-14 00:39:11 +00:00
|
|
|
|
2012-06-13 23:32:25 +00:00
|
|
|
err = fence->wait(Fence::TIMEOUT_NEVER);
|
|
|
|
if (err != OK) {
|
|
|
|
ALOGE("Fence::wait failed (%s)", strerror(-err));
|
|
|
|
cancelBuffer(out, fenceFd);
|
|
|
|
return err;
|
|
|
|
}
|
2011-07-14 00:39:11 +00:00
|
|
|
|
2012-06-13 23:32:25 +00:00
|
|
|
const Rect bounds(backBuffer->width, backBuffer->height);
|
2011-07-14 00:39:11 +00:00
|
|
|
|
2012-06-13 23:32:25 +00:00
|
|
|
Region newDirtyRegion;
|
|
|
|
if (inOutDirtyBounds) {
|
|
|
|
newDirtyRegion.set(static_cast<Rect const&>(*inOutDirtyBounds));
|
|
|
|
newDirtyRegion.andSelf(bounds);
|
|
|
|
} else {
|
|
|
|
newDirtyRegion.set(bounds);
|
|
|
|
}
|
2012-04-12 23:32:37 +00:00
|
|
|
|
2012-06-13 23:32:25 +00:00
|
|
|
// figure out if we can copy the frontbuffer back
|
|
|
|
const sp<GraphicBuffer>& frontBuffer(mPostedBuffer);
|
|
|
|
const bool canCopyBack = (frontBuffer != 0 &&
|
|
|
|
backBuffer->width == frontBuffer->width &&
|
|
|
|
backBuffer->height == frontBuffer->height &&
|
|
|
|
backBuffer->format == frontBuffer->format);
|
|
|
|
|
|
|
|
if (canCopyBack) {
|
|
|
|
// copy the area that is invalid and not repainted this round
|
|
|
|
const Region copyback(mDirtyRegion.subtract(newDirtyRegion));
|
|
|
|
if (!copyback.isEmpty())
|
|
|
|
copyBlt(backBuffer, frontBuffer, copyback);
|
|
|
|
} else {
|
|
|
|
// if we can't copy-back anything, modify the user's dirty
|
|
|
|
// region to make sure they redraw the whole buffer
|
|
|
|
newDirtyRegion.set(bounds);
|
|
|
|
mDirtyRegion.clear();
|
|
|
|
Mutex::Autolock lock(mMutex);
|
|
|
|
for (size_t i=0 ; i<NUM_BUFFER_SLOTS ; i++) {
|
|
|
|
mSlots[i].dirtyRegion.clear();
|
2011-07-14 00:39:11 +00:00
|
|
|
}
|
2012-06-13 23:32:25 +00:00
|
|
|
}
|
2011-07-14 00:39:11 +00:00
|
|
|
|
|
|
|
|
2012-06-13 23:32:25 +00:00
|
|
|
{ // scope for the lock
|
|
|
|
Mutex::Autolock lock(mMutex);
|
|
|
|
int backBufferSlot(getSlotFromBufferLocked(backBuffer.get()));
|
|
|
|
if (backBufferSlot >= 0) {
|
|
|
|
Region& dirtyRegion(mSlots[backBufferSlot].dirtyRegion);
|
|
|
|
mDirtyRegion.subtract(dirtyRegion);
|
|
|
|
dirtyRegion = newDirtyRegion;
|
|
|
|
}
|
|
|
|
}
|
2011-07-14 00:39:11 +00:00
|
|
|
|
2012-06-13 23:32:25 +00:00
|
|
|
mDirtyRegion.orSelf(newDirtyRegion);
|
|
|
|
if (inOutDirtyBounds) {
|
|
|
|
*inOutDirtyBounds = newDirtyRegion.getBounds();
|
2011-07-14 00:39:11 +00:00
|
|
|
}
|
2012-06-13 23:32:25 +00:00
|
|
|
|
|
|
|
void* vaddr;
|
|
|
|
status_t res = backBuffer->lock(
|
|
|
|
GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN,
|
|
|
|
newDirtyRegion.bounds(), &vaddr);
|
|
|
|
|
|
|
|
ALOGW_IF(res, "failed locking buffer (handle = %p)",
|
|
|
|
backBuffer->handle);
|
|
|
|
|
|
|
|
mLockedBuffer = backBuffer;
|
|
|
|
outBuffer->width = backBuffer->width;
|
|
|
|
outBuffer->height = backBuffer->height;
|
|
|
|
outBuffer->stride = backBuffer->stride;
|
|
|
|
outBuffer->format = backBuffer->format;
|
|
|
|
outBuffer->bits = vaddr;
|
2011-07-14 00:39:11 +00:00
|
|
|
}
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
status_t SurfaceTextureClient::unlockAndPost()
|
|
|
|
{
|
|
|
|
if (mLockedBuffer == 0) {
|
2012-01-06 19:20:56 +00:00
|
|
|
ALOGE("Surface::unlockAndPost failed, no locked buffer");
|
2011-07-14 00:39:11 +00:00
|
|
|
return INVALID_OPERATION;
|
|
|
|
}
|
|
|
|
|
|
|
|
status_t err = mLockedBuffer->unlock();
|
2012-01-06 19:20:56 +00:00
|
|
|
ALOGE_IF(err, "failed unlocking buffer (%p)", mLockedBuffer->handle);
|
2011-07-14 00:39:11 +00:00
|
|
|
|
2012-06-13 23:32:25 +00:00
|
|
|
err = queueBuffer(mLockedBuffer.get(), -1);
|
2012-01-06 19:20:56 +00:00
|
|
|
ALOGE_IF(err, "queueBuffer (handle=%p) failed (%s)",
|
2011-07-14 00:39:11 +00:00
|
|
|
mLockedBuffer->handle, strerror(-err));
|
|
|
|
|
|
|
|
mPostedBuffer = mLockedBuffer;
|
|
|
|
mLockedBuffer = 0;
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2010-12-20 19:27:26 +00:00
|
|
|
}; // namespace android
|