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