Bug 103650 - [CoordinatedGraphics] Use OwnPtr for LayerMap's layers in LayerTreeRenderer
Summary: [CoordinatedGraphics] Use OwnPtr for LayerMap's layers in LayerTreeRenderer
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebKit2 (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Chris Dumez
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-11-29 10:38 PST by Chris Dumez
Modified: 2012-12-01 02:06 PST (History)
6 users (show)

See Also:


Attachments
Patch (4.91 KB, patch)
2012-11-29 10:45 PST, Chris Dumez
no flags Details | Formatted Diff | Diff
Patch (4.92 KB, patch)
2012-11-29 11:45 PST, 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 2012-11-29 10:38:00 PST
We currently store raw pointers to WebCore::GraphicsLayer in the LayerMap meaning that we need to delete them manually.
We could use smart pointers and store them as OwnPtr in the LayerMap. The LayerMap would own the layers and we would not need to handle memory manually.
Comment 1 Chris Dumez 2012-11-29 10:45:02 PST
Created attachment 176759 [details]
Patch
Comment 2 Kenneth Rohde Christiansen 2012-11-29 10:50:06 PST
Comment on attachment 176759 [details]
Patch

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

> Source/WebKit2/UIProcess/CoordinatedGraphics/LayerTreeRenderer.h:183
> +    typedef HashMap< WebLayerID, OwnPtr<WebCore::GraphicsLayer> > LayerMap;

I dont think the first space is needed

> Source/WebKit2/UIProcess/CoordinatedGraphics/LayerTreeRenderer.h:185
> +    typedef HashMap<WebLayerID, WebCore::GraphicsLayer*> RawLayerMap;

LayerPtrMap ?
Comment 3 Kenneth Rohde Christiansen 2012-11-29 10:52:33 PST
Comment on attachment 176759 [details]
Patch

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

> Source/WebKit2/UIProcess/CoordinatedGraphics/LayerTreeRenderer.cpp:-375
>      m_fixedLayers.remove(layerID);
>  #if USE(GRAPHICS_SURFACE)
>      m_surfaceBackingStores.remove(layerID);
>  #endif
> -    delete layer;

so how are they stored here
Comment 4 Chris Dumez 2012-11-29 10:59:39 PST
Comment on attachment 176759 [details]
Patch

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

>> Source/WebKit2/UIProcess/CoordinatedGraphics/LayerTreeRenderer.cpp:-375
>> -    delete layer;
> 
> so how are they stored here

Sorry, I don't get the question. Is the comment on the right line?
I'm merely removing the explicit deletion here since it will get deleted when the OwnPtr goes out of scope.

>> Source/WebKit2/UIProcess/CoordinatedGraphics/LayerTreeRenderer.h:183
>> +    typedef HashMap< WebLayerID, OwnPtr<WebCore::GraphicsLayer> > LayerMap;
> 
> I dont think the first space is needed

It is not but I like symmetry :) Anyway, if the other way is more common I will change.

>> Source/WebKit2/UIProcess/CoordinatedGraphics/LayerTreeRenderer.h:185
>> +    typedef HashMap<WebLayerID, WebCore::GraphicsLayer*> RawLayerMap;
> 
> LayerPtrMap ?

Is it really clearer? They are both pointers (Ptr), the different is that one is raw and the other isn't. LayerRawPtrMap ?
Comment 5 Kenneth Rohde Christiansen 2012-11-29 11:40:43 PST
(In reply to comment #4)
> (From update of attachment 176759 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=176759&action=review
> 
> >> Source/WebKit2/UIProcess/CoordinatedGraphics/LayerTreeRenderer.cpp:-375
> >> -    delete layer;
> > 
> > so how are they stored here
> 
> Sorry, I don't get the question. Is the comment on the right line?
> I'm merely removing the explicit deletion here since it will get deleted when the OwnPtr goes out of scope.

I was refering to m_surfaceBackingStores.remove(layerID); but that is out of scope for this patch


> >> Source/WebKit2/UIProcess/CoordinatedGraphics/LayerTreeRenderer.h:183
> >> +    typedef HashMap< WebLayerID, OwnPtr<WebCore::GraphicsLayer> > LayerMap;
> > 
> > I dont think the first space is needed
> 
> It is not but I like symmetry :) Anyway, if the other way is more common I will change.

Dont do this, it is uncommon and as you can see not done in RawLayerMap

> 
> >> Source/WebKit2/UIProcess/CoordinatedGraphics/LayerTreeRenderer.h:185
> >> +    typedef HashMap<WebLayerID, WebCore::GraphicsLayer*> RawLayerMap;
> > 
> > LayerPtrMap ?
> 
> Is it really clearer? They are both pointers (Ptr), the different is that one is raw and the other isn't. LayerRawPtrMap ?

yes I like LayerRawPtrMap more
Comment 6 Chris Dumez 2012-11-29 11:45:28 PST
Created attachment 176771 [details]
Patch

Take Kenneth's feedback into consideration.
Comment 7 Noam Rosenthal 2012-11-29 11:47:34 PST
Comment on attachment 176771 [details]
Patch

This is fine with me. Leaving cq still at ? in case Kenneth has more comments :)
Comment 8 Mikhail Pozdnyakov 2012-11-29 12:37:11 PST
Comment on attachment 176771 [details]
Patch

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

