Bug 72327

Summary: WebGLRenderingContext: Remove duplicate DrawingBuffer binding code
Product: WebKit Reporter: Jeff Timanus <twiz>
Component: WebGLAssignee: Jeff Timanus <twiz>
Status: RESOLVED FIXED    
Severity: Normal CC: cc-bugs, dglazkov, jamesr, jchaffraix, kbr, senorblanco, webkit.review.bot
Priority: P2    
Version: 528+ (Nightly build)   
Hardware: All   
OS: All   
Bug Depends on: 72450    
Bug Blocks:    
Attachments:
Description Flags
Patch
none
Patch
none
Patch
none
Patch
none
Patch none

Description Jeff Timanus 2011-11-14 16:40:49 PST
The code paths in various WebGLRenderingContext methods duplicate the following structures frequently:

            // Commit DrawingBuffer if needed (e.g., for multisampling)
            if (!m_framebufferBinding && m_drawingBuffer)
                m_drawingBuffer->commit();

            // Interesting rendering code here . . . . 

            // Restore DrawingBuffer if needed
            if (!m_framebufferBinding && m_drawingBuffer)
                m_drawingBuffer->bind();

The code duplication should be eliminated via a scoped object.  See comments in https://bugs.webkit.org/show_bug.cgi?id=53201#c56
Comment 1 Jeff Timanus 2011-11-14 16:45:42 PST
Created attachment 115058 [details]
Patch
Comment 2 WebKit Review Bot 2011-11-14 16:55:43 PST
Comment on attachment 115058 [details]
Patch

Attachment 115058 [details] did not pass chromium-ews (chromium-xvfb):
Output: http://queues.webkit.org/results/10484102
Comment 3 Early Warning System Bot 2011-11-14 18:10:39 PST
Comment on attachment 115058 [details]
Patch

Attachment 115058 [details] did not pass qt-ews (qt):
Output: http://queues.webkit.org/results/10372339
Comment 4 Jeff Timanus 2011-11-14 18:38:35 PST
Created attachment 115081 [details]
Patch
Comment 5 Jeff Timanus 2011-11-14 18:43:27 PST
Comment on attachment 115081 [details]
Patch

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

> Source/WebCore/html/canvas/WebGLRenderingContext.cpp:1236
> +        ScopedDrawingBufferBinder(m_drawingBuffer, m_framebufferBinding);

Yikes!  There was a missing { } pair here that wasn't caught in my earlier submit.  Fixing here.
Comment 6 Stephen White 2011-11-15 06:47:21 PST
Comment on attachment 115081 [details]
Patch

Nice cleanup!  r=me
Comment 7 Julien Chaffraix 2011-11-15 09:10:51 PST
Comment on attachment 115081 [details]
Patch

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

> Source/WebCore/html/canvas/WebGLRenderingContext.cpp:105
> +        RefPtr<WebGLFramebuffer> m_framebufferBinding;

Quick question: do we really need to hold a reference to those 2 objects here? It looks like WebGLRenderingContext already hold a strong reference to those 2 so it just adds some reference churn.
Comment 8 Jeff Timanus 2011-11-15 09:26:02 PST
Comment on attachment 115081 [details]
Patch

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

>> Source/WebCore/html/canvas/WebGLRenderingContext.cpp:105
>> +        RefPtr<WebGLFramebuffer> m_framebufferBinding;
> 
> Quick question: do we really need to hold a reference to those 2 objects here? It looks like WebGLRenderingContext already hold a strong reference to those 2 so it just adds some reference churn.

No, there is no strict need for references to be held.  Raw pointers would also suffice.  

Is there a preference for smart pointers versus raw?  I chose smart pointers arbitrarily, because I have a slight aversion to storing raw pointers, except when necessary to prevent reference cycles or due to other implementation details.
Comment 9 Julien Chaffraix 2011-11-15 09:30:58 PST
Comment on attachment 115081 [details]
Patch

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

>>> Source/WebCore/html/canvas/WebGLRenderingContext.cpp:105
>>> +        RefPtr<WebGLFramebuffer> m_framebufferBinding;
>> 
>> Quick question: do we really need to hold a reference to those 2 objects here? It looks like WebGLRenderingContext already hold a strong reference to those 2 so it just adds some reference churn.
> 
> No, there is no strict need for references to be held.  Raw pointers would also suffice.  
> 
> Is there a preference for smart pointers versus raw?  I chose smart pointers arbitrarily, because I have a slight aversion to storing raw pointers, except when necessary to prevent reference cycles or due to other implementation details.

There is usually a preference towards using RefPtr only when you explicitly need to hold a reference to the object. It seems safe to switch that to raw pointers here so I would lean towards doing that (make sure you also change the constructor's arguments as PassRefPtr as the same effect).
Comment 10 Jeff Timanus 2011-11-15 10:36:33 PST
Created attachment 115195 [details]
Patch
Comment 11 Julien Chaffraix 2011-11-15 11:53:24 PST
Comment on attachment 115195 [details]
Patch

Forwarding Stephen's r+ as he knows the code better and I am fine with the new change. Thanks!
Comment 12 WebKit Review Bot 2011-11-15 12:21:24 PST
Comment on attachment 115195 [details]
Patch

Clearing flags on attachment: 115195

Committed r100308: <http://trac.webkit.org/changeset/100308>
Comment 13 WebKit Review Bot 2011-11-15 12:21:29 PST
All reviewed patches have been landed.  Closing bug.
Comment 14 Jeff Timanus 2011-11-15 19:34:32 PST
Created attachment 115301 [details]
Patch
Comment 15 Jeff Timanus 2011-11-15 19:36:57 PST
Comment on attachment 115301 [details]
Patch

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

> Source/WebCore/html/canvas/WebGLRenderingContext.cpp:1190
> +        ScopedDrawingBufferBinder binder(m_drawingBuffer.get(), m_framebufferBinding.get());

The previous changes had failed to make a local of the ScopedDrawingBufferBinder instance.  An anonymous instance was created, which was constructed and destroyed within the same sequence point, not at the scope block.
Comment 16 Kenneth Russell 2011-11-15 19:38:50 PST
For the record, previous patch was rolled out in https://bugs.webkit.org/show_bug.cgi?id=72450 / http://trac.webkit.org/changeset/100394 due to conformance suite regressions.
Comment 17 Kenneth Russell 2011-11-15 19:39:49 PST
Comment on attachment 115301 [details]
Patch

Nice cleanup and good catch. r=me
Comment 18 Jeff Timanus 2011-11-15 20:31:58 PST
(In reply to comment #14)
> Created an attachment (id=115301) [details]
> Patch

I can confirm that this change corrects all of the WebGL conformance regressions introduced by patch #3.

This patch fixes chrome bug crbug.com/104407, which had been opened in response to these regressions.
Comment 19 Kenneth Russell 2011-11-15 20:32:37 PST
Comment on attachment 115301 [details]
Patch

Sounds great. Marking cq+.
Comment 20 WebKit Review Bot 2011-11-15 20:47:28 PST
Comment on attachment 115301 [details]
Patch

Clearing flags on attachment: 115301

Committed r100399: <http://trac.webkit.org/changeset/100399>
Comment 21 WebKit Review Bot 2011-11-15 20:47:34 PST
All reviewed patches have been landed.  Closing bug.
Comment 22 Jeff Timanus 2011-11-23 12:31:06 PST
Created attachment 116399 [details]
Patch
Comment 23 Jeff Timanus 2011-11-23 12:34:36 PST
(In reply to comment #22)
> Created an attachment (id=116399) [details]
> Patch

Disregard this patch.  This patch was not intended for this issue.