Bug 745145, part 2: Implement the ScreenConfiguration hal for gonk. r=mounir

This commit is contained in:
Chris Jones 2012-05-08 14:36:07 -07:00
Родитель b689e2f633
Коммит 9699c13cf3
6 изменённых файлов: 125 добавлений и 26 удалений

Просмотреть файл

@ -138,10 +138,12 @@ endif #}
# Fallbacks for backends implemented on Android only.
ifneq (android,$(MOZ_WIDGET_TOOLKIT))
CPPSRCS += \
FallbackNetwork.cpp \
FallbackScreenOrientation.cpp \
$(NULL)
CPPSRCS += FallbackNetwork.cpp
endif
# Fallbacks for backends implemented on Gonk and Android only.
ifeq (,$(filter android gonk,$(MOZ_WIDGET_TOOLKIT)))
CPPSRCS += FallbackScreenOrientation.cpp
endif
include $(topsrcdir)/config/config.mk
@ -150,3 +152,9 @@ include $(topsrcdir)/config/rules.mk
CFLAGS += $(MOZ_DBUS_GLIB_CFLAGS)
CXXFLAGS += $(MOZ_DBUS_GLIB_CFLAGS)
ifeq (gonk,$(MOZ_WIDGET_TOOLKIT))
# So that we can call nsScreenManagerGonk::GetConfiguration().
LOCAL_INCLUDES += -I$(topsrcdir)/widget/gonk
LOCAL_INCLUDES += -I$(topsrcdir)/widget/xpwidgets
endif

Просмотреть файл

@ -4,35 +4,38 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "base/message_loop.h"
#include <errno.h>
#include <fcntl.h>
#include <math.h>
#include <stdio.h>
#include <sys/syscall.h>
#include <time.h>
#include "android/log.h"
#include "cutils/properties.h"
#include "hardware/hardware.h"
#include "hardware/lights.h"
#include "hardware_legacy/uevent.h"
#include "hardware_legacy/vibrator.h"
#include "base/message_loop.h"
#include "Hal.h"
#include "HalImpl.h"
#include "mozilla/dom/battery/Constants.h"
#include "mozilla/FileUtils.h"
#include "nsAlgorithm.h"
#include "nsThreadUtils.h"
#include "mozilla/Monitor.h"
#include "mozilla/Services.h"
#include "mozilla/FileUtils.h"
#include "nsThreadUtils.h"
#include "nsIRunnable.h"
#include "nsIThread.h"
#include "nsAlgorithm.h"
#include "nsIObserver.h"
#include "nsIObserverService.h"
#include "nsIRunnable.h"
#include "nsScreenManagerGonk.h"
#include "nsThreadUtils.h"
#include "nsThreadUtils.h"
#include "nsIThread.h"
#include "nsXULAppAPI.h"
#include "hardware/lights.h"
#include "hardware/hardware.h"
#include "hardware_legacy/vibrator.h"
#include "UeventPoller.h"
#include <stdio.h>
#include <math.h>
#include <fcntl.h>
#include <errno.h>
#include <time.h>
#include <sys/syscall.h>
#include <cutils/properties.h>
#include <android/log.h>
#define LOG(args...) __android_log_print(ANDROID_LOG_INFO, "Gonk", args)
#define NsecPerMsec 1000000
@ -592,5 +595,36 @@ SetTimezone(const nsCString& aTimezoneSpec)
tzset();
}
// Nothing to do here. Gonk widgetry always listens for screen
// orientation changes.
void
EnableScreenConfigurationNotifications()
{
}
void
DisableScreenConfigurationNotifications()
{
}
void
GetCurrentScreenConfiguration(hal::ScreenConfiguration* aScreenConfiguration)
{
*aScreenConfiguration = nsScreenGonk::GetConfiguration();
}
bool
LockScreenOrientation(const dom::ScreenOrientation& aOrientation)
{
// FIXME/bug 743638: implement
return false;
}
void
UnlockScreenOrientation()
{
// FIXME/bug 743638: implement
}
} // hal_impl
} // mozilla

