From a17c7b75087699a0f9d9ecd8981091bbf6d6a5be Mon Sep 17 00:00:00 2001 From: Sotaro Ikeda Date: Thu, 21 Nov 2013 16:03:27 -0500 Subject: [PATCH] Bug 929973 - Implement android::IGraphicBufferAlloc in B2G. r=mwu, r=mikeh --- dom/camera/GonkCameraHwMgr.cpp | 4 + .../gonk/nativewindow/FakeSurfaceComposer.cpp | 104 ++++++++++++++++++ .../gonk/nativewindow/FakeSurfaceComposer.h | 82 ++++++++++++++ widget/gonk/nativewindow/moz.build | 6 + widget/gonk/nsAppShell.cpp | 13 ++- 5 files changed, 206 insertions(+), 3 deletions(-) create mode 100644 widget/gonk/nativewindow/FakeSurfaceComposer.cpp create mode 100644 widget/gonk/nativewindow/FakeSurfaceComposer.h diff --git a/dom/camera/GonkCameraHwMgr.cpp b/dom/camera/GonkCameraHwMgr.cpp index 56cea5d2f12..5825f464368 100644 --- a/dom/camera/GonkCameraHwMgr.cpp +++ b/dom/camera/GonkCameraHwMgr.cpp @@ -71,6 +71,10 @@ GonkCameraHardware::OnNewFrame() return; } nsRefPtr buffer = mNativeWindow->getCurrentBuffer(); + if (!buffer) { + DOM_CAMERA_LOGW("received null frame"); + return; + } ReceiveFrame(mTarget, buffer); } diff --git a/widget/gonk/nativewindow/FakeSurfaceComposer.cpp b/widget/gonk/nativewindow/FakeSurfaceComposer.cpp new file mode 100644 index 00000000000..fddd6b933a3 --- /dev/null +++ b/widget/gonk/nativewindow/FakeSurfaceComposer.cpp @@ -0,0 +1,104 @@ +/* + * Copyright (C) 2007 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. + */ + +#include +#include +#include +#include + +#include +#include + +#include "FakeSurfaceComposer.h" + +namespace android { + +/* static */ +void FakeSurfaceComposer::instantiate() { + defaultServiceManager()->addService( + String16("SurfaceFlinger"), new FakeSurfaceComposer()); +} + +FakeSurfaceComposer::FakeSurfaceComposer() + : BnSurfaceComposer() +{ +} + +FakeSurfaceComposer::~FakeSurfaceComposer() +{ +} + +sp FakeSurfaceComposer::createConnection() +{ + return nullptr; +} + +sp FakeSurfaceComposer::createGraphicBufferAlloc() +{ + sp gba(new GraphicBufferAlloc()); + return gba; +} + +sp FakeSurfaceComposer::createDisplay(const String8& displayName, + bool secure) +{ + return nullptr; +} + +sp FakeSurfaceComposer::getBuiltInDisplay(int32_t id) { + return nullptr; +} + +void FakeSurfaceComposer::setTransactionState( + const Vector& state, + const Vector& displays, + uint32_t flags) +{ +} + +void FakeSurfaceComposer::bootFinished() +{ +} + +bool FakeSurfaceComposer::authenticateSurfaceTexture( + const sp& bufferProducer) const { + return false; +} + +sp FakeSurfaceComposer::createDisplayEventConnection() { + return nullptr; +} + +status_t FakeSurfaceComposer::captureScreen(const sp& display, + const sp& producer, + uint32_t reqWidth, uint32_t reqHeight, + uint32_t minLayerZ, uint32_t maxLayerZ, + bool isCpuConsumer) { + return INVALID_OPERATION; +} + +void FakeSurfaceComposer::blank(const sp& display) { +} + +void FakeSurfaceComposer::unblank(const sp& display) { +} + +status_t FakeSurfaceComposer::getDisplayInfo(const sp& display, DisplayInfo* info) { + return INVALID_OPERATION; +} + +}; // namespace android diff --git a/widget/gonk/nativewindow/FakeSurfaceComposer.h b/widget/gonk/nativewindow/FakeSurfaceComposer.h new file mode 100644 index 00000000000..87534e2c12a --- /dev/null +++ b/widget/gonk/nativewindow/FakeSurfaceComposer.h @@ -0,0 +1,82 @@ +/* + * Copyright (C) 2007 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_FAKE_SURFACE_COMPOSER_H +#define NATIVEWINDOW_FAKE_SURFACE_COMPOSER_H + +#include +#include + +#include + +#include + +#include +#include + +namespace android { + +// --------------------------------------------------------------------------- + +class IGraphicBufferAlloc; + +class FakeSurfaceComposer : public BinderService, + public BnSurfaceComposer +{ +public: + static char const* getServiceName() { + return "FakeSurfaceComposer"; + } + + // Instantiate MediaResourceManagerService and register to service manager. + // If service manager is not present, wait until service manager becomes present. + static void instantiate(); + +private: + FakeSurfaceComposer(); + // We're reference counted, never destroy FakeSurfaceComposer directly + virtual ~FakeSurfaceComposer(); + + /* ------------------------------------------------------------------------ + * ISurfaceComposer interface + */ + virtual sp createConnection(); + virtual sp createGraphicBufferAlloc(); + virtual sp createDisplay(const String8& displayName, bool secure); + virtual sp getBuiltInDisplay(int32_t id); + virtual void setTransactionState(const Vector& state, + const Vector& displays, uint32_t flags); + virtual void bootFinished(); + virtual bool authenticateSurfaceTexture( + const sp& bufferProducer) const; + virtual sp createDisplayEventConnection(); + virtual status_t captureScreen(const sp& display, + const sp& producer, + uint32_t reqWidth, uint32_t reqHeight, + uint32_t minLayerZ, uint32_t maxLayerZ, bool isCpuConsumer); + // called when screen needs to turn off + virtual void blank(const sp& display); + // called when screen is turning back on + virtual void unblank(const sp& display); + virtual status_t getDisplayInfo(const sp& display, DisplayInfo* info); + +}; + +// --------------------------------------------------------------------------- +}; // namespace android + +#endif // NATIVEWINDOW_FAKE_SURFACE_COMPOSER_H diff --git a/widget/gonk/nativewindow/moz.build b/widget/gonk/nativewindow/moz.build index 88695c7349b..06111ff8d49 100644 --- a/widget/gonk/nativewindow/moz.build +++ b/widget/gonk/nativewindow/moz.build @@ -46,6 +46,12 @@ if CONFIG['MOZ_B2G_CAMERA'] or CONFIG['MOZ_OMX_DECODER']: 'GonkNativeWindowICS.cpp', ] +if CONFIG['MOZ_B2G_CAMERA'] or CONFIG['MOZ_OMX_DECODER']: + if CONFIG['ANDROID_VERSION'] >= '18': + SOURCES += [ + 'FakeSurfaceComposer.cpp', + ] + FAIL_ON_WARNINGS = True include('/ipc/chromium/chromium-config.mozbuild') diff --git a/widget/gonk/nsAppShell.cpp b/widget/gonk/nsAppShell.cpp index 497efb9412e..d4fe27f44ee 100644 --- a/widget/gonk/nsAppShell.cpp +++ b/widget/gonk/nsAppShell.cpp @@ -40,6 +40,9 @@ #include "mozilla/Mutex.h" #include "mozilla/Services.h" #include "mozilla/TextEvents.h" +#if ANDROID_VERSION >= 18 +#include "nativewindow/FakeSurfaceComposer.h" +#endif #include "nsAppShell.h" #include "mozilla/dom/Touch.h" #include "nsGkAtoms.h" @@ -748,11 +751,15 @@ nsAppShell::Init() InitGonkMemoryPressureMonitoring(); -#ifdef MOZ_OMX_DECODER if (XRE_GetProcessType() == GeckoProcessType_Default) { - android::MediaResourceManagerService::instantiate(); - } +#ifdef MOZ_OMX_DECODER + android::MediaResourceManagerService::instantiate(); #endif +#if ANDROID_VERSION >= 18 + android::FakeSurfaceComposer::instantiate(); +#endif + } + nsCOMPtr obsServ = GetObserverService(); if (obsServ) { obsServ->AddObserver(this, "browser-ui-startup-complete", false);