2 * Copyright (c) 2007 Netlabs
3 * Copyright (c) 2006 Mozilla Corporation
4 * Copyright (c) 2006 Red Hat, Inc.
5 * Copyright (c) 2011 Andrea Canciani
7 * Permission to use, copy, modify, distribute, and sell this software
8 * and its documentation for any purpose is hereby granted without
9 * fee, provided that the above copyright notice appear in all copies
10 * and that both that copyright notice and this permission notice
11 * appear in supporting documentation, and that the name of
12 * the authors not be used in advertising or publicity pertaining to
13 * distribution of the software without specific, written prior
14 * permission. The authors make no representations about the
15 * suitability of this software for any purpose. It is provided "as
16 * is" without express or implied warranty.
18 * THE AUTHORS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
19 * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
20 * FITNESS, IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY SPECIAL,
21 * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
22 * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
23 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
24 * IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
26 * Authors: Peter Weilbacher <mozilla@weilbacher.org>
27 * Vladimir Vukicevic <vladimir@pobox.com> (win32/linux code)
28 * Carl Worth <cworth@cworth.org> (win32/linux code)
29 * Andrea Canciani <ranma42@gmail.com>
32 #include "cairo-perf.h"
33 #include "../src/cairo-time-private.h"
43 #define WIN32_LEAN_AND_MEAN
45 #elif defined(_POSIX_PRIORITY_SCHEDULING)
49 /* XXX: add thread-aware for gl backend */
50 #if CAIRO_HAS_GL_SURFACE || CAIRO_HAS_GLESV2_SURFACE
53 void cairo_perf_set_thread_aware (cairo_t *cr, cairo_bool_t thread_aware)
55 #if CAIRO_HAS_GL_SURFACE || CAIRO_HAS_GLESV2_SURFACE
56 cairo_device_t *device = cairo_surface_get_device (cairo_get_target (cr));
57 if (cairo_device_get_type (device) == CAIRO_DEVICE_TYPE_GL)
58 cairo_gl_device_set_thread_aware (device, thread_aware);
64 static cairo_time_t timer;
65 static cairo_perf_timer_synchronize_t cairo_perf_timer_synchronize = NULL;
66 static void *cairo_perf_timer_synchronize_closure = NULL;
69 cairo_perf_timer_set_synchronize (cairo_perf_timer_synchronize_t synchronize,
72 cairo_perf_timer_synchronize = synchronize;
73 cairo_perf_timer_synchronize_closure = closure;
77 cairo_perf_timer_start (void)
79 timer = _cairo_time_get ();
83 cairo_perf_timer_stop (void)
85 if (cairo_perf_timer_synchronize)
86 cairo_perf_timer_synchronize (cairo_perf_timer_synchronize_closure);
88 timer = _cairo_time_get_delta (timer);
92 cairo_perf_timer_elapsed (void)
98 cairo_perf_yield (void)
100 /* try to deactivate this thread until the scheduler calls it again */
104 #elif defined(_WIN32)
106 #elif defined(_POSIX_PRIORITY_SCHEDULING)