[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[tyndur-devel] [PATCH v2] + videolib
Signed-off-by: Alexander Siol <alex@xxxxxxxxxx>
---
src/modules/lib/video/bitmaps.c | 88 ++++++++++++++++++++++++++++++
src/modules/lib/video/context.c | 112 +++++++++++++++++++++++++++++++++++++++
src/modules/lib/video/drawing.c | 103 +++++++++++++++++++++++++++++++++++
src/modules/lib/video/query.c | 63 ++++++++++++++++++++++
src/modules/lib/video/video.c | 67 +++++++++++++++++++++++
5 files changed, 433 insertions(+), 0 deletions(-)
create mode 100644 src/modules/lib/video/bitmaps.c
create mode 100644 src/modules/lib/video/context.c
create mode 100644 src/modules/lib/video/drawing.c
create mode 100644 src/modules/lib/video/query.c
create mode 100644 src/modules/lib/video/video.c
diff --git a/src/modules/lib/video/bitmaps.c b/src/modules/lib/video/bitmaps.c
new file mode 100644
index 0000000..8295a5a
--- /dev/null
+++ b/src/modules/lib/video/bitmaps.c
@@ -0,0 +1,88 @@
+/*
+ * 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 <init.h>
+#include <rpc.h>
+#include <stdlib.h>
+#include <video/commands.h>
+#include <syscall.h>
+#include <string.h>
+
+extern driver_context_t* context;
+
+video_bitmap_t* libvideo_create_bitmap(int width, int height,
+ size_t data_length, void* data)
+{
+ video_bitmap_t *bitmap = calloc(1, sizeof(video_bitmap_t));
+ if (bitmap == NULL) {
+ return NULL;
+ }
+ dword *cmd = calloc(1, 4 * sizeof(dword) + data_length);
+ cmd[0] = VIDEO_CMD_CREATE_BITMAP;
+ cmd[1] = width;
+ cmd[2] = height;
+ cmd[3] = data_length;
+ if (data_length > 0) {
+ memcpy(&cmd[4], data, data_length);
+ }
+ bitmap->id = VIDEORPC_GET_DWORD(4 * sizeof(dword) + data_length,
+ (void*)cmd);
+ if (bitmap->id) {
+ bitmap->width = width;
+ bitmap->height = height;
+ return bitmap;
+ }
+ return NULL;
+}
+
+void libvideo_destroy_bitmap(video_bitmap_t *bitmap)
+{
+ dword cmd[2];
+ cmd[0] = VIDEO_CMD_DESTROY_BITMAP;
+ cmd[1] = bitmap->id;
+ free(bitmap);
+ VIDEORPC_GET_DWORD(sizeof(cmd), (void*)cmd);
+}
+
+video_bitmap_t* libvideo_get_frontbuffer_bitmap(int display)
+{
+ dword cmd[2];
+ cmd[0] = VIDEO_CMD_CREATE_FRONTBUFFER_BITMAP;
+ cmd[1] = display;
+ dword bitmapid = VIDEORPC_GET_DWORD(sizeof(cmd), (void*)cmd);
+ if (bitmapid) {
+ video_bitmap_t *bitmap = calloc(1, sizeof(video_bitmap_t));
+ if (bitmap) {
+ bitmap->id = bitmapid;
+ // FIXME: Breite und Höhe müssten irgendwie gesetzt werden.
+ return bitmap;
+ }
+ }
+ return NULL;
+}
diff --git a/src/modules/lib/video/context.c b/src/modules/lib/video/context.c
new file mode 100644
index 0000000..22735df
--- /dev/null
+++ b/src/modules/lib/video/context.c
@@ -0,0 +1,112 @@
+/*
+ * 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 <init.h>
+#include <rpc.h>
+#include <stdlib.h>
+#include <video/commands.h>
+#include <syscall.h>
+
+extern driver_context_t* context;
+
+int libvideo_change_device(int devicenum)
+{
+ REQUIRE_CMD_BUFFER(2);
+ SET_CMD_BUFFER(VIDEO_CMD_USE_DEVICE);
+ SET_CMD_BUFFER(devicenum);
+ return 0;
+}
+
+int libvideo_change_target(video_bitmap_t *bitmap)
+{
+ REQUIRE_CMD_BUFFER(2);
+ SET_CMD_BUFFER(VIDEO_CMD_USE_TARGET);
+ SET_CMD_BUFFER(bitmap->id);
+ return 0;
+}
+
+int libvideo_change_color(char alpha, char red, char green, char blue)
+{
+ REQUIRE_CMD_BUFFER(2);
+ char color[4];
+ color[0] = alpha;
+ color[1] = red;
+ color[2] = green;
+ color[3] = blue;
+ SET_CMD_BUFFER(VIDEO_CMD_USE_COLOR);
+ SET_CMD_BUFFER(*(dword*)color);
+ return 0;
+}
+
+int libvideo_change_rop(rop_t rop)
+{
+ REQUIRE_CMD_BUFFER(2);
+ SET_CMD_BUFFER(VIDEO_CMD_USE_ROP);
+ SET_CMD_BUFFER(rop);
+ return 0;
+}
+
+int libvideo_get_command_buffer(size_t length)
+{
+ if (context->cmdbufferid) {
+ libvideo_do_command_buffer();
+ close_shared_memory(context->cmdbufferid);
+ context->cmdbuffer = NULL;
+ }
+ dword cmd[2];
+ cmd[0] = VIDEO_CMD_GET_CMD_BUFFER;
+ cmd[1] = length;
+ dword id = VIDEORPC_GET_DWORD(sizeof(cmd), (void*)cmd);
+ if (id != -1) {
+ context->cmdbufferid = id;
+ context->cmdbuffer = open_shared_memory(id);
+ // BufferLen in DWords
+ context->cmdbufferlen = length / sizeof(dword);
+ context->cmdbufferpos = 0;
+ return 0;
+ } else {
+ context->cmdbufferid = 0;
+ context->cmdbuffer = NULL;
+ context->cmdbufferlen = 0;
+ context->cmdbufferpos = 0;
+ return -1;
+ }
+}
+
+int libvideo_do_command_buffer()
+{
+ dword cmd[2];
+ cmd[0] = VIDEO_CMD_DO_CMD_BUFFER;
+ cmd[1] = context->cmdbufferpos * 4;
+ int result = VIDEORPC_GET_DWORD(sizeof(cmd), (void*)cmd);
+ if (result == 0) {
+ context->cmdbufferpos = 0;
+ }
+ return result;
+}
diff --git a/src/modules/lib/video/drawing.c b/src/modules/lib/video/drawing.c
new file mode 100644
index 0000000..1260de4
--- /dev/null
+++ b/src/modules/lib/video/drawing.c
@@ -0,0 +1,103 @@
+/*
+ * 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 <init.h>
+#include <rpc.h>
+#include <stdlib.h>
+#include <video/commands.h>
+#include <syscall.h>
+
+extern driver_context_t* context;
+
+void libvideo_draw_pixel(int x, int y)
+{
+ if (context->cmdbufferpos + 3 >= context->cmdbufferlen)
+ libvideo_do_command_buffer();
+ SET_CMD_BUFFER(VIDEO_CMD_DRAW_PIXEL);
+ SET_CMD_BUFFER(x);
+ SET_CMD_BUFFER(y);
+}
+
+void libvideo_draw_rectangle(int x, int y, int width, int height)
+{
+ if (context->cmdbufferpos + 5 >= context->cmdbufferlen)
+ libvideo_do_command_buffer();
+ SET_CMD_BUFFER(VIDEO_CMD_DRAW_RECTANGLE);
+ SET_CMD_BUFFER(x);
+ SET_CMD_BUFFER(y);
+ SET_CMD_BUFFER(width);
+ SET_CMD_BUFFER(height);
+}
+
+void libvideo_draw_ellipse(int x, int y, int width, int height)
+{
+ if (context->cmdbufferpos + 5 >= context->cmdbufferlen)
+ libvideo_do_command_buffer();
+ SET_CMD_BUFFER(VIDEO_CMD_DRAW_ELLIPSE);
+ SET_CMD_BUFFER(x);
+ SET_CMD_BUFFER(y);
+ SET_CMD_BUFFER(width);
+ SET_CMD_BUFFER(height);
+}
+
+void libvideo_draw_line(int x1, int y1, int x2, int y2)
+{
+ if (context->cmdbufferpos + 5 >= context->cmdbufferlen)
+ libvideo_do_command_buffer();
+ SET_CMD_BUFFER(VIDEO_CMD_DRAW_LINE);
+ SET_CMD_BUFFER(x1);
+ SET_CMD_BUFFER(y1);
+ SET_CMD_BUFFER(x2);
+ SET_CMD_BUFFER(y2);
+}
+
+void libvideo_draw_bitmap(video_bitmap_t *bitmap, int x, int y)
+{
+ if (context->cmdbufferpos + 4 >= context->cmdbufferlen)
+ libvideo_do_command_buffer();
+ SET_CMD_BUFFER(VIDEO_CMD_DRAW_BITMAP);
+ SET_CMD_BUFFER(x);
+ SET_CMD_BUFFER(y);
+ SET_CMD_BUFFER(bitmap->id);
+}
+
+void libvideo_draw_bitmap_part(video_bitmap_t *bitmap, int x, int y, int srcx,
+ int srcy, int width, int height)
+{
+ if (context->cmdbufferpos + 8 >= context->cmdbufferlen)
+ libvideo_do_command_buffer();
+ SET_CMD_BUFFER(VIDEO_CMD_DRAW_BITMAP_PART);
+ SET_CMD_BUFFER(x);
+ SET_CMD_BUFFER(y);
+ SET_CMD_BUFFER(bitmap->id);
+ SET_CMD_BUFFER(srcx);
+ SET_CMD_BUFFER(srcy);
+ SET_CMD_BUFFER(width);
+ SET_CMD_BUFFER(height);
+}
diff --git a/src/modules/lib/video/query.c b/src/modules/lib/video/query.c
new file mode 100644
index 0000000..4bf9e1b
--- /dev/null
+++ b/src/modules/lib/video/query.c
@@ -0,0 +1,63 @@
+/*
+ * 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 <init.h>
+#include <rpc.h>
+#include <stdlib.h>
+#include <video/commands.h>
+#include <syscall.h>
+
+extern driver_context_t* context;
+
+int libvideo_get_num_devices(void)
+{
+ dword cmd[1];
+ cmd[0] = VIDEO_CMD_GET_NUM_DEVICES;
+ return VIDEORPC_GET_DWORD(sizeof(cmd), (void*)cmd);
+}
+
+int libvideo_get_num_displays(int device)
+{
+ dword cmd[2];
+ cmd[0] = VIDEO_CMD_GET_NUM_DISPLAYS;
+ cmd[1] = device;
+ return VIDEORPC_GET_DWORD(sizeof(cmd), (void*)cmd);
+}
+
+dword* libvideo_get_modes(int device, int display)
+{
+ dword cmd[3];
+ cmd[0] = VIDEO_CMD_GET_DISPLAY_MODES;
+ cmd[1] = device;
+ cmd[2] = display;
+ response_t *resp;
+ resp = rpc_get_response(context->driverpid, "VIDEODRV", sizeof(cmd),
+ (void*)cmd);
+ return resp->data;
+}
diff --git a/src/modules/lib/video/video.c b/src/modules/lib/video/video.c
new file mode 100644
index 0000000..952e619
--- /dev/null
+++ b/src/modules/lib/video/video.c
@@ -0,0 +1,67 @@
+/*
+ * 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 <init.h>
+#include <rpc.h>
+#include <stdlib.h>
+#include <video/commands.h>
+
+driver_context_t* context;
+
+driver_context_t* libvideo_create_driver_context(char* driver)
+{
+ driver_context_t* newcontext = calloc(1, sizeof(driver_context_t));
+ newcontext->driverpid = init_service_get(driver);
+ dword cmd[2];
+ cmd[0] = VIDEO_CMD_CREATE_CONTEXT;
+ newcontext->drivercontext = rpc_get_dword(newcontext->driverpid, "VIDEODRV",
+ sizeof(dword), (void*)cmd);
+ cmd[0] = VIDEO_CMD_USE_CONTEXT;
+ cmd[1] = newcontext->drivercontext;
+ rpc_get_dword(newcontext->driverpid, "VIDEODRV", sizeof(cmd), (void*)cmd);
+ return newcontext;
+}
+
+inline void libvideo_use_driver_context(driver_context_t* newcontext)
+{
+ context = newcontext;
+}
+
+int libvideo_change_display_resolution(int display, int width, int height,
+ int depth)
+{
+ dword cmd[6];
+ cmd[0] = VIDEO_CMD_SET_RESOLUTION;
+ cmd[1] = display;
+ cmd[2] = width;
+ cmd[3] = height;
+ cmd[4] = depth;
+ cmd[5] = 0;
+ return rpc_get_dword(context->driverpid, "VIDEODRV", sizeof(cmd), (void*)cmd);
+}
--
1.6.0.4