progs/tests: Ignores
[mesa.git] / progs / rbug / tex_dump.c
1 /*
2 * Copyright 2009 VMware, Inc.
3 * All Rights Reserved.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * on the rights to use, copy, modify, merge, publish, distribute, sub
9 * license, and/or sell copies of the Software, and to permit persons to whom
10 * the Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
14 * Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
19 * VMWARE AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
20 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
21 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
22 * USE OR OTHER DEALINGS IN THE SOFTWARE.
23 */
24
25 #include "pipe/p_compiler.h"
26 #include "pipe/p_format.h"
27 #include "pipe/p_state.h"
28 #include "util/u_memory.h"
29 #include "util/u_debug.h"
30 #include "util/u_format.h"
31 #include "util/u_network.h"
32 #include "util/u_string.h"
33 #include "util/u_tile.h"
34 #include "rbug/rbug.h"
35
36 static void dump(rbug_texture_t tex,
37 struct rbug_proto_texture_info_reply *info,
38 struct rbug_proto_texture_read_reply *read,
39 int mip)
40 {
41 enum pipe_format format = info->format;
42 uint8_t *data = read->data;
43 unsigned width = info->width[mip];
44 unsigned height = info->height[mip];
45 unsigned dst_stride = width * 4 * 4;
46 unsigned src_stride = read->stride;
47 float *rgba = MALLOC(dst_stride * height);
48 int i;
49 char filename[512];
50
51 util_snprintf(filename, 512, "%llu_%s_%u.bmp",
52 (unsigned long long)tex, util_format_name(info->format), mip);
53
54 if (util_format_is_compressed(info->format)) {
55 debug_printf("skipping: %s\n", filename);
56 return;
57 }
58
59 debug_printf("saving: %s\n", filename);
60
61 for (i = 0; i < height; i++) {
62 pipe_tile_raw_to_rgba(format, data + src_stride * i,
63 width, 1,
64 &rgba[width*4*i], dst_stride);
65 }
66
67 debug_dump_float_rgba_bmp(filename, width, height, rgba, width);
68
69 FREE(rgba);
70 }
71
72 static void talk()
73 {
74 int c = u_socket_connect("localhost", 13370);
75 struct rbug_connection *con = rbug_from_socket(c);
76 struct rbug_header *header;
77 struct rbug_header *header2;
78 struct rbug_proto_texture_list_reply *list;
79 struct rbug_proto_texture_info_reply *info;
80 struct rbug_proto_texture_read_reply *read;
81 int i, j;
82
83 assert(c >= 0);
84 assert(con);
85 debug_printf("Connection get!\n");
86
87 debug_printf("Sending get textures\n");
88 rbug_send_texture_list(con, NULL);
89
90 debug_printf("Waiting for textures\n");
91 header = rbug_get_message(con, NULL);
92 assert(header->opcode == RBUG_OP_TEXTURE_LIST_REPLY);
93 list = (struct rbug_proto_texture_list_reply *)header;
94
95 debug_printf("Got textures:\n");
96 for (i = 0; i < list->textures_len; i++) {
97 rbug_send_texture_info(con, list->textures[i], NULL);
98
99 header = rbug_get_message(con, NULL);
100 assert(header->opcode == RBUG_OP_TEXTURE_INFO_REPLY);
101 info = (struct rbug_proto_texture_info_reply *)header;
102
103 for (j = 0; j <= info->last_level; j++) {
104 rbug_send_texture_read(con, list->textures[i],
105 0, j, 0,
106 0, 0, info->width[j], info->height[j],
107 NULL);
108
109 header2 = rbug_get_message(con, NULL);
110 assert(header2->opcode == RBUG_OP_TEXTURE_READ_REPLY);
111 read = (struct rbug_proto_texture_read_reply *)header2;
112
113 dump(list->textures[i], info, read, j);
114
115 rbug_free_header(header2);
116 }
117
118 rbug_free_header(header);
119
120 }
121 rbug_free_header(&list->header);
122 rbug_disconnect(con);
123 }
124
125 int main(int argc, char** argv)
126 {
127 talk();
128 return 0;
129 }