132001f49Smrg/* 232001f49Smrg * Copyright 2009 VMware, Inc. 332001f49Smrg * All Rights Reserved. 432001f49Smrg * 532001f49Smrg * Permission is hereby granted, free of charge, to any person obtaining a 632001f49Smrg * copy of this software and associated documentation files (the "Software"), 732001f49Smrg * to deal in the Software without restriction, including without limitation 832001f49Smrg * on the rights to use, copy, modify, merge, publish, distribute, sub 932001f49Smrg * license, and/or sell copies of the Software, and to permit persons to whom 1032001f49Smrg * the Software is furnished to do so, subject to the following conditions: 1132001f49Smrg * 1232001f49Smrg * The above copyright notice and this permission notice (including the next 1332001f49Smrg * paragraph) shall be included in all copies or substantial portions of the 1432001f49Smrg * Software. 1532001f49Smrg * 1632001f49Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 1732001f49Smrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 1832001f49Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL 1932001f49Smrg * VMWARE AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM, 2032001f49Smrg * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 2132001f49Smrg * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 2232001f49Smrg * USE OR OTHER DEALINGS IN THE SOFTWARE. 2332001f49Smrg */ 2432001f49Smrg 2532001f49Smrg#include "pipe/p_compiler.h" 2632001f49Smrg#include "pipe/p_format.h" 2732001f49Smrg#include "pipe/p_state.h" 2832001f49Smrg#include "util/u_memory.h" 2932001f49Smrg#include "util/u_debug.h" 3032001f49Smrg#include "util/u_format.h" 3132001f49Smrg#include "util/u_network.h" 3232001f49Smrg#include "util/u_string.h" 3332001f49Smrg#include "util/u_tile.h" 3432001f49Smrg#include "rbug/rbug.h" 3532001f49Smrg 3632001f49Smrgstatic void dump(rbug_texture_t tex, 3732001f49Smrg struct rbug_proto_texture_info_reply *info, 3832001f49Smrg struct rbug_proto_texture_read_reply *read, 3932001f49Smrg int mip) 4032001f49Smrg{ 4132001f49Smrg enum pipe_format format = info->format; 4232001f49Smrg uint8_t *data = read->data; 4332001f49Smrg unsigned width = info->width[mip]; 4432001f49Smrg unsigned height = info->height[mip]; 4532001f49Smrg unsigned dst_stride = width * 4 * 4; 4632001f49Smrg unsigned src_stride = read->stride; 4732001f49Smrg float *rgba = MALLOC(dst_stride * height); 4832001f49Smrg int i; 4932001f49Smrg char filename[512]; 5032001f49Smrg 5132001f49Smrg util_snprintf(filename, 512, "%llu_%s_%u.bmp", 5232001f49Smrg (unsigned long long)tex, util_format_name(info->format), mip); 5332001f49Smrg 5432001f49Smrg if (util_format_is_compressed(info->format)) { 5532001f49Smrg debug_printf("skipping: %s\n", filename); 5632001f49Smrg return; 5732001f49Smrg } 5832001f49Smrg 5932001f49Smrg debug_printf("saving: %s\n", filename); 6032001f49Smrg 6132001f49Smrg for (i = 0; i < height; i++) { 6232001f49Smrg pipe_tile_raw_to_rgba(format, data + src_stride * i, 6332001f49Smrg width, 1, 6432001f49Smrg &rgba[width*4*i], dst_stride); 6532001f49Smrg } 6632001f49Smrg 6732001f49Smrg debug_dump_float_rgba_bmp(filename, width, height, rgba, width); 6832001f49Smrg 6932001f49Smrg FREE(rgba); 7032001f49Smrg} 7132001f49Smrg 7232001f49Smrgstatic void talk() 7332001f49Smrg{ 7432001f49Smrg int c = u_socket_connect("localhost", 13370); 7532001f49Smrg struct rbug_connection *con = rbug_from_socket(c); 7632001f49Smrg struct rbug_header *header; 7732001f49Smrg struct rbug_header *header2; 7832001f49Smrg struct rbug_proto_texture_list_reply *list; 7932001f49Smrg struct rbug_proto_texture_info_reply *info; 8032001f49Smrg struct rbug_proto_texture_read_reply *read; 8132001f49Smrg int i, j; 8232001f49Smrg 8332001f49Smrg assert(c >= 0); 8432001f49Smrg assert(con); 8532001f49Smrg debug_printf("Connection get!\n"); 8632001f49Smrg 8732001f49Smrg debug_printf("Sending get textures\n"); 8832001f49Smrg rbug_send_texture_list(con, NULL); 8932001f49Smrg 9032001f49Smrg debug_printf("Waiting for textures\n"); 9132001f49Smrg header = rbug_get_message(con, NULL); 9232001f49Smrg assert(header->opcode == RBUG_OP_TEXTURE_LIST_REPLY); 9332001f49Smrg list = (struct rbug_proto_texture_list_reply *)header; 9432001f49Smrg 9532001f49Smrg debug_printf("Got textures:\n"); 9632001f49Smrg for (i = 0; i < list->textures_len; i++) { 9732001f49Smrg rbug_send_texture_info(con, list->textures[i], NULL); 9832001f49Smrg 9932001f49Smrg header = rbug_get_message(con, NULL); 10032001f49Smrg assert(header->opcode == RBUG_OP_TEXTURE_INFO_REPLY); 10132001f49Smrg info = (struct rbug_proto_texture_info_reply *)header; 10232001f49Smrg 10332001f49Smrg for (j = 0; j <= info->last_level; j++) { 10432001f49Smrg rbug_send_texture_read(con, list->textures[i], 10532001f49Smrg 0, j, 0, 10632001f49Smrg 0, 0, info->width[j], info->height[j], 10732001f49Smrg NULL); 10832001f49Smrg 10932001f49Smrg header2 = rbug_get_message(con, NULL); 11032001f49Smrg assert(header2->opcode == RBUG_OP_TEXTURE_READ_REPLY); 11132001f49Smrg read = (struct rbug_proto_texture_read_reply *)header2; 11232001f49Smrg 11332001f49Smrg dump(list->textures[i], info, read, j); 11432001f49Smrg 11532001f49Smrg rbug_free_header(header2); 11632001f49Smrg } 11732001f49Smrg 11832001f49Smrg rbug_free_header(header); 11932001f49Smrg 12032001f49Smrg } 12132001f49Smrg rbug_free_header(&list->header); 12232001f49Smrg rbug_disconnect(con); 12332001f49Smrg} 12432001f49Smrg 12532001f49Smrgint main(int argc, char** argv) 12632001f49Smrg{ 12732001f49Smrg talk(); 12832001f49Smrg return 0; 12932001f49Smrg} 130