]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/dope/server/common/gfx_yuv420.c
Inital import
[l4.git] / l4 / pkg / dope / server / common / gfx_yuv420.c
1 /*
2  * \brief   DOpE gfx YUV420 image handler module
3  * \date    2003-05-20
4  * \author  Norman Feske <nf2@inf.tu-dresden.de>
5  */
6
7 /*
8  * Copyright (C) 2002-2004  Norman Feske  <nf2@os.inf.tu-dresden.de>
9  * Technische Universitaet Dresden, Operating Systems Research Group
10  *
11  * This file is part of the DOpE package, which is distributed under
12  * the  terms  of the  GNU General Public Licence 2.  Please see the
13  * COPYING file for details.
14  */
15
16 #include "dopestd.h"
17 #include "sharedmem.h"
18 #include "gfx_handler.h"
19 #include "gfx.h"
20
21 static struct sharedmem_services *shmem;
22
23 struct gfx_ds_data {
24         s32 w,h;            /* width and height of the image */
25         SHAREDMEM *smb;     /* shared memory block */
26         u8 *pixels;         /* YUV420 data color values of the pixels */
27 };
28
29 int init_gfximgyuv420(struct dope_services *d);
30
31 /*****************************
32  *** GFX HANDLER FUNCTIONS ***
33  *****************************/
34
35 static s32 img_get_width(struct gfx_ds_data *img) {
36         return img->w;
37 }
38
39 static s32 img_get_height(struct gfx_ds_data *img) {
40         return img->h;
41 }
42
43 static s32 img_get_type(struct gfx_ds_data *img) {
44   (void)img;
45         return GFX_IMG_TYPE_YUV420;
46 }
47
48 static void img_destroy(struct gfx_ds_data *img) {
49         free(img);
50 }
51
52 static void *img_map(struct gfx_ds_data *img) {
53         return img->pixels;
54 }
55
56 static s32 img_share(struct gfx_ds_data *img, THREAD *dst_thread) {
57         return shmem->share(img->smb, dst_thread);
58 }
59
60 static s32 img_get_ident(struct gfx_ds_data *img, char *dst_ident) {
61         shmem->get_ident(img->smb, dst_ident);
62         return 0;
63 }
64
65 /*************************
66  *** SERVICE FUNCTIONS ***
67  *************************/
68
69
70 static struct gfx_ds_data *create(s32 width, s32 height, struct gfx_ds_handler **handler) {
71   (void)handler;
72         struct gfx_ds_data *new;
73         new = zalloc(sizeof(struct gfx_ds_data));
74         if (!new) return NULL;
75         new->w = width;
76         new->h = height;
77         new->smb = shmem->alloc(width*height + (width*height/2));
78         new->pixels = (u8 *)(shmem->get_address(new->smb));
79         return new;
80 }
81
82 static s32 register_gfx_handler(struct gfx_ds_handler *handler) {
83         handler->get_width  = img_get_width;
84         handler->get_height = img_get_height;
85         handler->get_type   = img_get_type;
86         handler->destroy    = img_destroy;
87         handler->map        = img_map;
88         handler->share      = img_share;
89         handler->get_ident  = img_get_ident;
90         return 0;
91 }
92
93
94 /****************************************
95  *** SERVICE STRUCTURE OF THIS MODULE ***
96  ****************************************/
97
98 static struct gfx_handler_services services = {
99         create,
100         register_gfx_handler,
101 };
102
103
104 /**************************
105  *** MODULE ENTRY POINT ***
106  **************************/
107
108 int init_gfximgyuv420(struct dope_services *d) {
109         shmem = d->get_module("SharedMemory 1.0");
110         d->register_module("GfxImageYUV420 1.0",&services);
111         return 1;
112 }