From 86c5a2afb4cbebbc7b41b9815c993c4fcc099b64 Mon Sep 17 00:00:00 2001 From: Timo Dritschler Date: Fri, 9 May 2014 20:28:25 +0200 Subject: Added SDL (Simple Direct media Layer) image output to testing framework Test communicaation between server and client now passes images via KIRO-TRB Updated Makefile Removed Super-Verbose output from kiro_client_sync --- Makefile | 2 +- kiro-client.c | 2 -- test-client.c | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- test-server.c | 8 ++++--- 4 files changed, 81 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index a9d2143..92f5508 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ CC=gcc CFLAGS=-std=c99 -Wall -g -gdwarf-2 $(shell pkg-config --cflags gobject-2.0) -LDFLAGS=-lm -lrdmacm -libverbs -lpthread $(shell pkg-config --libs gobject-2.0) +LDFLAGS=-lSDL -lm -lrdmacm -libverbs -lpthread $(shell pkg-config --libs gobject-2.0) .PHONY : all diff --git a/kiro-client.c b/kiro-client.c index 7c328a5..b6a515e 100644 --- a/kiro-client.c +++ b/kiro-client.c @@ -219,8 +219,6 @@ int kiro_client_sync (KiroClient *self) rdma_destroy_ep(priv->conn); return -1; } - - printf("Memory successfully read from server.\n"); return 0; } diff --git a/test-client.c b/test-client.c index 5c78d42..65a3c08 100644 --- a/test-client.c +++ b/test-client.c @@ -2,6 +2,32 @@ #include #include #include "kiro-client.h" +#include "kiro-trb.h" +#include +#include + + +static _Bool init_app(const char * name, SDL_Surface * icon, uint32_t flags) +{ + atexit(SDL_Quit); + if(SDL_Init(flags) < 0) + return 0; + + SDL_WM_SetCaption(name, name); + SDL_WM_SetIcon(icon, NULL); + + return 1; +} + +static void render(SDL_Surface * sf) +{ + SDL_Surface * screen = SDL_GetVideoSurface(); + if(SDL_BlitSurface(sf, NULL, screen, NULL) == 0) + SDL_UpdateRect(screen, 0, 0, 0, 0); +} + +static int filter(const SDL_Event * event) +{ return event->type == SDL_QUIT; } int main ( int argc, char *argv[] ) @@ -14,6 +40,54 @@ int main ( int argc, char *argv[] ) KiroClient *client = g_object_new(KIRO_TYPE_CLIENT, NULL); if(-1 != kiro_client_connect(client, argv[1], argv[2])) kiro_client_sync(client); + + KiroTrb *trb = g_object_new(KIRO_TYPE_TRB, NULL); + kiro_trb_adopt(trb, kiro_client_get_memory(client)); + + _Bool ok = + init_app("UCA Images", NULL, SDL_INIT_VIDEO) && + SDL_SetVideoMode(512, 512, 8, SDL_HWSURFACE); + + assert(ok); + + uint32_t mask = 0xffffffff; + SDL_Surface * data_sf = SDL_CreateRGBSurfaceFrom( + kiro_trb_get_element(trb, 0), 512, 512, 8, 512, + mask, mask, mask, 0); + + SDL_Color colors[256]; + for(int i=0;i<256;i++){ + colors[i].r=i; + colors[i].g=i; + colors[i].b=i; + } + SDL_SetPalette(data_sf, SDL_LOGPAL|SDL_PHYSPAL, colors, 0, 256); + + SDL_SetEventFilter(filter); + + int cont = 1; + + struct KiroTrbInfo *header = (struct KiroTrbInfo *)kiro_trb_get_raw_buffer(trb); + + while(cont) + { + for(SDL_Event event; SDL_PollEvent(&event);) + if(event.type == SDL_QUIT) cont=0; + + kiro_client_sync(client); + SDL_Delay(10); + render(data_sf); + } + + g_object_unref(client); return 0; -} \ No newline at end of file +} + + + + + + + + diff --git a/test-server.c b/test-server.c index 1becb31..63fefaa 100644 --- a/test-server.c +++ b/test-server.c @@ -118,7 +118,7 @@ print_current_frame (gchar *buffer, guint number, guint width, guint height, GRa //pattern for (guint y = 16; y < height; y++) { guint index = y * width; - memcpy(&buffer[index], &default_line[0], width); + memcpy(buffer+index, &default_line[0], width); } //This block will fill a square at the center of the image with normal @@ -143,7 +143,7 @@ int main(void) { KiroServer *server = g_object_new(KIRO_TYPE_SERVER, NULL); KiroTrb *rb = g_object_new(KIRO_TYPE_TRB, NULL); - kiro_trb_reshape(rb, 512*512, 1000); + kiro_trb_reshape(rb, 512*512, 15); GRand *rand = g_rand_new(); if(0 > kiro_server_start(server, NULL, "60010", kiro_trb_get_raw_buffer(rb), kiro_trb_get_raw_size(rb))) { @@ -152,9 +152,11 @@ int main(void) } guint frame = 0; + gchar *buffer = NULL; while(1) { - print_current_frame(kiro_trb_dma_push(rb), frame, 512, 512, rand); + buffer = kiro_trb_dma_push(rb); + print_current_frame(buffer, frame, 512, 512, rand); frame++; } -- cgit v1.2.3