Title: [222834] trunk
Revision
222834
Author
g...@gnome.org
Date
2017-10-04 00:46:25 -0700 (Wed, 04 Oct 2017)

Log Message

[GLib] Let WebCore know of low power situations
https://bugs.webkit.org/show_bug.cgi?id=177810

Reviewed by Carlos Garcia Campos.

.:

WebCore can use knowledge of low power situations to throttle timers and avoid expensive
checks, lowering power usage. We can use upower's warning level to let WebCore know we are
in such a situation.

* Source/cmake/OptionsGTK.cmake: depend on upower-glib.
* Source/cmake/FindUPowerGLib.cmake: Added.

Source/WebCore:

WebCore can use knowledge of low power situations to throttle timers and avoid expensive
checks, lowering power usage. We can use upower's warning level to let WebCore know we are
in such a situation.

No tests as there is no way to mock upower.

* PlatformGTK.cmake: add new file.
* PlatformWPE.cmake: add new file.
* platform/LowPowerModeNotifier.cpp: use upower-glib to know about low power situations.
* platform/LowPowerModeNotifier.h: includes upower header as UpClient and UpDevice are not forward
declaration-friendly.
* platform/glib/LowPowerModeNotifierGLib.cpp: Added.
(WebCore::LowPowerModeNotifier::LowPowerModeNotifier):
(WebCore::LowPowerModeNotifier::updateState): update low power mode from warning-level.
(WebCore::LowPowerModeNotifier::warningLevelCallback): track upower's warning-level to know when
a low power situation occurs.
(WebCore::LowPowerModeNotifier::~LowPowerModeNotifier): stop tracking the warning-level signal.
(WebCore::LowPowerModeNotifier::isLowPowerModeEnabled const):

Tools:

* gtk/install-dependencies: add upower-glib dev packages for Debian, Arch and Fedora.

Modified Paths

Added Paths

Diff

Modified: trunk/ChangeLog (222833 => 222834)


--- trunk/ChangeLog	2017-10-04 07:33:08 UTC (rev 222833)
+++ trunk/ChangeLog	2017-10-04 07:46:25 UTC (rev 222834)
@@ -1,3 +1,17 @@
+2017-10-03  Gustavo Noronha Silva  <gustavo.noro...@collabora.co.uk>
+
+        [GLib] Let WebCore know of low power situations
+        https://bugs.webkit.org/show_bug.cgi?id=177810
+
+        Reviewed by Carlos Garcia Campos.
+
+        WebCore can use knowledge of low power situations to throttle timers and avoid expensive
+        checks, lowering power usage. We can use upower's warning level to let WebCore know we are
+        in such a situation.
+
+        * Source/cmake/OptionsGTK.cmake: depend on upower-glib.
+        * Source/cmake/FindUPowerGLib.cmake: Added.
+
 2017-10-03  Youenn Fablet  <you...@apple.com>
 
         Build libwebrtc unit tests executables

Modified: trunk/Source/WebCore/ChangeLog (222833 => 222834)


--- trunk/Source/WebCore/ChangeLog	2017-10-04 07:33:08 UTC (rev 222833)
+++ trunk/Source/WebCore/ChangeLog	2017-10-04 07:46:25 UTC (rev 222834)
@@ -1,3 +1,29 @@
+2017-10-03  Gustavo Noronha Silva  <gustavo.noro...@collabora.co.uk>
+
+        [GLib] Let WebCore know of low power situations
+        https://bugs.webkit.org/show_bug.cgi?id=177810
+
+        Reviewed by Carlos Garcia Campos.
+
+        WebCore can use knowledge of low power situations to throttle timers and avoid expensive
+        checks, lowering power usage. We can use upower's warning level to let WebCore know we are
+        in such a situation.
+
+        No tests as there is no way to mock upower.
+
+        * PlatformGTK.cmake: add new file.
+        * PlatformWPE.cmake: add new file.
+        * platform/LowPowerModeNotifier.cpp: use upower-glib to know about low power situations.
+        * platform/LowPowerModeNotifier.h: includes upower header as UpClient and UpDevice are not forward
+        declaration-friendly.
+        * platform/glib/LowPowerModeNotifierGLib.cpp: Added.
+        (WebCore::LowPowerModeNotifier::LowPowerModeNotifier):
+        (WebCore::LowPowerModeNotifier::updateState): update low power mode from warning-level.
+        (WebCore::LowPowerModeNotifier::warningLevelCallback): track upower's warning-level to know when
+        a low power situation occurs.
+        (WebCore::LowPowerModeNotifier::~LowPowerModeNotifier): stop tracking the warning-level signal.
+        (WebCore::LowPowerModeNotifier::isLowPowerModeEnabled const):
+
 2017-10-04  Joanmarie Diggs  <jdi...@igalia.com>
 
         AX: [ATK] aria-pressed="mixed" should be exposed via ATK_STATE_INDETERMINATE

