File: funcs.c

package info (click to toggle)
libggimisc 2.2.2-1
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 2,344 kB
  • ctags: 270
  • sloc: sh: 9,172; ansic: 1,014; makefile: 170
file content (227 lines) | stat: -rw-r--r-- 7,439 bytes parent folder | download | duplicates (3)
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
/* $Id: funcs.c,v 1.8 2005/07/30 12:48:49 cegger Exp $
******************************************************************************

   LibGgiMisc implementation for "fbdev" target -- API functions.

   
  
   Copyright (c) Fri Mar  2 2001 by: 
	Brian S. Julin		bri@calyx.com

  
   
   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 above copyright notice applies to all files in this package, unless 
   explicitly stated otherwise in the file itself or in a file named COPYING 
   in the same directory as the file.

   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 <ggi/display/fbdev.h>
#include "fbdevggimisc.h"

#include <string.h>

/* _All_ non-local (ie not declared 'static') functions and variables _must_
   be prefixed with the extension name, and for sublibs also with a unique
   sublib identifier. This is to keep the namespace clean on systems where
   all symbols are exported by default.
*/

/*-* API Implementation */


int GGIMISC_Fbdev_GetRayPos(ggi_visual * vis, int32_t * x, int32_t * y)
{
	int res;
	struct fb_vblank raypos;
	struct fb_var_screeninfo *s;

	/* This interface is not well defined.  Our best bet
	   is to take anything that says it is both capable
	   of being present, and is present, at face value. 

	   Neither is the GGIMisc interface well defined.
	   What to do when a valid count is available and there
	   is a sync or blank is not established.

	   The interworking between the interfaces is even 
	   worse -- GGI shields the user from knowing about
	   scandoubling/pixeldoubling.  Luckily we have 
	   the fbcon fix info.  Unluckily we don't know 
	   for sure how the counter relates to the fix info,
	   since that could be card dependent.

	   Though it would probably be safe to return both
	   the bit-shifted flags | the counts, due to 
	   screen dimensions not being quite 2^31 large,
	   I would say best bet is to define the flags as so:
	   #define GGI_RP_BORDER   0x7ffffffe
	   #define GGI_RP_BLANK    0x7ffffffd
	   #define GGI_RP_SYNC     0x7ffffffb
	   #define GGI_RP_DONTCARE 0x7ffffff7

	   These are relatively impossible for a counter to 
	   hit, and they leave negative numbers for us to 
	   use when a counter is available -- such that 
	   we put 0/0 at the screen origin.  You either
	   get flags _or_ numbers depending on what you pass
	   in -- some additional flags supplied for requesting:
	   GGI_RP_FLAGSONLY, GGI_RP_PIXELS_ADJUSTED, GGI_RP_PIXELS_RAW
	   GGI_RP_DOTS_ADJUSTED, GGI_RP_DOTS_RAW
	   GGI_RP_RAW_ADJUSTED, GGI_RP_RAW

	   On the fbdev side, the expension field in fb_vblank
	   are there by my plea, and hopefully will someday be used 
	   in the future to specify just what is being returned in 
	   the count variables.

	   Comments?

	   For now, if a count is there in either dimension,
	   it is used and Or'd with the flags, if they are present.
	   The fixinfo/count stuff is not done, as the only fbdev
	   device that has this does provide a vcount, so
	   the code would not be reached.

	 */
	*y = 0;
	*x = 0;
	if ((res = ioctl(LIBGGI_FD(vis), FBIOGET_VBLANK, &raypos)))
		return (res);
	if (!raypos.flags)
		return (GGI_ENOFUNC);	/* Got functionality? */
	if ((raypos.flags & FB_VBLANK_HAVE_VBLANK)
	    && (raypos.flags & FB_VBLANK_VBLANKING))
		*y |= GGI_RP_BLANK;
	if ((raypos.flags & FB_VBLANK_HAVE_VSYNC)
	    && (raypos.flags & FB_VBLANK_VSYNCING))
		*y |= GGI_RP_SYNC;
	if ((raypos.flags & FB_VBLANK_HAVE_VCOUNT) && raypos.vcount)
		*y = raypos.vcount & 0x7fffffff;
	if ((raypos.flags & FB_VBLANK_HAVE_HBLANK)
	    && (raypos.flags & FB_VBLANK_HBLANKING))
		*x |= GGI_RP_BLANK;
	if ((raypos.flags & FB_VBLANK_HAVE_HCOUNT) && raypos.hcount)
		*x = raypos.hcount & 0x7fffffff;
	if (*x | *y)
		return 0;
	if (!((raypos.flags & FB_VBLANK_HAVE_COUNT) && raypos.count))
		return (0);

	/* Now it gets ugly. */
	/* Punt!
	   We're going to assume that counter is in pixels from
	   the origin for now.
	 */
	s = &(FBDEV_PRIV(vis)->var);
	if (s->xres == 0)
		return (0);
	*y = raypos.count / s->xres;
	*x = raypos.count - *y * s->xres;
	return (0);
}


