Changeset 21771 in vbox
- Timestamp:
- Jul 22, 2009 5:50:48 PM (16 years ago)
- Location:
- trunk/src/VBox/Frontends/VBoxFB
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VBoxFB/Framebuffer.cpp
r19817 r21771 6 6 7 7 /* 8 * Copyright (C) 2006-200 7Sun Microsystems, Inc.8 * Copyright (C) 2006-2009 Sun Microsystems, Inc. 9 9 * 10 10 * This file is part of VirtualBox Open Source Edition (OSE), as … … 42 42 } 43 43 fbSurfaceLocked = 0; 44 uint32_tbitsPerPixel;44 PRUint32 bitsPerPixel; 45 45 GetBitsPerPixel(&bitsPerPixel); 46 46 fbPitch = fbWidth * (bitsPerPixel / 8); … … 65 65 } 66 66 67 NS_IMETHODIMP VBoxDirectFB::GetHeight( uint32_t*height)67 NS_IMETHODIMP VBoxDirectFB::GetHeight(PRUint32 *height) 68 68 { 69 69 if (!height) … … 130 130 } 131 131 132 NS_IMETHODIMP VBoxDirectFB::GetAddress( uint32_t*address)132 NS_IMETHODIMP VBoxDirectFB::GetAddress(PRUint8 **address) 133 133 { 134 134 if (!address) 135 135 return NS_ERROR_INVALID_POINTER; 136 *address = ( uint32_t)fbBufferAddress;137 return NS_OK; 138 } 139 140 NS_IMETHODIMP VBoxDirectFB::GetBitsPerPixel( uint32_t*bitsPerPixel)136 *address = (PRUint8 *)fbBufferAddress; 137 return NS_OK; 138 } 139 140 NS_IMETHODIMP VBoxDirectFB::GetBitsPerPixel(PRUint32 *bitsPerPixel) 141 141 { 142 142 if (!bitsPerPixel) … … 162 162 } 163 163 164 NS_IMETHODIMP VBoxDirectFB::GetBytesPerLine( uint32_t*bytesPerLine)164 NS_IMETHODIMP VBoxDirectFB::GetBytesPerLine(PRUint32 *bytesPerLine) 165 165 { 166 166 if (!bytesPerLine) … … 170 170 } 171 171 172 NS_IMETHODIMP VBoxDirectFB:: COMGETTER(PixelFormat) (ULONG*pixelFormat)172 NS_IMETHODIMP VBoxDirectFB::GetPixelFormat (PRUint32 *pixelFormat) 173 173 { 174 174 if (!pixelFormat) … … 178 178 } 179 179 180 NS_IMETHODIMP VBoxDirectFB:: COMGETTER(UsesGuestVRAM) (BOOL*usesGuestVRAM)180 NS_IMETHODIMP VBoxDirectFB::GetUsesGuestVRAM (PRBool *usesGuestVRAM) 181 181 { 182 182 if (!usesGuestVRAM) 183 183 return NS_ERROR_INVALID_POINTER; 184 *usesGuestVRAM = FALSE; 185 return NS_OK; 186 } 187 188 NS_IMETHODIMP VBoxDirectFB::NotifyUpdate(uint32_t x, uint32_t y, 189 uint32_t w, uint32_t h) 184 *usesGuestVRAM = false; 185 return NS_OK; 186 } 187 188 NS_IMETHODIMP VBoxDirectFB::GetHeightReduction(PRUint32 *heightReduction) 189 { 190 if (!heightReduction) 191 return NS_ERROR_INVALID_POINTER; 192 *heightReduction = 0; 193 return NS_OK; 194 } 195 196 NS_IMETHODIMP VBoxDirectFB::GetOverlay(IFramebufferOverlay **overlay) 197 { 198 if (!overlay) 199 return NS_ERROR_INVALID_POINTER; 200 /* Not yet implemented */ 201 *overlay = 0; 202 return NS_OK; 203 } 204 205 NS_IMETHODIMP VBoxDirectFB::GetWinId(PRUint64 *winId) 206 { 207 if (!winId) 208 return NS_ERROR_INVALID_POINTER; 209 *winId = 0; 210 return NS_OK; 211 } 212 213 NS_IMETHODIMP VBoxDirectFB::NotifyUpdate(PRUint32 x, PRUint32 y, 214 PRUint32 w, PRUint32 h) 190 215 { 191 216 // we only need to take action if we have a memory framebuffer … … 220 245 } 221 246 222 NS_IMETHODIMP VBoxDirectFB::RequestResize( ULONG aScreenId, ULONG pixelFormat, uint32_tvram,223 uint32_t bitsPerPixel, uint32_tbytesPerLine,224 uint32_t w, uint32_th,247 NS_IMETHODIMP VBoxDirectFB::RequestResize(PRUint32 aScreenId, PRUint32 pixelFormat, PRUint8 *vram, 248 PRUint32 bitsPerPixel, PRUint32 bytesPerLine, 249 PRUint32 w, PRUint32 h, 225 250 PRBool *finished) 226 251 { 227 252 uint32_t needsLocking = fbSurfaceLocked; 228 uint32_t bitsPerPixel; 229 230 GetBitsPerPixel(&bitsPerPixel); 231 printf("RequestResize: w = %d, h = %d, fbSurfaceLocked = %d\n", w, h, fbSurfaceLocked); 253 254 printf("RequestResize: aScreenId = %d, pixelFormat = %d, vram = %p, bitsPerPixel = %d, bytesPerLine = %d, w = %d, h = %d, fbSurfaceLocked = %d\n", aScreenId, pixelFormat, vram, bitsPerPixel, bytesPerLine, w, h, fbSurfaceLocked); 232 255 233 256 // we can't work with a locked surface … … 298 321 *finished = true; 299 322 return NS_OK; 323 } 324 325 NS_IMETHODIMP VBoxDirectFB::VideoModeSupported(PRUint32 w, PRUint32 h, PRUint32 bpp, PRBool *supported) 326 { 327 if (!supported) 328 return NS_ERROR_INVALID_POINTER; 329 *supported = true; 330 return NS_OK; 331 } 332 333 NS_IMETHODIMP VBoxDirectFB::GetVisibleRegion(PRUint8 *rectangles, PRUint32 count, PRUint32 *countCopied) 334 { 335 PRTRECT rects = (PRTRECT)rectangles; 336 337 if (!rects || !countCopied) 338 return NS_ERROR_INVALID_POINTER; 339 /** @todo */ 340 *countCopied = 0; 341 return NS_OK; 342 } 343 344 NS_IMETHODIMP VBoxDirectFB::SetVisibleRegion(PRUint8 *rectangles, PRUint32 count) 345 { 346 PRTRECT rects = (PRTRECT)rectangles; 347 348 if (!rects) 349 return NS_ERROR_INVALID_POINTER; 350 /** @todo */ 351 return NS_OK; 352 } 353 354 NS_IMETHODIMP VBoxDirectFB::ProcessVHWACommand(PRUint8 *command) 355 { 356 return NS_ERROR_NOT_IMPLEMENTED; 300 357 } 301 358 -
trunk/src/VBox/Frontends/VBoxFB/Framebuffer.h
r19817 r21771 6 6 7 7 /* 8 * Copyright (C) 2006-200 7Sun Microsystems, Inc.8 * Copyright (C) 2006-2009 Sun Microsystems, Inc. 9 9 * 10 10 * This file is part of VirtualBox Open Source Edition (OSE), as … … 34 34 NS_DECL_ISUPPORTS 35 35 36 NS_IMETHOD GetWidth( uint32 *width);37 NS_IMETHOD GetHeight( uint32_t*height);36 NS_IMETHOD GetWidth(PRUint32 *width); 37 NS_IMETHOD GetHeight(PRUint32 *height); 38 38 NS_IMETHOD Lock(); 39 39 NS_IMETHOD Unlock(); 40 NS_IMETHOD GetAddress(uint32_t *address); 41 NS_IMETHOD GetBitsPerPixel(uint32_t *bitsPerPixel); 42 NS_IMETHOD GetBytesPerLine(uint32_t *bytesPerLine); 43 NS_IMETHOD GetPixelFormat(ULONG *pixelFormat); 44 NS_IMETHOD GetUsesGuestVRAM(BOOL *usesGuestVRAM); 45 NS_IMETHOD NotifyUpdate(uint32_t x, uint32_t y, 46 uint32_t w, uint32_t h); 47 NS_IMETHOD RequestResize(ULONG aScreenId, ULONG pixelFormat, uint32_t vram, 48 uint32_t bitsPerPixel, uint32_t bytesPerLine, 49 uint32_t w, uint32_t h, 40 NS_IMETHOD GetAddress(PRUint8 **address); 41 NS_IMETHOD GetBitsPerPixel(PRUint32 *bitsPerPixel); 42 NS_IMETHOD GetBytesPerLine(PRUint32 *bytesPerLine); 43 NS_IMETHOD GetPixelFormat(PRUint32 *pixelFormat); 44 NS_IMETHOD GetUsesGuestVRAM(PRBool *usesGuestVRAM); 45 NS_IMETHOD GetHeightReduction(PRUint32 *heightReduction); 46 NS_IMETHOD GetOverlay(IFramebufferOverlay **aOverlay); 47 NS_IMETHOD GetWinId(PRUint64 *winId); 48 NS_IMETHOD NotifyUpdate(PRUint32 x, PRUint32 y, PRUint32 w, PRUint32 h); 49 NS_IMETHOD RequestResize(PRUint32 aScreenId, PRUint32 pixelFormat, PRUint8 *vram, 50 PRUint32 bitsPerPixel, PRUint32 bytesPerLine, 51 PRUint32 w, PRUint32 h, 50 52 PRBool *finished); 53 NS_IMETHOD VideoModeSupported(PRUint32 width, PRUint32 height, PRUint32 bpp, PRBool *supported); 54 NS_IMETHOD GetVisibleRegion(PRUint8 *aRectangles, PRUint32 aCount, PRUint32 *aCountCopied); 55 NS_IMETHOD SetVisibleRegion(PRUint8 *aRectangles, PRUint32 aCount); 56 57 NS_IMETHOD ProcessVHWACommand(PRUint8 *pCommand); 58 51 59 private: 52 60 int createSurface(uint32_t w, uint32_t h); -
trunk/src/VBox/Frontends/VBoxFB/Helper.cpp
r8155 r21771 6 6 7 7 /* 8 * Copyright (C) 2006-200 7Sun Microsystems, Inc.8 * Copyright (C) 2006-2009 Sun Microsystems, Inc. 9 9 * 10 10 * This file is part of VirtualBox Open Source Edition (OSE), as … … 27 27 * Globals 28 28 */ 29 videoMode videoModes[MAX_VIDEOMODES] = { 0};29 videoMode videoModes[MAX_VIDEOMODES] = {{0}}; 30 30 uint32_t numVideoModes = 0; 31 31 -
trunk/src/VBox/Frontends/VBoxFB/Helper.h
r8155 r21771 6 6 7 7 /* 8 * Copyright (C) 2006-200 7Sun Microsystems, Inc.8 * Copyright (C) 2006-2009 Sun Microsystems, Inc. 9 9 * 10 10 * This file is part of VirtualBox Open Source Edition (OSE), as … … 25 25 26 26 #define MAX_VIDEOMODES 64 27 typedefstruct videoMode27 struct videoMode 28 28 { 29 29 uint32_t width; -
trunk/src/VBox/Frontends/VBoxFB/Makefile.kmk
r12258 r21771 5 5 6 6 # 7 # Copyright (C) 2006-200 7Sun Microsystems, Inc.7 # Copyright (C) 2006-2009 Sun Microsystems, Inc. 8 8 # 9 9 # This file is part of VirtualBox Open Source Edition (OSE), as … … 23 23 include $(KBUILD_PATH)/subheader.kmk 24 24 25 PROGRAMS += VBoxFB 26 25 27 # 26 28 # VBoxFB 27 29 # 28 PROGRAMS += VBoxFB 29 VBoxFB_SOURCES 30 VBoxFB_TEMPLATE = VBOXR3NPEXE 31 VBoxFB_SOURCES = \ 30 32 VBoxFB.cpp \ 31 33 Framebuffer.cpp \ 32 34 Helper.cpp 33 VBoxFB_ DEFS = IN_RING3 IN_RT_R3 _GNU_SOURCE35 VBoxFB_CXXFLAGS = -Wno-non-virtual-dtor -fshort-wchar 34 36 ifdef VBOX_WITH_XPCOM_NAMESPACE_CLEANUP 35 37 VBoxFB_DEFS += VBOX_WITH_XPCOM_NAMESPACE_CLEANUP 36 38 endif 37 VBoxFB_INCS = \ 38 /usr/include/directfb \ 39 $(VBOX_PATH_SDK)/include \ 40 $(VBOX_XPCOM_INCS) 41 VBoxFB_LIBS = \ 42 $(PATH_LIB)/VBoxCOM$(VBOX_SUFF_LIB) \ 43 $(LIB_RUNTIME) \ 44 xpcomglue \ 45 nspr4 \ 46 plc4 \ 47 $(LIB_PTHREAD) \ 48 rt \ 49 directfb 50 VBoxFB_LIBPATH = \ 51 $(LIBPATH_XPCOM) 52 VBoxFB_CXXFLAGS = \ 53 -DNDEBUG -DTRIMMED -O -Wall -fno-rtti -fno-exceptions \ 54 -Wno-non-virtual-dtor -Wno-long-long -fshort-wchar -pthread -pipe 39 VBoxFB_INCS = $(VBOX_XPCOM_INCS) /usr/include/directfb 40 VBoxFB_LIBPATH = $(LIBPATH_XPCOM) 41 VBoxFB_LIBS = $(LIB_XPCOM) $(LIB_RUNTIME) directfb 42 VBoxFB_DEPS = $(VBOX_PATH_SDK)/bindings/xpcom/include/VirtualBox_XPCOM.h 55 43 44 # generate rules. 56 45 include $(KBUILD_PATH)/subfooter.kmk 57 46 -
trunk/src/VBox/Frontends/VBoxFB/VBoxFB.cpp
r19924 r21771 2 2 * 3 3 * VBox frontends: Framebuffer (FB, DirectFB): 4 * main() routine 4 * main() routine. 5 * 6 * NOTE: this code has not been tested, so expect bugs. It is not part 7 * of a regular VirtualBox build. 5 8 */ 6 9 7 10 /* 8 * Copyright (C) 2006-200 7Sun Microsystems, Inc.11 * Copyright (C) 2006-2009 Sun Microsystems, Inc. 9 12 * 10 13 * This file is part of VirtualBox Open Source Edition (OSE), as … … 49 52 int main(int argc, char *argv[]) 50 53 { 51 nsID uuid;54 const char *uuid = NULL; 52 55 int c; 53 56 int listHostModes = 0; … … 63 66 64 67 printf("VirtualBox DirectFB GUI built %s %s\n" 65 "(C) 2004-200 8Sun Microsystems, Inc.\n"68 "(C) 2004-2009 Sun Microsystems, Inc.\n" 66 69 "(C) 2004-2005 secunet Security Networks AG\n", __DATE__, __TIME__); 67 68 RTUuidClear((PRTUUID)&uuid);69 70 70 71 for (;;) … … 84 85 { 85 86 // UUID as string, parse it 86 if (!RT_SUCCESS(RTUuidFromStr((PRTUUID)&uuid, optarg))) 87 RTUUID buuid; 88 if (!RT_SUCCESS(RTUuidFromStr((PRTUUID)&buuid, optarg))) 87 89 { 88 90 printf("Error, invalid UUID format given!\n"); … … 90 92 exit(-1); 91 93 } 94 uuid = optarg; 92 95 break; 93 96 } … … 120 123 121 124 // check if we got a UUID 122 if ( RTUuidIsNull((PRTUUID)&uuid))125 if (!uuid) 123 126 { 124 127 printf("Error, no UUID given!\n"); … … 133 136 134 137 nsresult rc; 135 XPCOMGlueStartup(nsnull); 136 137 // get the path to the executable 138 char appPath [RTPATH_MAX]; 139 RTPathExecDir (appPath, RTPATH_MAX); 140 141 nsCOMPtr<nsIFile> nsAppPath; 138 /* 139 * Note that we scope all nsCOMPtr variables in order to have all XPCOM 140 * objects automatically released before we call NS_ShutdownXPCOM at the 141 * end. This is an XPCOM requirement. 142 */ 142 143 { 143 nsCOMPtr<nsILocalFile> file; 144 rc = NS_NewNativeLocalFile(nsEmbedCString (appPath), PR_FALSE, 145 getter_AddRefs (file)); 146 if (NS_SUCCEEDED(rc)) 147 { 148 nsAppPath = do_QueryInterface(file, &rc); 144 nsCOMPtr<nsIServiceManager> serviceManager; 145 rc = NS_InitXPCOM2(getter_AddRefs(serviceManager), nsnull, nsnull); 146 if (NS_FAILED(rc)) 147 { 148 printf("Error: XPCOM could not be initialized! rc=0x%x\n", rc); 149 exit(-1); 150 } 151 152 // register our component 153 nsCOMPtr<nsIComponentRegistrar> registrar = do_QueryInterface(serviceManager); 154 if (!registrar) 155 { 156 printf("Error: could not query nsIComponentRegistrar interface!\n"); 157 exit(-1); 158 } 159 registrar->AutoRegister(nsnull); 160 161 /* 162 * Make sure the main event queue is created. This event queue is 163 * responsible for dispatching incoming XPCOM IPC messages. The main 164 * thread should run this event queue's loop during lengthy non-XPCOM 165 * operations to ensure messages from the VirtualBox server and other 166 * XPCOM IPC clients are processed. This use case doesn't perform such 167 * operations so it doesn't run the event loop. 168 */ 169 nsCOMPtr<nsIEventQueue> eventQ; 170 rc = NS_GetMainEventQ(getter_AddRefs (eventQ)); 171 if (NS_FAILED(rc)) 172 { 173 printf("Error: could not get main event queue! rc=%08X\n", rc); 174 return -1; 175 } 176 177 /* 178 * Now XPCOM is ready and we can start to do real work. 179 * IVirtualBox is the root interface of VirtualBox and will be 180 * retrieved from the XPCOM component manager. We use the 181 * XPCOM provided smart pointer nsCOMPtr for all objects because 182 * that's very convenient and removes the need deal with reference 183 * counting and freeing. 184 */ 185 nsCOMPtr<nsIComponentManager> manager; 186 rc = NS_GetComponentManager (getter_AddRefs (manager)); 187 if (NS_FAILED(rc)) 188 { 189 printf("Error: could not get component manager! rc=%08X\n", rc); 190 exit(-1); 191 } 192 193 nsCOMPtr<IVirtualBox> virtualBox; 194 rc = manager->CreateInstanceByContractID(NS_VIRTUALBOX_CONTRACTID, 195 nsnull, 196 NS_GET_IID(IVirtualBox), 197 getter_AddRefs(virtualBox)); 198 if (NS_FAILED(rc)) 199 { 200 printf("Error, could not instantiate object! rc=0x%x\n", rc); 201 exit(-1); 202 } 203 204 nsCOMPtr<ISession> session; 205 rc = manager->CreateInstance(CLSID_Session, 206 nsnull, 207 NS_GET_IID(ISession), 208 getter_AddRefs(session)); 209 if (NS_FAILED(rc)) 210 { 211 printf("Error: could not instantiate Session object! rc = %08X\n", rc); 212 exit(-1); 213 } 214 215 // open session for this VM 216 rc = virtualBox->OpenSession(session, NS_ConvertUTF8toUTF16(uuid).get()); 217 if (NS_FAILED(rc)) 218 { 219 printf("Error: given machine not found!\n"); 220 exit(-1); 221 } 222 nsCOMPtr<IMachine> machine; 223 session->GetMachine(getter_AddRefs(machine)); 224 if (!machine) 225 { 226 printf("Error: given machine not found!\n"); 227 exit(-1); 228 } 229 nsCOMPtr<IConsole> console; 230 session->GetConsole(getter_AddRefs(console)); 231 if (!console) 232 { 233 printf("Error: cannot get console!\n"); 234 exit(-1); 235 } 236 237 nsCOMPtr<IDisplay> display; 238 console->GetDisplay(getter_AddRefs(display)); 239 if (!display) 240 { 241 printf("Error: could not get display object!\n"); 242 exit(-1); 243 } 244 245 nsCOMPtr<IKeyboard> keyboard; 246 nsCOMPtr<IMouse> mouse; 247 VBoxDirectFB *frameBuffer = NULL; 248 249 /** 250 * Init DirectFB 251 */ 252 IDirectFB *dfb = NULL; 253 IDirectFBSurface *surface = NULL; 254 IDirectFBInputDevice *dfbKeyboard = NULL; 255 IDirectFBInputDevice *dfbMouse = NULL; 256 IDirectFBEventBuffer *dfbEventBuffer = NULL; 257 DFBSurfaceDescription dsc; 258 int screen_width, screen_height; 259 260 DFBCHECK(DirectFBInit(&argc, &argv)); 261 DFBCHECK(DirectFBCreate(&dfb)); 262 DFBCHECK(dfb->SetCooperativeLevel(dfb, DFSCL_FULLSCREEN)); 263 // populate our structure of supported video modes 264 DFBCHECK(dfb->EnumVideoModes(dfb, enumVideoModesHandler, NULL)); 265 266 if (listHostModes) 267 { 268 printf("*****************************************************\n"); 269 printf("Number of available host video modes: %u\n", numVideoModes); 270 for (uint32_t i = 0; i < numVideoModes; i++) 271 { 272 printf("Mode %u: xres = %u, yres = %u, bpp = %u\n", i, 273 videoModes[i].width, videoModes[i].height, videoModes[i].bpp); 274 } 275 printf("Note: display modes with bpp < have been filtered out\n"); 276 printf("*****************************************************\n"); 277 goto Leave; 278 } 279 280 if (useFixedVideoMode) 281 { 282 int32_t bestVideoMode = getBestVideoMode(fixedVideoMode.width, 283 fixedVideoMode.height, 284 fixedVideoMode.bpp); 285 // validate the fixed mode 286 if ((bestVideoMode == -1) || 287 ((fixedVideoMode.width != videoModes[bestVideoMode].width) || 288 (fixedVideoMode.height != videoModes[bestVideoMode].height) || 289 (fixedVideoMode.bpp != videoModes[bestVideoMode].bpp))) 290 { 291 printf("Error: the specified fixed video mode is not available!\n"); 292 exit(-1); 293 } 294 } else 295 { 296 initialVideoMode = getBestVideoMode(640, 480, 16); 297 if (initialVideoMode == -1) 298 { 299 printf("Error: initial video mode 640x480x16 is not available!\n"); 300 exit(-1); 301 } 302 } 303 304 dsc.flags = DSDESC_CAPS; 305 dsc.caps = DSCAPS_PRIMARY; 306 DFBCHECK(dfb->CreateSurface(dfb, &dsc, &surface)); 307 DFBCHECK(surface->Clear(surface, 0, 0, 0, 0)); 308 DFBCHECK(surface->GetSize(surface, &screen_width, &screen_height)); 309 DFBCHECK(dfb->GetInputDevice(dfb, DIDID_KEYBOARD, &dfbKeyboard)); 310 DFBCHECK(dfbKeyboard->CreateEventBuffer(dfbKeyboard, &dfbEventBuffer)); 311 DFBCHECK(dfb->GetInputDevice(dfb, DIDID_MOUSE, &dfbMouse)); 312 DFBCHECK(dfbMouse->AttachEventBuffer(dfbMouse, dfbEventBuffer)); 313 314 315 if (useFixedVideoMode) 316 { 317 printf("Information: setting video mode to %ux%ux%u\n", fixedVideoMode.width, 318 fixedVideoMode.height, fixedVideoMode.bpp); 319 DFBCHECK(dfb->SetVideoMode(dfb, fixedVideoMode.width, 320 fixedVideoMode.height, fixedVideoMode.bpp)); 321 } else 322 { 323 printf("Information: starting with default video mode %ux%ux%u\n", 324 videoModes[initialVideoMode].width, videoModes[initialVideoMode].height, 325 videoModes[initialVideoMode].bpp); 326 DFBCHECK(dfb->SetVideoMode(dfb, videoModes[initialVideoMode].width, 327 videoModes[initialVideoMode].height, 328 videoModes[initialVideoMode].bpp)); 329 } 330 331 // register our framebuffer 332 frameBuffer = new VBoxDirectFB(dfb, surface); 333 display->SetFramebuffer(0, frameBuffer); 334 335 /** 336 * Start the VM execution thread 337 */ 338 console->PowerUp(NULL); 339 340 console->GetKeyboard(getter_AddRefs(keyboard)); 341 console->GetMouse(getter_AddRefs(mouse)); 342 343 /** 344 * Main event loop 345 */ 346 #define MAX_KEYEVENTS 10 347 PRInt32 keyEvents[MAX_KEYEVENTS]; 348 int numKeyEvents; 349 350 while (!quit) 351 { 352 DFBInputEvent event; 353 354 numKeyEvents = 0; 355 DFBCHECK(dfbEventBuffer->WaitForEvent(dfbEventBuffer)); 356 while (dfbEventBuffer->GetEvent(dfbEventBuffer, DFB_EVENT(&event)) == DFB_OK) 357 { 358 int mouseXDelta = 0; 359 int mouseYDelta = 0; 360 int mouseZDelta = 0; 361 switch (event.type) 362 { 363 #define QUEUEEXT() keyEvents[numKeyEvents++] = 0xe0 364 #define QUEUEKEY(scan) keyEvents[numKeyEvents++] = scan | (event.type == DIET_KEYRELEASE ? 0x80 : 0x00) 365 #define QUEUEKEYRAW(scan) keyEvents[numKeyEvents++] = scan 366 case DIET_KEYPRESS: 367 case DIET_KEYRELEASE: 368 { 369 // @@@AH development hack to get out of it! 370 if ((event.key_id == DIKI_ESCAPE) && (event.modifiers & (DIMM_CONTROL | DIMM_ALT))) 371 quit = 1; 372 373 if (numKeyEvents < MAX_KEYEVENTS) 374 { 375 //printf("%s: key_code: 0x%x\n", event.type == DIET_KEYPRESS ? "DIET_KEYPRESS" : "DIET_KEYRELEASE", event.key_code); 376 switch ((uint32_t)event.key_id) 377 { 378 case DIKI_CONTROL_R: 379 QUEUEEXT(); 380 QUEUEKEY(0x1d); 381 break; 382 case DIKI_INSERT: 383 QUEUEEXT(); 384 QUEUEKEY(0x52); 385 break; 386 case DIKI_DELETE: 387 QUEUEEXT(); 388 QUEUEKEY(0x53); 389 break; 390 case DIKI_HOME: 391 QUEUEEXT(); 392 QUEUEKEY(0x47); 393 break; 394 case DIKI_END: 395 QUEUEEXT(); 396 QUEUEKEY(0x4f); 397 break; 398 case DIKI_PAGE_UP: 399 QUEUEEXT(); 400 QUEUEKEY(0x49); 401 break; 402 case DIKI_PAGE_DOWN: 403 QUEUEEXT(); 404 QUEUEKEY(0x51); 405 break; 406 case DIKI_LEFT: 407 QUEUEEXT(); 408 QUEUEKEY(0x4b); 409 break; 410 case DIKI_RIGHT: 411 QUEUEEXT(); 412 QUEUEKEY(0x4d); 413 break; 414 case DIKI_UP: 415 QUEUEEXT(); 416 QUEUEKEY(0x48); 417 break; 418 case DIKI_DOWN: 419 QUEUEEXT(); 420 QUEUEKEY(0x50); 421 break; 422 case DIKI_KP_DIV: 423 QUEUEEXT(); 424 QUEUEKEY(0x35); 425 break; 426 case DIKI_KP_ENTER: 427 QUEUEEXT(); 428 QUEUEKEY(0x1c); 429 break; 430 case DIKI_PRINT: 431 // the break code is inverted! 432 if (event.type == DIET_KEYPRESS) 433 { 434 QUEUEEXT(); 435 QUEUEKEY(0x2a); 436 QUEUEEXT(); 437 QUEUEKEY(0x37); 438 } else 439 { 440 QUEUEEXT(); 441 QUEUEKEY(0x37); 442 QUEUEEXT(); 443 QUEUEKEY(0x2a); 444 } 445 break; 446 case DIKI_PAUSE: 447 // This is a super weird key. No break code and a 6 byte 448 // combination. 449 if (event.type == DIET_KEYPRESS) 450 { 451 QUEUEKEY(0xe1); 452 QUEUEKEY(0x1d); 453 QUEUEKEY(0x45); 454 QUEUEKEY(0xe1); 455 QUEUEKEY(0x9d); 456 QUEUEKEY(0xc5); 457 } 458 break; 459 case DIKI_META_L: 460 // the left Windows logo is a bit different 461 if (event.type == DIET_KEYPRESS) 462 { 463 QUEUEEXT(); 464 QUEUEKEYRAW(0x1f); 465 } else 466 { 467 QUEUEEXT(); 468 QUEUEKEYRAW(0xf0); 469 QUEUEKEYRAW(0x1f); 470 } 471 break; 472 case DIKI_META_R: 473 // the right Windows logo is a bit different 474 if (event.type == DIET_KEYPRESS) 475 { 476 QUEUEEXT(); 477 QUEUEKEYRAW(0x27); 478 } else 479 { 480 QUEUEEXT(); 481 QUEUEKEYRAW(0xf0); 482 QUEUEKEYRAW(0x27); 483 } 484 break; 485 case DIKI_SUPER_R: 486 // the popup menu is a bit different 487 if (event.type == DIET_KEYPRESS) 488 { 489 QUEUEEXT(); 490 QUEUEKEYRAW(0x2f); 491 } else 492 { 493 QUEUEEXT(); 494 QUEUEKEYRAW(0xf0); 495 QUEUEKEYRAW(0x2f); 496 } 497 break; 498 499 default: 500 // check if we got a hardware scancode 501 if (event.key_code != -1) 502 { 503 // take the scancode from DirectFB as is 504 QUEUEKEY(event.key_code); 505 } else 506 { 507 // XXX need extra handling! 508 } 509 } 510 } 511 break; 512 } 513 #undef QUEUEEXT 514 #undef QUEUEKEY 515 #undef QUEUEKEYRAW 516 517 case DIET_AXISMOTION: 518 { 519 switch (event.axis) 520 { 521 case DIAI_X: 522 mouseXDelta += event.axisrel; 523 break; 524 case DIAI_Y: 525 mouseYDelta += event.axisrel; 526 break; 527 case DIAI_Z: 528 mouseZDelta += event.axisrel; 529 break; 530 default: 531 break; 532 } 533 // fall through 534 } 535 case DIET_BUTTONPRESS: 536 // fall through; 537 case DIET_BUTTONRELEASE: 538 { 539 int buttonState = 0; 540 if (event.buttons & DIBM_LEFT) 541 buttonState |= MouseButtonState::LeftButton; 542 if (event.buttons & DIBM_RIGHT) 543 buttonState |= MouseButtonState::RightButton; 544 if (event.buttons & DIBM_MIDDLE) 545 buttonState |= MouseButtonState::MiddleButton; 546 mouse->PutMouseEvent(mouseXDelta, mouseYDelta, mouseZDelta, 547 buttonState); 548 break; 549 } 550 default: 551 break; 552 } 553 } 554 // did we get any keyboard events? 555 if (numKeyEvents > 0) 556 { 557 uint32_t codesStored; 558 if (numKeyEvents > 1) 559 { 560 keyboard->PutScancodes(numKeyEvents, keyEvents, 561 &codesStored); 562 } else 563 { 564 keyboard->PutScancode(keyEvents[0]); 565 } 566 } 567 } 568 { 569 nsCOMPtr<IProgress> progress; 570 console->PowerDown(getter_AddRefs(progress)); 571 progress->WaitForCompletion(-1); 149 572 } 150 573 } 151 if (NS_FAILED(rc)) 152 { 153 printf ("Error: failed to create file object! (rc=%08X)\n", rc); 154 exit(-1); 155 } 156 157 nsCOMPtr<nsIServiceManager> serviceManager; 158 rc = NS_InitXPCOM2(getter_AddRefs(serviceManager), nsAppPath, nsnull); 159 if (NS_FAILED(rc)) 160 { 161 printf("Error: XPCOM could not be initialized! rc=0x%x\n", rc); 162 exit(-1); 163 } 164 165 // register our component 166 nsCOMPtr<nsIComponentRegistrar> registrar = do_QueryInterface(serviceManager); 167 if (!registrar) 168 { 169 printf("Error: could not query nsIComponentRegistrar interface!\n"); 170 exit(-1); 171 } 172 registrar->AutoRegister(nsnull); 173 174 nsCOMPtr<ipcIService> ipcServ = do_GetService(IPC_SERVICE_CONTRACTID, &rc); 175 if (NS_FAILED(rc)) 176 { 177 printf("Error: could not get IPC service! rc = %08X\n", rc); 178 exit(-1); 179 } 180 181 nsCOMPtr<ipcIDConnectService> dcon = do_GetService(IPC_DCONNECTSERVICE_CONTRACTID, &rc); 182 if (NS_FAILED(rc)) 183 { 184 printf("Error: could not get DCONNECT service! rc = %08X\n", rc); 185 exit(-1); 186 } 187 188 PRUint32 serverID = 0; 189 rc = ipcServ->ResolveClientName("VirtualBoxServer", &serverID); 190 if (NS_FAILED(rc)) 191 { 192 printf("Error: could not get VirtualBox server ID! rc = %08X\n", rc); 193 exit(-1); 194 } 195 196 nsCOMPtr<nsIComponentManager> manager = do_QueryInterface(registrar); 197 if (!manager) 198 { 199 printf("Error: could not query nsIComponentManager interface!\n"); 200 exit(-1); 201 } 202 203 nsCOMPtr<IVirtualBox> virtualBox; 204 rc = dcon->CreateInstanceByContractID( 205 serverID, 206 NS_VIRTUALBOX_CONTRACTID, 207 NS_GET_IID(IVirtualBox), 208 getter_AddRefs(virtualBox)); 209 if (NS_FAILED(rc)) 210 { 211 printf("Error, could not instantiate object! rc=0x%x\n", rc); 212 exit(-1); 213 } 214 215 nsCOMPtr<ISession> session; 216 rc = manager->CreateInstance((nsCID)NS_SESSION_CID, 217 nsnull, 218 NS_GET_IID(ISession), 219 getter_AddRefs(session)); 220 if (NS_FAILED(rc)) 221 { 222 printf("Error: could not instantiate Session object! rc = %08X\n", rc); 223 exit(-1); 224 } 225 226 // open session for this VM 227 rc = virtualBox->OpenSession(session, uuid); 228 if (NS_FAILED(rc)) 229 { 230 printf("Error: given machine not found!\n"); 231 exit(-1); 232 } 233 IMachine *machine = NULL; 234 session->GetMachine(&machine); 235 if (!machine) 236 { 237 printf("Error: given machine not found!\n"); 238 exit(-1); 239 } 240 IConsole *console = NULL; 241 session->GetConsole(&console); 242 if (!console) 243 { 244 printf("Error: cannot get console!\n"); 245 exit(-1); 246 } 247 248 IDisplay *display = NULL; 249 console->GetDisplay(&display); 250 if (!display) 251 { 252 printf("Error: could not get display object!\n"); 253 exit(-1); 254 } 255 256 IKeyboard *keyboard = NULL; 257 IMouse *mouse = NULL; 258 VBoxDirectFB *frameBuffer = NULL; 259 260 /** 261 * Init DirectFB 574 575 Leave: 576 /* 577 * Perform the standard XPCOM shutdown procedure. 262 578 */ 263 IDirectFB *dfb = NULL; 264 IDirectFBSurface *surface = NULL; 265 IDirectFBInputDevice *dfbKeyboard = NULL; 266 IDirectFBInputDevice *dfbMouse = NULL; 267 IDirectFBEventBuffer *dfbEventBuffer = NULL; 268 DFBSurfaceDescription dsc; 269 int screen_width, screen_height; 270 271 DFBCHECK(DirectFBInit(&argc, &argv)); 272 DFBCHECK(DirectFBCreate(&dfb)); 273 DFBCHECK(dfb->SetCooperativeLevel(dfb, DFSCL_FULLSCREEN)); 274 // populate our structure of supported video modes 275 DFBCHECK(dfb->EnumVideoModes(dfb, enumVideoModesHandler, NULL)); 276 277 if (listHostModes) 278 { 279 printf("*****************************************************\n"); 280 printf("Number of available host video modes: %u\n", numVideoModes); 281 for (uint32_t i = 0; i < numVideoModes; i++) 282 { 283 printf("Mode %u: xres = %u, yres = %u, bpp = %u\n", i, 284 videoModes[i].width, videoModes[i].height, videoModes[i].bpp); 285 } 286 printf("Note: display modes with bpp < have been filtered out\n"); 287 printf("*****************************************************\n"); 288 goto Leave; 289 } 290 291 if (useFixedVideoMode) 292 { 293 int32_t bestVideoMode = getBestVideoMode(fixedVideoMode.width, 294 fixedVideoMode.height, 295 fixedVideoMode.bpp); 296 // validate the fixed mode 297 if ((bestVideoMode == -1) || 298 ((fixedVideoMode.width != videoModes[bestVideoMode].width) || 299 (fixedVideoMode.height != videoModes[bestVideoMode].height) || 300 (fixedVideoMode.bpp != videoModes[bestVideoMode].bpp))) 301 { 302 printf("Error: the specified fixed video mode is not available!\n"); 303 exit(-1); 304 } 305 } else 306 { 307 initialVideoMode = getBestVideoMode(640, 480, 16); 308 if (initialVideoMode == -1) 309 { 310 printf("Error: initial video mode 640x480x16 is not available!\n"); 311 exit(-1); 312 } 313 } 314 315 dsc.flags = DSDESC_CAPS; 316 dsc.caps = DSCAPS_PRIMARY; 317 DFBCHECK(dfb->CreateSurface(dfb, &dsc, &surface)); 318 DFBCHECK(surface->Clear(surface, 0, 0, 0, 0)); 319 DFBCHECK(surface->GetSize(surface, &screen_width, &screen_height)); 320 DFBCHECK(dfb->GetInputDevice(dfb, DIDID_KEYBOARD, &dfbKeyboard)); 321 DFBCHECK(dfbKeyboard->CreateEventBuffer(dfbKeyboard, &dfbEventBuffer)); 322 DFBCHECK(dfb->GetInputDevice(dfb, DIDID_MOUSE, &dfbMouse)); 323 DFBCHECK(dfbMouse->AttachEventBuffer(dfbMouse, dfbEventBuffer)); 324 325 326 if (useFixedVideoMode) 327 { 328 printf("Information: setting video mode to %ux%ux%u\n", fixedVideoMode.width, 329 fixedVideoMode.height, fixedVideoMode.bpp); 330 DFBCHECK(dfb->SetVideoMode(dfb, fixedVideoMode.width, 331 fixedVideoMode.height, fixedVideoMode.bpp)); 332 } else 333 { 334 printf("Information: starting with default video mode %ux%ux%u\n", 335 videoModes[initialVideoMode].width, videoModes[initialVideoMode].height, 336 videoModes[initialVideoMode].bpp); 337 DFBCHECK(dfb->SetVideoMode(dfb, videoModes[initialVideoMode].width, 338 videoModes[initialVideoMode].height, 339 videoModes[initialVideoMode].bpp)); 340 } 341 342 // register our framebuffer 343 frameBuffer = new VBoxDirectFB(dfb, surface); 344 display->SetFramebuffer(VBOX_VIDEO_PRIMARY_SCREEN, frameBuffer); 345 346 /** 347 * Start the VM execution thread 348 */ 349 console->PowerUp(NULL); 350 351 console->GetKeyboard(&keyboard); 352 console->GetMouse(&mouse); 353 354 /** 355 * Main event loop 356 */ 357 #define MAX_KEYEVENTS 10 358 int keyEvents[MAX_KEYEVENTS]; 359 int numKeyEvents; 360 361 while (!quit) 362 { 363 DFBInputEvent event; 364 365 numKeyEvents = 0; 366 DFBCHECK(dfbEventBuffer->WaitForEvent(dfbEventBuffer)); 367 while (dfbEventBuffer->GetEvent(dfbEventBuffer, DFB_EVENT(&event)) == DFB_OK) 368 { 369 int mouseXDelta = 0; 370 int mouseYDelta = 0; 371 int mouseZDelta = 0; 372 switch (event.type) 373 { 374 #define QUEUEEXT() keyEvents[numKeyEvents++] = 0xe0 375 #define QUEUEKEY(scan) keyEvents[numKeyEvents++] = scan | (event.type == DIET_KEYRELEASE ? 0x80 : 0x00) 376 #define QUEUEKEYRAW(scan) keyEvents[numKeyEvents++] = scan 377 case DIET_KEYPRESS: 378 case DIET_KEYRELEASE: 379 { 380 // @@@AH development hack to get out of it! 381 if ((event.key_id == DIKI_ESCAPE) && (event.modifiers & (DIMM_CONTROL | DIMM_ALT))) 382 quit = 1; 383 384 if (numKeyEvents < MAX_KEYEVENTS) 385 { 386 //printf("%s: key_code: 0x%x\n", event.type == DIET_KEYPRESS ? "DIET_KEYPRESS" : "DIET_KEYRELEASE", event.key_code); 387 switch ((uint32_t)event.key_id) 388 { 389 case DIKI_ALTGR: 390 QUEUEEXT(); 391 QUEUEKEY(0x38); 392 break; 393 case DIKI_CONTROL_R: 394 QUEUEEXT(); 395 QUEUEKEY(0x1d); 396 break; 397 case DIKI_INSERT: 398 QUEUEEXT(); 399 QUEUEKEY(0x52); 400 break; 401 case DIKI_DELETE: 402 QUEUEEXT(); 403 QUEUEKEY(0x53); 404 break; 405 case DIKI_HOME: 406 QUEUEEXT(); 407 QUEUEKEY(0x47); 408 break; 409 case DIKI_END: 410 QUEUEEXT(); 411 QUEUEKEY(0x4f); 412 break; 413 case DIKI_PAGE_UP: 414 QUEUEEXT(); 415 QUEUEKEY(0x49); 416 break; 417 case DIKI_PAGE_DOWN: 418 QUEUEEXT(); 419 QUEUEKEY(0x51); 420 break; 421 case DIKI_LEFT: 422 QUEUEEXT(); 423 QUEUEKEY(0x4b); 424 break; 425 case DIKI_RIGHT: 426 QUEUEEXT(); 427 QUEUEKEY(0x4d); 428 break; 429 case DIKI_UP: 430 QUEUEEXT(); 431 QUEUEKEY(0x48); 432 break; 433 case DIKI_DOWN: 434 QUEUEEXT(); 435 QUEUEKEY(0x50); 436 break; 437 case DIKI_KP_DIV: 438 QUEUEEXT(); 439 QUEUEKEY(0x35); 440 break; 441 case DIKI_KP_ENTER: 442 QUEUEEXT(); 443 QUEUEKEY(0x1c); 444 break; 445 case DIKI_PRINT: 446 // the break code is inverted! 447 if (event.type == DIET_KEYPRESS) 448 { 449 QUEUEEXT(); 450 QUEUEKEY(0x2a); 451 QUEUEEXT(); 452 QUEUEKEY(0x37); 453 } else 454 { 455 QUEUEEXT(); 456 QUEUEKEY(0x37); 457 QUEUEEXT(); 458 QUEUEKEY(0x2a); 459 } 460 break; 461 case DIKI_PAUSE: 462 // This is a super weird key. No break code and a 6 byte 463 // combination. 464 if (event.type == DIET_KEYPRESS) 465 { 466 QUEUEKEY(0xe1); 467 QUEUEKEY(0x1d); 468 QUEUEKEY(0x45); 469 QUEUEKEY(0xe1); 470 QUEUEKEY(0x9d); 471 QUEUEKEY(0xc5); 472 } 473 break; 474 case DIKI_META_L: 475 // the left Windows logo is a bit different 476 if (event.type == DIET_KEYPRESS) 477 { 478 QUEUEEXT(); 479 QUEUEKEYRAW(0x1f); 480 } else 481 { 482 QUEUEEXT(); 483 QUEUEKEYRAW(0xf0); 484 QUEUEKEYRAW(0x1f); 485 } 486 break; 487 case DIKI_META_R: 488 // the right Windows logo is a bit different 489 if (event.type == DIET_KEYPRESS) 490 { 491 QUEUEEXT(); 492 QUEUEKEYRAW(0x27); 493 } else 494 { 495 QUEUEEXT(); 496 QUEUEKEYRAW(0xf0); 497 QUEUEKEYRAW(0x27); 498 } 499 break; 500 case DIKI_SUPER_R: 501 // the popup menu is a bit different 502 if (event.type == DIET_KEYPRESS) 503 { 504 QUEUEEXT(); 505 QUEUEKEYRAW(0x2f); 506 } else 507 { 508 QUEUEEXT(); 509 QUEUEKEYRAW(0xf0); 510 QUEUEKEYRAW(0x2f); 511 } 512 break; 513 514 default: 515 // check if we got a hardware scancode 516 if (event.key_code != -1) 517 { 518 // take the scancode from DirectFB as is 519 QUEUEKEY(event.key_code); 520 } else 521 { 522 // XXX need extra handling! 523 } 524 } 525 } 526 break; 527 } 528 #undef QUEUEEXT 529 #undef QUEUEKEY 530 #undef QUEUEKEYRAW 531 532 case DIET_AXISMOTION: 533 { 534 switch (event.axis) 535 { 536 case DIAI_X: 537 mouseXDelta += event.axisrel; 538 break; 539 case DIAI_Y: 540 mouseYDelta += event.axisrel; 541 break; 542 case DIAI_Z: 543 mouseZDelta += event.axisrel; 544 break; 545 default: 546 break; 547 } 548 // fall through 549 } 550 case DIET_BUTTONPRESS: 551 // fall through; 552 case DIET_BUTTONRELEASE: 553 { 554 int buttonState = 0; 555 if (event.buttons & DIBM_LEFT) 556 buttonState |= MouseButtonState::LeftButton; 557 if (event.buttons & DIBM_RIGHT) 558 buttonState |= MouseButtonState::RightButton; 559 if (event.buttons & DIBM_MIDDLE) 560 buttonState |= MouseButtonState::MiddleButton; 561 mouse->PutMouseEvent(mouseXDelta, mouseYDelta, mouseZDelta, 562 buttonState); 563 break; 564 } 565 default: 566 break; 567 } 568 } 569 // did we get any keyboard events? 570 if (numKeyEvents > 0) 571 { 572 uint32_t codesStored; 573 if (numKeyEvents > 1) 574 { 575 com::SafeArray <LONG> keys (numKeyEvents); 576 for (size_t idx = 0; idx < keys.size(); ++idx) 577 keys[idx] = keyEvents[idx]; 578 keyboard->PutScancodes(ComSafeArrayAsInParam(keys), 579 &codesStored); 580 } else 581 { 582 keyboard->PutScancode(keyEvents[0]); 583 } 584 } 585 } 586 console->PowerDown(); 587 Leave: 588 if (mouse) 589 mouse->Release(); 590 if (keyboard) 591 keyboard->Release(); 592 if (display) 593 display->Release(); 594 if (console) 595 console->Release(); 596 if (machine) 597 machine->Release(); 598 virtualBox = NULL; 599 600 if (dfbEventBuffer) 601 dfbEventBuffer->Release(dfbEventBuffer); 602 if (dfbMouse) 603 dfbMouse->Release(dfbMouse); 604 if (dfbKeyboard) 605 dfbKeyboard->Release(dfbKeyboard); 606 if (surface) 607 surface->Release(surface); 608 if (dfb) 609 dfb->Release(dfb); 579 NS_ShutdownXPCOM(nsnull); 610 580 611 581 return 0; -
trunk/src/VBox/Frontends/VBoxFB/VBoxFB.h
r8155 r21771 6 6 7 7 /* 8 * Copyright (C) 2006-200 7Sun Microsystems, Inc.8 * Copyright (C) 2006-2009 Sun Microsystems, Inc. 9 9 * 10 10 * This file is part of VirtualBox Open Source Edition (OSE), as … … 36 36 #include <nsXPCOMGlue.h> 37 37 #include <nsMemory.h> 38 #include <nsStringAPI.h>39 38 #include <nsIProgrammingLanguage.h> 40 #include <nsEmbedString.h>41 39 #include <nsIFile.h> 42 40 #include <nsILocalFile.h> 41 #include <nsString.h> 42 #include <nsReadableUtils.h> 43 43 #include <VirtualBox_XPCOM.h> 44 44 #include <ipcIService.h> 45 #include <nsEventQueueUtils.h> 45 46 #include <ipcCID.h> 46 47 #include <ipcIDConnectService.h>
Note:
See TracChangeset
for help on using the changeset viewer.