> Source/WebKit2/UIProcess/CoordinatedGraphics/LayerTreeRenderer.cpp:366
> +    OwnPtr<GraphicsLayer> layer = m_layers.take(layerID);

Is it OwnPtr(const OwnPtr<ValueType>&); ?
        // This copy constructor is used implicitly by gcc when it generates
        // transients for assigning a PassOwnPtr<T> object to a stack-allocated
        // OwnPtr<T> object. It should never be called explicitly and gcc
        // should optimize away the constructor when generating code.
Comment 9 Chris Dumez 2012-11-29 12:39:09 PST
Comment on attachment 176771 [details]
Patch

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

>> Source/WebKit2/UIProcess/CoordinatedGraphics/LayerTreeRenderer.cpp:366
>> +    OwnPtr<GraphicsLayer> layer = m_layers.take(layerID);
> 
> Is it OwnPtr(const OwnPtr<ValueType>&); ?
>         // This copy constructor is used implicitly by gcc when it generates
>         // transients for assigning a PassOwnPtr<T> object to a stack-allocated
>         // OwnPtr<T> object. It should never be called explicitly and gcc
>         // should optimize away the constructor when generating code.

take() returns a PassOwnPtr here so it is fine.
Comment 10 WebKit Review Bot 2012-11-29 16:30:04 PST
Comment on attachment 176771 [details]
Patch

Clearing flags on attachment: 176771

Committed r136181: <http://trac.webkit.org/changeset/136181>
Comment 11 WebKit Review Bot 2012-11-29 16:30:09 PST
All reviewed patches have been landed.  Closing bug.
Comment 12 Dongseong Hwang 2012-12-01 00:45:45 PST
I'm afraid whether it is safe for HashMap to contain OwnPtr.

AFAIK, Vector<OwnPtr<T> > is unsafe because relocating can call destructor and constructor.

I don't know detail of HashMap implementation, so I can not say it is unsafe surely. However, I'm afraid.

In common, we don't store autoptr in stl::HashMap.
Comment 13 Chris Dumez 2012-12-01 01:01:08 PST
(In reply to comment #12)
> I'm afraid whether it is safe for HashMap to contain OwnPtr.
> 
> AFAIK, Vector<OwnPtr<T> > is unsafe because relocating can call destructor and constructor.
> 
> I don't know detail of HashMap implementation, so I can not say it is unsafe surely. However, I'm afraid.
> 
> In common, we don't store autoptr in stl::HashMap.

The WTF::HashMap has a specific behaviour for OwnPtr defined in HashTraits.h. I don't think this is unsafe and it is also used in other places in WebKit.
Comment 14 Dongseong Hwang 2012-12-01 02:06:31 PST
(In reply to comment #13)
> (In reply to comment #12)
> > I'm afraid whether it is safe for HashMap to contain OwnPtr.
> > 
> > AFAIK, Vector<OwnPtr<T> > is unsafe because relocating can call destructor and constructor.
> > 
> > I don't know detail of HashMap implementation, so I can not say it is unsafe surely. However, I'm afraid.
> > 
> > In common, we don't store autoptr in stl::HashMap.
> 
> The WTF::HashMap has a specific behaviour for OwnPtr defined in HashTraits.h. I don't think this is unsafe and it is also used in other places in WebKit.

Thanks for explanation!