mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-11 10:08:41 +00:00
Bug 1157874 - Remove screen related global variables from nsWindow.cpp r=mwu
This commit is contained in:
parent
fee82dca85
commit
ed293afca5
@ -986,7 +986,8 @@ DisableScreenConfigurationNotifications()
|
||||
void
|
||||
GetCurrentScreenConfiguration(hal::ScreenConfiguration* aScreenConfiguration)
|
||||
{
|
||||
*aScreenConfiguration = nsScreenGonk::GetConfiguration();
|
||||
nsRefPtr<nsScreenGonk> screen = nsScreenManagerGonk::GetPrimaryScreen();
|
||||
*aScreenConfiguration = screen->GetConfiguration();
|
||||
}
|
||||
|
||||
bool
|
||||
|
@ -575,18 +575,25 @@ GeckoInputReaderPolicy::setDisplayInfo()
|
||||
DISPLAY_ORIENTATION_270,
|
||||
"Orientation enums not matched!");
|
||||
|
||||
nsRefPtr<nsScreenGonk> screen = nsScreenManagerGonk::GetPrimaryScreen();
|
||||
|
||||
uint32_t rotation = nsIScreen::ROTATION_0_DEG;
|
||||
nsresult rv = screen->GetRotation(&rotation);
|
||||
MOZ_ASSERT(NS_SUCCEEDED(rv));
|
||||
nsIntRect screenBounds = screen->GetNaturalBounds();
|
||||
|
||||
DisplayViewport viewport;
|
||||
viewport.displayId = 0;
|
||||
viewport.orientation = nsScreenGonk::GetRotation();
|
||||
viewport.physicalRight = viewport.deviceWidth = gScreenBounds.width;
|
||||
viewport.physicalBottom = viewport.deviceHeight = gScreenBounds.height;
|
||||
viewport.orientation = rotation;
|
||||
viewport.physicalRight = viewport.deviceWidth = screenBounds.width;
|
||||
viewport.physicalBottom = viewport.deviceHeight = screenBounds.height;
|
||||
if (viewport.orientation == DISPLAY_ORIENTATION_90 ||
|
||||
viewport.orientation == DISPLAY_ORIENTATION_270) {
|
||||
viewport.logicalRight = gScreenBounds.height;
|
||||
viewport.logicalBottom = gScreenBounds.width;
|
||||
viewport.logicalRight = screenBounds.height;
|
||||
viewport.logicalBottom = screenBounds.width;
|
||||
} else {
|
||||
viewport.logicalRight = gScreenBounds.width;
|
||||
viewport.logicalBottom = gScreenBounds.height;
|
||||
viewport.logicalRight = screenBounds.width;
|
||||
viewport.logicalBottom = screenBounds.height;
|
||||
}
|
||||
mConfig.setDisplayInfo(false, viewport);
|
||||
}
|
||||
@ -1053,5 +1060,6 @@ nsAppShell::NotifyScreenRotation()
|
||||
gAppShell->mReaderPolicy->setDisplayInfo();
|
||||
gAppShell->mReader->requestRefreshConfiguration(InputReaderConfiguration::CHANGE_DISPLAY_INFO);
|
||||
|
||||
hal::NotifyScreenConfigurationChange(nsScreenGonk::GetConfiguration());
|
||||
nsRefPtr<nsScreenGonk> screen = nsScreenManagerGonk::GetPrimaryScreen();
|
||||
hal::NotifyScreenConfigurationChange(screen->GetConfiguration());
|
||||
}
|
||||
|
@ -23,12 +23,15 @@
|
||||
#include "nsBaseScreen.h"
|
||||
#include "nsIScreenManager.h"
|
||||
|
||||
class nsRunnable;
|
||||
class nsWindow;
|
||||
|
||||
class nsScreenGonk : public nsBaseScreen
|
||||
{
|
||||
typedef mozilla::hal::ScreenConfiguration ScreenConfiguration;
|
||||
|
||||
public:
|
||||
nsScreenGonk(void* nativeScreen);
|
||||
nsScreenGonk();
|
||||
~nsScreenGonk();
|
||||
|
||||
NS_IMETHOD GetId(uint32_t* aId);
|
||||
@ -39,8 +42,25 @@ public:
|
||||
NS_IMETHOD GetRotation(uint32_t* aRotation);
|
||||
NS_IMETHOD SetRotation(uint32_t aRotation);
|
||||
|
||||
static uint32_t GetRotation();
|
||||
static ScreenConfiguration GetConfiguration();
|
||||
nsIntRect GetNaturalBounds();
|
||||
uint32_t EffectiveScreenRotation();
|
||||
ScreenConfiguration GetConfiguration();
|
||||
|
||||
void RegisterWindow(nsWindow* aWindow);
|
||||
void UnregisterWindow(nsWindow* aWindow);
|
||||
void BringToTop(nsWindow* aWindow);
|
||||
|
||||
const nsTArray<nsWindow*>& GetTopWindows() const
|
||||
{
|
||||
return mTopWindows;
|
||||
}
|
||||
|
||||
protected:
|
||||
nsIntRect mScreenBounds;
|
||||
nsIntRect mVirtualBounds;
|
||||
uint32_t mScreenRotation;
|
||||
uint32_t mPhysicalScreenRotation;
|
||||
nsTArray<nsWindow*> mTopWindows;
|
||||
};
|
||||
|
||||
class nsScreenManagerGonk final : public nsIScreenManager
|
||||
@ -51,10 +71,19 @@ public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSISCREENMANAGER
|
||||
|
||||
static already_AddRefed<nsScreenManagerGonk> GetInstance();
|
||||
static already_AddRefed<nsScreenGonk> GetPrimaryScreen();
|
||||
|
||||
void Initialize();
|
||||
void DisplayEnabled(bool aEnabled);
|
||||
|
||||
protected:
|
||||
~nsScreenManagerGonk();
|
||||
|
||||
bool mInitialized;
|
||||
nsCOMPtr<nsIScreen> mOneScreen;
|
||||
nsRefPtr<nsRunnable> mScreenOnEvent;
|
||||
nsRefPtr<nsRunnable> mScreenOffEvent;
|
||||
};
|
||||
|
||||
#endif /* nsScreenManagerGonk_h___ */
|
||||
|
@ -71,23 +71,10 @@ using namespace mozilla::gl;
|
||||
using namespace mozilla::layers;
|
||||
using namespace mozilla::widget;
|
||||
|
||||
nsIntRect gScreenBounds;
|
||||
static uint32_t sScreenRotation;
|
||||
static uint32_t sPhysicalScreenRotation;
|
||||
static nsIntRect sVirtualBounds;
|
||||
|
||||
static nsTArray<nsWindow *> sTopWindows;
|
||||
static nsWindow *gFocusedWindow = nullptr;
|
||||
static bool sScreenInitialized;
|
||||
|
||||
namespace {
|
||||
|
||||
static uint32_t
|
||||
EffectiveScreenRotation()
|
||||
{
|
||||
return (sScreenRotation + sPhysicalScreenRotation) % (360 / 90);
|
||||
}
|
||||
|
||||
class ScreenOnOffEvent : public nsRunnable {
|
||||
public:
|
||||
ScreenOnOffEvent(bool on)
|
||||
@ -102,8 +89,11 @@ public:
|
||||
ProcessPriorityManager::Freeze();
|
||||
}
|
||||
|
||||
for (uint32_t i = 0; i < sTopWindows.Length(); i++) {
|
||||
nsWindow *win = sTopWindows[i];
|
||||
nsRefPtr<nsScreenGonk> screen = nsScreenManagerGonk::GetPrimaryScreen();
|
||||
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);
|
||||
@ -126,14 +116,11 @@ private:
|
||||
bool mIsOn;
|
||||
};
|
||||
|
||||
static StaticRefPtr<ScreenOnOffEvent> sScreenOnEvent;
|
||||
static StaticRefPtr<ScreenOnOffEvent> sScreenOffEvent;
|
||||
|
||||
static void
|
||||
displayEnabledCallback(bool enabled)
|
||||
{
|
||||
HwcComposer2D::GetInstance()->EnableVsync(enabled);
|
||||
NS_DispatchToMainThread(enabled ? sScreenOnEvent : sScreenOffEvent);
|
||||
nsRefPtr<nsScreenManagerGonk> screenManager = nsScreenManagerGonk::GetInstance();
|
||||
screenManager->DisplayEnabled(enabled);
|
||||
}
|
||||
|
||||
} // anonymous namespace
|
||||
@ -144,34 +131,9 @@ nsWindow::nsWindow()
|
||||
{
|
||||
mFramebuffer = nullptr;
|
||||
|
||||
if (sScreenInitialized)
|
||||
return;
|
||||
|
||||
sScreenOnEvent = new ScreenOnOffEvent(true);
|
||||
ClearOnShutdown(&sScreenOnEvent);
|
||||
sScreenOffEvent = new ScreenOnOffEvent(false);
|
||||
ClearOnShutdown(&sScreenOffEvent);
|
||||
GetGonkDisplay()->OnEnabled(displayEnabledCallback);
|
||||
|
||||
nsIntSize screenSize;
|
||||
|
||||
ANativeWindow *win = GetGonkDisplay()->GetNativeWindow();
|
||||
|
||||
if (win->query(win, NATIVE_WINDOW_WIDTH, &screenSize.width) ||
|
||||
win->query(win, NATIVE_WINDOW_HEIGHT, &screenSize.height)) {
|
||||
NS_RUNTIMEABORT("Failed to get native window size, aborting...");
|
||||
}
|
||||
gScreenBounds = gfx::IntRect(gfx::IntPoint(0, 0), screenSize);
|
||||
|
||||
char propValue[PROPERTY_VALUE_MAX];
|
||||
property_get("ro.sf.hwrotation", propValue, "0");
|
||||
sPhysicalScreenRotation = atoi(propValue) / 90;
|
||||
|
||||
sVirtualBounds = gScreenBounds;
|
||||
|
||||
sScreenInitialized = true;
|
||||
|
||||
nsAppShell::NotifyScreenInitialized();
|
||||
nsRefPtr<nsScreenManagerGonk> screenManager = nsScreenManagerGonk::GetInstance();
|
||||
screenManager->Initialize();
|
||||
mScreen = nsScreenManagerGonk::GetPrimaryScreen();
|
||||
|
||||
// This is a hack to force initialization of the compositor
|
||||
// resources, if we're going to use omtc.
|
||||
@ -198,14 +160,18 @@ nsWindow::DoDraw(void)
|
||||
return;
|
||||
}
|
||||
|
||||
if (sTopWindows.IsEmpty()) {
|
||||
nsRefPtr<nsScreenGonk> screen = nsScreenManagerGonk::GetPrimaryScreen();
|
||||
const nsTArray<nsWindow*>& windows = screen->GetTopWindows();
|
||||
|
||||
if (windows.IsEmpty()) {
|
||||
LOG(" no window to draw, bailing");
|
||||
return;
|
||||
}
|
||||
|
||||
nsWindow *targetWindow = (nsWindow *)sTopWindows[0];
|
||||
while (targetWindow->GetLastChild())
|
||||
nsWindow *targetWindow = (nsWindow *)windows[0];
|
||||
while (targetWindow->GetLastChild()) {
|
||||
targetWindow = (nsWindow *)targetWindow->GetLastChild();
|
||||
}
|
||||
|
||||
nsIWidgetListener* listener = targetWindow->GetWidgetListener();
|
||||
if (listener) {
|
||||
@ -214,7 +180,7 @@ nsWindow::DoDraw(void)
|
||||
|
||||
LayerManager* lm = targetWindow->GetLayerManager();
|
||||
if (mozilla::layers::LayersBackend::LAYERS_CLIENT == lm->GetBackendType()) {
|
||||
// No need to do anything, the compositor will handle drawing
|
||||
// No need to do anything, the compositor will handle drawing
|
||||
} else {
|
||||
NS_RUNTIMEABORT("Unexpected layer manager type");
|
||||
}
|
||||
@ -228,7 +194,7 @@ nsWindow::DoDraw(void)
|
||||
void
|
||||
nsWindow::ConfigureAPZControllerThread()
|
||||
{
|
||||
APZThreadUtils::SetControllerThread(CompositorParent::CompositorLoop());
|
||||
APZThreadUtils::SetControllerThread(CompositorParent::CompositorLoop());
|
||||
}
|
||||
|
||||
/*static*/ nsEventStatus
|
||||
@ -430,7 +396,10 @@ nsWindow::Create(nsIWidget *aParent,
|
||||
const nsIntRect &aRect,
|
||||
nsWidgetInitData *aInitData)
|
||||
{
|
||||
BaseCreate(aParent, IS_TOPLEVEL() ? sVirtualBounds : aRect,
|
||||
nsIntRect virtualBounds;
|
||||
mScreen->GetRect(&virtualBounds.x, &virtualBounds.y,
|
||||
&virtualBounds.width, &virtualBounds.height);
|
||||
BaseCreate(aParent, IS_TOPLEVEL() ? virtualBounds : aRect,
|
||||
aInitData);
|
||||
|
||||
mBounds = aRect;
|
||||
@ -439,15 +408,16 @@ nsWindow::Create(nsIWidget *aParent,
|
||||
mVisible = false;
|
||||
|
||||
if (!aParent) {
|
||||
mBounds = sVirtualBounds;
|
||||
mBounds = virtualBounds;
|
||||
}
|
||||
|
||||
if (!IS_TOPLEVEL())
|
||||
if (!IS_TOPLEVEL()) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
sTopWindows.AppendElement(this);
|
||||
mScreen->RegisterWindow(this);
|
||||
|
||||
Resize(0, 0, sVirtualBounds.width, sVirtualBounds.height, false);
|
||||
Resize(0, 0, virtualBounds.width, virtualBounds.height, false);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
@ -455,9 +425,10 @@ NS_IMETHODIMP
|
||||
nsWindow::Destroy(void)
|
||||
{
|
||||
mOnDestroyCalled = true;
|
||||
sTopWindows.RemoveElement(this);
|
||||
if (this == gFocusedWindow)
|
||||
mScreen->UnregisterWindow(this);
|
||||
if (this == gFocusedWindow) {
|
||||
gFocusedWindow = nullptr;
|
||||
}
|
||||
nsBaseWidget::OnDestroy();
|
||||
return NS_OK;
|
||||
}
|
||||
@ -465,24 +436,29 @@ nsWindow::Destroy(void)
|
||||
NS_IMETHODIMP
|
||||
nsWindow::Show(bool aState)
|
||||
{
|
||||
if (mWindowType == eWindowType_invisible)
|
||||
if (mWindowType == eWindowType_invisible) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
if (mVisible == aState)
|
||||
if (mVisible == aState) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
mVisible = aState;
|
||||
if (!IS_TOPLEVEL())
|
||||
if (!IS_TOPLEVEL()) {
|
||||
return mParent ? mParent->Show(aState) : NS_OK;
|
||||
}
|
||||
|
||||
if (aState) {
|
||||
BringToTop();
|
||||
} else {
|
||||
for (unsigned int i = 0; i < sTopWindows.Length(); i++) {
|
||||
nsWindow *win = sTopWindows[i];
|
||||
if (!win->mVisible)
|
||||
const nsTArray<nsWindow*>& windows =
|
||||
mScreen->GetTopWindows();
|
||||
for (unsigned int i = 0; i < windows.Length(); i++) {
|
||||
nsWindow *win = windows[i];
|
||||
if (!win->mVisible) {
|
||||
continue;
|
||||
|
||||
}
|
||||
win->BringToTop();
|
||||
break;
|
||||
}
|
||||
@ -529,11 +505,16 @@ nsWindow::Resize(double aX,
|
||||
{
|
||||
mBounds = nsIntRect(NSToIntRound(aX), NSToIntRound(aY),
|
||||
NSToIntRound(aWidth), NSToIntRound(aHeight));
|
||||
if (mWidgetListener)
|
||||
if (mWidgetListener) {
|
||||
mWidgetListener->WindowResized(this, mBounds.width, mBounds.height);
|
||||
}
|
||||
|
||||
if (aRepaint)
|
||||
Invalidate(sVirtualBounds);
|
||||
if (aRepaint) {
|
||||
nsIntRect virtualBounds;
|
||||
mScreen->GetRect(&virtualBounds.x, &virtualBounds.y,
|
||||
&virtualBounds.width, &virtualBounds.height);
|
||||
Invalidate(virtualBounds);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
@ -553,9 +534,9 @@ nsWindow::IsEnabled() const
|
||||
NS_IMETHODIMP
|
||||
nsWindow::SetFocus(bool aRaise)
|
||||
{
|
||||
if (aRaise)
|
||||
if (aRaise) {
|
||||
BringToTop();
|
||||
|
||||
}
|
||||
gFocusedWindow = this;
|
||||
return NS_OK;
|
||||
}
|
||||
@ -570,10 +551,13 @@ NS_IMETHODIMP
|
||||
nsWindow::Invalidate(const nsIntRect &aRect)
|
||||
{
|
||||
nsWindow *top = mParent;
|
||||
while (top && top->mParent)
|
||||
while (top && top->mParent) {
|
||||
top = top->mParent;
|
||||
if (top != sTopWindows[0] && this != sTopWindows[0])
|
||||
}
|
||||
const nsTArray<nsWindow*>& windows = mScreen->GetTopWindows();
|
||||
if (top != windows[0] && this != windows[0]) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
gDrawRequest = true;
|
||||
mozilla::NotifyEvent();
|
||||
@ -626,8 +610,9 @@ nsWindow::SetNativeData(uint32_t aDataType, uintptr_t aVal)
|
||||
NS_IMETHODIMP
|
||||
nsWindow::DispatchEvent(WidgetGUIEvent* aEvent, nsEventStatus& aStatus)
|
||||
{
|
||||
if (mWidgetListener)
|
||||
if (mWidgetListener) {
|
||||
aStatus = mWidgetListener->HandleEvent(aEvent, mUseAttachedEvents);
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
@ -667,8 +652,11 @@ nsWindow::MakeFullScreen(bool aFullScreen, nsIScreen*)
|
||||
// toplevel widget, so it doesn't make sense to ever "exit"
|
||||
// fullscreen. If we do, we can leave parts of the screen
|
||||
// unpainted.
|
||||
Resize(sVirtualBounds.x, sVirtualBounds.y,
|
||||
sVirtualBounds.width, sVirtualBounds.height,
|
||||
nsIntRect virtualBounds;
|
||||
mScreen->GetRect(&virtualBounds.x, &virtualBounds.y,
|
||||
&virtualBounds.width, &virtualBounds.height);
|
||||
Resize(virtualBounds.x, virtualBounds.y,
|
||||
virtualBounds.width, virtualBounds.height,
|
||||
/*repaint*/true);
|
||||
}
|
||||
return NS_OK;
|
||||
@ -785,16 +773,18 @@ nsWindow::GetLayerManager(PLayerTransactionChild* aShadowManager,
|
||||
LayerManagerPersistence aPersistence,
|
||||
bool* aAllowRetaining)
|
||||
{
|
||||
if (aAllowRetaining)
|
||||
if (aAllowRetaining) {
|
||||
*aAllowRetaining = true;
|
||||
}
|
||||
if (mLayerManager) {
|
||||
// This layer manager might be used for painting outside of DoDraw(), so we need
|
||||
// to set the correct rotation on it.
|
||||
if (mLayerManager->GetBackendType() == LayersBackend::LAYERS_CLIENT) {
|
||||
ClientLayerManager* manager =
|
||||
static_cast<ClientLayerManager*>(mLayerManager.get());
|
||||
uint32_t rotation = mScreen->EffectiveScreenRotation();
|
||||
manager->SetDefaultTargetConfiguration(mozilla::layers::BufferMode::BUFFER_NONE,
|
||||
ScreenRotation(EffectiveScreenRotation()));
|
||||
ScreenRotation(rotation));
|
||||
}
|
||||
return mLayerManager;
|
||||
}
|
||||
@ -802,7 +792,9 @@ nsWindow::GetLayerManager(PLayerTransactionChild* aShadowManager,
|
||||
// Set mUseLayersAcceleration here to make it consistent with
|
||||
// nsBaseWidget::GetLayerManager
|
||||
mUseLayersAcceleration = ComputeShouldAccelerate(mUseLayersAcceleration);
|
||||
nsWindow *topWindow = sTopWindows[0];
|
||||
|
||||
const nsTArray<nsWindow*>& windows = mScreen->GetTopWindows();
|
||||
nsWindow *topWindow = windows[0];
|
||||
|
||||
if (!topWindow) {
|
||||
LOGW(" -- no topwindow\n");
|
||||
@ -820,17 +812,23 @@ nsWindow::GetLayerManager(PLayerTransactionChild* aShadowManager,
|
||||
void
|
||||
nsWindow::BringToTop()
|
||||
{
|
||||
if (!sTopWindows.IsEmpty()) {
|
||||
if (nsIWidgetListener* listener = sTopWindows[0]->GetWidgetListener())
|
||||
const nsTArray<nsWindow*>& windows = mScreen->GetTopWindows();
|
||||
if (!windows.IsEmpty()) {
|
||||
if (nsIWidgetListener* listener = windows[0]->GetWidgetListener()) {
|
||||
listener->WindowDeactivated();
|
||||
}
|
||||
}
|
||||
|
||||
sTopWindows.RemoveElement(this);
|
||||
sTopWindows.InsertElementAt(0, this);
|
||||
mScreen->BringToTop(this);
|
||||
|
||||
if (mWidgetListener)
|
||||
if (mWidgetListener) {
|
||||
mWidgetListener->WindowActivated();
|
||||
Invalidate(sVirtualBounds);
|
||||
}
|
||||
|
||||
nsIntRect virtualBounds;
|
||||
mScreen->GetRect(&virtualBounds.x, &virtualBounds.y,
|
||||
&virtualBounds.width, &virtualBounds.height);
|
||||
Invalidate(virtualBounds);
|
||||
}
|
||||
|
||||
void
|
||||
@ -860,7 +858,7 @@ nsWindow::GetGLFrameBufferFormat()
|
||||
nsIntRect
|
||||
nsWindow::GetNaturalBounds()
|
||||
{
|
||||
return gScreenBounds;
|
||||
return mScreen->GetNaturalBounds();
|
||||
}
|
||||
|
||||
bool
|
||||
@ -880,8 +878,24 @@ nsWindow::GetComposer2D()
|
||||
|
||||
// nsScreenGonk.cpp
|
||||
|
||||
nsScreenGonk::nsScreenGonk(void *nativeScreen)
|
||||
nsScreenGonk::nsScreenGonk()
|
||||
: mScreenRotation(nsIScreen::ROTATION_0_DEG)
|
||||
, mPhysicalScreenRotation(nsIScreen::ROTATION_0_DEG)
|
||||
{
|
||||
nsIntSize screenSize;
|
||||
|
||||
ANativeWindow *win = GetGonkDisplay()->GetNativeWindow();
|
||||
if (win->query(win, NATIVE_WINDOW_WIDTH, &screenSize.width) ||
|
||||
win->query(win, NATIVE_WINDOW_HEIGHT, &screenSize.height)) {
|
||||
NS_RUNTIMEABORT("Failed to get native window size, aborting...");
|
||||
}
|
||||
mScreenBounds = gfx::IntRect(gfx::IntPoint(0, 0), screenSize);
|
||||
|
||||
char propValue[PROPERTY_VALUE_MAX];
|
||||
property_get("ro.sf.hwrotation", propValue, "0");
|
||||
mPhysicalScreenRotation = atoi(propValue) / 90;
|
||||
|
||||
mVirtualBounds = mScreenBounds;
|
||||
}
|
||||
|
||||
nsScreenGonk::~nsScreenGonk()
|
||||
@ -899,11 +913,11 @@ NS_IMETHODIMP
|
||||
nsScreenGonk::GetRect(int32_t *outLeft, int32_t *outTop,
|
||||
int32_t *outWidth, int32_t *outHeight)
|
||||
{
|
||||
*outLeft = sVirtualBounds.x;
|
||||
*outTop = sVirtualBounds.y;
|
||||
*outLeft = mVirtualBounds.x;
|
||||
*outTop = mVirtualBounds.y;
|
||||
|
||||
*outWidth = sVirtualBounds.width;
|
||||
*outHeight = sVirtualBounds.height;
|
||||
*outWidth = mVirtualBounds.width;
|
||||
*outHeight = mVirtualBounds.height;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
@ -945,39 +959,55 @@ nsScreenGonk::GetColorDepth(int32_t *aColorDepth)
|
||||
NS_IMETHODIMP
|
||||
nsScreenGonk::GetRotation(uint32_t* aRotation)
|
||||
{
|
||||
*aRotation = sScreenRotation;
|
||||
*aRotation = mScreenRotation;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsScreenGonk::SetRotation(uint32_t aRotation)
|
||||
{
|
||||
if (!(aRotation <= ROTATION_270_DEG))
|
||||
if (!(aRotation <= ROTATION_270_DEG)) {
|
||||
return NS_ERROR_ILLEGAL_VALUE;
|
||||
}
|
||||
|
||||
if (sScreenRotation == aRotation)
|
||||
if (mScreenRotation == aRotation) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
sScreenRotation = aRotation;
|
||||
mScreenRotation = aRotation;
|
||||
uint32_t rotation = EffectiveScreenRotation();
|
||||
if (rotation == nsIScreen::ROTATION_90_DEG ||
|
||||
rotation == nsIScreen::ROTATION_270_DEG) {
|
||||
sVirtualBounds = nsIntRect(0, 0, gScreenBounds.height,
|
||||
gScreenBounds.width);
|
||||
mVirtualBounds = nsIntRect(0, 0,
|
||||
mScreenBounds.height,
|
||||
mScreenBounds.width);
|
||||
} else {
|
||||
sVirtualBounds = gScreenBounds;
|
||||
mVirtualBounds = mScreenBounds;
|
||||
}
|
||||
|
||||
nsAppShell::NotifyScreenRotation();
|
||||
|
||||
for (unsigned int i = 0; i < sTopWindows.Length(); i++)
|
||||
sTopWindows[i]->Resize(sVirtualBounds.width,
|
||||
sVirtualBounds.height,
|
||||
true);
|
||||
for (unsigned int i = 0; i < mTopWindows.Length(); i++) {
|
||||
mTopWindows[i]->Resize(mVirtualBounds.width,
|
||||
mVirtualBounds.height,
|
||||
true);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsIntRect
|
||||
nsScreenGonk::GetNaturalBounds()
|
||||
{
|
||||
return mScreenBounds;
|
||||
}
|
||||
|
||||
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.
|
||||
static ScreenOrientation
|
||||
@ -986,53 +1016,110 @@ ComputeOrientation(uint32_t aRotation, const nsIntSize& aScreenSize)
|
||||
bool naturallyPortrait = (aScreenSize.height > aScreenSize.width);
|
||||
switch (aRotation) {
|
||||
case nsIScreen::ROTATION_0_DEG:
|
||||
return (naturallyPortrait ? eScreenOrientation_PortraitPrimary :
|
||||
return (naturallyPortrait ? eScreenOrientation_PortraitPrimary :
|
||||
eScreenOrientation_LandscapePrimary);
|
||||
case nsIScreen::ROTATION_90_DEG:
|
||||
// Arbitrarily choosing 90deg to be primary "unnatural"
|
||||
// rotation.
|
||||
return (naturallyPortrait ? eScreenOrientation_LandscapePrimary :
|
||||
return (naturallyPortrait ? eScreenOrientation_LandscapePrimary :
|
||||
eScreenOrientation_PortraitPrimary);
|
||||
case nsIScreen::ROTATION_180_DEG:
|
||||
return (naturallyPortrait ? eScreenOrientation_PortraitSecondary :
|
||||
return (naturallyPortrait ? eScreenOrientation_PortraitSecondary :
|
||||
eScreenOrientation_LandscapeSecondary);
|
||||
case nsIScreen::ROTATION_270_DEG:
|
||||
return (naturallyPortrait ? eScreenOrientation_LandscapeSecondary :
|
||||
return (naturallyPortrait ? eScreenOrientation_LandscapeSecondary :
|
||||
eScreenOrientation_PortraitSecondary);
|
||||
default:
|
||||
MOZ_CRASH("Gonk screen must always have a known rotation");
|
||||
}
|
||||
}
|
||||
|
||||
/*static*/ uint32_t
|
||||
nsScreenGonk::GetRotation()
|
||||
{
|
||||
return sScreenRotation;
|
||||
}
|
||||
|
||||
/*static*/ ScreenConfiguration
|
||||
ScreenConfiguration
|
||||
nsScreenGonk::GetConfiguration()
|
||||
{
|
||||
ScreenOrientation orientation = ComputeOrientation(sScreenRotation,
|
||||
gScreenBounds.Size());
|
||||
ScreenOrientation orientation = ComputeOrientation(mScreenRotation,
|
||||
mScreenBounds.Size());
|
||||
uint32_t colorDepth = ColorDepth();
|
||||
// NB: perpetuating colorDepth == pixelDepth illusion here, for
|
||||
// consistency.
|
||||
return ScreenConfiguration(sVirtualBounds, orientation,
|
||||
return ScreenConfiguration(mVirtualBounds, orientation,
|
||||
colorDepth, colorDepth);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS(nsScreenManagerGonk, nsIScreenManager)
|
||||
|
||||
nsScreenManagerGonk::nsScreenManagerGonk()
|
||||
: mInitialized(false)
|
||||
{
|
||||
mOneScreen = new nsScreenGonk(nullptr);
|
||||
mOneScreen = new nsScreenGonk();
|
||||
}
|
||||
|
||||
nsScreenManagerGonk::~nsScreenManagerGonk()
|
||||
{
|
||||
}
|
||||
|
||||
/* static */ already_AddRefed<nsScreenManagerGonk>
|
||||
nsScreenManagerGonk::GetInstance()
|
||||
{
|
||||
nsCOMPtr<nsIScreenManager> manager;
|
||||
manager = do_GetService("@mozilla.org/gfx/screenmanager;1");
|
||||
MOZ_ASSERT(manager);
|
||||
return already_AddRefed<nsScreenManagerGonk>(
|
||||
static_cast<nsScreenManagerGonk*>(manager.forget().take()));
|
||||
}
|
||||
|
||||
/* static */ already_AddRefed< nsScreenGonk>
|
||||
nsScreenManagerGonk::GetPrimaryScreen()
|
||||
{
|
||||
nsRefPtr<nsScreenManagerGonk> manager = nsScreenManagerGonk::GetInstance();
|
||||
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);
|
||||
|
||||
nsAppShell::NotifyScreenInitialized();
|
||||
mInitialized = true;
|
||||
}
|
||||
|
||||
void
|
||||
nsScreenManagerGonk::DisplayEnabled(bool aEnabled)
|
||||
{
|
||||
HwcComposer2D::GetInstance()->EnableVsync(aEnabled);
|
||||
NS_DispatchToMainThread(aEnabled ? mScreenOnEvent : mScreenOffEvent);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsScreenManagerGonk::GetPrimaryScreen(nsIScreen **outScreen)
|
||||
{
|
||||
|
@ -22,7 +22,6 @@
|
||||
#include "nsIIdleServiceInternal.h"
|
||||
#include "Units.h"
|
||||
|
||||
extern nsIntRect gScreenBounds;
|
||||
class ANativeWindowBuffer;
|
||||
|
||||
namespace widget {
|
||||
@ -30,6 +29,8 @@ struct InputContext;
|
||||
struct InputContextAction;
|
||||
}
|
||||
|
||||
class nsScreenGonk;
|
||||
|
||||
class nsWindow : public nsBaseWidget
|
||||
{
|
||||
public:
|
||||
@ -154,6 +155,8 @@ private:
|
||||
// This is used by SynthesizeNativeTouchPoint to maintain state between
|
||||
// multiple synthesized points
|
||||
nsAutoPtr<mozilla::MultiTouchInput> mSynthesizedTouchInput;
|
||||
|
||||
nsRefPtr<nsScreenGonk> mScreen;
|
||||
};
|
||||
|
||||
#endif /* nsWindow_h */
|
||||
|
Loading…
x
Reference in New Issue
Block a user