Modified: trunk/Source/WebCore/PlatformGTK.cmake (222833 => 222834)


--- trunk/Source/WebCore/PlatformGTK.cmake	2017-10-04 07:33:08 UTC (rev 222833)
+++ trunk/Source/WebCore/PlatformGTK.cmake	2017-10-04 07:46:25 UTC (rev 222834)
@@ -71,6 +71,7 @@
     platform/glib/FileSystemGlib.cpp
     platform/glib/KeyedDecoderGlib.cpp
     platform/glib/KeyedEncoderGlib.cpp
+    platform/glib/LowPowerModeNotifierGLib.cpp
     platform/glib/MainThreadSharedTimerGLib.cpp
     platform/glib/SSLKeyGeneratorGLib.cpp
     platform/glib/SharedBufferGlib.cpp
@@ -213,6 +214,7 @@
     ${LIBSOUP_LIBRARIES}
     ${LIBTASN1_LIBRARIES}
     ${HYPHEN_LIBRARIES}
+    ${UPOWERGLIB_LIBRARIES}
     ${X11_X11_LIB}
     ${X11_Xcomposite_LIB}
     ${X11_Xdamage_LIB}
@@ -233,6 +235,7 @@
     ${LIBSECRET_INCLUDE_DIRS}
     ${LIBSOUP_INCLUDE_DIRS}
     ${LIBTASN1_INCLUDE_DIRS}
+    ${UPOWERGLIB_INCLUDE_DIRS}
     ${ZLIB_INCLUDE_DIRS}
 )
 

Modified: trunk/Source/WebCore/PlatformWPE.cmake (222833 => 222834)


--- trunk/Source/WebCore/PlatformWPE.cmake	2017-10-04 07:33:08 UTC (rev 222833)
+++ trunk/Source/WebCore/PlatformWPE.cmake	2017-10-04 07:46:25 UTC (rev 222834)
@@ -74,6 +74,7 @@
     platform/glib/FileSystemGlib.cpp
     platform/glib/KeyedDecoderGlib.cpp
     platform/glib/KeyedEncoderGlib.cpp
+    platform/glib/LowPowerModeNotifierGLib.cpp
     platform/glib/MainThreadSharedTimerGLib.cpp
     platform/glib/SSLKeyGeneratorGLib.cpp
     platform/glib/SharedBufferGlib.cpp
@@ -173,6 +174,7 @@
     ${ICU_LIBRARIES}
     ${LIBSOUP_LIBRARIES}
     ${LIBTASN1_LIBRARIES}
+    ${UPOWERGLIB_LIBRARIES}
     ${WPE_LIBRARIES}
 )
 
@@ -183,6 +185,7 @@
     ${ICU_INCLUDE_DIRS}
     ${LIBSOUP_INCLUDE_DIRS}
     ${LIBTASN1_INCLUDE_DIRS}
+    ${UPOWERGLIB_INCLUDE_DIRS}
     ${WPE_INCLUDE_DIRS}
 )
 

Modified: trunk/Source/WebCore/platform/LowPowerModeNotifier.cpp (222833 => 222834)


--- trunk/Source/WebCore/platform/LowPowerModeNotifier.cpp	2017-10-04 07:33:08 UTC (rev 222833)
+++ trunk/Source/WebCore/platform/LowPowerModeNotifier.cpp	2017-10-04 07:46:25 UTC (rev 222834)
@@ -28,7 +28,7 @@
 
 namespace WebCore {
 
-#if !PLATFORM(IOS)
+#if !PLATFORM(IOS) && !USE(UPOWER)
 
 LowPowerModeNotifier::LowPowerModeNotifier(LowPowerModeChangeCallback&&)
 {

Modified: trunk/Source/WebCore/platform/LowPowerModeNotifier.h (222833 => 222834)


--- trunk/Source/WebCore/platform/LowPowerModeNotifier.h	2017-10-04 07:33:08 UTC (rev 222833)
+++ trunk/Source/WebCore/platform/LowPowerModeNotifier.h	2017-10-04 07:46:25 UTC (rev 222834)
@@ -34,6 +34,11 @@
 
 #endif
 
+#if USE(UPOWER)
+#include <libupower-glib/upower.h>
+#include <wtf/glib/GRefPtr.h>
+#endif
+
 namespace WebCore {
 
 class LowPowerModeNotifier {
@@ -51,6 +56,14 @@
 
     RetainPtr<WebLowPowerModeObserver> m_observer;
     LowPowerModeChangeCallback m_callback;
+#elif USE(UPOWER)
+    static void warningLevelCallback(LowPowerModeNotifier*);
+    void updateState();
+
+    GRefPtr<UpClient> m_upClient;
+    GRefPtr<UpDevice> m_device;
+    LowPowerModeChangeCallback m_callback;
+    bool m_lowPowerModeEnabled { false };
 #endif
 };
 

Added: trunk/Source/WebCore/platform/glib/LowPowerModeNotifierGLib.cpp (0 => 222834)


--- trunk/Source/WebCore/platform/glib/LowPowerModeNotifierGLib.cpp	                        (rev 0)
+++ trunk/Source/WebCore/platform/glib/LowPowerModeNotifierGLib.cpp	2017-10-04 07:46:25 UTC (rev 222834)
@@ -0,0 +1,59 @@
+/*
+ *  Copyright (C) 2017 Collabora Ltd.
+ *
+ *  This library is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Lesser General Public
+ *  License as published by the Free Software Foundation; either
+ *  version 2 of the License, or (at your option) any later version.
+ *
+ *  This library is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  Lesser General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Lesser General Public
+ *  License along with this library; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#include "config.h"
+#include "LowPowerModeNotifier.h"
+
+#if USE(UPOWER)
+namespace WebCore {
+
+LowPowerModeNotifier::LowPowerModeNotifier(LowPowerModeChangeCallback&& callback)
+    : m_upClient(adoptGRef(up_client_new()))
+    , m_device(adoptGRef(up_client_get_display_device(m_upClient.get())))
+    , m_callback(WTFMove(callback))
+{
+    updateState();
+
+    g_signal_connect_swapped(m_device.get(), "notify::warning-level", G_CALLBACK(warningLevelCallback), this);
+}
+
+void LowPowerModeNotifier::updateState()
+{
+    UpDeviceLevel warningLevel;
+    g_object_get(G_OBJECT(m_device.get()), "warning-level", &warningLevel, nullptr);
+    m_lowPowerModeEnabled = warningLevel > UP_DEVICE_LEVEL_DISCHARGING && warningLevel < UP_DEVICE_LEVEL_NORMAL;
+}
+
+void LowPowerModeNotifier::warningLevelCallback(LowPowerModeNotifier* notifier)
+{
+    notifier->updateState();
+    notifier->m_callback(notifier->m_lowPowerModeEnabled);
+}
+
+LowPowerModeNotifier::~LowPowerModeNotifier()
+{
+    g_signal_handlers_disconnect_by_data(m_device.get(), this);
+}
+
+bool LowPowerModeNotifier::isLowPowerModeEnabled() const
+{
+    return m_lowPowerModeEnabled;
+}
+
+}
+#endif

Added: trunk/Source/cmake/FindUPowerGLib.cmake (0 => 222834)


--- trunk/Source/cmake/FindUPowerGLib.cmake	                        (rev 0)
+++ trunk/Source/cmake/FindUPowerGLib.cmake	2017-10-04 07:46:25 UTC (rev 222834)
@@ -0,0 +1,47 @@
+# - Try to find libupower-glib.
+# Once done, this will define
+#
+#  UPOWERGLIB_INCLUDE_DIRS - the libtasn1 include directories
+#  UPOWERGLIB_LIBRARIES - the libtasn1 libraries.
+#
+# Copyright (C) 2017 Collabora Ltd.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+# THE POSSIBILITY OF SUCH DAMAGE.
+
+find_package(PkgConfig)
+pkg_check_modules(PC_UPOWERGLIB QUIET upower-glib)
+
+find_path(UPOWERGLIB_INCLUDE_DIRS
+    NAMES libupower-glib/upower.h
+    PATHS ${PC_UPOWERGLIB_INCLUDEDIR} ${PC_UPOWERGLIB_INCLUDE_DIRS}
+)
+
+find_library(UPOWERGLIB_LIBRARIES
+    NAMES upower-glib
+    PATHS ${PC_UPOWERGLIB_LIBDIR} ${PC_UPOWERGLIB_LIBRARY_DIRS}
+)
+
+mark_as_advanced(UPOWERGLIB_INCLUDE_DIRS UPOWERGLIB_LIBRARIES)
+
+include(FindPackageHandleStandardArgs)
+find_package_handle_standard_args(UPowerGLib REQUIRED_VARS UPOWERGLIB_INCLUDE_DIRS UPOWERGLIB_LIBRARIES
+                                  VERSION_VAR   PC_UPOWERGLIB_VERSION)

Modified: trunk/Source/cmake/OptionsGTK.cmake (222833 => 222834)


--- trunk/Source/cmake/OptionsGTK.cmake	2017-10-04 07:33:08 UTC (rev 222833)
+++ trunk/Source/cmake/OptionsGTK.cmake	2017-10-04 07:46:25 UTC (rev 222834)
@@ -92,6 +92,7 @@
 WEBKIT_OPTION_DEFINE(USE_LIBNOTIFY "Whether to enable the default web notification implementation." PUBLIC ON)
 WEBKIT_OPTION_DEFINE(USE_LIBHYPHEN "Whether to enable the default automatic hyphenation implementation." PUBLIC ON)
 WEBKIT_OPTION_DEFINE(USE_LIBSECRET "Whether to enable the persistent credential storage using libsecret." PUBLIC ON)
+WEBKIT_OPTION_DEFINE(USE_UPOWER "Whether to enable the low power mode implementation." PUBLIC ON)
 
 # Private options specific to the GTK+ port. Changing these options is
 # completely unsupported. They are intended for use only by WebKit developers.
@@ -374,6 +375,13 @@
     endif ()
 endif ()
 
+if (USE_UPOWER)
+    find_package(UPowerGLib)
+    if (NOT UPOWERGLIB_FOUND)
+       message(FATAL_ERROR "upower-glib is needed for USE_UPOWER.")
+    endif ()
+endif ()
+
 # Override the cached variables, gtk-doc and gobject-introspection do not really work when cross-building.
 if (CMAKE_CROSSCOMPILING)
     set(ENABLE_GTKDOC OFF)

Modified: trunk/Tools/ChangeLog (222833 => 222834)


--- trunk/Tools/ChangeLog	2017-10-04 07:33:08 UTC (rev 222833)
+++ trunk/Tools/ChangeLog	2017-10-04 07:46:25 UTC (rev 222834)
@@ -1,3 +1,12 @@
+2017-10-03  Gustavo Noronha Silva  <gustavo.noro...@collabora.co.uk>
+
+        [GLib] Let WebCore know of low power situations
+        https://bugs.webkit.org/show_bug.cgi?id=177810
+
+        Reviewed by Carlos Garcia Campos.
+
+        * gtk/install-dependencies: add upower-glib dev packages for Debian, Arch and Fedora.
+
 2017-10-03  Saam Barati  <sbar...@apple.com>
 
         Implement polymorphic prototypes

Modified: trunk/Tools/gtk/install-dependencies (222833 => 222834)


--- trunk/Tools/gtk/install-dependencies	2017-10-04 07:33:08 UTC (rev 222833)
+++ trunk/Tools/gtk/install-dependencies	2017-10-04 07:46:25 UTC (rev 222834)
@@ -137,6 +137,7 @@
         libtool \
         libvorbis-dev \
         libvpx-dev \
+        libupower-glib-dev \
         libwebp-dev \
         libxcomposite-dev \
         libxt-dev \
@@ -296,6 +297,7 @@
         libxt \
         libxslt \
         libxtst \
+        upower \
         ninja \
         ruby \
         util-linux \
@@ -439,7 +441,8 @@
         python-devel \
         redhat-rpm-config \
         ruby \
-        sqlite-devel"
+        sqlite-devel \
+        upower-devel"
 
     # These are dependencies necessary for running tests.
     packages="$packages \
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to