2011-11-11 04:17:46 +04:00
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (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.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is Gonk.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* the Mozilla Foundation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2011
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* Michael Wu <mwu@mozilla.com>
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
|
|
|
#include <EGL/egl.h>
|
|
|
|
#include <EGL/eglext.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
|
|
|
#include "ui/FramebufferNativeWindow.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"
|
|
|
|
#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"
|
2011-11-11 04:17:46 +04:00
|
|
|
|
|
|
|
#define LOG(args...) __android_log_print(ANDROID_LOG_INFO, "Gonk" , ## args)
|
|
|
|
|
|
|
|
#define IS_TOPLEVEL() (mWindowType == eWindowType_toplevel || mWindowType == eWindowType_dialog)
|
|
|
|
|
2011-12-24 11:13:33 +04:00
|
|
|
using namespace mozilla;
|
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;
|
|
|
|
static nsIntRect sVirtualBounds;
|
|
|
|
static gfxMatrix sRotationMatrix;
|
2011-11-11 04:17:46 +04:00
|
|
|
|
|
|
|
static nsRefPtr<GLContext> sGLContext;
|
|
|
|
static nsTArray<nsWindow *> sTopWindows;
|
|
|
|
static nsWindow *gWindowToRedraw = nsnull;
|
|
|
|
static nsWindow *gFocusedWindow = nsnull;
|
|
|
|
static android::FramebufferNativeWindow *gNativeWindow = nsnull;
|
2011-12-24 11:13:33 +04:00
|
|
|
static bool sFramebufferOpen;
|
2012-04-05 20:15:19 +04:00
|
|
|
static bool sUsingOMTC;
|
|
|
|
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 {
|
|
|
|
|
|
|
|
class ScreenOnOffEvent : public nsRunnable {
|
|
|
|
public:
|
|
|
|
ScreenOnOffEvent(bool on)
|
|
|
|
: mIsOn(on)
|
|
|
|
{}
|
|
|
|
|
|
|
|
NS_IMETHOD Run() {
|
|
|
|
nsSizeModeEvent event(true, NS_SIZEMODE, NULL);
|
|
|
|
nsEventStatus status;
|
|
|
|
|
|
|
|
event.time = PR_Now() / 1000;
|
|
|
|
event.mSizeMode = mIsOn ? nsSizeMode_Fullscreen : nsSizeMode_Minimized;
|
|
|
|
|
|
|
|
for (PRUint32 i = 0; i < sTopWindows.Length(); i++) {
|
|
|
|
nsWindow *win = sTopWindows[i];
|
|
|
|
event.widget = win;
|
|
|
|
win->DispatchEvent(&event, status);
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
int len = 0;
|
|
|
|
char buf;
|
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.
|
|
|
|
{
|
|
|
|
ScopedClose fd(open(kSleepFile, O_RDONLY, 0));
|
|
|
|
do {
|
2012-04-12 14:21:24 +04:00
|
|
|
len = read(fd.get(), &buf, 1);
|
2012-04-05 10:03:00 +04:00
|
|
|
} while (len < 0 && errno == EINTR);
|
|
|
|
NS_WARN_IF_FALSE(len >= 0, "WAIT_FOR_FB_SLEEP failed");
|
|
|
|
NS_DispatchToMainThread(mScreenOffEvent);
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
ScopedClose fd(open(kWakeFile, O_RDONLY, 0));
|
|
|
|
do {
|
2012-04-12 14:21:24 +04:00
|
|
|
len = read(fd.get(), &buf, 1);
|
2012-04-05 10:03:00 +04:00
|
|
|
} while (len < 0 && errno == EINTR);
|
|
|
|
NS_WARN_IF_FALSE(len >= 0, "WAIT_FOR_FB_WAKE failed");
|
|
|
|
NS_DispatchToMainThread(mScreenOnEvent);
|
|
|
|
}
|
|
|
|
}
|
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-04-05 20:15:19 +04:00
|
|
|
if (!sGLContext && !sFramebufferOpen && !sUsingOMTC) {
|
2012-02-21 02:07:13 +04:00
|
|
|
// workaround Bug 725143
|
|
|
|
hal::SetScreenEnabled(true);
|
|
|
|
|
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-04-05 20:15:19 +04:00
|
|
|
sUsingOMTC = Preferences::GetBool("layers.offmainthreadcomposition.enabled", false);
|
|
|
|
|
2011-12-24 11:13:33 +04:00
|
|
|
// We (apparently) don't have a way to tell if allocating the
|
|
|
|
// fbs succeeded or failed.
|
2011-11-11 04:17:46 +04:00
|
|
|
gNativeWindow = new android::FramebufferNativeWindow();
|
2012-04-05 20:15:19 +04:00
|
|
|
if (sUsingOMTC) {
|
2011-12-24 11:13:33 +04:00
|
|
|
nsIntSize screenSize;
|
2012-04-05 20:15:19 +04:00
|
|
|
bool gotFB = Framebuffer::GetSize(&screenSize);
|
|
|
|
MOZ_ASSERT(gotFB);
|
2011-12-24 11:13:33 +04:00
|
|
|
gScreenBounds = nsIntRect(nsIntPoint(0, 0), screenSize);
|
2012-04-05 20:15:19 +04:00
|
|
|
|
|
|
|
sOMTCSurface = new gfxImageSurface(gfxIntSize(1, 1),
|
|
|
|
gfxASurface::ImageFormatRGB24);
|
|
|
|
} else {
|
|
|
|
sGLContext = GLContextProvider::CreateForWindow(this);
|
|
|
|
// CreateForWindow sets up gScreenBounds
|
|
|
|
if (!sGLContext) {
|
|
|
|
LOG("Failed to create GL context for fb, trying /dev/graphics/fb0");
|
|
|
|
|
|
|
|
// We can't delete gNativeWindow.
|
|
|
|
|
|
|
|
nsIntSize screenSize;
|
|
|
|
sFramebufferOpen = Framebuffer::Open(&screenSize);
|
|
|
|
gScreenBounds = nsIntRect(nsIntPoint(0, 0), screenSize);
|
|
|
|
if (!sFramebufferOpen) {
|
|
|
|
LOG("Failed to mmap fb(?!?), aborting ...");
|
|
|
|
NS_RUNTIMEABORT("Can't open GL context and can't fall back on /dev/graphics/fb0 ...");
|
|
|
|
}
|
2011-12-24 11:13:33 +04:00
|
|
|
}
|
|
|
|
}
|
2012-02-07 05:47:11 +04:00
|
|
|
sVirtualBounds = gScreenBounds;
|
2012-03-25 14:06:02 +04:00
|
|
|
|
|
|
|
nsAppShell::NotifyScreenInitialized();
|
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
|
|
|
|
|
|
|
nsPaintEvent event(true, NS_PAINT, gWindowToRedraw);
|
2011-12-30 03:01:51 +04:00
|
|
|
event.region = gWindowToRedraw->mDirtyRegion;
|
|
|
|
gWindowToRedraw->mDirtyRegion.SetEmpty();
|
2011-12-24 11:13:33 +04:00
|
|
|
|
|
|
|
LayerManager* lm = gWindowToRedraw->GetLayerManager();
|
|
|
|
if (LayerManager::LAYERS_OPENGL == lm->GetBackendType()) {
|
2012-02-07 05:47:11 +04:00
|
|
|
LayerManagerOGL* oglm = static_cast<LayerManagerOGL*>(lm);
|
|
|
|
oglm->SetClippingRegion(event.region);
|
|
|
|
oglm->SetWorldTransform(sRotationMatrix);
|
2011-12-24 11:13:33 +04:00
|
|
|
gWindowToRedraw->mEventCallback(&event);
|
|
|
|
} else if (LayerManager::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);
|
2011-12-24 11:13:33 +04:00
|
|
|
gfxUtils::PathFromRegion(ctx, event.region);
|
|
|
|
ctx->Clip();
|
|
|
|
|
|
|
|
// No double-buffering needed.
|
|
|
|
AutoLayerManagerSetup setupLayerManager(
|
|
|
|
gWindowToRedraw, ctx, BasicLayerManager::BUFFER_NONE);
|
|
|
|
gWindowToRedraw->mEventCallback(&event);
|
|
|
|
}
|
|
|
|
|
2012-04-05 20:15:19 +04:00
|
|
|
if (!sUsingOMTC) {
|
|
|
|
targetSurface->Flush();
|
|
|
|
Framebuffer::Present(event.region);
|
|
|
|
}
|
2011-12-24 11:13:33 +04:00
|
|
|
} else {
|
|
|
|
NS_RUNTIMEABORT("Unexpected layer manager type");
|
|
|
|
}
|
2011-11-11 04:17:46 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsEventStatus
|
|
|
|
nsWindow::DispatchInputEvent(nsGUIEvent &aEvent)
|
|
|
|
{
|
|
|
|
if (!gFocusedWindow)
|
|
|
|
return nsEventStatus_eIgnore;
|
|
|
|
|
2012-01-11 06:07:00 +04:00
|
|
|
gFocusedWindow->UserActivity();
|
2011-11-11 04:17:46 +04:00
|
|
|
aEvent.widget = gFocusedWindow;
|
|
|
|
return gFocusedWindow->mEventCallback(&aEvent);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindow::Create(nsIWidget *aParent,
|
|
|
|
void *aNativeParent,
|
|
|
|
const nsIntRect &aRect,
|
|
|
|
EVENT_CALLBACK aHandleEventFunction,
|
|
|
|
nsDeviceContext *aContext,
|
|
|
|
nsWidgetInitData *aInitData)
|
|
|
|
{
|
2012-02-07 05:47:11 +04:00
|
|
|
BaseCreate(aParent, IS_TOPLEVEL() ? sVirtualBounds : aRect,
|
2011-11-11 04:17:46 +04:00
|
|
|
aHandleEventFunction, aContext, aInitData);
|
|
|
|
|
|
|
|
mBounds = aRect;
|
|
|
|
|
|
|
|
nsWindow *parent = (nsWindow *)aNativeParent;
|
|
|
|
mParent = parent;
|
|
|
|
|
|
|
|
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)
|
|
|
|
gWindowToRedraw = nsnull;
|
|
|
|
if (this == gFocusedWindow)
|
|
|
|
gFocusedWindow = nsnull;
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindow::IsVisible(bool & aState)
|
|
|
|
{
|
|
|
|
aState = mVisible;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindow::ConstrainPosition(bool aAllowSlop,
|
2012-01-05 23:17:14 +04:00
|
|
|
PRInt32 *aX,
|
|
|
|
PRInt32 *aY)
|
2011-11-11 04:17:46 +04:00
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindow::Move(PRInt32 aX,
|
|
|
|
PRInt32 aY)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindow::Resize(PRInt32 aWidth,
|
|
|
|
PRInt32 aHeight,
|
|
|
|
bool aRepaint)
|
|
|
|
{
|
|
|
|
return Resize(0, 0, aWidth, aHeight, aRepaint);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindow::Resize(PRInt32 aX,
|
|
|
|
PRInt32 aY,
|
|
|
|
PRInt32 aWidth,
|
|
|
|
PRInt32 aHeight,
|
|
|
|
bool aRepaint)
|
|
|
|
{
|
|
|
|
nsSizeEvent event(true, NS_SIZE, this);
|
|
|
|
event.time = PR_Now() / 1000;
|
|
|
|
|
|
|
|
nsIntRect rect(aX, aY, aWidth, aHeight);
|
2012-02-07 05:47:11 +04:00
|
|
|
mBounds = rect;
|
2011-11-11 04:17:46 +04:00
|
|
|
event.windowSize = ▭
|
2012-02-07 05:47:11 +04:00
|
|
|
event.mWinWidth = sVirtualBounds.width;
|
|
|
|
event.mWinHeight = sVirtualBounds.height;
|
2011-11-11 04:17:46 +04:00
|
|
|
|
|
|
|
(*mEventCallback)(&event);
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindow::IsEnabled(bool *aState)
|
|
|
|
{
|
|
|
|
*aState = true;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
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*
|
|
|
|
nsWindow::GetNativeData(PRUint32 aDataType)
|
|
|
|
{
|
|
|
|
switch (aDataType) {
|
|
|
|
case NS_NATIVE_WINDOW:
|
|
|
|
return gNativeWindow;
|
|
|
|
case NS_NATIVE_WIDGET:
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsWindow::DispatchEvent(nsGUIEvent *aEvent, nsEventStatus &aStatus)
|
|
|
|
{
|
2011-12-16 03:38:45 +04:00
|
|
|
aStatus = (*mEventCallback)(aEvent);
|
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-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;
|
|
|
|
}
|
|
|
|
|
|
|
|
float
|
|
|
|
nsWindow::GetDPI()
|
|
|
|
{
|
|
|
|
return gNativeWindow->xdpi;
|
|
|
|
}
|
|
|
|
|
|
|
|
LayerManager *
|
|
|
|
nsWindow::GetLayerManager(PLayersChild* aShadowManager,
|
|
|
|
LayersBackend aBackendHint,
|
|
|
|
LayerManagerPersistence aPersistence,
|
|
|
|
bool* aAllowRetaining)
|
|
|
|
{
|
|
|
|
if (aAllowRetaining)
|
|
|
|
*aAllowRetaining = true;
|
|
|
|
if (mLayerManager)
|
|
|
|
return mLayerManager;
|
|
|
|
|
|
|
|
nsWindow *topWindow = sTopWindows[0];
|
|
|
|
|
|
|
|
if (!topWindow) {
|
|
|
|
LOG(" -- no topwindow\n");
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
2012-04-05 20:15:19 +04:00
|
|
|
if (sUsingOMTC) {
|
|
|
|
CreateCompositor();
|
|
|
|
if (mLayerManager)
|
|
|
|
return mLayerManager;
|
|
|
|
}
|
|
|
|
|
2011-12-24 11:13:33 +04:00
|
|
|
if (sGLContext) {
|
|
|
|
nsRefPtr<LayerManagerOGL> layerManager = new LayerManagerOGL(this);
|
2011-11-11 04:17:46 +04:00
|
|
|
|
2011-12-24 11:13:33 +04:00
|
|
|
if (layerManager->Initialize(sGLContext))
|
|
|
|
mLayerManager = layerManager;
|
|
|
|
else
|
|
|
|
LOG("Could not create OGL LayerManager");
|
|
|
|
} else {
|
|
|
|
MOZ_ASSERT(sFramebufferOpen);
|
|
|
|
mLayerManager = new BasicShadowLayerManager(this);
|
|
|
|
}
|
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()) {
|
|
|
|
nsGUIEvent event(true, NS_DEACTIVATE, sTopWindows[0]);
|
|
|
|
(*mEventCallback)(&event);
|
|
|
|
}
|
|
|
|
|
|
|
|
sTopWindows.RemoveElement(this);
|
|
|
|
sTopWindows.InsertElementAt(0, this);
|
|
|
|
|
|
|
|
nsGUIEvent event(true, NS_ACTIVATE, this);
|
|
|
|
(*mEventCallback)(&event);
|
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) {
|
|
|
|
mIdleService->ResetIdleTimeOut();
|
|
|
|
}
|
|
|
|
}
|
2012-01-26 06:05:34 +04:00
|
|
|
|
|
|
|
PRUint32
|
|
|
|
nsWindow::GetGLFrameBufferFormat()
|
|
|
|
{
|
|
|
|
if (mLayerManager &&
|
|
|
|
mLayerManager->GetBackendType() == LayerManager::LAYERS_OPENGL) {
|
|
|
|
// 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
|
|
|
|
|
|
|
// nsScreenGonk.cpp
|
|
|
|
|
|
|
|
nsScreenGonk::nsScreenGonk(void *nativeScreen)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsScreenGonk::~nsScreenGonk()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsScreenGonk::GetRect(PRInt32 *outLeft, PRInt32 *outTop,
|
|
|
|
PRInt32 *outWidth, PRInt32 *outHeight)
|
|
|
|
{
|
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
|
|
|
|
nsScreenGonk::GetAvailRect(PRInt32 *outLeft, PRInt32 *outTop,
|
|
|
|
PRInt32 *outWidth, PRInt32 *outHeight)
|
|
|
|
{
|
|
|
|
return GetRect(outLeft, outTop, outWidth, outHeight);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsScreenGonk::GetPixelDepth(PRInt32 *aPixelDepth)
|
|
|
|
{
|
2012-03-09 04:01:12 +04:00
|
|
|
*aPixelDepth = gNativeWindow->getDevice()->format == GGL_PIXEL_FORMAT_RGB_565 ? 16 : 24;
|
2012-02-07 02:47:11 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsScreenGonk::GetColorDepth(PRInt32 *aColorDepth)
|
|
|
|
{
|
|
|
|
return GetPixelDepth(aColorDepth);
|
|
|
|
}
|
|
|
|
|
2012-02-07 05:47:11 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsScreenGonk::GetRotation(PRUint32* aRotation)
|
|
|
|
{
|
|
|
|
*aRotation = sScreenRotation;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsScreenGonk::SetRotation(PRUint32 aRotation)
|
|
|
|
{
|
|
|
|
if (!(ROTATION_0_DEG <= aRotation && aRotation <= ROTATION_270_DEG))
|
|
|
|
return NS_ERROR_ILLEGAL_VALUE;
|
|
|
|
|
|
|
|
if (sScreenRotation == aRotation)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
sScreenRotation = aRotation;
|
|
|
|
sRotationMatrix.Reset();
|
|
|
|
switch (aRotation) {
|
|
|
|
case nsIScreen::ROTATION_0_DEG:
|
|
|
|
sVirtualBounds = gScreenBounds;
|
|
|
|
break;
|
|
|
|
case nsIScreen::ROTATION_90_DEG:
|
|
|
|
sRotationMatrix.Translate(gfxPoint(gScreenBounds.width, 0));
|
|
|
|
sRotationMatrix.Rotate(M_PI / 2);
|
|
|
|
sVirtualBounds = nsIntRect(0, 0, gScreenBounds.height,
|
|
|
|
gScreenBounds.width);
|
|
|
|
break;
|
|
|
|
case nsIScreen::ROTATION_180_DEG:
|
|
|
|
sRotationMatrix.Translate(gfxPoint(gScreenBounds.width,
|
|
|
|
gScreenBounds.height));
|
|
|
|
sRotationMatrix.Rotate(M_PI);
|
|
|
|
sVirtualBounds = gScreenBounds;
|
|
|
|
break;
|
|
|
|
case nsIScreen::ROTATION_270_DEG:
|
|
|
|
sRotationMatrix.Translate(gfxPoint(0, gScreenBounds.height));
|
|
|
|
sRotationMatrix.Rotate(M_PI * 3 / 2);
|
|
|
|
sVirtualBounds = nsIntRect(0, 0, gScreenBounds.height,
|
|
|
|
gScreenBounds.width);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
MOZ_NOT_REACHED("Unknown rotation");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t
|
|
|
|
nsScreenGonk::GetRotation()
|
|
|
|
{
|
|
|
|
return sScreenRotation;
|
|
|
|
}
|
|
|
|
|
2012-02-07 02:47:11 +04:00
|
|
|
NS_IMPL_ISUPPORTS1(nsScreenManagerGonk, nsIScreenManager)
|
|
|
|
|
|
|
|
nsScreenManagerGonk::nsScreenManagerGonk()
|
|
|
|
{
|
|
|
|
mOneScreen = new nsScreenGonk(nsnull);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsScreenManagerGonk::~nsScreenManagerGonk()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsScreenManagerGonk::GetPrimaryScreen(nsIScreen **outScreen)
|
|
|
|
{
|
|
|
|
NS_IF_ADDREF(*outScreen = mOneScreen.get());
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsScreenManagerGonk::ScreenForRect(PRInt32 inLeft,
|
|
|
|
PRInt32 inTop,
|
|
|
|
PRInt32 inWidth,
|
|
|
|
PRInt32 inHeight,
|
|
|
|
nsIScreen **outScreen)
|
|
|
|
{
|
|
|
|
return GetPrimaryScreen(outScreen);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsScreenManagerGonk::ScreenForNativeWidget(void *aWidget, nsIScreen **outScreen)
|
|
|
|
{
|
|
|
|
return GetPrimaryScreen(outScreen);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsScreenManagerGonk::GetNumberOfScreens(PRUint32 *aNumberOfScreens)
|
|
|
|
{
|
|
|
|
*aNumberOfScreens = 1;
|
|
|
|
return NS_OK;
|
|
|
|
}
|