Bug 922510 - Extend GonkNativeWindow to support android JB 4.2.2, r=sotaro,gps

This commit is contained in:
Peter Chang 2013-10-18 10:42:43 +08:00
parent 0e53b20b57
commit f2befa9556
16 changed files with 119 additions and 29 deletions

View File

@ -24,7 +24,7 @@ LIBS += \
$(DEPTH)/widget/gonk/libdisplay/$(LIB_PREFIX)display.$(LIB_SUFFIX) \
$(MOZ_ZLIB_LIBS) \
$(NULL)
ifeq (18,$(ANDROID_VERSION))
ifeq ($(ANDROID_VERSION),$(findstring $(ANDROID_VERSION),17 18))
LIBS += \
-lgui \
-lsuspend \

View File

@ -227,7 +227,7 @@ if test -n "$gonkdir" ; then
AC_SUBST(MOZ_OMX_DECODER)
MOZ_RTSP=1
;;
18)
17|18)
GONK_INCLUDES="-I$gonkdir/frameworks/native/include -I$gonkdir/frameworks/av/include -I$gonkdir/frameworks/av/include/media -I$gonkdir/frameworks/av/include/camera -I$gonkdir/frameworks/native/include/media/openmax -I$gonkdir/frameworks/av/media/libstagefright/include"
if test -d "$gonkdir/external/bluetooth/bluez"; then
GONK_INCLUDES+=" -I$gonkdir/external/dbus -I$gonkdir/external/bluetooth/bluez/lib"

View File

