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