1/*
2	Copyright 1999, Be Incorporated.   All Rights Reserved.
3	This file may be used under the terms of the Be Sample Code License.
4
5	Other authors:
6	Mark Watson,
7	Rudolf Cornelissen 10/2002-8/2009
8*/
9
10#define MODULE_BIT 0x08000000
11
12#include "acc_std.h"
13
14/*
15The standard entry point.  Given a uint32 feature identifier, this routine
16returns a pointer to the function that implements the feature.  Some features
17require more information than just the identifier to select the proper
18function.  The extra information (which is specific to the feature) is
19pointed at by the void *data parameter.  By default, no extra information
20is available.  Any extra information available to choose the function will be
21noted on a case by case below.
22*/
23
24/*
25These definitions are out of pure lazyness.
26*/
27#define CHKO(x) case B_##x: \
28	if (check_overlay_capability(B_##x) == B_OK) return (void *)x; else return (void *)0
29#define CHKA(x) case B_##x: \
30	if (check_acc_capability(B_##x) == B_OK) \
31	{if(!si->settings.dma_acc) return (void *)x##_PIO; else return (void *)x##_DMA;} \
32	else return (void *)0
33#define CHKS(x) case B_##x: \
34	if(!si->settings.dma_acc) return (void *)x##_PIO; else return (void *)x##_DMA
35#define HOOK(x) case B_##x: return (void *)x
36#define ZERO(x) case B_##x: return (void *)0
37#define HRDC(x) case B_##x: return si->settings.hardcursor? (void *)x: (void *)0; // apsed
38
39void *	get_accelerant_hook(uint32 feature, void *data)
40{
41	switch (feature)
42	{
43		/*
44		One of either B_INIT_ACCELERANT or B_CLONE_ACCELERANT will be requested and
45		subsequently called before any other hook is requested.  All other feature
46		hook selections can be predicated on variables assigned during the accelerant
47		initialization process.
48		*/
49
50		/* initialization */
51		HOOK(INIT_ACCELERANT);
52		HOOK(CLONE_ACCELERANT);
53
54		HOOK(ACCELERANT_CLONE_INFO_SIZE);
55		HOOK(GET_ACCELERANT_CLONE_INFO);
56		HOOK(UNINIT_ACCELERANT);
57		HOOK(GET_ACCELERANT_DEVICE_INFO);
58		HOOK(ACCELERANT_RETRACE_SEMAPHORE);
59
60		/* mode configuration */
61		HOOK(ACCELERANT_MODE_COUNT);
62		HOOK(GET_MODE_LIST);
63		HOOK(PROPOSE_DISPLAY_MODE);
64		HOOK(SET_DISPLAY_MODE);
65		HOOK(GET_DISPLAY_MODE);
66#ifdef __HAIKU__
67		HOOK(GET_EDID_INFO);
68		HOOK(GET_PREFERRED_DISPLAY_MODE);
69#endif
70		HOOK(GET_FRAME_BUFFER_CONFIG);
71		HOOK(GET_PIXEL_CLOCK_LIMITS);
72		HOOK(MOVE_DISPLAY);
73		HOOK(SET_INDEXED_COLORS);
74		HOOK(GET_TIMING_CONSTRAINTS);
75
76		HOOK(DPMS_CAPABILITIES);
77		HOOK(DPMS_MODE);
78		HOOK(SET_DPMS_MODE);
79
80		/* cursor managment */
81		HRDC(SET_CURSOR_SHAPE);
82		HRDC(MOVE_CURSOR);
83		HRDC(SHOW_CURSOR);
84
85		/* synchronization */
86		HOOK(ACCELERANT_ENGINE_COUNT);
87		CHKS(ACQUIRE_ENGINE);
88		HOOK(RELEASE_ENGINE);
89		HOOK(WAIT_ENGINE_IDLE);
90		HOOK(GET_SYNC_TOKEN);
91		HOOK(SYNC_TO_TOKEN);
92
93		/*
94		Depending on the engine architecture, you may choose to provide a different
95		function to be used with each bit-depth for example.
96
97		Note: These hooks are re-acquired by the app_server after each mode switch.
98		*/
99
100		/* only export video overlay functions if card is capable of it */
101		CHKO(OVERLAY_COUNT);
102		CHKO(OVERLAY_SUPPORTED_SPACES);
103		CHKO(OVERLAY_SUPPORTED_FEATURES);
104		CHKO(ALLOCATE_OVERLAY_BUFFER);
105		CHKO(RELEASE_OVERLAY_BUFFER);
106		CHKO(GET_OVERLAY_CONSTRAINTS);
107		CHKO(ALLOCATE_OVERLAY);
108		CHKO(RELEASE_OVERLAY);
109		CHKO(CONFIGURE_OVERLAY);
110
111		/*
112		When requesting an acceleration hook, the calling application provides a
113		pointer to the display_mode for which the acceleration function will be used.
114		Depending on the engine architecture, you may choose to provide a different
115		function to be used with each bit-depth.  In the sample driver we return
116		the same function all the time.
117
118		Note: These hooks are re-acquired by the app_server after each mode switch.
119		*/
120
121		/* only export 2D acceleration functions in modes that are capable of it */
122		/* used by the app_server and applications (BWindowScreen) */
123		CHKA(SCREEN_TO_SCREEN_BLIT);
124		CHKA(FILL_RECTANGLE);
125		CHKA(INVERT_RECTANGLE);
126		CHKA(FILL_SPAN);
127		/* not (yet) used by the app_server:
128		 * so just for application use (BWindowScreen) */
129//		CHKA(SCREEN_TO_SCREEN_TRANSPARENT_BLIT);
130		CHKA(SCREEN_TO_SCREEN_SCALED_FILTERED_BLIT);
131	}
132
133	/* Return a null pointer for any feature we don't understand. */
134	return 0;
135}
136#undef CHKO
137#undef CHKA
138#undef CHKD
139#undef HOOK
140#undef ZERO
141#undef HRDC
142
143status_t check_overlay_capability(uint32 feature)
144{
145	char *msg = "";
146
147	/* setup logmessage text */
148	switch (feature)
149	{
150	case B_OVERLAY_COUNT:
151		msg = "B_OVERLAY_COUNT";
152		break;
153	case B_OVERLAY_SUPPORTED_SPACES:
154		msg = "B_OVERLAY_SUPPORTED_SPACES";
155		break;
156	case B_OVERLAY_SUPPORTED_FEATURES:
157		msg = "B_OVERLAY_SUPPORTED_FEATURES";
158		break;
159	case B_ALLOCATE_OVERLAY_BUFFER:
160		msg = "B_ALLOCATE_OVERLAY_BUFFER";
161		break;
162	case B_RELEASE_OVERLAY_BUFFER:
163		msg = "B_RELEASE_OVERLAY_BUFFER";
164		break;
165	case B_GET_OVERLAY_CONSTRAINTS:
166		msg = "B_GET_OVERLAY_CONSTRAINTS";
167		break;
168	case B_ALLOCATE_OVERLAY:
169		msg = "B_ALLOCATE_OVERLAY";
170		break;
171	case B_RELEASE_OVERLAY:
172		msg = "B_RELEASE_OVERLAY";
173		break;
174	case B_CONFIGURE_OVERLAY:
175		msg = "B_CONFIGURE_OVERLAY";
176		break;
177	default:
178		msg = "UNKNOWN";
179		break;
180	}
181
182	/* all older cards have a supported bes */
183	if ((si->ps.card_type <= NV40) || (si->ps.card_type == NV45))
184	{
185		LOG(4, ("Overlay: Exporting hook %s.\n", msg));
186		return B_OK;
187	}
188
189	/* all newer NV40 architecture cards have a new HDTV capable bes except for
190	 * GeForce 6800's. Unfortunately we have no info about the new bes yet. */
191	LOG(4, ("Overlay: Not exporting hook %s.\n", msg));
192	return B_ERROR;
193}
194
195status_t check_acc_capability(uint32 feature)
196{
197	char *msg = "";
198
199	/* setup logmessage text */
200	switch (feature)
201	{
202	case B_SCREEN_TO_SCREEN_BLIT:
203		msg = "B_SCREEN_TO_SCREEN_BLIT";
204		break;
205	case B_FILL_RECTANGLE:
206		msg = "B_FILL_RECTANGLE";
207		break;
208	case B_INVERT_RECTANGLE:
209		msg = "B_INVERT_RECTANGLE";
210		break;
211	case B_FILL_SPAN:
212		msg = "B_FILL_SPAN";
213		break;
214	case B_SCREEN_TO_SCREEN_TRANSPARENT_BLIT:
215		msg = "B_SCREEN_TO_SCREEN_TRANSPARENT_BLIT";
216		break;
217	case B_SCREEN_TO_SCREEN_SCALED_FILTERED_BLIT:
218		msg = "B_SCREEN_TO_SCREEN_SCALED_FILTERED_BLIT";
219		/* this function is only defined for DMA acceleration,
220		 * but doesn't support the B_CMAP8 colorspace */
221		//fixme: checkout B_CMAP8 support sometime, as some cards seem to support it?
222		if (!si->settings.dma_acc || (si->dm.space == B_CMAP8))
223		{
224			LOG(4, ("Acc: Not exporting hook %s.\n", msg));
225			return B_ERROR;
226		}
227		break;
228	default:
229		msg = "UNKNOWN";
230		break;
231	}
232
233	/* hardware acceleration is only supported in modes with upto a certain
234	 * memory pitch.. and acceleration must not be blocked */
235	if (si->acc_mode && !si->settings.block_acc)
236	{
237		LOG(4, ("Acc: Exporting hook %s.\n", msg));
238		return B_OK;
239	}
240	else
241	{
242		LOG(4, ("Acc: Not exporting hook %s.\n", msg));
243		return B_ERROR;
244	}
245}
246