>From 3e7b60d37dac1be5e5b195126c3244b2418c01f6 Mon Sep 17 00:00:00 2001 From: Mathias Gottschlag Date: Tue, 14 Oct 2008 15:53:53 +0200 Subject: [PATCH] + Videolibrary fuer Anzeigen von Grafik in Programmen --- src/modules/include/video/commands.h | 72 ++++++++ src/modules/include/video/drawing.h | 187 +++++++++++++++++++ src/modules/include/video/video.h | 84 +++++++++ src/modules/lib/video/drawing.c | 335 ++++++++++++++++++++++++++++++++++ src/modules/lib/video/video.c | 259 ++++++++++++++++++++++++++ 5 files changed, 937 insertions(+), 0 deletions(-) create mode 100644 src/modules/include/video/commands.h create mode 100644 src/modules/include/video/drawing.h create mode 100644 src/modules/include/video/video.h create mode 100644 src/modules/lib/video/drawing.c create mode 100644 src/modules/lib/video/video.c diff --git a/src/modules/include/video/commands.h b/src/modules/include/video/commands.h new file mode 100644 index 0000000..cea4b1e --- /dev/null +++ b/src/modules/include/video/commands.h @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2007 The LOST Project. All rights reserved. + * + * This code is derived from software contributed to the LOST Project + * by Mathias Gottschlag. + * + * 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. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the LOST Project + * and its contributors. + * 4. Neither the name of the LOST Project nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * 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. + */ + +#ifndef VIDEO_COMMANDS_H +#define VIDEO_COMMANDS_H + +// Driver commands +#define VIDEO_ADD_VSCREEN 0 +#define VIDEO_REMOVE_VSCREEN 1 +#define VIDEO_SET_ACTIVE_VSCREEN 2 +#define VIDEO_GET_ACTIVE_VSCREEN 3 + +#define VIDEO_SET_RESOLUTION 4 +#define VIDEO_GET_RESOLUTION 5 +#define VIDEO_GET_RESOLUTION_LIST 6 + +#define VIDEO_UPLOAD_BITMAP 9 +#define VIDEO_DESTROY_BITMAP 10 +#define VIDEO_DESTROY_ALL_BITMAPS 11 +#define VIDEO_COMMAND_STREAM 12 + +#define VIDEO_GET_COMMAND_BUFFER 7 + +// Client commands +#define VIDEO_CLIENT_DEACTIVATE 0 +#define VIDEO_CLIENT_ACTIVATE 1 + +// Command stream +#define VIDEO_CMD_SET_ROP 0 +#define VIDEO_CMD_SET_TARGET 1 +#define VIDEO_CMD_DRAW_DOT 8 +#define VIDEO_CMD_DRAW_RECT 2 +#define VIDEO_CMD_DRAW_LINE 3 +#define VIDEO_CMD_DRAW_ELLIPSE 4 +#define VIDEO_CMD_DRAW_BITMAP 5 +#define VIDEO_CMD_DRAW_BITMAP_PART 6 +#define VIDEO_CMD_COPY_SCREEN 7 + + +#endif diff --git a/src/modules/include/video/drawing.h b/src/modules/include/video/drawing.h new file mode 100644 index 0000000..440acf9 --- /dev/null +++ b/src/modules/include/video/drawing.h @@ -0,0 +1,187 @@ +/* + * Copyright (c) 2008 The LOST Project. All rights reserved. + * + * This code is derived from software contributed to the LOST Project + * by Mathias Gottschlag. + * + * 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. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the LOST Project + * and its contributors. + * 4. Neither the name of the LOST Project nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * 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. + */ + +#ifndef DRAWING_H +#define DRAWING_H + +/** + * Startet einen Videokommandostream. Kommandos werden gebuffert per Shared + * Memory uebertragen. + */ +void video_start_command(void); +/** + * Beendet einen Videokommandostream und sendet ihn an den Treiber. + */ +void video_end_command(void); + +/** + * Raster Ops kontrollieren, wie etwas gezeichnet wird + */ +typedef enum video_rop { + /// Normales Schreiben aufs Ziel, Untergrund wird ueberschrieben + ROP_COPY, + /// Zwischen Untergrund und zu schreibendem wird ein "or" durchgeführt + /// Beispiel: Malen von Teilen mittels einer weissen Maske + ROP_OR, + /// Zwischen Untergrund und zu schreibendem wird ein "and" durchgeführt + /// Beispiel: Loeschen von Teilen mittels einer schwarzen Maske + ROP_AND, + /// Zwischen Untergrund und zu schreibendem wird ein "xor" durchgeführt + /// Beispiel: Invertieren eines Bildes durch Uebermalen mit weissem Rechteck + ROP_XOR +} video_rop_t; + +/** + * Stellt den Raster Op ein, der zum Zeichnen benutzt wird + * Muss zwischen video_start_command und video_end_command aufgerufen werden. + */ +void video_set_rop(video_rop_t rop); + +/** + * Stellt das Ziel ein, auf das geschrieben wird. + * Muss zwischen video_start_command und video_end_command aufgerufen werden. + * @param bitmap Zielbitmap. Wenn gleich 0, dann wird auf den Bildschirm + * geschrieben. + */ +void video_set_target(int bitmap); // 0 = Screen + +/** + * Zeichnet einen farbigen Punkt + * Muss zwischen video_start_command und video_end_command aufgerufen werden. + * @param color Farbe des Punktes + * @param x X-Koordinate + * @param y Y-Koordinate + */ +void video_draw_dot(int color, int x, int y); +/** + * Zeichnet ein farbiges Rechteck + * Muss zwischen video_start_command und video_end_command aufgerufen werden. + * @param color Farbe des Rechtecks + * @param x X-Koordinate + * @param y Y-Koordinate + * @param width Breite des Rechtecks + * @param height Hoehe des Rechtecks + */ +void video_draw_solid_rect(int color, int x, int y, int width, int height); +/** + * Zeichnet eine farbige Linie + * Muss zwischen video_start_command und video_end_command aufgerufen werden. + * @param color Farbe der Linie + * @param x1 X-Koordinate des Startpunkts + * @param y1 Y-Koordinate des Startpunkts + * @param x2 X-Koordinate des Endpunkts + * @param y2 Y-Koordinate des Endpunkts + */ +void video_draw_line(int color, int x1, int y1, int x2, int y2); +/** + * Zeichnet eine farbige Ellipse + * Muss zwischen video_start_command und video_end_command aufgerufen werden. + * @param color Farbe der Ellipse + * @param x X-Koordinate + * @param y Y-Koordinate + * @param width Breite der Ellipse + * @param height Hoehe der Ellipse + */ +void video_draw_ellipse(int color, int x, int y, int width, int height); + +/** + * Zeichnet ein komplettes Bitmap aufs Ziel. Das Bitmap muss vorher via + * video_upload_bitmap geladen worden sein. + * Muss zwischen video_start_command und video_end_command aufgerufen werden. + * @param bitmap Zu benutzendes Bitmap + * @param x X-Koordinate + * @param y Y-Koordinate + */ +void video_draw_bitmap(int bitmap, int x, int y); +/** + * Zeichnet einen Teil eines Bitmaps aufs Ziel. Das Bitmap muss vorher via + * video_upload_bitmap geladen worden sein. + * Muss zwischen video_start_command und video_end_command aufgerufen werden. + * @param bitmap Zu benutzendes Bitmap + * @param x X-Koordinate + * @param y Y-Koordinate + * @param srcx X-Koordinate des zu zeichnenden Teils + * @param srcy Y-Koordinate des zu zeichnenden Teils + * @param srcwidth Breite des zu zeichnenden Teils + * @param srcheight Hoehe des zu zeichnenden Teils + */ +void video_draw_bitmap_part(int bitmap, int x, int y, int srcx, int srcy, int srcwidth, int srcheight); +/** + * Zeichnet einen Teil aus dem Bildschirm aufs Ziel. + * Muss zwischen video_start_command und video_end_command aufgerufen werden. + * @param x X-Koordinate + * @param y Y-Koordinate + * @param srcx X-Koordinate des zu zeichnenden Teils + * @param srcy Y-Koordinate des zu zeichnenden Teils + * @param srcwidth Breite des zu zeichnenden Teils + * @param srcheight Hoehe des zu zeichnenden Teils + */ +void video_copy_screen(int x, int y, int srcx, int srcy, int srcwidth, int srcheight); + +// Bitmapformate +#define BITMAP_FORMAT_MONO_1 0 +#define BITMAP_FORMAT_MONO_8 1 +#define BITMAP_FORMAT_R8G8B8_24 2 +#define BITMAP_FORMAT_B8G8R8_24 3 +#define BITMAP_FORMAT_R8G8B8_32 4 +#define BITMAP_FORMAT_B8G8R8_32 5 +#define BITMAP_FORMAT_R5G6B5_16 6 +#define BITMAP_FORMAT_B5G6R5_16 7 +#define BITMAP_FORMAT_R5G5B5_16 8 +#define BITMAP_FORMAT_B5G5R5_16 9 +#define BITMAP_FORMAT_GREY_8 10 + +/** + * Laedt ein Bitmap in den Videotreiber. + * @param data Pixeldaten oder 0, wenn das Bitmap nicht initialisiert werden soll + * @param width Breite des Bitmaps + * @param height Hoehe des Bitmaps + * @param format Format der Pixeldaten + * @return ID des Bitmaps + */ +int video_upload_bitmap(void *data, int width, int height, int format); +/** + * Loescht das Bitmap mit der angegebenen ID + * @param bitmap Zu loeschendes Bitmap + */ +void video_delete_bitmap(int bitmap); +/** + * Loescht alle Bitmaps, die zuvor via video_upload_bitmap in den Videotreiber + * geladen wurden + */ +void video_delete_all_bitmaps(void); + +#endif + diff --git a/src/modules/include/video/video.h b/src/modules/include/video/video.h new file mode 100644 index 0000000..0e9bcaf --- /dev/null +++ b/src/modules/include/video/video.h @@ -0,0 +1,84 @@ +/* + * Copyright (c) 2007 Mathias Gottschlag + * + * This program is free software. It comes without any warranty, to + * the extent permitted by applicable law. You can redistribute it + * and/or modify it under the terms of the Do What The Fuck You Want + * To Public License, Version 2, as published by Sam Hocevar. See + * http://sam.zoy.org/projects/COPYING.WTFPL for more details. + */ + +#ifndef VIDEO_H +#define VIDEO_H + +#include "types.h" + +typedef struct resolution_t +{ + dword width; + dword height; + dword bpp; + int text; +} resolution_t; + +typedef struct resolution_list_t +{ + dword res_count; + resolution_t *resolutions; +} resolution_list_t; + +/** + * Initialisiert die Grafik: Stellt die Verbindung zu einem Grafiktreiber her + * und erstellt einen virtuellen Bildschirm + */ +int video_init(void); +/** + * Schliesst den virtuellen Bildschirm und Beendet Verbindung zum Grafiktreiber + */ +void video_close(void); + +/** + * Stellt die Aufloesung des Bildschirms ein + * @param width Breite des Bildschirms + * @param height Hoehe des Bildschirms + * @param bpp Bits pro Pixel + */ +int video_set_resolution(dword width, dword height, dword bpp); +/** + * Liefert die derzeitige Aufloesung zurueck + */ +resolution_t video_get_resolution(void); +/** + * Liefert eine Liste mit den moeglichen Aufloesungen zurueck. + * Die Liste muss vom aufrufenden Programm nicht geloescht werden. + */ +resolution_list_t video_get_possible_resolutions(void); + +/** + * Liefert den Index des virtuellen Bildschirms zurueck + */ +int video_get_vscreen(void); +/** + * Liefert zurueck, ob der derzeige virtuelle Bildschirm aktiv ist oder nicht. + * Aus Performancegruenden sollte nur gezeichnet werden, wenn der Bildschirm + * aktiv ist. + */ +int video_is_active(void); +/** + * Liefert die PID des Videotreibers zurueck. + */ +pid_t video_get_driver(void); + +/** + * Stellt ein Callback ein, das aufgerufen wird, wenn der virtuelle Bildschirm + * aktiviert wird. In diesem Fall muss das gesamte Bild neu gezeichnet werden. + */ +void video_set_activate_callback(void (*activate)(void)); +/** + * Stellt ein Callback ein, das aufgerufen wird, wenn der virtuelle Bildschirm + * deaktiviert wird. In diesem Fall sollte nicht mehr gezeichnet werden. + */ +void video_set_deactivate_callback(void (*deactivate)(void)); + +#endif + diff --git a/src/modules/lib/video/drawing.c b/src/modules/lib/video/drawing.c new file mode 100644 index 0000000..87a57b1 --- /dev/null +++ b/src/modules/lib/video/drawing.c @@ -0,0 +1,335 @@ +/* + * Copyright (c) 2008 The LOST Project. All rights reserved. + * + * This code is derived from software contributed to the LOST Project + * by Mathias Gottschlag. + * + * 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. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the LOST Project + * and its contributors. + * 4. Neither the name of the LOST Project nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * 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