mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-30 00:01:50 +00:00
Bug 1098970 - Part 3: Add new files for Nativewindow. r=sotaro
1. Copied Surface.* and rename them as GonkNativeWindowClientLL.* 2. Copied BufferItemConsumer.* and rename them as GonkNativeWindowLL.* 3. Add new IGonkGraphicBufferConsumer.h to control the version 4. Fix the file mode for some JB files (remove execute permission)
This commit is contained in:
parent
82bb82c84a
commit
fbec25158c
0
widget/gonk/nativewindow/GonkBufferQueue.h
Executable file → Normal file
0
widget/gonk/nativewindow/GonkBufferQueue.h
Executable file → Normal file
0
widget/gonk/nativewindow/GonkBufferQueueJB.cpp
Executable file → Normal file
0
widget/gonk/nativewindow/GonkBufferQueueJB.cpp
Executable file → Normal file
0
widget/gonk/nativewindow/GonkBufferQueueJB.h
Executable file → Normal file
0
widget/gonk/nativewindow/GonkBufferQueueJB.h
Executable file → Normal file
0
widget/gonk/nativewindow/GonkConsumerBaseJB.cpp
Executable file → Normal file
0
widget/gonk/nativewindow/GonkConsumerBaseJB.cpp
Executable file → Normal file
0
widget/gonk/nativewindow/GonkConsumerBaseJB.h
Executable file → Normal file
0
widget/gonk/nativewindow/GonkConsumerBaseJB.h
Executable file → Normal file
0
widget/gonk/nativewindow/GonkNativeWindowClientJB.cpp
Executable file → Normal file
0
widget/gonk/nativewindow/GonkNativeWindowClientJB.cpp
Executable file → Normal file
0
widget/gonk/nativewindow/GonkNativeWindowClientJB.h
Executable file → Normal file
0
widget/gonk/nativewindow/GonkNativeWindowClientJB.h
Executable file → Normal file
910
widget/gonk/nativewindow/GonkNativeWindowClientLL.cpp
Normal file
910
widget/gonk/nativewindow/GonkNativeWindowClientLL.cpp
Normal file
@ -0,0 +1,910 @@
|
||||
/*
|
||||
* 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 "Surface"
|
||||
#define ATRACE_TAG ATRACE_TAG_GRAPHICS
|
||||
//#define LOG_NDEBUG 0
|
||||
|
||||
#include <android/native_window.h>
|
||||
|
||||
#include <binder/Parcel.h>
|
||||
|
||||
#include <utils/Log.h>
|
||||
#include <utils/Trace.h>
|
||||
#include <utils/NativeHandle.h>
|
||||
|
||||
#include <ui/Fence.h>
|
||||
|
||||
#include <gui/IProducerListener.h>
|
||||
#include <gui/ISurfaceComposer.h>
|
||||
#include <gui/SurfaceComposerClient.h>
|
||||
#include <gui/GLConsumer.h>
|
||||
#include <gui/Surface.h>
|
||||
|
||||
#include <private/gui/ComposerService.h>
|
||||
|
||||
namespace android {
|
||||
|
||||
Surface::Surface(
|
||||
const sp<IGraphicBufferProducer>& bufferProducer,
|
||||
bool controlledByApp)
|
||||
: mGraphicBufferProducer(bufferProducer)
|
||||
{
|
||||
// Initialize the ANativeWindow function pointers.
|
||||
ANativeWindow::setSwapInterval = hook_setSwapInterval;
|
||||
ANativeWindow::dequeueBuffer = hook_dequeueBuffer;
|
||||
ANativeWindow::cancelBuffer = hook_cancelBuffer;
|
||||
ANativeWindow::queueBuffer = hook_queueBuffer;
|
||||
ANativeWindow::query = hook_query;
|
||||
ANativeWindow::perform = hook_perform;
|
||||
|
||||
ANativeWindow::dequeueBuffer_DEPRECATED = hook_dequeueBuffer_DEPRECATED;
|
||||
ANativeWindow::cancelBuffer_DEPRECATED = hook_cancelBuffer_DEPRECATED;
|
||||
ANativeWindow::lockBuffer_DEPRECATED = hook_lockBuffer_DEPRECATED;
|
||||
ANativeWindow::queueBuffer_DEPRECATED = hook_queueBuffer_DEPRECATED;
|
||||
|
||||
const_cast<int&>(ANativeWindow::minSwapInterval) = 0;
|
||||
const_cast<int&>(ANativeWindow::maxSwapInterval) = 1;
|
||||
|
||||
mReqWidth = 0;
|
||||
mReqHeight = 0;
|
||||
mReqFormat = 0;
|
||||
mReqUsage = 0;
|
||||
mTimestamp = NATIVE_WINDOW_TIMESTAMP_AUTO;
|
||||
mCrop.clear();
|
||||
mScalingMode = NATIVE_WINDOW_SCALING_MODE_FREEZE;
|
||||
mTransform = 0;
|
||||
mStickyTransform = 0;
|
||||
mDefaultWidth = 0;
|
||||
mDefaultHeight = 0;
|
||||
mUserWidth = 0;
|
||||
mUserHeight = 0;
|
||||
mTransformHint = 0;
|
||||
mConsumerRunningBehind = false;
|
||||
mConnectedToCpu = false;
|
||||
mProducerControlledByApp = controlledByApp;
|
||||
mSwapIntervalZero = false;
|
||||
}
|
||||
|
||||
Surface::~Surface() {
|
||||
if (mConnectedToCpu) {
|
||||
Surface::disconnect(NATIVE_WINDOW_API_CPU);
|
||||
}
|
||||
}
|
||||
|
||||
sp<IGraphicBufferProducer> Surface::getIGraphicBufferProducer() const {
|
||||
return mGraphicBufferProducer;
|
||||
}
|
||||
|
||||
void Surface::setSidebandStream(const sp<NativeHandle>& stream) {
|
||||
mGraphicBufferProducer->setSidebandStream(stream);
|
||||
}
|
||||
|
||||
void Surface::allocateBuffers() {
|
||||
uint32_t reqWidth = mReqWidth ? mReqWidth : mUserWidth;
|
||||
uint32_t reqHeight = mReqHeight ? mReqHeight : mUserHeight;
|
||||
mGraphicBufferProducer->allocateBuffers(mSwapIntervalZero, mReqWidth,
|
||||
mReqHeight, mReqFormat, mReqUsage);
|
||||
}
|
||||
|
||||
int Surface::hook_setSwapInterval(ANativeWindow* window, int interval) {
|
||||
Surface* c = getSelf(window);
|
||||
return c->setSwapInterval(interval);
|
||||
}
|
||||
|
||||
int Surface::hook_dequeueBuffer(ANativeWindow* window,
|
||||
ANativeWindowBuffer** buffer, int* fenceFd) {
|
||||
Surface* c = getSelf(window);
|
||||
return c->dequeueBuffer(buffer, fenceFd);
|
||||
}
|
||||
|
||||
int Surface::hook_cancelBuffer(ANativeWindow* window,
|
||||
ANativeWindowBuffer* buffer, int fenceFd) {
|
||||
Surface* c = getSelf(window);
|
||||
return c->cancelBuffer(buffer, fenceFd);
|
||||
}
|
||||
|
||||
int Surface::hook_queueBuffer(ANativeWindow* window,
|
||||
ANativeWindowBuffer* buffer, int fenceFd) {
|
||||
Surface* c = getSelf(window);
|
||||
return c->queueBuffer(buffer, fenceFd);
|
||||
}
|
||||
|
||||
int Surface::hook_dequeueBuffer_DEPRECATED(ANativeWindow* window,
|
||||
ANativeWindowBuffer** buffer) {
|
||||
Surface* c = getSelf(window);
|
||||
ANativeWindowBuffer* buf;
|
||||
int fenceFd = -1;
|
||||
int result = c->dequeueBuffer(&buf, &fenceFd);
|
||||
sp<Fence> fence(new Fence(fenceFd));
|
||||
int waitResult = fence->waitForever("dequeueBuffer_DEPRECATED");
|
||||
if (waitResult != OK) {
|
||||
ALOGE("dequeueBuffer_DEPRECATED: Fence::wait returned an error: %d",
|
||||
waitResult);
|
||||
c->cancelBuffer(buf, -1);
|
||||
return waitResult;
|
||||
}
|
||||
*buffer = buf;
|
||||
return result;
|
||||
}
|
||||
|
||||
int Surface::hook_cancelBuffer_DEPRECATED(ANativeWindow* window,
|
||||
ANativeWindowBuffer* buffer) {
|
||||
Surface* c = getSelf(window);
|
||||
return c->cancelBuffer(buffer, -1);
|
||||
}
|
||||
|
||||
int Surface::hook_lockBuffer_DEPRECATED(ANativeWindow* window,
|
||||
ANativeWindowBuffer* buffer) {
|
||||
Surface* c = getSelf(window);
|
||||
return c->lockBuffer_DEPRECATED(buffer);
|
||||
}
|
||||
|
||||
int Surface::hook_queueBuffer_DEPRECATED(ANativeWindow* window,
|
||||
ANativeWindowBuffer* buffer) {
|
||||
Surface* c = getSelf(window);
|
||||
return c->queueBuffer(buffer, -1);
|
||||
}
|
||||
|
||||
int Surface::hook_query(const ANativeWindow* window,
|
||||
int what, int* value) {
|
||||
const Surface* c = getSelf(window);
|
||||
return c->query(what, value);
|
||||
}
|
||||
|
||||
int Surface::hook_perform(ANativeWindow* window, int operation, ...) {
|
||||
va_list args;
|
||||
va_start(args, operation);
|
||||
Surface* c = getSelf(window);
|
||||
return c->perform(operation, args);
|
||||
}
|
||||
|
||||
int Surface::setSwapInterval(int interval) {
|
||||
ATRACE_CALL();
|
||||
// EGL specification states:
|
||||
// interval is silently clamped to minimum and maximum implementation
|
||||
// dependent values before being stored.
|
||||
|
||||
if (interval < minSwapInterval)
|
||||
interval = minSwapInterval;
|
||||
|
||||
if (interval > maxSwapInterval)
|
||||
interval = maxSwapInterval;
|
||||
|
||||
mSwapIntervalZero = (interval == 0);
|
||||
|
||||
return NO_ERROR;
|
||||
}
|
||||
|
||||
int Surface::dequeueBuffer(android_native_buffer_t** buffer, int* fenceFd) {
|
||||
ATRACE_CALL();
|
||||
ALOGV("Surface::dequeueBuffer");
|
||||
|
||||
int reqW;
|
||||
int reqH;
|
||||
bool swapIntervalZero;
|
||||
uint32_t reqFormat;
|
||||
uint32_t reqUsage;
|
||||
|
||||
{
|
||||
Mutex::Autolock lock(mMutex);
|
||||
|
||||
reqW = mReqWidth ? mReqWidth : mUserWidth;
|
||||
reqH = mReqHeight ? mReqHeight : mUserHeight;
|
||||
|
||||
swapIntervalZero = mSwapIntervalZero;
|
||||
reqFormat = mReqFormat;
|
||||
reqUsage = mReqUsage;
|
||||
} // Drop the lock so that we can still touch the Surface while blocking in IGBP::dequeueBuffer
|
||||
|
||||
int buf = -1;
|
||||
sp<Fence> fence;
|
||||
status_t result = mGraphicBufferProducer->dequeueBuffer(&buf, &fence, swapIntervalZero,
|
||||
reqW, reqH, reqFormat, reqUsage);
|
||||
|
||||
if (result < 0) {
|
||||
ALOGV("dequeueBuffer: IGraphicBufferProducer::dequeueBuffer(%d, %d, %d, %d, %d)"
|
||||
"failed: %d", swapIntervalZero, reqW, reqH, reqFormat, reqUsage,
|
||||
result);
|
||||
return result;
|
||||
}
|
||||
|
||||
Mutex::Autolock lock(mMutex);
|
||||
|
||||
sp<GraphicBuffer>& gbuf(mSlots[buf].buffer);
|
||||
|
||||
// this should never happen
|
||||
ALOGE_IF(fence == NULL, "Surface::dequeueBuffer: received null Fence! buf=%d", buf);
|
||||
|
||||
if (result & IGraphicBufferProducer::RELEASE_ALL_BUFFERS) {
|
||||
freeAllBuffers();
|
||||
}
|
||||
|
||||
if ((result & IGraphicBufferProducer::BUFFER_NEEDS_REALLOCATION) || gbuf == 0) {
|
||||
result = mGraphicBufferProducer->requestBuffer(buf, &gbuf);
|
||||
if (result != NO_ERROR) {
|
||||
ALOGE("dequeueBuffer: IGraphicBufferProducer::requestBuffer failed: %d", result);
|
||||
mGraphicBufferProducer->cancelBuffer(buf, fence);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
if (fence->isValid()) {
|
||||
*fenceFd = fence->dup();
|
||||
if (*fenceFd == -1) {
|
||||
ALOGE("dequeueBuffer: error duping fence: %d", errno);
|
||||
// dup() should never fail; something is badly wrong. Soldier on
|
||||
// and hope for the best; the worst that should happen is some
|
||||
// visible corruption that lasts until the next frame.
|
||||
}
|
||||
} else {
|
||||
*fenceFd = -1;
|
||||
}
|
||||
|
||||
*buffer = gbuf.get();
|
||||
return OK;
|
||||
}
|
||||
|
||||
int Surface::cancelBuffer(android_native_buffer_t* buffer,
|
||||
int fenceFd) {
|
||||
ATRACE_CALL();
|
||||
ALOGV("Surface::cancelBuffer");
|
||||
Mutex::Autolock lock(mMutex);
|
||||
int i = getSlotFromBufferLocked(buffer);
|
||||
if (i < 0) {
|
||||
return i;
|
||||
}
|
||||
sp<Fence> fence(fenceFd >= 0 ? new Fence(fenceFd) : Fence::NO_FENCE);
|
||||
mGraphicBufferProducer->cancelBuffer(i, fence);
|
||||
return OK;
|
||||
}
|
||||
|
||||
int Surface::getSlotFromBufferLocked(
|
||||
android_native_buffer_t* buffer) const {
|
||||
bool dumpedState = false;
|
||||
for (int i = 0; i < NUM_BUFFER_SLOTS; i++) {
|
||||
if (mSlots[i].buffer != NULL &&
|
||||
mSlots[i].buffer->handle == buffer->handle) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
ALOGE("getSlotFromBufferLocked: unknown buffer: %p", buffer->handle);
|
||||
return BAD_VALUE;
|
||||
}
|
||||
|
||||
int Surface::lockBuffer_DEPRECATED(android_native_buffer_t* buffer __attribute__((unused))) {
|
||||
ALOGV("Surface::lockBuffer");
|
||||
Mutex::Autolock lock(mMutex);
|
||||
return OK;
|
||||
}
|
||||
|
||||
int Surface::queueBuffer(android_native_buffer_t* buffer, int fenceFd) {
|
||||
ATRACE_CALL();
|
||||
ALOGV("Surface::queueBuffer");
|
||||
Mutex::Autolock lock(mMutex);
|
||||
int64_t timestamp;
|
||||
bool isAutoTimestamp = false;
|
||||
if (mTimestamp == NATIVE_WINDOW_TIMESTAMP_AUTO) {
|
||||
timestamp = systemTime(SYSTEM_TIME_MONOTONIC);
|
||||
isAutoTimestamp = true;
|
||||
ALOGV("Surface::queueBuffer making up timestamp: %.2f ms",
|
||||
timestamp / 1000000.f);
|
||||
} else {
|
||||
timestamp = mTimestamp;
|
||||
}
|
||||
int i = getSlotFromBufferLocked(buffer);
|
||||
if (i < 0) {
|
||||
return i;
|
||||
}
|
||||
|
||||
|
||||
// Make sure the crop rectangle is entirely inside the buffer.
|
||||
Rect crop;
|
||||
mCrop.intersect(Rect(buffer->width, buffer->height), &crop);
|
||||
|
||||
sp<Fence> fence(fenceFd >= 0 ? new Fence(fenceFd) : Fence::NO_FENCE);
|
||||
IGraphicBufferProducer::QueueBufferOutput output;
|
||||
IGraphicBufferProducer::QueueBufferInput input(timestamp, isAutoTimestamp,
|
||||
crop, mScalingMode, mTransform ^ mStickyTransform, mSwapIntervalZero,
|
||||
fence, mStickyTransform);
|
||||
status_t err = mGraphicBufferProducer->queueBuffer(i, input, &output);
|
||||
if (err != OK) {
|
||||
ALOGE("queueBuffer: error queuing buffer to SurfaceTexture, %d", err);
|
||||
}
|
||||
uint32_t numPendingBuffers = 0;
|
||||
uint32_t hint = 0;
|
||||
output.deflate(&mDefaultWidth, &mDefaultHeight, &hint,
|
||||
&numPendingBuffers);
|
||||
|
||||
// Disable transform hint if sticky transform is set.
|
||||
if (mStickyTransform == 0) {
|
||||
mTransformHint = hint;
|
||||
}
|
||||
|
||||
mConsumerRunningBehind = (numPendingBuffers >= 2);
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
int Surface::query(int what, int* value) const {
|
||||
ATRACE_CALL();
|
||||
ALOGV("Surface::query");
|
||||
{ // scope for the lock
|
||||
Mutex::Autolock lock(mMutex);
|
||||
switch (what) {
|
||||
case NATIVE_WINDOW_FORMAT:
|
||||
if (mReqFormat) {
|
||||
*value = mReqFormat;
|
||||
return NO_ERROR;
|
||||
}
|
||||
break;
|
||||
case NATIVE_WINDOW_QUEUES_TO_WINDOW_COMPOSER: {
|
||||
sp<ISurfaceComposer> composer(
|
||||
ComposerService::getComposerService());
|
||||
if (composer->authenticateSurfaceTexture(mGraphicBufferProducer)) {
|
||||
*value = 1;
|
||||
} else {
|
||||
*value = 0;
|
||||
}
|
||||
return NO_ERROR;
|
||||
}
|
||||
case NATIVE_WINDOW_CONCRETE_TYPE:
|
||||
*value = NATIVE_WINDOW_SURFACE;
|
||||
return NO_ERROR;
|
||||
case NATIVE_WINDOW_DEFAULT_WIDTH:
|
||||
*value = mUserWidth ? mUserWidth : mDefaultWidth;
|
||||
return NO_ERROR;
|
||||
case NATIVE_WINDOW_DEFAULT_HEIGHT:
|
||||
*value = mUserHeight ? mUserHeight : mDefaultHeight;
|
||||
return NO_ERROR;
|
||||
case NATIVE_WINDOW_TRANSFORM_HINT:
|
||||
*value = mTransformHint;
|
||||
return NO_ERROR;
|
||||
case NATIVE_WINDOW_CONSUMER_RUNNING_BEHIND: {
|
||||
status_t err = NO_ERROR;
|
||||
if (!mConsumerRunningBehind) {
|
||||
*value = 0;
|
||||
} else {
|
||||
err = mGraphicBufferProducer->query(what, value);
|
||||
if (err == NO_ERROR) {
|
||||
mConsumerRunningBehind = *value;
|
||||
}
|
||||
}
|
||||
return err;
|
||||
}
|
||||
}
|
||||
}
|
||||
return mGraphicBufferProducer->query(what, value);
|
||||
}
|
||||
|
||||
int Surface::perform(int operation, va_list args)
|
||||
{
|
||||
int res = NO_ERROR;
|
||||
switch (operation) {
|
||||
case NATIVE_WINDOW_CONNECT:
|
||||
// deprecated. must return NO_ERROR.
|
||||
break;
|
||||
case NATIVE_WINDOW_DISCONNECT:
|
||||
// deprecated. must return NO_ERROR.
|
||||
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;
|
||||
case NATIVE_WINDOW_SET_BUFFERS_STICKY_TRANSFORM:
|
||||
res = dispatchSetBuffersStickyTransform(args);
|
||||
break;
|
||||
case NATIVE_WINDOW_SET_BUFFERS_TIMESTAMP:
|
||||
res = dispatchSetBuffersTimestamp(args);
|
||||
break;
|
||||
case NATIVE_WINDOW_SET_BUFFERS_DIMENSIONS:
|
||||
res = dispatchSetBuffersDimensions(args);
|
||||
break;
|
||||
case NATIVE_WINDOW_SET_BUFFERS_USER_DIMENSIONS:
|
||||
res = dispatchSetBuffersUserDimensions(args);
|
||||
break;
|
||||
case NATIVE_WINDOW_SET_BUFFERS_FORMAT:
|
||||
res = dispatchSetBuffersFormat(args);
|
||||
break;
|
||||
case NATIVE_WINDOW_LOCK:
|
||||
res = dispatchLock(args);
|
||||
break;
|
||||
case NATIVE_WINDOW_UNLOCK_AND_POST:
|
||||
res = dispatchUnlockAndPost(args);
|
||||
break;
|
||||
case NATIVE_WINDOW_SET_SCALING_MODE:
|
||||
res = dispatchSetScalingMode(args);
|
||||
break;
|
||||
case NATIVE_WINDOW_API_CONNECT:
|
||||
res = dispatchConnect(args);
|
||||
break;
|
||||
case NATIVE_WINDOW_API_DISCONNECT:
|
||||
res = dispatchDisconnect(args);
|
||||
break;
|
||||
case NATIVE_WINDOW_SET_SIDEBAND_STREAM:
|
||||
res = dispatchSetSidebandStream(args);
|
||||
break;
|
||||
default:
|
||||
res = NAME_NOT_FOUND;
|
||||
break;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
int Surface::dispatchConnect(va_list args) {
|
||||
int api = va_arg(args, int);
|
||||
return connect(api);
|
||||
}
|
||||
|
||||
int Surface::dispatchDisconnect(va_list args) {
|
||||
int api = va_arg(args, int);
|
||||
return disconnect(api);
|
||||
}
|
||||
|
||||
int Surface::dispatchSetUsage(va_list args) {
|
||||
int usage = va_arg(args, int);
|
||||
return setUsage(usage);
|
||||
}
|
||||
|
||||
int Surface::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 Surface::dispatchSetBufferCount(va_list args) {
|
||||
size_t bufferCount = va_arg(args, size_t);
|
||||
return setBufferCount(bufferCount);
|
||||
}
|
||||
|
||||
int Surface::dispatchSetBuffersGeometry(va_list args) {
|
||||
int w = va_arg(args, int);
|
||||
int h = va_arg(args, int);
|
||||
int f = va_arg(args, int);
|
||||
int err = setBuffersDimensions(w, h);
|
||||
if (err != 0) {
|
||||
return err;
|
||||
}
|
||||
return setBuffersFormat(f);
|
||||
}
|
||||
|
||||
int Surface::dispatchSetBuffersDimensions(va_list args) {
|
||||
int w = va_arg(args, int);
|
||||
int h = va_arg(args, int);
|
||||
return setBuffersDimensions(w, h);
|
||||
}
|
||||
|
||||
int Surface::dispatchSetBuffersUserDimensions(va_list args) {
|
||||
int w = va_arg(args, int);
|
||||
int h = va_arg(args, int);
|
||||
return setBuffersUserDimensions(w, h);
|
||||
}
|
||||
|
||||
int Surface::dispatchSetBuffersFormat(va_list args) {
|
||||
int f = va_arg(args, int);
|
||||
return setBuffersFormat(f);
|
||||
}
|
||||
|
||||
int Surface::dispatchSetScalingMode(va_list args) {
|
||||
int m = va_arg(args, int);
|
||||
return setScalingMode(m);
|
||||
}
|
||||
|
||||
int Surface::dispatchSetBuffersTransform(va_list args) {
|
||||
int transform = va_arg(args, int);
|
||||
return setBuffersTransform(transform);
|
||||
}
|
||||
|
||||
int Surface::dispatchSetBuffersStickyTransform(va_list args) {
|
||||
int transform = va_arg(args, int);
|
||||
return setBuffersStickyTransform(transform);
|
||||
}
|
||||
|
||||
int Surface::dispatchSetBuffersTimestamp(va_list args) {
|
||||
int64_t timestamp = va_arg(args, int64_t);
|
||||
return setBuffersTimestamp(timestamp);
|
||||
}
|
||||
|
||||
int Surface::dispatchLock(va_list args) {
|
||||
ANativeWindow_Buffer* outBuffer = va_arg(args, ANativeWindow_Buffer*);
|
||||
ARect* inOutDirtyBounds = va_arg(args, ARect*);
|
||||
return lock(outBuffer, inOutDirtyBounds);
|
||||
}
|
||||
|
||||
int Surface::dispatchUnlockAndPost(va_list args __attribute__((unused))) {
|
||||
return unlockAndPost();
|
||||
}
|
||||
|
||||
int Surface::dispatchSetSidebandStream(va_list args) {
|
||||
native_handle_t* sH = va_arg(args, native_handle_t*);
|
||||
sp<NativeHandle> sidebandHandle = NativeHandle::create(sH, false);
|
||||
setSidebandStream(sidebandHandle);
|
||||
return OK;
|
||||
}
|
||||
|
||||
int Surface::connect(int api) {
|
||||
ATRACE_CALL();
|
||||
ALOGV("Surface::connect");
|
||||
static sp<IProducerListener> listener = new DummyProducerListener();
|
||||
Mutex::Autolock lock(mMutex);
|
||||
IGraphicBufferProducer::QueueBufferOutput output;
|
||||
int err = mGraphicBufferProducer->connect(listener, api, mProducerControlledByApp, &output);
|
||||
if (err == NO_ERROR) {
|
||||
uint32_t numPendingBuffers = 0;
|
||||
uint32_t hint = 0;
|
||||
output.deflate(&mDefaultWidth, &mDefaultHeight, &hint,
|
||||
&numPendingBuffers);
|
||||
|
||||
// Disable transform hint if sticky transform is set.
|
||||
if (mStickyTransform == 0) {
|
||||
mTransformHint = hint;
|
||||
}
|
||||
|
||||
mConsumerRunningBehind = (numPendingBuffers >= 2);
|
||||
}
|
||||
if (!err && api == NATIVE_WINDOW_API_CPU) {
|
||||
mConnectedToCpu = true;
|
||||
}
|
||||
return err;
|
||||
}
|
||||
|
||||
|
||||
int Surface::disconnect(int api) {
|
||||
ATRACE_CALL();
|
||||
ALOGV("Surface::disconnect");
|
||||
Mutex::Autolock lock(mMutex);
|
||||
freeAllBuffers();
|
||||
int err = mGraphicBufferProducer->disconnect(api);
|
||||
if (!err) {
|
||||
mReqFormat = 0;
|
||||
mReqWidth = 0;
|
||||
mReqHeight = 0;
|
||||
mReqUsage = 0;
|
||||
mCrop.clear();
|
||||
mScalingMode = NATIVE_WINDOW_SCALING_MODE_FREEZE;
|
||||
mTransform = 0;
|
||||
mStickyTransform = 0;
|
||||
|
||||
if (api == NATIVE_WINDOW_API_CPU) {
|
||||
mConnectedToCpu = false;
|
||||
}
|
||||
}
|
||||
return err;
|
||||
}
|
||||
|
||||
int Surface::setUsage(uint32_t reqUsage)
|
||||
{
|
||||
ALOGV("Surface::setUsage");
|
||||
Mutex::Autolock lock(mMutex);
|
||||
mReqUsage = reqUsage;
|
||||
return OK;
|
||||
}
|
||||
|
||||
int Surface::setCrop(Rect const* rect)
|
||||
{
|
||||
ATRACE_CALL();
|
||||
|
||||
Rect realRect;
|
||||
if (rect == NULL || rect->isEmpty()) {
|
||||
realRect.clear();
|
||||
} else {
|
||||
realRect = *rect;
|
||||
}
|
||||
|
||||
ALOGV("Surface::setCrop rect=[%d %d %d %d]",
|
||||
realRect.left, realRect.top, realRect.right, realRect.bottom);
|
||||
|
||||
Mutex::Autolock lock(mMutex);
|
||||
mCrop = realRect;
|
||||
return NO_ERROR;
|
||||
}
|
||||
|
||||
int Surface::setBufferCount(int bufferCount)
|
||||
{
|
||||
ATRACE_CALL();
|
||||
ALOGV("Surface::setBufferCount");
|
||||
Mutex::Autolock lock(mMutex);
|
||||
|
||||
status_t err = mGraphicBufferProducer->setBufferCount(bufferCount);
|
||||
ALOGE_IF(err, "IGraphicBufferProducer::setBufferCount(%d) returned %s",
|
||||
bufferCount, strerror(-err));
|
||||
|
||||
if (err == NO_ERROR) {
|
||||
freeAllBuffers();
|
||||
}
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
int Surface::setBuffersDimensions(int w, int h)
|
||||
{
|
||||
ATRACE_CALL();
|
||||
ALOGV("Surface::setBuffersDimensions");
|
||||
|
||||
if (w<0 || h<0)
|
||||
return BAD_VALUE;
|
||||
|
||||
if ((w && !h) || (!w && h))
|
||||
return BAD_VALUE;
|
||||
|
||||
Mutex::Autolock lock(mMutex);
|
||||
mReqWidth = w;
|
||||
mReqHeight = h;
|
||||
return NO_ERROR;
|
||||
}
|
||||
|
||||
int Surface::setBuffersUserDimensions(int w, int h)
|
||||
{
|
||||
ATRACE_CALL();
|
||||
ALOGV("Surface::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;
|
||||
}
|
||||
|
||||
int Surface::setBuffersFormat(int format)
|
||||
{
|
||||
ALOGV("Surface::setBuffersFormat");
|
||||
|
||||
if (format<0)
|
||||
return BAD_VALUE;
|
||||
|
||||
Mutex::Autolock lock(mMutex);
|
||||
mReqFormat = format;
|
||||
return NO_ERROR;
|
||||
}
|
||||
|
||||
int Surface::setScalingMode(int mode)
|
||||
{
|
||||
ATRACE_CALL();
|
||||
ALOGV("Surface::setScalingMode(%d)", mode);
|
||||
|
||||
switch (mode) {
|
||||
case NATIVE_WINDOW_SCALING_MODE_FREEZE:
|
||||
case NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW:
|
||||
case NATIVE_WINDOW_SCALING_MODE_SCALE_CROP:
|
||||
break;
|
||||
default:
|
||||
ALOGE("unknown scaling mode: %d", mode);
|
||||
return BAD_VALUE;
|
||||
}
|
||||
|
||||
Mutex::Autolock lock(mMutex);
|
||||
mScalingMode = mode;
|
||||
return NO_ERROR;
|
||||
}
|
||||
|
||||
int Surface::setBuffersTransform(int transform)
|
||||
{
|
||||
ATRACE_CALL();
|
||||
ALOGV("Surface::setBuffersTransform");
|
||||
Mutex::Autolock lock(mMutex);
|
||||
mTransform = transform;
|
||||
return NO_ERROR;
|
||||
}
|
||||
|
||||
int Surface::setBuffersStickyTransform(int transform)
|
||||
{
|
||||
ATRACE_CALL();
|
||||
ALOGV("Surface::setBuffersStickyTransform");
|
||||
Mutex::Autolock lock(mMutex);
|
||||
mStickyTransform = transform;
|
||||
return NO_ERROR;
|
||||
}
|
||||
|
||||
int Surface::setBuffersTimestamp(int64_t timestamp)
|
||||
{
|
||||
ALOGV("Surface::setBuffersTimestamp");
|
||||
Mutex::Autolock lock(mMutex);
|
||||
mTimestamp = timestamp;
|
||||
return NO_ERROR;
|
||||
}
|
||||
|
||||
void Surface::freeAllBuffers() {
|
||||
for (int i = 0; i < NUM_BUFFER_SLOTS; i++) {
|
||||
mSlots[i].buffer = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// 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);
|
||||
ALOGE_IF(err, "error locking src buffer %s", strerror(-err));
|
||||
|
||||
uint8_t* dst_bits = NULL;
|
||||
err = dst->lock(GRALLOC_USAGE_SW_WRITE_OFTEN, reg.bounds(), (void**)&dst_bits);
|
||||
ALOGE_IF(err, "error locking dst buffer %s", strerror(-err));
|
||||
|
||||
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 Surface::lock(
|
||||
ANativeWindow_Buffer* outBuffer, ARect* inOutDirtyBounds)
|
||||
{
|
||||
if (mLockedBuffer != 0) {
|
||||
ALOGE("Surface::lock failed, already locked");
|
||||
return INVALID_OPERATION;
|
||||
}
|
||||
|
||||
if (!mConnectedToCpu) {
|
||||
int err = Surface::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;
|
||||
int fenceFd = -1;
|
||||
status_t err = dequeueBuffer(&out, &fenceFd);
|
||||
ALOGE_IF(err, "dequeueBuffer failed (%s)", strerror(-err));
|
||||
if (err == NO_ERROR) {
|
||||
sp<GraphicBuffer> backBuffer(GraphicBuffer::getSelf(out));
|
||||
const Rect bounds(backBuffer->width, backBuffer->height);
|
||||
|
||||
Region newDirtyRegion;
|
||||
if (inOutDirtyBounds) {
|
||||
newDirtyRegion.set(static_cast<Rect const&>(*inOutDirtyBounds));
|
||||
newDirtyRegion.andSelf(bounds);
|
||||
} else {
|
||||
newDirtyRegion.set(bounds);
|
||||
}
|
||||
|
||||
// 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();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
{ // 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;
|
||||
}
|
||||
}
|
||||
|
||||
mDirtyRegion.orSelf(newDirtyRegion);
|
||||
if (inOutDirtyBounds) {
|
||||
*inOutDirtyBounds = newDirtyRegion.getBounds();
|
||||
}
|
||||
|
||||
void* vaddr;
|
||||
status_t res = backBuffer->lockAsync(
|
||||
GRALLOC_USAGE_SW_READ_OFTEN | GRALLOC_USAGE_SW_WRITE_OFTEN,
|
||||
newDirtyRegion.bounds(), &vaddr, fenceFd);
|
||||
|
||||
ALOGW_IF(res, "failed locking buffer (handle = %p)",
|
||||
backBuffer->handle);
|
||||
|
||||
if (res != 0) {
|
||||
err = INVALID_OPERATION;
|
||||
} else {
|
||||
mLockedBuffer = backBuffer;
|
||||
outBuffer->width = backBuffer->width;
|
||||
outBuffer->height = backBuffer->height;
|
||||
outBuffer->stride = backBuffer->stride;
|
||||
outBuffer->format = backBuffer->format;
|
||||
outBuffer->bits = vaddr;
|
||||
}
|
||||
}
|
||||
return err;
|
||||
}
|
||||
|
||||
status_t Surface::unlockAndPost()
|
||||
{
|
||||
if (mLockedBuffer == 0) {
|
||||
ALOGE("Surface::unlockAndPost failed, no locked buffer");
|
||||
return INVALID_OPERATION;
|
||||
}
|
||||
|
||||
int fd = -1;
|
||||
status_t err = mLockedBuffer->unlockAsync(&fd);
|
||||
ALOGE_IF(err, "failed unlocking buffer (%p)", mLockedBuffer->handle);
|
||||
|
||||
err = queueBuffer(mLockedBuffer.get(), fd);
|
||||
ALOGE_IF(err, "queueBuffer (handle=%p) failed (%s)",
|
||||
mLockedBuffer->handle, strerror(-err));
|
||||
|
||||
mPostedBuffer = mLockedBuffer;
|
||||
mLockedBuffer = 0;
|
||||
return err;
|
||||
}
|
||||
|
||||
}; // namespace android
|
293
widget/gonk/nativewindow/GonkNativeWindowClientLL.h
Normal file
293
widget/gonk/nativewindow/GonkNativeWindowClientLL.h
Normal file
@ -0,0 +1,293 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef ANDROID_GUI_SURFACE_H
|
||||
#define ANDROID_GUI_SURFACE_H
|
||||
|
||||
#include <gui/IGraphicBufferProducer.h>
|
||||
#include <gui/BufferQueue.h>
|
||||
|
||||
#include <ui/ANativeObjectBase.h>
|
||||
#include <ui/Region.h>
|
||||
|
||||
#include <utils/RefBase.h>
|
||||
#include <utils/threads.h>
|
||||
#include <utils/KeyedVector.h>
|
||||
|
||||
struct ANativeWindow_Buffer;
|
||||
|
||||
namespace android {
|
||||
|
||||
/*
|
||||
* An implementation of ANativeWindow that feeds graphics buffers into a
|
||||
* BufferQueue.
|
||||
*
|
||||
* This is typically used by programs that want to render frames through
|
||||
* some means (maybe OpenGL, a software renderer, or a hardware decoder)
|
||||
* and have the frames they create forwarded to SurfaceFlinger for
|
||||
* compositing. For example, a video decoder could render a frame and call
|
||||
* eglSwapBuffers(), which invokes ANativeWindow callbacks defined by
|
||||
* Surface. Surface then forwards the buffers through Binder IPC
|
||||
* to the BufferQueue's producer interface, providing the new frame to a
|
||||
* consumer such as GLConsumer.
|
||||
*/
|
||||
class Surface
|
||||
: public ANativeObjectBase<ANativeWindow, Surface, RefBase>
|
||||
{
|
||||
public:
|
||||
|
||||
/*
|
||||
* creates a Surface from the given IGraphicBufferProducer (which concrete
|
||||
* implementation is a BufferQueue).
|
||||
*
|
||||
* Surface is mainly state-less while it's disconnected, it can be
|
||||
* viewed as a glorified IGraphicBufferProducer holder. It's therefore
|
||||
* safe to create other Surfaces from the same IGraphicBufferProducer.
|
||||
*
|
||||
* However, once a Surface is connected, it'll prevent other Surfaces
|
||||
* referring to the same IGraphicBufferProducer to become connected and
|
||||
* therefore prevent them to be used as actual producers of buffers.
|
||||
*
|
||||
* the controlledByApp flag indicates that this Surface (producer) is
|
||||
* controlled by the application. This flag is used at connect time.
|
||||
*/
|
||||
Surface(const sp<IGraphicBufferProducer>& bufferProducer, bool controlledByApp = false);
|
||||
|
||||
/* getIGraphicBufferProducer() returns the IGraphicBufferProducer this
|
||||
* Surface was created with. Usually it's an error to use the
|
||||
* IGraphicBufferProducer while the Surface is connected.
|
||||
*/
|
||||
sp<IGraphicBufferProducer> getIGraphicBufferProducer() const;
|
||||
|
||||
/* convenience function to check that the given surface is non NULL as
|
||||
* well as its IGraphicBufferProducer */
|
||||
static bool isValid(const sp<Surface>& surface) {
|
||||
return surface != NULL && surface->getIGraphicBufferProducer() != NULL;
|
||||
}
|
||||
|
||||
/* Attaches a sideband buffer stream to the Surface's IGraphicBufferProducer.
|
||||
*
|
||||
* A sideband stream is a device-specific mechanism for passing buffers
|
||||
* from the producer to the consumer without using dequeueBuffer/
|
||||
* queueBuffer. If a sideband stream is present, the consumer can choose
|
||||
* whether to acquire buffers from the sideband stream or from the queued
|
||||
* buffers.
|
||||
*
|
||||
* Passing NULL or a different stream handle will detach the previous
|
||||
* handle if any.
|
||||
*/
|
||||
void setSidebandStream(const sp<NativeHandle>& stream);
|
||||
|
||||
/* Allocates buffers based on the current dimensions/format.
|
||||
*
|
||||
* This function will allocate up to the maximum number of buffers
|
||||
* permitted by the current BufferQueue configuration. It will use the
|
||||
* default format and dimensions. This is most useful to avoid an allocation
|
||||
* delay during dequeueBuffer. If there are already the maximum number of
|
||||
* buffers allocated, this function has no effect.
|
||||
*/
|
||||
void allocateBuffers();
|
||||
|
||||
protected:
|
||||
virtual ~Surface();
|
||||
|
||||
private:
|
||||
// can't be copied
|
||||
Surface& operator = (const Surface& rhs);
|
||||
Surface(const Surface& rhs);
|
||||
|
||||
// ANativeWindow hooks
|
||||
static int hook_cancelBuffer(ANativeWindow* window,
|
||||
ANativeWindowBuffer* buffer, int fenceFd);
|
||||
static int hook_dequeueBuffer(ANativeWindow* window,
|
||||
ANativeWindowBuffer** buffer, int* fenceFd);
|
||||
static int hook_perform(ANativeWindow* window, int operation, ...);
|
||||
static int hook_query(const ANativeWindow* window, int what, int* value);
|
||||
static int hook_queueBuffer(ANativeWindow* window,
|
||||
ANativeWindowBuffer* buffer, int fenceFd);
|
||||
static int hook_setSwapInterval(ANativeWindow* window, int interval);
|
||||
|
||||
static int hook_cancelBuffer_DEPRECATED(ANativeWindow* window,
|
||||
ANativeWindowBuffer* buffer);
|
||||
static int hook_dequeueBuffer_DEPRECATED(ANativeWindow* window,
|
||||
ANativeWindowBuffer** buffer);
|
||||
static int hook_lockBuffer_DEPRECATED(ANativeWindow* window,
|
||||
ANativeWindowBuffer* buffer);
|
||||
static int hook_queueBuffer_DEPRECATED(ANativeWindow* window,
|
||||
ANativeWindowBuffer* buffer);
|
||||
|
||||
int dispatchConnect(va_list args);
|
||||
int dispatchDisconnect(va_list args);
|
||||
int dispatchSetBufferCount(va_list args);
|
||||
int dispatchSetBuffersGeometry(va_list args);
|
||||
int dispatchSetBuffersDimensions(va_list args);
|
||||
int dispatchSetBuffersUserDimensions(va_list args);
|
||||
int dispatchSetBuffersFormat(va_list args);
|
||||
int dispatchSetScalingMode(va_list args);
|
||||
int dispatchSetBuffersTransform(va_list args);
|
||||
int dispatchSetBuffersStickyTransform(va_list args);
|
||||
int dispatchSetBuffersTimestamp(va_list args);
|
||||
int dispatchSetCrop(va_list args);
|
||||
int dispatchSetPostTransformCrop(va_list args);
|
||||
int dispatchSetUsage(va_list args);
|
||||
int dispatchLock(va_list args);
|
||||
int dispatchUnlockAndPost(va_list args);
|
||||
int dispatchSetSidebandStream(va_list args);
|
||||
|
||||
protected:
|
||||
virtual int dequeueBuffer(ANativeWindowBuffer** buffer, int* fenceFd);
|
||||
virtual int cancelBuffer(ANativeWindowBuffer* buffer, int fenceFd);
|
||||
virtual int queueBuffer(ANativeWindowBuffer* buffer, int fenceFd);
|
||||
virtual int perform(int operation, va_list args);
|
||||
virtual int query(int what, int* value) const;
|
||||
virtual int setSwapInterval(int interval);
|
||||
|
||||
virtual int lockBuffer_DEPRECATED(ANativeWindowBuffer* buffer);
|
||||
|
||||
virtual int connect(int api);
|
||||
virtual int disconnect(int api);
|
||||
virtual int setBufferCount(int bufferCount);
|
||||
virtual int setBuffersDimensions(int w, int h);
|
||||
virtual int setBuffersUserDimensions(int w, int h);
|
||||
virtual int setBuffersFormat(int format);
|
||||
virtual int setScalingMode(int mode);
|
||||
virtual int setBuffersTransform(int transform);
|
||||
virtual int setBuffersStickyTransform(int transform);
|
||||
virtual int setBuffersTimestamp(int64_t timestamp);
|
||||
virtual int setCrop(Rect const* rect);
|
||||
virtual int setUsage(uint32_t reqUsage);
|
||||
|
||||
public:
|
||||
virtual int lock(ANativeWindow_Buffer* outBuffer, ARect* inOutDirtyBounds);
|
||||
virtual int unlockAndPost();
|
||||
|
||||
protected:
|
||||
enum { NUM_BUFFER_SLOTS = BufferQueue::NUM_BUFFER_SLOTS };
|
||||
enum { DEFAULT_FORMAT = PIXEL_FORMAT_RGBA_8888 };
|
||||
|
||||
private:
|
||||
void freeAllBuffers();
|
||||
int getSlotFromBufferLocked(android_native_buffer_t* buffer) const;
|
||||
|
||||
struct BufferSlot {
|
||||
sp<GraphicBuffer> buffer;
|
||||
Region dirtyRegion;
|
||||
};
|
||||
|
||||
// mSurfaceTexture is the interface to the surface texture server. All
|
||||
// operations on the surface texture client ultimately translate into
|
||||
// interactions with the server using this interface.
|
||||
// TODO: rename to mBufferProducer
|
||||
sp<IGraphicBufferProducer> mGraphicBufferProducer;
|
||||
|
||||
// mSlots stores the buffers that have been allocated for each buffer slot.
|
||||
// It is initialized to null pointers, and gets filled in with the result of
|
||||
// IGraphicBufferProducer::requestBuffer when the client dequeues a buffer from a
|
||||
// slot that has not yet been used. The buffer allocated to a slot will also
|
||||
// be replaced if the requested buffer usage or geometry differs from that
|
||||
// of the buffer allocated to a slot.
|
||||
BufferSlot mSlots[NUM_BUFFER_SLOTS];
|
||||
|
||||
// mReqWidth is the buffer width that will be requested at the next dequeue
|
||||
// operation. It is initialized to 1.
|
||||
uint32_t mReqWidth;
|
||||
|
||||
// mReqHeight is the buffer height that will be requested at the next
|
||||
// dequeue operation. It is initialized to 1.
|
||||
uint32_t mReqHeight;
|
||||
|
||||
// mReqFormat is the buffer pixel format that will be requested at the next
|
||||
// deuque operation. It is initialized to PIXEL_FORMAT_RGBA_8888.
|
||||
uint32_t mReqFormat;
|
||||
|
||||
// mReqUsage is the set of buffer usage flags that will be requested
|
||||
// at the next deuque operation. It is initialized to 0.
|
||||
uint32_t mReqUsage;
|
||||
|
||||
// mTimestamp is the timestamp that will be used for the next buffer queue
|
||||
// operation. It defaults to NATIVE_WINDOW_TIMESTAMP_AUTO, which means that
|
||||
// a timestamp is auto-generated when queueBuffer is called.
|
||||
int64_t mTimestamp;
|
||||
|
||||
// mCrop is the crop rectangle that will be used for the next buffer
|
||||
// that gets queued. It is set by calling setCrop.
|
||||
Rect mCrop;
|
||||
|
||||
// mScalingMode is the scaling mode that will be used for the next
|
||||
// buffers that get queued. It is set by calling setScalingMode.
|
||||
int mScalingMode;
|
||||
|
||||
// mTransform is the transform identifier that will be used for the next
|
||||
// buffer that gets queued. It is set by calling setTransform.
|
||||
uint32_t mTransform;
|
||||
|
||||
// mStickyTransform is a transform that is applied on top of mTransform
|
||||
// in each buffer that is queued. This is typically used to force the
|
||||
// compositor to apply a transform, and will prevent the transform hint
|
||||
// from being set by the compositor.
|
||||
uint32_t mStickyTransform;
|
||||
|
||||
// mDefaultWidth is default width of the buffers, regardless of the
|
||||
// native_window_set_buffers_dimensions call.
|
||||
uint32_t mDefaultWidth;
|
||||
|
||||
// mDefaultHeight is default height of the buffers, regardless of the
|
||||
// native_window_set_buffers_dimensions call.
|
||||
uint32_t mDefaultHeight;
|
||||
|
||||
// mUserWidth, if non-zero, is an application-specified override
|
||||
// of mDefaultWidth. This is lower priority than the width set by
|
||||
// native_window_set_buffers_dimensions.
|
||||
uint32_t mUserWidth;
|
||||
|
||||
// mUserHeight, if non-zero, is an application-specified override
|
||||
// of mDefaultHeight. This is lower priority than the height set
|
||||
// by native_window_set_buffers_dimensions.
|
||||
uint32_t mUserHeight;
|
||||
|
||||
// mTransformHint is the transform probably applied to buffers of this
|
||||
// window. this is only a hint, actual transform may differ.
|
||||
uint32_t mTransformHint;
|
||||
|
||||
// mProducerControlledByApp whether this buffer producer is controlled
|
||||
// by the application
|
||||
bool mProducerControlledByApp;
|
||||
|
||||
// mSwapIntervalZero set if we should drop buffers at queue() time to
|
||||
// achieve an asynchronous swap interval
|
||||
bool mSwapIntervalZero;
|
||||
|
||||
// mConsumerRunningBehind whether the consumer is running more than
|
||||
// one buffer behind the producer.
|
||||
mutable bool mConsumerRunningBehind;
|
||||
|
||||
// mMutex is the mutex used to prevent concurrent access to the member
|
||||
// variables of Surface objects. It must be locked whenever the
|
||||
// member variables are accessed.
|
||||
mutable Mutex mMutex;
|
||||
|
||||
// must be used from the lock/unlock thread
|
||||
sp<GraphicBuffer> mLockedBuffer;
|
||||
sp<GraphicBuffer> mPostedBuffer;
|
||||
bool mConnectedToCpu;
|
||||
|
||||
// must be accessed from lock/unlock thread only
|
||||
Region mDirtyRegion;
|
||||
};
|
||||
|
||||
}; // namespace android
|
||||
|
||||
#endif // ANDROID_GUI_SURFACE_H
|
0
widget/gonk/nativewindow/GonkNativeWindowJB.cpp
Executable file → Normal file
0
widget/gonk/nativewindow/GonkNativeWindowJB.cpp
Executable file → Normal file
0
widget/gonk/nativewindow/GonkNativeWindowJB.h
Executable file → Normal file
0
widget/gonk/nativewindow/GonkNativeWindowJB.h
Executable file → Normal file
113
widget/gonk/nativewindow/GonkNativeWindowLL.cpp
Normal file
113
widget/gonk/nativewindow/GonkNativeWindowLL.cpp
Normal file
@ -0,0 +1,113 @@
|
||||
/*
|
||||
* Copyright (C) 2012 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_NDEBUG 0
|
||||
#define LOG_TAG "BufferItemConsumer"
|
||||
#define ATRACE_TAG ATRACE_TAG_GRAPHICS
|
||||
#include <utils/Log.h>
|
||||
|
||||
#include <gui/BufferItemConsumer.h>
|
||||
|
||||
#define BI_LOGV(x, ...) ALOGV("[%s] "x, mName.string(), ##__VA_ARGS__)
|
||||
#define BI_LOGD(x, ...) ALOGD("[%s] "x, mName.string(), ##__VA_ARGS__)
|
||||
#define BI_LOGI(x, ...) ALOGI("[%s] "x, mName.string(), ##__VA_ARGS__)
|
||||
#define BI_LOGW(x, ...) ALOGW("[%s] "x, mName.string(), ##__VA_ARGS__)
|
||||
#define BI_LOGE(x, ...) ALOGE("[%s] "x, mName.string(), ##__VA_ARGS__)
|
||||
|
||||
namespace android {
|
||||
|
||||
BufferItemConsumer::BufferItemConsumer(
|
||||
const sp<IGraphicBufferConsumer>& consumer, uint32_t consumerUsage,
|
||||
int bufferCount, bool controlledByApp) :
|
||||
ConsumerBase(consumer, controlledByApp)
|
||||
{
|
||||
status_t err = mConsumer->setConsumerUsageBits(consumerUsage);
|
||||
LOG_ALWAYS_FATAL_IF(err != OK,
|
||||
"Failed to set consumer usage bits to %#x", consumerUsage);
|
||||
if (bufferCount != DEFAULT_MAX_BUFFERS) {
|
||||
err = mConsumer->setMaxAcquiredBufferCount(bufferCount);
|
||||
LOG_ALWAYS_FATAL_IF(err != OK,
|
||||
"Failed to set max acquired buffer count to %d", bufferCount);
|
||||
}
|
||||
}
|
||||
|
||||
BufferItemConsumer::~BufferItemConsumer() {
|
||||
}
|
||||
|
||||
void BufferItemConsumer::setName(const String8& name) {
|
||||
Mutex::Autolock _l(mMutex);
|
||||
mName = name;
|
||||
mConsumer->setConsumerName(name);
|
||||
}
|
||||
|
||||
status_t BufferItemConsumer::acquireBuffer(BufferItem *item,
|
||||
nsecs_t presentWhen, bool waitForFence) {
|
||||
status_t err;
|
||||
|
||||
if (!item) return BAD_VALUE;
|
||||
|
||||
Mutex::Autolock _l(mMutex);
|
||||
|
||||
err = acquireBufferLocked(item, presentWhen);
|
||||
if (err != OK) {
|
||||
if (err != NO_BUFFER_AVAILABLE) {
|
||||
BI_LOGE("Error acquiring buffer: %s (%d)", strerror(err), err);
|
||||
}
|
||||
return err;
|
||||
}
|
||||
|
||||
if (waitForFence) {
|
||||
err = item->mFence->waitForever("BufferItemConsumer::acquireBuffer");
|
||||
if (err != OK) {
|
||||
BI_LOGE("Failed to wait for fence of acquired buffer: %s (%d)",
|
||||
strerror(-err), err);
|
||||
return err;
|
||||
}
|
||||
}
|
||||
|
||||
item->mGraphicBuffer = mSlots[item->mBuf].mGraphicBuffer;
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
status_t BufferItemConsumer::releaseBuffer(const BufferItem &item,
|
||||
const sp<Fence>& releaseFence) {
|
||||
status_t err;
|
||||
|
||||
Mutex::Autolock _l(mMutex);
|
||||
|
||||
err = addReleaseFenceLocked(item.mBuf, item.mGraphicBuffer, releaseFence);
|
||||
|
||||
err = releaseBufferLocked(item.mBuf, item.mGraphicBuffer, EGL_NO_DISPLAY,
|
||||
EGL_NO_SYNC_KHR);
|
||||
if (err != OK) {
|
||||
BI_LOGE("Failed to release buffer: %s (%d)",
|
||||
strerror(-err), err);
|
||||
}
|
||||
return err;
|
||||
}
|
||||
|
||||
status_t BufferItemConsumer::setDefaultBufferSize(uint32_t w, uint32_t h) {
|
||||
Mutex::Autolock _l(mMutex);
|
||||
return mConsumer->setDefaultBufferSize(w, h);
|
||||
}
|
||||
|
||||
status_t BufferItemConsumer::setDefaultBufferFormat(uint32_t defaultFormat) {
|
||||
Mutex::Autolock _l(mMutex);
|
||||
return mConsumer->setDefaultBufferFormat(defaultFormat);
|
||||
}
|
||||
|
||||
} // namespace android
|
103
widget/gonk/nativewindow/GonkNativeWindowLL.h
Normal file
103
widget/gonk/nativewindow/GonkNativeWindowLL.h
Normal file
@ -0,0 +1,103 @@
|
||||
/*
|
||||
* Copyright (C) 2012 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.
|
||||
*/
|
||||
|
||||
#ifndef ANDROID_GUI_BUFFERITEMCONSUMER_H
|
||||
#define ANDROID_GUI_BUFFERITEMCONSUMER_H
|
||||
|
||||
#include <gui/ConsumerBase.h>
|
||||
|
||||
#include <ui/GraphicBuffer.h>
|
||||
|
||||
#include <utils/String8.h>
|
||||
#include <utils/Vector.h>
|
||||
#include <utils/threads.h>
|
||||
|
||||
#define ANDROID_GRAPHICS_BUFFERITEMCONSUMER_JNI_ID "mBufferItemConsumer"
|
||||
|
||||
namespace android {
|
||||
|
||||
class BufferQueue;
|
||||
|
||||
/**
|
||||
* BufferItemConsumer is a BufferQueue consumer endpoint that allows clients
|
||||
* access to the whole BufferItem entry from BufferQueue. Multiple buffers may
|
||||
* be acquired at once, to be used concurrently by the client. This consumer can
|
||||
* operate either in synchronous or asynchronous mode.
|
||||
*/
|
||||
class BufferItemConsumer: public ConsumerBase
|
||||
{
|
||||
public:
|
||||
typedef ConsumerBase::FrameAvailableListener FrameAvailableListener;
|
||||
|
||||
typedef BufferQueue::BufferItem BufferItem;
|
||||
|
||||
enum { DEFAULT_MAX_BUFFERS = -1 };
|
||||
enum { INVALID_BUFFER_SLOT = BufferQueue::INVALID_BUFFER_SLOT };
|
||||
enum { NO_BUFFER_AVAILABLE = BufferQueue::NO_BUFFER_AVAILABLE };
|
||||
|
||||
// Create a new buffer item consumer. The consumerUsage parameter determines
|
||||
// the consumer usage flags passed to the graphics allocator. The
|
||||
// bufferCount parameter specifies how many buffers can be locked for user
|
||||
// access at the same time.
|
||||
// controlledByApp tells whether this consumer is controlled by the
|
||||
// application.
|
||||
BufferItemConsumer(const sp<IGraphicBufferConsumer>& consumer,
|
||||
uint32_t consumerUsage, int bufferCount = DEFAULT_MAX_BUFFERS,
|
||||
bool controlledByApp = false);
|
||||
|
||||
virtual ~BufferItemConsumer();
|
||||
|
||||
// set the name of the BufferItemConsumer that will be used to identify it in
|
||||
// log messages.
|
||||
void setName(const String8& name);
|
||||
|
||||
// Gets the next graphics buffer from the producer, filling out the
|
||||
// passed-in BufferItem structure. Returns NO_BUFFER_AVAILABLE if the queue
|
||||
// of buffers is empty, and INVALID_OPERATION if the maximum number of
|
||||
// buffers is already acquired.
|
||||
//
|
||||
// Only a fixed number of buffers can be acquired at a time, determined by
|
||||
// the construction-time bufferCount parameter. If INVALID_OPERATION is
|
||||
// returned by acquireBuffer, then old buffers must be returned to the
|
||||
// queue by calling releaseBuffer before more buffers can be acquired.
|
||||
//
|
||||
// If waitForFence is true, and the acquired BufferItem has a valid fence object,
|
||||
// acquireBuffer will wait on the fence with no timeout before returning.
|
||||
status_t acquireBuffer(BufferItem *item, nsecs_t presentWhen,
|
||||
bool waitForFence = true);
|
||||
|
||||
// Returns an acquired buffer to the queue, allowing it to be reused. Since
|
||||
// only a fixed number of buffers may be acquired at a time, old buffers
|
||||
// must be released by calling releaseBuffer to ensure new buffers can be
|
||||
// acquired by acquireBuffer. Once a BufferItem is released, the caller must
|
||||
// not access any members of the BufferItem, and should immediately remove
|
||||
// all of its references to the BufferItem itself.
|
||||
status_t releaseBuffer(const BufferItem &item,
|
||||
const sp<Fence>& releaseFence = Fence::NO_FENCE);
|
||||
|
||||
// setDefaultBufferSize is used to set the size of buffers returned by
|
||||
// requestBuffers when a with and height of zero is requested.
|
||||
status_t setDefaultBufferSize(uint32_t w, uint32_t h);
|
||||
|
||||
// setDefaultBufferFormat allows the BufferQueue to create
|
||||
// GraphicBuffers of a defaultFormat if no format is specified
|
||||
// in dequeueBuffer
|
||||
status_t setDefaultBufferFormat(uint32_t defaultFormat);
|
||||
};
|
||||
|
||||
} // namespace android
|
||||
|
||||
#endif // ANDROID_GUI_CPUCONSUMER_H
|
18
widget/gonk/nativewindow/IGonkGraphicBufferConsumer.h
Normal file
18
widget/gonk/nativewindow/IGonkGraphicBufferConsumer.h
Normal file
@ -0,0 +1,18 @@
|
||||
/* Copyright 2013 Mozilla Foundation and Mozilla contributors
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#if defined(MOZ_WIDGET_GONK) && ANDROID_VERSION >= 19
|
||||
# include "IGonkGraphicBufferConsumerKK.h"
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user