File: visual.c

package info (click to toggle)
libggi 1%3A2.0.1-2
  • links: PTS
  • area: main
  • in suites: woody
  • size: 6,072 kB
  • ctags: 5,274
  • sloc: ansic: 42,720; sh: 6,508; makefile: 666
file content (157 lines) | stat: -rw-r--r-- 4,415 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
/* $Id: visual.c,v 1.1.1.1 2001/05/12 23:01:37 cegger Exp $
******************************************************************************

   LibGGI - kgicon specific overrides for fbcon
   Initialization

   Copyright (C) 1998-2000 Marcus Sundberg	[marcus@ggi-project.org]

   Permission is hereby granted, free of charge, to any person obtaining a
   copy of this software and associated documentation files (the "Software"),
   to deal in the Software without restriction, including without limitation
   the rights to use, copy, modify, merge, publish, distribute, sublicense,
   and/or sell copies of the Software, and to permit persons to whom the
   Software is furnished to do so, subject to the following conditions:

   The above copyright notice and this permission notice shall be included in
   all copies or substantial portions of the Software.

   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
   IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
   THE AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
   IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
   CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

******************************************************************************
*/

#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <fcntl.h>
#include <ggi/default/genkgi.h>


static int GGIclose(ggi_visual *vis, struct ggi_dlhandle *dlh)
{
	struct genkgi_priv *priv;

	priv = GENKGI_PRIV(vis);

	if (priv->mapped_kgicommand) {
		munmap((void*) priv->mapped_kgicommand,
		       priv->kgicommand_buffersize);
		GGIDPRINT_MISC("gengki: Unmapped kgicommand\n");
	}
	if (priv->fd_kgicommand >= 0) {
		close(priv->fd_kgicommand);
	}

	if (priv->mapped_gc) {
		munmap((void*) priv->mapped_gc, priv->gc_size);
		GGIDPRINT_MISC("gengki: Unmapped GC\n");
	}
	if (priv->close_gc) {
		close(priv->fd_gc);
	}

	free(priv);
	GENKGI_PRIV(vis) = NULL;

	return 0;
}
		

static int GGIopen(ggi_visual *vis, struct ggi_dlhandle *dlh,
		   const char *args, void *argptr, uint32 *dlret)
{
	struct genkgi_priv *priv;
	unsigned long gc_offset = 0;
	char gc[13];
	char kgicommand[21];
	
	sprintf(gc, "/proc/gfx%d/gc", FBDEV_PRIV(vis)->fbnum);
	sprintf(kgicommand, "/proc/gfx%d/kgicommand", FBDEV_PRIV(vis)->fbnum);

	priv = malloc(sizeof(struct genkgi_priv));
	if (priv == NULL) {
		return GGI_ENOMEM;
	}

	priv->mapped_gc = NULL;
	priv->gc_size = getpagesize();
	priv->close_gc = 1;
	priv->mapped_kgicommand = NULL;
	priv->fd_kgicommand = -1;
	/* FIXME: Need to handle this more intelligently */
	priv->kgicommand_buffersize = getpagesize() * 1024;

	GENKGI_PRIV(vis) = priv;

	priv->fd_gc = open(gc, O_RDWR);
	if (priv->fd_gc < 0) {
		priv->fd_gc = LIBGGI_FD(vis);
		priv->close_gc = 0;
		gc_offset = MMAP_TYPE_GC;
	}

	priv->mapped_gc = (ggi_gc *) mmap(NULL, priv->gc_size,
					  PROT_READ | PROT_WRITE,
					  MAP_SHARED, priv->fd_gc,
					  gc_offset);
	if (priv->mapped_gc == MAP_FAILED) {
		GGIclose(vis, dlh);
		return GGI_ENODEVICE;
	}
	GGIDPRINT_MISC("gengki: Mapped GC at %p\n", priv->mapped_gc);
	
	priv->fd_kgicommand = open(kgicommand, O_RDWR);
	if (priv->fd_kgicommand >= 0 &&
	    (priv->mapped_kgicommand = mmap(NULL, priv->kgicommand_buffersize,
					   PROT_READ | PROT_WRITE, MAP_SHARED,
					   priv->fd_kgicommand, 0))
	    != MAP_FAILED) {
		priv->kgicommand_ptr = priv->mapped_kgicommand;
		GGIDPRINT_MISC("gengki: Mapped kgicommand pingpong FIFO at %p\n", 
			       priv->mapped_kgicommand);
	}

	LIBGGI_GC(vis) = priv->mapped_gc;

	priv->drawline = vis->opdraw->drawline;
	priv->drawbox = vis->opdraw->drawbox;
	priv->copybox = vis->opdraw->copybox;
	priv->fillscreen = vis->opdraw->fillscreen;

	vis->opdraw->drawline = GGI_genkgi_drawline;
	vis->opdraw->drawbox = GGI_genkgi_drawbox;
	vis->opdraw->copybox = GGI_genkgi_copybox;
	vis->opdraw->fillscreen = GGI_genkgi_fillscreen;

	*dlret = GGI_DL_OPDRAW;
	return 0;
}


int GGIdl_genkgi(int func, void **funcptr)
{
	switch (func) {
	case GGIFUNC_open:
		*funcptr = GGIopen;
		return 0;
	case GGIFUNC_exit:
		*funcptr = NULL;
		return 0;
	case GGIFUNC_close:
		*funcptr = GGIclose;
		return 0;
	default:
		*funcptr = NULL;
	}

	return GGI_ENOTFOUND;
}

#include <ggi/internal/ggidlinit.h>