[tyndur-devel] [PATCH 6/6] + gfxtest: Testprogramm für videolib und cdi.video
Alexander Siol ·
Signed-off-by: Alexander Siol <alex at tyndur.org> --- src/modules/c/gfxtest/Makefile.all | 8 +++ src/modules/c/gfxtest/main.c | 110 ++++++++++++++++++++++++++++++++++++ 2 files changed, 118 insertions(+), 0 deletions(-) create mode 100644 src/modules/c/gfxtest/Makefile.all create mode 100644 src/modules/c/gfxtest/main.c diff --git a/src/modules/c/gfxtest/Makefile.all b/src/modules/c/gfxtest/Makefile.all new file mode 100644 index 0000000..ad34934 --- /dev/null +++ b/src/modules/c/gfxtest/Makefile.all @@ -0,0 +1,8 @@ +shopt -s extglob +source $LOST_BUILDMK_ROOT/config.sh + +echo "LD $1/apps/gfxtest" +$LOST_TOOLS_LD -ogfxtest -Ttext=0x40000000 *.o --start-group $2 --end-group + + +mv gfxtest $1/apps/ diff --git a/src/modules/c/gfxtest/main.c b/src/modules/c/gfxtest/main.c new file mode 100644 index 0000000..f2b767c --- /dev/null +++ b/src/modules/c/gfxtest/main.c @@ -0,0 +1,110 @@ +/* + * Copyright (c) 2009 The tyndur Project. All rights reserved. + * + * This code is derived from software contributed to the tyndur Project + * by Alexander Siol. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.*/ + +#include <video/video.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <math.h> + +int main(int argc, char** argv) +{ + stdout = 0; + driver_context_t* main_context; + main_context = libvideo_create_driver_context("vesa"); + libvideo_use_driver_context(main_context); + libvideo_get_command_buffer(1024); + + printf("Habe Kontext:\n pid: %d\n context: %d\n", context->driverpid, + context->drivercontext); + printf("Kommandobuffer: %d an %x, Länge %d\n", context->cmdbufferid, + context->cmdbuffer, context->cmdbufferlen); + + int num_devices = libvideo_get_num_devices(); + int a, b, c; + for (a = 0; a < num_devices; a++) { + printf("Device %d / %d\n", a + 1, num_devices); + int num_displays = libvideo_get_num_displays(a); + for (b = 0; b < num_displays; b++) { + dword* modes = libvideo_get_modes(0, 0); + printf("\tDisplay %d / %d, %d Modi verfügbar\n", b + 1, + num_displays, modes[0]); + for (c = 0; c < modes[0]; c++) { + printf("\t\tModus: %dx%dx%d\n", modes[1 + c*4], + modes[1 + c*4 + 1], modes[1 + c*4 + 2]); + } + } + } + + libvideo_change_device(0); + printf("Gerät gesetzt.\n"); + + libvideo_change_color(0, 255, 0, 0); + libvideo_do_command_buffer(); + + printf("Farbe gesetzt.\n"); + + if (libvideo_change_display_resolution(0, 1024, 768, 16) != 0) { + printf("Modus setzen fehlgeschlagen\n"); + return -1; + } + + printf("Modus gesetzt.\n"); + + video_bitmap_t *front; + front = libvideo_get_frontbuffer_bitmap(0); + + video_bitmap_t *drawing_test_bitmap; + drawing_test_bitmap = libvideo_create_bitmap(800, 600, 0, NULL); + + + void *databuffer = malloc(20 * 20 * 4); + memset(databuffer, 0xdd, 20*20*4); + video_bitmap_t *loaded_bitmap; + loaded_bitmap = libvideo_create_bitmap(20, 20, 20*20*4, databuffer); + libvideo_change_target(drawing_test_bitmap); + + // Sternförmig Linien malen. + int x = 100, y = 100; + for (a = 0; a <= 360; a += 1) { + x = cos(a * M_PI / 180) * 50; + y = sin(a * M_PI / 180) * 50; + libvideo_change_color(0, a * 255 / 360, a * 255 / 360, a * 255 / 360); + libvideo_draw_line(100, 100, 100 + x, 100 + y); + } + + libvideo_change_target(front); + libvideo_draw_rectangle(200, 200, 200, 200); + libvideo_draw_pixel(800, 600); + libvideo_draw_bitmap_part(drawing_test_bitmap, 50, 50, 50, 50, 100, 100); + libvideo_draw_bitmap(loaded_bitmap, 90, 90); + libvideo_do_command_buffer(); + + printf("Finished.\n", front->id); + + return 0; +} -- 1.6.0.4