Add stubs for Direct3D9 backend.
[cairo/gpu.git] / src / cairo-debug.c
blobd4548f1570b7a4e93671b4b4fee0b77303585457
1 /* cairo - a vector graphics library with display and print output
3 * Copyright © 2005 Red Hat, Inc.
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.
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 * You should have received a copy of the MPL along with this library
17 * in the file COPYING-MPL-1.1
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/
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.
28 * The Original Code is the cairo graphics library.
30 * The Initial Developer of the Original Code is Red Hat, Inc.
32 * Contributor(s):
33 * Carl D. Worth <cworth@cworth.org>
36 #include "cairoint.h"
38 /**
39 * cairo_debug_reset_static_data:
41 * Resets all static data within cairo to its original state,
42 * (ie. identical to the state at the time of program invocation). For
43 * example, all caches within cairo will be flushed empty.
45 * This function is intended to be useful when using memory-checking
46 * tools such as valgrind. When valgrind's memcheck analyzes a
47 * cairo-using program without a call to cairo_debug_reset_static_data(),
48 * it will report all data reachable via cairo's static objects as
49 * "still reachable". Calling cairo_debug_reset_static_data() just prior
50 * to program termination will make it easier to get squeaky clean
51 * reports from valgrind.
53 * WARNING: It is only safe to call this function when there are no
54 * active cairo objects remaining, (ie. the appropriate destroy
55 * functions have been called as necessary). If there are active cairo
56 * objects, this call is likely to cause a crash, (eg. an assertion
57 * failure due to a hash table being destroyed when non-empty).
58 **/
59 void
60 cairo_debug_reset_static_data (void)
62 CAIRO_MUTEX_INITIALIZE ();
64 _cairo_scaled_font_map_destroy ();
66 _cairo_toy_font_face_reset_static_data ();
68 #if CAIRO_HAS_FT_FONT
69 _cairo_ft_font_reset_static_data ();
70 #endif
72 _cairo_intern_string_reset_static_data ();
74 _cairo_scaled_font_reset_static_data ();
76 _cairo_pattern_reset_static_data ();
78 CAIRO_MUTEX_FINALIZE ();
81 #if HAVE_VALGRIND
82 void
83 _cairo_debug_check_image_surface_is_defined (const cairo_surface_t *surface)
85 const cairo_image_surface_t *image = (cairo_image_surface_t *) surface;
86 const uint8_t *bits;
87 int row, width;
89 if (surface == NULL)
90 return;
92 if (! RUNNING_ON_VALGRIND)
93 return;
95 bits = image->data;
96 switch (image->format) {
97 case CAIRO_FORMAT_A1:
98 width = (image->width + 7)/8;
99 break;
100 case CAIRO_FORMAT_A8:
101 width = image->width;
102 break;
103 case CAIRO_FORMAT_RGB24:
104 case CAIRO_FORMAT_ARGB32:
105 width = image->width*4;
106 break;
107 default:
108 /* XXX compute width from pixman bpp */
109 return;
112 for (row = 0; row < image->height; row++) {
113 VALGRIND_CHECK_MEM_IS_DEFINED (bits, width);
114 /* and then silence any future valgrind warnings */
115 VALGRIND_MAKE_MEM_DEFINED (bits, width);
116 bits += image->stride;
119 #endif
122 #if 0
123 void
124 _cairo_image_surface_write_to_ppm (cairo_image_surface_t *isurf, const char *fn)
126 char *fmt;
127 if (isurf->format == CAIRO_FORMAT_ARGB32 || isurf->format == CAIRO_FORMAT_RGB24)
128 fmt = "P6";
129 else if (isurf->format == CAIRO_FORMAT_A8)
130 fmt = "P5";
131 else
132 return;
134 FILE *fp = fopen(fn, "wb");
135 if (!fp)
136 return;
138 fprintf (fp, "%s %d %d 255\n", fmt,isurf->width, isurf->height);
139 for (int j = 0; j < isurf->height; j++) {
140 unsigned char *row = isurf->data + isurf->stride * j;
141 for (int i = 0; i < isurf->width; i++) {
142 if (isurf->format == CAIRO_FORMAT_ARGB32 || isurf->format == CAIRO_FORMAT_RGB24) {
143 unsigned char r = *row++;
144 unsigned char g = *row++;
145 unsigned char b = *row++;
146 *row++;
147 putc(r, fp);
148 putc(g, fp);
149 putc(b, fp);
150 } else {
151 unsigned char a = *row++;
152 putc(a, fp);
157 fclose (fp);
159 fprintf (stderr, "Wrote %s\n", fn);
161 #endif