xref: /haiku/headers/os/add-ons/graphics/Accelerant.h (revision 23f179da55b1bd1ba84fbf3d3c56947e2c8d0aca)
1 /*
2  * Copyright 2009, Haiku, Inc. All rights reserved.
3  * Distributed under the terms of the MIT License.
4  */
5 #ifndef _ACCELERANT_H_
6 #define _ACCELERANT_H_
7 
8 
9 #include <GraphicsDefs.h>
10 #include <OS.h>
11 
12 
13 #if defined(__cplusplus)
14 	extern "C" {
15 #endif
16 
17 
18 #define B_ACCELERANT_ENTRY_POINT	"get_accelerant_hook"
19 #define B_ACCELERANT_VERSION		1
20 
21 
22 typedef void* (*GetAccelerantHook)(uint32, void*);
23 
24 void* get_accelerant_hook(uint32 feature, void* data);
25 
26 
27 enum {
28 	/* initialization */
29 	B_INIT_ACCELERANT = 0,				/* required */
30 	B_ACCELERANT_CLONE_INFO_SIZE,		/* required */
31 	B_GET_ACCELERANT_CLONE_INFO,		/* required */
32 	B_CLONE_ACCELERANT,					/* required */
33 	B_UNINIT_ACCELERANT,				/* required */
34 	B_GET_ACCELERANT_DEVICE_INFO,		/* required */
35 	B_ACCELERANT_RETRACE_SEMAPHORE,		/* optional */
36 
37 	/* mode configuration */
38 	B_ACCELERANT_MODE_COUNT = 0x100,	/* required */
39 	B_GET_MODE_LIST,					/* required */
40 	B_PROPOSE_DISPLAY_MODE,				/* optional */
41 	B_SET_DISPLAY_MODE,					/* required */
42 	B_GET_DISPLAY_MODE,					/* required */
43 	B_GET_FRAME_BUFFER_CONFIG,			/* required */
44 	B_GET_PIXEL_CLOCK_LIMITS,			/* required */
45 	B_GET_TIMING_CONSTRAINTS,			/* optional */
46 	B_MOVE_DISPLAY,						/* optional */
47 	B_SET_INDEXED_COLORS,				/* required if driver supports 8bit */
48 										/* indexed modes */
49 	B_DPMS_CAPABILITIES,				/* required if driver supports DPMS */
50 	B_DPMS_MODE,						/* required if driver supports DPMS */
51 	B_SET_DPMS_MODE,					/* required if driver supports DPMS */
52 	B_GET_PREFERRED_DISPLAY_MODE,		/* optional */
53 	B_GET_MONITOR_INFO,					/* optional */
54 	B_GET_EDID_INFO,					/* optional */
55 
56 	/* cursor managment */
57 	B_MOVE_CURSOR = 0x200,				/* optional */
58 	B_SET_CURSOR_SHAPE,					/* optional */
59 	B_SHOW_CURSOR,						/* optional */
60 
61 	/* synchronization */
62 	B_ACCELERANT_ENGINE_COUNT = 0x300,	/* required */
63 	B_ACQUIRE_ENGINE,					/* required */
64 	B_RELEASE_ENGINE,					/* required */
65 	B_WAIT_ENGINE_IDLE,					/* required */
66 	B_GET_SYNC_TOKEN,					/* required */
67 	B_SYNC_TO_TOKEN,					/* required */
68 
69 	/* 2D acceleration */
70 	B_SCREEN_TO_SCREEN_BLIT = 0x400,	/* optional */
71 	B_FILL_RECTANGLE,					/* optional */
72 	B_INVERT_RECTANGLE,					/* optional */
73 	B_FILL_SPAN,						/* optional */
74 	B_SCREEN_TO_SCREEN_TRANSPARENT_BLIT,	/* optional */
75 	B_SCREEN_TO_SCREEN_SCALED_FILTERED_BLIT,	/* optional.
76 		NOTE: source and dest may NOT overlap */
77 
78 	/* 3D acceleration */
79 	B_ACCELERANT_PRIVATE_START = (int)0x80000000
80 };
81 
82 
83 typedef struct {
84 	uint32	version;					/* structure version number */
85 	char 	name[32];					/* a name the user will recognize */
86 										/* the device by */
87 	char	chipset[32];				/* the chipset used by the device */
88 	char	serial_no[32];				/* serial number for the device */
89 	uint32	memory;						/* amount of memory on the device, */
90 										/* in bytes */
91 	uint32	dac_speed;					/* nominal DAC speed, in MHz */
92 } accelerant_device_info;
93 
94 
95 typedef struct {
96 	uint32	pixel_clock;				/* kHz */
97 	uint16	h_display;					/* in pixels (not character clocks) */
98 	uint16	h_sync_start;
99 	uint16	h_sync_end;
100 	uint16	h_total;
101 	uint16	v_display;					/* in lines */
102 	uint16	v_sync_start;
103 	uint16	v_sync_end;
104 	uint16	v_total;
105 	uint32	flags;						/* sync polarity, etc. */
106 } display_timing;
107 
108 typedef struct {
109 	display_timing	timing;				/* CTRC info */
110 	uint32			space;				/* pixel configuration */
111 	uint16			virtual_width;		/* in pixels */
112 	uint16			virtual_height;		/* in lines */
113 	uint16			h_display_start;	/* first displayed pixel in line */
114 	uint16			v_display_start;	/* first displayed line */
115 	uint32			flags;				/* mode flags (Some drivers use this */
116 										/* for dual head related options.) */
117 } display_mode;
118 
119 typedef struct {
120 	void*	frame_buffer;				/* pointer to first byte of frame */
121 										/* buffer in virtual memory */
122 
123 	void*	frame_buffer_dma;			/* pointer to first byte of frame */
124 										/* buffer in physical memory for DMA */
125 
126 	uint32	bytes_per_row;				/* number of bytes in one */
127 										/* virtual_width line */
128 										/* not neccesarily the same as */
129 										/* virtual_width * byte_per_pixel */
130 } frame_buffer_config;
131 
132 typedef struct {
133 	uint16	h_res;						/* minimum effective change in */
134 										/* horizontal pixels, usually 8 */
135 
136 	uint16	h_sync_min;					/* min/max horizontal sync pulse */
137 										/* width in pixels, a multiple of */
138 										/* h_res */
139 	uint16	h_sync_max;
140 	uint16	h_blank_min;				/* min/max horizontal blank pulse */
141 										/* width in pixels, a multiple of */
142 										/* h_res */
143 	uint16	h_blank_max;
144 	uint16	v_res;						/* minimum effective change in */
145 										/* vertical lines, usually 1 */
146 
147 	uint16	v_sync_min;					/* min/max vertical sync pulse */
148 										/* width in lines, a multiple of */
149 										/* v_res */
150 	uint16	v_sync_max;
151 	uint16	v_blank_min;				/* min/max vertical blank pulse */
152 										/* width in linex, a multiple of */
153 										/* v_res */
154 	uint16	v_blank_max;
155 } display_timing_constraints;
156 
157 
158 // WARNING: This is experimental new Haiku API
159 typedef struct {
160 	uint32	version;
161 	char	vendor[128];
162 	char	name[128];
163 	char	serial_number[128];
164 	uint32	product_id;
165 	struct {
166 		uint16	week;
167 		uint16	year;
168 	}		produced;
169 	float	width;
170 	float	height;
171 	uint32	min_horizontal_frequency;	/* in kHz */
172 	uint32	max_horizontal_frequency;
173 	uint32	min_vertical_frequency;		/* in Hz */
174 	uint32	max_vertical_frequency;
175 	uint32	max_pixel_clock;			/* in kHz */
176 } monitor_info;
177 
178 
179 /* mode flags */
180 enum {
181 	B_SCROLL			= 1 << 0,
182 	B_8_BIT_DAC			= 1 << 1,
183 	B_HARDWARE_CURSOR	= 1 << 2,
184 	B_PARALLEL_ACCESS	= 1 << 3,
185 	B_DPMS				= 1 << 4,
186 	B_IO_FB_NA			= 1 << 5
187 };
188 
189 
190 /* power saver flags */
191 enum {
192 	B_DPMS_ON			= 1 << 0,
193 	B_DPMS_STAND_BY		= 1 << 1,
194 	B_DPMS_SUSPEND		= 1 << 2,
195 	B_DPMS_OFF			= 1 << 3
196 };
197 
198 
199 /* timing flags */
200 enum {
201 	B_BLANK_PEDESTAL	= 1 << 27,
202 	B_TIMING_INTERLACED	= 1 << 28,
203 	B_POSITIVE_HSYNC	= 1 << 29,
204 	B_POSITIVE_VSYNC	= 1 << 30,
205 	B_SYNC_ON_GREEN		= 1 << 31
206 };
207 
208 
209 typedef struct {
210 	uint16	src_left;					/* guaranteed constrained to */
211 										/* virtual width and height */
212 	uint16	src_top;
213 	uint16	dest_left;
214 	uint16	dest_top;
215 	uint16	width;						/* 0 to N, where zero means */
216 										/* one pixel, one means two pixels, */
217 										/* etc. */
218 	uint16	height;						/* 0 to M, where zero means one */
219 										/* line, one means two lines, etc. */
220 } blit_params;
221 
222 
223 typedef struct {
224 	uint16	src_left;					/* guaranteed constrained to */
225 										/* virtual width and height */
226 	uint16	src_top;
227 	uint16	src_width;					/* 0 to N, where zero means one */
228 										/* pixel, one means two pixels, */
229 										/* etc. */
230 	uint16	src_height;					/* 0 to M, where zero means one */
231 										/* line, one means two lines, etc. */
232 	uint16	dest_left;
233 	uint16	dest_top;
234 	uint16	dest_width;					/* 0 to N, where zero means one */
235 										/* pixel, one means two pixels, etc. */
236 	uint16	dest_height;				/* 0 to M, where zero means one */
237 										/* line, one means two lines, etc. */
238 } scaled_blit_params;
239 
240 
241 typedef struct {
242 	uint16	left;						/* guaranteed constrained to */
243 										/* virtual width and height */
244 	uint16	top;
245 	uint16	right;
246 	uint16	bottom;
247 } fill_rect_params;
248 
249 
250 typedef struct {
251 	uint32	engine_id;					/* 0 == no engine, 1,2,3 etc */
252 										/* individual engines */
253 	uint32	capability_mask;			/* features this engine supports */
254 	void*	opaque;						/* optional pointer to engine */
255 										/* private storage */
256 } engine_token;
257 
258 
259 enum {	/* engine capabilities */
260 	B_2D_ACCELERATION = 1 << 0,
261 	B_3D_ACCELERATION = 1 << 1
262 };
263 
264 
265 typedef struct {
266 	uint64	counter;					/* counts issued primatives */
267 	uint32	engine_id;					/* what engine the counter is for */
268 	char	opaque[12];					/* 12 bytes of private storage */
269 } sync_token;
270 
271 
272 /* Masks for color info */
273 /* B_CMAP8    - 0x000000ff */
274 /* B_RGB15/16 - 0x0000ffff */
275 /* B_RGB24    - 0x00ffffff */
276 /* B_RGB32    - 0xffffffff */
277 
278 typedef status_t (*init_accelerant)(int fd);
279 typedef ssize_t (*accelerant_clone_info_size)(void);
280 typedef void (*get_accelerant_clone_info)(void* data);
281 typedef status_t (*clone_accelerant)(void* data);
282 typedef void (*uninit_accelerant)(void);
283 typedef status_t (*get_accelerant_device_info)(accelerant_device_info* adi);
284 
285 typedef uint32 (*accelerant_mode_count)(void);
286 typedef status_t (*get_mode_list)(display_mode*);
287 typedef status_t (*propose_display_mode)(display_mode* target,
288 	display_mode* low, display_mode* high);
289 typedef status_t (*set_display_mode)(display_mode* mode_to_set);
290 typedef status_t (*get_display_mode)(display_mode* current_mode);
291 typedef status_t (*get_frame_buffer_config)(frame_buffer_config*
292 	a_frame_buffer);
293 typedef status_t (*get_pixel_clock_limits)(display_mode* dm, uint32* low,
294 	uint32* high);
295 typedef status_t (*move_display_area)(uint16 h_display_start,
296 	uint16 v_display_start);
297 typedef status_t (*get_timing_constraints)(display_timing_constraints* dtc);
298 typedef void (*set_indexed_colors)(uint count, uint8 first, uint8* color_data,
299 	uint32 flags);
300 typedef uint32 (*dpms_capabilities)(void);
301 typedef uint32 (*dpms_mode)(void);
302 typedef status_t (*set_dpms_mode)(uint32 dpms_flags);
303 typedef status_t (*get_preferred_display_mode)(display_mode* preferredMode);
304 typedef status_t (*get_monitor_info)(monitor_info* info);
305 typedef status_t (*get_edid_info)(void* info, uint32 size, uint32* _version);
306 typedef sem_id (*accelerant_retrace_semaphore)(void);
307 
308 typedef status_t (*set_cursor_shape)(uint16 width, uint16 height,
309 	uint16 hot_x, uint16 hot_y, uint8* andMask, uint8* xorMask);
310 typedef void (*move_cursor)(uint16 x, uint16 y);
311 typedef void (*show_cursor)(bool is_visible);
312 
313 typedef uint32 (*accelerant_engine_count)(void);
314 typedef status_t (*acquire_engine)(uint32 capabilities, uint32 max_wait,
315 	sync_token* st, engine_token** et);
316 typedef status_t (*release_engine)(engine_token* et, sync_token* st);
317 typedef void (*wait_engine_idle)(void);
318 typedef status_t (*get_sync_token)(engine_token* et, sync_token* st);
319 typedef status_t (*sync_to_token)(sync_token* st);
320 
321 typedef void (*screen_to_screen_blit)(engine_token* et, blit_params* list,
322 	uint32 count);
323 typedef void (*fill_rectangle)(engine_token* et, uint32 color,
324 	fill_rect_params* list, uint32 count);
325 typedef void (*invert_rectangle)(engine_token* et, fill_rect_params* list,
326 	uint32 count);
327 typedef void (*screen_to_screen_transparent_blit)(engine_token* et,
328 	uint32 transparent_color, blit_params* list, uint32 count);
329 typedef void (*screen_to_screen_scaled_filtered_blit)(engine_token* et,
330 	scaled_blit_params* list, uint32 count);
331 
332 typedef void (*fill_span)(engine_token* et, uint32 color, uint16* list,
333 	uint32 count);
334 /*
335 	The uint16* list points to a list of tripples:
336 		list[N+0]  Y co-ordinate of span
337 		list[N+1]  Left x co-ordinate of span
338 		list[N+2]  Right x co-ordinate of span
339 	where N is in the range 0 to count-1.
340 */
341 
342 
343 #if defined(__cplusplus)
344 }
345 #endif
346 
347 #endif
348