Kernel/drvutil - Adding software cursor support
[tpg/acess2.git] / Kernel / include / api_drv_video.h
1 /**\r
2  * \file api_drv_video.h\r
3  * \brief Video Driver Interface Definitions\r
4  * \note For AcessOS Version 1\r
5  * \r
6  * Video drivers extend the common driver interface api_drv_common.h\r
7  * and must support _at least_ the IOCtl numbers defined in this file\r
8  * to be compatable with Acess.\r
9  * \r
10  * \section IOCtls\r
11  * As said, a compatable driver must implement these calls correctly,\r
12  * but they may choose not to allow direct user access to the framebuffer.\r
13  * \r
14  * \section Screen Contents\r
15  * Writes to the driver's file while in component colour modes\r
16  * must correspond to a change of the contents of the screen. The framebuffer\r
17  * must start at offset 0 in the file.\r
18  * Reading from the screen must either return zero, or read from the\r
19  * framebuffer.\r
20  * \r
21  * \section Mode Support\r
22  * All video drivers must support at least one text mode (Mode #0)\r
23  * For each graphics mode the driver exposes, there must be a corresponding\r
24  * text mode with the same resolution, this mode will be used when the\r
25  * user switches to a text Virtual Terminal while in graphics mode.\r
26  */\r
27 #ifndef _API_DRV_VIDEO_H\r
28 #define _API_DRV_VIDEO_H\r
29 \r
30 #include <api_drv_common.h>\r
31 \r
32 /**\r
33  * \enum eTplVideo_IOCtl\r
34  * \brief Common Video IOCtl Calls\r
35  * \extends eTplDrv_IOCtl\r
36  */\r
37 enum eTplVideo_IOCtl {\r
38         /**\r
39          * ioctl(..., int *mode)\r
40          * \brief Get/Set Mode\r
41          * \return Current mode ID or -1 on error\r
42          * \r
43          * If \a mode is non-NULL, the current video mode is set to \a *mode.\r
44          * This updated ID is then returned to the user.\r
45          */\r
46         VIDEO_IOCTL_GETSETMODE = 4,\r
47         \r
48         /**\r
49          * ioctl(..., tVideo_IOCtl_Mode *info)\r
50          * \brief Find a matching mode\r
51          * \return 1 if a mode was found, 0 otherwise\r
52          * \r
53          * Using avaliable modes matching the \a bpp and \a flags fields\r
54          * set the \a id, \a width and \a heights fields to the closest\r
55          * matching mode.\r
56          */\r
57         VIDEO_IOCTL_FINDMODE,\r
58         \r
59         /**\r
60          * ioctl(..., tVideo_IOCtl_Mode *info)\r
61          * \brief Get mode info\r
62          * \return 1 if the mode exists, 0 otherwise\r
63          * \r
64          * Set \a info's fields to the mode specified by the \a id field.\r
65          */\r
66         VIDEO_IOCTL_MODEINFO,\r
67         \r
68         /**\r
69          * ioctl(..., int *NewFormat)\r
70          * \brief Switches between Text, Framebuffer and 3D modes\r
71          * \param NewFormat     Pointer to the new format code (see eTplVideo_BufFormats)\r
72          * \return Original format\r
73          * \r
74          * Enabes and disables the video text mode, changing the behavior of\r
75          * writes to the device file.\r
76          */\r
77         VIDEO_IOCTL_SETBUFFORMAT,\r
78         \r
79         /**\r
80          * ioctl(..., tVideo_IOCtl_Pos *pos)\r
81          * \brief Sets the cursor position\r
82          * \return Boolean success\r
83          * \r
84          * Set the text mode cursor position (if it is supported)\r
85          * If the \a pos is set to (-1,-1) the cursor is hidden, otherwise\r
86          * \a pos MUST be within the current screen size (as given by the\r
87          * current mode's tVideo_IOCtl_Mode.width and tVideo_IOCtl_Mode.height\r
88          * fields).\r
89          */\r
90         VIDEO_IOCTL_SETCURSOR,\r
91         \r
92         /**\r
93          * ioctl(..., tVideo_IOCtl_Bitmap *Image)\r
94          * \brief Sets the cursor image\r
95          * \return Boolean success\r
96          *\r
97          * Sets the graphics mode cursor image\r
98          */\r
99         VIDEO_IOCTL_SETCURSORBITMAP\r
100 };\r
101 #define DRV_VIDEO_IOCTLNAMES    "getset_mode", "find+mode", "mode_info", "set_buf_format", "set_cursor", "set_cursor_bitmap"\r
102 \r
103 /**\r
104  * \brief Mode Structure used in IOCtl Calls\r
105  * \r
106  * Defines a video mode supported by (or requested of) this driver (depending\r
107  * on what ioctl call is used)\r
108  */\r
109 typedef struct sVideo_IOCtl_Mode\r
110 {\r
111         short   id;             //!< Mode ID\r
112         Uint16  width;  //!< Width\r
113         Uint16  height; //!< Height\r
114         Uint8   bpp;    //!< Bits per pixel\r
115         Uint8   flags;  //!< Mode Flags (none defined, should be zero)\r
116 }       tVideo_IOCtl_Mode;\r
117 \r
118 /**\r
119  * \brief Buffer Format Codes\r
120  */\r
121 enum eTplVideo_BufFormats\r
122 {\r
123         /**\r
124          * \brief Text Mode\r
125          * \r
126          * The device file presents itself as an array of ::tVT_Char\r
127          * each describing a character cell on the screen.\r
128          * These cells are each \a giVT_CharWidth pixels wide and\r
129          * \a giVT_CharHeight high.\r
130          */\r
131         VIDEO_BUFFMT_TEXT,\r
132         /**\r
133          * \brief Framebuffer Mode\r
134          * \r
135          * The device file presents as an array of 32-bpp pixels describing\r
136          * the entire screen. The format of a single pixel is in xRGB format\r
137          * (top 8 bits ignored, next 8 bits red, next 8 bits green and\r
138          * the bottom 8 bits blue)\r
139          */\r
140         VIDEO_BUFFMT_FRAMEBUFFER,\r
141         /**\r
142          * \brief 2D Accelerated Mode\r
143          * \r
144          * The device file acts as a character device, accepting a stream of\r
145          * commands described in eTplVideo_2DCommands when written to.\r
146          */\r
147         VIDEO_BUFFMT_2DSTREAM,\r
148         /**\r
149          * \brief 3D Accelerated Mode\r
150          * \r
151          * The device file acts as a character device, accepting a stream of\r
152          * commands described in eTplVideo_3DCommands when written to.\r
153          */\r
154         VIDEO_BUFFMT_3DSTREAM\r
155 };\r
156 \r
157 /**\r
158  * \brief 2D Accellerated Video Commands\r
159  * \r
160  * Commands passed in the command stream for ::VIDEO_BUFFMT_2DSTREAM\r
161  */\r
162 enum eTplVideo_2DCommands\r
163 {\r
164         /**\r
165          * \brief No Operation\r
166          */\r
167         VIDEO_2DOP_NOP,\r
168         /**\r
169          * \brief Fill a region\r
170          * \param X     Uint16 - Leftmost pixels of the region\r
171          * \param Y     Uint16 - Topmost pixels of the region\r
172          * \param W     Uint16 - Width of the region\r
173          * \param H     Uint16 - Height of the region\r
174          * \param Colour        Uint32 - Value to fill with\r
175          */\r
176         VIDEO_2DOP_FILL,\r
177         /**\r
178          * \brief Copy a region from one part of the framebuffer to another\r
179          * \param DestX Uint16 - Leftmost pixels of the destination\r
180          * \param DestY Uint16 - Topmost pixels of the destination\r
181          * \param SrcX  Uint16 - Leftmost pixels of the source\r
182          * \param SrcY  Uint16 - Topmost pixels of the source\r
183          * \param Width Uint16 - Width of the region\r
184          * \param Height        Uint16 - Height of the region\r
185          */\r
186         VIDEO_2DOP_BLIT,\r
187 \r
188 \r
189         /**\r
190          * \brief Copy a region from video memory to the framebuffer\r
191          */\r
192         VIDEO_2DOP_BLITBUF,\r
193 \r
194         /**\r
195          * \brief Copy and scale a region from video memory to the framebuffer\r
196          */\r
197         VIDEO_2DOP_BLITSCALEBUF,\r
198 \r
199         NUM_VIDEO_2DOPS\r
200 };\r
201 \r
202 /**\r
203  * \brief Describes a position in the video framebuffer\r
204  */\r
205 typedef struct sVideo_IOCtl_Pos\r
206 {\r
207         Sint16  x;      //!< X Coordinate\r
208         Sint16  y;      //!< Y Coordinate\r
209 }       tVideo_IOCtl_Pos;\r
210 \r
211 /**\r
212  * \brief Bitmap object (out of band image)\r
213  */\r
214 typedef struct sVideo_IOCtl_Bitmap\r
215 {\r
216         Sint16  W;      //!< Width of image\r
217         Sint16  H;      //!< Height of image\r
218         Sint16  XOfs;   //!< X Offset of center\r
219         Sint16  YOfs;   //!< Y Offset of center\r
220         Uint32  Data[]; //!< Image data (ARGB array)\r
221 }       tVideo_IOCtl_Bitmap;\r
222 \r
223 /**\r
224  * \brief Virtual Terminal Representation of a character\r
225  */\r
226 typedef struct sVT_Char\r
227 {\r
228         Uint32  Ch;     //!< UTF-32 Character\r
229         union {\r
230                 struct {\r
231                         Uint16  BGCol;  //!< 12-bit Foreground Colour\r
232                         Uint16  FGCol;  //!< 12-bit Background Colour\r
233                 };\r
234                 Uint32  Colour; //!< Compound colour for ease of access\r
235         };\r
236 }       tVT_Char;\r
237 \r
238 /**\r
239  * \name Basic builtin colour definitions\r
240  * \{\r
241  */\r
242 #define VT_COL_BLACK    0x0000\r
243 #define VT_COL_GREY             0x0888\r
244 #define VT_COL_LTGREY   0x0CCC\r
245 #define VT_COL_WHITE    0x0FFF\r
246 /**\r
247  * \}\r
248  */\r
249 \r
250 //! \brief Defines the width of a rendered character\r
251 extern int      giVT_CharWidth;\r
252 //! \brief Defines the height of a rendered character\r
253 extern int      giVT_CharHeight;\r
254 /**\r
255  * \brief Driver helper that renders a character to a buffer\r
256  * \param Codepoint     Unicode character to render\r
257  * \param Buffer        Buffer to render to\r
258  * \param Depth Bit depth of the destination buffer\r
259  * \param Pitch Number of bytes per line\r
260  * \param BGC   32-bit Background Colour\r
261  * \param FGC   32-bit Foreground Colour\r
262  * \r
263  * This function is provided to help video drivers to support a simple\r
264  * text mode by keeping the character rendering abstracted from the driver,\r
265  * easing the driver development and reducing code duplication.\r
266  */\r
267 extern void     VT_Font_Render(Uint32 Codepoint, void *Buffer, int Depth, int Pitch, Uint32 BGC, Uint32 FGC);\r
268 /**\r
269  * \fn Uint32 VT_Colour12to24(Uint16 Col12)\r
270  * \brief Converts a colour from 12bpp to 24bpp\r
271  * \param Col12 12-bpp input colour\r
272  * \return Expanded 32-bpp (24-bit colour) version of \a Col12\r
273  */\r
274 extern Uint32   VT_Colour12to24(Uint16 Col12);\r
275 /**\r
276  * \brief Converts a colour from 12bpp to 14bpp\r
277  * \param Col12 12-bpp input colour\r
278  * \return 15 bits per pixel value\r
279  */\r
280 extern Uint16   VT_Colour12to15(Uint16 Col12);\r
281 /**\r
282  * \brief Converts a colour from 12bpp to 32bpp\r
283  * \param Col12 12-bpp input colour\r
284  * \param Depth Desired bit depth\r
285  * \return \a Depth bit number, denoting Col12\r
286  * \r
287  * Expands the source colour into a \a Depth bits per pixel representation.\r
288  * The colours are expanded with preference to Green, Blue and Red in that order\r
289  * (so, green gets the first spare pixel, blue gets the next, and red never gets\r
290  * the spare). \n\r
291  * The final bit of each component is used to fill the lower bits of the output.\r
292  */\r
293 extern Uint32   VT_Colour12toN(Uint16 Col12, int Depth);\r
294 \r
295 typedef struct sDrvUtil_Video_BufInfo   tDrvUtil_Video_BufInfo;\r
296 typedef struct sDrvUtil_Video_2DHandlers        tDrvUtil_Video_2DHandlers;\r
297 \r
298 /**\r
299  * \brief Maximum cursor width for using the DrvUtil software cursor\r
300  */\r
301 #define DRVUTIL_MAX_CURSOR_W    32\r
302 /**\r
303  * \brief Maximum cursor width for using the DrvUtil software cursor\r
304  */\r
305 #define DRVUTIL_MAX_CURSOR_H    32\r
306 \r
307 /**\r
308  * \brief Framebuffer information used by all DrvUtil_Video functions\r
309  */\r
310 struct sDrvUtil_Video_BufInfo\r
311 {\r
312         /**\r
313          * \brief Framebuffer virtual address\r
314          */\r
315         void    *Framebuffer;\r
316         /**\r
317          * \brief Bytes between the start of each line\r
318          */\r
319          int    Pitch;\r
320         /**\r
321          * \brief Number of pixels in each line\r
322          */\r
323         short   Width;\r
324         /**\r
325          * \brief Total number of lines\r
326          */\r
327         short   Height;\r
328         /**\r
329          * \brief Bit depth of the framebuffer\r
330          */\r
331          int    Depth;\r
332         \r
333         /**\r
334          * \brief Software cursor controls\r
335          * \{\r
336          */\r
337         /**\r
338          * \brief X coordinate of the cursor\r
339          */\r
340         short   CursorX;\r
341         /**\r
342          * \brief Y coordinate of the cursor\r
343          */\r
344         short   CursorY;\r
345 \r
346         /**\r
347          * \brief Cursor bitmap\r
348          */\r
349         tVideo_IOCtl_Bitmap     *CursorBitmap;\r
350 \r
351         /**\r
352          * \brief Buffer to store the area under the cursor\r
353          */\r
354         void    *CursorSaveBuf;\r
355         /*\r
356          * \}\r
357          */\r
358 };\r
359 \r
360 /**\r
361  * \brief Handlers for eTplVideo_2DCommands\r
362  */\r
363 struct sDrvUtil_Video_2DHandlers\r
364 {\r
365         /**\r
366          * \brief No Operation, Ignored\r
367          * \see VIDEO_2DOP_NOP\r
368          */\r
369         void    *Nop;\r
370         /**\r
371          * \brief Fill a buffer region\r
372          * \param X     Lefthand edge\r
373          * \param Y     Top edge\r
374          * \param W     Width\r
375          * \param H     Height\r
376          * \param Colour        Colour to fill with\r
377          * \see VIDEO_2DOP_FILL\r
378          */\r
379         void    (*Fill)(void *Ent, Uint16 X, Uint16 Y, Uint16 W, Uint16 H, Uint32 Colour);\r
380         /**\r
381          * \brief Fill a buffer region\r
382          * \param DestX Lefthand edge of destination\r
383          * \param DestY Top edge of destination\r
384          * \param SrcX  Lefthand edge of source\r
385          * \param SrcY  Top edge of source\r
386          * \param W     Width\r
387          * \param H     Height\r
388          * \see VIDEO_2DOP_BLIT\r
389          */\r
390         void    (*Blit)(void *Ent, Uint16 DestX, Uint16 DestY, Uint16 SrcX, Uint16 SrcY, Uint16 W, Uint16 H);\r
391 };\r
392 \r
393 /**\r
394  * \brief Handle a 2D operation stream for a driver\r
395  * \param Ent   Value to pass to handlers\r
396  * \param Buffer        Stream buffer\r
397  * \param Length        Length of stream\r
398  * \param Handlers      Handlers to use for the stream\r
399  * \param SizeofHandlers        Size of \a tDrvUtil_Video_2DHandlers according\r
400  *        to the driver. Used as version control and error avoidence.\r
401  */\r
402 extern int      DrvUtil_Video_2DStream(void *Ent, void *Buffer, int Length,\r
403         tDrvUtil_Video_2DHandlers *Handlers, int SizeofHandlers);\r
404 \r
405 /**\r
406  * \brief Perform write operations to a LFB\r
407  * \param Mode  Buffer mode (see eTplVideo_BufFormats)\r
408  * \param FBInfo        Framebuffer descriptor, see type for details\r
409  * \param Offset        Offset provided by VFS call\r
410  * \param Length        Length provided by VFS call\r
411  * \param Src   Data from VFS call\r
412  * \return Number of bytes written\r
413  *\r
414  * Handles all write modes in software, using the VT font calls for rendering.\r
415  * \note Calls the cursor clear and redraw if the cursor area is touched\r
416  */\r
417 extern int      DrvUtil_Video_WriteLFB(int Mode, tDrvUtil_Video_BufInfo *FBInfo, size_t Offset, size_t Length, void *Src);\r
418 \r
419 /**\r
420  * \brief Software cursor rendering\r
421  * \{\r
422  */\r
423 /**\r
424  * \brief Set the cursor bitmap for a buffer\r
425  * \param Buf   Framebuffer descriptor\r
426  * \param Bitmap        New cursor bitmap\r
427  */\r
428 extern void     DrvUtil_Video_SetCursor(tDrvUtil_Video_BufInfo *Buf, tVideo_IOCtl_Bitmap *Bitmap);\r
429 /**\r
430  * \brief Render the cursor at (\a X, \a Y)\r
431  * \param Buf   Framebuffer descriptor, see type for details\r
432  * \param X     X coord of the cursor\r
433  * \param Y     Y coord of the cursor\r
434  */\r
435 extern void     DrvUtil_Video_DrawCursor(tDrvUtil_Video_BufInfo *Buf, int X, int Y);\r
436 /**\r
437  * \brief Removes the rendered cursor from the screen\r
438  * \param Buf   Framebuffer descriptor, see type for details\r
439  */\r
440 extern void     DrvUtil_Video_RemoveCursor(tDrvUtil_Video_BufInfo *Buf);\r
441 /**\r
442  * \}\r
443  */\r
444 #endif\r

UCC git Repository :: git.ucc.asn.au