tcp: Add APICall trace entry and move TRACEs into locked parts.
[haiku.git] / src / add-ons / accelerants / vesa / hooks.cpp
blob5563119fc02022706df253d859fc587ced8cd11d
1 /*
2 * Copyright 2005-2012, Axel Dörfler, axeld@pinc-software.de.
3 * All rights reserved. Distributed under the terms of the MIT License.
4 */
7 #include "accelerant_protos.h"
8 #include "accelerant.h"
10 #include <new>
13 #define FAKE_OVERLAY_SUPPORT 0
14 // Enables a fake overlay support, making the app_server believe it can
15 // use overlays with this driver; the actual buffers are in the frame
16 // buffer so the on-screen graphics will be messed up.
18 #define FAKE_HARDWARE_CURSOR_SUPPORT 0
19 // Enables the faking of a hardware cursor. The cursor will not be
20 // visible, but it will still function.
23 #if FAKE_OVERLAY_SUPPORT
24 static int32 sOverlayToken;
25 static int32 sOverlayChannelUsed;
28 static uint32
29 vesa_overlay_count(const display_mode* mode)
31 return 1;
35 static const uint32*
36 vesa_overlay_supported_spaces(const display_mode* mode)
38 static const uint32 kSupportedSpaces[] = {B_RGB15, B_RGB16, B_RGB32,
39 B_YCbCr422, 0};
41 return kSupportedSpaces;
45 static uint32
46 vesa_overlay_supported_features(uint32 colorSpace)
48 return B_OVERLAY_COLOR_KEY
49 | B_OVERLAY_HORIZONTAL_FILTERING
50 | B_OVERLAY_VERTICAL_FILTERING
51 | B_OVERLAY_HORIZONTAL_MIRRORING;
55 static const overlay_buffer*
56 vesa_allocate_overlay_buffer(color_space colorSpace, uint16 width,
57 uint16 height)
59 debug_printf("allocate_overlay_buffer(width %u, height %u, colorSpace %u)\n",
60 width, height, colorSpace);
62 overlay_buffer* buffer = new(std::nothrow) overlay_buffer;
63 if (buffer == NULL)
64 return NULL;
66 buffer->space = colorSpace;
67 buffer->width = width;
68 buffer->height = height;
69 buffer->bytes_per_row = gInfo->shared_info->bytes_per_row;
71 buffer->buffer = gInfo->shared_info->frame_buffer;
72 buffer->buffer_dma = (uint8*)gInfo->shared_info->physical_frame_buffer;
74 return buffer;
78 static status_t
79 vesa_release_overlay_buffer(const overlay_buffer* buffer)
81 debug_printf("release_overlay_buffer(buffer %p)\n", buffer);
83 delete buffer;
84 return B_OK;
88 static status_t
89 vesa_get_overlay_constraints(const display_mode* mode,
90 const overlay_buffer* buffer, overlay_constraints* constraints)
92 debug_printf("get_overlay_constraints(buffer %p)\n", buffer);
94 // position
95 constraints->view.h_alignment = 0;
96 constraints->view.v_alignment = 0;
98 // alignment
99 constraints->view.width_alignment = 7;
100 constraints->view.height_alignment = 0;
102 // size
103 constraints->view.width.min = 4;
104 constraints->view.height.min = 4;
105 constraints->view.width.max = buffer->width;
106 constraints->view.height.max = buffer->height;
108 // scaler output restrictions
109 constraints->window.h_alignment = 0;
110 constraints->window.v_alignment = 0;
111 constraints->window.width_alignment = 0;
112 constraints->window.height_alignment = 0;
113 constraints->window.width.min = 2;
114 constraints->window.width.max = mode->virtual_width;
115 constraints->window.height.min = 2;
116 constraints->window.height.max = mode->virtual_height;
118 constraints->h_scale.min = 1.0f / (1 << 4);
119 constraints->h_scale.max = buffer->width * 7;
120 constraints->v_scale.min = 1.0f / (1 << 4);
121 constraints->v_scale.max = buffer->height * 7;
123 return B_OK;
127 static overlay_token
128 vesa_allocate_overlay()
130 debug_printf("allocate_overlay()\n");
132 // we only use a single overlay channel
133 if (atomic_or(&sOverlayChannelUsed, 1) != 0)
134 return NULL;
136 return (overlay_token)++sOverlayToken;
140 static status_t
141 vesa_release_overlay(overlay_token overlayToken)
143 debug_printf("allocate_overlay(token %ld)\n", (uint32)overlayToken);
145 if (overlayToken != (overlay_token)sOverlayToken)
146 return B_BAD_VALUE;
148 atomic_and(&sOverlayChannelUsed, 0);
150 return B_OK;
154 static status_t
155 vesa_configure_overlay(overlay_token overlayToken, const overlay_buffer* buffer,
156 const overlay_window* window, const overlay_view* view)
158 debug_printf("configure_overlay: buffer %p, window %p, view %p\n",
159 buffer, window, view);
160 return B_OK;
162 #endif // FAKE_OVERLAY_SUPPORT
165 #if FAKE_HARDWARE_CURSOR_SUPPORT
166 status_t
167 vesa_set_cursor_shape(uint16 width, uint16 height, uint16 hotX, uint16 hotY,
168 const uint8* andMask, const uint8* xorMask)
170 return B_OK;
174 status_t
175 vesa_set_cursor_bitmap(uint16 width, uint16 height, uint16 hotX, uint16 hotY,
176 color_space colorSpace, uint16 bytesPerRow, const uint8* bitmapData)
178 return B_OK;
182 void
183 vesa_move_cursor(uint16 x, uint16 y)
188 void
189 vesa_show_cursor(bool isVisible)
192 #endif // # FAKE_HARDWARE_CURSOR_SUPPORT
195 extern "C" void*
196 get_accelerant_hook(uint32 feature, void* data)
198 switch (feature) {
199 /* general */
200 case B_INIT_ACCELERANT:
201 return (void*)vesa_init_accelerant;
202 case B_UNINIT_ACCELERANT:
203 return (void*)vesa_uninit_accelerant;
204 case B_CLONE_ACCELERANT:
205 return (void*)vesa_clone_accelerant;
206 case B_ACCELERANT_CLONE_INFO_SIZE:
207 return (void*)vesa_accelerant_clone_info_size;
208 case B_GET_ACCELERANT_CLONE_INFO:
209 return (void*)vesa_get_accelerant_clone_info;
210 case B_GET_ACCELERANT_DEVICE_INFO:
211 return (void*)vesa_get_accelerant_device_info;
212 case B_ACCELERANT_RETRACE_SEMAPHORE:
213 return (void*)vesa_accelerant_retrace_semaphore;
215 /* mode configuration */
216 case B_ACCELERANT_MODE_COUNT:
217 return (void*)vesa_accelerant_mode_count;
218 case B_GET_MODE_LIST:
219 return (void*)vesa_get_mode_list;
220 case B_PROPOSE_DISPLAY_MODE:
221 return (void*)vesa_propose_display_mode;
222 case B_SET_DISPLAY_MODE:
223 return (void*)vesa_set_display_mode;
224 case B_GET_DISPLAY_MODE:
225 return (void*)vesa_get_display_mode;
226 case B_GET_EDID_INFO:
227 return (void*)vesa_get_edid_info;
228 case B_GET_FRAME_BUFFER_CONFIG:
229 return (void*)vesa_get_frame_buffer_config;
230 case B_GET_PIXEL_CLOCK_LIMITS:
231 return (void*)vesa_get_pixel_clock_limits;
232 case B_MOVE_DISPLAY:
233 return (void*)vesa_move_display;
234 case B_SET_INDEXED_COLORS:
235 return (void*)vesa_set_indexed_colors;
236 case B_GET_TIMING_CONSTRAINTS:
237 return (void*)vesa_get_timing_constraints;
239 /* DPMS */
240 case B_DPMS_CAPABILITIES:
241 return (void*)vesa_dpms_capabilities;
242 case B_DPMS_MODE:
243 return (void*)vesa_dpms_mode;
244 case B_SET_DPMS_MODE:
245 return (void*)vesa_set_dpms_mode;
247 /* cursor managment */
248 #if FAKE_HARDWARE_CURSOR_SUPPORT
249 case B_SET_CURSOR_SHAPE:
250 return (void*)vesa_set_cursor_shape;
251 case B_MOVE_CURSOR:
252 return (void*)vesa_move_cursor;
253 case B_SHOW_CURSOR:
254 return (void*)vesa_show_cursor;
255 case B_SET_CURSOR_BITMAP:
256 return (void*)vesa_set_cursor_bitmap;
257 #endif
259 /* engine/synchronization */
260 case B_ACCELERANT_ENGINE_COUNT:
261 return (void*)vesa_accelerant_engine_count;
262 case B_ACQUIRE_ENGINE:
263 return (void*)vesa_acquire_engine;
264 case B_RELEASE_ENGINE:
265 return (void*)vesa_release_engine;
266 case B_WAIT_ENGINE_IDLE:
267 return (void*)vesa_wait_engine_idle;
268 case B_GET_SYNC_TOKEN:
269 return (void*)vesa_get_sync_token;
270 case B_SYNC_TO_TOKEN:
271 return (void*)vesa_sync_to_token;
273 #if FAKE_OVERLAY_SUPPORT
274 // overlay
275 case B_OVERLAY_COUNT:
276 return (void*)vesa_overlay_count;
277 case B_OVERLAY_SUPPORTED_SPACES:
278 return (void*)vesa_overlay_supported_spaces;
279 case B_OVERLAY_SUPPORTED_FEATURES:
280 return (void*)vesa_overlay_supported_features;
281 case B_ALLOCATE_OVERLAY_BUFFER:
282 return (void*)vesa_allocate_overlay_buffer;
283 case B_RELEASE_OVERLAY_BUFFER:
284 return (void*)vesa_release_overlay_buffer;
285 case B_GET_OVERLAY_CONSTRAINTS:
286 return (void*)vesa_get_overlay_constraints;
287 case B_ALLOCATE_OVERLAY:
288 return (void*)vesa_allocate_overlay;
289 case B_RELEASE_OVERLAY:
290 return (void*)vesa_release_overlay;
291 case B_CONFIGURE_OVERLAY:
292 return (void*)vesa_configure_overlay;
293 #endif // FAKE_OVERLAY_SUPPORT
296 return NULL;