2012-07-20 13:10:44 +04: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.
|
|
|
|
*/
|
2011-11-11 04:17:46 +04:00
|
|
|
|
2012-12-15 03:58:45 +04:00
|
|
|
#include "mozilla/DebugOnly.h"
|
|
|
|
|
2012-04-05 10:03:00 +04:00
|
|
|
#include <fcntl.h>
|
2011-12-24 11:13:33 +04:00
|
|
|
|
|
|
|
#include "android/log.h"
|
2011-11-11 04:17:46 +04:00
|
|
|
|
2012-09-12 00:05:52 +04:00
|
|
|
#include "mozilla/dom/TabParent.h"
|
2012-01-17 14:55:25 +04:00
|
|
|
#include "mozilla/Hal.h"
|
2012-04-05 20:15:19 +04:00
|
|
|
#include "mozilla/Preferences.h"
|
2012-04-05 10:03:00 +04:00
|
|
|
#include "mozilla/FileUtils.h"
|
2011-12-24 11:13:33 +04:00
|
|
|
#include "Framebuffer.h"
|
|
|
|
#include "gfxContext.h"
|
2012-08-19 23:33:25 +04:00
|
|
|
#include "gfxPlatform.h"
|
2011-12-24 11:13:33 +04:00
|
|
|
#include "gfxUtils.h"
|
2011-11-11 04:17:46 +04:00
|
|
|
#include "GLContextProvider.h"
|
2011-12-24 11:13:33 +04:00
|
|
|
#include "LayerManagerOGL.h"
|
|
|
|
#include "nsAutoPtr.h"
|
|
|
|
#include "nsAppShell.h"
|
2012-01-11 06:07:00 +04:00
|
|
|
#include "nsIdleService.h"
|
2012-02-07 02:47:11 +04:00
|
|
|
#include "nsScreenManagerGonk.h"
|
|
|
|
#include "nsTArray.h"
|
2011-12-24 11:13:33 +04:00
|
|
|
#include "nsWindow.h"
|
2012-08-15 22:52:42 +04:00
|
|
|
#include "nsIWidgetListener.h"
|
2012-05-23 23:35:13 +04:00
|
|
|
#include "cutils/properties.h"
|
2013-05-01 09:03:25 +04:00
|
|
|
#include "ClientLayerManager.h"
|
2012-07-31 04:42:26 +04:00
|
|
|
#include "BasicLayers.h"
|
2013-05-08 07:58:22 +04:00
|
|
|
#include "libdisplay/GonkDisplay.h"
|
|
|
|
#include "pixelflinger/format.h"
|
|
|
|
|
|
|
|
#if ANDROID_VERSION == 15
|
|
|
|
#include "HwcComposer2D.h"
|
|
|
|
#endif
|
2011-11-11 04:17:46 +04:00
|
|
|
|
|
|
|
#define LOG(args...) __android_log_print(ANDROID_LOG_INFO, "Gonk" , ## args)
|
2012-07-07 18:07:00 +04:00
|
|
|
#define LOGW(args...) __android_log_print(ANDROID_LOG_WARN, "Gonk", ## args)
|
|
|
|
#define LOGE(args...) __android_log_print(ANDROID_LOG_ERROR, "Gonk", ## args)
|
2011-11-11 04:17:46 +04:00
|
|
|
|
|
|
|
#define IS_TOPLEVEL() (mWindowType == eWindowType_toplevel || mWindowType == eWindowType_dialog)
|
|
|
|
|
2011-12-24 11:13:33 +04:00
|
|
|
using namespace mozilla;
|
2012-05-09 01:36:07 +04:00
|
|
|
using namespace mozilla::dom;
|
|
|
|
using namespace mozilla::hal;
|
2011-11-11 04:17:46 +04:00
|
|
|
using namespace mozilla::gl;
|
|
|
|
using namespace mozilla::layers;
|
2011-12-16 03:38:45 +04:00
|
|
|
using namespace mozilla::widget;
|
2011-11-11 04:17:46 +04:00
|
|
|
|
|
|
|
nsIntRect gScreenBounds;
|
2012-02-07 05:47:11 +04:00
|
|
|
static uint32_t sScreenRotation;
|
2012-05-23 23:35:13 +04:00
|
|
|
static uint32_t sPhysicalScreenRotation;
|
2012-02-07 05:47:11 +04:00
|
|
|
static nsIntRect sVirtualBounds;
|
|
|
|
static gfxMatrix sRotationMatrix;
|
2011-11-11 04:17:46 +04:00
|
|
|
|
|
|
|
static nsRefPtr<GLContext> sGLContext;
|
|
|
|
static nsTArray<nsWindow *> sTopWindows;
|
2012-07-30 18:20:58 +04:00
|
|
|
static nsWindow *gWindowToRedraw = nullptr;
|
|
|
|
static nsWindow *gFocusedWindow = nullptr;
|
2011-12-24 11:13:33 +04:00
|
|
|
static bool sFramebufferOpen;
|
2012-04-05 20:15:19 +04:00
|
|
|
static bool sUsingOMTC;
|
2012-11-19 21:58:38 +04:00
|
|
|
static bool sUsingHwc;
|
2012-06-26 18:38:50 +04:00
|
|
|
static bool sScreenInitialized;
|
2012-04-05 20:15:19 +04:00
|
|
|
static nsRefPtr<gfxASurface> sOMTCSurface;
|
2012-04-26 12:46:52 +04:00
|
|
|
static pthread_t sFramebufferWatchThread;
|
2012-04-05 10:03:00 +04:00
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
static uint32_t
|
2012-07-24 23:01:09 +04:00
|
|
|
EffectiveScreenRotation()
|
|
|
|
{
|
|
|
|
return (sScreenRotation + sPhysicalScreenRotation) % (360 / 90);
|
|
|
|
}
|
|
|
|
|
2012-04-05 10:03:00 +04:00
|
|
|
class ScreenOnOffEvent : public nsRunnable {
|
|
|
|
public:
|
|
|
|
ScreenOnOffEvent(bool on)
|
|
|
|
: mIsOn(on)
|
|
|
|
{}
|
|
|
|
|
|
|
|
NS_IMETHOD Run() {
|
2012-08-22 19:56:38 +04:00
|
|
|
for (uint32_t i = 0; i < sTopWindows.Length(); i++) {
|
2012-04-05 10:03:00 +04:00
|
|
|
nsWindow *win = sTopWindows[i];
|
2012-08-15 22:52:42 +04:00
|
|
|
|
|
|
|
if (nsIWidgetListener* listener = win->GetWidgetListener()) {
|
|
|
|
listener->SizeModeChanged(mIsOn ? nsSizeMode_Fullscreen : nsSizeMode_Minimized);
|
|
|
|
}
|
2012-04-05 10:03:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
bool mIsOn;
|
|
|
|
};
|
|
|
|
|
|
|
|
static const char* kSleepFile = "/sys/power/wait_for_fb_sleep";
|
|
|
|
static const char* kWakeFile = "/sys/power/wait_for_fb_wake";
|
|
|
|
|
2012-04-26 12:46:52 +04:00
|
|
|
static void *frameBufferWatcher(void *) {
|
2012-04-05 10:03:00 +04:00
|
|
|
|
2012-04-26 12:46:52 +04:00
|
|
|
char buf;
|
2013-03-27 19:19:09 +04:00
|
|
|
bool ret;
|
2012-04-05 10:03:00 +04:00
|
|
|
|
2012-04-26 12:46:52 +04:00
|
|
|
nsRefPtr<ScreenOnOffEvent> mScreenOnEvent = new ScreenOnOffEvent(true);
|
|
|
|
nsRefPtr<ScreenOnOffEvent> mScreenOffEvent = new ScreenOnOffEvent(false);
|
|
|
|
|
|
|
|
while (true) {
|
2012-04-05 10:03:00 +04:00
|
|
|
// Cannot use epoll here because kSleepFile and kWakeFile are
|
|
|
|
// always ready to read and blocking.
|
2013-03-27 19:19:09 +04:00
|
|
|
ret = ReadSysFile(kSleepFile, &buf, sizeof(buf));
|
|
|
|
NS_WARN_IF_FALSE(ret, "WAIT_FOR_FB_SLEEP failed");
|
|
|
|
NS_DispatchToMainThread(mScreenOffEvent);
|
2012-04-05 10:03:00 +04:00
|
|
|
|
2013-03-27 19:19:09 +04:00
|
|
|
ret = ReadSysFile(kWakeFile, &buf, sizeof(buf));
|
|
|
|
NS_WARN_IF_FALSE(ret, "WAIT_FOR_FB_WAKE failed");
|
|
|
|
NS_DispatchToMainThread(mScreenOnEvent);
|
2012-04-05 10:03:00 +04:00
|
|
|
}
|
2012-07-31 04:42:26 +04:00
|
|
|
|
2012-04-26 12:46:52 +04:00
|
|
|
return NULL;
|
|
|
|
}
|
2012-04-05 10:03:00 +04:00
|
|
|
|
|
|
|
} // anonymous namespace
|
2011-11-11 04:17:46 +04:00
|
|
|
|
|
|
|
nsWindow::nsWindow()
|
|
|
|
{
|
2012-06-26 18:38:50 +04:00
|
|
|
if (!sScreenInitialized) {
|
2012-04-26 12:46:52 +04:00
|
|
|
// Watching screen on/off state by using a pthread
|
|
|
|
// which implicitly calls exit() when the main thread ends
|
|
|
|
if (pthread_create(&sFramebufferWatchThread, NULL, frameBufferWatcher, NULL)) {
|
|
|
|
NS_RUNTIMEABORT("Failed to create framebufferWatcherThread, aborting...");
|
|
|
|
}
|
2012-04-05 10:03:00 +04:00
|
|
|
|
2012-06-26 18:38:50 +04:00
|
|
|
nsIntSize screenSize;
|
2012-12-08 04:02:48 +04:00
|
|
|
bool gotFB = Framebuffer::GetSize(&screenSize);
|
|
|
|
if (!gotFB) {
|
|
|
|
NS_RUNTIMEABORT("Failed to get size from framebuffer, aborting...");
|
|
|
|
}
|
2012-06-26 18:38:50 +04:00
|
|
|
gScreenBounds = nsIntRect(nsIntPoint(0, 0), screenSize);
|
2012-05-23 23:35:13 +04:00
|
|
|
|
|
|
|
char propValue[PROPERTY_VALUE_MAX];
|
|
|
|
property_get("ro.sf.hwrotation", propValue, "0");
|
|
|
|
sPhysicalScreenRotation = atoi(propValue) / 90;
|
|
|
|
|
|
|
|
// Unlike nsScreenGonk::SetRotation(), only support 0 and 180 as there
|
|
|
|
// are no known screens that are mounted at 90 or 270 at the moment.
|
|
|
|
switch (sPhysicalScreenRotation) {
|
|
|
|
case nsIScreen::ROTATION_0_DEG:
|
|
|
|
break;
|
|
|
|
case nsIScreen::ROTATION_180_DEG:
|
|
|
|
sRotationMatrix.Translate(gfxPoint(gScreenBounds.width,
|
|
|
|
gScreenBounds.height));
|
|
|
|
sRotationMatrix.Rotate(M_PI);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
MOZ_NOT_REACHED("Unknown rotation");
|
|
|
|
break;
|
|
|
|
}
|
2012-02-07 05:47:11 +04:00
|
|
|
sVirtualBounds = gScreenBounds;
|
2012-03-25 14:06:02 +04:00
|
|
|
|
2012-06-26 18:38:50 +04:00
|
|
|
sScreenInitialized = true;
|
|
|
|
|
2012-03-25 14:06:02 +04:00
|
|
|
nsAppShell::NotifyScreenInitialized();
|
2012-07-13 19:25:29 +04:00
|
|
|
|
|
|
|
// This is a hack to force initialization of the compositor
|
|
|
|
// resources, if we're going to use omtc.
|
|
|
|
//
|
|
|
|
// NB: GetPlatform() will create the gfxPlatform, which wants
|
|
|
|
// to know the color depth, which asks our native window.
|
|
|
|
// This has to happen after other init has finished.
|
|
|
|
gfxPlatform::GetPlatform();
|
2013-03-04 22:32:20 +04:00
|
|
|
sUsingOMTC = ShouldUseOffMainThreadCompositing();
|
2013-05-10 01:40:46 +04:00
|
|
|
|
|
|
|
property_get("ro.display.colorfill", propValue, "0");
|
|
|
|
sUsingHwc = Preferences::GetBool("layers.composer2d.enabled",
|
|
|
|
atoi(propValue) == 1);
|
2012-07-13 19:25:29 +04:00
|
|
|
|
|
|
|
if (sUsingOMTC) {
|
|
|
|
sOMTCSurface = new gfxImageSurface(gfxIntSize(1, 1),
|
|
|
|
gfxASurface::ImageFormatRGB24);
|
|
|
|
}
|
2011-11-11 04:17:46 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsWindow::~nsWindow()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsWindow::DoDraw(void)
|
|
|
|
{
|
2012-01-17 14:55:25 +04:00
|
|
|
if (!hal::GetScreenEnabled()) {
|
|
|
|
gDrawRequest = true;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-12-24 11:13:33 +04:00
|
|
|
if (!gWindowToRedraw) {
|
|
|
|
LOG(" no window to draw, bailing");
|
2011-11-11 04:17:46 +04:00
|
|
|
return;
|
2011-12-24 11:13:33 +04:00
|
|
|
}
|
2011-11-11 04:17:46 +04:00
|
|
|
|
2012-08-15 22:52:42 +04:00
|
|
|
nsIntRegion region = gWindowToRedraw->mDirtyRegion;
|
2011-12-30 03:01:51 +04:00
|
|
|
gWindowToRedraw->mDirtyRegion.SetEmpty();
|
2011-12-24 11:13:33 +04:00
|
|
|
|
2013-01-28 23:34:03 +04:00
|
|
|
nsIWidgetListener* listener = gWindowToRedraw->GetWidgetListener();
|
|
|
|
if (listener) {
|
2013-01-28 23:34:08 +04:00
|
|
|
listener->WillPaintWindow(gWindowToRedraw);
|
2013-01-28 23:34:03 +04:00
|
|
|
}
|
|
|
|
|
2011-12-24 11:13:33 +04:00
|
|
|
LayerManager* lm = gWindowToRedraw->GetLayerManager();
|
2012-07-18 20:31:40 +04:00
|
|
|
if (mozilla::layers::LAYERS_OPENGL == lm->GetBackendType()) {
|
2012-02-07 05:47:11 +04:00
|
|
|
LayerManagerOGL* oglm = static_cast<LayerManagerOGL*>(lm);
|
2012-08-15 22:52:42 +04:00
|
|
|
oglm->SetClippingRegion(region);
|
2012-02-07 05:47:11 +04:00
|
|
|
oglm->SetWorldTransform(sRotationMatrix);
|
2012-08-15 22:52:42 +04:00
|
|
|
|
2013-01-28 23:34:03 +04:00
|
|
|
listener = gWindowToRedraw->GetWidgetListener();
|
|
|
|
if (listener) {
|
2013-01-28 23:34:06 +04:00
|
|
|
listener->PaintWindow(gWindowToRedraw, region, 0);
|
2013-01-28 23:34:03 +04:00
|
|
|
}
|
2013-05-01 09:03:25 +04:00
|
|
|
} else if (mozilla::layers::LAYERS_CLIENT == lm->GetBackendType()) {
|
|
|
|
// No need to do anything, the compositor will handle drawing
|
2012-07-18 20:31:40 +04:00
|
|
|
} else if (mozilla::layers::LAYERS_BASIC == lm->GetBackendType()) {
|
2012-04-05 20:15:19 +04:00
|
|
|
MOZ_ASSERT(sFramebufferOpen || sUsingOMTC);
|
|
|
|
nsRefPtr<gfxASurface> targetSurface;
|
|
|
|
|
|
|
|
if(sUsingOMTC)
|
|
|
|
targetSurface = sOMTCSurface;
|
|
|
|
else
|
|
|
|
targetSurface = Framebuffer::BackBuffer();
|
2011-12-24 11:13:33 +04:00
|
|
|
|
|
|
|
{
|
2012-04-05 20:15:19 +04:00
|
|
|
nsRefPtr<gfxContext> ctx = new gfxContext(targetSurface);
|
2012-08-15 22:52:42 +04:00
|
|
|
gfxUtils::PathFromRegion(ctx, region);
|
2011-12-24 11:13:33 +04:00
|
|
|
ctx->Clip();
|
|
|
|
|
|
|
|
// No double-buffering needed.
|
|
|
|
AutoLayerManagerSetup setupLayerManager(
|
2012-07-31 04:42:26 +04:00
|
|
|
gWindowToRedraw, ctx, mozilla::layers::BUFFER_NONE,
|
2012-07-24 23:01:09 +04:00
|
|
|
ScreenRotation(EffectiveScreenRotation()));
|
2012-08-15 22:52:42 +04:00
|
|
|
|
2013-01-28 23:34:03 +04:00
|
|
|
listener = gWindowToRedraw->GetWidgetListener();
|
|
|
|
if (listener) {
|
2013-01-28 23:34:06 +04:00
|
|
|
listener->PaintWindow(gWindowToRedraw, region, 0);
|
2013-01-28 23:34:03 +04:00
|
|
|
}
|
2011-12-24 11:13:33 +04:00
|
|
|
}
|
|
|
|
|
2012-04-05 20:15:19 +04:00
|
|
|
if (!sUsingOMTC) {
|
|
|
|
targetSurface->Flush();
|
2012-08-15 22:52:42 +04:00
|
|
|
Framebuffer::Present(region);
|
2012-04-05 20:15:19 +04:00
|
|
|
}
|
2011-12-24 11:13:33 +04:00
|
|
|
} else {
|
|
|
|
NS_RUNTIMEABORT("Unexpected layer manager type");
|
|
|
|
}
|
2013-01-28 23:34:03 +04:00
|
|
|
|
|
|
|
listener = gWindowToRedraw->GetWidgetListener();
|
|
|
|
if (listener) {
|
|
|
|
listener->DidPaintWindow();
|
|
|
|
}
|
2011-11-11 04:17:46 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsEventStatus
|
2012-09-12 00:05:52 +04:00
|
|
|
nsWindow::DispatchInputEvent(nsGUIEvent &aEvent, bool* aWasCaptured)
|
2011-11-11 04:17:46 +04:00
|
|
|
{
|
2012-09-12 00:05:52 +04:00
|
|
|
if (aWasCaptured) {
|
|
|
|
*aWasCaptured = false;
|
|
|
|
}
|
|
|
|
if (!gFocusedWindow) {
|
2011-11-11 04:17:46 +04:00
|
|
|
return nsEventStatus_eIgnore;
|
2012-09-12 00:05:52 +04:00
|
|
|
}
|
2011-11-11 04:17:46 +04:00
|
|
|
|
2012-01-11 06:07:00 +04:00
|
|
|
gFocusedWindow->UserActivity();
|
2012-08-15 22:53:09 +04:00
|
|
|
|
2012-08-16 04:54:18 +04:00
|
|
|
aEvent.widget = gFocusedWindow;
|
2012-09-12 00:05:52 +04:00
|
|
|
|
|
|
|
if (TabParent* capturer = TabParent::GetEventCapturer()) {
|
|
|
|
bool captured = capturer->TryCapture(aEvent);
|
|
|
|
if (aWasCaptured) {
|
|
|
|
*aWasCaptured = captured;
|
|
|
|
}
|
|
|
|
if (captured) {
|
|
|
|
return nsEventStatus_eConsumeNoDefault;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsEventStatus status;
|
2012-08-15 22:53:09 +04:00
|
|
|
gFocusedWindow->DispatchEvent(&aEvent, status);
|
|
|
|
return status;
|
2011-11-11 04:17:46 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindow::Create(nsIWidget *aParent,
|
|
|
|
void *aNativeParent,
|
|
|
|
const nsIntRect &aRect,
|
|
|
|
nsDeviceContext *aContext,
|
|
|
|
nsWidgetInitData *aInitData)
|
|
|
|
{
|
2012-02-07 05:47:11 +04:00
|
|
|
BaseCreate(aParent, IS_TOPLEVEL() ? sVirtualBounds : aRect,
|
2012-08-15 22:53:09 +04:00
|
|
|
aContext, aInitData);
|
2011-11-11 04:17:46 +04:00
|
|
|
|
|
|
|
mBounds = aRect;
|
|
|
|
|
|
|
|
nsWindow *parent = (nsWindow *)aNativeParent;
|
|
|
|
mParent = parent;
|
2012-06-12 12:00:21 +04:00
|
|
|
mVisible = false;
|
2011-11-11 04:17:46 +04:00
|
|
|
|
|
|
|
if (!aNativeParent) {
|
2012-02-07 05:47:11 +04:00
|
|
|
mBounds = sVirtualBounds;
|
2011-11-11 04:17:46 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!IS_TOPLEVEL())
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
sTopWindows.AppendElement(this);
|
|
|
|
|
2012-02-07 05:47:11 +04:00
|
|
|
Resize(0, 0, sVirtualBounds.width, sVirtualBounds.height, false);
|
2011-11-11 04:17:46 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindow::Destroy(void)
|
|
|
|
{
|
|
|
|
sTopWindows.RemoveElement(this);
|
|
|
|
if (this == gWindowToRedraw)
|
2012-07-30 18:20:58 +04:00
|
|
|
gWindowToRedraw = nullptr;
|
2011-11-11 04:17:46 +04:00
|
|
|
if (this == gFocusedWindow)
|
2012-07-30 18:20:58 +04:00
|
|
|
gFocusedWindow = nullptr;
|
2011-11-11 04:17:46 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindow::Show(bool aState)
|
|
|
|
{
|
2011-11-22 23:51:52 +04:00
|
|
|
if (mWindowType == eWindowType_invisible)
|
2011-11-11 04:17:46 +04:00
|
|
|
return NS_OK;
|
|
|
|
|
2012-01-06 01:23:34 +04:00
|
|
|
if (mVisible == aState)
|
|
|
|
return NS_OK;
|
|
|
|
|
2011-11-22 23:51:52 +04:00
|
|
|
mVisible = aState;
|
|
|
|
if (!IS_TOPLEVEL())
|
|
|
|
return mParent ? mParent->Show(aState) : NS_OK;
|
|
|
|
|
2012-01-06 01:23:34 +04:00
|
|
|
if (aState) {
|
2011-11-11 04:17:46 +04:00
|
|
|
BringToTop();
|
2012-01-06 01:23:34 +04:00
|
|
|
} else {
|
|
|
|
for (unsigned int i = 0; i < sTopWindows.Length(); i++) {
|
|
|
|
nsWindow *win = sTopWindows[i];
|
|
|
|
if (!win->mVisible)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
win->BringToTop();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2011-11-11 04:17:46 +04:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-07-19 12:57:50 +04:00
|
|
|
bool
|
|
|
|
nsWindow::IsVisible() const
|
2011-11-11 04:17:46 +04:00
|
|
|
{
|
2012-07-19 12:57:50 +04:00
|
|
|
return mVisible;
|
2011-11-11 04:17:46 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindow::ConstrainPosition(bool aAllowSlop,
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t *aX,
|
|
|
|
int32_t *aY)
|
2011-11-11 04:17:46 +04:00
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-12-12 13:57:38 +04:00
|
|
|
nsWindow::Move(double aX,
|
|
|
|
double aY)
|
2011-11-11 04:17:46 +04:00
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-12-12 13:57:38 +04:00
|
|
|
nsWindow::Resize(double aWidth,
|
|
|
|
double aHeight,
|
|
|
|
bool aRepaint)
|
2011-11-11 04:17:46 +04:00
|
|
|
{
|
|
|
|
return Resize(0, 0, aWidth, aHeight, aRepaint);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-12-12 13:57:38 +04:00
|
|
|
nsWindow::Resize(double aX,
|
|
|
|
double aY,
|
|
|
|
double aWidth,
|
|
|
|
double aHeight,
|
|
|
|
bool aRepaint)
|
2011-11-11 04:17:46 +04:00
|
|
|
{
|
2012-12-12 13:57:38 +04:00
|
|
|
mBounds = nsIntRect(NSToIntRound(aX), NSToIntRound(aY),
|
|
|
|
NSToIntRound(aWidth), NSToIntRound(aHeight));
|
2012-08-15 22:52:42 +04:00
|
|
|
if (mWidgetListener)
|
2012-12-12 13:57:38 +04:00
|
|
|
mWidgetListener->WindowResized(this, mBounds.width, mBounds.height);
|
2011-11-11 04:17:46 +04:00
|
|
|
|
2012-02-22 12:50:44 +04:00
|
|
|
if (aRepaint && gWindowToRedraw)
|
|
|
|
gWindowToRedraw->Invalidate(sVirtualBounds);
|
|
|
|
|
2011-11-11 04:17:46 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindow::Enable(bool aState)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-07-23 09:19:08 +04:00
|
|
|
bool
|
|
|
|
nsWindow::IsEnabled() const
|
2011-11-11 04:17:46 +04:00
|
|
|
{
|
2012-07-23 09:19:08 +04:00
|
|
|
return true;
|
2011-11-11 04:17:46 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindow::SetFocus(bool aRaise)
|
|
|
|
{
|
|
|
|
if (aRaise)
|
|
|
|
BringToTop();
|
|
|
|
|
|
|
|
gFocusedWindow = this;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindow::ConfigureChildren(const nsTArray<nsIWidget::Configuration>&)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-01-19 01:22:12 +04:00
|
|
|
nsWindow::Invalidate(const nsIntRect &aRect)
|
2011-11-11 04:17:46 +04:00
|
|
|
{
|
2011-11-22 23:51:52 +04:00
|
|
|
nsWindow *parent = mParent;
|
|
|
|
while (parent && parent != sTopWindows[0])
|
|
|
|
parent = parent->mParent;
|
2012-01-06 01:23:34 +04:00
|
|
|
if (parent != sTopWindows[0])
|
2011-11-22 23:51:52 +04:00
|
|
|
return NS_OK;
|
|
|
|
|
2011-12-30 03:01:51 +04:00
|
|
|
mDirtyRegion.Or(mDirtyRegion, aRect);
|
2011-11-11 04:17:46 +04:00
|
|
|
gWindowToRedraw = this;
|
2012-01-19 01:22:12 +04:00
|
|
|
gDrawRequest = true;
|
|
|
|
mozilla::NotifyEvent();
|
2011-11-11 04:17:46 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIntPoint
|
|
|
|
nsWindow::WidgetToScreenOffset()
|
|
|
|
{
|
|
|
|
nsIntPoint p(0, 0);
|
|
|
|
nsWindow *w = this;
|
|
|
|
|
|
|
|
while (w && w->mParent) {
|
|
|
|
p.x += w->mBounds.x;
|
|
|
|
p.y += w->mBounds.y;
|
|
|
|
|
|
|
|
w = w->mParent;
|
|
|
|
}
|
|
|
|
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
|
|
|
void*
|
2012-08-22 19:56:38 +04:00
|
|
|
nsWindow::GetNativeData(uint32_t aDataType)
|
2011-11-11 04:17:46 +04:00
|
|
|
{
|
|
|
|
switch (aDataType) {
|
|
|
|
case NS_NATIVE_WINDOW:
|
2013-05-08 07:58:22 +04:00
|
|
|
return GetGonkDisplay()->GetNativeWindow();
|
2011-11-11 04:17:46 +04:00
|
|
|
case NS_NATIVE_WIDGET:
|
|
|
|
return this;
|
|
|
|
}
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2011-11-11 04:17:46 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindow::DispatchEvent(nsGUIEvent *aEvent, nsEventStatus &aStatus)
|
|
|
|
{
|
2012-08-15 22:53:09 +04:00
|
|
|
if (mWidgetListener)
|
|
|
|
aStatus = mWidgetListener->HandleEvent(aEvent, mUseAttachedEvents);
|
2011-11-11 04:17:46 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-12-16 03:38:45 +04:00
|
|
|
NS_IMETHODIMP_(void)
|
|
|
|
nsWindow::SetInputContext(const InputContext& aContext,
|
|
|
|
const InputContextAction& aAction)
|
|
|
|
{
|
2012-01-05 23:17:14 +04:00
|
|
|
mInputContext = aContext;
|
2011-12-16 03:38:45 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP_(InputContext)
|
|
|
|
nsWindow::GetInputContext()
|
|
|
|
{
|
2012-10-27 03:35:21 +04:00
|
|
|
// There is only one IME context on Gonk.
|
|
|
|
mInputContext.mNativeIMEContext = nullptr;
|
2012-01-05 23:17:14 +04:00
|
|
|
return mInputContext;
|
2011-12-16 03:38:45 +04:00
|
|
|
}
|
|
|
|
|
2011-11-11 04:17:46 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindow::ReparentNativeWidget(nsIWidget* aNewParent)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-08-15 10:13:48 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindow::MakeFullScreen(bool aFullScreen)
|
|
|
|
{
|
|
|
|
if (mWindowType != eWindowType_toplevel) {
|
|
|
|
// Ignore fullscreen request for non-toplevel windows.
|
|
|
|
NS_WARNING("MakeFullScreen() on a dialog or child widget?");
|
|
|
|
return nsBaseWidget::MakeFullScreen(aFullScreen);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aFullScreen) {
|
|
|
|
// Fullscreen is "sticky" for toplevel widgets on gonk: we
|
|
|
|
// must paint the entire screen, and should only have one
|
|
|
|
// 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,
|
|
|
|
/*repaint*/true);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-11-11 04:17:46 +04:00
|
|
|
float
|
|
|
|
nsWindow::GetDPI()
|
|
|
|
{
|
2013-05-08 07:58:22 +04:00
|
|
|
return GetGonkDisplay()->xdpi;
|
2011-11-11 04:17:46 +04:00
|
|
|
}
|
|
|
|
|
2013-05-02 00:04:56 +04:00
|
|
|
double
|
|
|
|
nsWindow::GetDefaultScaleInternal()
|
|
|
|
{
|
|
|
|
double rawscale = GetDPI() / 192.0;
|
|
|
|
if (rawscale < 1.25)
|
|
|
|
return 1;
|
|
|
|
else if (rawscale < 1.75)
|
|
|
|
return 1.5;
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
|
2011-11-11 04:17:46 +04:00
|
|
|
LayerManager *
|
2013-04-24 22:42:40 +04:00
|
|
|
nsWindow::GetLayerManager(PLayerTransactionChild* aShadowManager,
|
2011-11-11 04:17:46 +04:00
|
|
|
LayersBackend aBackendHint,
|
|
|
|
LayerManagerPersistence aPersistence,
|
|
|
|
bool* aAllowRetaining)
|
|
|
|
{
|
|
|
|
if (aAllowRetaining)
|
|
|
|
*aAllowRetaining = true;
|
2012-08-15 05:10:40 +04:00
|
|
|
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() == LAYERS_BASIC) {
|
|
|
|
BasicLayerManager* manager =
|
|
|
|
static_cast<BasicLayerManager*>(mLayerManager.get());
|
2013-05-01 09:03:25 +04:00
|
|
|
manager->SetDefaultTargetConfiguration(mozilla::layers::BUFFER_NONE,
|
|
|
|
ScreenRotation(EffectiveScreenRotation()));
|
|
|
|
} else if (mLayerManager->GetBackendType() == LAYERS_CLIENT) {
|
|
|
|
ClientLayerManager* manager =
|
|
|
|
static_cast<ClientLayerManager*>(mLayerManager.get());
|
|
|
|
manager->SetDefaultTargetConfiguration(mozilla::layers::BUFFER_NONE,
|
2012-08-15 05:10:40 +04:00
|
|
|
ScreenRotation(EffectiveScreenRotation()));
|
|
|
|
}
|
2011-11-11 04:17:46 +04:00
|
|
|
return mLayerManager;
|
2012-08-15 05:10:40 +04:00
|
|
|
}
|
2011-11-11 04:17:46 +04:00
|
|
|
|
2012-11-15 22:55:15 +04:00
|
|
|
// Set mUseLayersAcceleration here to make it consistent with
|
2012-07-04 16:30:59 +04:00
|
|
|
// nsBaseWidget::GetLayerManager
|
2012-11-15 22:55:15 +04:00
|
|
|
mUseLayersAcceleration = ComputeShouldAccelerate(mUseLayersAcceleration);
|
2011-11-11 04:17:46 +04:00
|
|
|
nsWindow *topWindow = sTopWindows[0];
|
|
|
|
|
|
|
|
if (!topWindow) {
|
2012-07-07 18:07:00 +04:00
|
|
|
LOGW(" -- no topwindow\n");
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2011-11-11 04:17:46 +04:00
|
|
|
}
|
|
|
|
|
2012-04-05 20:15:19 +04:00
|
|
|
if (sUsingOMTC) {
|
|
|
|
CreateCompositor();
|
|
|
|
if (mLayerManager)
|
|
|
|
return mLayerManager;
|
|
|
|
}
|
|
|
|
|
2012-11-15 22:55:15 +04:00
|
|
|
if (mUseLayersAcceleration) {
|
2012-07-07 18:07:00 +04:00
|
|
|
DebugOnly<nsIntRect> fbBounds = gScreenBounds;
|
|
|
|
if (!sGLContext) {
|
|
|
|
sGLContext = GLContextProvider::CreateForWindow(this);
|
|
|
|
}
|
2011-11-11 04:17:46 +04:00
|
|
|
|
2012-07-07 18:07:00 +04:00
|
|
|
MOZ_ASSERT(fbBounds.value == gScreenBounds);
|
|
|
|
if (sGLContext) {
|
|
|
|
nsRefPtr<LayerManagerOGL> layerManager = new LayerManagerOGL(this);
|
|
|
|
|
|
|
|
if (layerManager->Initialize(sGLContext)) {
|
|
|
|
mLayerManager = layerManager;
|
|
|
|
return mLayerManager;
|
|
|
|
} else {
|
|
|
|
LOGW("Could not create OGL LayerManager");
|
|
|
|
}
|
2012-06-26 18:38:50 +04:00
|
|
|
} else {
|
2012-07-07 18:07:00 +04:00
|
|
|
LOGW("GL context was not created");
|
2012-06-26 18:38:50 +04:00
|
|
|
}
|
2011-12-24 11:13:33 +04:00
|
|
|
}
|
2011-11-11 04:17:46 +04:00
|
|
|
|
2012-07-07 18:07:00 +04:00
|
|
|
// Fall back to software rendering.
|
|
|
|
sFramebufferOpen = Framebuffer::Open();
|
|
|
|
if (sFramebufferOpen) {
|
|
|
|
LOG("Falling back to framebuffer software rendering");
|
|
|
|
} else {
|
|
|
|
LOGE("Failed to mmap fb(?!?), aborting ...");
|
|
|
|
NS_RUNTIMEABORT("Can't open GL context and can't fall back on /dev/graphics/fb0 ...");
|
|
|
|
}
|
|
|
|
|
2013-05-01 09:03:25 +04:00
|
|
|
mLayerManager = new ClientLayerManager(this);
|
2012-11-15 22:55:15 +04:00
|
|
|
mUseLayersAcceleration = false;
|
2012-06-26 18:38:50 +04:00
|
|
|
|
2011-11-11 04:17:46 +04:00
|
|
|
return mLayerManager;
|
|
|
|
}
|
|
|
|
|
|
|
|
gfxASurface *
|
|
|
|
nsWindow::GetThebesSurface()
|
|
|
|
{
|
|
|
|
/* This is really a dummy surface; this is only used when doing reflow, because
|
|
|
|
* we need a RenderingContext to measure text against.
|
|
|
|
*/
|
|
|
|
|
|
|
|
// XXX this really wants to return already_AddRefed, but this only really gets used
|
|
|
|
// on direct assignment to a gfxASurface
|
|
|
|
return new gfxImageSurface(gfxIntSize(5,5), gfxImageSurface::ImageFormatRGB24);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsWindow::BringToTop()
|
|
|
|
{
|
|
|
|
if (!sTopWindows.IsEmpty()) {
|
2012-08-15 22:52:42 +04:00
|
|
|
if (nsIWidgetListener* listener = sTopWindows[0]->GetWidgetListener())
|
|
|
|
listener->WindowDeactivated();
|
2011-11-11 04:17:46 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
sTopWindows.RemoveElement(this);
|
|
|
|
sTopWindows.InsertElementAt(0, this);
|
|
|
|
|
2012-08-15 22:52:42 +04:00
|
|
|
if (mWidgetListener)
|
|
|
|
mWidgetListener->WindowActivated();
|
2012-02-07 05:47:11 +04:00
|
|
|
Invalidate(sVirtualBounds);
|
2011-11-11 04:17:46 +04:00
|
|
|
}
|
|
|
|
|
2012-01-11 06:07:00 +04:00
|
|
|
void
|
|
|
|
nsWindow::UserActivity()
|
|
|
|
{
|
|
|
|
if (!mIdleService) {
|
|
|
|
mIdleService = do_GetService("@mozilla.org/widget/idleservice;1");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mIdleService) {
|
2012-06-29 12:32:21 +04:00
|
|
|
mIdleService->ResetIdleTimeOut(0);
|
2012-01-11 06:07:00 +04:00
|
|
|
}
|
|
|
|
}
|
2012-01-26 06:05:34 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t
|
2012-01-26 06:05:34 +04:00
|
|
|
nsWindow::GetGLFrameBufferFormat()
|
|
|
|
{
|
|
|
|
if (mLayerManager &&
|
2012-07-18 20:31:40 +04:00
|
|
|
mLayerManager->GetBackendType() == mozilla::layers::LAYERS_OPENGL) {
|
2012-01-26 06:05:34 +04:00
|
|
|
// We directly map the hardware fb on Gonk. The hardware fb
|
|
|
|
// has RGB format.
|
|
|
|
return LOCAL_GL_RGB;
|
|
|
|
}
|
|
|
|
return LOCAL_GL_NONE;
|
|
|
|
}
|
2012-02-07 02:47:11 +04:00
|
|
|
|
2012-07-24 23:01:09 +04:00
|
|
|
nsIntRect
|
|
|
|
nsWindow::GetNaturalBounds()
|
|
|
|
{
|
|
|
|
return gScreenBounds;
|
|
|
|
}
|
|
|
|
|
2012-08-14 06:41:09 +04:00
|
|
|
bool
|
|
|
|
nsWindow::NeedsPaint()
|
|
|
|
{
|
|
|
|
if (!mLayerManager) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return nsIWidget::NeedsPaint();
|
|
|
|
}
|
|
|
|
|
2012-11-19 21:58:38 +04:00
|
|
|
Composer2D*
|
|
|
|
nsWindow::GetComposer2D()
|
|
|
|
{
|
|
|
|
if (!sUsingHwc) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2013-05-08 07:58:22 +04:00
|
|
|
|
|
|
|
#if ANDROID_VERSION == 15
|
2012-11-19 21:58:38 +04:00
|
|
|
if (HwcComposer2D* hwc = HwcComposer2D::GetInstance()) {
|
|
|
|
return hwc->Initialized() ? hwc : nullptr;
|
|
|
|
}
|
2013-05-08 07:58:22 +04:00
|
|
|
#endif
|
|
|
|
|
2012-11-19 21:58:38 +04:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2012-02-07 02:47:11 +04:00
|
|
|
// nsScreenGonk.cpp
|
|
|
|
|
|
|
|
nsScreenGonk::nsScreenGonk(void *nativeScreen)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsScreenGonk::~nsScreenGonk()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 19:56:38 +04:00
|
|
|
nsScreenGonk::GetRect(int32_t *outLeft, int32_t *outTop,
|
|
|
|
int32_t *outWidth, int32_t *outHeight)
|
2012-02-07 02:47:11 +04:00
|
|
|
{
|
2012-02-07 05:47:11 +04:00
|
|
|
*outLeft = sVirtualBounds.x;
|
|
|
|
*outTop = sVirtualBounds.y;
|
2012-02-07 02:47:11 +04:00
|
|
|
|
2012-02-07 05:47:11 +04:00
|
|
|
*outWidth = sVirtualBounds.width;
|
|
|
|
*outHeight = sVirtualBounds.height;
|
2012-02-07 02:47:11 +04:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 19:56:38 +04:00
|
|
|
nsScreenGonk::GetAvailRect(int32_t *outLeft, int32_t *outTop,
|
|
|
|
int32_t *outWidth, int32_t *outHeight)
|
2012-02-07 02:47:11 +04:00
|
|
|
{
|
|
|
|
return GetRect(outLeft, outTop, outWidth, outHeight);
|
|
|
|
}
|
|
|
|
|
2012-05-09 01:36:07 +04:00
|
|
|
static uint32_t
|
|
|
|
ColorDepth()
|
|
|
|
{
|
2013-05-08 07:58:22 +04:00
|
|
|
switch (GetGonkDisplay()->surfaceformat) {
|
2012-06-22 12:18:54 +04:00
|
|
|
case GGL_PIXEL_FORMAT_RGB_565:
|
|
|
|
return 16;
|
|
|
|
case GGL_PIXEL_FORMAT_RGBA_8888:
|
|
|
|
return 32;
|
|
|
|
}
|
|
|
|
return 24; // GGL_PIXEL_FORMAT_RGBX_8888
|
2012-05-09 01:36:07 +04:00
|
|
|
}
|
2012-02-07 02:47:11 +04:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 19:56:38 +04:00
|
|
|
nsScreenGonk::GetPixelDepth(int32_t *aPixelDepth)
|
2012-02-07 02:47:11 +04:00
|
|
|
{
|
2012-05-09 01:36:07 +04:00
|
|
|
// XXX: this should actually return 32 when we're using 24-bit
|
|
|
|
// color, because we use RGBX.
|
|
|
|
*aPixelDepth = ColorDepth();
|
2012-02-07 02:47:11 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 19:56:38 +04:00
|
|
|
nsScreenGonk::GetColorDepth(int32_t *aColorDepth)
|
2012-02-07 02:47:11 +04:00
|
|
|
{
|
|
|
|
return GetPixelDepth(aColorDepth);
|
|
|
|
}
|
|
|
|
|
2012-02-07 05:47:11 +04:00
|
|
|
NS_IMETHODIMP
|
2012-08-22 19:56:38 +04:00
|
|
|
nsScreenGonk::GetRotation(uint32_t* aRotation)
|
2012-02-07 05:47:11 +04:00
|
|
|
{
|
|
|
|
*aRotation = sScreenRotation;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 19:56:38 +04:00
|
|
|
nsScreenGonk::SetRotation(uint32_t aRotation)
|
2012-02-07 05:47:11 +04:00
|
|
|
{
|
2012-07-31 04:42:26 +04:00
|
|
|
if (!(aRotation <= ROTATION_270_DEG))
|
2012-02-07 05:47:11 +04:00
|
|
|
return NS_ERROR_ILLEGAL_VALUE;
|
|
|
|
|
|
|
|
if (sScreenRotation == aRotation)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
sScreenRotation = aRotation;
|
2012-07-24 23:01:09 +04:00
|
|
|
sRotationMatrix =
|
Bug 825928: Land layers refactoring. r=jrmuizel,bas,nical,mattwoodrow,roc,nrc,benwa,bjacob,jgilbert,kchen CLOSED TREE
Please contact Bas Schouten <bschouten@mozilla.com>, Nicolas Silva <nsilva@mozilla.com> or Nicholas Cameron <ncameron@mozilla.com> with general questions. Below is a rough list of authors to contact with specific questions.
Authors:
gfx/layers/Compositor.* gfx/layers/Effects.h - Compositor Interface - bas,nrc,nical
gfx/layers/d3d* - D3D9/D3D10 - bas
gfx/layers/ThebesLayer* - ThebesLayers - nrc,bas
gfx/layers/composite/* - CompositeLayers - nrc,nical
gfx/layers/client/* - Client - nrc,nical,bas
gfx/layers/*Image* - nical
gfx/layers/ipc ipc - IPC - nical
gfx/layers/opengl - CompositorOGL - nrc,nical
gfx/2d - bas,nrc
gfx/gl - GLContext - bjacob
dom/* layout/* - DOM - mattwoodrow
2013-04-10 13:20:52 +04:00
|
|
|
ComputeTransformForRotation(gScreenBounds,
|
|
|
|
ScreenRotation(EffectiveScreenRotation()));
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t rotation = EffectiveScreenRotation();
|
2012-07-24 23:01:09 +04:00
|
|
|
if (rotation == nsIScreen::ROTATION_90_DEG ||
|
|
|
|
rotation == nsIScreen::ROTATION_270_DEG) {
|
2012-02-07 05:47:11 +04:00
|
|
|
sVirtualBounds = nsIntRect(0, 0, gScreenBounds.height,
|
2012-07-24 23:01:09 +04:00
|
|
|
gScreenBounds.width);
|
|
|
|
} else {
|
2012-02-07 05:47:11 +04:00
|
|
|
sVirtualBounds = gScreenBounds;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (unsigned int i = 0; i < sTopWindows.Length(); i++)
|
|
|
|
sTopWindows[i]->Resize(sVirtualBounds.width,
|
|
|
|
sVirtualBounds.height,
|
|
|
|
!i);
|
|
|
|
|
2012-04-25 07:59:01 +04:00
|
|
|
nsAppShell::NotifyScreenRotation();
|
|
|
|
|
2012-02-07 05:47:11 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-05-09 01:36:07 +04:00
|
|
|
// 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
|
2012-02-07 05:47:11 +04:00
|
|
|
nsScreenGonk::GetRotation()
|
|
|
|
{
|
|
|
|
return sScreenRotation;
|
|
|
|
}
|
|
|
|
|
2012-05-09 01:36:07 +04:00
|
|
|
/*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);
|
|
|
|
}
|
|
|
|
|
2012-02-07 02:47:11 +04:00
|
|
|
NS_IMPL_ISUPPORTS1(nsScreenManagerGonk, nsIScreenManager)
|
|
|
|
|
|
|
|
nsScreenManagerGonk::nsScreenManagerGonk()
|
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
mOneScreen = new nsScreenGonk(nullptr);
|
2012-02-07 02:47:11 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsScreenManagerGonk::~nsScreenManagerGonk()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsScreenManagerGonk::GetPrimaryScreen(nsIScreen **outScreen)
|
|
|
|
{
|
|
|
|
NS_IF_ADDREF(*outScreen = mOneScreen.get());
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 19:56:38 +04:00
|
|
|
nsScreenManagerGonk::ScreenForRect(int32_t inLeft,
|
|
|
|
int32_t inTop,
|
|
|
|
int32_t inWidth,
|
|
|
|
int32_t inHeight,
|
2012-02-07 02:47:11 +04:00
|
|
|
nsIScreen **outScreen)
|
|
|
|
{
|
|
|
|
return GetPrimaryScreen(outScreen);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsScreenManagerGonk::ScreenForNativeWidget(void *aWidget, nsIScreen **outScreen)
|
|
|
|
{
|
|
|
|
return GetPrimaryScreen(outScreen);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 19:56:38 +04:00
|
|
|
nsScreenManagerGonk::GetNumberOfScreens(uint32_t *aNumberOfScreens)
|
2012-02-07 02:47:11 +04:00
|
|
|
{
|
|
|
|
*aNumberOfScreens = 1;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2013-04-10 01:07:02 +04:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsScreenManagerGonk::GetSystemDefaultScale(float *aDefaultScale)
|
|
|
|
{
|
|
|
|
*aDefaultScale = 1.0f;
|
|
|
|
return NS_OK;
|
|
|
|
}
|