@ -467,7 +467,7 @@ bool OmxDecoder::AllocateMediaResources()
if ((mVideoTrack != nullptr) && (mVideoSource == nullptr)) {
mNativeWindow = new GonkNativeWindow();
#if defined(MOZ_WIDGET_GONK) && ANDROID_VERSION >= 18
#if defined(MOZ_WIDGET_GONK) && ANDROID_VERSION >= 17
mNativeWindowClient = new GonkNativeWindowClient(mNativeWindow->getBufferQueue());
#else
mNativeWindowClient = new GonkNativeWindowClient(mNativeWindow);

View File

@ -183,7 +183,7 @@ GonkCameraHardware::Init()
mNativeWindow = new GonkNativeWindow();
mNativeWindow->setNewFrameCallback(this);
mCamera->setListener(this);
#if defined(MOZ_WIDGET_GONK) && ANDROID_VERSION >= 18
#if defined(MOZ_WIDGET_GONK) && ANDROID_VERSION >= 17
mCamera->setPreviewTexture(mNativeWindow->getBufferQueue());
#else
mCamera->setPreviewTexture(mNativeWindow);

View File

@ -130,7 +130,7 @@ static int32_t getColorFormat(const char* colorFormat) {
if (!strcmp(colorFormat, "OMX_TI_COLOR_FormatYUV420PackedSemiPlanar")) {
return OMX_TI_COLOR_FormatYUV420PackedSemiPlanar;
}
#if defined(MOZ_WIDGET_GONK) && ANDROID_VERSION >= 18
#if defined(MOZ_WIDGET_GONK) && ANDROID_VERSION >= 17
if (!strcmp(colorFormat, CameraParameters::PIXEL_FORMAT_ANDROID_OPAQUE)) {
return OMX_COLOR_FormatAndroidOpaque;
}
@ -542,7 +542,7 @@ status_t GonkCameraSource::start(MetaData *meta) {
if (meta->findInt64(kKeyTime, &startTimeUs)) {
mStartTimeUs = startTimeUs;
}
#if defined(MOZ_WIDGET_GONK) && ANDROID_VERSION >= 18
#if defined(MOZ_WIDGET_GONK) && ANDROID_VERSION >= 17
int32_t nBuffers;
if (meta->findInt32(kKeyNumBuffers, &nBuffers)) {
CHECK_GT(nBuffers, 0);

View File

@ -480,10 +480,12 @@ status_t GonkBufferQueue::queueBuffer(int buf,
input.deflate(&timestamp, &crop, &scalingMode, &transform, &fence);
#if ANDROID_VERSION >= 18
if (fence == NULL) {
ST_LOGE("queueBuffer: fence is NULL");
return BAD_VALUE;
}
#endif
ST_LOGV("queueBuffer: slot=%d time=%#llx crop=[%d,%d,%d,%d] tr=%#x "
"scale=%s",
@ -583,7 +585,12 @@ status_t GonkBufferQueue::queueBuffer(int buf,
return NO_ERROR;
}
#if ANDROID_VERSION == 17
void GonkBufferQueue::cancelBuffer(int buf, sp<Fence> fence) {
#else
void GonkBufferQueue::cancelBuffer(int buf, const sp<Fence>& fence) {
#endif
ST_LOGV("cancelBuffer: slot=%d", buf);
Mutex::Autolock lock(mMutex);
@ -601,9 +608,11 @@ void GonkBufferQueue::cancelBuffer(int buf, const sp<Fence>& fence) {
ST_LOGE("cancelBuffer: slot %d is not owned by the client (state=%d)",
buf, mSlots[buf].mBufferState);
return;
#if ANDROID_VERSION >= 18
} else if (fence == NULL) {
ST_LOGE("cancelBuffer: fence is NULL");
return;
#endif
}
mSlots[buf].mBufferState = BufferSlot::FREE;
mSlots[buf].mFrameNumber = 0;
@ -872,7 +881,11 @@ status_t GonkBufferQueue::acquireBuffer(BufferItem *buffer) {
status_t GonkBufferQueue::releaseBuffer(int buf, const sp<Fence>& fence) {
Mutex::Autolock _l(mMutex);
#if ANDROID_VERSION == 17
if (buf == INVALID_BUFFER_SLOT) {
#else
if (buf == INVALID_BUFFER_SLOT || fence == NULL) {
#endif
return BAD_VALUE;
}

View File

@ -19,7 +19,11 @@
#define NATIVEWINDOW_GONKBUFFERQUEUE_H
#include <gui/IGraphicBufferAlloc.h>
#if ANDROID_VERSION == 17
#include <gui/ISurfaceTexture.h>
#else
#include <gui/IGraphicBufferProducer.h>
#endif
#include <ui/Fence.h>
#include <ui/GraphicBuffer.h>
@ -30,10 +34,18 @@
#include "mozilla/layers/LayersSurfaces.h"
#if ANDROID_VERSION == 17
#define IGraphicBufferProducer ISurfaceTexture
#endif
namespace android {
// ----------------------------------------------------------------------------
#if ANDROID_VERSION == 17
class GonkBufferQueue : public BnSurfaceTexture {
#else
class GonkBufferQueue : public BnGraphicBufferProducer {
#endif
typedef mozilla::layers::SurfaceDescriptor SurfaceDescriptor;
public:
@ -171,6 +183,13 @@ public:
//
// In both cases, the producer will need to call requestBuffer to get a
// GraphicBuffer handle for the returned slot.
#if ANDROID_VERSION == 17
virtual status_t dequeueBuffer(int *buf, sp<Fence>& fence,
uint32_t width, uint32_t height, uint32_t format, uint32_t usage) {
return dequeueBuffer(buf, &fence, width, height, format, usage);
}
#endif
virtual status_t dequeueBuffer(int *buf, sp<Fence>* fence,
uint32_t width, uint32_t height, uint32_t format, uint32_t usage);
@ -197,7 +216,11 @@ public:
//
// The buffer will not be overwritten until the fence signals. The fence
// will usually be the one obtained from dequeueBuffer.
#if ANDROID_VERSION == 17
virtual void cancelBuffer(int buf, sp<Fence> fence);
#else
virtual void cancelBuffer(int buf, const sp<Fence>& fence);
#endif
// setSynchronousMode sets whether dequeueBuffer is synchronous or
// asynchronous. In synchronous mode, dequeueBuffer blocks until

View File

@ -102,7 +102,11 @@ void GonkConsumerBase::onFrameAvailable() {
sp<FrameAvailableListener> listener;
{ // scope for the lock
Mutex::Autolock lock(mMutex);
#if ANDROID_VERSION == 17
listener = mFrameAvailableListener;
#else
listener = mFrameAvailableListener.promote();
#endif
}
if (listener != NULL) {
@ -151,7 +155,11 @@ void GonkConsumerBase::abandonLocked() {
}
void GonkConsumerBase::setFrameAvailableListener(
#if ANDROID_VERSION == 17
const sp<FrameAvailableListener>& listener) {
#else
const wp<FrameAvailableListener>& listener) {
#endif
CB_LOGV("setFrameAvailableListener");
Mutex::Autolock lock(mMutex);
mFrameAvailableListener = listener;

View File

@ -78,7 +78,11 @@ public:
// setFrameAvailableListener sets the listener object that will be notified
// when a new frame becomes available.
#if ANDROID_VERSION == 17
void setFrameAvailableListener(const sp<FrameAvailableListener>& listener);
#else
void setFrameAvailableListener(const wp<FrameAvailableListener>& listener);
#endif
private:
GonkConsumerBase(const GonkConsumerBase&);
@ -210,7 +214,11 @@ protected:
// mFrameAvailableListener is the listener object that will be called when a
// new frame becomes available. If it is not NULL it will be called from
// queueBuffer.
#if ANDROID_VERSION == 17
sp<FrameAvailableListener> mFrameAvailableListener;
#else
wp<FrameAvailableListener> mFrameAvailableListener;
#endif
// The GonkConsumerBase has-a GonkBufferQueue and is responsible for creating this object
// if none is supplied

View File

@ -13,7 +13,7 @@
* limitations under the License.
*/
#if defined(MOZ_WIDGET_GONK) && ANDROID_VERSION >= 18
#if defined(MOZ_WIDGET_GONK) && ANDROID_VERSION >= 17
# include "GonkNativeWindowJB.h"
#elif defined(MOZ_WIDGET_GONK) && ANDROID_VERSION == 15
# include "GonkNativeWindowICS.h"

View File

@ -13,7 +13,7 @@
* limitations under the License.
*/
#if defined(MOZ_WIDGET_GONK) && ANDROID_VERSION >= 18
#if defined(MOZ_WIDGET_GONK) && ANDROID_VERSION >= 17
# include "GonkNativeWindowClientJB.h"
#elif defined(MOZ_WIDGET_GONK) && ANDROID_VERSION == 15
# include "GonkNativeWindowClientICS.h"

View File

@ -20,7 +20,11 @@
//#define LOG_NDEBUG 0
#include <android/native_window.h>
#if ANDROID_VERSION == 17
#include <utils/Trace.h>
#else
#include <cutils/trace.h>
#endif
#include <binder/Parcel.h>
#include <utils/Log.h>
@ -32,7 +36,7 @@ namespace android {
GonkNativeWindowClient::GonkNativeWindowClient(
const sp<IGraphicBufferProducer>& bufferProducer)
: mGraphicBufferProducer(bufferProducer)
: mBufferProducer(bufferProducer)
{
// Initialize the ANativeWindow function pointers.
ANativeWindow::setSwapInterval = hook_setSwapInterval;
@ -73,8 +77,12 @@ GonkNativeWindowClient::~GonkNativeWindowClient() {
}
}
#if ANDROID_VERSION == 17
sp<IGraphicBufferProducer> GonkNativeWindowClient::getISurfaceTexture() const {
#else
sp<IGraphicBufferProducer> GonkNativeWindowClient::getIGraphicBufferProducer() const {
return mGraphicBufferProducer;
#endif
return mBufferProducer;
}
int GonkNativeWindowClient::hook_setSwapInterval(ANativeWindow* window, int interval) {
@ -107,7 +115,11 @@ int GonkNativeWindowClient::hook_dequeueBuffer_DEPRECATED(ANativeWindow* window,
int fenceFd = -1;
int result = c->dequeueBuffer(&buf, &fenceFd);
sp<Fence> fence(new Fence(fenceFd));
#if ANDROID_VERSION == 17
int waitResult = fence->waitForever(1000, "dequeueBuffer_DEPRECATED");
#else
int waitResult = fence->waitForever("dequeueBuffer_DEPRECATED");
#endif
if (waitResult != OK) {
ALOGE("dequeueBuffer_DEPRECATED: Fence::wait returned an error: %d",
waitResult);
@ -161,7 +173,7 @@ int GonkNativeWindowClient::setSwapInterval(int interval) {
if (interval > maxSwapInterval)
interval = maxSwapInterval;
status_t res = mGraphicBufferProducer->setSynchronousMode(interval ? true : false);
status_t res = mBufferProducer->setSynchronousMode(interval ? true : false);
return res;
}
@ -174,10 +186,16 @@ int GonkNativeWindowClient::dequeueBuffer(android_native_buffer_t** buffer,
int reqW = mReqWidth ? mReqWidth : mUserWidth;
int reqH = mReqHeight ? mReqHeight : mUserHeight;
sp<Fence> fence;
status_t result = mGraphicBufferProducer->dequeueBuffer(&buf, &fence,
#if ANDROID_VERSION == 17
status_t result = mBufferProducer->dequeueBuffer(&buf, fence,
reqW, reqH, mReqFormat, mReqUsage);
#else
status_t result = mBufferProducer->dequeueBuffer(&buf, &fence,
reqW, reqH, mReqFormat, mReqUsage);
#endif
if (result < 0) {
ALOGV("dequeueBuffer: IGraphicBufferProducer::dequeueBuffer(%d, %d, %d, %d)"
ALOGV("dequeueBuffer: dequeueBuffer(%d, %d, %d, %d)"
"failed: %d", mReqWidth, mReqHeight, mReqFormat, mReqUsage,
result);
return result;
@ -188,9 +206,10 @@ int GonkNativeWindowClient::dequeueBuffer(android_native_buffer_t** buffer,
}
if ((result & IGraphicBufferProducer::BUFFER_NEEDS_REALLOCATION) || gbuf == 0) {
result = mGraphicBufferProducer->requestBuffer(buf, &gbuf);
result = mBufferProducer->requestBuffer(buf, &gbuf);
if (result != NO_ERROR) {
ALOGE("dequeueBuffer: IGraphicBufferProducer::requestBuffer failed: %d",
ALOGE("dequeueBuffer: requestBuffer failed: %d",
result);
return result;
}
@ -221,7 +240,7 @@ int GonkNativeWindowClient::cancelBuffer(android_native_buffer_t* buffer,
return i;
}
sp<Fence> fence(fenceFd >= 0 ? new Fence(fenceFd) : Fence::NO_FENCE);
mGraphicBufferProducer->cancelBuffer(i, fence);
mBufferProducer->cancelBuffer(i, fence);
return OK;
}
@ -269,7 +288,7 @@ int GonkNativeWindowClient::queueBuffer(android_native_buffer_t* buffer, int fen
IGraphicBufferProducer::QueueBufferOutput output;
IGraphicBufferProducer::QueueBufferInput input(timestamp, crop, mScalingMode,
mTransform, fence);
status_t err = mGraphicBufferProducer->queueBuffer(i, input, &output);
status_t err = mBufferProducer->queueBuffer(i, input, &output);
if (err != OK) {
ALOGE("queueBuffer: error queuing buffer to SurfaceTexture, %d", err);
}
@ -296,7 +315,7 @@ int GonkNativeWindowClient::query(int what, int* value) const {
case NATIVE_WINDOW_QUEUES_TO_WINDOW_COMPOSER: {
//sp<ISurfaceComposer> composer(
// ComposerService::getComposerService());
//if (composer->authenticateSurfaceTexture(mGraphicBufferProducer)) {
//if (composer->authenticateSurfaceTexture(mBufferProducer)) {
// *value = 1;
//} else {
*value = 0;
@ -304,7 +323,11 @@ int GonkNativeWindowClient::query(int what, int* value) const {
return NO_ERROR;
}
case NATIVE_WINDOW_CONCRETE_TYPE:
#if ANDROID_VERSION == 17
*value = NATIVE_WINDOW_SURFACE_TEXTURE_CLIENT;
#else
*value = NATIVE_WINDOW_SURFACE;
#endif
return NO_ERROR;
case NATIVE_WINDOW_DEFAULT_WIDTH:
*value = mUserWidth ? mUserWidth : mDefaultWidth;
@ -320,7 +343,7 @@ int GonkNativeWindowClient::query(int what, int* value) const {
if (!mConsumerRunningBehind) {
*value = 0;
} else {
err = mGraphicBufferProducer->query(what, value);
err = mBufferProducer->query(what, value);
if (err == NO_ERROR) {
mConsumerRunningBehind = *value;
}
@ -329,7 +352,8 @@ int GonkNativeWindowClient::query(int what, int* value) const {
}
}
}
return mGraphicBufferProducer->query(what, value);
return mBufferProducer->query(what, value);
}
int GonkNativeWindowClient::perform(int operation, va_list args)
@ -474,7 +498,7 @@ int GonkNativeWindowClient::connect(int api) {
ALOGV("GonkNativeWindowClient::connect");
Mutex::Autolock lock(mMutex);
IGraphicBufferProducer::QueueBufferOutput output;
int err = mGraphicBufferProducer->connect(api, &output);
int err = mBufferProducer->connect(api, &output);
if (err == NO_ERROR) {
uint32_t numPendingBuffers = 0;
output.deflate(&mDefaultWidth, &mDefaultHeight, &mTransformHint,
@ -491,7 +515,8 @@ int GonkNativeWindowClient::disconnect(int api) {
ALOGV("GonkNativeWindowClient::disconnect");
Mutex::Autolock lock(mMutex);
freeAllBuffers();
int err = mGraphicBufferProducer->disconnect(api);
int err = mBufferProducer->disconnect(api);
if (!err) {
mReqFormat = 0;
mReqWidth = 0;
@ -537,7 +562,7 @@ int GonkNativeWindowClient::setBufferCount(int bufferCount)
ALOGV("GonkNativeWindowClient::setBufferCount");
Mutex::Autolock lock(mMutex);
status_t err = mGraphicBufferProducer->setBufferCount(bufferCount);
status_t err = mBufferProducer->setBufferCount(bufferCount);
ALOGE_IF(err, "IGraphicBufferProducer::setBufferCount(%d) returned %s",
bufferCount, strerror(-err));

View File

@ -18,7 +18,11 @@
#ifndef NATIVEWINDOW_GONKNATIVEWINDOWCLIENT_JB_H
#define NATIVEWINDOW_GONKNATIVEWINDOWCLIENT_JB_H
#if ANDROID_VERSION == 17
#include <gui/ISurfaceTexture.h>
#else
#include <gui/IGraphicBufferProducer.h>
#endif
#include <ui/ANativeObjectBase.h>
#include <ui/Region.h>
@ -69,13 +73,19 @@ public:
* GonkNativeWindowClient was created with. Usually it's an error to use the
* IGraphicBufferProducer while the GonkNativeWindowClient is connected.
*/
#if ANDROID_VERSION == 17
sp<IGraphicBufferProducer> getISurfaceTexture() const;
#else
sp<IGraphicBufferProducer> getIGraphicBufferProducer() const;
#endif
/* convenience function to check that the given surface is non NULL as
* well as its IGraphicBufferProducer */
#if ANDROID_VERSION >= 18
static bool isValid(const sp<GonkNativeWindowClient>& surface) {
return surface != NULL && surface->getIGraphicBufferProducer() != NULL;
}
#endif
protected:
virtual ~GonkNativeWindowClient();
@ -163,8 +173,7 @@ private:
// 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;
sp<IGraphicBufferProducer> mBufferProducer;
// 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

View File

@ -47,7 +47,7 @@ void GonkNativeWindow::setName(const String8& name) {
mName = name;
mBufferQueue->setConsumerName(name);
}
#if ANDROID_VERSION >= 18
status_t GonkNativeWindow::acquireBuffer(BufferItem *item, bool waitForFence) {
status_t err;
@ -92,6 +92,7 @@ status_t GonkNativeWindow::releaseBuffer(const BufferItem &item,
}
return err;
}
#endif
status_t GonkNativeWindow::setDefaultBufferSize(uint32_t w, uint32_t h) {
Mutex::Autolock _l(mMutex);

View File

@ -86,16 +86,19 @@ class GonkNativeWindow: public GonkConsumerBase
//
// If waitForFence is true, and the acquired BufferItem has a valid fence object,
// acquireBuffer will wait on the fence with no timeout before returning.
#if ANDROID_VERSION >= 18
status_t acquireBuffer(BufferItem *item, bool waitForFence = true);
#endif
// 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.
#if ANDROID_VERSION >= 18
status_t releaseBuffer(const BufferItem &item,
const sp<Fence>& releaseFence = Fence::NO_FENCE);
#endif
sp<IGraphicBufferProducer> getProducerInterface() const { return getBufferQueue(); }

View File

@ -21,7 +21,7 @@ EXPORTS += [
'GonkNativeWindowClient.h',
]
if CONFIG['ANDROID_VERSION'] == '18':
if CONFIG['ANDROID_VERSION'] in ('17', '18'):
EXPORTS += [
'GonkBufferQueue.h',
'GonkConsumerBase.h',
@ -35,7 +35,7 @@ elif CONFIG['ANDROID_VERSION'] == '15':
]
if CONFIG['MOZ_B2G_CAMERA'] or CONFIG['MOZ_OMX_DECODER']:
if CONFIG['ANDROID_VERSION'] == '18':
if CONFIG['ANDROID_VERSION'] in ('17', '18'):
CPP_SOURCES += [
'GonkBufferQueue.cpp',
'GonkConsumerBase.cpp',