summaryrefslogtreecommitdiff
path: root/src/cgdebug.h
blob: 99bd21e889050bcceba023c4d1bbaff499cb28bd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
//
// "$Id: cgdebug.h 8864 2011-07-19 04:49:30Z greg.ercolano $"
//
// OS X Core Graphics debugging help for the Fast Light Tool Kit (FLTK).
//
// Copyright 1998-2010 by Bill Spitzak and others.
//
// This library is free software. Distribution and use rights are outlined in
// the file "COPYING" which should have been included with this file.  If this
// file is missing or damaged, see the license at:
//
//     http://www.fltk.org/COPYING.php
//
// Please report all bugs and problems on the following page:
//
//     http://www.fltk.org/str.php
//

// This file allows easier debugging of Mac OS X Core Graphics 
// code. This file is normally not included into any FLTK builds,
// but since it has proven to be tremendously useful in debugging
// the FLTK port to "Quartz", I decided to add this file in case
// more bugs show up.
//
// This header is activated by adding the following
// line to "config.h"
//   #include "src/cgdebug.h"
//
// Running "./configure" will remove this line from "config.h".
//
// When used erreanously, Core Graphics prints warnings to 
// stderr. This is helpful, however it is not possible to 
// associate a line number or source file with the warning message.
// This headr file outputs a trace of CG calls, interweaveing
// them with CG warnings.
//
// Matthias

#ifndef CGDEBUG
#define CGDEBUG

#include <stdio.h>
#include <Carbon/Carbon.h>

//+BitmapContextCreate
//+BitmapContextGetData
// ClipCGContextToRegion
// QDBeginCGContext
// QDEndCGContext

//+AddArc
//+AddLineToPoint
// ClipToRect
// ClosePath
//+ConcatCTM
//+DrawImage
// FillPath
// FillRect
// Flush
//+GetCTM
// MoveToPoint
//+Release
// RestoreGState
// SaveGState
//+ScaleCTM
//+SetLineCap
//+SetLineDash
//+SetLineJoin
//+SetLineWidth
//+SetRGBFillColor
//+SetRGBStrokeColor
//+SetShouldAntialias
//+SetTextMatrix
//+StrokePath
//+TranslateCTM

inline OSStatus dbgLocation(const char *file, int line) 
{
  fprintf(stderr, "%s:%d ", file, line);
  return 0;
}

inline OSStatus dbgEndl()     
{
  fprintf(stderr, "\n");
  return 0;
}


inline void dbgCGContextClipToRect(CGContextRef a, CGRect b)
{
  CGContextClipToRect(a, b);
}

#define CGContextClipToRect(a, b) { \
  fprintf(stderr, "%s:%d ", __FILE__, __LINE__); \
  dbgCGContextClipToRect(a, b); \
  fprintf(stderr, "\n"); }

inline void dbgCGContextFillRect(CGContextRef a, CGRect b)
{
  CGContextFillRect(a, b);
}

#define CGContextFillRect(a, b) { \
  fprintf(stderr, "%s:%d ", __FILE__, __LINE__); \
  dbgCGContextFillRect(a, b); \
  fprintf(stderr, "\n"); }

inline OSStatus dbgQDEndCGContext(CGrafPtr a, CGContextRef *b) 
{
  return QDEndCGContext(a, b);
}

#define QDEndCGContext(a, b) ( \
  dbgLocation(__FILE__, __LINE__) + \
  dbgQDEndCGContext(a, b) + \
  dbgEndl() )

inline OSStatus dbgQDBeginCGContext(CGrafPtr a, CGContextRef *b) 
{
  return QDBeginCGContext(a, b);
}

#define QDBeginCGContext(a, b) ( \
  dbgLocation(__FILE__, __LINE__) + \
  dbgQDBeginCGContext(a, b) + \
  dbgEndl() )

inline void dbgClipCGContextToRegion(CGContextRef a, const Rect *b, RgnHandle c) 
{
  ClipCGContextToRegion(a, b, c);
}

#define ClipCGContextToRegion(a, b, c) { \
  fprintf(stderr, "%s:%d ", __FILE__, __LINE__); \
  dbgClipCGContextToRegion(a, b, c); \
  fprintf(stderr, "\n"); }

inline void dbgCGContextMoveToPoint(CGContextRef context, float x, float y)
{
  CGContextMoveToPoint(context, x, y);
}

#define CGContextMoveToPoint(a, b, c) { \
  fprintf(stderr, "%s:%d ", __FILE__, __LINE__); \
  dbgCGContextMoveToPoint(a, b, c); \
  fprintf(stderr, "\n"); }

inline void dbgCGContextFillPath(CGContextRef context)
{ 
  CGContextFillPath(context);
}

#define CGContextFillPath(a) { \
  fprintf(stderr, "%s:%d ", __FILE__, __LINE__); \
  dbgCGContextFillPath(a); \
  fprintf(stderr, "\n"); }

inline void dbgCGContextClosePath(CGContextRef context)
{ 
  CGContextClosePath(context);
}

#define CGContextClosePath(a) { \
  fprintf(stderr, "%s:%d ", __FILE__, __LINE__); \
  dbgCGContextClosePath(a); \
  fprintf(stderr, "\n"); }

inline void dbgCGContextFlush(CGContextRef context)
{ 
  CGContextFlush(context);
}

#define CGContextFlush(a) { \
  fprintf(stderr, "%s:%d ", __FILE__, __LINE__); \
  dbgCGContextFlush(a); \
  fprintf(stderr, "\n"); }

inline void dbgCGContextSaveGState(CGContextRef context)
{ 
  CGContextSaveGState(context);
}

#define CGContextSaveGState(a) { \
  fprintf(stderr, "%s:%d ", __FILE__, __LINE__); \
  dbgCGContextSaveGState(a); \
  fprintf(stderr, "\n"); }

inline void dbgCGContextRestoreGState(CGContextRef context)
{ 
  CGContextRestoreGState(context);
}

#define CGContextRestoreGState(a) { \
  fprintf(stderr, "%s:%d ", __FILE__, __LINE__); \
  dbgCGContextRestoreGState(a); \
  fprintf(stderr, "\n"); }


#endif

//
// End of "$Id: cgdebug.h 8864 2011-07-19 04:49:30Z greg.ercolano $".
//