RESOLVED FIXED103650
[CoordinatedGraphics] Use OwnPtr for LayerMap's layers in LayerTreeRenderer
https://bugs.webkit.org/show_bug.cgi?id=103650
Summary [CoordinatedGraphics] Use OwnPtr for LayerMap's layers in LayerTreeRenderer
Chris Dumez
Reported 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.
Attachments
Patch (4.91 KB, patch)
2012-11-29 10:45 PST, Chris Dumez
no flags
Patch (4.92 KB, patch)
2012-11-29 11:45 PST, Chris Dumez
no flags
Chris Dumez
Comment 1 2012-11-29 10:45:02 PST
Kenneth Rohde Christiansen
Comment 2 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 ?
Kenneth Rohde Christiansen
Comment 3 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
Chris Dumez
Comment 4 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 ?
Kenneth Rohde Christiansen
Comment 5 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
Chris Dumez
Comment 6 2012-11-29 11:45:28 PST
Created attachment 176771 [details] Patch Take Kenneth's feedback into consideration.
Noam Rosenthal
Comment 7 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 :)
Mikhail Pozdnyakov
Comment 8 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.
Chris Dumez
Comment 9 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.
WebKit Review Bot
Comment 10 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>
WebKit Review Bot
Comment 11 2012-11-29 16:30:09 PST
All reviewed patches have been landed. Closing bug.
Dongseong Hwang
Comment 12 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.
Chris Dumez
Comment 13 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.
Dongseong Hwang
Comment 14 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!
Note You need to log in before you can comment on or make changes to this bug.