int GGIMISC_Fbdev_WaitRayPos(ggi_visual * vis, int32_t * x, int32_t * y)
{
	struct fb_vblank raypos;
	uint32_t flags = 0;
	int res;

	/* This implementation is just wrong.  Needs a lot of work 
	   and clearer API definition. */
	if (*x == GGI_RP_DONTCARE && *y == GGI_RP_DONTCARE)
		return (0);
	if ((res = ioctl(LIBGGI_FD(vis), FBIOGET_VBLANK, &raypos)))
		return (res);
	if (!raypos.flags)
		return (GGI_ENOFUNC);	/* Got functionality? */
	if (*x & GGI_RP_BLANK)
		flags |= FB_VBLANK_HAVE_HBLANK;
	if (*y & GGI_RP_BLANK)
		flags |= FB_VBLANK_HAVE_VBLANK;
	if (*y & GGI_RP_SYNC)
		flags |= FB_VBLANK_HAVE_VSYNC;
	if ((flags & raypos.flags) != flags) {
		*x = 0;
		*y = 0;		/* This tells user to try using numbers instead */
		return (GGI_ENOFUNC);
	}
	if (flags) {
		flags = 0;
		if (*x & GGI_RP_BLANK)
			flags |= FB_VBLANK_HBLANKING;
		if (*y & GGI_RP_BLANK)
			flags |= FB_VBLANK_VBLANKING;
		if (*y & GGI_RP_SYNC)
			flags |= FB_VBLANK_VSYNCING;
		/* Yeah, we busy poll.  
		   Weren't expecting something fancy, were you? */
		while (1) {
			res =
			    ioctl(LIBGGI_FD(vis), FBIOGET_VBLANK, &raypos);
			if (res)
				return (GGI_EUNKNOWN);
			if ((flags & raypos.flags) == flags)
				return (0);
		}
	}
	/* I may have hacked getraypos, but this could cause a hang,
	   so we won't do FB_VBLANK_HAVE_COUNT this time. */
	if ((*x != GGI_RP_DONTCARE)
	    && !(raypos.flags & FB_VBLANK_HAVE_HCOUNT))
		return (GGI_ENOFUNC);
	if ((*y != GGI_RP_DONTCARE)
	    && !(raypos.flags & FB_VBLANK_HAVE_VCOUNT))
		return (GGI_ENOFUNC);
	while (1) {
		res = ioctl(LIBGGI_FD(vis), FBIOGET_VBLANK, &raypos);
		if (res)
			return (GGI_EUNKNOWN);
		if (((*x == GGI_RP_DONTCARE) || (*x < (signed)raypos.hcount)) &&
		    ((*y == GGI_RP_DONTCARE) || (*y < (signed)raypos.vcount)))
			return (0);
	}
}


/* Expecting this to work?  Read the source... the only
   fb driver that seems to really do it now is amifb. */
int GGIMISC_Fbdev_SetSplitline(ggi_visual * vis, int y)
{
	int res;
	struct fb_var_screeninfo var;
	if (FBDEV_PRIV(vis)->orig_fix.ypanstep == 0)
		return (GGI_ENOFUNC);
#warning threadsafe?
	memcpy(&var, &(FBDEV_PRIV(vis)->var), sizeof(var));
	var.yoffset = y;
	var.xoffset = 0;
	var.vmode |= FB_VMODE_YWRAP;
	if ((res = ioctl(LIBGGI_FD(vis), FBIOGET_VBLANK, &var)))
		return (res);
	return (0);
}