Changeset 148202 in webkit


Ignore:
Timestamp:
Apr 11, 2013 7:42:14 AM (11 years ago)
Author:
commit-queue@webkit.org
Message:

[GTK][AC] use a smart pointer for GList and ClutterCanvas
https://bugs.webkit.org/show_bug.cgi?id=114057

Patch by ChangSeok Oh <ChangSeok Oh> on 2013-04-11
Reviewed by Gustavo Noronha Silva.

We can make simple code & prevent possible memory leak by using a proper smart pointer.
Especially if we get children by clutter_actor_get_children, we should free it after using.

No functionality changed.

  • platform/graphics/clutter/GraphicsLayerActor.cpp:

(graphicsLayerActorUpdateTexture):
(graphicsLayerActorRemoveAll):

Location:
trunk/Source/WebCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r148201 r148202  
     12013-04-11  ChangSeok Oh  <changseok.oh@collabora.com>
     2
     3        [GTK][AC] use a smart pointer for GList and ClutterCanvas
     4        https://bugs.webkit.org/show_bug.cgi?id=114057
     5
     6        Reviewed by Gustavo Noronha Silva.
     7
     8        We can make simple code & prevent possible memory leak by using a proper smart pointer.
     9        Especially if we get children by clutter_actor_get_children, we should free it after using.
     10
     11        No functionality changed.
     12
     13        * platform/graphics/clutter/GraphicsLayerActor.cpp:
     14        (graphicsLayerActorUpdateTexture):
     15        (graphicsLayerActorRemoveAll):
     16
    1172013-04-11  Arvid Nilsson  <anilsson@rim.com>
    218
  • trunk/Source/WebCore/platform/graphics/clutter/GraphicsLayerActor.cpp

    r147644 r148202  
    3030#include "RefPtrCairo.h"
    3131#include "TransformationMatrix.h"
     32#include <algorithm>
     33#include <wtf/gobject/GOwnPtr.h>
    3234#include <wtf/text/CString.h>
    3335
     
    267269
    268270    ClutterActor* actor = CLUTTER_ACTOR(layer);
    269     ClutterContent* canvas = clutter_actor_get_content(actor);
     271    GRefPtr<ClutterContent> canvas = adoptGRef(clutter_actor_get_content(actor));
    270272    if (canvas) {
    271273        // Nothing needs a texture, remove the one we have, if any.
    272274        if (!priv->drawsContent && !priv->surface) {
    273             g_signal_handlers_disconnect_by_func(canvas, reinterpret_cast<void*>(graphicsLayerActorDraw), layer);
     275            g_signal_handlers_disconnect_by_func(canvas.get(), reinterpret_cast<void*>(graphicsLayerActorDraw), layer);
    274276            clutter_actor_set_content(actor, 0);
    275277        }
     
    278280
    279281    // We should have a texture, so create one.
    280     int width = ceilf(clutter_actor_get_width(actor));
    281     int height = ceilf(clutter_actor_get_height(actor));
    282 
    283     canvas = clutter_canvas_new();
    284     clutter_actor_set_content(actor, canvas);
    285     clutter_canvas_set_size(CLUTTER_CANVAS(canvas), width > 0 ? width : 1, height > 0 ? height : 1);
    286     g_object_unref(canvas);
    287    
    288     g_signal_connect(canvas, "draw", G_CALLBACK(graphicsLayerActorDraw), layer);
     282    canvas = adoptGRef(clutter_canvas_new());
     283    clutter_actor_set_content(actor, canvas.get());
     284
     285    int width = std::max(static_cast<int>(ceilf(clutter_actor_get_width(actor))), 1);
     286    int height = std::max(static_cast<int>(ceilf(clutter_actor_get_height(actor))), 1);
     287    clutter_canvas_set_size(CLUTTER_CANVAS(canvas.get()), width, height);
     288
     289    g_signal_connect(canvas.get(), "draw", G_CALLBACK(graphicsLayerActorDraw), layer);
    289290}
    290291
     
    340341    g_return_if_fail(GRAPHICS_LAYER_IS_ACTOR(layer));
    341342
    342     GList* children = clutter_actor_get_children(CLUTTER_ACTOR(layer));
    343     for (; children; children = children->next)
    344         clutter_actor_remove_child(CLUTTER_ACTOR(layer), CLUTTER_ACTOR(children->data));
     343    GOwnPtr<GList> children(clutter_actor_get_children(CLUTTER_ACTOR(layer)));
     344    for (GList* child = children.get(); child; child = child->next)
     345        clutter_actor_remove_child(CLUTTER_ACTOR(layer), CLUTTER_ACTOR(child->data));
    345346}
    346347
Note: See TracChangeset for help on using the changeset viewer.