[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Lost] [PATCH] [2/5] + Videolibrary fuer Anzeigen von Grafik in Programmen
Und die entsprechende Library, mit der Programme Grafik anzeigen können.
Basiert noch auf n paar unschönen Hacks in vterm und hat atm keine
Möglichkeit, dass ein Programm iwie an Input kommt.
Mathias
From 3e7b60d37dac1be5e5b195126c3244b2418c01f6 Mon Sep 17 00:00:00 2001
From: Mathias Gottschlag <mathias-go@xxxxxx>
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 <video/drawing.h>
+#include <video/video.h>
+#include <video/commands.h>
+#include <rpc.h>
+#include <stdio.h>
+
+extern dword cmdbufferid;
+extern char *cmdbuffer;
+unsigned int cmdbufferlength = 0;
+static int vscreen = 0;
+static pid_t driverpid = 0;
+
+// TODO: Variable Buffergroesse
+
+/**
+ * Startet einen Videokommandostream. Kommandos werden gebuffert per Shared
+ * Memory uebertragen.
+ */
+void video_start_command(void)
+{
+ if (!cmdbuffer) return;
+ cmdbufferlength = 0;
+ vscreen = video_get_vscreen();
+ driverpid = video_get_driver();
+}
+/**
+ * Beendet einen Videokommandostream und sendet ihn an den Treiber.
+ */
+void video_end_command(void)
+{
+ if (!cmdbuffer || !cmdbufferlength) return;
+
+ // Send buffer to driver
+ int command[5];
+ command[0] = 0;
+ command[1] = VIDEO_COMMAND_STREAM;
+ command[2] = vscreen;
+ command[3] = 0; // First screen, TODO
+ command[4] = cmdbufferlength;
+ rpc_get_dword(driverpid,
+ "VIDEODRV",
+ sizeof(int) * 5,
+ (char*)command);
+ cmdbufferlength = 0;
+}
+
+/**
+ * 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)
+{
+ if (!cmdbuffer) return;
+ if (cmdbufferlength >= 64 * 1024 - 2) video_end_command();
+ cmdbuffer[cmdbufferlength] = VIDEO_CMD_SET_ROP;
+ cmdbuffer[cmdbufferlength + 1] = rop;
+ cmdbufferlength += 2;
+}
+
+/**
+ * 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)
+{
+ if (!cmdbuffer) return;
+ if (cmdbufferlength >= 64 * 1024 - 5) video_end_command();
+ cmdbuffer[cmdbufferlength] = VIDEO_CMD_SET_TARGET;
+ *((unsigned int*)&cmdbuffer[cmdbufferlength + 1]) = bitmap;
+ cmdbufferlength += 5;
+}
+
+/**
+ * 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)
+{
+ if (!cmdbuffer) return;
+ if (cmdbufferlength >= 64 * 1024 - 8) video_end_command();
+ cmdbuffer[cmdbufferlength] = VIDEO_CMD_DRAW_DOT;
+ *((unsigned int*)&cmdbuffer[cmdbufferlength + 1]) = color;
+ *((unsigned short*)&cmdbuffer[cmdbufferlength + 4]) = x;
+ *((unsigned short*)&cmdbuffer[cmdbufferlength + 6]) = y;
+ cmdbufferlength += 8;
+}
+
+/**
+ * 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)
+{
+ if (!cmdbuffer) return;
+ if (cmdbufferlength >= 64 * 1024 - 12) video_end_command();
+ cmdbuffer[cmdbufferlength] = VIDEO_CMD_DRAW_RECT;
+ *((unsigned int*)&cmdbuffer[cmdbufferlength + 1]) = color;
+ *((unsigned short*)&cmdbuffer[cmdbufferlength + 4]) = x;
+ *((unsigned short*)&cmdbuffer[cmdbufferlength + 6]) = y;
+ *((unsigned short*)&cmdbuffer[cmdbufferlength + 8]) = width;
+ *((unsigned short*)&cmdbuffer[cmdbufferlength + 10]) = height;
+ cmdbufferlength += 12;
+}
+/**
+ * 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)
+{
+ if (!cmdbuffer) return;
+ if (cmdbufferlength >= 64 * 1024 - 12) video_end_command();
+ cmdbuffer[cmdbufferlength] = VIDEO_CMD_DRAW_LINE;
+ *((unsigned int*)&cmdbuffer[cmdbufferlength + 1]) = color;
+ *((unsigned short*)&cmdbuffer[cmdbufferlength + 4]) = x1;
+ *((unsigned short*)&cmdbuffer[cmdbufferlength + 6]) = y1;
+ *((unsigned short*)&cmdbuffer[cmdbufferlength + 8]) = x2;
+ *((unsigned short*)&cmdbuffer[cmdbufferlength + 10]) = y2;
+ cmdbufferlength += 12;
+}
+/**
+ * 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)
+{
+ if (!cmdbuffer) return;
+ if (cmdbufferlength >= 64 * 1024 - 12) video_end_command();
+ cmdbuffer[cmdbufferlength] = VIDEO_CMD_DRAW_ELLIPSE;
+ *((unsigned int*)&cmdbuffer[cmdbufferlength + 1]) = color;
+ *((unsigned short*)&cmdbuffer[cmdbufferlength + 4]) = x;
+ *((unsigned short*)&cmdbuffer[cmdbufferlength + 6]) = y;
+ *((unsigned short*)&cmdbuffer[cmdbufferlength + 8]) = width;
+ *((unsigned short*)&cmdbuffer[cmdbufferlength + 10]) = height;
+ cmdbufferlength += 12;
+}
+
+/**
+ * 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)
+{
+ if (!cmdbuffer) return;
+ if (cmdbufferlength >= 64 * 1024 - 9) video_end_command();
+ cmdbuffer[cmdbufferlength] = VIDEO_CMD_DRAW_BITMAP;
+ *((unsigned int*)&cmdbuffer[cmdbufferlength + 1]) = bitmap;
+ *((unsigned short*)&cmdbuffer[cmdbufferlength + 5]) = x;
+ *((unsigned short*)&cmdbuffer[cmdbufferlength + 7]) = y;
+ cmdbufferlength += 9;
+}
+/**
+ * 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)
+{
+ if (!cmdbuffer) return;
+ if (cmdbufferlength >= 64 * 1024 - 17) video_end_command();
+ cmdbuffer[cmdbufferlength] = VIDEO_CMD_DRAW_BITMAP_PART;
+ *((unsigned int*)&cmdbuffer[cmdbufferlength + 1]) = bitmap;
+ *((unsigned short*)&cmdbuffer[cmdbufferlength + 5]) = x;
+ *((unsigned short*)&cmdbuffer[cmdbufferlength + 7]) = y;
+ *((unsigned short*)&cmdbuffer[cmdbufferlength + 9]) = srcx;
+ *((unsigned short*)&cmdbuffer[cmdbufferlength + 11]) = srcy;
+ *((unsigned short*)&cmdbuffer[cmdbufferlength + 13]) = srcwidth;
+ *((unsigned short*)&cmdbuffer[cmdbufferlength + 15]) = srcwidth;
+ cmdbufferlength += 17;
+}
+
+/**
+ * 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)
+{
+ if (!cmdbuffer) return;
+ if (cmdbufferlength >= 64 * 1024 - 13) video_end_command();
+ cmdbuffer[cmdbufferlength] = VIDEO_CMD_COPY_SCREEN;
+ *((unsigned short*)&cmdbuffer[cmdbufferlength + 1]) = x;
+ *((unsigned short*)&cmdbuffer[cmdbufferlength + 3]) = y;
+ *((unsigned short*)&cmdbuffer[cmdbufferlength + 5]) = srcx;
+ *((unsigned short*)&cmdbuffer[cmdbufferlength + 7]) = srcy;
+ *((unsigned short*)&cmdbuffer[cmdbufferlength + 9]) = srcwidth;
+ *((unsigned short*)&cmdbuffer[cmdbufferlength + 11]) = srcwidth;
+ cmdbufferlength += 13;
+}
+
+/**
+ * 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)
+{
+ vscreen = video_get_vscreen();
+ driverpid = video_get_driver();
+ int datalength = width * height;
+ if (format == BITMAP_FORMAT_MONO_1) datalength /= 8;
+ if (format == BITMAP_FORMAT_R8G8B8_24) datalength *= 3;
+ if (format == BITMAP_FORMAT_B8G8R8_24) datalength *= 3;
+ if (format == BITMAP_FORMAT_R8G8B8_32) datalength *= 4;
+ if (format == BITMAP_FORMAT_B8G8R8_32) datalength *= 4;
+ if (format == BITMAP_FORMAT_R5G6B5_16) datalength *= 2;
+ if (format == BITMAP_FORMAT_B5G6R5_16) datalength *= 2;
+ if (format == BITMAP_FORMAT_R5G5B5_16) datalength *= 2;
+ if (format == BITMAP_FORMAT_B5G5R5_16) datalength *= 2;
+ if (!data) datalength = 0;
+ // Send bitmap to driver
+ char command[7 * sizeof(int) + datalength];
+ ((dword*)command)[0] = 0;
+ ((dword*)command)[1] = VIDEO_UPLOAD_BITMAP;
+ ((dword*)command)[2] = vscreen;
+ ((dword*)command)[3] = width;
+ ((dword*)command)[4] = height;
+ ((dword*)command)[5] = format;
+ ((dword*)command)[6] = datalength;
+ memcpy(command + 7 * 4, data, datalength);
+ return rpc_get_dword(driverpid,
+ "VIDEODRV",
+ 7 * sizeof(int) + datalength,
+ (char*)command);
+ return 0;
+}
+/**
+ * Loescht das Bitmap mit der angegebenen ID
+ * @param bitmap Zu loeschendes Bitmap
+ */
+void video_delete_bitmap(int bitmap)
+{
+ vscreen = video_get_vscreen();
+ driverpid = video_get_driver();
+ int command[4];
+ command[0] = 0;
+ command[1] = VIDEO_DESTROY_BITMAP;
+ command[2] = vscreen;
+ command[3] = bitmap;
+ rpc_get_dword(driverpid,
+ "VIDEODRV",
+ sizeof(int) * 4,
+ (char*)command);
+}
+/**
+ * Loescht alle Bitmaps, die zuvor via video_upload_bitmap in den Videotreiber
+ * geladen wurden
+ */
+void video_delete_all_bitmaps(void)
+{
+ vscreen = video_get_vscreen();
+ driverpid = video_get_driver();
+ int command[3];
+ command[0] = 0;
+ command[1] = VIDEO_DESTROY_ALL_BITMAPS;
+ command[2] = vscreen;
+ rpc_get_dword(driverpid,
+ "VIDEODRV",
+ sizeof(int) * 3,
+ (char*)command);
+}
+
diff --git a/src/modules/lib/video/video.c b/src/modules/lib/video/video.c
new file mode 100644
index 0000000..4cfa119
--- /dev/null
+++ b/src/modules/lib/video/video.c
@@ -0,0 +1,259 @@
+/*
+ * 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 <video/video.h>
+#include <video/commands.h>
+
+#include <stdio.h>
+#include <rpc.h>
+#include <init.h>
+#include <syscall.h>
+
+static FILE *ctrlfile = 0;
+static int vscreen = 0;
+static int isactive = 0;
+
+// TODO: Das hier muss wechselbar sein
+static char *driver = "cirrus";
+static pid_t driverpid = 0;
+
+dword cmdbufferid = 0;
+char *cmdbuffer = 0;
+
+// Callbacks
+static void (*activatecb)(void) = 0;
+static void (*deactivatecb)(void) = 0;
+
+void rpc_video_interface(pid_t pid,
+ dword correlation_id,
+ size_t data_size,
+ void* data);
+
+
+/**
+ * Initialisiert die Grafik: Stellt die Verbindung zu einem Grafiktreiber her
+ * und erstellt einen virtuellen Bildschirm
+ */
+int video_init(void)
+{
+ register_message_handler("VIDEOLIB", rpc_video_interface);
+
+ // Virtuelles Terminal erzeugen
+ pid_t vterm = init_service_get("vterm");
+ int result = rpc_get_dword(vterm,
+ "GFXVTERM",
+ 0,
+ 0);
+ if (result == -1) {
+ printf("[ libvideo ] Konnte kein virtuelles Terminal erzeugen.\n");
+ return 0;
+ }
+ // Video-Datei oeffnen
+ char vtermpath[30];
+ snprintf(vtermpath, 30, "vterm:/vterm%d/video", result);
+ ctrlfile = fopen(vtermpath, "r");
+ if (!ctrlfile) {
+ printf("[ libvideo ] Konnte virtuelles Terminal nicht oeffnen.\n");
+ return 0;
+ }
+ vscreen = result;
+
+ driverpid = init_service_get(driver);
+ if (!driverpid) {
+ printf("[ libvideo ] Treiber nicht gefunden.\n");
+ video_close();
+ return 0;
+ }
+
+ // Get buffer used for drawing
+ int command[3];
+ command[0] = 0;
+ command[1] = VIDEO_GET_COMMAND_BUFFER;
+ command[2] = vscreen;
+ cmdbufferid = rpc_get_dword(driverpid,
+ "VIDEODRV",
+ sizeof(int) * 3,
+ (char*)command);
+
+ if (!cmdbufferid) {
+ printf("[ libvideo ] Kein Zeichenbuffer erhalten!\n");
+ video_close();
+ return 0;
+ }
+ cmdbuffer = open_shared_memory(cmdbufferid);
+ printf("[ libvideo ] Buffer: %p\n", cmdbuffer);
+
+ return 1;
+}
+// Interne Funktion nur fuer vterm selbst
+void video_init_vterm(pid_t driver)
+{
+ register_message_handler("VIDEOLIB", rpc_video_interface);
+
+ driverpid = driver;
+
+ // Get buffer used for drawing
+ int command[3];
+ command[0] = 0;
+ command[1] = VIDEO_GET_COMMAND_BUFFER;
+ command[2] = vscreen;
+ cmdbufferid = rpc_get_dword(driverpid,
+ "VIDEODRV",
+ sizeof(int) * 3,
+ (char*)command);
+}
+/**
+ * Schliesst den virtuellen Bildschirm und Beendet Verbindung zum Grafiktreiber
+ */
+void video_close(void)
+{
+ if (cmdbufferid) {
+ close_shared_memory(cmdbufferid);
+ cmdbufferid = 0;
+ }
+ fclose(ctrlfile);
+ ctrlfile = 0;
+}
+
+/**
+ * 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)
+{
+ int command[8];
+ command[0] = 0;
+ command[1] = VIDEO_SET_RESOLUTION;
+ command[2] = vscreen;
+ command[3] = 0;
+ command[4] = width;
+ command[5] = height;
+ command[6] = bpp;
+ command[7] = 0;
+ return rpc_get_dword(driverpid,
+ "VIDEODRV",
+ sizeof(int) * 8,
+ (char*)command);
+}
+/**
+ * Liefert die derzeitige Aufloesung zurueck
+ */
+resolution_t video_get_resolution(void)
+{
+ resolution_t res;
+ memset(&res, 0, sizeof(res));
+ return res;
+}
+/**
+ * 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)
+{
+ resolution_list_t res;
+ memset(&res, 0, sizeof(res));
+ return res;
+}
+
+/**
+ * Liefert den Index des virtuellen Bildschirms zurueck
+ */
+int video_get_vscreen(void)
+{
+ return vscreen;
+}
+/**
+ * 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)
+{
+ return isactive;
+}
+/**
+ * Liefert die PID des Videotreibers zurueck.
+ */
+pid_t video_get_driver(void)
+{
+ return driverpid;
+}
+
+/**
+ * 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))
+{
+ activatecb = activate;
+}
+/**
+ * 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))
+{
+ deactivatecb = deactivate;
+}
+
+void rpc_video_interface(pid_t pid,
+ dword correlation_id,
+ size_t data_size,
+ void* data)
+{
+ // Befehlsinformation auslesen
+ int *command = data;
+ if (data_size < sizeof(int)) {
+ rpc_send_dword_response(pid, correlation_id, 0);
+ return;
+ }
+
+ // Befehl ausführen
+ switch (command[0]) {
+ case VIDEO_CLIENT_DEACTIVATE:
+ isactive = 0;
+ if (deactivatecb) deactivatecb();
+ break;
+ case VIDEO_CLIENT_ACTIVATE:
+ // Neuen Framebuffer allokieren
+ isactive = 1;
+ if (activatecb) activatecb();
+ break;
+ }
+ rpc_send_dword_response(pid, correlation_id, 1);
+}
+
--
1.5.4.3