Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to defer delivering an event to a background tab until it's foreground again?

19 views
Skip to first unread message

Benoit Jacob

unread,
Apr 29, 2012, 11:34:47 AM4/29/12
to dev-platform
Hi,

Recently we started losing all WebGL contexts on "memory-pressure"
events. These can be manually triggered in about:memory by clicking
"Minimize memory usage".

Losing a WebGL context consists in:
- immediately freeing all its resources and setting a flag that
causes WebGL calls to be no-ops.
- immediately delivering a a "webglcontextlost" event to the script.
If the scripts wants to restore that context, it does
"preventDefault", in which case, if the browser decides to allow
restoring the context, the script gets a "webglcontextrestored" event,
at which time it can start recreating the WebGL context's state.

If a background tab script loses a WebGL context, I would like it to
get "webglcontextlost" immediately but "webglcontextrestored" only
when it's in the foreground again.

Does that sound OK? How can I achieve this?

Benoit

Justin Lebar

unread,
Apr 29, 2012, 11:53:06 AM4/29/12
to Benoit Jacob, dev-platform
> If a background tab script loses a WebGL context, I would like it to
> get "webglcontextlost" immediately but "webglcontextrestored" only
> when it's in the foreground again.

Register a visibilitychange listener on the window?

https://developer.mozilla.org/en/DOM/Using_the_Page_Visibility_API

> Does that sound OK? How can I achieve this?

We're currently pretty bad at sending memory-pressure notifications
when we're actually low on memory. So you may want to expire the
context after the tab is in the background for some amount of time.

-Justin

Benoit Jacob

unread,
Apr 29, 2012, 3:49:01 PM4/29/12
to Justin Lebar, dev-platform
2012/4/29 Justin Lebar <justin...@gmail.com>:
>> If a background tab script loses a WebGL context, I would like it to
>> get "webglcontextlost" immediately but "webglcontextrestored" only
>> when it's in the foreground again.
>
> Register a visibilitychange listener on the window?
>
> https://developer.mozilla.org/en/DOM/Using_the_Page_Visibility_API

How do I do this in C++ code?

>
>> Does that sound OK? How can I achieve this?
>
> We're currently pretty bad at sending memory-pressure notifications
> when we're actually low on memory.  So you may want to expire the
> context after the tab is in the background for some amount of time.

I planned to do this as a separate, orthogonal thing, yes. Any pointer
on how to implement this?

Benoit

>
> -Justin

Justin Lebar

unread,
Apr 30, 2012, 11:44:18 AM4/30/12
to Benoit Jacob, dev-platform
On Sun, Apr 29, 2012 at 3:49 PM, Benoit Jacob <jacob.b...@gmail.com> wrote:
> 2012/4/29 Justin Lebar <justin...@gmail.com>:
>>> If a background tab script loses a WebGL context, I would like it to
>>> get "webglcontextlost" immediately but "webglcontextrestored" only
>>> when it's in the foreground again.
>>
>> Register a visibilitychange listener on the window?
>>
>> https://developer.mozilla.org/en/DOM/Using_the_Page_Visibility_API
>
> How do I do this in C++ code?

I searched C++ files for "visibilitychange" and found that
dom/power/WakeLock.cpp implements a visibilitychange listener. Maybe
start there and ping me if it's unclear?

>> We're currently pretty bad at sending memory-pressure notifications
>> when we're actually low on memory.  So you may want to expire the
>> context after the tab is in the background for some amount of time.
>
> I planned to do this as a separate, orthogonal thing, yes. Any pointer
> on how to implement this?

There's similar logic in image/src/DiscardTracker.cpp, although I kind
of wish we would generalize it into a "discard list" data structure.

-Justin
0 new messages