Bug 171977 - Stop using PassRefPtr in platform/graphics
Summary: Stop using PassRefPtr in platform/graphics
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Platform (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Chris Dumez
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-05-11 09:44 PDT by Chris Dumez
Modified: 2017-05-11 19:58 PDT (History)
6 users (show)

See Also:


Attachments
WIP Patch (136.58 KB, patch)
2017-05-11 12:37 PDT, Chris Dumez
no flags Details | Formatted Diff | Diff
WIP Patch (138.56 KB, patch)
2017-05-11 12:53 PDT, Chris Dumez
no flags Details | Formatted Diff | Diff
WIP Patch (144.46 KB, patch)
2017-05-11 13:01 PDT, Chris Dumez
no flags Details | Formatted Diff | Diff
WIP Patch (149.90 KB, patch)
2017-05-11 13:12 PDT, Chris Dumez
no flags Details | Formatted Diff | Diff
Patch (172.72 KB, patch)
2017-05-11 13:25 PDT, Chris Dumez
no flags Details | Formatted Diff | Diff
Patch (172.73 KB, patch)
2017-05-11 13:31 PDT, Chris Dumez
no flags Details | Formatted Diff | Diff
Patch (173.10 KB, patch)
2017-05-11 13:47 PDT, Chris Dumez
no flags Details | Formatted Diff | Diff
Patch (173.12 KB, patch)
2017-05-11 13:59 PDT, Chris Dumez
no flags Details | Formatted Diff | Diff
Patch (175.49 KB, patch)
2017-05-11 14:57 PDT, Chris Dumez
no flags Details | Formatted Diff | Diff
Patch (175.52 KB, patch)
2017-05-11 15:07 PDT, Chris Dumez
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Chris Dumez 2017-05-11 09:44:13 PDT
Stop using PassRefPtr in platform/graphics.
Comment 1 Chris Dumez 2017-05-11 12:37:50 PDT
Created attachment 309753 [details]
WIP Patch
Comment 2 Chris Dumez 2017-05-11 12:53:33 PDT
Created attachment 309755 [details]
WIP Patch
Comment 3 Chris Dumez 2017-05-11 13:01:35 PDT
Created attachment 309757 [details]
WIP Patch
Comment 4 Chris Dumez 2017-05-11 13:12:14 PDT
Created attachment 309760 [details]
WIP Patch
Comment 5 Chris Dumez 2017-05-11 13:25:40 PDT
Created attachment 309762 [details]
Patch
Comment 6 Chris Dumez 2017-05-11 13:31:55 PDT
Created attachment 309765 [details]
Patch
Comment 7 Chris Dumez 2017-05-11 13:47:32 PDT
Created attachment 309771 [details]
Patch
Comment 8 Chris Dumez 2017-05-11 13:59:47 PDT
Created attachment 309777 [details]
Patch
Comment 9 Chris Dumez 2017-05-11 14:57:49 PDT
Created attachment 309791 [details]
Patch
Comment 10 Alex Christensen 2017-05-11 15:04:22 PDT
Comment on attachment 309777 [details]
Patch

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

> Source/WebCore/platform/graphics/filters/FilterOperation.h:182
>          ASSERT_NOT_REACHED();
> -        return nullptr;
> +        return *static_cast<FilterOperation*>(nullptr);

This looks gross.  It should return a RefPtr or RELEASE_ASSERT_NOT_REACHED().  We shouldn't have to check a valid Ref for a nullptr.

> Source/WebCore/rendering/RenderLayer.cpp:3717
>      if (renderer().document().deviceScaleFactor() >= 2) {
> -        static NeverDestroyed<Image*> resizeCornerImageHiRes(Image::loadPlatformResource("textAreaResizeCorner@2x").leakRef());
> +        static NeverDestroyed<Image*> resizeCornerImageHiRes(&Image::loadPlatformResource("textAreaResizeCorner@2x").leakRef());

Don't we have 3x resources now?  Maybe we should update this.
Comment 11 Chris Dumez 2017-05-11 15:06:33 PDT
(In reply to Alex Christensen from comment #10)
> Comment on attachment 309777 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=309777&action=review
> 
> > Source/WebCore/platform/graphics/filters/FilterOperation.h:182
> >          ASSERT_NOT_REACHED();
> > -        return nullptr;
> > +        return *static_cast<FilterOperation*>(nullptr);
> 
> This looks gross.  It should return a RefPtr or
> RELEASE_ASSERT_NOT_REACHED().  We shouldn't have to check a valid Ref for a
> nullptr.

Sure, I do not mind making it a release assertion. It is going to crash on the next line anyway.

> 
> > Source/WebCore/rendering/RenderLayer.cpp:3717
> >      if (renderer().document().deviceScaleFactor() >= 2) {
> > -        static NeverDestroyed<Image*> resizeCornerImageHiRes(Image::loadPlatformResource("textAreaResizeCorner@2x").leakRef());
> > +        static NeverDestroyed<Image*> resizeCornerImageHiRes(&Image::loadPlatformResource("textAreaResizeCorner@2x").leakRef());
> 
> Don't we have 3x resources now?  Maybe we should update this.

Seems out of scope.
Comment 12 Chris Dumez 2017-05-11 15:07:26 PDT
Created attachment 309793 [details]
Patch
Comment 13 Alex Christensen 2017-05-11 15:29:56 PDT
> > Don't we have 3x resources now?  Maybe we should update this.
> 
> Seems out of scope.

Definitely out of scope.
Comment 14 Alex Christensen 2017-05-11 15:31:17 PDT
Comment on attachment 309793 [details]
Patch

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

> Source/WebCore/platform/graphics/filters/FilterOperation.h:182
> +        return *static_cast<FilterOperation*>(nullptr);

I would prefer dereferencing this.  Dereferencing nullptr feels really bad.
Comment 15 Chris Dumez 2017-05-11 15:38:08 PDT
(In reply to Alex Christensen from comment #14)
> Comment on attachment 309793 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=309793&action=review
> 
> > Source/WebCore/platform/graphics/filters/FilterOperation.h:182
> > +        return *static_cast<FilterOperation*>(nullptr);
> 
> I would prefer dereferencing this.  Dereferencing nullptr feels really bad.

If I return |this|, then I would need to const_cast it. Note that dereferencing nullptr is the pattern used here already:
Ref<Node> ShadowRoot::cloneNodeInternal(Document&, CloningOperation)
{
    RELEASE_ASSERT_NOT_REACHED();
    return *static_cast<Node*>(nullptr); // ShadowRoots should never be cloned.
}
Comment 16 Ryosuke Niwa 2017-05-11 16:38:18 PDT
Comment on attachment 309793 [details]
Patch

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

>>> Source/WebCore/platform/graphics/filters/FilterOperation.h:182
>>> +        return *static_cast<FilterOperation*>(nullptr);
>> 
>> I would prefer dereferencing this.  Dereferencing nullptr feels really bad.
> 
> If I return |this|, then I would need to const_cast it. Note that dereferencing nullptr is the pattern used here already:
> Ref<Node> ShadowRoot::cloneNodeInternal(Document&, CloningOperation)
> {
>     RELEASE_ASSERT_NOT_REACHED();
>     return *static_cast<Node*>(nullptr); // ShadowRoots should never be cloned.
> }

Yeah, I think returning casted nullptr is fine.
clang would be eliminating this code anyway due to reachability.
Comment 17 Chris Dumez 2017-05-11 16:40:19 PDT
Comment on attachment 309793 [details]
Patch

Clearing flags on attachment: 309793

Committed r216702: <http://trac.webkit.org/changeset/216702>
Comment 18 Chris Dumez 2017-05-11 16:40:21 PDT
All reviewed patches have been landed.  Closing bug.
Comment 19 Carlos Alberto Lopez Perez 2017-05-11 19:58:05 PDT
Committed r216722: <http://trac.webkit.org/changeset/216722>