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