Update change log.
[platform/upstream/cairo.git] / boilerplate / cairo-boilerplate.h
1 /*
2  * Copyright © 2004,2006 Red Hat, Inc.
3  *
4  * Permission to use, copy, modify, distribute, and sell this software
5  * and its documentation for any purpose is hereby granted without
6  * fee, provided that the above copyright notice appear in all copies
7  * and that both that copyright notice and this permission notice
8  * appear in supporting documentation, and that the name of
9  * Red Hat, Inc. not be used in advertising or publicity pertaining to
10  * distribution of the software without specific, written prior
11  * permission. Red Hat, Inc. makes no representations about the
12  * suitability of this software for any purpose.  It is provided "as
13  * is" without express or implied warranty.
14  *
15  * RED HAT, INC. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
16  * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
17  * FITNESS, IN NO EVENT SHALL RED HAT, INC. BE LIABLE FOR ANY SPECIAL,
18  * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
19  * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
20  * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
21  * IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
22  *
23  * Author: Carl D. Worth <cworth@cworth.org>
24  */
25
26 #ifndef _CAIRO_BOILERPLATE_H_
27 #define _CAIRO_BOILERPLATE_H_
28
29 #if HAVE_CONFIG_H
30 #include "config.h"
31 #endif
32
33 #include <stdio.h>
34 #include <stdlib.h>
35 #include <math.h>
36 #include <cairo.h>
37 #include <string.h>
38
39 #include "cairo-compiler-private.h"
40
41 #if   HAVE_STDINT_H
42 # include <stdint.h>
43 #elif HAVE_INTTYPES_H
44 # include <inttypes.h>
45 #elif HAVE_SYS_INT_TYPES_H
46 # include <sys/int_types.h>
47 #elif defined(_MSC_VER)
48 # include <stdint.h>
49   typedef __int8 int8_t;
50   typedef unsigned __int8 uint8_t;
51   typedef __int16 int16_t;
52   typedef unsigned __int16 uint16_t;
53   typedef __int32 int32_t;
54   typedef unsigned __int32 uint32_t;
55   typedef __int64 int64_t;
56   typedef unsigned __int64 uint64_t;
57 #else
58 #error Cannot find definitions for fixed-width integral types (uint8_t, uint32_t, etc.)
59 #endif
60
61 #ifndef HAVE_UINT64_T
62 # define HAVE_UINT64_T 1
63 #endif
64 #ifndef INT16_MIN
65 # define INT16_MIN      (-32767-1)
66 #endif
67 #ifndef INT16_MAX
68 # define INT16_MAX      (32767)
69 #endif
70 #ifndef UINT16_MAX
71 # define UINT16_MAX     (65535)
72 #endif
73
74 #ifndef CAIRO_BOILERPLATE_DEBUG
75 #define CAIRO_BOILERPLATE_DEBUG(x)
76 #endif
77
78 #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ > 4)
79 #define CAIRO_BOILERPLATE_PRINTF_FORMAT(fmt_index, va_index) \
80         __attribute__((__format__(__printf__, fmt_index, va_index)))
81 #else
82 #define CAIRO_BOILERPLATE_PRINTF_FORMAT(fmt_index, va_index)
83 #endif
84
85 #ifndef FALSE
86 #define FALSE 0
87 #endif
88
89 #ifndef TRUE
90 #define TRUE 1
91 #endif
92
93 #ifndef M_PI
94 #define M_PI 3.14159265358979323846
95 #endif
96
97 CAIRO_BEGIN_DECLS
98
99 /* A fake format we use for the flattened ARGB output of the PS and
100  * PDF surfaces. */
101 #define CAIRO_TEST_CONTENT_COLOR_ALPHA_FLATTENED ((unsigned int) -1)
102
103 extern const cairo_user_data_key_t cairo_boilerplate_output_basename_key;
104
105 cairo_content_t
106 cairo_boilerplate_content (cairo_content_t content);
107
108 const char *
109 cairo_boilerplate_content_name (cairo_content_t content);
110
111 cairo_format_t
112 cairo_boilerplate_format_from_content (cairo_content_t content);
113
114 typedef enum {
115     CAIRO_BOILERPLATE_MODE_TEST,
116     CAIRO_BOILERPLATE_MODE_PERF,
117
118     /* This will allow running performance test with threads. The
119      * GL backend is very slow on some drivers when run with thread
120      * awareness turned on. */
121     CAIRO_BOILERPLATE_MODE_PERF_THREADS,
122 } cairo_boilerplate_mode_t;
123
124 typedef cairo_surface_t *
125 (*cairo_boilerplate_create_surface_t) (const char                *name,
126                                        cairo_content_t            content,
127                                        double                     width,
128                                        double                     height,
129                                        double                     max_width,
130                                        double                     max_height,
131                                        cairo_boilerplate_mode_t   mode,
132                                        void                     **closure);
133
134 typedef cairo_surface_t *
135 (*cairo_boilerplate_create_similar_t) (cairo_surface_t           *other,
136                                        cairo_content_t            content,
137                                        int                        width,
138                                        int                        height);
139
140 typedef void
141 (*cairo_boilerplate_force_fallbacks_t) (cairo_surface_t *surface,
142                                        double            x_pixels_per_inch,
143                                        double            y_pixels_per_inch);
144
145 typedef cairo_status_t
146 (*cairo_boilerplate_finish_surface_t) (cairo_surface_t *surface);
147
148 typedef cairo_surface_t *
149 (*cairo_boilerplate_get_image_surface_t) (cairo_surface_t *surface,
150                                           int page,
151                                           int width,
152                                           int height);
153
154 typedef cairo_status_t
155 (*cairo_boilerplate_write_to_png_t) (cairo_surface_t *surface,
156                                      const char *filename);
157
158 typedef void
159 (*cairo_boilerplate_cleanup_t) (void *closure);
160
161 typedef void
162 (*cairo_boilerplate_wait_t) (void *closure);
163
164 typedef char *
165 (*cairo_boilerplate_describe_t) (void *closure);
166
167 typedef struct _cairo_boilerplate_target {
168     const char                                  *name;
169     const char                                  *basename;
170     const char                                  *file_extension;
171     const char                                  *reference_target;
172     cairo_surface_type_t                         expected_type;
173     cairo_content_t                              content;
174     unsigned int                                 error_tolerance;
175     const char                                  *probe; /* runtime dl check */
176     cairo_boilerplate_create_surface_t           create_surface;
177     cairo_boilerplate_create_similar_t           create_similar;
178     cairo_boilerplate_force_fallbacks_t          force_fallbacks;
179     cairo_boilerplate_finish_surface_t           finish_surface;
180     cairo_boilerplate_get_image_surface_t        get_image_surface;
181     cairo_boilerplate_write_to_png_t             write_to_png;
182     cairo_boilerplate_cleanup_t                  cleanup;
183     cairo_boilerplate_wait_t                     synchronize;
184     cairo_boilerplate_describe_t                 describe;
185     cairo_bool_t                                 is_measurable;
186     cairo_bool_t                                 is_vector;
187     cairo_bool_t                                 is_recording;
188 } cairo_boilerplate_target_t;
189
190 const cairo_boilerplate_target_t *
191 cairo_boilerplate_get_image_target (cairo_content_t content);
192
193 const cairo_boilerplate_target_t *
194 cairo_boilerplate_get_target_by_name (const char      *name,
195                                       cairo_content_t  content);
196
197 const cairo_boilerplate_target_t **
198 cairo_boilerplate_get_targets (int          *num_targets,
199                                cairo_bool_t *limited_targets);
200
201 void
202 cairo_boilerplate_free_targets (const cairo_boilerplate_target_t **targets);
203
204 cairo_surface_t *
205 _cairo_boilerplate_get_image_surface (cairo_surface_t *src,
206                                       int              page,
207                                       int              width,
208                                       int              height);
209 cairo_surface_t *
210 cairo_boilerplate_get_image_surface_from_png (const char   *filename,
211                                               int           width,
212                                               int           height,
213                                               cairo_bool_t  flatten);
214
215 cairo_surface_t *
216 cairo_boilerplate_surface_create_in_error (cairo_status_t status);
217
218 enum {
219     CAIRO_BOILERPLATE_OPEN_NO_DAEMON = 0x1,
220 };
221
222 FILE *
223 cairo_boilerplate_open_any2ppm (const char   *filename,
224                                 int           page,
225                                 unsigned int  flags,
226                                 int        (**close_cb) (FILE *));
227
228 cairo_surface_t *
229 cairo_boilerplate_image_surface_create_from_ppm_stream (FILE *file);
230
231 cairo_surface_t *
232 cairo_boilerplate_convert_to_image (const char *filename,
233                                     int         page);
234
235 int
236 cairo_boilerplate_version (void);
237
238 const char*
239 cairo_boilerplate_version_string (void);
240
241 void
242 cairo_boilerplate_fini (void);
243
244 #include "cairo-boilerplate-system.h"
245
246 CAIRO_END_DECLS
247
248 #endif