RefPtrEfl.cpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /*
  2. * Copyright (C) 2011 Samsung Electronics
  3. * Copyright (C) 2012 Intel Corporation. All rights reserved.
  4. *
  5. * This library is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU Lesser General Public
  7. * License as published by the Free Software Foundation; either
  8. * version 2 of the License, or (at your option) any later version.
  9. *
  10. * This library is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * Lesser General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU Lesser General Public
  16. * License along with this library; if not, write to the Free Software
  17. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  18. */
  19. #include "config.h"
  20. #include "RefPtrEfl.h"
  21. #include <Evas.h>
  22. namespace WTF {
  23. template<> void refIfNotNull(Evas_Object* ptr)
  24. {
  25. if (LIKELY(!!ptr))
  26. evas_object_ref(ptr);
  27. }
  28. template<> void derefIfNotNull(Evas_Object* ptr)
  29. {
  30. // Refcounting in Evas_Object is different that normal. The object is created
  31. // with an external ref count of 0, but with one internal count of 1 which can
  32. // only be removed by calling _del. Calling _del with an external ref count > 0,
  33. // postposes deletion until it reaches 0.
  34. if (LIKELY(!!ptr)) {
  35. if (evas_object_ref_get(ptr) > 0)
  36. evas_object_unref(ptr);
  37. else
  38. evas_object_del(ptr);
  39. }
  40. }
  41. }