Просмотреть файл

@ -80,9 +80,10 @@
(void)0
#endif
using namespace mozilla;
using namespace android;
using namespace hal;
using namespace mozilla;
using namespace mozilla::dom;
using namespace mozilla::hal;
bool gDrawRequest = false;
static nsAppShell *gAppShell = NULL;
@ -710,4 +711,6 @@ nsAppShell::NotifyScreenRotation()
{
gAppShell->mReaderPolicy->setDisplayInfo();
gAppShell->mReader->requestRefreshConfiguration(InputReaderConfiguration::CHANGE_DISPLAY_INFO);
hal::NotifyScreenConfigurationChange(nsScreenGonk::GetConfiguration());
}

Просмотреть файл

@ -39,6 +39,7 @@
#ifndef nsScreenManagerGonk_h___
#define nsScreenManagerGonk_h___
#include "mozilla/Hal.h"
#include "nsCOMPtr.h"
#include "nsBaseScreen.h"
@ -46,6 +47,8 @@
class nsScreenGonk : public nsBaseScreen
{
typedef mozilla::hal::ScreenConfiguration ScreenConfiguration;
public:
nsScreenGonk(void* nativeScreen);
~nsScreenGonk();
@ -58,6 +61,7 @@ public:
NS_IMETHOD SetRotation(PRUint32 aRotation);
static uint32_t GetRotation();
static ScreenConfiguration GetConfiguration();
};
class nsScreenManagerGonk : public nsIScreenManager

Просмотреть файл

@ -36,6 +36,8 @@
*
* ***** END LICENSE BLOCK ***** */
#include "base/basictypes.h"
#include "mozilla/ModuleUtils.h"
#include "nsCOMPtr.h"

Просмотреть файл

@ -62,6 +62,8 @@
#define IS_TOPLEVEL() (mWindowType == eWindowType_toplevel || mWindowType == eWindowType_dialog)
using namespace mozilla;
using namespace mozilla::dom;
using namespace mozilla::hal;
using namespace mozilla::gl;
using namespace mozilla::layers;
using namespace mozilla::widget;
@ -611,11 +613,18 @@ nsScreenGonk::GetAvailRect(PRInt32 *outLeft, PRInt32 *outTop,
return GetRect(outLeft, outTop, outWidth, outHeight);
}
static uint32_t
ColorDepth()
{
return gNativeWindow->getDevice()->format == GGL_PIXEL_FORMAT_RGB_565 ? 16 : 24;
}
NS_IMETHODIMP
nsScreenGonk::GetPixelDepth(PRInt32 *aPixelDepth)
{
*aPixelDepth = gNativeWindow->getDevice()->format == GGL_PIXEL_FORMAT_RGB_565 ? 16 : 24;
// XXX: this should actually return 32 when we're using 24-bit
// color, because we use RGBX.
*aPixelDepth = ColorDepth();
return NS_OK;
}
@ -680,12 +689,51 @@ nsScreenGonk::SetRotation(PRUint32 aRotation)
return NS_OK;
}
uint32_t
// NB: This isn't gonk-specific, but gonk is the only widget backend
// that does this calculation itself, currently.
static ScreenOrientation
ComputeOrientation(uint32_t aRotation, const nsIntSize& aScreenSize)
{
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_NOT_REACHED("Gonk screen must always have a known rotation");
return eScreenOrientation_None;
}
}
/*static*/ uint32_t
nsScreenGonk::GetRotation()
{
return sScreenRotation;
}
/*static*/ ScreenConfiguration
nsScreenGonk::GetConfiguration()
{
ScreenOrientation orientation = ComputeOrientation(sScreenRotation,
gScreenBounds.Size());
uint32_t colorDepth = ColorDepth();
// NB: perpetuating colorDepth == pixelDepth illusion here, for
// consistency.
return ScreenConfiguration(sVirtualBounds, orientation,
colorDepth, colorDepth);
}
NS_IMPL_ISUPPORTS1(nsScreenManagerGonk, nsIScreenManager)
nsScreenManagerGonk::nsScreenManagerGonk()