2015-05-22 08:40:09 +00:00
|
|
|
/* Copyright 2012 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "android/log.h"
|
|
|
|
#include "GLContext.h"
|
2015-07-13 15:53:10 +00:00
|
|
|
#include "gfxPrefs.h"
|
2016-01-14 04:37:56 +00:00
|
|
|
#include "gfxUtils.h"
|
2015-05-22 08:40:09 +00:00
|
|
|
#include "mozilla/MouseEvents.h"
|
|
|
|
#include "mozilla/TouchEvents.h"
|
|
|
|
#include "mozilla/Hal.h"
|
2015-06-10 14:55:28 +00:00
|
|
|
#include "libdisplay/BootAnimation.h"
|
2015-05-22 08:40:09 +00:00
|
|
|
#include "libdisplay/GonkDisplay.h"
|
|
|
|
#include "nsScreenManagerGonk.h"
|
|
|
|
#include "nsThreadUtils.h"
|
|
|
|
#include "HwcComposer2D.h"
|
|
|
|
#include "VsyncSource.h"
|
|
|
|
#include "nsWindow.h"
|
2016-02-03 04:37:31 +00:00
|
|
|
#include "mozilla/ClearOnShutdown.h"
|
2016-03-22 18:08:38 +00:00
|
|
|
#include "mozilla/layers/CompositorBridgeParent.h"
|
2016-05-18 16:47:58 +00:00
|
|
|
#include "mozilla/layers/CompositorThread.h"
|
2015-05-22 08:40:09 +00:00
|
|
|
#include "mozilla/Services.h"
|
|
|
|
#include "mozilla/ProcessPriorityManager.h"
|
|
|
|
#include "nsIdleService.h"
|
|
|
|
#include "nsIObserverService.h"
|
|
|
|
#include "nsAppShell.h"
|
2015-12-03 06:27:55 +00:00
|
|
|
#include "nsProxyRelease.h"
|
2015-05-22 08:40:09 +00:00
|
|
|
#include "nsTArray.h"
|
|
|
|
#include "pixelflinger/format.h"
|
2015-06-05 03:29:30 +00:00
|
|
|
#include "nsIDisplayInfo.h"
|
2016-07-21 11:45:43 +00:00
|
|
|
#include "base/task.h"
|
2015-06-05 03:29:30 +00:00
|
|
|
|
|
|
|
#if ANDROID_VERSION >= 17
|
|
|
|
#include "libdisplay/DisplaySurface.h"
|
|
|
|
#endif
|
2015-05-22 08:40:09 +00:00
|
|
|
|
|
|
|
#define LOG(args...) __android_log_print(ANDROID_LOG_INFO, "nsScreenGonk" , ## args)
|
|
|
|
#define LOGW(args...) __android_log_print(ANDROID_LOG_WARN, "nsScreenGonk", ## args)
|
|
|
|
#define LOGE(args...) __android_log_print(ANDROID_LOG_ERROR, "nsScreenGonk", ## args)
|
|
|
|
|
|
|
|
using namespace mozilla;
|
|
|
|
using namespace mozilla::hal;
|
|
|
|
using namespace mozilla::gfx;
|
|
|
|
using namespace mozilla::gl;
|
2015-07-24 17:56:05 +00:00
|
|
|
using namespace mozilla::layers;
|
2015-05-22 08:40:09 +00:00
|
|
|
using namespace mozilla::dom;
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2016-04-27 10:05:40 +00:00
|
|
|
class ScreenOnOffEvent : public mozilla::Runnable {
|
2015-05-22 08:40:09 +00:00
|
|
|
public:
|
|
|
|
ScreenOnOffEvent(bool on)
|
|
|
|
: mIsOn(on)
|
|
|
|
{}
|
|
|
|
|
2016-08-08 02:18:10 +00:00
|
|
|
NS_IMETHOD Run() override {
|
2015-05-22 08:40:09 +00:00
|
|
|
// Notify observers that the screen state has just changed.
|
|
|
|
nsCOMPtr<nsIObserverService> observerService = mozilla::services::GetObserverService();
|
|
|
|
if (observerService) {
|
|
|
|
observerService->NotifyObservers(
|
|
|
|
nullptr, "screen-state-changed",
|
2016-07-21 05:03:25 +00:00
|
|
|
mIsOn ? u"on" : u"off"
|
2015-05-22 08:40:09 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<nsScreenGonk> screen = nsScreenManagerGonk::GetPrimaryScreen();
|
2015-05-22 08:40:09 +00:00
|
|
|
const nsTArray<nsWindow*>& windows = screen->GetTopWindows();
|
|
|
|
|
|
|
|
for (uint32_t i = 0; i < windows.Length(); i++) {
|
|
|
|
nsWindow *win = windows[i];
|
|
|
|
|
|
|
|
if (nsIWidgetListener* listener = win->GetWidgetListener()) {
|
|
|
|
listener->SizeModeChanged(mIsOn ? nsSizeMode_Fullscreen : nsSizeMode_Minimized);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
bool mIsOn;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
displayEnabledCallback(bool enabled)
|
|
|
|
{
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<nsScreenManagerGonk> screenManager = nsScreenManagerGonk::GetInstance();
|
2015-05-22 08:40:09 +00:00
|
|
|
screenManager->DisplayEnabled(enabled);
|
|
|
|
}
|
|
|
|
|
2015-07-13 15:25:42 +00:00
|
|
|
} // namespace
|
2015-05-22 08:40:09 +00:00
|
|
|
|
|
|
|
static uint32_t
|
|
|
|
SurfaceFormatToColorDepth(int32_t aSurfaceFormat)
|
|
|
|
{
|
|
|
|
switch (aSurfaceFormat) {
|
|
|
|
case GGL_PIXEL_FORMAT_RGB_565:
|
|
|
|
return 16;
|
|
|
|
case GGL_PIXEL_FORMAT_RGBA_8888:
|
|
|
|
return 32;
|
|
|
|
}
|
|
|
|
return 24; // GGL_PIXEL_FORMAT_RGBX_8888
|
|
|
|
}
|
|
|
|
|
|
|
|
// nsScreenGonk.cpp
|
|
|
|
|
2015-06-05 03:29:30 +00:00
|
|
|
nsScreenGonk::nsScreenGonk(uint32_t aId,
|
|
|
|
GonkDisplay::DisplayType aDisplayType,
|
2015-11-13 05:09:58 +00:00
|
|
|
const GonkDisplay::NativeData& aNativeData,
|
|
|
|
NotifyDisplayChangedEvent aEventVisibility)
|
2015-05-22 08:40:09 +00:00
|
|
|
: mId(aId)
|
2015-11-13 05:09:58 +00:00
|
|
|
, mEventVisibility(aEventVisibility)
|
2015-06-05 03:29:30 +00:00
|
|
|
, mNativeWindow(aNativeData.mNativeWindow)
|
|
|
|
, mDpi(aNativeData.mXdpi)
|
2015-05-22 08:40:09 +00:00
|
|
|
, mScreenRotation(nsIScreen::ROTATION_0_DEG)
|
|
|
|
, mPhysicalScreenRotation(nsIScreen::ROTATION_0_DEG)
|
2015-06-05 03:29:30 +00:00
|
|
|
#if ANDROID_VERSION >= 17
|
|
|
|
, mDisplaySurface(aNativeData.mDisplaySurface)
|
|
|
|
#endif
|
2015-08-08 20:50:47 +00:00
|
|
|
, mIsMirroring(false)
|
2015-06-05 03:29:30 +00:00
|
|
|
, mDisplayType(aDisplayType)
|
2015-07-24 17:56:05 +00:00
|
|
|
, mEGLDisplay(EGL_NO_DISPLAY)
|
|
|
|
, mEGLSurface(EGL_NO_SURFACE)
|
2015-06-05 03:29:30 +00:00
|
|
|
, mGLContext(nullptr)
|
2016-01-14 04:37:56 +00:00
|
|
|
, mFramebuffer(nullptr)
|
|
|
|
, mMappedBuffer(nullptr)
|
2015-05-22 08:40:09 +00:00
|
|
|
{
|
|
|
|
if (mNativeWindow->query(mNativeWindow.get(), NATIVE_WINDOW_WIDTH, &mVirtualBounds.width) ||
|
|
|
|
mNativeWindow->query(mNativeWindow.get(), NATIVE_WINDOW_HEIGHT, &mVirtualBounds.height) ||
|
2015-06-05 03:29:30 +00:00
|
|
|
mNativeWindow->query(mNativeWindow.get(), NATIVE_WINDOW_FORMAT, &mSurfaceFormat)) {
|
2016-12-02 21:46:53 +00:00
|
|
|
MOZ_CRASH("Failed to get native window size, aborting...");
|
2015-05-22 08:40:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
mNaturalBounds = mVirtualBounds;
|
|
|
|
|
|
|
|
if (IsPrimaryScreen()) {
|
|
|
|
char propValue[PROPERTY_VALUE_MAX];
|
|
|
|
property_get("ro.sf.hwrotation", propValue, "0");
|
|
|
|
mPhysicalScreenRotation = atoi(propValue) / 90;
|
|
|
|
}
|
|
|
|
|
2015-06-05 03:29:30 +00:00
|
|
|
mColorDepth = SurfaceFormatToColorDepth(mSurfaceFormat);
|
2015-05-22 08:40:09 +00:00
|
|
|
}
|
|
|
|
|
2015-08-08 20:50:47 +00:00
|
|
|
static void
|
2016-05-19 07:20:08 +00:00
|
|
|
ReleaseGLContextSync(mozilla::gl::GLContext* aGLContext)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(CompositorThreadHolder::IsInCompositorThread());
|
2015-08-08 20:50:47 +00:00
|
|
|
aGLContext->Release();
|
|
|
|
}
|
|
|
|
|
2015-05-22 08:40:09 +00:00
|
|
|
nsScreenGonk::~nsScreenGonk()
|
|
|
|
{
|
2015-08-08 20:50:47 +00:00
|
|
|
// Release GLContext on compositor thread
|
|
|
|
if (mGLContext) {
|
2016-05-18 16:47:58 +00:00
|
|
|
CompositorThreadHolder::Loop()->PostTask(
|
2015-08-08 20:50:47 +00:00
|
|
|
NewRunnableFunction(&ReleaseGLContextSync,
|
|
|
|
mGLContext.forget().take()));
|
|
|
|
mGLContext = nullptr;
|
|
|
|
}
|
2015-05-22 08:40:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
nsScreenGonk::IsPrimaryScreen()
|
|
|
|
{
|
2015-06-05 03:29:30 +00:00
|
|
|
return mDisplayType == GonkDisplay::DISPLAY_PRIMARY;
|
2015-05-22 08:40:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsScreenGonk::GetId(uint32_t *outId)
|
|
|
|
{
|
|
|
|
*outId = mId;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t
|
|
|
|
nsScreenGonk::GetId()
|
|
|
|
{
|
|
|
|
return mId;
|
|
|
|
}
|
|
|
|
|
2015-11-13 05:09:58 +00:00
|
|
|
NotifyDisplayChangedEvent
|
|
|
|
nsScreenGonk::GetEventVisibility()
|
|
|
|
{
|
|
|
|
return mEventVisibility;
|
|
|
|
}
|
|
|
|
|
2015-05-22 08:40:09 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsScreenGonk::GetRect(int32_t *outLeft, int32_t *outTop,
|
|
|
|
int32_t *outWidth, int32_t *outHeight)
|
|
|
|
{
|
|
|
|
*outLeft = mVirtualBounds.x;
|
|
|
|
*outTop = mVirtualBounds.y;
|
|
|
|
|
|
|
|
*outWidth = mVirtualBounds.width;
|
|
|
|
*outHeight = mVirtualBounds.height;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-11-13 09:37:02 +00:00
|
|
|
LayoutDeviceIntRect
|
2015-05-22 08:40:09 +00:00
|
|
|
nsScreenGonk::GetRect()
|
|
|
|
{
|
|
|
|
return mVirtualBounds;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsScreenGonk::GetAvailRect(int32_t *outLeft, int32_t *outTop,
|
|
|
|
int32_t *outWidth, int32_t *outHeight)
|
|
|
|
{
|
|
|
|
return GetRect(outLeft, outTop, outWidth, outHeight);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsScreenGonk::GetPixelDepth(int32_t *aPixelDepth)
|
|
|
|
{
|
|
|
|
// XXX: this should actually return 32 when we're using 24-bit
|
|
|
|
// color, because we use RGBX.
|
|
|
|
*aPixelDepth = mColorDepth;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsScreenGonk::GetColorDepth(int32_t *aColorDepth)
|
|
|
|
{
|
|
|
|
*aColorDepth = mColorDepth;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsScreenGonk::GetRotation(uint32_t* aRotation)
|
|
|
|
{
|
|
|
|
*aRotation = mScreenRotation;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
float
|
|
|
|
nsScreenGonk::GetDpi()
|
|
|
|
{
|
|
|
|
return mDpi;
|
|
|
|
}
|
|
|
|
|
2015-06-05 03:29:30 +00:00
|
|
|
int32_t
|
|
|
|
nsScreenGonk::GetSurfaceFormat()
|
|
|
|
{
|
|
|
|
return mSurfaceFormat;
|
|
|
|
}
|
|
|
|
|
2015-05-22 08:40:09 +00:00
|
|
|
ANativeWindow*
|
|
|
|
nsScreenGonk::GetNativeWindow()
|
|
|
|
{
|
|
|
|
return mNativeWindow.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsScreenGonk::SetRotation(uint32_t aRotation)
|
|
|
|
{
|
|
|
|
if (!(aRotation <= ROTATION_270_DEG)) {
|
|
|
|
return NS_ERROR_ILLEGAL_VALUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mScreenRotation == aRotation) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
mScreenRotation = aRotation;
|
|
|
|
uint32_t rotation = EffectiveScreenRotation();
|
|
|
|
if (rotation == nsIScreen::ROTATION_90_DEG ||
|
|
|
|
rotation == nsIScreen::ROTATION_270_DEG) {
|
2015-11-13 09:37:02 +00:00
|
|
|
mVirtualBounds = LayoutDeviceIntRect(0, 0,
|
|
|
|
mNaturalBounds.height,
|
|
|
|
mNaturalBounds.width);
|
2015-05-22 08:40:09 +00:00
|
|
|
} else {
|
|
|
|
mVirtualBounds = mNaturalBounds;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAppShell::NotifyScreenRotation();
|
|
|
|
|
|
|
|
for (unsigned int i = 0; i < mTopWindows.Length(); i++) {
|
|
|
|
mTopWindows[i]->Resize(mVirtualBounds.width,
|
2015-06-05 03:29:30 +00:00
|
|
|
mVirtualBounds.height,
|
|
|
|
true);
|
2015-05-22 08:40:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-11-12 13:44:43 +00:00
|
|
|
LayoutDeviceIntRect
|
|
|
|
nsScreenGonk::GetNaturalBounds()
|
2015-05-22 08:40:09 +00:00
|
|
|
{
|
2015-11-13 09:37:02 +00:00
|
|
|
return mNaturalBounds;
|
2015-05-22 08:40:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t
|
|
|
|
nsScreenGonk::EffectiveScreenRotation()
|
|
|
|
{
|
|
|
|
return (mScreenRotation + mPhysicalScreenRotation) % (360 / 90);
|
|
|
|
}
|
|
|
|
|
|
|
|
// NB: This isn't gonk-specific, but gonk is the only widget backend
|
|
|
|
// that does this calculation itself, currently.
|
2015-08-18 21:55:09 +00:00
|
|
|
static ScreenOrientationInternal
|
2015-11-13 09:37:02 +00:00
|
|
|
ComputeOrientation(uint32_t aRotation, const LayoutDeviceIntSize& aScreenSize)
|
2015-05-22 08:40:09 +00:00
|
|
|
{
|
|
|
|
bool naturallyPortrait = (aScreenSize.height > aScreenSize.width);
|
|
|
|
switch (aRotation) {
|
|
|
|
case nsIScreen::ROTATION_0_DEG:
|
|
|
|
return (naturallyPortrait ? eScreenOrientation_PortraitPrimary :
|
|
|
|
eScreenOrientation_LandscapePrimary);
|
|
|
|
case nsIScreen::ROTATION_90_DEG:
|
|
|
|
// Arbitrarily choosing 90deg to be primary "unnatural"
|
|
|
|
// rotation.
|
|
|
|
return (naturallyPortrait ? eScreenOrientation_LandscapePrimary :
|
|
|
|
eScreenOrientation_PortraitPrimary);
|
|
|
|
case nsIScreen::ROTATION_180_DEG:
|
|
|
|
return (naturallyPortrait ? eScreenOrientation_PortraitSecondary :
|
|
|
|
eScreenOrientation_LandscapeSecondary);
|
|
|
|
case nsIScreen::ROTATION_270_DEG:
|
|
|
|
return (naturallyPortrait ? eScreenOrientation_LandscapeSecondary :
|
|
|
|
eScreenOrientation_PortraitSecondary);
|
|
|
|
default:
|
|
|
|
MOZ_CRASH("Gonk screen must always have a known rotation");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-18 21:55:15 +00:00
|
|
|
static uint16_t
|
|
|
|
RotationToAngle(uint32_t aRotation)
|
|
|
|
{
|
|
|
|
uint16_t angle = 90 * aRotation;
|
|
|
|
MOZ_ASSERT(angle == 0 || angle == 90 || angle == 180 || angle == 270);
|
|
|
|
return angle;
|
|
|
|
}
|
|
|
|
|
2015-05-22 08:40:09 +00:00
|
|
|
ScreenConfiguration
|
|
|
|
nsScreenGonk::GetConfiguration()
|
|
|
|
{
|
2015-11-13 09:37:02 +00:00
|
|
|
ScreenOrientationInternal orientation =
|
|
|
|
ComputeOrientation(mScreenRotation, mNaturalBounds.Size());
|
2015-05-22 08:40:09 +00:00
|
|
|
|
|
|
|
// NB: perpetuating colorDepth == pixelDepth illusion here, for
|
|
|
|
// consistency.
|
2015-11-13 09:37:02 +00:00
|
|
|
return ScreenConfiguration(mVirtualBounds.ToUnknownRect(), orientation,
|
2015-08-18 21:55:15 +00:00
|
|
|
RotationToAngle(mScreenRotation),
|
2015-05-22 08:40:09 +00:00
|
|
|
mColorDepth, mColorDepth);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsScreenGonk::RegisterWindow(nsWindow* aWindow)
|
|
|
|
{
|
|
|
|
mTopWindows.AppendElement(aWindow);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsScreenGonk::UnregisterWindow(nsWindow* aWindow)
|
|
|
|
{
|
|
|
|
mTopWindows.RemoveElement(aWindow);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsScreenGonk::BringToTop(nsWindow* aWindow)
|
|
|
|
{
|
|
|
|
mTopWindows.RemoveElement(aWindow);
|
|
|
|
mTopWindows.InsertElementAt(0, aWindow);
|
|
|
|
}
|
|
|
|
|
2016-01-14 04:37:56 +00:00
|
|
|
static gralloc_module_t const*
|
|
|
|
gralloc_module()
|
|
|
|
{
|
|
|
|
hw_module_t const *module;
|
|
|
|
if (hw_get_module(GRALLOC_HARDWARE_MODULE_ID, &module)) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
return reinterpret_cast<gralloc_module_t const*>(module);
|
|
|
|
}
|
|
|
|
|
|
|
|
static SurfaceFormat
|
|
|
|
HalFormatToSurfaceFormat(int aHalFormat)
|
|
|
|
{
|
|
|
|
switch (aHalFormat) {
|
|
|
|
case HAL_PIXEL_FORMAT_RGBA_8888:
|
|
|
|
// Needs RB swap
|
|
|
|
return SurfaceFormat::B8G8R8A8;
|
|
|
|
case HAL_PIXEL_FORMAT_RGBX_8888:
|
|
|
|
// Needs RB swap
|
|
|
|
return SurfaceFormat::B8G8R8X8;
|
|
|
|
case HAL_PIXEL_FORMAT_BGRA_8888:
|
|
|
|
return SurfaceFormat::B8G8R8A8;
|
|
|
|
case HAL_PIXEL_FORMAT_RGB_565:
|
|
|
|
return SurfaceFormat::R5G6B5_UINT16;
|
|
|
|
default:
|
|
|
|
MOZ_CRASH("Unhandled HAL pixel format");
|
|
|
|
return SurfaceFormat::UNKNOWN; // not reached
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
|
|
|
NeedsRBSwap(int aHalFormat)
|
|
|
|
{
|
|
|
|
switch (aHalFormat) {
|
|
|
|
case HAL_PIXEL_FORMAT_RGBA_8888:
|
|
|
|
return true;
|
|
|
|
case HAL_PIXEL_FORMAT_RGBX_8888:
|
|
|
|
return true;
|
|
|
|
case HAL_PIXEL_FORMAT_BGRA_8888:
|
|
|
|
return false;
|
|
|
|
case HAL_PIXEL_FORMAT_RGB_565:
|
|
|
|
return false;
|
|
|
|
default:
|
|
|
|
MOZ_CRASH("Unhandled HAL pixel format");
|
|
|
|
return false; // not reached
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<DrawTarget>
|
|
|
|
nsScreenGonk::StartRemoteDrawing()
|
|
|
|
{
|
2016-05-19 07:20:08 +00:00
|
|
|
MOZ_ASSERT(CompositorThreadHolder::IsInCompositorThread());
|
2016-01-14 04:37:56 +00:00
|
|
|
MOZ_ASSERT(!mFramebuffer);
|
|
|
|
MOZ_ASSERT(!mMappedBuffer);
|
|
|
|
|
|
|
|
mFramebuffer = DequeueBuffer();
|
|
|
|
int width = mFramebuffer->width, height = mFramebuffer->height;
|
|
|
|
if (gralloc_module()->lock(gralloc_module(), mFramebuffer->handle,
|
|
|
|
GRALLOC_USAGE_SW_READ_NEVER |
|
|
|
|
GRALLOC_USAGE_SW_WRITE_OFTEN |
|
|
|
|
GRALLOC_USAGE_HW_FB,
|
|
|
|
0, 0, width, height,
|
|
|
|
reinterpret_cast<void**>(&mMappedBuffer))) {
|
|
|
|
EndRemoteDrawing();
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
SurfaceFormat format = HalFormatToSurfaceFormat(GetSurfaceFormat());
|
|
|
|
mFramebufferTarget = Factory::CreateDrawTargetForData(
|
|
|
|
BackendType::CAIRO,
|
|
|
|
mMappedBuffer,
|
|
|
|
IntSize(width, height),
|
|
|
|
mFramebuffer->stride * gfx::BytesPerPixel(format),
|
|
|
|
format);
|
|
|
|
if (!mFramebufferTarget) {
|
|
|
|
MOZ_CRASH("nsWindow::StartRemoteDrawing failed in CreateDrawTargetForData");
|
|
|
|
}
|
|
|
|
if (!mBackBuffer ||
|
|
|
|
mBackBuffer->GetSize() != mFramebufferTarget->GetSize() ||
|
|
|
|
mBackBuffer->GetFormat() != mFramebufferTarget->GetFormat()) {
|
|
|
|
mBackBuffer = mFramebufferTarget->CreateSimilarDrawTarget(
|
|
|
|
mFramebufferTarget->GetSize(), mFramebufferTarget->GetFormat());
|
|
|
|
}
|
|
|
|
RefPtr<DrawTarget> buffer(mBackBuffer);
|
|
|
|
return buffer.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsScreenGonk::EndRemoteDrawing()
|
|
|
|
{
|
2016-05-19 07:20:08 +00:00
|
|
|
MOZ_ASSERT(CompositorThreadHolder::IsInCompositorThread());
|
2016-01-14 04:37:56 +00:00
|
|
|
|
|
|
|
if (mFramebufferTarget && mFramebuffer) {
|
|
|
|
IntSize size = mFramebufferTarget->GetSize();
|
|
|
|
Rect rect(0, 0, size.width, size.height);
|
|
|
|
RefPtr<SourceSurface> source = mBackBuffer->Snapshot();
|
|
|
|
mFramebufferTarget->DrawSurface(source, rect, rect);
|
|
|
|
|
|
|
|
// Convert from BGR to RGB
|
|
|
|
// XXX this is a temporary solution. It consumes extra cpu cycles,
|
|
|
|
// it should not be used on product device.
|
|
|
|
if (NeedsRBSwap(GetSurfaceFormat())) {
|
|
|
|
LOGE("Very slow composition path, it should not be used on product!!!");
|
|
|
|
SurfaceFormat format = HalFormatToSurfaceFormat(GetSurfaceFormat());
|
|
|
|
gfxUtils::ConvertBGRAtoRGBA(
|
|
|
|
mMappedBuffer,
|
|
|
|
mFramebuffer->stride * mFramebuffer->height * gfx::BytesPerPixel(format));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (mMappedBuffer) {
|
|
|
|
MOZ_ASSERT(mFramebuffer);
|
|
|
|
gralloc_module()->unlock(gralloc_module(), mFramebuffer->handle);
|
|
|
|
mMappedBuffer = nullptr;
|
|
|
|
}
|
|
|
|
if (mFramebuffer) {
|
|
|
|
QueueBuffer(mFramebuffer);
|
|
|
|
}
|
|
|
|
mFramebuffer = nullptr;
|
|
|
|
mFramebufferTarget = nullptr;
|
|
|
|
}
|
|
|
|
|
2015-10-04 00:06:19 +00:00
|
|
|
ANativeWindowBuffer*
|
|
|
|
nsScreenGonk::DequeueBuffer()
|
|
|
|
{
|
|
|
|
ANativeWindowBuffer* buf = nullptr;
|
|
|
|
#if ANDROID_VERSION >= 17
|
|
|
|
int fenceFd = -1;
|
|
|
|
mNativeWindow->dequeueBuffer(mNativeWindow.get(), &buf, &fenceFd);
|
|
|
|
android::sp<android::Fence> fence(new android::Fence(fenceFd));
|
|
|
|
#if ANDROID_VERSION == 17
|
|
|
|
fence->waitForever(1000, "nsScreenGonk_DequeueBuffer");
|
|
|
|
// 1000 is what Android uses. It is a warning timeout in ms.
|
|
|
|
// This timeout was removed in ANDROID_VERSION 18.
|
|
|
|
#else
|
|
|
|
fence->waitForever("nsScreenGonk_DequeueBuffer");
|
|
|
|
#endif
|
|
|
|
#else
|
|
|
|
mNativeWindow->dequeueBuffer(mNativeWindow.get(), &buf);
|
|
|
|
#endif
|
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
nsScreenGonk::QueueBuffer(ANativeWindowBuffer* buf)
|
|
|
|
{
|
|
|
|
#if ANDROID_VERSION >= 17
|
|
|
|
int ret = mNativeWindow->queueBuffer(mNativeWindow.get(), buf, -1);
|
|
|
|
return ret == 0;
|
|
|
|
#else
|
|
|
|
int ret = mNativeWindow->queueBuffer(mNativeWindow.get(), buf);
|
|
|
|
return ret == 0;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2016-01-21 08:21:50 +00:00
|
|
|
nsresult
|
|
|
|
nsScreenGonk::MakeSnapshot(ANativeWindowBuffer* aBuffer)
|
|
|
|
{
|
2016-05-19 07:20:08 +00:00
|
|
|
MOZ_ASSERT(CompositorThreadHolder::IsInCompositorThread());
|
2016-01-21 08:21:50 +00:00
|
|
|
MOZ_ASSERT(aBuffer);
|
|
|
|
|
2016-03-22 18:08:38 +00:00
|
|
|
layers::CompositorBridgeParent* compositorParent = mCompositorBridgeParent;
|
2016-01-21 08:21:50 +00:00
|
|
|
if (!compositorParent) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
int width = aBuffer->width, height = aBuffer->height;
|
|
|
|
uint8_t* mappedBuffer = nullptr;
|
|
|
|
if (gralloc_module()->lock(gralloc_module(), aBuffer->handle,
|
|
|
|
GRALLOC_USAGE_SW_READ_OFTEN |
|
|
|
|
GRALLOC_USAGE_SW_WRITE_OFTEN,
|
|
|
|
0, 0, width, height,
|
|
|
|
reinterpret_cast<void**>(&mappedBuffer))) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
SurfaceFormat format = HalFormatToSurfaceFormat(GetSurfaceFormat());
|
|
|
|
RefPtr<DrawTarget> mTarget =
|
|
|
|
Factory::CreateDrawTargetForData(
|
|
|
|
BackendType::CAIRO,
|
|
|
|
mappedBuffer,
|
|
|
|
IntSize(width, height),
|
|
|
|
aBuffer->stride * gfx::BytesPerPixel(format),
|
|
|
|
format);
|
|
|
|
if (!mTarget) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
gfx::IntRect rect = GetRect().ToUnknownRect();
|
|
|
|
compositorParent->ForceComposeToTarget(mTarget, &rect);
|
|
|
|
|
|
|
|
// Convert from BGR to RGB
|
|
|
|
// XXX this is a temporary solution. It consumes extra cpu cycles,
|
|
|
|
if (NeedsRBSwap(GetSurfaceFormat())) {
|
|
|
|
LOGE("Slow path of making Snapshot!!!");
|
|
|
|
SurfaceFormat format = HalFormatToSurfaceFormat(GetSurfaceFormat());
|
|
|
|
gfxUtils::ConvertBGRAtoRGBA(
|
|
|
|
mappedBuffer,
|
|
|
|
aBuffer->stride * aBuffer->height * gfx::BytesPerPixel(format));
|
|
|
|
mappedBuffer = nullptr;
|
|
|
|
}
|
|
|
|
gralloc_module()->unlock(gralloc_module(), aBuffer->handle);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-03-22 18:08:38 +00:00
|
|
|
nsScreenGonk::SetCompositorBridgeParent(layers::CompositorBridgeParent* aCompositorBridgeParent)
|
2016-01-21 08:21:50 +00:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2016-03-22 18:08:38 +00:00
|
|
|
mCompositorBridgeParent = aCompositorBridgeParent;
|
2016-01-21 08:21:50 +00:00
|
|
|
}
|
|
|
|
|
2015-06-05 03:29:30 +00:00
|
|
|
#if ANDROID_VERSION >= 17
|
|
|
|
android::DisplaySurface*
|
|
|
|
nsScreenGonk::GetDisplaySurface()
|
|
|
|
{
|
|
|
|
return mDisplaySurface.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
nsScreenGonk::GetPrevDispAcquireFd()
|
|
|
|
{
|
|
|
|
if (!mDisplaySurface.get()) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return mDisplaySurface->GetPrevDispAcquireFd();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
GonkDisplay::DisplayType
|
|
|
|
nsScreenGonk::GetDisplayType()
|
|
|
|
{
|
|
|
|
return mDisplayType;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2015-08-08 20:50:47 +00:00
|
|
|
nsScreenGonk::SetEGLInfo(hwc_display_t aDisplay,
|
|
|
|
hwc_surface_t aSurface,
|
2015-06-05 03:29:30 +00:00
|
|
|
gl::GLContext* aGLContext)
|
|
|
|
{
|
2016-05-19 07:20:08 +00:00
|
|
|
MOZ_ASSERT(CompositorThreadHolder::IsInCompositorThread());
|
2015-07-24 17:56:05 +00:00
|
|
|
mEGLDisplay = aDisplay;
|
|
|
|
mEGLSurface = aSurface;
|
2015-06-05 03:29:30 +00:00
|
|
|
mGLContext = aGLContext;
|
|
|
|
}
|
|
|
|
|
|
|
|
hwc_display_t
|
2015-07-24 17:56:05 +00:00
|
|
|
nsScreenGonk::GetEGLDisplay()
|
2015-06-05 03:29:30 +00:00
|
|
|
{
|
2016-05-19 07:20:08 +00:00
|
|
|
MOZ_ASSERT(CompositorThreadHolder::IsInCompositorThread());
|
2015-07-24 17:56:05 +00:00
|
|
|
return mEGLDisplay;
|
2015-06-05 03:29:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
hwc_surface_t
|
2015-07-24 17:56:05 +00:00
|
|
|
nsScreenGonk::GetEGLSurface()
|
2015-06-05 03:29:30 +00:00
|
|
|
{
|
2016-05-19 07:20:08 +00:00
|
|
|
MOZ_ASSERT(CompositorThreadHolder::IsInCompositorThread());
|
2015-07-24 17:56:05 +00:00
|
|
|
return mEGLSurface;
|
2015-06-05 03:29:30 +00:00
|
|
|
}
|
|
|
|
|
2015-11-13 10:18:14 +00:00
|
|
|
already_AddRefed<mozilla::gl::GLContext>
|
|
|
|
nsScreenGonk::GetGLContext()
|
|
|
|
{
|
2016-05-19 07:20:08 +00:00
|
|
|
MOZ_ASSERT(CompositorThreadHolder::IsInCompositorThread());
|
2015-11-13 10:18:14 +00:00
|
|
|
RefPtr<mozilla::gl::GLContext>glContext = mGLContext;
|
|
|
|
return glContext.forget();
|
|
|
|
}
|
|
|
|
|
2015-08-08 20:50:47 +00:00
|
|
|
static void
|
2015-12-03 06:27:55 +00:00
|
|
|
UpdateMirroringWidgetSync(nsMainThreadPtrHandle<nsScreenGonk>&& aScreen, nsWindow* aWindow)
|
2015-11-03 00:50:45 +00:00
|
|
|
{
|
2016-05-19 07:20:08 +00:00
|
|
|
MOZ_ASSERT(CompositorThreadHolder::IsInCompositorThread());
|
2015-08-08 20:50:47 +00:00
|
|
|
already_AddRefed<nsWindow> window(aWindow);
|
|
|
|
aScreen->UpdateMirroringWidget(window);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
nsScreenGonk::EnableMirroring()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
MOZ_ASSERT(!IsPrimaryScreen());
|
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<nsScreenGonk> primaryScreen = nsScreenManagerGonk::GetPrimaryScreen();
|
2015-08-08 20:50:47 +00:00
|
|
|
NS_ENSURE_TRUE(primaryScreen, false);
|
|
|
|
|
|
|
|
bool ret = primaryScreen->SetMirroringScreen(this);
|
|
|
|
NS_ENSURE_TRUE(ret, false);
|
|
|
|
|
|
|
|
// Create a widget for mirroring
|
|
|
|
nsWidgetInitData initData;
|
|
|
|
initData.mScreenId = mId;
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<nsWindow> window = new nsWindow();
|
2016-08-19 14:47:42 +00:00
|
|
|
nsresult rv = window->Create(nullptr, nullptr, mNaturalBounds, &initData);
|
|
|
|
NS_ENSURE_SUCCESS(rv, false);
|
2015-08-08 20:50:47 +00:00
|
|
|
MOZ_ASSERT(static_cast<nsWindow*>(window)->GetScreen() == this);
|
|
|
|
|
|
|
|
// Update mMirroringWidget on compositor thread
|
2015-12-03 06:27:55 +00:00
|
|
|
nsMainThreadPtrHandle<nsScreenGonk> primary =
|
|
|
|
nsMainThreadPtrHandle<nsScreenGonk>(new nsMainThreadPtrHolder<nsScreenGonk>(primaryScreen, false));
|
2016-05-18 16:47:58 +00:00
|
|
|
CompositorThreadHolder::Loop()->PostTask(
|
2015-08-08 20:50:47 +00:00
|
|
|
NewRunnableFunction(&UpdateMirroringWidgetSync,
|
2015-12-03 06:27:55 +00:00
|
|
|
primary,
|
2015-08-08 20:50:47 +00:00
|
|
|
window.forget().take()));
|
|
|
|
|
|
|
|
mIsMirroring = true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
nsScreenGonk::DisableMirroring()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
MOZ_ASSERT(!IsPrimaryScreen());
|
|
|
|
|
|
|
|
mIsMirroring = false;
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<nsScreenGonk> primaryScreen = nsScreenManagerGonk::GetPrimaryScreen();
|
2015-08-08 20:50:47 +00:00
|
|
|
NS_ENSURE_TRUE(primaryScreen, false);
|
|
|
|
|
|
|
|
bool ret = primaryScreen->ClearMirroringScreen(this);
|
|
|
|
NS_ENSURE_TRUE(ret, false);
|
|
|
|
|
|
|
|
// Update mMirroringWidget on compositor thread
|
2015-12-03 06:27:55 +00:00
|
|
|
nsMainThreadPtrHandle<nsScreenGonk> primary =
|
|
|
|
nsMainThreadPtrHandle<nsScreenGonk>(new nsMainThreadPtrHolder<nsScreenGonk>(primaryScreen, false));
|
2016-05-18 16:47:58 +00:00
|
|
|
CompositorThreadHolder::Loop()->PostTask(
|
2015-08-08 20:50:47 +00:00
|
|
|
NewRunnableFunction(&UpdateMirroringWidgetSync,
|
2015-12-03 06:27:55 +00:00
|
|
|
primary,
|
2015-08-08 20:50:47 +00:00
|
|
|
nullptr));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
nsScreenGonk::SetMirroringScreen(nsScreenGonk* aScreen)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
MOZ_ASSERT(IsPrimaryScreen());
|
|
|
|
|
|
|
|
if (mMirroringScreen) {
|
|
|
|
return false;
|
|
|
|
}
|
2015-08-10 23:28:36 +00:00
|
|
|
mMirroringScreen = aScreen;
|
2015-08-08 20:50:47 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
nsScreenGonk::ClearMirroringScreen(nsScreenGonk* aScreen)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
MOZ_ASSERT(IsPrimaryScreen());
|
|
|
|
|
|
|
|
if (mMirroringScreen != aScreen) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
mMirroringScreen = nullptr;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsScreenGonk::UpdateMirroringWidget(already_AddRefed<nsWindow>& aWindow)
|
|
|
|
{
|
2016-05-19 07:20:08 +00:00
|
|
|
MOZ_ASSERT(CompositorThreadHolder::IsInCompositorThread());
|
2015-08-08 20:50:47 +00:00
|
|
|
MOZ_ASSERT(IsPrimaryScreen());
|
|
|
|
|
|
|
|
if (mMirroringWidget) {
|
|
|
|
nsCOMPtr<nsIWidget> widget = mMirroringWidget.forget();
|
2016-02-10 07:23:00 +00:00
|
|
|
NS_ReleaseOnMainThread(widget.forget());
|
2015-08-08 20:50:47 +00:00
|
|
|
}
|
|
|
|
mMirroringWidget = aWindow;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsWindow*
|
|
|
|
nsScreenGonk::GetMirroringWidget()
|
|
|
|
{
|
2016-05-19 07:20:08 +00:00
|
|
|
MOZ_ASSERT(CompositorThreadHolder::IsInCompositorThread());
|
2015-08-08 20:50:47 +00:00
|
|
|
MOZ_ASSERT(IsPrimaryScreen());
|
|
|
|
|
|
|
|
return mMirroringWidget;
|
|
|
|
}
|
|
|
|
|
2015-05-22 08:40:09 +00:00
|
|
|
NS_IMPL_ISUPPORTS(nsScreenManagerGonk, nsIScreenManager)
|
|
|
|
|
|
|
|
nsScreenManagerGonk::nsScreenManagerGonk()
|
|
|
|
: mInitialized(false)
|
2016-02-16 23:43:00 +00:00
|
|
|
#if ANDROID_VERSION >= 19
|
|
|
|
, mDisplayEnabled(false)
|
|
|
|
#endif
|
2015-05-22 08:40:09 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsScreenManagerGonk::~nsScreenManagerGonk()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-02-03 04:37:31 +00:00
|
|
|
static StaticRefPtr<nsScreenManagerGonk> sScreenManagerGonk;
|
|
|
|
|
2015-05-22 08:40:09 +00:00
|
|
|
/* static */ already_AddRefed<nsScreenManagerGonk>
|
|
|
|
nsScreenManagerGonk::GetInstance()
|
|
|
|
{
|
2016-02-03 04:37:31 +00:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
|
|
|
// Avoid creating nsScreenManagerGonk from content process.
|
|
|
|
if (!XRE_IsParentProcess()) {
|
|
|
|
MOZ_CRASH("Non-chrome processes should not get here.");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Avoid creating multiple nsScreenManagerGonk instance inside main process.
|
|
|
|
if (!sScreenManagerGonk) {
|
|
|
|
sScreenManagerGonk = new nsScreenManagerGonk();
|
|
|
|
ClearOnShutdown(&sScreenManagerGonk);
|
|
|
|
}
|
|
|
|
|
|
|
|
RefPtr<nsScreenManagerGonk> screenMgr = sScreenManagerGonk.get();
|
|
|
|
return screenMgr.forget();
|
2015-05-22 08:40:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* static */ already_AddRefed< nsScreenGonk>
|
|
|
|
nsScreenManagerGonk::GetPrimaryScreen()
|
|
|
|
{
|
2016-02-03 04:37:31 +00:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<nsScreenManagerGonk> manager = nsScreenManagerGonk::GetInstance();
|
2015-05-22 08:40:09 +00:00
|
|
|
nsCOMPtr<nsIScreen> screen;
|
|
|
|
manager->GetPrimaryScreen(getter_AddRefs(screen));
|
|
|
|
MOZ_ASSERT(screen);
|
|
|
|
return already_AddRefed<nsScreenGonk>(
|
|
|
|
static_cast<nsScreenGonk*>(screen.forget().take()));
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsScreenManagerGonk::Initialize()
|
|
|
|
{
|
|
|
|
if (mInitialized) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mScreenOnEvent = new ScreenOnOffEvent(true);
|
|
|
|
mScreenOffEvent = new ScreenOnOffEvent(false);
|
|
|
|
GetGonkDisplay()->OnEnabled(displayEnabledCallback);
|
|
|
|
|
2015-06-05 03:29:30 +00:00
|
|
|
AddScreen(GonkDisplay::DISPLAY_PRIMARY);
|
2015-05-22 08:40:09 +00:00
|
|
|
|
|
|
|
nsAppShell::NotifyScreenInitialized();
|
|
|
|
mInitialized = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsScreenManagerGonk::DisplayEnabled(bool aEnabled)
|
|
|
|
{
|
2016-02-16 23:43:00 +00:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
2016-01-19 19:58:00 +00:00
|
|
|
#if ANDROID_VERSION >= 19
|
2016-02-16 23:43:00 +00:00
|
|
|
/* Bug 1244044
|
|
|
|
* This function could be called before |mCompositorVsyncScheduler| is set.
|
|
|
|
* To avoid this issue, keep the value stored in |mDisplayEnabled|.
|
|
|
|
*/
|
|
|
|
mDisplayEnabled = aEnabled;
|
2016-01-19 19:58:00 +00:00
|
|
|
if (mCompositorVsyncScheduler) {
|
2016-02-16 23:43:00 +00:00
|
|
|
mCompositorVsyncScheduler->SetDisplay(mDisplayEnabled);
|
2016-01-19 19:58:00 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-08-24 15:27:23 +00:00
|
|
|
VsyncControl(aEnabled);
|
2015-05-22 08:40:09 +00:00
|
|
|
NS_DispatchToMainThread(aEnabled ? mScreenOnEvent : mScreenOffEvent);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsScreenManagerGonk::GetPrimaryScreen(nsIScreen **outScreen)
|
|
|
|
{
|
|
|
|
NS_IF_ADDREF(*outScreen = mScreens[0].get());
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsScreenManagerGonk::ScreenForId(uint32_t aId,
|
|
|
|
nsIScreen **outScreen)
|
|
|
|
{
|
|
|
|
for (size_t i = 0; i < mScreens.Length(); i++) {
|
|
|
|
if (mScreens[i]->GetId() == aId) {
|
|
|
|
NS_IF_ADDREF(*outScreen = mScreens[i].get());
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*outScreen = nullptr;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsScreenManagerGonk::ScreenForRect(int32_t inLeft,
|
|
|
|
int32_t inTop,
|
|
|
|
int32_t inWidth,
|
|
|
|
int32_t inHeight,
|
|
|
|
nsIScreen **outScreen)
|
|
|
|
{
|
|
|
|
// Since all screens have independent coordinate system, we could
|
|
|
|
// only return the primary screen no matter what rect is given.
|
|
|
|
return GetPrimaryScreen(outScreen);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsScreenManagerGonk::ScreenForNativeWidget(void *aWidget, nsIScreen **outScreen)
|
|
|
|
{
|
|
|
|
for (size_t i = 0; i < mScreens.Length(); i++) {
|
|
|
|
if (aWidget == mScreens[i]->GetNativeWindow()) {
|
|
|
|
NS_IF_ADDREF(*outScreen = mScreens[i].get());
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*outScreen = nullptr;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsScreenManagerGonk::GetNumberOfScreens(uint32_t *aNumberOfScreens)
|
|
|
|
{
|
|
|
|
*aNumberOfScreens = mScreens.Length();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsScreenManagerGonk::GetSystemDefaultScale(float *aDefaultScale)
|
|
|
|
{
|
|
|
|
*aDefaultScale = 1.0f;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsScreenManagerGonk::VsyncControl(bool aEnabled)
|
|
|
|
{
|
|
|
|
if (!NS_IsMainThread()) {
|
|
|
|
NS_DispatchToMainThread(
|
2016-05-18 16:25:35 +00:00
|
|
|
NewRunnableMethod<bool>(this,
|
|
|
|
&nsScreenManagerGonk::VsyncControl,
|
|
|
|
aEnabled));
|
2015-05-22 08:40:09 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
VsyncSource::Display &display = gfxPlatform::GetPlatform()->GetHardwareVsync()->GetGlobalDisplay();
|
|
|
|
if (aEnabled) {
|
|
|
|
display.EnableVsync();
|
|
|
|
} else {
|
|
|
|
display.DisableVsync();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t
|
2015-06-05 03:29:30 +00:00
|
|
|
nsScreenManagerGonk::GetIdFromType(GonkDisplay::DisplayType aDisplayType)
|
2015-05-22 08:40:09 +00:00
|
|
|
{
|
|
|
|
// This is the only place where we make the assumption that
|
|
|
|
// display type is equivalent to screen id.
|
|
|
|
|
|
|
|
// Bug 1138287 will address the conversion from type to id.
|
|
|
|
return aDisplayType;
|
|
|
|
}
|
|
|
|
|
2015-06-05 03:29:30 +00:00
|
|
|
bool
|
|
|
|
nsScreenManagerGonk::IsScreenConnected(uint32_t aId)
|
|
|
|
{
|
|
|
|
for (size_t i = 0; i < mScreens.Length(); ++i) {
|
|
|
|
if (mScreens[i]->GetId() == aId) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
// A concrete class as a subject for 'display-changed' observer event.
|
|
|
|
class DisplayInfo : public nsIDisplayInfo {
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
|
|
|
DisplayInfo(uint32_t aId, bool aConnected)
|
|
|
|
: mId(aId)
|
|
|
|
, mConnected(aConnected)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP GetId(int32_t *aId)
|
|
|
|
{
|
|
|
|
*aId = mId;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP GetConnected(bool *aConnected)
|
|
|
|
{
|
|
|
|
*aConnected = mConnected;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
virtual ~DisplayInfo() {}
|
|
|
|
|
|
|
|
uint32_t mId;
|
|
|
|
bool mConnected;
|
|
|
|
};
|
|
|
|
|
|
|
|
NS_IMPL_ISUPPORTS(DisplayInfo, nsIDisplayInfo, nsISupports)
|
|
|
|
|
2016-04-27 10:05:40 +00:00
|
|
|
class NotifyTask : public mozilla::Runnable {
|
2015-06-05 03:29:30 +00:00
|
|
|
public:
|
|
|
|
NotifyTask(uint32_t aId, bool aConnected)
|
|
|
|
: mDisplayInfo(new DisplayInfo(aId, aConnected))
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-08-08 02:18:10 +00:00
|
|
|
NS_IMETHOD Run() override
|
2015-06-05 03:29:30 +00:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService();
|
|
|
|
if (os) {
|
|
|
|
os->NotifyObservers(mDisplayInfo, "display-changed", nullptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
private:
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<DisplayInfo> mDisplayInfo;
|
2015-06-05 03:29:30 +00:00
|
|
|
};
|
|
|
|
|
2015-05-22 08:40:09 +00:00
|
|
|
void
|
2015-06-05 03:29:30 +00:00
|
|
|
NotifyDisplayChange(uint32_t aId, bool aConnected)
|
|
|
|
{
|
|
|
|
NS_DispatchToMainThread(new NotifyTask(aId, aConnected));
|
|
|
|
}
|
|
|
|
|
|
|
|
} // end of unnamed namespace.
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsScreenManagerGonk::AddScreen(GonkDisplay::DisplayType aDisplayType,
|
2015-11-13 05:09:58 +00:00
|
|
|
android::IGraphicBufferProducer* aSink,
|
|
|
|
NotifyDisplayChangedEvent aEventVisibility)
|
2015-05-22 08:40:09 +00:00
|
|
|
{
|
2015-06-05 03:29:30 +00:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
|
|
|
NS_ENSURE_TRUE(aDisplayType < GonkDisplay::DisplayType::NUM_DISPLAY_TYPES,
|
|
|
|
NS_ERROR_FAILURE);
|
2015-05-22 08:40:09 +00:00
|
|
|
|
|
|
|
uint32_t id = GetIdFromType(aDisplayType);
|
2015-06-05 03:29:30 +00:00
|
|
|
NS_ENSURE_TRUE(!IsScreenConnected(id), NS_ERROR_FAILURE);
|
2015-05-22 08:40:09 +00:00
|
|
|
|
2015-06-05 03:29:30 +00:00
|
|
|
GonkDisplay::NativeData nativeData =
|
2015-08-08 20:50:47 +00:00
|
|
|
GetGonkDisplay()->GetNativeData(aDisplayType, aSink);
|
2015-11-13 05:09:58 +00:00
|
|
|
nsScreenGonk* screen = new nsScreenGonk(id,
|
|
|
|
aDisplayType,
|
|
|
|
nativeData,
|
|
|
|
aEventVisibility);
|
2015-05-22 08:40:09 +00:00
|
|
|
mScreens.AppendElement(screen);
|
2015-06-05 03:29:30 +00:00
|
|
|
|
2015-11-13 05:09:58 +00:00
|
|
|
if (aEventVisibility == NotifyDisplayChangedEvent::Observable) {
|
|
|
|
NotifyDisplayChange(id, true);
|
|
|
|
}
|
2015-06-05 03:29:30 +00:00
|
|
|
|
2015-08-08 20:50:47 +00:00
|
|
|
// By default, non primary screen does mirroring.
|
|
|
|
if (aDisplayType != GonkDisplay::DISPLAY_PRIMARY &&
|
|
|
|
gfxPrefs::ScreenMirroringEnabled()) {
|
|
|
|
screen->EnableMirroring();
|
|
|
|
}
|
|
|
|
|
2015-06-05 03:29:30 +00:00
|
|
|
return NS_OK;
|
2015-05-22 08:40:09 +00:00
|
|
|
}
|
|
|
|
|
2015-06-05 03:29:30 +00:00
|
|
|
nsresult
|
|
|
|
nsScreenManagerGonk::RemoveScreen(GonkDisplay::DisplayType aDisplayType)
|
2015-05-22 08:40:09 +00:00
|
|
|
{
|
2015-06-05 03:29:30 +00:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
|
|
|
NS_ENSURE_TRUE(aDisplayType < GonkDisplay::DisplayType::NUM_DISPLAY_TYPES,
|
|
|
|
NS_ERROR_FAILURE);
|
|
|
|
|
2015-11-13 05:09:58 +00:00
|
|
|
NotifyDisplayChangedEvent eventVisibility = NotifyDisplayChangedEvent::Observable;
|
2015-05-22 08:40:09 +00:00
|
|
|
uint32_t screenId = GetIdFromType(aDisplayType);
|
2015-06-05 03:29:30 +00:00
|
|
|
NS_ENSURE_TRUE(IsScreenConnected(screenId), NS_ERROR_FAILURE);
|
|
|
|
|
2015-05-22 08:40:09 +00:00
|
|
|
for (size_t i = 0; i < mScreens.Length(); i++) {
|
|
|
|
if (mScreens[i]->GetId() == screenId) {
|
2015-08-08 20:50:47 +00:00
|
|
|
if (mScreens[i]->IsMirroring()) {
|
|
|
|
mScreens[i]->DisableMirroring();
|
|
|
|
}
|
2015-11-13 05:09:58 +00:00
|
|
|
eventVisibility = mScreens[i]->GetEventVisibility();
|
2015-05-22 08:40:09 +00:00
|
|
|
mScreens.RemoveElementAt(i);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2015-06-05 03:29:30 +00:00
|
|
|
|
2015-11-13 05:09:58 +00:00
|
|
|
if (eventVisibility == NotifyDisplayChangedEvent::Observable) {
|
|
|
|
NotifyDisplayChange(screenId, false);
|
|
|
|
}
|
2015-06-05 03:29:30 +00:00
|
|
|
return NS_OK;
|
2015-05-22 08:40:09 +00:00
|
|
|
}
|
2016-01-19 19:58:00 +00:00
|
|
|
|
|
|
|
#if ANDROID_VERSION >= 19
|
|
|
|
void
|
|
|
|
nsScreenManagerGonk::SetCompositorVsyncScheduler(mozilla::layers::CompositorVsyncScheduler *aObserver)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
2016-03-22 18:08:38 +00:00
|
|
|
// We assume on b2g that there is only 1 CompositorBridgeParent
|
2016-01-19 19:58:00 +00:00
|
|
|
MOZ_ASSERT(mCompositorVsyncScheduler == nullptr);
|
2016-02-16 23:43:00 +00:00
|
|
|
MOZ_ASSERT(aObserver);
|
2016-01-19 19:58:00 +00:00
|
|
|
mCompositorVsyncScheduler = aObserver;
|
2016-02-16 23:43:00 +00:00
|
|
|
mCompositorVsyncScheduler->SetDisplay(mDisplayEnabled);
|
2016-01-19 19:58:00 +00:00
|
|
|
}
|
|
|
|
#endif
|