Update change log.
[platform/upstream/cairo.git] / boilerplate / cairo-boilerplate-qt.cpp
1 /* Cairo - a vector graphics library with display and print output
2  *
3  * Copyright © 2009 Chris Wilson
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it either under the terms of the GNU Lesser General Public
7  * License version 2.1 as published by the Free Software Foundation
8  * (the "LGPL") or, at your option, under the terms of the Mozilla
9  * Public License Version 1.1 (the "MPL"). If you do not alter this
10  * notice, a recipient may use your version of this file under either
11  * the MPL or the LGPL.
12  *
13  * You should have received a copy of the LGPL along with this library
14  * in the file COPYING-LGPL-2.1; if not, write to the Free Software
15  * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA
16  * You should have received a copy of the MPL along with this library
17  * in the file COPYING-MPL-1.1
18  *
19  * The contents of this file are subject to the Mozilla Public License
20  * Version 1.1 (the "License"); you may not use this file except in
21  * compliance with the License. You may obtain a copy of the License at
22  * http://www.mozilla.org/MPL/
23  *
24  * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY
25  * OF ANY KIND, either express or implied. See the LGPL or the MPL for
26  * the specific language governing rights and limitations.
27  *
28  * The Original Code is the cairo graphics library.
29  *
30  * The Initial Developer of the Original Code is Chris Wilson.
31  */
32
33 #include "cairo-boilerplate-private.h"
34
35 #include <cairo-qt.h>
36
37 #include <qapplication.h>
38 #include <X11/Xlib.h>
39
40 typedef struct _qt_closure {
41     Display *dpy;
42     QApplication *app;
43 } qt_closure_t;
44
45 static void
46 _cairo_boilerplate_qt_cleanup (void *closure)
47 {
48     qt_closure_t *qtc = (qt_closure_t *) closure;
49
50     delete qtc->app;
51     XCloseDisplay (qtc->dpy);
52     free (qtc);
53 }
54
55 static cairo_surface_t *
56 _cairo_boilerplate_qt_create_surface (const char                *name,
57                                       cairo_content_t            content,
58                                       double                     width,
59                                       double                     height,
60                                       double                     max_width,
61                                       double                     max_height,
62                                       cairo_boilerplate_mode_t   mode,
63                                       void                     **closure)
64 {
65     qt_closure_t *qtc;
66
67     qtc = (qt_closure_t *) xcalloc (1, sizeof (qt_closure_t));
68     qtc->dpy = XOpenDisplay (NULL);
69     if (qtc->dpy == NULL) {
70         free (qtc);
71         return NULL;
72     }
73
74     if (mode == CAIRO_BOILERPLATE_MODE_TEST)
75         XSynchronize (qtc->dpy, True);
76
77     qtc->app = new QApplication (qtc->dpy);
78     *closure = qtc;
79     return cairo_qt_surface_create_with_qpixmap (content, width, height);
80 }
81
82 static void
83 _cairo_boilerplate_qt_synchronize (void *closure)
84 {
85     qt_closure_t *qtc = (qt_closure_t *) closure;
86
87     qtc->app->flush (); /* not sure if this is sufficient */
88 }
89
90 static const cairo_boilerplate_target_t targets[] = {
91     {
92         "qt", "qt", NULL, NULL,
93         CAIRO_SURFACE_TYPE_QT, CAIRO_CONTENT_COLOR_ALPHA, 0,
94         "cairo_qt_surface_create",
95         _cairo_boilerplate_qt_create_surface,
96         NULL, NULL, NULL,
97         _cairo_boilerplate_get_image_surface,
98         cairo_surface_write_to_png,
99         _cairo_boilerplate_qt_cleanup
100     },
101     {
102         "qt", "qt", NULL, NULL,
103         CAIRO_SURFACE_TYPE_QT, CAIRO_CONTENT_COLOR, 0,
104         "cairo_qt_surface_create",
105         _cairo_boilerplate_qt_create_surface,
106         NULL, NULL, NULL,
107         _cairo_boilerplate_get_image_surface,
108         cairo_surface_write_to_png,
109         _cairo_boilerplate_qt_cleanup
110     },
111 };
112 extern "C" {
113 CAIRO_BOILERPLATE (qt, targets)
114 }