f518e74a4de842d1960b9750a562f92556e9faed
[tpg/acess2.git] / Kernel / include / tpl_drv_video.h
1 /**\r
2  * \file tpl_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 tpl_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 _TPL_VIDEO_H\r
28 #define _TPL_VIDEO_H\r
29 \r
30 #include <tpl_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 field to the mode id of the mode with the closest\r
55          * \a width and \a height.\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 Unit (Character or Pixel, depending on \a flags)\r
115         Uint8   flags;  //!< Mode Flags\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 /**\r
296  * \brief Handlers for eTplVideo_2DCommands\r
297  */\r
298 typedef struct sDrvUtil_Video_2DHandlers\r
299 {\r
300         /**\r
301          * \brief No Operation, Ignored\r
302          * \see VIDEO_2DOP_NOP\r
303          */\r
304         void    *Nop;\r
305         /**\r
306          * \brief Fill a buffer region\r
307          * \param X     Lefthand edge\r
308          * \param Y     Top edge\r
309          * \param W     Width\r
310          * \param H     Height\r
311          * \param Colour        Colour to fill with\r
312          * \see VIDEO_2DOP_FILL\r
313          */\r
314         void    (*Fill)(void *Ent, Uint16 X, Uint16 Y, Uint16 W, Uint16 H, Uint32 Colour);\r
315         /**\r
316          * \brief Fill a buffer region\r
317          * \param DestX Lefthand edge of destination\r
318          * \param DestY Top edge of destination\r
319          * \param SrcX  Lefthand edge of source\r
320          * \param SrcY  Top edge of source\r
321          * \param W     Width\r
322          * \param H     Height\r
323          * \see VIDEO_2DOP_BLIT\r
324          */\r
325         void    (*Blit)(void *Ent, Uint16 DestX, Uint16 DestY, Uint16 SrcX, Uint16 SrcY, Uint16 W, Uint16 H);\r
326 }       tDrvUtil_Video_2DHandlers;\r
327 \r
328 /**\r
329  * \brief Handle a 2D operation stream for a driver\r
330  * \param Ent   Value to pass to handlers\r
331  * \param Buffer        Stream buffer\r
332  * \param Length        Length of stream\r
333  * \param Handlers      Handlers to use for the stream\r
334  * \param SizeofHandlers        Size of \a tDrvUtil_Video_2DHandlers according\r
335  *        to the driver. Used as version control and error avoidence.\r
336  */\r
337 extern Uint64   DrvUtil_Video_2DStream(void *Ent, void *Buffer, int Length,\r
338         tDrvUtil_Video_2DHandlers *Handlers, int SizeofHandlers);\r
339 \r
340 #endif\r

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