Open Bug 546837 Opened 15 years ago Updated 2 years ago

[OS X] Smoothly animate native widgets even when the main thread is blocked

Categories

(Core :: Widget: Cocoa, defect, P3)

x86
macOS
defect

Tracking

()

People

(Reporter: faaborg, Unassigned)

References

(Blocks 1 open bug)

Details

(Whiteboard: tpi:+)

Attachments

(2 files, 1 obsolete file)

This is the OS X equivalent to bug 392644 on Windows.  A number of native OS X widgets animate, including pulsing default dialog button, the pulsing progress bar, etc.  In Firefox we currently use a javascript timer for some of these, but that is really a hack.  This bug is to track support of native widget animation on OS X.
Blocks: 463695
Depends on: 546842
Blocks: 546842
No longer depends on: 546842
(In reply to comment #0)
> This is the OS X equivalent to bug 392644 on Windows.  A number of native OS X
> widgets animate, including pulsing default dialog button, the pulsing progress
> bar, etc.

What is "etc"? I'm only aware of those two.

> In Firefox we currently use a javascript timer for some of these,
> but that is really a hack. This bug is to track support of native widget
> animation on OS X.

So this bug is really about changing the implementation not to use JavaScript for the animation? There's no such thing as "native" animation - we just have to trigger repaints at the right time, and whether those are triggered via JavaScript or something else doesn't really matter.
>What is "etc"? I'm only aware of those two.

Was filing quickly and figured I missed some.  Aside from variations of the progress bar (indeterminate, normal), I guess those are in fact the only two that have any amount of animation.

>So this bug is really about changing the implementation not to use JavaScript
>for the animation? There's no such thing as "native" animation - we just have
>to trigger repaints at the right time, and whether those are triggered via
>JavaScript or something else doesn't really matter.

Sorry, meant [firefox's animation] of [native widgets].  We need to drastically increase the frame rate of the animation in order to be imperceptibly non-native.

My impression, although I could be entirely wrong, is that instead of a top down approach where javascript forcibly animates these widgets, we would want to go with more of a bottom up approach, where the widgets can call their own repaints, and we are able to refresh the widgets in a way that doesn't block other javascript code from executing, and doesn't look like Firefox is struggling to draw a button or progress bar.
I read up on how Cocoa does these things for native NSProgressIndicators: they use a separate so-called heartbeat thread which repeatedly redraws the control by calling lockFocusIfCanDraw, drawRect, unlockFocus. Doing that kind of multithreaded drawing in Gecko isn't possible currently.

Roc, how will that change when we have a retained scene graph and off-the-main-thread animation? Will those animations be restricted to basic layer attributes like transform and opacity, or will it be possible to draw into them without waiting for the main thread to become available?
Summary: [OS X] Widget Animation → [OS X] Smoothly animate native widgets even when the main thread is blocked
We could definitely make it work once we have off-main-thread layer rendering. We should probably create a new layer type to represent animated theme backgrounds and create a thread-safe version of nsITheme::DrawWidgetBackground. This would be a very nice way to implement theme animation.

However, you'd have to put the themed display item in its own layer, which has memory overhead and can affect the display of content above it. In particular you would probably lose subpixel AA of text above the theme background. Not a problem for progress indicators I guess, maybe a problem for a throbbing dialog button?
Sounds good. We can probably get away with disabling subpixel AA for text on default buttons.
Hey guys, I think we're going to need this for bug 565217. Any progress updates, target milestone?
Blocks: 565217
Off-main-thread rendering won't happen for Firefox 4, as far as I know.
It won't. Why do you think it's needed for bug 565217?
(In reply to comment #8)
> It won't. Why do you think it's needed for bug 565217?

Our plan is to run the cycle collector's traverse phase while the main thread is blocked on the native event queue. If we can build a complete model and identify cycles before the main thread wakes back up then we can avoid a blocking cycle collection. If, on the other hand, we can't identify cycles in that amount of time then we will have to throw the model away and start over again next time. If we're constantly waking up to paint buttons then we will not see much benefit.
Well, the only reason we'd be waking up to paint is if either something changed, or if the OS needs something repainted that was just revealed.  The latter case is going to be rare, and the former case is going to require the main thread to be woken up no matter what -- even if the actual compositing happens off-thread.  Regardless, I don't think this specific bug is about either issue, but is instead much more narrowly scoped.
(In reply to comment #10)
> Well, the only reason we'd be waking up to paint is if either something
> changed, or if the OS needs something repainted that was just revealed.  The
> latter case is going to be rare, and the former case is going to require the
> main thread to be woken up no matter what -- even if the actual compositing
> happens off-thread.

No, the idea here is that we could animate native widgets by making them their own layers and doing the animation entirely in the layer compositing process.

But that certainly is not going to happen for FF4.
Well, I was more worried about the "one timer per animated button" problem where we have lots and lots of independent timers going off really frequently when they could all be rolled into one. Is that a separate issue?
Aha, great! Is there a bug filed for that?
I've filed bug 586216 on that.
Great! I'll flip the blocking flags to that bug instead as this one seems to be a much longer term solution.
No longer blocks: 565217
Depends on: 894905
This bug probably requires the same infrastructure as bug 717872, so I'm setting a dependency on that. Specifically, what I think is missing is:
 - Ability to update some kind of RGBA Image from a secondary thread. At the moment
   it looks like Images other than PLANAR_YCBCR can only be set on the main thread.
 - Ability to use simple memory buffers for data storage instead of shmems which are
   too heavy-weight.
 - fixes for some threading / object ownership issues
Depends on: omtagif
Attached patch wip (obsolete) — Splinter Review
This is on top of bug 894905.
Attached file testcase
Depends on: 894925
Attached patch wipSplinter Review
Attachment #777130 - Attachment is obsolete: true
Priority: -- → P3
Whiteboard: tpi:+
Severity: normal → S3
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: