Changes.
[cairo/gpu.git] / src / cairo-space.c
blobd9d86740b7758dce3640a8057423811dbf5e7cb7
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.
35 * Contributor(s):
36 * Carl Worth <cworth@cworth.org>
39 #include <float.h>
40 #include <X11/Xlib.h>
41 #include "cairoint.h"
43 #if CAIRO_HAS_GPU_GALLIUM_SURFACE
44 #include "cairo-gpu-gallium.h"
45 #endif
47 #if CAIRO_HAS_GPU_GL_SURFACE
48 #include "cairo-gpu-gl.h"
49 #endif
51 #if CAIRO_HAS_XLIB_SURFACE
52 #include "cairo-xlib.h"
53 #endif
55 #if CAIRO_HAS_XCB_SURFACE
56 #include "cairo-xcb.h"
57 #endif
59 cairo_public cairo_space_t *
60 cairo_xproto_space_create (const char* name)
62 cairo_space_t* space;
63 #if CAIRO_HAS_XCB_SURFACE
64 space = cairo_xcb_space_create(name);
65 if(space)
66 return space;
67 #endif
69 #if CAIRO_HAS_XLIB_SURFACE
70 space = cairo_xlib_space_create(name);
71 if(space)
72 return space;
73 #endif
74 return 0;
77 cairo_public cairo_space_t *
78 cairo_space_wrap_xlib(Display* dpy, int screen, int owns_dpy)
80 cairo_space_t* space;
81 #if CAIRO_HAS_GPU_GALLIUM_SURFACE
82 space = cairo_gallium_x11_space_wrap(dpy, screen, owns_dpy, 0);
83 if(space)
85 if(space->is_software)
86 cairo_space_destroy(space);
87 else
88 return space;
90 #endif
91 #if CAIRO_HAS_GPU_GL_SURFACE
92 space = cairo_glx_space_wrap(0, dpy, owns_dpy, 1, 0, 0);
93 if(space)
95 if(space->is_software)
96 cairo_space_destroy(space);
97 else
98 return space;
100 #endif
101 #if CAIRO_HAS_XCB_SURFACE
102 space = cairo_xcb_space_wrap_xlib(dpy, screen, owns_dpy);
103 if(space)
104 return space;
105 #endif
106 #if CAIRO_HAS_XLIB_SURFACE
107 space = cairo_xlib_space_wrap(dpy, screen, owns_dpy);
108 if(space)
109 return space;
110 #endif
111 return 0;
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);
120 if(space)
121 return space;
122 #endif
123 return 0;
126 cairo_public cairo_space_t *
127 cairo_space_create_for_display(const char* name)
129 cairo_space_t* space;
130 Display* dpy;
131 dpy = XOpenDisplay(name);
132 if(!dpy)
133 return 0;
135 space = cairo_space_wrap_xlib(dpy, DefaultScreen(dpy), 1);
136 if(!space)
138 XCloseDisplay(dpy);
139 return 0;
142 return space;
145 /* Try in order:
146 * 1. Gallium, standalone
147 * 2. Gallium via X11/WGL
148 * 3. EGL (not implemented)
149 * 4. GLX/WGL
150 * 5. X11/XRender
153 cairo_space_t *
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);
160 if(space)
162 if(space->is_software)
163 cairo_space_destroy(space);
164 else
165 return space;
167 #endif
169 space = cairo_space_create_for_display(0);
170 if(space)
171 return space;
173 return 0;
175 slim_hidden_def (cairo_space_create);
177 void
178 cairo_space_destroy(cairo_space_t * space)
180 if(!space)
181 return;
183 if(!_cairo_reference_count_dec_and_test(&space->ref_count))
184 return;
186 space->backend->destroy(space);
188 slim_hidden_def (cairo_space_destroy);
190 cairo_space_t *
191 cairo_space_reference(cairo_space_t * space)
193 if(space == NULL || CAIRO_REFERENCE_COUNT_IS_INVALID(&space->ref_count))
195 return space;
198 assert(CAIRO_REFERENCE_COUNT_HAS_REFERENCE(&space->ref_count));
199 _cairo_reference_count_inc(&space->ref_count);
201 return space;
203 slim_hidden_def (cairo_space_reference);
205 /* This may only synchronize drawing to the space done from the current thread */
206 cairo_status_t
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);
216 cairo_bool_t
217 cairo_space_is_software(cairo_space_t* space)
219 return !space || space->is_software;