BRL-CAD
if_debug.c
Go to the documentation of this file.
1 /* I F _ D E B U G . C
2  * BRL-CAD
3  *
4  * Copyright (c) 2004-2014 United States Government as represented by
5  * the U.S. Army Research Laboratory.
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public License
9  * version 2.1 as published by the Free Software Foundation.
10  *
11  * This library is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this file; see the file named COPYING for more
18  * information.
19  */
20 /** @addtogroup if */
21 /** @{ */
22 /** @file if_debug.c
23  *
24  * Reports all calls to fb_log().
25  */
26 /** @} */
27 
28 #include "common.h"
29 
30 #include <stdlib.h>
31 #include <stdio.h>
32 #include <ctype.h>
33 
34 #include "bu/color.h"
35 #include "bu/log.h"
36 #include "fb_private.h"
37 #include "fb.h"
38 
39 HIDDEN int
40 deb_open(fb *ifp, const char *file, int width, int height)
41 {
42  FB_CK_FB(ifp);
43  if (file == (char *)NULL)
44  fb_log("fb_open(%p, NULL, %d, %d)\n",
45  (void *)ifp, width, height);
46  else
47  fb_log("fb_open(%p, \"%s\", %d, %d)\n",
48  (void *)ifp, file, width, height);
49 
50  /* check for default size */
51  if (width <= 0)
52  width = ifp->if_width;
53  if (height <= 0)
54  height = ifp->if_height;
55 
56  /* set debug bit vector */
57  if (file != NULL) {
58  const char *cp;
59  for (cp = file; *cp != '\0' && !isdigit((int)*cp); cp++)
60  ;
61  sscanf(cp, "%d", &ifp->if_debug);
62  } else {
63  ifp->if_debug = 0;
64  }
65 
66  /* Give the user whatever width was asked for */
67  ifp->if_width = width;
68  ifp->if_height = height;
69 
70  return 0;
71 }
72 
75 {
76  return NULL;
77 }
78 
79 
80 HIDDEN void
82 {
83  return;
84 }
85 
86 HIDDEN int
87 deb_open_existing(fb *UNUSED(ifp), int UNUSED(width), int UNUSED(height), struct fb_platform_specific *UNUSED(fb_p))
88 {
89  return 0;
90 }
91 
92 HIDDEN int
94 {
95  return 0;
96 }
97 
98 HIDDEN int
100 {
101  FB_CK_FB(ifp);
102  fb_log("fb_close(%p)\n", (void *)ifp);
103  return 0;
104 }
105 
106 HIDDEN int
107 deb_configure_window(fb *UNUSED(ifp), int UNUSED(width), int UNUSED(height))
108 {
109  return 0;
110 }
111 
112 HIDDEN int
113 deb_refresh(fb *UNUSED(ifp), int UNUSED(x), int UNUSED(y), int UNUSED(w), int UNUSED(h))
114 {
115  return 0;
116 }
117 
118 HIDDEN int
119 deb_clear(fb *ifp, unsigned char *pp)
120 {
121  FB_CK_FB(ifp);
122  if (pp == 0)
123  fb_log("fb_clear(%p, NULL)\n", (void *)ifp);
124  else
125  fb_log("fb_clear(x%p, &[%d %d %d])\n",
126  (void *)ifp,
127  (int)(pp[RED]), (int)(pp[GRN]),
128  (int)(pp[BLU]));
129  return 0;
130 }
131 
132 
134 deb_read(fb *ifp, int x, int y, unsigned char *pixelp, size_t count)
135 {
136  FB_CK_FB(ifp);
137  fb_log("fb_read(%p, %4d, %4d, %p, %lu)\n",
138  (void *)ifp, x, y,
139  (void *)pixelp, count);
140  return count;
141 }
142 
143 
145 deb_write(fb *ifp, int x, int y, const unsigned char *pixelp, size_t count)
146 {
147  size_t i;
148 
149  FB_CK_FB(ifp);
150  fb_log("fb_write(%p, %4d, %4d, %p, %ld)\n",
151  (void *)ifp, x, y,
152  (void *)pixelp, (long)count);
153 
154  /* write them out, four per line */
155  if (ifp->if_debug & FB_DEBUG_RW) {
156  for (i = 0; i < count; i++) {
157  if (i % 4 == 0)
158  fb_log("%4zu:", i);
159  fb_log(" [%3d, %3d, %3d]", *(pixelp+(i*3)+RED),
160  *(pixelp+(i*3)+GRN), *(pixelp+(i*3)+BLU));
161  if (i % 4 == 3)
162  fb_log("\n");
163  }
164  if (i % 4 != 0)
165  fb_log("\n");
166  }
167 
168  return count;
169 }
170 
171 
172 HIDDEN int
173 deb_rmap(fb *ifp, ColorMap *cmp)
174 {
175  FB_CK_FB(ifp);
176  fb_log("fb_rmap(%p, %p)\n",
177  (void *)ifp, (void *)cmp);
178  return 0;
179 }
180 
181 
182 HIDDEN int
183 deb_wmap(fb *ifp, const ColorMap *cmp)
184 {
185  int i;
186 
187  FB_CK_FB(ifp);
188  if (cmp == NULL)
189  fb_log("fb_wmap(%p, NULL)\n",
190  (void *)ifp);
191  else
192  fb_log("fb_wmap(%p, %p)\n",
193  (void *)ifp, (void *)cmp);
194 
195  if (ifp->if_debug & FB_DEBUG_CMAP && cmp != NULL) {
196  for (i = 0; i < 256; i++) {
197  fb_log("%3d: [ 0x%4lx, 0x%4lx, 0x%4lx ]\n",
198  i,
199  (unsigned long)cmp->cm_red[i],
200  (unsigned long)cmp->cm_green[i],
201  (unsigned long)cmp->cm_blue[i]);
202  }
203  }
204 
205  return 0;
206 }
207 
208 
209 HIDDEN int
210 deb_view(fb *ifp, int xcenter, int ycenter, int xzoom, int yzoom)
211 {
212  FB_CK_FB(ifp);
213  fb_log("fb_view(%p, %4d, %4d, %4d, %4d)\n",
214  (void *)ifp, xcenter, ycenter, xzoom, yzoom);
215  fb_sim_view(ifp, xcenter, ycenter, xzoom, yzoom);
216  return 0;
217 }
218 
219 
220 HIDDEN int
221 deb_getview(fb *ifp, int *xcenter, int *ycenter, int *xzoom, int *yzoom)
222 {
223  FB_CK_FB(ifp);
224  fb_log("fb_getview(%p, %p, %p, %p, %p)\n",
225  (void *)ifp, (void *)xcenter, (void *)ycenter, (void *)xzoom, (void *)yzoom);
226  fb_sim_getview(ifp, xcenter, ycenter, xzoom, yzoom);
227  fb_log(" <= %d %d %d %d\n",
228  *xcenter, *ycenter, *xzoom, *yzoom);
229  return 0;
230 }
231 
232 
233 HIDDEN int
234 deb_setcursor(fb *ifp, const unsigned char *bits, int xbits, int ybits, int xorig, int yorig)
235 {
236  FB_CK_FB(ifp);
237  fb_log("fb_setcursor(%p, %p, %d, %d, %d, %d)\n",
238  (void *)ifp, (void *)bits, xbits, ybits, xorig, yorig);
239  return 0;
240 }
241 
242 
243 HIDDEN int
244 deb_cursor(fb *ifp, int mode, int x, int y)
245 {
246  fb_log("fb_cursor(%p, %d, %4d, %4d)\n",
247  (void *)ifp, mode, x, y);
248  fb_sim_cursor(ifp, mode, x, y);
249  return 0;
250 }
251 
252 
253 HIDDEN int
254 deb_getcursor(fb *ifp, int *mode, int *x, int *y)
255 {
256  FB_CK_FB(ifp);
257  fb_log("fb_getcursor(%p, %p, %p, %p)\n",
258  (void *)ifp, (void *)mode, (void *)x, (void *)y);
259  fb_sim_getcursor(ifp, mode, x, y);
260  fb_log(" <= %d %d %d\n", *mode, *x, *y);
261  return 0;
262 }
263 
264 
265 HIDDEN int
266 deb_readrect(fb *ifp, int xmin, int ymin, int width, int height, unsigned char *pp)
267 {
268  FB_CK_FB(ifp);
269  fb_log("fb_readrect(%p, (%4d, %4d), %4d, %4d, %p)\n",
270  (void *)ifp, xmin, ymin, width, height,
271  (void *)pp);
272  return width*height;
273 }
274 
275 
276 HIDDEN int
277 deb_writerect(fb *ifp, int xmin, int ymin, int width, int height, const unsigned char *pp)
278 {
279  FB_CK_FB(ifp);
280  fb_log("fb_writerect(%p, %4d, %4d, %4d, %4d, %p)\n",
281  (void *)ifp, xmin, ymin, width, height,
282  (void *)pp);
283  return width*height;
284 }
285 
286 
287 HIDDEN int
288 deb_bwreadrect(fb *ifp, int xmin, int ymin, int width, int height, unsigned char *pp)
289 {
290  FB_CK_FB(ifp);
291  fb_log("fb_bwreadrect(%p, (%4d, %4d), %4d, %4d, %p)\n",
292  (void *)ifp, xmin, ymin, width, height,
293  (void *)pp);
294  return width*height;
295 }
296 
297 
298 HIDDEN int
299 deb_bwwriterect(fb *ifp, int xmin, int ymin, int width, int height, const unsigned char *pp)
300 {
301  FB_CK_FB(ifp);
302  fb_log("fb_bwwriterect(%p, %4d, %4d, %4d, %4d, %p)\n",
303  (void *)ifp, xmin, ymin, width, height,
304  (void *)pp);
305  return width*height;
306 }
307 
308 
309 HIDDEN int
311 {
312  FB_CK_FB(ifp);
313  fb_log("fb_poll(%p)\n", (void *)ifp);
314  return 0;
315 }
316 
317 
318 HIDDEN int
320 {
321  FB_CK_FB(ifp);
322  fb_log("if_flush(%p)\n", (void *)ifp);
323  return 0;
324 }
325 
326 
327 HIDDEN int
329 {
330  FB_CK_FB(ifp);
331  fb_log("fb_free(%p)\n", (void *)ifp);
332  return 0;
333 }
334 
335 
336 /*ARGSUSED*/
337 HIDDEN int
339 {
340  FB_CK_FB(ifp);
341  fb_log("Description: %s\n", debug_interface.if_type);
342  fb_log("Device: %s\n", ifp->if_name);
343  fb_log("Max width/height: %d %d\n",
346  fb_log("Default width/height: %d %d\n",
349  fb_log("\
350 Usage: /dev/debug[#]\n\
351  where # is a optional bit vector from:\n\
352  1 debug buffered I/O calls\n\
353  2 show colormap entries in rmap/wmap calls\n\
354  4 show actual pixel values in read/write calls\n");
355  /*8 buffered read/write values - ifdef'd out*/
356 
357  return 0;
358 }
359 
360 
361 /* This is the ONLY thing that we "export" */
363  0,
365  deb_open,
368  deb_get_fbps,
369  deb_put_fbps,
370  deb_close,
371  deb_clear,
372  deb_read,
373  deb_write,
374  deb_rmap,
375  deb_wmap,
376  deb_view,
377  deb_getview,
379  deb_cursor,
381  deb_readrect,
386  deb_refresh,
387  deb_poll,
388  deb_flush,
389  deb_free,
390  deb_help,
391  "Debugging Interface",
392  32*1024, /* max width */
393  32*1024, /* max height */
394  "/dev/debug",
395  512, /* current/default width */
396  512, /* current/default height */
397  -1, /* select fd */
398  -1, /* file descriptor */
399  1, 1, /* zoom */
400  256, 256, /* window center */
401  0, 0, 0, /* cursor */
402  PIXEL_NULL, /* page_base */
403  PIXEL_NULL, /* page_curp */
404  PIXEL_NULL, /* page_endp */
405  -1, /* page_no */
406  0, /* page_ref */
407  0L, /* page_curpos */
408  0L, /* page_pixels */
409  0, /* debug */
410  0, /* refresh rate */
411  {0}, /* u1 */
412  {0}, /* u2 */
413  {0}, /* u3 */
414  {0}, /* u4 */
415  {0}, /* u5 */
416  {0} /* u6 */
417 };
418 
419 
420 /*
421  * Local Variables:
422  * mode: C
423  * tab-width: 8
424  * indent-tabs-mode: t
425  * c-file-style: "stroustrup"
426  * End:
427  * ex: shiftwidth=4 tabstop=8
428  */
ptrdiff_t ssize_t
Definition: common.h:119
HIDDEN void deb_put_fbps(struct fb_platform_specific *fbps)
Definition: if_debug.c:81
void fb_log(const char *fmt,...) _BU_ATTR_PRINTF12
Definition: fb_log.c:42
unsigned short cm_green[256]
Definition: fb.h:84
HIDDEN ssize_t deb_write(fb *ifp, int x, int y, const unsigned char *pixelp, size_t count)
Definition: if_debug.c:145
HIDDEN int deb_bwwriterect(fb *ifp, int xmin, int ymin, int width, int height, const unsigned char *pp)
Definition: if_debug.c:299
HIDDEN int deb_bwreadrect(fb *ifp, int xmin, int ymin, int width, int height, unsigned char *pp)
Definition: if_debug.c:288
#define RED
Definition: color.h:39
HIDDEN int deb_getcursor(fb *ifp, int *mode, int *x, int *y)
Definition: if_debug.c:254
HIDDEN struct fb_platform_specific * deb_get_fbps(uint32_t magic)
Definition: if_debug.c:74
HIDDEN int deb_flush(fb *ifp)
Definition: if_debug.c:319
#define PIXEL_NULL
Definition: fb.h:89
HIDDEN int deb_wmap(fb *ifp, const ColorMap *cmp)
Definition: if_debug.c:183
Header file for the BRL-CAD common definitions.
int if_max_width
max device width
Definition: fb_private.h:111
HIDDEN int deb_view(fb *ifp, int xcenter, int ycenter, int xzoom, int yzoom)
Definition: if_debug.c:210
#define BLU
Definition: color.h:41
ustring width
HIDDEN int deb_open_existing(fb *ifp, int width, int height, struct fb_platform_specific *fb_p)
Definition: if_debug.c:87
#define HIDDEN
Definition: common.h:86
char * if_type
what "open" calls it
Definition: fb_private.h:110
HIDDEN int deb_rmap(fb *ifp, ColorMap *cmp)
Definition: if_debug.c:173
HIDDEN int deb_getview(fb *ifp, int *xcenter, int *ycenter, int *xzoom, int *yzoom)
Definition: if_debug.c:221
HIDDEN int deb_readrect(fb *ifp, int xmin, int ymin, int width, int height, unsigned char *pp)
Definition: if_debug.c:266
#define FB_CK_FB(_p)
Definition: fb.h:100
HIDDEN int deb_open(fb *ifp, const char *file, int width, int height)
Definition: if_debug.c:40
int fb_sim_getcursor(fb *ifp, int *mode, int *x, int *y)
Definition: fb_util.c:96
HIDDEN int deb_poll(fb *ifp)
Definition: if_debug.c:310
HIDDEN int deb_refresh(fb *ifp, int x, int y, int w, int h)
Definition: if_debug.c:113
HIDDEN int deb_free(fb *ifp)
Definition: if_debug.c:328
unsigned short cm_red[256]
Definition: fb.h:83
#define FB_DEBUG_CMAP
Definition: fb.h:197
HIDDEN int deb_help(fb *ifp)
Definition: if_debug.c:338
int if_max_height
max device height
Definition: fb_private.h:112
oldeumate l2 magic
Definition: nmg_mod.c:3843
#define UNUSED(parameter)
Definition: common.h:239
int fb_sim_cursor(fb *ifp, int mode, int x, int y)
Definition: fb_util.c:79
HIDDEN int deb_close(fb *ifp)
Definition: if_debug.c:99
HIDDEN int deb_clear(fb *ifp, unsigned char *pp)
Definition: if_debug.c:119
Definition: fb.h:82
#define FB_DEBUG_MAGIC
Definition: magic.h:186
HIDDEN int deb_writerect(fb *ifp, int xmin, int ymin, int width, int height, const unsigned char *pp)
Definition: if_debug.c:277
#define FB_DEBUG_RW
Definition: fb.h:198
int fb_sim_getview(fb *ifp, int *xcenter, int *ycenter, int *xzoom, int *yzoom)
Definition: fb_util.c:61
HIDDEN int deb_configure_window(fb *ifp, int width, int height)
Definition: if_debug.c:107
HIDDEN int deb_cursor(fb *ifp, int mode, int x, int y)
Definition: if_debug.c:244
int fb_sim_view(fb *ifp, int xcenter, int ycenter, int xzoom, int yzoom)
Definition: fb_util.c:43
HIDDEN int deb_setcursor(fb *ifp, const unsigned char *bits, int xbits, int ybits, int xorig, int yorig)
Definition: if_debug.c:234
A frame-buffer IO structure.
Definition: fb_private.h:80
int if_width
current values
Definition: fb_private.h:115
unsigned short cm_blue[256]
Definition: fb.h:85
#define GRN
Definition: color.h:40
HIDDEN int deb_close_existing(fb *ifp)
Definition: if_debug.c:93
char * if_name
what the user called it
Definition: fb_private.h:114
int if_debug
Buffered IO debug flag.
Definition: fb_private.h:134
HIDDEN ssize_t deb_read(fb *ifp, int x, int y, unsigned char *pixelp, size_t count)
Definition: if_debug.c:134
fb debug_interface
Definition: if_debug.c:362