1 /**************************************************************************
3 * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
4 * Copyright (c) 2008 VMware, Inc.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the
9 * "Software"), to deal in the Software without restriction, including
10 * without limitation the rights to use, copy, modify, merge, publish,
11 * distribute, sub license, and/or sell copies of the Software, and to
12 * permit persons to whom the Software is furnished to do so, subject to
13 * the following conditions:
15 * The above copyright notice and this permission notice (including the
16 * next paragraph) shall be included in all copies or substantial portions
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
22 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
23 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
24 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
25 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 **************************************************************************/
30 #include "pipe/p_config.h"
35 #ifdef PIPE_SUBSYSTEM_WINDOWS_DISPLAY
40 #elif defined(PIPE_SUBSYSTEM_WINDOWS_CE)
47 #elif defined(PIPE_SUBSYSTEM_WINDOWS_USER)
49 #ifndef WIN32_LEAN_AND_MEAN
50 #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
62 #include "pipe/p_compiler.h"
63 #include "util/u_debug.h"
64 #include "pipe/p_format.h"
65 #include "pipe/p_state.h"
66 #include "pipe/p_inlines.h"
67 #include "util/u_memory.h"
68 #include "util/u_string.h"
69 #include "util/u_stream.h"
70 #include "util/u_math.h"
71 #include "util/u_tile.h"
74 #ifdef PIPE_SUBSYSTEM_WINDOWS_DISPLAY
76 _EngDebugPrint(const char *format
, ...)
80 EngDebugPrint("", (PCHAR
)format
, ap
);
86 void _debug_vprintf(const char *format
, va_list ap
)
88 #if defined(PIPE_SUBSYSTEM_WINDOWS_DISPLAY)
89 /* EngDebugPrint does not handle float point arguments, so we need to use
90 * our own vsnprintf implementation. It is also very slow, so buffer until
91 * we find a newline. */
92 static char buf
[512] = {'\0'};
93 size_t len
= strlen(buf
);
94 int ret
= util_vsnprintf(buf
+ len
, sizeof(buf
) - len
, format
, ap
);
95 if(ret
> (int)(sizeof(buf
) - len
- 1) || util_strchr(buf
+ len
, '\n')) {
96 _EngDebugPrint("%s", buf
);
99 #elif defined(PIPE_SUBSYSTEM_WINDOWS_USER)
100 /* EngDebugPrint does not handle float point arguments, so we need to use
101 * our own vsnprintf implementation. It is also very slow, so buffer until
102 * we find a newline. */
103 static char buf
[512 + 1] = {'\0'};
104 size_t len
= strlen(buf
);
105 int ret
= util_vsnprintf(buf
+ len
, sizeof(buf
) - len
, format
, ap
);
106 if(ret
> (int)(sizeof(buf
) - len
- 1) || util_strchr(buf
+ len
, '\n')) {
107 OutputDebugStringA(buf
);
111 if(GetConsoleWindow() && !IsDebuggerPresent()) {
112 vfprintf(stderr
, format
, ap
);
116 #elif defined(PIPE_SUBSYSTEM_WINDOWS_CE)
117 wchar_t *wide_format
;
121 #if (_WIN32_WCE < 600)
122 ret
= vsprintf(buf
, format
, ap
);
124 sprintf(buf
, "Cant handle debug print!");
128 ret
= vsprintf_s(buf
, 512, format
, ap
);
130 sprintf_s(buf
, 512, "Cant handle debug print!");
135 /* Format is ascii - needs to be converted to wchar_t for printing */
136 wide_str_len
= MultiByteToWideChar(CP_ACP
, 0, (const char *) buf
, -1, NULL
, 0);
137 wide_format
= (wchar_t *) malloc((wide_str_len
+1) * sizeof(wchar_t));
139 MultiByteToWideChar(CP_ACP
, 0, (const char *) buf
, -1,
140 wide_format
, wide_str_len
);
141 NKDbgPrintfW(wide_format
, wide_format
);
144 #elif defined(PIPE_SUBSYSTEM_WINDOWS_MINIPORT)
146 #else /* !PIPE_SUBSYSTEM_WINDOWS */
148 vfprintf(stderr
, format
, ap
);
155 void debug_print_blob( const char *name
,
159 const unsigned *ublob
= (const unsigned *)blob
;
162 debug_printf("%s (%d dwords%s)\n", name
, size
/4,
163 size
%4 ? "... plus a few bytes" : "");
165 for (i
= 0; i
< size
/4; i
++) {
166 debug_printf("%d:\t%08x\n", i
, ublob
[i
]);
172 void _debug_break(void)
174 #if defined(PIPE_ARCH_X86) && defined(PIPE_CC_GCC)
176 #elif defined(PIPE_ARCH_X86) && defined(PIPE_CC_MSVC)
178 #elif defined(PIPE_SUBSYSTEM_WINDOWS_DISPLAY)
186 #ifdef PIPE_SUBSYSTEM_WINDOWS_DISPLAY
188 find(const char *start
, const char *end
, char c
)
191 for(p
= start
; !end
|| p
!= end
; ++p
) {
201 compare(const char *start
, const char *end
, const char *s
)
204 for(p
= start
, q
= s
; p
!= end
&& *q
!= '\0'; ++p
, ++q
) {
208 return p
== end
&& *q
== '\0';
212 copy(char *dst
, const char *start
, const char *end
, size_t n
)
216 for(p
= start
, q
= dst
, n
= n
- 1; p
!= end
&& n
; ++p
, ++q
, --n
)
223 static INLINE
const char *
224 _debug_get_option(const char *name
)
226 #if defined(PIPE_SUBSYSTEM_WINDOWS_DISPLAY)
227 /* EngMapFile creates the file if it does not exists, so it must either be
228 * disabled on release versions (or put in a less conspicuous place). */
230 const char *result
= NULL
;
232 const void *pMap
= NULL
;
233 const char *sol
, *eol
, *sep
;
234 static char output
[1024];
236 pMap
= EngMapFile(L
"\\??\\c:\\gallium.cfg", 0, &iFile
);
238 sol
= (const char *)pMap
;
240 /* TODO: handle LF line endings */
241 eol
= find(sol
, NULL
, '\r');
242 if(!eol
|| eol
== sol
)
244 sep
= find(sol
, eol
, '=');
247 if(compare(sol
, sep
, name
)) {
248 copy(output
, sep
+ 1, eol
, sizeof(output
));
260 #elif defined(PIPE_SUBSYSTEM_WINDOWS_CE) || defined(PIPE_SUBSYSTEM_WINDOWS_MINIPORT)
261 /* TODO: implement */
269 debug_get_option(const char *name
, const char *dfault
)
273 result
= _debug_get_option(name
);
277 debug_printf("%s: %s = %s\n", __FUNCTION__
, name
, result
? result
: "(null)");
283 debug_get_bool_option(const char *name
, boolean dfault
)
285 const char *str
= _debug_get_option(name
);
290 else if(!util_strcmp(str
, "n"))
292 else if(!util_strcmp(str
, "no"))
294 else if(!util_strcmp(str
, "0"))
296 else if(!util_strcmp(str
, "f"))
298 else if(!util_strcmp(str
, "false"))
303 debug_printf("%s: %s = %s\n", __FUNCTION__
, name
, result
? "TRUE" : "FALSE");
310 debug_get_num_option(const char *name
, long dfault
)
315 str
= _debug_get_option(name
);
330 while('0' <= c
&& c
<= '9') {
331 result
= result
*10 + (c
- '0');
337 debug_printf("%s: %s = %li\n", __FUNCTION__
, name
, result
);
344 debug_get_flags_option(const char *name
,
345 const struct debug_named_value
*flags
,
346 unsigned long dfault
)
348 unsigned long result
;
351 str
= _debug_get_option(name
);
354 else if (!util_strcmp(str
, "help")) {
356 while (flags
->name
) {
357 debug_printf("%s: help for %s: %s [0x%lx]\n", __FUNCTION__
, name
, flags
->name
, flags
->value
);
363 while( flags
->name
) {
364 if (!util_strcmp(str
, "all") || util_strstr(str
, flags
->name
))
365 result
|= flags
->value
;
371 debug_printf("%s: %s = 0x%lx (%s)\n", __FUNCTION__
, name
, result
, str
);
374 debug_printf("%s: %s = 0x%lx\n", __FUNCTION__
, name
, result
);
381 void _debug_assert_fail(const char *expr
,
384 const char *function
)
386 _debug_printf("%s:%u:%s: Assertion `%s' failed.\n", file
, line
, function
, expr
);
387 #if defined(PIPE_OS_WINDOWS) && !defined(PIPE_SUBSYSTEM_WINDOWS_USER)
388 if (debug_get_bool_option("GALLIUM_ABORT_ON_ASSERT", FALSE
))
390 if (debug_get_bool_option("GALLIUM_ABORT_ON_ASSERT", TRUE
))
394 _debug_printf("continuing...\n");
399 debug_dump_enum(const struct debug_named_value
*names
,
402 static char rest
[64];
405 if(names
->value
== value
)
410 util_snprintf(rest
, sizeof(rest
), "0x%08lx", value
);
416 debug_dump_enum_noprefix(const struct debug_named_value
*names
,
420 static char rest
[64];
423 if(names
->value
== value
) {
424 const char *name
= names
->name
;
425 while (*name
== *prefix
) {
436 util_snprintf(rest
, sizeof(rest
), "0x%08lx", value
);
442 debug_dump_flags(const struct debug_named_value
*names
,
445 static char output
[4096];
446 static char rest
[256];
452 if((names
->value
& value
) == names
->value
) {
454 util_strncat(output
, "|", sizeof(output
));
457 util_strncat(output
, names
->name
, sizeof(output
));
458 value
&= ~names
->value
;
465 util_strncat(output
, "|", sizeof(output
));
469 util_snprintf(rest
, sizeof(rest
), "0x%08lx", value
);
470 util_strncat(output
, rest
, sizeof(output
));
480 static const struct debug_named_value pipe_format_names
[] = {
482 DEBUG_NAMED_VALUE(PIPE_FORMAT_NONE
),
483 DEBUG_NAMED_VALUE(PIPE_FORMAT_A8R8G8B8_UNORM
),
484 DEBUG_NAMED_VALUE(PIPE_FORMAT_X8R8G8B8_UNORM
),
485 DEBUG_NAMED_VALUE(PIPE_FORMAT_B8G8R8A8_UNORM
),
486 DEBUG_NAMED_VALUE(PIPE_FORMAT_B8G8R8X8_UNORM
),
487 DEBUG_NAMED_VALUE(PIPE_FORMAT_A1R5G5B5_UNORM
),
488 DEBUG_NAMED_VALUE(PIPE_FORMAT_A4R4G4B4_UNORM
),
489 DEBUG_NAMED_VALUE(PIPE_FORMAT_R5G6B5_UNORM
),
490 DEBUG_NAMED_VALUE(PIPE_FORMAT_A2B10G10R10_UNORM
),
491 DEBUG_NAMED_VALUE(PIPE_FORMAT_L8_UNORM
),
492 DEBUG_NAMED_VALUE(PIPE_FORMAT_A8_UNORM
),
493 DEBUG_NAMED_VALUE(PIPE_FORMAT_I8_UNORM
),
494 DEBUG_NAMED_VALUE(PIPE_FORMAT_A8L8_UNORM
),
495 DEBUG_NAMED_VALUE(PIPE_FORMAT_L16_UNORM
),
496 DEBUG_NAMED_VALUE(PIPE_FORMAT_YCBCR
),
497 DEBUG_NAMED_VALUE(PIPE_FORMAT_YCBCR_REV
),
498 DEBUG_NAMED_VALUE(PIPE_FORMAT_Z16_UNORM
),
499 DEBUG_NAMED_VALUE(PIPE_FORMAT_Z32_UNORM
),
500 DEBUG_NAMED_VALUE(PIPE_FORMAT_Z32_FLOAT
),
501 DEBUG_NAMED_VALUE(PIPE_FORMAT_S8Z24_UNORM
),
502 DEBUG_NAMED_VALUE(PIPE_FORMAT_Z24S8_UNORM
),
503 DEBUG_NAMED_VALUE(PIPE_FORMAT_X8Z24_UNORM
),
504 DEBUG_NAMED_VALUE(PIPE_FORMAT_Z24X8_UNORM
),
505 DEBUG_NAMED_VALUE(PIPE_FORMAT_S8_UNORM
),
506 DEBUG_NAMED_VALUE(PIPE_FORMAT_R64_FLOAT
),
507 DEBUG_NAMED_VALUE(PIPE_FORMAT_R64G64_FLOAT
),
508 DEBUG_NAMED_VALUE(PIPE_FORMAT_R64G64B64_FLOAT
),
509 DEBUG_NAMED_VALUE(PIPE_FORMAT_R64G64B64A64_FLOAT
),
510 DEBUG_NAMED_VALUE(PIPE_FORMAT_R32_FLOAT
),
511 DEBUG_NAMED_VALUE(PIPE_FORMAT_R32G32_FLOAT
),
512 DEBUG_NAMED_VALUE(PIPE_FORMAT_R32G32B32_FLOAT
),
513 DEBUG_NAMED_VALUE(PIPE_FORMAT_R32G32B32A32_FLOAT
),
514 DEBUG_NAMED_VALUE(PIPE_FORMAT_R32_UNORM
),
515 DEBUG_NAMED_VALUE(PIPE_FORMAT_R32G32_UNORM
),
516 DEBUG_NAMED_VALUE(PIPE_FORMAT_R32G32B32_UNORM
),
517 DEBUG_NAMED_VALUE(PIPE_FORMAT_R32G32B32A32_UNORM
),
518 DEBUG_NAMED_VALUE(PIPE_FORMAT_R32_USCALED
),
519 DEBUG_NAMED_VALUE(PIPE_FORMAT_R32G32_USCALED
),
520 DEBUG_NAMED_VALUE(PIPE_FORMAT_R32G32B32_USCALED
),
521 DEBUG_NAMED_VALUE(PIPE_FORMAT_R32G32B32A32_USCALED
),
522 DEBUG_NAMED_VALUE(PIPE_FORMAT_R32_SNORM
),
523 DEBUG_NAMED_VALUE(PIPE_FORMAT_R32G32_SNORM
),
524 DEBUG_NAMED_VALUE(PIPE_FORMAT_R32G32B32_SNORM
),
525 DEBUG_NAMED_VALUE(PIPE_FORMAT_R32G32B32A32_SNORM
),
526 DEBUG_NAMED_VALUE(PIPE_FORMAT_R32_SSCALED
),
527 DEBUG_NAMED_VALUE(PIPE_FORMAT_R32G32_SSCALED
),
528 DEBUG_NAMED_VALUE(PIPE_FORMAT_R32G32B32_SSCALED
),
529 DEBUG_NAMED_VALUE(PIPE_FORMAT_R32G32B32A32_SSCALED
),
530 DEBUG_NAMED_VALUE(PIPE_FORMAT_R16_UNORM
),
531 DEBUG_NAMED_VALUE(PIPE_FORMAT_R16G16_UNORM
),
532 DEBUG_NAMED_VALUE(PIPE_FORMAT_R16G16B16_UNORM
),
533 DEBUG_NAMED_VALUE(PIPE_FORMAT_R16G16B16A16_UNORM
),
534 DEBUG_NAMED_VALUE(PIPE_FORMAT_R16_USCALED
),
535 DEBUG_NAMED_VALUE(PIPE_FORMAT_R16G16_USCALED
),
536 DEBUG_NAMED_VALUE(PIPE_FORMAT_R16G16B16_USCALED
),
537 DEBUG_NAMED_VALUE(PIPE_FORMAT_R16G16B16A16_USCALED
),
538 DEBUG_NAMED_VALUE(PIPE_FORMAT_R16_SNORM
),
539 DEBUG_NAMED_VALUE(PIPE_FORMAT_R16G16_SNORM
),
540 DEBUG_NAMED_VALUE(PIPE_FORMAT_R16G16B16_SNORM
),
541 DEBUG_NAMED_VALUE(PIPE_FORMAT_R16G16B16A16_SNORM
),
542 DEBUG_NAMED_VALUE(PIPE_FORMAT_R16_SSCALED
),
543 DEBUG_NAMED_VALUE(PIPE_FORMAT_R16G16_SSCALED
),
544 DEBUG_NAMED_VALUE(PIPE_FORMAT_R16G16B16_SSCALED
),
545 DEBUG_NAMED_VALUE(PIPE_FORMAT_R16G16B16A16_SSCALED
),
546 DEBUG_NAMED_VALUE(PIPE_FORMAT_R8_UNORM
),
547 DEBUG_NAMED_VALUE(PIPE_FORMAT_R8G8_UNORM
),
548 DEBUG_NAMED_VALUE(PIPE_FORMAT_R8G8B8_UNORM
),
549 DEBUG_NAMED_VALUE(PIPE_FORMAT_R8G8B8A8_UNORM
),
550 DEBUG_NAMED_VALUE(PIPE_FORMAT_R8G8B8X8_UNORM
),
551 DEBUG_NAMED_VALUE(PIPE_FORMAT_R8_USCALED
),
552 DEBUG_NAMED_VALUE(PIPE_FORMAT_R8G8_USCALED
),
553 DEBUG_NAMED_VALUE(PIPE_FORMAT_R8G8B8_USCALED
),
554 DEBUG_NAMED_VALUE(PIPE_FORMAT_R8G8B8A8_USCALED
),
555 DEBUG_NAMED_VALUE(PIPE_FORMAT_R8G8B8X8_USCALED
),
556 DEBUG_NAMED_VALUE(PIPE_FORMAT_R8_SNORM
),
557 DEBUG_NAMED_VALUE(PIPE_FORMAT_R8G8_SNORM
),
558 DEBUG_NAMED_VALUE(PIPE_FORMAT_R8G8B8_SNORM
),
559 DEBUG_NAMED_VALUE(PIPE_FORMAT_R8G8B8A8_SNORM
),
560 DEBUG_NAMED_VALUE(PIPE_FORMAT_R8G8B8X8_SNORM
),
561 DEBUG_NAMED_VALUE(PIPE_FORMAT_B6G5R5_SNORM
),
562 DEBUG_NAMED_VALUE(PIPE_FORMAT_A8B8G8R8_SNORM
),
563 DEBUG_NAMED_VALUE(PIPE_FORMAT_X8B8G8R8_SNORM
),
564 DEBUG_NAMED_VALUE(PIPE_FORMAT_R8_SSCALED
),
565 DEBUG_NAMED_VALUE(PIPE_FORMAT_R8G8_SSCALED
),
566 DEBUG_NAMED_VALUE(PIPE_FORMAT_R8G8B8_SSCALED
),
567 DEBUG_NAMED_VALUE(PIPE_FORMAT_R8G8B8A8_SSCALED
),
568 DEBUG_NAMED_VALUE(PIPE_FORMAT_R8G8B8X8_SSCALED
),
569 DEBUG_NAMED_VALUE(PIPE_FORMAT_L8_SRGB
),
570 DEBUG_NAMED_VALUE(PIPE_FORMAT_A8L8_SRGB
),
571 DEBUG_NAMED_VALUE(PIPE_FORMAT_R8G8B8_SRGB
),
572 DEBUG_NAMED_VALUE(PIPE_FORMAT_R8G8B8A8_SRGB
),
573 DEBUG_NAMED_VALUE(PIPE_FORMAT_R8G8B8X8_SRGB
),
574 DEBUG_NAMED_VALUE(PIPE_FORMAT_A8R8G8B8_SRGB
),
575 DEBUG_NAMED_VALUE(PIPE_FORMAT_X8R8G8B8_SRGB
),
576 DEBUG_NAMED_VALUE(PIPE_FORMAT_B8G8R8A8_SRGB
),
577 DEBUG_NAMED_VALUE(PIPE_FORMAT_B8G8R8X8_SRGB
),
578 DEBUG_NAMED_VALUE(PIPE_FORMAT_X8UB8UG8SR8S_NORM
),
579 DEBUG_NAMED_VALUE(PIPE_FORMAT_B6UG5SR5S_NORM
),
580 DEBUG_NAMED_VALUE(PIPE_FORMAT_DXT1_RGB
),
581 DEBUG_NAMED_VALUE(PIPE_FORMAT_DXT1_RGBA
),
582 DEBUG_NAMED_VALUE(PIPE_FORMAT_DXT3_RGBA
),
583 DEBUG_NAMED_VALUE(PIPE_FORMAT_DXT5_RGBA
),
584 DEBUG_NAMED_VALUE(PIPE_FORMAT_DXT1_SRGB
),
585 DEBUG_NAMED_VALUE(PIPE_FORMAT_DXT1_SRGBA
),
586 DEBUG_NAMED_VALUE(PIPE_FORMAT_DXT3_SRGBA
),
587 DEBUG_NAMED_VALUE(PIPE_FORMAT_DXT5_SRGBA
),
589 DEBUG_NAMED_VALUE_END
593 void debug_print_format(const char *msg
, unsigned fmt
)
595 debug_printf("%s: %s\n", msg
, debug_dump_enum(pipe_format_names
, fmt
));
599 const char *pf_name( enum pipe_format format
)
601 return debug_dump_enum(pipe_format_names
, format
);
606 void debug_dump_image(const char *prefix
,
607 unsigned format
, unsigned cpp
,
608 unsigned width
, unsigned height
,
612 #ifdef PIPE_SUBSYSTEM_WINDOWS_DISPLAY
613 static unsigned no
= 0;
615 WCHAR wfilename
[sizeof(filename
)];
623 unsigned char *pMap
= NULL
;
626 util_snprintf(filename
, sizeof(filename
), "\\??\\c:\\%03u%s.raw", ++no
, prefix
);
627 for(i
= 0; i
< sizeof(filename
); ++i
)
628 wfilename
[i
] = (WCHAR
)filename
[i
];
630 pMap
= (unsigned char *)EngMapFile(wfilename
, sizeof(header
) + height
*width
*cpp
, &iFile
);
634 header
.format
= format
;
636 header
.width
= width
;
637 header
.height
= height
;
638 memcpy(pMap
, &header
, sizeof(header
));
639 pMap
+= sizeof(header
);
641 for(i
= 0; i
< height
; ++i
) {
642 memcpy(pMap
, (unsigned char *)data
+ stride
*i
, cpp
*width
);
650 void debug_dump_surface(const char *prefix
,
651 struct pipe_surface
*surface
)
653 struct pipe_texture
*texture
;
654 struct pipe_screen
*screen
;
655 struct pipe_transfer
*transfer
;
661 texture
= surface
->texture
;
662 screen
= texture
->screen
;
664 transfer
= screen
->get_tex_transfer(screen
, texture
, surface
->face
,
665 surface
->level
, surface
->zslice
,
666 PIPE_TRANSFER_READ
, 0, 0, surface
->width
,
669 data
= screen
->transfer_map(screen
, transfer
);
673 debug_dump_image(prefix
,
675 transfer
->block
.size
,
681 screen
->transfer_unmap(screen
, transfer
);
683 screen
->tex_transfer_release(screen
, &transfer
);
688 struct bmp_file_header
{
691 uint16_t bfReserved1
;
692 uint16_t bfReserved2
;
697 struct bmp_info_header
{
703 uint32_t biCompression
;
704 uint32_t biSizeImage
;
705 int32_t biXPelsPerMeter
;
706 int32_t biYPelsPerMeter
;
708 uint32_t biClrImportant
;
711 struct bmp_rgb_quad
{
719 debug_dump_surface_bmp(const char *filename
,
720 struct pipe_surface
*surface
)
722 #ifndef PIPE_SUBSYSTEM_WINDOWS_MINIPORT
723 struct pipe_texture
*texture
;
724 struct pipe_screen
*screen
;
725 struct util_stream
*stream
;
726 struct pipe_transfer
*transfer
;
727 struct bmp_file_header bmfh
;
728 struct bmp_info_header bmih
;
735 rgba
= MALLOC(surface
->width
*4*sizeof(float));
739 bmfh
.bfType
= 0x4d42;
740 bmfh
.bfSize
= 14 + 40 + surface
->height
*surface
->width
*4;
741 bmfh
.bfReserved1
= 0;
742 bmfh
.bfReserved2
= 0;
743 bmfh
.bfOffBits
= 14 + 40;
746 bmih
.biWidth
= surface
->width
;
747 bmih
.biHeight
= surface
->height
;
749 bmih
.biBitCount
= 32;
750 bmih
.biCompression
= 0;
751 bmih
.biSizeImage
= surface
->height
*surface
->width
*4;
752 bmih
.biXPelsPerMeter
= 0;
753 bmih
.biYPelsPerMeter
= 0;
755 bmih
.biClrImportant
= 0;
757 stream
= util_stream_create(filename
, bmfh
.bfSize
);
761 util_stream_write(stream
, &bmfh
, 14);
762 util_stream_write(stream
, &bmih
, 40);
764 texture
= surface
->texture
;
765 screen
= texture
->screen
;
767 transfer
= screen
->get_tex_transfer(screen
, texture
, surface
->face
,
768 surface
->level
, surface
->zslice
,
769 PIPE_TRANSFER_READ
, 0, 0, surface
->width
,
774 pipe_get_tile_rgba(transfer
,
775 0, y
, surface
->width
, 1,
777 for(x
= 0; x
< surface
->width
; ++x
)
779 struct bmp_rgb_quad pixel
;
780 pixel
.rgbRed
= float_to_ubyte(rgba
[x
*4 + 0]);
781 pixel
.rgbGreen
= float_to_ubyte(rgba
[x
*4 + 1]);
782 pixel
.rgbBlue
= float_to_ubyte(rgba
[x
*4 + 2]);
783 pixel
.rgbAlpha
= float_to_ubyte(rgba
[x
*4 + 3]);
784 util_stream_write(stream
, &pixel
, 4);
788 screen
->tex_transfer_release(screen
, &transfer
);
790 util_stream_close(stream
);