VirtualBox

source: vbox/trunk/src/VBox/Additions/haiku/VBoxVideo/accelerant/accelerant.cpp@ 43364

Last change on this file since 43364 was 43364, checked in by vboxsync, 12 years ago

Haiku Additions: cleanup.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 12.7 KB
Line 
1/* $Id: accelerant.cpp 43364 2012-09-20 12:12:09Z vboxsync $ */
2/** @file
3 * VBoxVideo Accelerant; Haiku Guest Additions, implementation.
4 */
5
6/*
7 * Copyright (C) 2012 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 */
17
18/*
19 * This code is based on:
20 *
21 * VirtualBox Guest Additions for Haiku.
22 * Copyright (c) 2011 Mike Smith <[email protected]>
23 * François Revol <[email protected]>
24 *
25 * Permission is hereby granted, free of charge, to any person
26 * obtaining a copy of this software and associated documentation
27 * files (the "Software"), to deal in the Software without
28 * restriction, including without limitation the rights to use,
29 * copy, modify, merge, publish, distribute, sublicense, and/or sell
30 * copies of the Software, and to permit persons to whom the
31 * Software is furnished to do so, subject to the following
32 * conditions:
33 *
34 * The above copyright notice and this permission notice shall be
35 * included in all copies or substantial portions of the Software.
36 *
37 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
38 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
39 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
40 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
41 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
42 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
43 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
44 * OTHER DEALINGS IN THE SOFTWARE.
45 */
46
47#include <Accelerant.h>
48#include "accelerant.h"
49#include <stdio.h>
50#include <string.h>
51#include <errno.h>
52
53#define TRACE(x...) do { FILE* logfile = fopen("/var/log/vboxvideo.accelerant.log", "a"); fprintf(logfile, x); fflush(logfile); fsync(fileno(logfile)); fclose(logfile); sync(); } while(0)
54
55class AreaCloner
56{
57 public:
58 AreaCloner() : fArea(-1) { }
59 ~AreaCloner()
60 {
61 if (fArea >= B_OK)
62 delete_area(fArea);
63 }
64
65 area_id Clone(const char *name, void **_address, uint32 spec, uint32 protection, area_id sourceArea)
66 {
67 fArea = clone_area(name, _address, spec, protection, sourceArea);
68 return fArea;
69 }
70
71 status_t InitCheck() { return fArea < B_OK ? (status_t)fArea : B_OK; }
72 void Keep() { fArea = -1; }
73
74 private:
75 area_id fArea;
76};
77
78AccelerantInfo gInfo;
79
80static engine_token sEngineToken = { 1, 0 /*B_2D_ACCELERATION*/, NULL };
81
82extern "C"
83void* get_accelerant_hook(uint32 feature, void *data)
84{
85 TRACE("%s\n", __FUNCTION__);
86 switch (feature)
87 {
88 /* general */
89 case B_INIT_ACCELERANT:
90 return (void *)vboxvideo_init_accelerant;
91 case B_UNINIT_ACCELERANT:
92 return (void *)vboxvideo_uninit_accelerant;
93 case B_CLONE_ACCELERANT:
94 return (void *)vboxvideo_clone_accelerant;
95 case B_ACCELERANT_CLONE_INFO_SIZE:
96 return (void *)vboxvideo_accelerant_clone_info_size;
97 case B_GET_ACCELERANT_CLONE_INFO:
98 return (void *)vboxvideo_get_accelerant_clone_info;
99 case B_GET_ACCELERANT_DEVICE_INFO:
100 return (void *)vboxvideo_get_accelerant_device_info;
101 case B_ACCELERANT_RETRACE_SEMAPHORE:
102 return (void *)vboxvideo_accelerant_retrace_semaphore;
103
104 /* mode configuration */
105 case B_ACCELERANT_MODE_COUNT:
106 return (void *)vboxvideo_accelerant_mode_count;
107 case B_GET_MODE_LIST:
108 return (void *)vboxvideo_get_mode_list;
109 case B_SET_DISPLAY_MODE:
110 return (void *)vboxvideo_set_display_mode;
111 case B_GET_DISPLAY_MODE:
112 return (void *)vboxvideo_get_display_mode;
113 case B_GET_EDID_INFO:
114 return (void *)vboxvideo_get_edid_info;
115 case B_GET_FRAME_BUFFER_CONFIG:
116 return (void *)vboxvideo_get_frame_buffer_config;
117 case B_GET_PIXEL_CLOCK_LIMITS:
118 return (void *)vboxvideo_get_pixel_clock_limits;
119
120 /* cursor managment */
121 /*case B_SET_CURSOR_SHAPE:
122 return (void*)vboxvideo_set_cursor_shape;
123 case B_MOVE_CURSOR:
124 return (void*)vboxvideo_move_cursor;
125 case B_SHOW_CURSOR:
126 return (void*)vboxvideo_show_cursor;*/
127
128 /* engine/synchronization */
129 case B_ACCELERANT_ENGINE_COUNT:
130 return (void *)vboxvideo_accelerant_engine_count;
131 case B_ACQUIRE_ENGINE:
132 return (void *)vboxvideo_acquire_engine;
133 case B_RELEASE_ENGINE:
134 return (void *)vboxvideo_release_engine;
135 case B_WAIT_ENGINE_IDLE:
136 return (void *)vboxvideo_wait_engine_idle;
137 case B_GET_SYNC_TOKEN:
138 return (void *)vboxvideo_get_sync_token;
139 case B_SYNC_TO_TOKEN:
140 return (void *)vboxvideo_sync_to_token;
141 }
142
143 return NULL;
144}
145
146status_t vboxvideo_init_common(int fd, bool cloned)
147{
148 unlink("/var/log/vboxvideo.accelerant.log"); // clear old log - next TRACE() will recreate it
149 TRACE("%s\n", __FUNCTION__);
150
151 gInfo.deviceFD = fd;
152 gInfo.isClone = cloned;
153 gInfo.sharedInfo = NULL;
154 gInfo.sharedInfoArea = -1;
155
156 area_id sharedArea;
157 if (ioctl(gInfo.deviceFD, VBOXVIDEO_GET_PRIVATE_DATA, &sharedArea, sizeof(area_id)) != 0)
158 {
159 TRACE("ioctl failed\n");
160 return B_ERROR;
161 }
162
163 AreaCloner sharedCloner;
164 gInfo.sharedInfoArea = sharedCloner.Clone("vboxvideo shared info",
165 (void **)&gInfo.sharedInfo, B_ANY_ADDRESS,
166 B_READ_AREA | B_WRITE_AREA, sharedArea);
167 status_t status = sharedCloner.InitCheck();
168 if (status < B_OK)
169 {
170 TRACE("InitCheck failed (%s)\n", strerror(status));
171 return status;
172 }
173 sharedCloner.Keep();
174
175 return B_OK;
176}
177
178status_t vboxvideo_init_accelerant(int fd)
179{
180 return vboxvideo_init_common(fd, false);
181}
182
183ssize_t vboxvideo_accelerant_clone_info_size(void)
184{
185 TRACE("%s\n", __FUNCTION__);
186 return B_PATH_NAME_LENGTH;
187}
188
189void vboxvideo_get_accelerant_clone_info(void *data)
190{
191 TRACE("%s\n", __FUNCTION__);
192 ioctl(gInfo.deviceFD, VBOXVIDEO_GET_DEVICE_NAME, data, B_PATH_NAME_LENGTH);
193}
194
195status_t vboxvideo_clone_accelerant(void *data)
196{
197 TRACE("%s\n", __FUNCTION__);
198
199 // create full device name
200 char path[MAXPATHLEN];
201 strcpy(path, "/dev/");
202 strcat(path, (const char *)data);
203
204 int fd = open(path, B_READ_WRITE);
205 if (fd < 0)
206 return errno;
207
208 return vboxvideo_init_common(fd, true);
209}
210
211void vboxvideo_uninit_accelerant(void)
212{
213 delete_area(gInfo.sharedInfoArea);
214 gInfo.sharedInfo = NULL;
215 gInfo.sharedInfoArea = -1;
216
217 if (gInfo.isClone)
218 close(gInfo.deviceFD);
219
220 TRACE("%s\n", __FUNCTION__);
221}
222
223status_t vboxvideo_get_accelerant_device_info(accelerant_device_info *adi)
224{
225 TRACE("%s\n", __FUNCTION__);
226 adi->version = B_ACCELERANT_VERSION;
227 strcpy(adi->name, "Virtual display");
228 strcpy(adi->chipset, "VirtualBox Graphics Adapter");
229 strcpy(adi->serial_no, "9001");
230 return B_OK;
231}
232
233sem_id vboxvideo_accelerant_retrace_semaphore(void)
234{
235 TRACE("%s\n", __FUNCTION__);
236 return -1;
237}
238
239// modes & constraints
240uint32 vboxvideo_accelerant_mode_count(void)
241{
242 TRACE("%s\n", __FUNCTION__);
243 return 1;
244}
245
246status_t vboxvideo_get_mode_list(display_mode *dm)
247{
248 // TODO return some standard modes here
249 TRACE("%s\n", __FUNCTION__);
250 return vboxvideo_get_display_mode(dm);
251}
252
253status_t vboxvideo_set_display_mode(display_mode *modeToSet)
254{
255 TRACE("%s\n", __FUNCTION__);
256 TRACE("trying to set mode %dx%d\n", modeToSet->timing.h_display, modeToSet->timing.v_display);
257 return ioctl(gInfo.deviceFD, VBOXVIDEO_SET_DISPLAY_MODE, modeToSet, sizeof(display_mode));
258}
259
260status_t vboxvideo_get_display_mode(display_mode *currentMode)
261{
262 TRACE("%s\n", __FUNCTION__);
263 *currentMode = gInfo.sharedInfo->currentMode;
264 TRACE("current mode is %dx%d\n", currentMode->timing.h_display, currentMode->timing.v_display);
265 return B_OK;
266}
267
268status_t vboxvideo_get_edid_info(void *info, size_t size, uint32 *_version)
269{
270 TRACE("%s\n", __FUNCTION__);
271
272 // copied from the X11 implementation:
273 static const uint8 edid_data[128] = {
274 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, /* header */
275 0x58, 0x58, /* manufacturer (VBX) */
276 0x00, 0x00, /* product code */
277 0x00, 0x00, 0x00, 0x00, /* serial number goes here */
278 0x01, /* week of manufacture */
279 0x00, /* year of manufacture */
280 0x01, 0x03, /* EDID version */
281 0x80, /* capabilities - digital */
282 0x00, /* horiz. res in cm, zero for projectors */
283 0x00, /* vert. res in cm */
284 0x78, /* display gamma (120 == 2.2). Should we ask the host for this? */
285 0xEE, /* features (standby, suspend, off, RGB, standard colour space,
286 * preferred timing mode) */
287 0xEE, 0x91, 0xA3, 0x54, 0x4C, 0x99, 0x26, 0x0F, 0x50, 0x54,
288 /* chromaticity for standard colour space - should we ask the host? */
289 0x00, 0x00, 0x00, /* no default timings */
290 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
291 0x01, 0x01, 0x01, 0x01, /* no standard timings */
292 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
293 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* descriptor block 1 goes here */
294 0x00, 0x00, 0x00, 0xFD, 0x00, /* descriptor block 2, monitor ranges */
295 0x00, 0xC8, 0x00, 0xC8, 0x64, 0x00, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20,
296 0x20, /* 0-200Hz vertical, 0-200KHz horizontal, 1000MHz pixel clock */
297 0x00, 0x00, 0x00, 0xFC, 0x00, /* descriptor block 3, monitor name */
298 'V', 'B', 'O', 'X', ' ', 'm', 'o', 'n', 'i', 't', 'o', 'r', '\n',
299 0x00, 0x00, 0x00, 0x10, 0x00, /* descriptor block 4: dummy data */
300 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
301 0x20,
302 0x00, /* number of extensions */
303 0x00 /* checksum goes here */
304 };
305
306 if (size < 128)
307 return B_BUFFER_OVERFLOW;
308
309 *_version = 1; /*EDID_VERSION_1*/
310 memcpy(info, edid_data, 128);
311 return B_OK;
312}
313
314status_t vboxvideo_get_frame_buffer_config(frame_buffer_config *config)
315{
316 TRACE("%s\n", __FUNCTION__);
317 config->frame_buffer = gInfo.sharedInfo->framebuffer;
318 config->frame_buffer_dma = NULL;
319 config->bytes_per_row = get_depth_for_color_space(gInfo.sharedInfo->currentMode.space)
320 * gInfo.sharedInfo->currentMode.timing.h_display / 8;
321 return B_OK;
322}
323
324status_t vboxvideo_get_pixel_clock_limits(display_mode *dm, uint32 *low, uint32 *high)
325{
326 TRACE("%s\n", __FUNCTION__);
327 // irrelevant for virtual monitors
328 *low = 0;
329 *high = 9001;
330 return B_OK;
331}
332
333// cursor
334status_t vboxvideo_set_cursor_shape(uint16 width, uint16 height, uint16 hotX, uint16 hotY, uint8 *andMask, uint8 *xorMask)
335{
336 TRACE("%s\n", __FUNCTION__);
337 // VBoxHGSMIUpdatePointerShape
338 return B_UNSUPPORTED;
339}
340
341void vboxvideo_move_cursor(uint16 x, uint16 y)
342{
343 TRACE("%s\n", __FUNCTION__);
344}
345
346void vboxvideo_show_cursor(bool is_visible)
347{
348 TRACE("%s\n", __FUNCTION__);
349}
350
351// accelerant engine
352uint32 vboxvideo_accelerant_engine_count(void)
353{
354 TRACE("%s\n", __FUNCTION__);
355 return 1;
356}
357
358status_t vboxvideo_acquire_engine(uint32 capabilities, uint32 maxWait, sync_token *st, engine_token **et)
359{
360 TRACE("%s\n", __FUNCTION__);
361 *et = &sEngineToken;
362 return B_OK;
363}
364
365status_t vboxvideo_release_engine(engine_token *et, sync_token *st)
366{
367 TRACE("%s\n", __FUNCTION__);
368 if (st != NULL)
369 st->engine_id = et->engine_id;
370
371 return B_OK;
372}
373
374void vboxvideo_wait_engine_idle(void)
375{
376 TRACE("%s\n", __FUNCTION__);
377}
378
379status_t vboxvideo_get_sync_token(engine_token *et, sync_token *st)
380{
381 TRACE("%s\n", __FUNCTION__);
382 return B_OK;
383}
384
385status_t vboxvideo_sync_to_token(sync_token *st)
386{
387 TRACE("%s\n", __FUNCTION__);
388 return B_OK;
389}
390
391// 2D acceleration
392void vboxvideo_screen_to_screen_blit(engine_token *et, blit_params *list, uint32 count)
393{
394 TRACE("%s\n", __FUNCTION__);
395}
396
397void vboxvideo_fill_rectangle(engine_token *et, uint32 color, fill_rect_params *list, uint32 count)
398{
399 TRACE("%s\n", __FUNCTION__);
400}
401
402void vboxvideo_invert_rectangle(engine_token *et, fill_rect_params *list, uint32 count)
403{
404 TRACE("%s\n", __FUNCTION__);
405}
406
407void vboxvideo_fill_span(engine_token *et, uint32 color, uint16 *list, uint32 count)
408{
409 TRACE("%s\n", __FUNCTION__);
410}
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette