<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>285167</bug_id>
          
          <creation_ts>2024-12-26 09:16:37 -0800</creation_ts>
          <short_desc>[GTK] Monitor window surfaces obscured by other windows (to suspend tabs, stop the frame clock and tell web apps to throttle themselves)</short_desc>
          <delta_ts>2025-01-10 00:31:00 -0800</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>WebKitGTK</component>
          <version>WebKit Nightly Build</version>
          <rep_platform>PC</rep_platform>
          <op_sys>Linux</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          <see_also>https://bugs.webkit.org/show_bug.cgi?id=207756</see_also>
    
    <see_also>https://bugs.webkit.org/show_bug.cgi?id=259227</see_also>
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords>Performance</keywords>
          <priority>P2</priority>
          <bug_severity>Enhancement</bug_severity>
          <target_milestone>---</target_milestone>
          
          <blocked>245783</blocked>
          <everconfirmed>1</everconfirmed>
          <reporter name="Jeff Fortin">nekohayo</reporter>
          <assigned_to name="Carlos Garcia Campos">cgarcia</assigned_to>
          <cc>bugs-noreply</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>2083978</commentid>
    <comment_count>0</comment_count>
    <who name="Jeff Fortin">nekohayo</who>
    <bug_when>2024-12-26 09:16:37 -0800</bug_when>
    <thetext>Context: https://bugs.webkit.org/show_bug.cgi?id=207756#c46

Symptoms: currently, if you have a website doing constant animations (or anything that uses the CPU), it will keep using CPU even if the window/surface is obscured by another.

The goal is for it to stop wasting CPU/GPU/battery power when the user does not have the web view (and tab) focused at the forefront, by stopping the frame clock and telling web apps to throttle themselves, by propagating `document.visibilityState` and `visibilitychange`, as per:

* https://developer.mozilla.org/en-US/docs/Web/API/Document/visibilitychange_event
* https://developer.mozilla.org/en-US/docs/Web/API/Document/visibilityState

I would want this to happen when the window is:

* hidden in part or whole by another window (whether maximized or not)
* on another virtual workspace
* minimized (or in hidden state)

We originally thought it was a Mutter window management bug, but it seems to be a case where WebKitGTK is not actually using the Mutter/Wayland APIs to achieve this. Among the things I heard:

&gt; It&apos;s the owner of the `xdg_toplevel` that receives the suspended event.  
&gt; GTK4 for example plumbs this to `GDK_TOPLEVEL_STATE_SUSPENDED`.  
&gt; For WebKitGTK to make use of it, it needs to check for `GDK_TOPLEVEL_STATE_SUSPENDED`.  
&gt; In GTK3, it&apos;s exposed as `GDK_VISIBILITY_FULLY_OBSCURED`.

Please see https://gitlab.gnome.org/GNOME/mutter/-/issues/3634 for the detailed discussion around this, as reference.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2084173</commentid>
    <comment_count>1</comment_count>
    <who name="Jeff Fortin">nekohayo</who>
    <bug_when>2024-12-28 17:05:35 -0800</bug_when>
    <thetext>In case it makes it easier to test one of the scenarios, in a similar issue in Firefox (https://bugzilla.mozilla.org/show_bug.cgi?id=1771902), I have discovered this handy CSS animations bench test: https://fqueze.github.io/tests/test-background-anim.html

With that test, Epiphany TP (Skia) uses CPU even if the browser window is partially or fully occluded by another app&apos;s window.
CPU usage falls to zero if switching to another tab, minimizing the window, or switching to another workspace.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2085765</commentid>
    <comment_count>2</comment_count>
    <who name="Carlos Garcia Campos">cgarcia</who>
    <bug_when>2025-01-08 05:11:10 -0800</bug_when>
    <thetext>Pull request: https://github.com/WebKit/WebKit/pull/38717</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2086283</commentid>
    <comment_count>3</comment_count>
    <who name="EWS">ews-feeder</who>
    <bug_when>2025-01-10 00:30:57 -0800</bug_when>
    <thetext>Committed 288685@main (8d7385fad3ff): &lt;https://commits.webkit.org/288685@main&gt;

Reviewed commits have been landed. Closing PR #38717 and removing active labels.</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>