1 /* cairo - a vector graphics library with display and print output
3 * Copyright © 2009 Luca Barbieri
4 * Copyright © 2009 Eric Anholt
5 * Copyright © 2009 Chris Wilson
6 * Copyright © 2005 Red Hat, Inc
8 * This library is free software; you can redistribute it and/or
9 * modify it either under the terms of the GNU Lesser General Public
10 * License version 2.1 as published by the Free Software Foundation
11 * (the "LGPL") or, at your option, under the terms of the Mozilla
12 * Public License Version 1.1 (the "MPL"). If you do not alter this
13 * notice, a recipient may use your version of this file under either
14 * the MPL or the LGPL.
16 * You should have received a copy of the LGPL along with this library
17 * in the file COPYING-LGPL-2.1; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 * You should have received a copy of the MPL along with this library
20 * in the file COPYING-MPL-1.1
22 * The contents of this file are subject to the Mozilla Public License
23 * Version 1.1 (the "License"); you may not use this file except in
24 * compliance with the License. You may obtain a copy of the License at
25 * http://www.mozilla.org/MPL/
27 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY
28 * OF ANY KIND, either express or implied. See the LGPL or the MPL for
29 * the specific language governing rights and limitations.
31 * The Original Code is the cairo graphics library.
33 * The Initial Developer of the Original Code is Red Hat, Inc.
36 * Carl Worth <cworth@cworth.org>
43 #if CAIRO_HAS_GPU_GALLIUM_SURFACE
44 #include "cairo-gpu-gallium.h"
47 #if CAIRO_HAS_GPU_GL_SURFACE
48 #include "cairo-gpu-gl.h"
51 #if CAIRO_HAS_XLIB_SURFACE
52 #include "cairo-xlib.h"
55 #if CAIRO_HAS_XCB_SURFACE
56 #include "cairo-xcb.h"
59 cairo_public cairo_space_t
*
60 cairo_xproto_space_create (const char* name
)
63 #if CAIRO_HAS_XCB_SURFACE
64 space
= cairo_xcb_space_create(name
);
69 #if CAIRO_HAS_XLIB_SURFACE
70 space
= cairo_xlib_space_create(name
);
77 cairo_public cairo_space_t
*
78 cairo_space_wrap_xlib(Display
* dpy
, int screen
, int owns_dpy
)
81 #if CAIRO_HAS_GPU_GALLIUM_SURFACE
82 space
= cairo_gallium_x11_space_wrap(dpy
, screen
, owns_dpy
, 0);
85 if(space
->is_software
)
86 cairo_space_destroy(space
);
91 #if CAIRO_HAS_GPU_GL_SURFACE
92 space
= cairo_glx_space_wrap(0, dpy
, owns_dpy
, 1, 0, 0);
95 if(space
->is_software
)
96 cairo_space_destroy(space
);
101 #if CAIRO_HAS_XCB_SURFACE
102 space
= cairo_xcb_space_wrap_xlib(dpy
, screen
, owns_dpy
);
106 #if CAIRO_HAS_XLIB_SURFACE
107 space
= cairo_xlib_space_wrap(dpy
, screen
, owns_dpy
);
114 cairo_public cairo_space_t
*
115 cairo_space_wrap_xcb(xcb_connection_t
* conn
, int screen
, int owns_dpy
)
117 cairo_space_t
* space
;
118 #if CAIRO_HAS_XCB_SURFACE
119 space
= cairo_xcb_space_wrap(conn
, screen
, owns_dpy
);
126 cairo_public cairo_space_t
*
127 cairo_space_create_for_display(const char* name
)
129 cairo_space_t
* space
;
131 dpy
= XOpenDisplay(name
);
135 space
= cairo_space_wrap_xlib(dpy
, DefaultScreen(dpy
), 1);
146 * 1. Gallium, standalone
147 * 2. Gallium via X11/WGL
148 * 3. EGL (not implemented)
154 cairo_space_create(void)
156 cairo_space_t
*space
;
158 #if CAIRO_HAS_GPU_GALLIUM_SURFACE
159 space
= cairo_gallium_drm_space_create(0, 0);
162 if(space
->is_software
)
163 cairo_space_destroy(space
);
169 space
= cairo_space_create_for_display(0);
175 slim_hidden_def (cairo_space_create
);
178 cairo_space_destroy(cairo_space_t
* space
)
183 if(!_cairo_reference_count_dec_and_test(&space
->ref_count
))
186 space
->backend
->destroy(space
);
188 slim_hidden_def (cairo_space_destroy
);
191 cairo_space_reference(cairo_space_t
* space
)
193 if(space
== NULL
|| CAIRO_REFERENCE_COUNT_IS_INVALID(&space
->ref_count
))
198 assert(CAIRO_REFERENCE_COUNT_HAS_REFERENCE(&space
->ref_count
));
199 _cairo_reference_count_inc(&space
->ref_count
);
203 slim_hidden_def (cairo_space_reference
);
205 /* This may only synchronize drawing to the space done from the current thread */
207 cairo_space_sync(cairo_space_t
* space
)
209 if(space
&& space
->backend
->sync
)
210 return space
->backend
->sync(space
);
212 return CAIRO_STATUS_SUCCESS
;
214 slim_hidden_def (cairo_space_sync
);
217 cairo_space_is_software(cairo_space_t
* space
)
219 return !space
|| space
->is_software
;