From 082d84a8a04ce05db10655461ceeeec40618c78a Mon Sep 17 00:00:00 2001 From: Sotaro Ikeda Date: Sun, 31 Jan 2016 16:29:59 -0800 Subject: [PATCH] Bug 1239611 - Remove GonkNativeWindowClient r=nical --- dom/media/omx/OMXCodecWrapper.h | 1 - dom/media/omx/OmxDecoder.cpp | 1 - .../gonk/GonkVideoDecoderManager.cpp | 1 - .../platforms/gonk/GonkVideoDecoderManager.h | 1 - .../nativewindow/GonkNativeWindowClient.h | 24 - .../GonkNativeWindowClientICS.cpp | 446 ----------- .../nativewindow/GonkNativeWindowClientICS.h | 136 ---- .../nativewindow/GonkNativeWindowClientJB.cpp | 679 ---------------- .../nativewindow/GonkNativeWindowClientJB.h | 262 ------ .../nativewindow/GonkNativeWindowClientKK.cpp | 673 ---------------- .../nativewindow/GonkNativeWindowClientKK.h | 264 ------- .../nativewindow/GonkNativeWindowClientLL.cpp | 743 ------------------ .../nativewindow/GonkNativeWindowClientLL.h | 295 ------- widget/gonk/nativewindow/moz.build | 9 - 14 files changed, 3535 deletions(-) delete mode 100644 widget/gonk/nativewindow/GonkNativeWindowClient.h delete mode 100644 widget/gonk/nativewindow/GonkNativeWindowClientICS.cpp delete mode 100644 widget/gonk/nativewindow/GonkNativeWindowClientICS.h delete mode 100644 widget/gonk/nativewindow/GonkNativeWindowClientJB.cpp delete mode 100644 widget/gonk/nativewindow/GonkNativeWindowClientJB.h delete mode 100644 widget/gonk/nativewindow/GonkNativeWindowClientKK.cpp delete mode 100644 widget/gonk/nativewindow/GonkNativeWindowClientKK.h delete mode 100644 widget/gonk/nativewindow/GonkNativeWindowClientLL.cpp delete mode 100644 widget/gonk/nativewindow/GonkNativeWindowClientLL.h diff --git a/dom/media/omx/OMXCodecWrapper.h b/dom/media/omx/OMXCodecWrapper.h index 0c039bf6465..b17f4ad5eef 100644 --- a/dom/media/omx/OMXCodecWrapper.h +++ b/dom/media/omx/OMXCodecWrapper.h @@ -14,7 +14,6 @@ #include "AudioSegment.h" #include "GonkNativeWindow.h" -#include "GonkNativeWindowClient.h" #include "mozilla/media/MediaSystemResourceClient.h" #include "mozilla/RefPtr.h" diff --git a/dom/media/omx/OmxDecoder.cpp b/dom/media/omx/OmxDecoder.cpp index d277bbb76ac..fc2466c35e4 100644 --- a/dom/media/omx/OmxDecoder.cpp +++ b/dom/media/omx/OmxDecoder.cpp @@ -35,7 +35,6 @@ #include "mozilla/Logging.h" #include "GonkNativeWindow.h" -#include "GonkNativeWindowClient.h" #include "OMXCodecProxy.h" #include "OmxDecoder.h" diff --git a/dom/media/platforms/gonk/GonkVideoDecoderManager.cpp b/dom/media/platforms/gonk/GonkVideoDecoderManager.cpp index 8accc17c3e3..d94fe468cc3 100644 --- a/dom/media/platforms/gonk/GonkVideoDecoderManager.cpp +++ b/dom/media/platforms/gonk/GonkVideoDecoderManager.cpp @@ -20,7 +20,6 @@ #include #include #include "GonkNativeWindow.h" -#include "GonkNativeWindowClient.h" #include "mozilla/layers/GrallocTextureClient.h" #include "mozilla/layers/ImageBridgeChild.h" #include "mozilla/layers/TextureClient.h" diff --git a/dom/media/platforms/gonk/GonkVideoDecoderManager.h b/dom/media/platforms/gonk/GonkVideoDecoderManager.h index 91eb6e5d416..a2614c56f72 100644 --- a/dom/media/platforms/gonk/GonkVideoDecoderManager.h +++ b/dom/media/platforms/gonk/GonkVideoDecoderManager.h @@ -13,7 +13,6 @@ #include "I420ColorConverterHelper.h" #include "MediaCodecProxy.h" #include "GonkNativeWindow.h" -#include "GonkNativeWindowClient.h" #include "mozilla/layers/FenceUtils.h" #include "mozilla/UniquePtr.h" #include diff --git a/widget/gonk/nativewindow/GonkNativeWindowClient.h b/widget/gonk/nativewindow/GonkNativeWindowClient.h deleted file mode 100644 index 90ca0561dfa..00000000000 --- a/widget/gonk/nativewindow/GonkNativeWindowClient.h +++ /dev/null @@ -1,24 +0,0 @@ -/* 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 >= 21 -# include "GonkNativeWindowClientLL.h" -#elif defined(MOZ_WIDGET_GONK) && ANDROID_VERSION >= 19 -# include "GonkNativeWindowClientKK.h" -#elif defined(MOZ_WIDGET_GONK) && ANDROID_VERSION >= 17 -# include "GonkNativeWindowClientJB.h" -#elif defined(MOZ_WIDGET_GONK) && ANDROID_VERSION == 15 -# include "GonkNativeWindowClientICS.h" -#endif diff --git a/widget/gonk/nativewindow/GonkNativeWindowClientICS.cpp b/widget/gonk/nativewindow/GonkNativeWindowClientICS.cpp deleted file mode 100644 index 63fc075e660..00000000000 --- a/widget/gonk/nativewindow/GonkNativeWindowClientICS.cpp +++ /dev/null @@ -1,446 +0,0 @@ -/* - * Copyright (C) 2010 The Android Open Source Project - * Copyright (C) 2012 Mozilla Foundation - * - * 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. - */ - -#include "base/basictypes.h" - -#include "CameraCommon.h" -#include "GonkNativeWindow.h" -#include "GonkNativeWindowClient.h" -#include "nsDebug.h" - -/** - * DOM_CAMERA_LOGI() is enabled in debug builds, and turned on by setting - * NSPR_LOG_MODULES=Camera:N environment variable, where N >= 3. - * - * CNW_LOGE() is always enabled. - */ -#define CNW_LOGD(...) DOM_CAMERA_LOGI(__VA_ARGS__) -#define CNW_LOGE(...) {(void)printf_stderr(__VA_ARGS__);} - -using namespace android; -using namespace mozilla::layers; - -GonkNativeWindowClient::GonkNativeWindowClient(const sp& window) - : mNativeWindow(window) { - GonkNativeWindowClient::init(); -} - -GonkNativeWindowClient::~GonkNativeWindowClient() { - if (mConnectedToCpu) { - GonkNativeWindowClient::disconnect(NATIVE_WINDOW_API_CPU); - } -} - -void GonkNativeWindowClient::init() { - // Initialize the ANativeWindow function pointers. - ANativeWindow::setSwapInterval = hook_setSwapInterval; - ANativeWindow::dequeueBuffer = hook_dequeueBuffer; - ANativeWindow::cancelBuffer = hook_cancelBuffer; - ANativeWindow::lockBuffer = hook_lockBuffer; - ANativeWindow::queueBuffer = hook_queueBuffer; - ANativeWindow::query = hook_query; - ANativeWindow::perform = hook_perform; - - mReqWidth = 0; - mReqHeight = 0; - mReqFormat = 0; - mReqUsage = 0; - mTimestamp = NATIVE_WINDOW_TIMESTAMP_AUTO; - mDefaultWidth = 0; - mDefaultHeight = 0; - mTransformHint = 0; - mConnectedToCpu = false; -} - - -int GonkNativeWindowClient::hook_setSwapInterval(ANativeWindow* window, int interval) { - GonkNativeWindowClient* c = getSelf(window); - return c->setSwapInterval(interval); -} - -int GonkNativeWindowClient::hook_dequeueBuffer(ANativeWindow* window, - ANativeWindowBuffer** buffer) { - GonkNativeWindowClient* c = getSelf(window); - return c->dequeueBuffer(buffer); -} - -int GonkNativeWindowClient::hook_cancelBuffer(ANativeWindow* window, - ANativeWindowBuffer* buffer) { - GonkNativeWindowClient* c = getSelf(window); - return c->cancelBuffer(buffer); -} - -int GonkNativeWindowClient::hook_lockBuffer(ANativeWindow* window, - ANativeWindowBuffer* buffer) { - GonkNativeWindowClient* c = getSelf(window); - return c->lockBuffer(buffer); -} - -int GonkNativeWindowClient::hook_queueBuffer(ANativeWindow* window, - ANativeWindowBuffer* buffer) { - GonkNativeWindowClient* c = getSelf(window); - return c->queueBuffer(buffer); -} - -int GonkNativeWindowClient::hook_query(const ANativeWindow* window, - int what, int* value) { - const GonkNativeWindowClient* c = getSelf(window); - return c->query(what, value); -} - -int GonkNativeWindowClient::hook_perform(ANativeWindow* window, int operation, ...) { - va_list args; - va_start(args, operation); - GonkNativeWindowClient* c = getSelf(window); - return c->perform(operation, args); -} - -int GonkNativeWindowClient::setSwapInterval(int interval) { - return NO_ERROR; -} - -int GonkNativeWindowClient::dequeueBuffer(android_native_buffer_t** buffer) { - CNW_LOGD("GonkNativeWindowClient::dequeueBuffer"); - Mutex::Autolock lock(mMutex); - int buf = -1; - status_t result = mNativeWindow->dequeueBuffer(&buf, mReqWidth, mReqHeight, - mReqFormat, mReqUsage); - if (result < 0) { - CNW_LOGD("dequeueBuffer: ISurfaceTexture::dequeueBuffer(%d, %d, %d, %d)" - "failed: %d", mReqWidth, mReqHeight, mReqFormat, mReqUsage, - result); - return result; - } - sp& gbuf(mSlots[buf]); - if (result & ISurfaceTexture::RELEASE_ALL_BUFFERS) { - freeAllBuffers(); - } - - if ((result & ISurfaceTexture::BUFFER_NEEDS_REALLOCATION) || gbuf == 0) { - result = mNativeWindow->requestBuffer(buf, &gbuf); - if (result != NO_ERROR) { - CNW_LOGE("dequeueBuffer: ISurfaceTexture::requestBuffer failed: %d", - result); - return result; - } - } - *buffer = gbuf.get(); - return OK; -} - -int GonkNativeWindowClient::cancelBuffer(ANativeWindowBuffer* buffer) { - CNW_LOGD("GonkNativeWindowClient::cancelBuffer"); - Mutex::Autolock lock(mMutex); - int i = getSlotFromBufferLocked(buffer); - if (i < 0) { - return i; - } - mNativeWindow->cancelBuffer(i); - return OK; -} - -int GonkNativeWindowClient::getSlotFromBufferLocked( - android_native_buffer_t* buffer) const { - bool dumpedState = false; - for (int i = 0; i < NUM_BUFFER_SLOTS; i++) { - // XXX: Dump the slots whenever we hit a NULL entry while searching for - // a buffer. - if (mSlots[i] == NULL) { - if (!dumpedState) { - CNW_LOGD("getSlotFromBufferLocked: encountered NULL buffer in slot %d " - "looking for buffer %p", i, buffer->handle); - for (int j = 0; j < NUM_BUFFER_SLOTS; j++) { - if (mSlots[j] == NULL) { - CNW_LOGD("getSlotFromBufferLocked: %02d: NULL", j); - } else { - CNW_LOGD("getSlotFromBufferLocked: %02d: %p", j, mSlots[j]->handle); - } - } - dumpedState = true; - } - } - - if (mSlots[i] != NULL && mSlots[i]->handle == buffer->handle) { - return i; - } - } - CNW_LOGE("getSlotFromBufferLocked: unknown buffer: %p", buffer->handle); - return BAD_VALUE; -} - - -int GonkNativeWindowClient::lockBuffer(android_native_buffer_t* buffer) { - CNW_LOGD("GonkNativeWindowClient::lockBuffer"); - Mutex::Autolock lock(mMutex); - return OK; -} - -int GonkNativeWindowClient::queueBuffer(android_native_buffer_t* buffer) { - CNW_LOGD("GonkNativeWindowClient::queueBuffer"); - Mutex::Autolock lock(mMutex); - int64_t timestamp; - if (mTimestamp == NATIVE_WINDOW_TIMESTAMP_AUTO) { - timestamp = systemTime(SYSTEM_TIME_MONOTONIC); - CNW_LOGD("GonkNativeWindowClient::queueBuffer making up timestamp: %.2f ms", - timestamp / 1000000.f); - } else { - timestamp = mTimestamp; - } - int i = getSlotFromBufferLocked(buffer); - if (i < 0) { - return i; - } - status_t err = mNativeWindow->queueBuffer(i, timestamp, - &mDefaultWidth, &mDefaultHeight, &mTransformHint); - if (err != OK) { - CNW_LOGE("queueBuffer: error queuing buffer to GonkNativeWindow, %d", err); - } - return err; -} - -int GonkNativeWindowClient::query(int what, int* value) const { - CNW_LOGD("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: - *value = 0; - return NO_ERROR; - case NATIVE_WINDOW_CONCRETE_TYPE: - *value = NATIVE_WINDOW_SURFACE_TEXTURE_CLIENT; - return NO_ERROR; - case NATIVE_WINDOW_DEFAULT_WIDTH: - *value = mDefaultWidth; - return NO_ERROR; - case NATIVE_WINDOW_DEFAULT_HEIGHT: - *value = mDefaultHeight; - return NO_ERROR; - case NATIVE_WINDOW_TRANSFORM_HINT: - *value = mTransformHint; - return NO_ERROR; - } - } - return mNativeWindow->query(what, value); -} - -int GonkNativeWindowClient::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_SCALING_MODE: - return NO_ERROR; - case NATIVE_WINDOW_SET_USAGE: - res = dispatchSetUsage(args); - break; - case NATIVE_WINDOW_SET_CROP: - //not implemented - 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: - //not implemented - 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_FORMAT: - res = dispatchSetBuffersFormat(args); - break; - case NATIVE_WINDOW_LOCK: - res = INVALID_OPERATION;// not supported - break; - case NATIVE_WINDOW_UNLOCK_AND_POST: - res = INVALID_OPERATION;// not supported - break; - case NATIVE_WINDOW_API_CONNECT: - res = dispatchConnect(args); - break; - case NATIVE_WINDOW_API_DISCONNECT: - res = dispatchDisconnect(args); - break; - case NATIVE_WINDOW_SET_BUFFERS_SIZE: - //not implemented - break; - default: - res = NAME_NOT_FOUND; - break; - } - return res; -} - -int GonkNativeWindowClient::dispatchConnect(va_list args) { - int api = va_arg(args, int); - return connect(api); -} - -int GonkNativeWindowClient::dispatchDisconnect(va_list args) { - int api = va_arg(args, int); - return disconnect(api); -} - -int GonkNativeWindowClient::dispatchSetUsage(va_list args) { - int usage = va_arg(args, int); - return setUsage(usage); -} - -int GonkNativeWindowClient::dispatchSetBufferCount(va_list args) { - size_t bufferCount = va_arg(args, size_t); - return setBufferCount(bufferCount); -} - -int GonkNativeWindowClient::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 GonkNativeWindowClient::dispatchSetBuffersDimensions(va_list args) { - int w = va_arg(args, int); - int h = va_arg(args, int); - return setBuffersDimensions(w, h); -} - -int GonkNativeWindowClient::dispatchSetBuffersFormat(va_list args) { - int f = va_arg(args, int); - return setBuffersFormat(f); -} - -int GonkNativeWindowClient::dispatchSetBuffersTimestamp(va_list args) { - int64_t timestamp = va_arg(args, int64_t); - return setBuffersTimestamp(timestamp); -} - -int GonkNativeWindowClient::connect(int api) { - CNW_LOGD("GonkNativeWindowClient::connect"); - Mutex::Autolock lock(mMutex); - int err = mNativeWindow->connect(api, - &mDefaultWidth, &mDefaultHeight, &mTransformHint); - if (!err && api == NATIVE_WINDOW_API_CPU) { - mConnectedToCpu = true; - } - return err; -} - -int GonkNativeWindowClient::disconnect(int api) { - CNW_LOGD("GonkNativeWindowClient::disconnect"); - Mutex::Autolock lock(mMutex); - freeAllBuffers(); - int err = mNativeWindow->disconnect(api); - if (!err) { - mReqFormat = 0; - mReqWidth = 0; - mReqHeight = 0; - mReqUsage = 0; - if (api == NATIVE_WINDOW_API_CPU) { - mConnectedToCpu = false; - } - } - return err; -} - -int GonkNativeWindowClient::setUsage(uint32_t reqUsage) -{ - CNW_LOGD("GonkNativeWindowClient::setUsage"); - Mutex::Autolock lock(mMutex); - mReqUsage = reqUsage; - return OK; -} - -int GonkNativeWindowClient::setBufferCount(int bufferCount) -{ - CNW_LOGD("GonkNativeWindowClient::setBufferCount"); - Mutex::Autolock lock(mMutex); - - status_t err = mNativeWindow->setBufferCount(bufferCount); - if (err == NO_ERROR) { - freeAllBuffers(); - } - - return err; -} - -int GonkNativeWindowClient::setBuffersDimensions(int w, int h) -{ - CNW_LOGD("GonkNativeWindowClient::setBuffersDimensions"); - Mutex::Autolock lock(mMutex); - - if (w<0 || h<0) - return BAD_VALUE; - - if ((w && !h) || (!w && h)) - return BAD_VALUE; - - mReqWidth = w; - mReqHeight = h; - - status_t err = OK; - - return err; -} - -int GonkNativeWindowClient::setBuffersFormat(int format) -{ - CNW_LOGD("GonkNativeWindowClient::setBuffersFormat"); - Mutex::Autolock lock(mMutex); - - if (format<0) - return BAD_VALUE; - - mReqFormat = format; - - return NO_ERROR; -} - - -int GonkNativeWindowClient::setBuffersTimestamp(int64_t timestamp) -{ - CNW_LOGD("GonkNativeWindowClient::setBuffersTimestamp"); - Mutex::Autolock lock(mMutex); - mTimestamp = timestamp; - return NO_ERROR; -} - -void GonkNativeWindowClient::freeAllBuffers() { - for (int i = 0; i < NUM_BUFFER_SLOTS; i++) { - mSlots[i] = 0; - } -} - diff --git a/widget/gonk/nativewindow/GonkNativeWindowClientICS.h b/widget/gonk/nativewindow/GonkNativeWindowClientICS.h deleted file mode 100644 index bd5720000d9..00000000000 --- a/widget/gonk/nativewindow/GonkNativeWindowClientICS.h +++ /dev/null @@ -1,136 +0,0 @@ -/* - * Copyright (C) 2010 The Android Open Source Project - * Copyright (C) 2012 Mozilla Foundation - * - * 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 NATIVEWINDOW_GONKNATIVEWINDOWCLIENT_ICS_H -#define NATIVEWINDOW_GONKNATIVEWINDOWCLIENT_ICS_H - -#include - -#include "GonkNativeWindow.h" - -namespace android { - -class GonkNativeWindowClient : public EGLNativeBase -{ -public: - GonkNativeWindowClient(const sp& window); - ~GonkNativeWindowClient(); // this class cannot be overloaded - -private: - void init(); - - // ANativeWindow hooks - static int hook_cancelBuffer(ANativeWindow* window, ANativeWindowBuffer* buffer); - static int hook_dequeueBuffer(ANativeWindow* window, ANativeWindowBuffer** buffer); - static int hook_lockBuffer(ANativeWindow* window, ANativeWindowBuffer* buffer); - 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); - static int hook_setSwapInterval(ANativeWindow* window, int interval); - - 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 dispatchSetBuffersFormat(va_list args); - int dispatchSetBuffersTimestamp(va_list args); - int dispatchSetUsage(va_list args); - -protected: - virtual int cancelBuffer(ANativeWindowBuffer* buffer); - virtual int dequeueBuffer(ANativeWindowBuffer** buffer); - virtual int lockBuffer(ANativeWindowBuffer* buffer); - virtual int perform(int operation, va_list args); - virtual int query(int what, int* value) const; - virtual int queueBuffer(ANativeWindowBuffer* buffer); - virtual int setSwapInterval(int interval); - - virtual int connect(int api); - virtual int disconnect(int api); - virtual int setBufferCount(int bufferCount); - virtual int setBuffersDimensions(int w, int h); - virtual int setBuffersFormat(int format); - virtual int setBuffersTimestamp(int64_t timestamp); - virtual int setUsage(uint32_t reqUsage); - - int getNumberOfArgsForOperation(int operation); - - enum { MIN_UNDEQUEUED_BUFFERS = GonkNativeWindow::MIN_UNDEQUEUED_BUFFERS }; - enum { NUM_BUFFER_SLOTS = GonkNativeWindow::NUM_BUFFER_SLOTS }; - enum { DEFAULT_FORMAT = PIXEL_FORMAT_RGBA_8888 }; - enum { NATIVE_WINDOW_SET_BUFFERS_SIZE = 0x10000000 }; - -private: - void freeAllBuffers(); - int getSlotFromBufferLocked(android_native_buffer_t* buffer) const; - - sp mNativeWindow; - - // 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 - // ISurfaceTexture::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. - sp 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 deuque - // 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; - - // mDefaultWidth is default width of the window, regardless of the - // native_window_set_buffers_dimensions call - uint32_t mDefaultWidth; - - // mDefaultHeight is default width of the window, regardless of the - // native_window_set_buffers_dimensions call - uint32_t mDefaultHeight; - - // mTransformHint is the transform probably applied to buffers of this - // window. this is only a hint, actual transform may differ. - uint32_t mTransformHint; - - // mMutex is the mutex used to prevent concurrent access to the member - // variables of GonkNativeWindow objects. It must be locked whenever the - // member variables are accessed. - mutable Mutex mMutex; - - bool mConnectedToCpu; -}; - - -}; // namespace android - -#endif // NATIVEWINDOW_GONKNATIVEWINDOWCLIENT_ICS_H diff --git a/widget/gonk/nativewindow/GonkNativeWindowClientJB.cpp b/widget/gonk/nativewindow/GonkNativeWindowClientJB.cpp deleted file mode 100644 index 7345bb49ac4..00000000000 --- a/widget/gonk/nativewindow/GonkNativeWindowClientJB.cpp +++ /dev/null @@ -1,679 +0,0 @@ -/* - * Copyright (C) 2010 The Android Open Source Project - * Copyright (C) 2013 Mozilla Foundation - * - * 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 "GonkNativeWindowClient" -#define ATRACE_TAG ATRACE_TAG_GRAPHICS -//#define LOG_NDEBUG 0 - -#include -#if ANDROID_VERSION == 17 -#include -#else -#include -#endif - -#include -#include -#include - -#include "GonkNativeWindowClientJB.h" - -namespace android { - -GonkNativeWindowClient::GonkNativeWindowClient( - const sp& bufferProducer) - : mBufferProducer(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(ANativeWindow::minSwapInterval) = 0; - const_cast(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; - mDefaultWidth = 0; - mDefaultHeight = 0; - mUserWidth = 0; - mUserHeight = 0; - mTransformHint = 0; - mConsumerRunningBehind = false; - mConnectedToCpu = false; -} - -GonkNativeWindowClient::~GonkNativeWindowClient() { - if (mConnectedToCpu) { - GonkNativeWindowClient::disconnect(NATIVE_WINDOW_API_CPU); - } -} - -#if ANDROID_VERSION == 17 -sp GonkNativeWindowClient::getISurfaceTexture() const { -#else -sp GonkNativeWindowClient::getIGraphicBufferProducer() const { -#endif - return mBufferProducer; -} - -int GonkNativeWindowClient::hook_setSwapInterval(ANativeWindow* window, int interval) { - GonkNativeWindowClient* c = getSelf(window); - return c->setSwapInterval(interval); -} - -int GonkNativeWindowClient::hook_dequeueBuffer(ANativeWindow* window, - ANativeWindowBuffer** buffer, int* fenceFd) { - GonkNativeWindowClient* c = getSelf(window); - return c->dequeueBuffer(buffer, fenceFd); -} - -int GonkNativeWindowClient::hook_cancelBuffer(ANativeWindow* window, - ANativeWindowBuffer* buffer, int fenceFd) { - GonkNativeWindowClient* c = getSelf(window); - return c->cancelBuffer(buffer, fenceFd); -} - -int GonkNativeWindowClient::hook_queueBuffer(ANativeWindow* window, - ANativeWindowBuffer* buffer, int fenceFd) { - GonkNativeWindowClient* c = getSelf(window); - return c->queueBuffer(buffer, fenceFd); -} - -int GonkNativeWindowClient::hook_dequeueBuffer_DEPRECATED(ANativeWindow* window, - ANativeWindowBuffer** buffer) { - GonkNativeWindowClient* c = getSelf(window); - ANativeWindowBuffer* buf; - int fenceFd = -1; - int result = c->dequeueBuffer(&buf, &fenceFd); - sp 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); - c->cancelBuffer(buf, -1); - return waitResult; - } - *buffer = buf; - return result; -} - -int GonkNativeWindowClient::hook_cancelBuffer_DEPRECATED(ANativeWindow* window, - ANativeWindowBuffer* buffer) { - GonkNativeWindowClient* c = getSelf(window); - return c->cancelBuffer(buffer, -1); -} - -int GonkNativeWindowClient::hook_lockBuffer_DEPRECATED(ANativeWindow* window, - ANativeWindowBuffer* buffer) { - GonkNativeWindowClient* c = getSelf(window); - return c->lockBuffer_DEPRECATED(buffer); -} - -int GonkNativeWindowClient::hook_queueBuffer_DEPRECATED(ANativeWindow* window, - ANativeWindowBuffer* buffer) { - GonkNativeWindowClient* c = getSelf(window); - return c->queueBuffer(buffer, -1); -} - -int GonkNativeWindowClient::hook_query(const ANativeWindow* window, - int what, int* value) { - const GonkNativeWindowClient* c = getSelf(window); - return c->query(what, value); -} - -int GonkNativeWindowClient::hook_perform(ANativeWindow* window, int operation, ...) { - va_list args; - va_start(args, operation); - GonkNativeWindowClient* c = getSelf(window); - return c->perform(operation, args); -} - -int GonkNativeWindowClient::setSwapInterval(int interval) { - // 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 = mBufferProducer->setSynchronousMode(interval ? true : false); - - return res; -} - -int GonkNativeWindowClient::dequeueBuffer(android_native_buffer_t** buffer, - int* fenceFd) { - ALOGV("GonkNativeWindowClient::dequeueBuffer"); - Mutex::Autolock lock(mMutex); - int buf = -1; - int reqW = mReqWidth ? mReqWidth : mUserWidth; - int reqH = mReqHeight ? mReqHeight : mUserHeight; - sp 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: dequeueBuffer(%d, %d, %d, %d)" - "failed: %d", mReqWidth, mReqHeight, mReqFormat, mReqUsage, - result); - return result; - } - sp& gbuf(mSlots[buf].buffer); - if (result & IGraphicBufferProducer::RELEASE_ALL_BUFFERS) { - freeAllBuffers(); - } - - if ((result & IGraphicBufferProducer::BUFFER_NEEDS_REALLOCATION) || gbuf == 0) { - result = mBufferProducer->requestBuffer(buf, &gbuf); - - if (result != NO_ERROR) { - ALOGE("dequeueBuffer: requestBuffer failed: %d", - result); - return result; - } - } - - if (fence.get() && 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 GonkNativeWindowClient::cancelBuffer(android_native_buffer_t* buffer, - int fenceFd) { - ALOGV("GonkNativeWindowClient::cancelBuffer"); - Mutex::Autolock lock(mMutex); - int i = getSlotFromBufferLocked(buffer); - if (i < 0) { - return i; - } - sp fence(fenceFd >= 0 ? new Fence(fenceFd) : Fence::NO_FENCE); - mBufferProducer->cancelBuffer(i, fence); - return OK; -} - -int GonkNativeWindowClient::getSlotFromBufferLocked( - android_native_buffer_t* buffer) const { - 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 GonkNativeWindowClient::lockBuffer_DEPRECATED(android_native_buffer_t* buffer) { - ALOGV("GonkNativeWindowClient::lockBuffer"); - Mutex::Autolock lock(mMutex); - return OK; -} - -int GonkNativeWindowClient::queueBuffer(android_native_buffer_t* buffer, int fenceFd) { - ALOGV("GonkNativeWindowClient::queueBuffer"); - Mutex::Autolock lock(mMutex); - int64_t timestamp; - if (mTimestamp == NATIVE_WINDOW_TIMESTAMP_AUTO) { - timestamp = systemTime(SYSTEM_TIME_MONOTONIC); - ALOGV("GonkNativeWindowClient::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(fenceFd >= 0 ? new Fence(fenceFd) : Fence::NO_FENCE); - IGraphicBufferProducer::QueueBufferOutput output; - - IGraphicBufferProducer::QueueBufferInput input(timestamp, crop, mScalingMode, - mTransform, fence); - status_t err = mBufferProducer->queueBuffer(i, input, &output); - if (err != OK) { - ALOGE("queueBuffer: error queuing buffer to SurfaceTexture, %d", err); - } - uint32_t numPendingBuffers = 0; - output.deflate(&mDefaultWidth, &mDefaultHeight, &mTransformHint, - &numPendingBuffers); - - mConsumerRunningBehind = (numPendingBuffers >= 2); - - return err; -} - -int GonkNativeWindowClient::query(int what, int* value) const { - ALOGV("GonkNativeWindowClient::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 composer( - // ComposerService::getComposerService()); - //if (composer->authenticateSurfaceTexture(mBufferProducer)) { - // *value = 1; - //} else { - *value = 0; - //} - 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; - 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 = mBufferProducer->query(what, value); - if (err == NO_ERROR) { - mConsumerRunningBehind = *value; - } - } - return err; - } - } - } - - return mBufferProducer->query(what, value); -} - -int GonkNativeWindowClient::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_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; - default: - res = NAME_NOT_FOUND; - break; - } - return res; -} - -int GonkNativeWindowClient::dispatchConnect(va_list args) { - int api = va_arg(args, int); - return connect(api); -} - -int GonkNativeWindowClient::dispatchDisconnect(va_list args) { - int api = va_arg(args, int); - return disconnect(api); -} - -int GonkNativeWindowClient::dispatchSetUsage(va_list args) { - int usage = va_arg(args, int); - return setUsage(usage); -} - -int GonkNativeWindowClient::dispatchSetCrop(va_list args) { - android_native_rect_t const* rect = va_arg(args, android_native_rect_t*); - return setCrop(reinterpret_cast(rect)); -} - -int GonkNativeWindowClient::dispatchSetBufferCount(va_list args) { - size_t bufferCount = va_arg(args, size_t); - return setBufferCount(bufferCount); -} - -int GonkNativeWindowClient::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 GonkNativeWindowClient::dispatchSetBuffersDimensions(va_list args) { - int w = va_arg(args, int); - int h = va_arg(args, int); - return setBuffersDimensions(w, h); -} - -int GonkNativeWindowClient::dispatchSetBuffersUserDimensions(va_list args) { - int w = va_arg(args, int); - int h = va_arg(args, int); - return setBuffersUserDimensions(w, h); -} - -int GonkNativeWindowClient::dispatchSetBuffersFormat(va_list args) { - int f = va_arg(args, int); - return setBuffersFormat(f); -} - -int GonkNativeWindowClient::dispatchSetScalingMode(va_list args) { - int m = va_arg(args, int); - return setScalingMode(m); -} - -int GonkNativeWindowClient::dispatchSetBuffersTransform(va_list args) { - int transform = va_arg(args, int); - return setBuffersTransform(transform); -} - -int GonkNativeWindowClient::dispatchSetBuffersTimestamp(va_list args) { - int64_t timestamp = va_arg(args, int64_t); - return setBuffersTimestamp(timestamp); -} - -int GonkNativeWindowClient::dispatchLock(va_list args) { - ANativeWindow_Buffer* outBuffer = va_arg(args, ANativeWindow_Buffer*); - ARect* inOutDirtyBounds = va_arg(args, ARect*); - return lock(outBuffer, inOutDirtyBounds); -} - -int GonkNativeWindowClient::dispatchUnlockAndPost(va_list args) { - return unlockAndPost(); -} - - -int GonkNativeWindowClient::connect(int api) { - ALOGV("GonkNativeWindowClient::connect"); - - Mutex::Autolock lock(mMutex); - IGraphicBufferProducer::QueueBufferOutput output; - - int err = mBufferProducer->connect(api, &output); - if (err == NO_ERROR) { - uint32_t numPendingBuffers = 0; - output.deflate(&mDefaultWidth, &mDefaultHeight, &mTransformHint, - &numPendingBuffers); - mConsumerRunningBehind = (numPendingBuffers >= 2); - } - if (!err && api == NATIVE_WINDOW_API_CPU) { - mConnectedToCpu = true; - } - return err; -} - -int GonkNativeWindowClient::disconnect(int api) { - ALOGV("GonkNativeWindowClient::disconnect"); - Mutex::Autolock lock(mMutex); - freeAllBuffers(); - int err = mBufferProducer->disconnect(api); - - if (!err) { - mReqFormat = 0; - mReqWidth = 0; - mReqHeight = 0; - mReqUsage = 0; - mCrop.clear(); - mScalingMode = NATIVE_WINDOW_SCALING_MODE_FREEZE; - mTransform = 0; - if (api == NATIVE_WINDOW_API_CPU) { - mConnectedToCpu = false; - } - } - return err; -} - -int GonkNativeWindowClient::setUsage(uint32_t reqUsage) -{ - ALOGV("GonkNativeWindowClient::setUsage"); - Mutex::Autolock lock(mMutex); - mReqUsage = reqUsage; - return OK; -} - -int GonkNativeWindowClient::setCrop(Rect const* rect) -{ - Rect realRect; - if (rect == NULL || rect->isEmpty()) { - realRect.clear(); - } else { - realRect = *rect; - } - - ALOGV("GonkNativeWindowClient::setCrop rect=[%d %d %d %d]", - realRect.left, realRect.top, realRect.right, realRect.bottom); - - Mutex::Autolock lock(mMutex); - mCrop = realRect; - return NO_ERROR; -} - -int GonkNativeWindowClient::setBufferCount(int bufferCount) -{ - ALOGV("GonkNativeWindowClient::setBufferCount"); - Mutex::Autolock lock(mMutex); - - status_t err = mBufferProducer->setBufferCount(bufferCount); - ALOGE_IF(err, "IGraphicBufferProducer::setBufferCount(%d) returned %s", - bufferCount, strerror(-err)); - - if (err == NO_ERROR) { - freeAllBuffers(); - } - - return err; -} - -int GonkNativeWindowClient::setBuffersDimensions(int w, int h) -{ - ALOGV("GonkNativeWindowClient::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 GonkNativeWindowClient::setBuffersUserDimensions(int w, int h) -{ - ALOGV("GonkNativeWindowClient::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 GonkNativeWindowClient::setBuffersFormat(int format) -{ - ALOGV("GonkNativeWindowClient::setBuffersFormat"); - - if (format<0) - return BAD_VALUE; - - Mutex::Autolock lock(mMutex); - mReqFormat = format; - return NO_ERROR; -} - -int GonkNativeWindowClient::setScalingMode(int mode) -{ - ALOGV("GonkNativeWindowClient::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 GonkNativeWindowClient::setBuffersTransform(int transform) -{ - ALOGV("GonkNativeWindowClient::setBuffersTransform"); - Mutex::Autolock lock(mMutex); - mTransform = transform; - return NO_ERROR; -} - -int GonkNativeWindowClient::setBuffersTimestamp(int64_t timestamp) -{ - ALOGV("GonkNativeWindowClient::setBuffersTimestamp"); - Mutex::Autolock lock(mMutex); - mTimestamp = timestamp; - return NO_ERROR; -} - -void GonkNativeWindowClient::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 - -// ---------------------------------------------------------------------------- - -status_t GonkNativeWindowClient::lock( - ANativeWindow_Buffer* outBuffer, ARect* inOutDirtyBounds) -{ - return INVALID_OPERATION; -} - -status_t GonkNativeWindowClient::unlockAndPost() -{ - return INVALID_OPERATION; -} - -}; // namespace android diff --git a/widget/gonk/nativewindow/GonkNativeWindowClientJB.h b/widget/gonk/nativewindow/GonkNativeWindowClientJB.h deleted file mode 100644 index 1e2fb00667a..00000000000 --- a/widget/gonk/nativewindow/GonkNativeWindowClientJB.h +++ /dev/null @@ -1,262 +0,0 @@ -/* - * Copyright (C) 2010 The Android Open Source Project - * Copyright (C) 2013 Mozilla Foundation - * - * 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 NATIVEWINDOW_GONKNATIVEWINDOWCLIENT_JB_H -#define NATIVEWINDOW_GONKNATIVEWINDOWCLIENT_JB_H - -#if ANDROID_VERSION == 17 -#include -#else -#include -#endif - -#include -#include - -#include -#include -#include - -#include "mozilla/Types.h" -#include "GonkBufferQueue.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 - * GonkNativeWindowClient. GonkNativeWindowClient then forwards the buffers through Binder IPC - * to the BufferQueue's producer interface, providing the new frame to a - * consumer such as GLConsumer. - */ -class GonkNativeWindowClient - : public ANativeObjectBase -{ -public: - - /* - * creates a GonkNativeWindowClient from the given IGraphicBufferProducer (which concrete - * implementation is a BufferQueue). - * - * GonkNativeWindowClient is mainly state-less while it's disconnected, it can be - * viewed as a glorified IGraphicBufferProducer holder. It's therefore - * safe to create other GonkNativeWindowClients from the same IGraphicBufferProducer. - * - * However, once a GonkNativeWindowClient is connected, it'll prevent other GonkNativeWindowClients - * referring to the same IGraphicBufferProducer to become connected and - * therefore prevent them to be used as actual producers of buffers. - */ - GonkNativeWindowClient(const sp& bufferProducer); - - /* getIGraphicBufferProducer() returns the IGraphicBufferProducer this - * GonkNativeWindowClient was created with. Usually it's an error to use the - * IGraphicBufferProducer while the GonkNativeWindowClient is connected. - */ -#if ANDROID_VERSION == 17 - sp getISurfaceTexture() const; -#else - sp 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& surface) { - return surface != NULL && surface->getIGraphicBufferProducer() != NULL; - } -#endif - -protected: - virtual ~GonkNativeWindowClient(); - -private: - // can't be copied - GonkNativeWindowClient& operator = (const GonkNativeWindowClient& rhs); - GonkNativeWindowClient(const GonkNativeWindowClient& 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 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); - -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 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 = GonkBufferQueue::NUM_BUFFER_SLOTS }; - enum { DEFAULT_FORMAT = PIXEL_FORMAT_RGBA_8888 }; - -private: - void freeAllBuffers(); - int getSlotFromBufferLocked(android_native_buffer_t* buffer) const; - - struct BufferSlot { - sp 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. - sp 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 - // 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; - - // 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; - - // 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 GonkNativeWindowClient objects. It must be locked whenever the - // member variables are accessed. - mutable Mutex mMutex; - - // must be used from the lock/unlock thread - sp mLockedBuffer; - sp mPostedBuffer; - bool mConnectedToCpu; - - // must be accessed from lock/unlock thread only - Region mDirtyRegion; -}; - -}; // namespace android - -#endif // NATIVEWINDOW_GONKNATIVEWINDOWCLIENT_JB_H diff --git a/widget/gonk/nativewindow/GonkNativeWindowClientKK.cpp b/widget/gonk/nativewindow/GonkNativeWindowClientKK.cpp deleted file mode 100644 index 06d1c4efc07..00000000000 --- a/widget/gonk/nativewindow/GonkNativeWindowClientKK.cpp +++ /dev/null @@ -1,673 +0,0 @@ -/* - * Copyright (C) 2010 The Android Open Source Project - * Copyright (C) 2013 Mozilla Foundation - * - * 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 "GonkNativeWindowClient" -#define ATRACE_TAG ATRACE_TAG_GRAPHICS -//#define LOG_NDEBUG 0 - -#include - -#include - -#include -#include - -#include - -#include "GonkNativeWindowClientKK.h" - -namespace android { - -GonkNativeWindowClient::GonkNativeWindowClient( - const sp& 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(ANativeWindow::minSwapInterval) = 0; - const_cast(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; - mDefaultWidth = 0; - mDefaultHeight = 0; - mUserWidth = 0; - mUserHeight = 0; - mTransformHint = 0; - mConsumerRunningBehind = false; - mConnectedToCpu = false; - mProducerControlledByApp = controlledByApp; - mSwapIntervalZero = false; -} - -GonkNativeWindowClient::~GonkNativeWindowClient() { - if (mConnectedToCpu) { - GonkNativeWindowClient::disconnect(NATIVE_WINDOW_API_CPU); - } -} - -sp GonkNativeWindowClient::getIGraphicBufferProducer() const { - return mGraphicBufferProducer; -} - -int GonkNativeWindowClient::hook_setSwapInterval(ANativeWindow* window, int interval) { - GonkNativeWindowClient* c = getSelf(window); - return c->setSwapInterval(interval); -} - -int GonkNativeWindowClient::hook_dequeueBuffer(ANativeWindow* window, - ANativeWindowBuffer** buffer, int* fenceFd) { - GonkNativeWindowClient* c = getSelf(window); - return c->dequeueBuffer(buffer, fenceFd); -} - -int GonkNativeWindowClient::hook_cancelBuffer(ANativeWindow* window, - ANativeWindowBuffer* buffer, int fenceFd) { - GonkNativeWindowClient* c = getSelf(window); - return c->cancelBuffer(buffer, fenceFd); -} - -int GonkNativeWindowClient::hook_queueBuffer(ANativeWindow* window, - ANativeWindowBuffer* buffer, int fenceFd) { - GonkNativeWindowClient* c = getSelf(window); - return c->queueBuffer(buffer, fenceFd); -} - -int GonkNativeWindowClient::hook_dequeueBuffer_DEPRECATED(ANativeWindow* window, - ANativeWindowBuffer** buffer) { - GonkNativeWindowClient* c = getSelf(window); - ANativeWindowBuffer* buf; - int fenceFd = -1; - int result = c->dequeueBuffer(&buf, &fenceFd); - sp 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 GonkNativeWindowClient::hook_cancelBuffer_DEPRECATED(ANativeWindow* window, - ANativeWindowBuffer* buffer) { - GonkNativeWindowClient* c = getSelf(window); - return c->cancelBuffer(buffer, -1); -} - -int GonkNativeWindowClient::hook_lockBuffer_DEPRECATED(ANativeWindow* window, - ANativeWindowBuffer* buffer) { - GonkNativeWindowClient* c = getSelf(window); - return c->lockBuffer_DEPRECATED(buffer); -} - -int GonkNativeWindowClient::hook_queueBuffer_DEPRECATED(ANativeWindow* window, - ANativeWindowBuffer* buffer) { - GonkNativeWindowClient* c = getSelf(window); - return c->queueBuffer(buffer, -1); -} - -int GonkNativeWindowClient::hook_query(const ANativeWindow* window, - int what, int* value) { - const GonkNativeWindowClient* c = getSelf(window); - return c->query(what, value); -} - -int GonkNativeWindowClient::hook_perform(ANativeWindow* window, int operation, ...) { - va_list args; - va_start(args, operation); - GonkNativeWindowClient* c = getSelf(window); - return c->perform(operation, args); -} - -int GonkNativeWindowClient::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; - - return NO_ERROR; -} - -int GonkNativeWindowClient::dequeueBuffer(android_native_buffer_t** buffer, int* fenceFd) { - ATRACE_CALL(); - ALOGV("GonkNativeWindowClient::dequeueBuffer"); - Mutex::Autolock lock(mMutex); - int buf = -1; - int reqW = mReqWidth ? mReqWidth : mUserWidth; - int reqH = mReqHeight ? mReqHeight : mUserHeight; - sp fence; - status_t result = mGraphicBufferProducer->dequeueBuffer(&buf, &fence, mSwapIntervalZero, - reqW, reqH, mReqFormat, mReqUsage); - if (result < 0) { - ALOGV("dequeueBuffer: IGraphicBufferProducer::dequeueBuffer(%d, %d, %d, %d)" - "failed: %d", mReqWidth, mReqHeight, mReqFormat, mReqUsage, - result); - return result; - } - sp& 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); - 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 GonkNativeWindowClient::cancelBuffer(android_native_buffer_t* buffer, - int fenceFd) { - ATRACE_CALL(); - ALOGV("GonkNativeWindowClient::cancelBuffer"); - Mutex::Autolock lock(mMutex); - int i = getSlotFromBufferLocked(buffer); - if (i < 0) { - return i; - } - sp fence(fenceFd >= 0 ? new Fence(fenceFd) : Fence::NO_FENCE); - mGraphicBufferProducer->cancelBuffer(i, fence); - return OK; -} - -int GonkNativeWindowClient::getSlotFromBufferLocked( - android_native_buffer_t* buffer) const { - 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 GonkNativeWindowClient::lockBuffer_DEPRECATED(android_native_buffer_t* buffer) { - ALOGV("GonkNativeWindowClient::lockBuffer"); - Mutex::Autolock lock(mMutex); - return OK; -} - -int GonkNativeWindowClient::queueBuffer(android_native_buffer_t* buffer, int fenceFd) { - ATRACE_CALL(); - ALOGV("GonkNativeWindowClient::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("GonkNativeWindowClient::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(fenceFd >= 0 ? new Fence(fenceFd) : Fence::NO_FENCE); - IGraphicBufferProducer::QueueBufferOutput output; - IGraphicBufferProducer::QueueBufferInput input(timestamp, isAutoTimestamp, - crop, mScalingMode, mTransform, mSwapIntervalZero, fence); - status_t err = mGraphicBufferProducer->queueBuffer(i, input, &output); - if (err != OK) { - ALOGE("queueBuffer: error queuing buffer to SurfaceTexture, %d", err); - } - uint32_t numPendingBuffers = 0; - output.deflate(&mDefaultWidth, &mDefaultHeight, &mTransformHint, - &numPendingBuffers); - - mConsumerRunningBehind = (numPendingBuffers >= 2); - - return err; -} - -int GonkNativeWindowClient::query(int what, int* value) const { - ATRACE_CALL(); - ALOGV("GonkNativeWindowClient::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 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 GonkNativeWindowClient::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_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; - default: - res = NAME_NOT_FOUND; - break; - } - return res; -} - -int GonkNativeWindowClient::dispatchConnect(va_list args) { - int api = va_arg(args, int); - return connect(api); -} - -int GonkNativeWindowClient::dispatchDisconnect(va_list args) { - int api = va_arg(args, int); - return disconnect(api); -} - -int GonkNativeWindowClient::dispatchSetUsage(va_list args) { - int usage = va_arg(args, int); - return setUsage(usage); -} - -int GonkNativeWindowClient::dispatchSetCrop(va_list args) { - android_native_rect_t const* rect = va_arg(args, android_native_rect_t*); - return setCrop(reinterpret_cast(rect)); -} - -int GonkNativeWindowClient::dispatchSetBufferCount(va_list args) { - size_t bufferCount = va_arg(args, size_t); - return setBufferCount(bufferCount); -} - -int GonkNativeWindowClient::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 GonkNativeWindowClient::dispatchSetBuffersDimensions(va_list args) { - int w = va_arg(args, int); - int h = va_arg(args, int); - return setBuffersDimensions(w, h); -} - -int GonkNativeWindowClient::dispatchSetBuffersUserDimensions(va_list args) { - int w = va_arg(args, int); - int h = va_arg(args, int); - return setBuffersUserDimensions(w, h); -} - -int GonkNativeWindowClient::dispatchSetBuffersFormat(va_list args) { - int f = va_arg(args, int); - return setBuffersFormat(f); -} - -int GonkNativeWindowClient::dispatchSetScalingMode(va_list args) { - int m = va_arg(args, int); - return setScalingMode(m); -} - -int GonkNativeWindowClient::dispatchSetBuffersTransform(va_list args) { - int transform = va_arg(args, int); - return setBuffersTransform(transform); -} - -int GonkNativeWindowClient::dispatchSetBuffersTimestamp(va_list args) { - int64_t timestamp = va_arg(args, int64_t); - return setBuffersTimestamp(timestamp); -} - -int GonkNativeWindowClient::dispatchLock(va_list args) { - ANativeWindow_Buffer* outBuffer = va_arg(args, ANativeWindow_Buffer*); - ARect* inOutDirtyBounds = va_arg(args, ARect*); - return lock(outBuffer, inOutDirtyBounds); -} - -int GonkNativeWindowClient::dispatchUnlockAndPost(va_list args) { - return unlockAndPost(); -} - - -int GonkNativeWindowClient::connect(int api) { - ATRACE_CALL(); - ALOGV("GonkNativeWindowClient::connect"); - static sp sLife = new BBinder(); - Mutex::Autolock lock(mMutex); - IGraphicBufferProducer::QueueBufferOutput output; - int err = mGraphicBufferProducer->connect(sLife, api, true, &output); - if (err == NO_ERROR) { - uint32_t numPendingBuffers = 0; - output.deflate(&mDefaultWidth, &mDefaultHeight, &mTransformHint, - &numPendingBuffers); - mConsumerRunningBehind = (numPendingBuffers >= 2); - } - if (!err && api == NATIVE_WINDOW_API_CPU) { - mConnectedToCpu = true; - } - return err; -} - - -int GonkNativeWindowClient::disconnect(int api) { - ATRACE_CALL(); - ALOGV("GonkNativeWindowClient::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; - if (api == NATIVE_WINDOW_API_CPU) { - mConnectedToCpu = false; - } - } - return err; -} - -int GonkNativeWindowClient::setUsage(uint32_t reqUsage) -{ - ALOGV("GonkNativeWindowClient::setUsage"); - Mutex::Autolock lock(mMutex); - mReqUsage = reqUsage; - return OK; -} - -int GonkNativeWindowClient::setCrop(Rect const* rect) -{ - ATRACE_CALL(); - - Rect realRect; - if (rect == NULL || rect->isEmpty()) { - realRect.clear(); - } else { - realRect = *rect; - } - - ALOGV("GonkNativeWindowClient::setCrop rect=[%d %d %d %d]", - realRect.left, realRect.top, realRect.right, realRect.bottom); - - Mutex::Autolock lock(mMutex); - mCrop = realRect; - return NO_ERROR; -} - -int GonkNativeWindowClient::setBufferCount(int bufferCount) -{ - ATRACE_CALL(); - ALOGV("GonkNativeWindowClient::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 GonkNativeWindowClient::setBuffersDimensions(int w, int h) -{ - ATRACE_CALL(); - ALOGV("GonkNativeWindowClient::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 GonkNativeWindowClient::setBuffersUserDimensions(int w, int h) -{ - ATRACE_CALL(); - ALOGV("GonkNativeWindowClient::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 GonkNativeWindowClient::setBuffersFormat(int format) -{ - ALOGV("GonkNativeWindowClient::setBuffersFormat"); - - if (format<0) - return BAD_VALUE; - - Mutex::Autolock lock(mMutex); - mReqFormat = format; - return NO_ERROR; -} - -int GonkNativeWindowClient::setScalingMode(int mode) -{ - ATRACE_CALL(); - ALOGV("GonkNativeWindowClient::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 GonkNativeWindowClient::setBuffersTransform(int transform) -{ - ATRACE_CALL(); - ALOGV("GonkNativeWindowClient::setBuffersTransform"); - Mutex::Autolock lock(mMutex); - mTransform = transform; - return NO_ERROR; -} - -int GonkNativeWindowClient::setBuffersTimestamp(int64_t timestamp) -{ - ALOGV("GonkNativeWindowClient::setBuffersTimestamp"); - Mutex::Autolock lock(mMutex); - mTimestamp = timestamp; - return NO_ERROR; -} - -void GonkNativeWindowClient::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 - -// ---------------------------------------------------------------------------- - -status_t GonkNativeWindowClient::lock( - ANativeWindow_Buffer* outBuffer, ARect* inOutDirtyBounds) -{ - return INVALID_OPERATION; -} - -status_t GonkNativeWindowClient::unlockAndPost() -{ - return INVALID_OPERATION; -} - -}; // namespace android diff --git a/widget/gonk/nativewindow/GonkNativeWindowClientKK.h b/widget/gonk/nativewindow/GonkNativeWindowClientKK.h deleted file mode 100644 index 13648161019..00000000000 --- a/widget/gonk/nativewindow/GonkNativeWindowClientKK.h +++ /dev/null @@ -1,264 +0,0 @@ -/* - * Copyright (C) 2010 The Android Open Source Project - * Copyright (C) 2013 Mozilla Foundation - * - * 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 NATIVEWINDOW_GONKNATIVEWINDOWCLIENT_KK_H -#define NATIVEWINDOW_GONKNATIVEWINDOWCLIENT_KK_H - -#include - -#include -#include - -#include -#include -#include - -#include "mozilla/Types.h" -#include "GonkBufferQueue.h" - -struct MOZ_EXPORT 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 - * GonkNativeWindowClient. GonkNativeWindowClient then forwards the buffers through Binder IPC - * to the BufferQueue's producer interface, providing the new frame to a - * consumer such as GLConsumer. - */ -class GonkNativeWindowClient - : public ANativeObjectBase -{ -public: - - /* - * creates a GonkNativeWindowClient from the given IGraphicBufferProducer (which concrete - * implementation is a BufferQueue). - * - * GonkNativeWindowClient is mainly state-less while it's disconnected, it can be - * viewed as a glorified IGraphicBufferProducer holder. It's therefore - * safe to create other GonkNativeWindowClients from the same IGraphicBufferProducer. - * - * However, once a GonkNativeWindowClient is connected, it'll prevent other GonkNativeWindowClients - * 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. - */ - GonkNativeWindowClient(const sp& bufferProducer, bool controlledByApp = false); - - /* getIGraphicBufferProducer() returns the IGraphicBufferProducer this - * GonkNativeWindowClient was created with. Usually it's an error to use the - * IGraphicBufferProducer while the GonkNativeWindowClient is connected. - */ - sp getIGraphicBufferProducer() const; - - /* convenience function to check that the given surface is non NULL as - * well as its IGraphicBufferProducer */ - static bool isValid(const sp& surface) { - return surface != NULL && surface->getIGraphicBufferProducer() != NULL; - } - -protected: - virtual ~GonkNativeWindowClient(); - -private: - // can't be copied - GonkNativeWindowClient& operator = (const GonkNativeWindowClient& rhs); - GonkNativeWindowClient(const GonkNativeWindowClient& 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 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); - -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 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 = GonkBufferQueue::NUM_BUFFER_SLOTS }; - enum { DEFAULT_FORMAT = PIXEL_FORMAT_RGBA_8888 }; - -private: - void freeAllBuffers(); - int getSlotFromBufferLocked(android_native_buffer_t* buffer) const; - - struct BufferSlot { - sp 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 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; - - // 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 GonkNativeWindowClient objects. It must be locked whenever the - // member variables are accessed. - mutable Mutex mMutex; - - // must be used from the lock/unlock thread - sp mLockedBuffer; - sp mPostedBuffer; - bool mConnectedToCpu; - - // must be accessed from lock/unlock thread only - Region mDirtyRegion; -}; - -}; // namespace android - -#endif // NATIVEWINDOW_GONKNATIVEWINDOWCLIENT_JB_H diff --git a/widget/gonk/nativewindow/GonkNativeWindowClientLL.cpp b/widget/gonk/nativewindow/GonkNativeWindowClientLL.cpp deleted file mode 100644 index 2eb73f987d7..00000000000 --- a/widget/gonk/nativewindow/GonkNativeWindowClientLL.cpp +++ /dev/null @@ -1,743 +0,0 @@ -/* - * Copyright (C) 2010 The Android Open Source Project - * Copyright (C) 2014 Mozilla Foundation - * - * 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 "GonkNativeWindowClient" -#define ATRACE_TAG ATRACE_TAG_GRAPHICS -//#define LOG_NDEBUG 0 - -#include - -#include - -#include -#include -#include - -#include - -#include -#include "GonkNativeWindowClientLL.h" - -namespace android { - -GonkNativeWindowClient::GonkNativeWindowClient( - const sp& 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(ANativeWindow::minSwapInterval) = 0; - const_cast(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; -} - -GonkNativeWindowClient::~GonkNativeWindowClient() { - if (mConnectedToCpu) { - GonkNativeWindowClient::disconnect(NATIVE_WINDOW_API_CPU); - } -} - -sp GonkNativeWindowClient::getIGraphicBufferProducer() const { - return mGraphicBufferProducer; -} - -void GonkNativeWindowClient::setSidebandStream(const sp& stream) { - mGraphicBufferProducer->setSidebandStream(stream); -} - -void GonkNativeWindowClient::allocateBuffers() { - uint32_t reqWidth = mReqWidth ? mReqWidth : mUserWidth; - uint32_t reqHeight = mReqHeight ? mReqHeight : mUserHeight; - mGraphicBufferProducer->allocateBuffers(mSwapIntervalZero, reqWidth, - reqHeight, mReqFormat, mReqUsage); -} - -int GonkNativeWindowClient::hook_setSwapInterval(ANativeWindow* window, int interval) { - GonkNativeWindowClient* c = getSelf(window); - return c->setSwapInterval(interval); -} - -int GonkNativeWindowClient::hook_dequeueBuffer(ANativeWindow* window, - ANativeWindowBuffer** buffer, int* fenceFd) { - GonkNativeWindowClient* c = getSelf(window); - return c->dequeueBuffer(buffer, fenceFd); -} - -int GonkNativeWindowClient::hook_cancelBuffer(ANativeWindow* window, - ANativeWindowBuffer* buffer, int fenceFd) { - GonkNativeWindowClient* c = getSelf(window); - return c->cancelBuffer(buffer, fenceFd); -} - -int GonkNativeWindowClient::hook_queueBuffer(ANativeWindow* window, - ANativeWindowBuffer* buffer, int fenceFd) { - GonkNativeWindowClient* c = getSelf(window); - return c->queueBuffer(buffer, fenceFd); -} - -int GonkNativeWindowClient::hook_dequeueBuffer_DEPRECATED(ANativeWindow* window, - ANativeWindowBuffer** buffer) { - GonkNativeWindowClient* c = getSelf(window); - ANativeWindowBuffer* buf; - int fenceFd = -1; - int result = c->dequeueBuffer(&buf, &fenceFd); - sp 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 GonkNativeWindowClient::hook_cancelBuffer_DEPRECATED(ANativeWindow* window, - ANativeWindowBuffer* buffer) { - GonkNativeWindowClient* c = getSelf(window); - return c->cancelBuffer(buffer, -1); -} - -int GonkNativeWindowClient::hook_lockBuffer_DEPRECATED(ANativeWindow* window, - ANativeWindowBuffer* buffer) { - GonkNativeWindowClient* c = getSelf(window); - return c->lockBuffer_DEPRECATED(buffer); -} - -int GonkNativeWindowClient::hook_queueBuffer_DEPRECATED(ANativeWindow* window, - ANativeWindowBuffer* buffer) { - GonkNativeWindowClient* c = getSelf(window); - return c->queueBuffer(buffer, -1); -} - -int GonkNativeWindowClient::hook_query(const ANativeWindow* window, - int what, int* value) { - const GonkNativeWindowClient* c = getSelf(window); - return c->query(what, value); -} - -int GonkNativeWindowClient::hook_perform(ANativeWindow* window, int operation, ...) { - va_list args; - va_start(args, operation); - GonkNativeWindowClient* c = getSelf(window); - return c->perform(operation, args); -} - -int GonkNativeWindowClient::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; - - return NO_ERROR; -} - -int GonkNativeWindowClient::dequeueBuffer(android_native_buffer_t** buffer, int* fenceFd) { - ATRACE_CALL(); - ALOGV("GonkNativeWindowClient::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 GonkNativeWindowClient while blocking in IGBP::dequeueBuffer - - int buf = -1; - sp 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& gbuf(mSlots[buf].buffer); - - // this should never happen - ALOGE_IF(fence == NULL, "GonkNativeWindowClient::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 GonkNativeWindowClient::cancelBuffer(android_native_buffer_t* buffer, - int fenceFd) { - ATRACE_CALL(); - ALOGV("GonkNativeWindowClient::cancelBuffer"); - Mutex::Autolock lock(mMutex); - int i = getSlotFromBufferLocked(buffer); - if (i < 0) { - return i; - } - sp fence(fenceFd >= 0 ? new Fence(fenceFd) : Fence::NO_FENCE); - mGraphicBufferProducer->cancelBuffer(i, fence); - return OK; -} - -int GonkNativeWindowClient::getSlotFromBufferLocked( - android_native_buffer_t* buffer) const { - 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 GonkNativeWindowClient::lockBuffer_DEPRECATED(android_native_buffer_t* buffer __attribute__((unused))) { - ALOGV("GonkNativeWindowClient::lockBuffer"); - Mutex::Autolock lock(mMutex); - return OK; -} - -int GonkNativeWindowClient::queueBuffer(android_native_buffer_t* buffer, int fenceFd) { - ATRACE_CALL(); - ALOGV("GonkNativeWindowClient::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("GonkNativeWindowClient::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(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 GonkNativeWindowClient::query(int what, int* value) const { - ATRACE_CALL(); - ALOGV("GonkNativeWindowClient::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: { - *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 GonkNativeWindowClient::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 GonkNativeWindowClient::dispatchConnect(va_list args) { - int api = va_arg(args, int); - return connect(api); -} - -int GonkNativeWindowClient::dispatchDisconnect(va_list args) { - int api = va_arg(args, int); - return disconnect(api); -} - -int GonkNativeWindowClient::dispatchSetUsage(va_list args) { - int usage = va_arg(args, int); - return setUsage(usage); -} - -int GonkNativeWindowClient::dispatchSetCrop(va_list args) { - android_native_rect_t const* rect = va_arg(args, android_native_rect_t*); - return setCrop(reinterpret_cast(rect)); -} - -int GonkNativeWindowClient::dispatchSetBufferCount(va_list args) { - size_t bufferCount = va_arg(args, size_t); - return setBufferCount(bufferCount); -} - -int GonkNativeWindowClient::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 GonkNativeWindowClient::dispatchSetBuffersDimensions(va_list args) { - int w = va_arg(args, int); - int h = va_arg(args, int); - return setBuffersDimensions(w, h); -} - -int GonkNativeWindowClient::dispatchSetBuffersUserDimensions(va_list args) { - int w = va_arg(args, int); - int h = va_arg(args, int); - return setBuffersUserDimensions(w, h); -} - -int GonkNativeWindowClient::dispatchSetBuffersFormat(va_list args) { - int f = va_arg(args, int); - return setBuffersFormat(f); -} - -int GonkNativeWindowClient::dispatchSetScalingMode(va_list args) { - int m = va_arg(args, int); - return setScalingMode(m); -} - -int GonkNativeWindowClient::dispatchSetBuffersTransform(va_list args) { - int transform = va_arg(args, int); - return setBuffersTransform(transform); -} - -int GonkNativeWindowClient::dispatchSetBuffersStickyTransform(va_list args) { - int transform = va_arg(args, int); - return setBuffersStickyTransform(transform); -} - -int GonkNativeWindowClient::dispatchSetBuffersTimestamp(va_list args) { - int64_t timestamp = va_arg(args, int64_t); - return setBuffersTimestamp(timestamp); -} - -int GonkNativeWindowClient::dispatchLock(va_list args) { - ANativeWindow_Buffer* outBuffer = va_arg(args, ANativeWindow_Buffer*); - ARect* inOutDirtyBounds = va_arg(args, ARect*); - return lock(outBuffer, inOutDirtyBounds); -} - -int GonkNativeWindowClient::dispatchUnlockAndPost(va_list args __attribute__((unused))) { - return unlockAndPost(); -} - -int GonkNativeWindowClient::dispatchSetSidebandStream(va_list args) { - native_handle_t* sH = va_arg(args, native_handle_t*); - sp sidebandHandle = NativeHandle::create(sH, false); - setSidebandStream(sidebandHandle); - return OK; -} - -int GonkNativeWindowClient::connect(int api) { - ATRACE_CALL(); - ALOGV("GonkNativeWindowClient::connect"); - static sp listener = new DummyProducerListener(); - Mutex::Autolock lock(mMutex); - IGraphicBufferProducer::QueueBufferOutput output; - int err = mGraphicBufferProducer->connect(listener, api, true, &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 GonkNativeWindowClient::disconnect(int api) { - ATRACE_CALL(); - ALOGV("GonkNativeWindowClient::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 GonkNativeWindowClient::setUsage(uint32_t reqUsage) -{ - ALOGV("GonkNativeWindowClient::setUsage"); - Mutex::Autolock lock(mMutex); - mReqUsage = reqUsage; - return OK; -} - -int GonkNativeWindowClient::setCrop(Rect const* rect) -{ - ATRACE_CALL(); - - Rect realRect; - if (rect == NULL || rect->isEmpty()) { - realRect.clear(); - } else { - realRect = *rect; - } - - ALOGV("GonkNativeWindowClient::setCrop rect=[%d %d %d %d]", - realRect.left, realRect.top, realRect.right, realRect.bottom); - - Mutex::Autolock lock(mMutex); - mCrop = realRect; - return NO_ERROR; -} - -int GonkNativeWindowClient::setBufferCount(int bufferCount) -{ - ATRACE_CALL(); - ALOGV("GonkNativeWindowClient::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 GonkNativeWindowClient::setBuffersDimensions(int w, int h) -{ - ATRACE_CALL(); - ALOGV("GonkNativeWindowClient::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 GonkNativeWindowClient::setBuffersUserDimensions(int w, int h) -{ - ATRACE_CALL(); - ALOGV("GonkNativeWindowClient::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 GonkNativeWindowClient::setBuffersFormat(int format) -{ - ALOGV("GonkNativeWindowClient::setBuffersFormat"); - - if (format<0) - return BAD_VALUE; - - Mutex::Autolock lock(mMutex); - mReqFormat = format; - return NO_ERROR; -} - -int GonkNativeWindowClient::setScalingMode(int mode) -{ - ATRACE_CALL(); - ALOGV("GonkNativeWindowClient::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 GonkNativeWindowClient::setBuffersTransform(int transform) -{ - ATRACE_CALL(); - ALOGV("GonkNativeWindowClient::setBuffersTransform"); - Mutex::Autolock lock(mMutex); - mTransform = transform; - return NO_ERROR; -} - -int GonkNativeWindowClient::setBuffersStickyTransform(int transform) -{ - ATRACE_CALL(); - ALOGV("GonkNativeWindowClient::setBuffersStickyTransform"); - Mutex::Autolock lock(mMutex); - mStickyTransform = transform; - return NO_ERROR; -} - -int GonkNativeWindowClient::setBuffersTimestamp(int64_t timestamp) -{ - ALOGV("GonkNativeWindowClient::setBuffersTimestamp"); - Mutex::Autolock lock(mMutex); - mTimestamp = timestamp; - return NO_ERROR; -} - -void GonkNativeWindowClient::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 - -// ---------------------------------------------------------------------------- - -status_t GonkNativeWindowClient::lock( - ANativeWindow_Buffer* outBuffer, ARect* inOutDirtyBounds) -{ - return INVALID_OPERATION; -} - -status_t GonkNativeWindowClient::unlockAndPost() -{ - return INVALID_OPERATION; -} - -}; // namespace android diff --git a/widget/gonk/nativewindow/GonkNativeWindowClientLL.h b/widget/gonk/nativewindow/GonkNativeWindowClientLL.h deleted file mode 100644 index d20314524c1..00000000000 --- a/widget/gonk/nativewindow/GonkNativeWindowClientLL.h +++ /dev/null @@ -1,295 +0,0 @@ -/* - * Copyright (C) 2010 The Android Open Source Project - * Copyright (C) 2014 Mozilla Foundation - * - * 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 NATIVEWINDOW_GONKNATIVEWINDOWCLIENT_LL_H -#define NATIVEWINDOW_GONKNATIVEWINDOWCLIENT_LL_H - -#include - -#include -#include - -#include -#include -#include - -#include "GonkBufferQueueLL.h" - -struct ANativeWindow_Buffer; - -namespace android { - -/* - * An implementation of ANativeWindow that feeds graphics buffers into a - * GonkBufferQueue. - * - * 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 - * GonkNativeWindowClient. GonkNativeWindowClient then forwards the buffers through Binder IPC - * to the GonkBufferQueue's producer interface, providing the new frame to a - * consumer such as GLConsumer. - */ -class GonkNativeWindowClient - : public ANativeObjectBase -{ -public: - - /* - * creates a GonkNativeWindowClient from the given IGraphicBufferProducer (which concrete - * implementation is a GonkBufferQueue). - * - * GonkNativeWindowClient is mainly state-less while it's disconnected, it can be - * viewed as a glorified IGraphicBufferProducer holder. It's therefore - * safe to create other GonkNativeWindowClients from the same IGraphicBufferProducer. - * - * However, once a GonkNativeWindowClient is connected, it'll prevent other GonkNativeWindowClients - * 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 GonkNativeWindowClient (producer) is - * controlled by the application. This flag is used at connect time. - */ - GonkNativeWindowClient(const sp& bufferProducer, bool controlledByApp = false); - - /* getIGraphicBufferProducer() returns the IGraphicBufferProducer this - * GonkNativeWindowClient was created with. Usually it's an error to use the - * IGraphicBufferProducer while the GonkNativeWindowClient is connected. - */ - sp getIGraphicBufferProducer() const; - - /* convenience function to check that the given surface is non NULL as - * well as its IGraphicBufferProducer */ - static bool isValid(const sp& surface) { - return surface != NULL && surface->getIGraphicBufferProducer() != NULL; - } - - /* Attaches a sideband buffer stream to the GonkNativeWindowClient'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& stream); - - /* Allocates buffers based on the current dimensions/format. - * - * This function will allocate up to the maximum number of buffers - * permitted by the current GonkBufferQueue 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 ~GonkNativeWindowClient(); - -private: - // can't be copied - GonkNativeWindowClient& operator = (const GonkNativeWindowClient& rhs); - GonkNativeWindowClient(const GonkNativeWindowClient& 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 = GonkBufferQueue::NUM_BUFFER_SLOTS }; - enum { DEFAULT_FORMAT = PIXEL_FORMAT_RGBA_8888 }; - -private: - void freeAllBuffers(); - int getSlotFromBufferLocked(android_native_buffer_t* buffer) const; - - struct BufferSlot { - sp 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 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 GonkNativeWindowClient objects. It must be locked whenever the - // member variables are accessed. - mutable Mutex mMutex; - - // must be used from the lock/unlock thread - sp mLockedBuffer; - sp mPostedBuffer; - bool mConnectedToCpu; - - // must be accessed from lock/unlock thread only - Region mDirtyRegion; -}; - -}; // namespace android - -#endif // NATIVEWINDOW_GONKNATIVEWINDOWCLIENT_LL_H diff --git a/widget/gonk/nativewindow/moz.build b/widget/gonk/nativewindow/moz.build index 96fe175d2c1..df64ad52026 100644 --- a/widget/gonk/nativewindow/moz.build +++ b/widget/gonk/nativewindow/moz.build @@ -17,7 +17,6 @@ EXPORTS += [ 'GonkBufferQueue.h', 'GonkNativeWindow.h', - 'GonkNativeWindowClient.h', ] if CONFIG['ANDROID_VERSION'] >= '19': @@ -32,7 +31,6 @@ if CONFIG['ANDROID_VERSION'] >= '21': 'GonkBufferQueueLL/GonkBufferQueueProducer.h', 'GonkBufferQueueLL/GonkBufferSlot.h', 'GonkConsumerBaseLL.h', - 'GonkNativeWindowClientLL.h', 'GonkNativeWindowLL.h', 'IGonkGraphicBufferConsumerLL.h', ] @@ -40,7 +38,6 @@ elif CONFIG['ANDROID_VERSION'] >= '19': EXPORTS += [ 'GonkBufferQueueKK.h', 'GonkConsumerBaseKK.h', - 'GonkNativeWindowClientKK.h', 'GonkNativeWindowKK.h', 'IGonkGraphicBufferConsumerKK.h', ] @@ -48,12 +45,10 @@ elif CONFIG['ANDROID_VERSION'] in ('17', '18'): EXPORTS += [ 'GonkBufferQueueJB.h', 'GonkConsumerBaseJB.h', - 'GonkNativeWindowClientJB.h', 'GonkNativeWindowJB.h', ] elif CONFIG['ANDROID_VERSION'] == '15': EXPORTS += [ - 'GonkNativeWindowClientICS.h', 'GonkNativeWindowICS.h', ] @@ -67,7 +62,6 @@ if CONFIG['MOZ_B2G_CAMERA'] or CONFIG['MOZ_OMX_DECODER'] or CONFIG['MOZ_WEBRTC'] 'GonkBufferQueueLL/GonkBufferQueueProducer.cpp', 'GonkBufferQueueLL/GonkBufferSlot.cpp', 'GonkConsumerBaseLL.cpp', - 'GonkNativeWindowClientLL.cpp', 'GonkNativeWindowLL.cpp', 'IGonkGraphicBufferConsumerLL.cpp', ] @@ -75,7 +69,6 @@ if CONFIG['MOZ_B2G_CAMERA'] or CONFIG['MOZ_OMX_DECODER'] or CONFIG['MOZ_WEBRTC'] SOURCES += [ 'GonkBufferQueueKK.cpp', 'GonkConsumerBaseKK.cpp', - 'GonkNativeWindowClientKK.cpp', 'GonkNativeWindowKK.cpp', 'IGonkGraphicBufferConsumerKK.cpp', ] @@ -83,12 +76,10 @@ if CONFIG['MOZ_B2G_CAMERA'] or CONFIG['MOZ_OMX_DECODER'] or CONFIG['MOZ_WEBRTC'] SOURCES += [ 'GonkBufferQueueJB.cpp', 'GonkConsumerBaseJB.cpp', - 'GonkNativeWindowClientJB.cpp', 'GonkNativeWindowJB.cpp', ] elif CONFIG['ANDROID_VERSION'] == '15': SOURCES += [ - 'GonkNativeWindowClientICS.cpp', 'GonkNativeWindowICS.cpp', ]