Bug 983971 - Do not use gralloc for small size on ICS gonk r=nical
[gecko.git] / widget / qt / nsIdleServiceQt.cpp
blobb9fea1fa35ee892c59b2ce19f2d60eae65ecc244
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* vim:expandtab:shiftwidth=4:tabstop=4:
3 */
4 /* This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
8 #ifdef MOZ_X11
9 #include "mozilla/X11Util.h"
10 #endif
11 #include "nsIdleServiceQt.h"
12 #include "nsIServiceManager.h"
13 #include "nsDebug.h"
14 #include "prlink.h"
16 #if defined(MOZ_X11)
17 typedef bool (*_XScreenSaverQueryExtension_fn)(Display* dpy, int* event_base,
18 int* error_base);
20 typedef XScreenSaverInfo* (*_XScreenSaverAllocInfo_fn)(void);
22 typedef void (*_XScreenSaverQueryInfo_fn)(Display* dpy, Drawable drw,
23 XScreenSaverInfo *info);
25 static _XScreenSaverQueryExtension_fn _XSSQueryExtension = nullptr;
26 static _XScreenSaverAllocInfo_fn _XSSAllocInfo = nullptr;
27 static _XScreenSaverQueryInfo_fn _XSSQueryInfo = nullptr;
28 #endif
30 static bool sInitialized = false;
32 NS_IMPL_ISUPPORTS_INHERITED0(nsIdleServiceQt, nsIdleService)
34 nsIdleServiceQt::nsIdleServiceQt()
35 #if defined(MOZ_X11)
36 : mXssInfo(nullptr)
37 #endif
41 static void Initialize()
43 sInitialized = true;
45 #if defined(MOZ_X11)
46 // This will leak - See comments in ~nsIdleServiceQt().
47 PRLibrary* xsslib = PR_LoadLibrary("libXss.so.1");
48 if (!xsslib) {
49 return;
52 _XSSQueryExtension = (_XScreenSaverQueryExtension_fn)
53 PR_FindFunctionSymbol(xsslib, "XScreenSaverQueryExtension");
54 _XSSAllocInfo = (_XScreenSaverAllocInfo_fn)
55 PR_FindFunctionSymbol(xsslib, "XScreenSaverAllocInfo");
56 _XSSQueryInfo = (_XScreenSaverQueryInfo_fn)
57 PR_FindFunctionSymbol(xsslib, "XScreenSaverQueryInfo");
58 #endif
61 nsIdleServiceQt::~nsIdleServiceQt()
63 #if defined(MOZ_X11)
64 if (mXssInfo)
65 XFree(mXssInfo);
67 // It is not safe to unload libXScrnSaver until each display is closed because
68 // the library registers callbacks through XESetCloseDisplay (Bug 397607).
69 // (Also the library and its functions are scoped for the file not the object.)
70 #if 0
71 if (xsslib) {
72 PR_UnloadLibrary(xsslib);
73 xsslib = nullptr;
75 #endif
76 #endif
79 bool
80 nsIdleServiceQt::PollIdleTime(uint32_t *aIdleTime)
82 #if defined(MOZ_X11)
83 // Ask xscreensaver about idle time:
84 *aIdleTime = 0;
86 // We might not have a display (cf. in xpcshell)
87 Display *dplay = mozilla::DefaultXDisplay();
88 if (!dplay) {
89 return false;
92 if (!sInitialized) {
93 Initialize();
95 if (!_XSSQueryExtension || !_XSSAllocInfo || !_XSSQueryInfo) {
96 return false;
99 int event_base, error_base;
100 if (_XSSQueryExtension(dplay, &event_base, &error_base)) {
101 if (!mXssInfo)
102 mXssInfo = _XSSAllocInfo();
103 if (!mXssInfo)
104 return false;
106 _XSSQueryInfo(dplay, RootWindowOfScreen(DefaultScreenOfDisplay(mozilla::DefaultXDisplay())), mXssInfo);
107 *aIdleTime = mXssInfo->idle;
108 return true;
110 #endif
112 return false;
115 bool
116 nsIdleServiceQt::UsePollMode()
118 #if defined(MOZ_X11)
119 return false;
120 #endif
121 return true;