Bug 88940

Summary: DrawingArea: Painting is being resumed while the view is not visible
Product: WebKit Reporter: Tim Horton <thorton>
Component: WebKit2Assignee: Tim Horton <thorton>
Status: RESOLVED FIXED    
Severity: Normal CC: adele, andersca, bdakin, jer.noble, simon.fraser
Priority: P2 Keywords: InRadar
Version: 528+ (Nightly build)   
Hardware: Unspecified   
OS: Unspecified   
Attachments:
Description Flags
patch, but needs more testing before landing
none
patch (disable suspend/resumePainting messages when doing fullscreen animation)
dino: review-
patch, name is no better, changelog is improved dino: review+

Description Tim Horton 2012-06-12 17:22:25 PDT
From my ChangeLog:

Using requestAnimationFrame and the fullscreen API on a DrawingArea-backed window
would cause rAF to permanently suspend animations when fullscreened, because of the following:

0. JavaScript causes fullscreen transition to start.
1. Painting (and rAF) are suspended.
2. The page changes size.
    a. DrawingAreaProxyImpl::sizeDidChange() calls DrawingAreaImpl::updateBackingStoreState, which calls DrawingAreaImpl::resumePainting.
    b. DrawingAreaImpl::resumePainting resumes painting, but does *not* resume rAF, because windowIsVisible is (legitimately) false.
3. The view becomes visible, windowIsVisible is updated to true.
4. visibilityDidChange() calls resumePainting again, but this time it early exits because painting is not suspended.

Notice that because of the early exit in 4, rAF is never resumed.

I have a fix:

If DrawingAreaProxyImpl::sizeDidChange or DrawingAreaProxyImpl::deviceScaleFactorDidChange are called while the view is not visible, defer their call to update the backing store state until the view is once again made visible.

<rdar://problem/11587039>
Comment 1 Tim Horton 2012-06-12 17:32:53 PDT
The radar is actually <rdar://problem/11652545>
Comment 2 Tim Horton 2012-06-12 17:45:24 PDT
Created attachment 147201 [details]
patch, but needs more testing before landing
Comment 3 Tim Horton 2012-06-13 15:53:42 PDT
Created attachment 147433 [details]
patch (disable suspend/resumePainting messages when doing fullscreen animation)

The old patch didn't work, because we actually depend on painting *not* being frozen to paint the image that's animated to full-screen! So, it caused the animation to look terrible.

This one is a bit more wonky/scary, but I haven't been able to break it yet. Still needs more testing.
Comment 4 Jer Noble 2012-06-14 13:39:20 PDT
Looks good to me.  Informal r+.
Comment 5 Dean Jackson 2012-06-14 13:48:46 PDT
Comment on attachment 147433 [details]
patch (disable suspend/resumePainting messages when doing fullscreen animation)

View in context: https://bugs.webkit.org/attachment.cgi?id=147433&action=review

> Source/WebKit2/ChangeLog:9
> +        Don't send any SuspendPainting/ResumePainting messages during full-screen animations on Mac.

Could you add more explanation here? Why was this a problem, and what are you doing now (transitions to and from fullscreen can continue to paint, etc).

> Source/WebKit2/UIProcess/API/mac/WKView.h:47
> +@property BOOL automaticallySuspendAndResumePainting;

I don't like the name of this property. Also, it's probably a bit backwards isn't it? You are now adding the functionality to NOT automatically suspend painting. Maybe it should be just called suspendsPaintingDuringWindowAnimations or something (that's a bad name too)
Comment 6 Tim Horton 2012-06-14 15:18:43 PDT
(In reply to comment #5)
> (From update of attachment 147433 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=147433&action=review
> 
> > Source/WebKit2/ChangeLog:9
> > +        Don't send any SuspendPainting/ResumePainting messages during full-screen animations on Mac.
> 
> Could you add more explanation here? Why was this a problem, and what are you doing now (transitions to and from fullscreen can continue to paint, etc).
> 
> > Source/WebKit2/UIProcess/API/mac/WKView.h:47
> > +@property BOOL automaticallySuspendAndResumePainting;
> 
> I don't like the name of this property. Also, it's probably a bit backwards isn't it? You are now adding the functionality to NOT automatically suspend painting. Maybe it should be just called suspendsPaintingDuringWindowAnimations or something (that's a bad name too)

"DuringWindowAnimations" is irrelevant, WKView has no idea that's why this is being used, just that it should stop sending suspend/resume messages.
Comment 7 Tim Horton 2012-06-14 15:18:53 PDT
I still don't have a good name.
Comment 8 Tim Horton 2012-06-14 16:20:11 PDT
Created attachment 147676 [details]
patch, name is no better, changelog is improved
Comment 9 Dean Jackson 2012-06-14 16:32:32 PDT
Comment on attachment 147676 [details]
patch, name is no better, changelog is improved

View in context: https://bugs.webkit.org/attachment.cgi?id=147676&action=review

Great changelog.

Still don't like the name. Maybe suspendPaintingWhileWindowHostingChanges ? Marking r+ and we can work out the name on irc.

> Source/WebKit2/ChangeLog:10
> +        would cause rAF to permanently suspend animations when fullscreened, because of the following:

I would invent a word like "fullscreened" in my own patch, but in review I must strangely request something like "when the page is made fullscreen" :)
Comment 10 Tim Horton 2012-06-14 17:04:26 PDT
http://trac.webkit.org/changeset/120376