2 Copyright (C) 2009-2010 ProFUSION embedded systems
3 Copyright (C) 2009-2010 Samsung Electronics
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library 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.
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 Library General Public License for more details.
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
24 #include "bindings/js/GCController.h"
25 #include "workers/WorkerThread.h"
27 #include "ewk_private.h"
28 #include <eina_safety_checks.h>
35 * Converts an image from cairo_surface to the Evas_Object.
37 * @param canvas display canvas
38 * @param surface cairo representation of an image
39 * @return converted cairo_surface object to the Evas_Object
41 Evas_Object *ewk_util_image_from_cairo_surface_add(Evas *canvas, cairo_surface_t *surface)
43 cairo_status_t status;
44 cairo_surface_type_t type;
45 cairo_format_t format;
51 EINA_SAFETY_ON_NULL_RETURN_VAL(canvas, 0);
52 EINA_SAFETY_ON_NULL_RETURN_VAL(surface, 0);
54 status = cairo_surface_status(surface);
55 if (status != CAIRO_STATUS_SUCCESS) {
56 ERR("cairo surface is invalid: %s", cairo_status_to_string(status));
60 type = cairo_surface_get_type(surface);
61 if (type != CAIRO_SURFACE_TYPE_IMAGE) {
62 ERR("unknown surface type %d, required %d (CAIRO_SURFACE_TYPE_IMAGE).",
63 type, CAIRO_SURFACE_TYPE_IMAGE);
67 format = cairo_image_surface_get_format(surface);
68 if (format != CAIRO_FORMAT_ARGB32 && format != CAIRO_FORMAT_RGB24) {
69 ERR("unknown surface format %d, expected %d or %d.",
70 format, CAIRO_FORMAT_ARGB32, CAIRO_FORMAT_RGB24);
74 w = cairo_image_surface_get_width(surface);
75 h = cairo_image_surface_get_height(surface);
76 stride = cairo_image_surface_get_stride(surface);
77 if (w <= 0 || h <= 0 || stride <= 0) {
78 ERR("invalid image size %dx%d, stride=%d", w, h, stride);
82 src = cairo_image_surface_get_data(surface);
84 ERR("could not get source data.");
88 image = evas_object_image_filled_add(canvas);
90 ERR("could not add image to canvas.");
94 evas_object_image_colorspace_set(image, EVAS_COLORSPACE_ARGB8888);
95 evas_object_image_size_set(image, w, h);
96 evas_object_image_alpha_set(image, format == CAIRO_FORMAT_ARGB32);
98 if (evas_object_image_stride_get(image) != stride) {
99 ERR("evas' stride %d diverges from cairo's %d.",
100 evas_object_image_stride_get(image), stride);
101 evas_object_del(image);
105 dst = evas_object_image_data_get(image, EINA_TRUE);
106 memcpy(dst, src, h * stride);
107 evas_object_image_data_set(image, dst);
109 evas_object_resize(image, w, h); // helpful but not really required
117 * Performs garbage collection of JavaScript objects.
119 void ewk_util_javascript_gc_collect()
121 WebCore::gcController().garbageCollectNow();
127 * Performs garbage collection of JavaScript objects in a separate thread.
129 * @param waitUntilDone If @c TRUE, wait the garbage collection thread to finish; if @c FALSE,
130 * return as soon as the thread has been created.
132 void ewk_util_javascript_gc_alternate_thread_collect(Eina_Bool waitUntilDone)
134 WebCore::gcController().garbageCollectOnAlternateThreadForDebugging(waitUntilDone);
140 * Returns the number of current JavaScript objects.
142 unsigned ewk_util_javascript_gc_object_count_get()
144 return WebCore::JSDOMWindow::commonJSGlobalData()->heap.objectCount();
150 * Returns the number of current worked threads.
152 unsigned ewk_util_worker_thread_count()
155 return WebCore::WorkerThread::workerThreadCount();
165 * @return device's dpi value.
167 int ewk_util_dpi_get(void)
170 return ecore_x_dpi_get();