Changeset 20243 in vbox
- Timestamp:
- Jun 4, 2009 12:06:23 AM (16 years ago)
- Location:
- trunk
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/VBox/VBoxVideo.h
r20009 r20243 258 258 { 259 259 VBOXVHWACMD_TYPE_SURF_CREATE = 1, 260 VBOXVHWACMD_TYPE_SURF_DESTROY 260 VBOXVHWACMD_TYPE_SURF_DESTROY, 261 VBOXVHWACMD_TYPE_SURF_LOCK, 262 VBOXVHWACMD_TYPE_SURF_UNLOCK, 263 VBOXVHWACMD_TYPE_SURF_BLT 261 264 } VBOXVHWACMD_TYPE; 262 265 … … 289 292 #define VBOXVHWASURF_OVERLAY 0x00000002 290 293 294 typedef struct _VBOXVHWA_COLORKEY 295 { 296 uint32_t low; 297 uint32_t high; 298 } VBOXVHWA_COLORKEY; 299 300 typedef struct _VBOXVHWA_PIXELFORMAT 301 { 302 uint32_t flags; 303 uint32_t fourCC; 304 union 305 { 306 uint32_t rgbBitCount; 307 uint32_t yuvBitCount; 308 } c; 309 310 union 311 { 312 uint32_t rgbRBitMask; 313 uint32_t yuvYBitMask; 314 } m1; 315 316 union 317 { 318 uint32_t rgbGBitMask; 319 uint32_t yuvUBitMask; 320 } m2; 321 322 union 323 { 324 uint32_t rgbBBitMask; 325 uint32_t yuvVBitMask; 326 } m3; 327 } VBOXVHWA_PIXELFORMAT; 328 291 329 typedef struct _VBOXVHWA_SURFINFO 292 330 { 293 uint32_t surfChars; 294 VBOXVHWA_RECTL rectl; 331 uint32_t height; 332 uint32_t width; 333 VBOXVHWA_COLORKEY DstOverlayCK; 334 VBOXVHWA_COLORKEY DstBltCK; 335 VBOXVHWA_COLORKEY SrcOverlayCK; 336 VBOXVHWA_COLORKEY SrcBltCK; 337 VBOXVHWA_PIXELFORMAT PixelFormat; 338 uint32_t surfCaps; 339 uint32_t Reserved; 295 340 } VBOXVHWA_SURFINFO; 296 341 … … 321 366 } u; 322 367 } VBOXVHWACMD_SURF_DESTROY; 368 369 typedef struct _VBOXVHWACMD_SURF_LOCK 370 { 371 union 372 { 373 struct 374 { 375 VBOXVHWA_SURFHANDLE hSurf; 376 uint32_t flags; 377 uint32_t Reserved; 378 VBOXVHWA_RECTL rect; 379 } in; 380 } u; 381 } VBOXVHWACMD_SURF_LOCK; 382 383 typedef struct _VBOXVHWACMD_SURF_UNLOCK 384 { 385 union 386 { 387 struct 388 { 389 VBOXVHWA_SURFHANDLE hSurf; 390 } in; 391 } u; 392 } VBOXVHWACMD_SURF_UNLOCK; 393 394 typedef struct _VBOXVHWACMD_SURF_BLT 395 { 396 union 397 { 398 struct 399 { 400 VBOXVHWA_SURFHANDLE hDstSurf; 401 VBOXVHWA_RECTL dstRect; 402 VBOXVHWA_SURFHANDLE hSrcSurf; 403 VBOXVHWA_RECTL srcRect; 404 uint32_t flags; 405 uint32_t reserved; 406 } in; 407 } u; 408 } VBOXVHWACMD_SURF_BLT; 409 323 410 #pragma pack() 324 411 # endif /* #ifdef VBOX_WITH_VIDEOHWACCEL */ -
trunk/src/VBox/Frontends/VirtualBox/Makefile.kmk
r20242 r20243 450 450 endif 451 451 452 ifdef VBOX_WITH_VIDEOHWACCEL 453 VirtualBox_SOURCES += \ 454 src/VBoxFBQGL.cpp 455 endif 452 456 # The Qt modules we're using. 453 457 # (The include directory and lib/framework for each module will be added by the Qt4 unit.) -
trunk/src/VBox/Frontends/VirtualBox/include/VBoxConsoleView.h
r20200 r20243 220 220 bool isRunning() { return mLastState == KMachineState_Running; } 221 221 222 #ifdef VBOX_WITH_VIDEOHWACCEL223 void handleVHWACommand(struct _VBOXVHWACMD *pCommand);224 #endif225 226 222 static void dimImage (QImage &img); 227 223 -
trunk/src/VBox/Frontends/VirtualBox/include/VBoxFrameBuffer.h
r20242 r20243 267 267 virtual void moveEvent (QMoveEvent * /*me*/ ) {} 268 268 269 #ifdef VBOX_WITH_VIDEOHWACCEL 270 /* this method is called from the GUI thread 271 * to perform the actual Video HW Acceleration command processing */ 272 virtual void doProcessVHWACommand(struct _VBOXVHWACMD * pCommand); 273 #endif 274 269 275 protected: 270 276 … … 318 324 #if defined (VBOX_GUI_USE_QGL) 319 325 320 #ifdef DEBUG321 #define VBOXQGL_ASSERTNOERR() \322 do { GLenum err = glGetError(); \323 Assert(err == GL_NO_ERROR); \324 }while(0)325 326 #define VBOXQGL_CHECKERR(_op) \327 do { \328 glGetError(); \329 _op \330 VBOXQGL_ASSERTNOERR(); \331 }while(0)332 #else333 #define VBOXQGL_ASSERTNOERR() \334 do {}while(0)335 336 #define VBOXQGL_CHECKERR(_op) \337 do { \338 _op \339 }while(0)340 #endif341 326 class VBoxGLWidget : public QGLWidget 342 327 { … … 420 405 ULONG aW, ULONG aH); 421 406 407 #ifdef VBOX_WITH_VIDEOHWACCEL 408 STDMETHOD(ProcessVHWACommand)(BYTE *pCommand); 409 #endif 410 422 411 ulong pixelFormat() { return vboxWidget()->vboxPixelFormat(); } 423 412 bool usesGuestVRAM() { return vboxWidget()->vboxUsesGuestVRAM(); } … … 429 418 void paintEvent (QPaintEvent *pe); 430 419 void resizeEvent (VBoxResizeEvent *re); 420 #ifdef VBOX_WITH_VIDEOHWACCEL 421 void doProcessVHWACommand(struct _VBOXVHWACMD * pCommand); 422 #endif 423 431 424 private: 432 425 void vboxMakeCurrent(); -
trunk/src/VBox/Frontends/VirtualBox/src/VBoxConsoleView.cpp
r20242 r20243 92 92 # include <VBox/err.h> 93 93 #endif /* defined (Q_WS_MAC) */ 94 95 #ifdef VBOX_WITH_VIDEOHWACCEL96 #include <VBox/VBoxVideo.h>97 #endif98 94 99 95 #if defined (Q_WS_WIN32) … … 1708 1704 { 1709 1705 VBoxVHWACommandProcessEvent *cmde = (VBoxVHWACommandProcessEvent *)e; 1710 handleVHWACommand(cmde->command());1706 mFrameBuf->doProcessVHWACommand(cmde->command()); 1711 1707 return true; 1712 1708 } … … 1719 1715 return QAbstractScrollArea::event (e); 1720 1716 } 1721 1722 #ifdef VBOX_WITH_VIDEOHWACCEL1723 void VBoxConsoleView::handleVHWACommand(struct _VBOXVHWACMD *pCmd)1724 {1725 switch(pCmd->enmCmd)1726 {1727 case VBOXVHWACMD_TYPE_SURF_CREATE:1728 {1729 VBOXVHWACMD_SURF_CREATE * pBody = VBOXVHWACMD_BODY(pCmd, VBOXVHWACMD_SURF_CREATE);1730 pCmd->rc = VERR_NOT_IMPLEMENTED;1731 break;1732 } break;1733 case VBOXVHWACMD_TYPE_SURF_DESTROY:1734 {1735 VBOXVHWACMD_SURF_DESTROY * pBody = VBOXVHWACMD_BODY(pCmd, VBOXVHWACMD_SURF_DESTROY);1736 pCmd->rc = VERR_NOT_IMPLEMENTED;1737 break;1738 } break;1739 }1740 1741 CDisplay display = mConsole.GetDisplay();1742 Assert (!display.isNull());1743 1744 display.CompleteVHWACommand((BYTE*)pCmd);1745 }1746 #endif1747 1717 1748 1718 bool VBoxConsoleView::eventFilter (QObject *watched, QEvent *e) -
trunk/src/VBox/Frontends/VirtualBox/src/VBoxFrameBuffer.cpp
r20242 r20243 29 29 /* Qt includes */ 30 30 #include <QPainter> 31 #if defined (VBOX_GUI_USE_QGL) 32 #include <QGLWidget> 33 34 #include <iprt/asm.h> 31 32 #ifdef VBOX_WITH_VIDEOHWACCEL 33 #include <VBox/VBoxVideo.h> 35 34 #endif 36 35 … … 267 266 STDMETHODIMP VBoxFrameBuffer::ProcessVHWACommand(BYTE *pCommand) 268 267 { 269 #ifdef VBOX_WITH_VIDEOHWACCEL270 QApplication::postEvent (mView,271 new VBoxVHWACommandProcessEvent ((struct _VBOXVHWACMD*)pCommand));272 return S_OK;273 #else274 268 Q_UNUSED (pCommand); 275 269 return E_NOTIMPL; 276 #endif 277 } 270 } 271 272 #ifdef VBOX_WITH_VIDEOHWACCEL 273 void VBoxFrameBuffer::doProcessVHWACommand(struct _VBOXVHWACMD * pCommand) 274 { 275 pCommand->rc = VERR_NOT_IMPLEMENTED; 276 CDisplay display = mView->console().GetDisplay(); 277 Assert (!display.isNull()); 278 279 display.CompleteVHWACommand((BYTE*)pCommand); 280 } 281 #endif 278 282 279 283 // … … 445 449 #if defined (VBOX_GUI_USE_QGL) 446 450 447 #define VBOXQGLLOG(_m) 448 449 /** @class VBoxQGLFrameBuffer 450 * 451 * The VBoxQImageFrameBuffer class is a class that implements the IFrameBuffer 452 * interface and uses QImage as the direct storage for VM display data. QImage 453 * is then converted to QPixmap and blitted to the console view widget. 454 */ 455 456 VBoxQGLFrameBuffer::VBoxQGLFrameBuffer (VBoxConsoleView *aView) : 457 VBoxFrameBuffer (aView) 458 { 459 // mWidget = new GLWidget(aView->viewport()); 460 resizeEvent (new VBoxResizeEvent (FramebufferPixelFormat_Opaque, 461 NULL, 0, 0, 640, 480)); 462 } 463 464 /** @note This method is called on EMT from under this object's lock */ 465 STDMETHODIMP VBoxQGLFrameBuffer::NotifyUpdate (ULONG aX, ULONG aY, 466 ULONG aW, ULONG aH) 467 { 468 /* We're not on the GUI thread and update() isn't thread safe in 469 * Qt 4.3.x on the Win, Qt 3.3.x on the Mac (4.2.x is), 470 * on Linux (didn't check Qt 4.x there) and probably on other 471 * non-DOS platforms, so post the event instead. */ 472 QApplication::postEvent (mView, 473 new VBoxRepaintEvent (aX, aY, aW, aH)); 474 475 return S_OK; 476 } 477 478 void VBoxQGLFrameBuffer::vboxMakeCurrent() 479 { 480 ((QGLWidget*)mView->viewport())->makeCurrent(); 481 } 482 483 VBoxGLWidget* VBoxQGLFrameBuffer::vboxWidget() 484 { 485 return (VBoxGLWidget*)mView->viewport(); 486 } 487 488 void VBoxQGLFrameBuffer::paintEvent (QPaintEvent *pe) 489 { 490 vboxWidget()->vboxPaintEvent(pe); 491 } 492 493 static GLsizei makePowerOf2(GLsizei val) 494 { 495 int last = ASMBitLastSetS32(val); 496 if(last>1) 497 { 498 last--; 499 if((1 << last) != val) 500 { 501 Assert((1 << last) < val); 502 val = (1 << (last+1)); 503 } 504 } 505 return val; 506 } 507 508 void VBoxGLWidget::vboxResizeEvent (VBoxResizeEvent *re) 509 { 510 VBOXQGLLOG(("-->resizing: pixelFormat(%d), VRAM(0x%x), bitsPerPixel(%d), bytesPerLine(%d), width(%d), height(%d)\n", 511 re->pixelFormat(), 512 re->VRAM(), 513 re->bitsPerPixel(), 514 re->bytesPerLine(), 515 re->width(), 516 re->height())); 517 mRe = re; 518 updateGL(); 519 mRe = NULL; 520 } 521 522 void VBoxGLWidget::vboxPaintEvent (QPaintEvent *pe) 523 { 524 mpIntersectionRect = &pe->rect(); 525 updateGL(); 526 mpIntersectionRect = NULL; 527 } 528 529 void VBoxGLWidget::paintGL() 530 { 531 if(mRe) 532 { 533 vboxDoResize(mRe); 534 } 535 else 536 { 537 vboxDoPaint(mpIntersectionRect); 538 } 539 } 540 541 void VBoxGLWidget::initializeGL() 542 { 543 glEnable(GL_TEXTURE_2D); 544 glGenTextures(1, &mTexture); 545 VBOXQGL_ASSERTNOERR(); 546 547 glBindTexture(GL_TEXTURE_2D, mTexture); 548 VBOXQGL_ASSERTNOERR(); 549 550 glPixelStorei(GL_UNPACK_ALIGNMENT, 1); 551 VBOXQGL_ASSERTNOERR(); 552 glPixelStorei(GL_PACK_ALIGNMENT, 1); 553 VBOXQGL_ASSERTNOERR(); 554 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 555 VBOXQGL_ASSERTNOERR(); 556 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 557 VBOXQGL_ASSERTNOERR(); 558 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); 559 VBOXQGL_ASSERTNOERR(); 560 561 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL); 562 VBOXQGL_ASSERTNOERR(); 563 564 vboxDoInitDisplay(); 565 } 566 567 void VBoxGLWidget::vboxDoPaint(const QRect *rec) 568 { 569 Assert(glIsTexture(mTexture)); 570 glBindTexture(GL_TEXTURE_2D, mTexture); 571 572 int x = rec->x(); 573 int y = rec->y(); 574 int width = rec->width(); 575 int height = rec->height(); 576 577 VBOXQGLLOG(("x(%d), y(%d), width(%d), height(%d)\n", x, y, width, height)); 578 uchar * address = mAddress + y*mBytesPerLine + x*mBytesPerPixel; 579 580 VBOXQGL_CHECKERR( 581 glPixelStorei(GL_PACK_ROW_LENGTH, mDisplayWidth); 582 ); 583 VBOXQGL_CHECKERR( 584 glPixelStorei(GL_UNPACK_ROW_LENGTH, mDisplayWidth); 585 ); 586 VBOXQGL_CHECKERR( 587 glTexSubImage2D(GL_TEXTURE_2D, 588 0, 589 x, y, width, height, 590 mFormat, 591 mType, 592 address); 593 ); 594 595 vboxDoPerformDisplay(); 596 } 597 598 void VBoxGLWidget::vboxDoResize(VBoxResizeEvent *re) 599 { 600 bool remind = false; 601 bool fallback = false; 602 603 /* clean the old values first */ 604 if(mAddress) 605 { 606 if(!mUsesGuestVRAM) 607 { 608 if(mAddress) 609 { 610 free(mAddress); 611 } 612 } 613 } 614 615 GLenum type; 616 GLint internalformat; 617 GLenum format; 618 619 /* check if we support the pixel format and can use the guest VRAM directly */ 620 if (re->pixelFormat() == FramebufferPixelFormat_FOURCC_RGB) 621 { 622 mBitsPerPixel = re->bitsPerPixel(); 623 mBytesPerLine = re->bytesPerLine(); 624 ulong bitsPerLine = mBytesPerLine * 8; 625 626 switch (mBitsPerPixel) 627 { 628 case 32: 629 internalformat = 3;//GL_RGB; 630 format = GL_BGRA_EXT;//GL_RGBA; 631 type = GL_UNSIGNED_BYTE; 632 break; 633 case 24: 634 Assert(0); 635 internalformat = 3;//GL_RGB; 636 format = GL_BGR_EXT; 637 type = GL_UNSIGNED_BYTE; 638 remind = true; 639 break; 640 case 8: 641 Assert(0); 642 internalformat = 1;//GL_RGB; 643 format = GL_BLUE;//GL_RGB; 644 type = GL_UNSIGNED_BYTE; 645 remind = true; 646 break; 647 case 1: 648 Assert(0); 649 internalformat = 1; 650 format = GL_COLOR_INDEX; 651 type = GL_BITMAP; 652 remind = true; 653 break; 654 default: 655 Assert(0); 656 remind = true; 657 fallback = true; 658 break; 659 } 660 661 if (!fallback) 662 { 663 /* QImage only supports 32-bit aligned scan lines... */ 664 Assert ((re->bytesPerLine() & 3) == 0); 665 fallback = ((re->bytesPerLine() & 3) != 0); 666 } 667 if (!fallback) 668 { 669 /* ...and the scan lines ought to be a whole number of pixels. */ 670 Assert ((bitsPerLine & (re->bitsPerPixel() - 1)) == 0); 671 fallback = ((bitsPerLine & (re->bitsPerPixel() - 1)) != 0); 672 } 673 if (!fallback) 674 { 675 ulong virtWdt = bitsPerLine / re->bitsPerPixel(); 676 mPixelFormat = FramebufferPixelFormat_FOURCC_RGB; 677 mUsesGuestVRAM = true; 678 } 679 } 680 else 681 { 682 fallback = true; 683 } 684 685 if (fallback) 686 { 687 /* we don't support either the pixel format or the color depth, 688 * fallback to a self-provided 32bpp RGB buffer */ 689 mBitsPerPixel = 32; 690 mBytesPerLine = re->width()*mBitsPerPixel/8; 691 mPixelFormat = FramebufferPixelFormat_FOURCC_RGB; 692 internalformat = 3;//GL_RGB; 693 format = GL_BGRA_EXT;//GL_RGBA; 694 type = GL_UNSIGNED_BYTE; 695 mUsesGuestVRAM = false; 696 } 697 698 mFormat = format; 699 mType = type; 700 mInternalFormat = internalformat; 701 mBytesPerPixel = mBitsPerPixel/8; 702 mDisplayWidth = mBytesPerLine/mBytesPerPixel; 703 mDisplayHeight = re->height(); 704 705 GLsizei wdt = makePowerOf2(mDisplayWidth); 706 GLsizei hgt = makePowerOf2(mDisplayHeight); 707 Assert(wdt >= (GLsizei)mDisplayWidth); 708 Assert(hgt >= (GLsizei)mDisplayHeight); 709 710 int size = wdt * hgt * (mBitsPerPixel/8); 711 uchar * address = (uchar *)malloc(size); 712 memset(address, 0, size); 713 714 glBindTexture(GL_TEXTURE_2D, mTexture); 715 VBOXQGL_CHECKERR( 716 glTexImage2D(GL_TEXTURE_2D, 717 0, 718 internalformat, 719 wdt, 720 hgt, 721 0, 722 format, 723 type, 724 (GLvoid *)address); 725 ); 726 glMatrixMode(GL_TEXTURE); 727 glLoadIdentity(); 728 glScalef(((double)mDisplayWidth)/wdt, ((double)mDisplayHeight)/hgt, 1.0f); 729 glMatrixMode(GL_MODELVIEW); 730 731 if(mUsesGuestVRAM) 732 { 733 mAddress = re->VRAM(); 734 free(address); 735 } 736 else 737 { 738 mAddress = address; 739 } 740 741 glViewport(0, 0, mDisplayWidth, mDisplayHeight); 742 glMatrixMode(GL_PROJECTION); 743 glLoadIdentity(); 744 glFrustum(0., (GLdouble)mDisplayWidth, 0., (GLdouble)mDisplayHeight, 0., 0.); 745 glMatrixMode(GL_MODELVIEW); 746 glLoadIdentity(); 747 748 if (remind) 749 { 750 class RemindEvent : public VBoxAsyncEvent 751 { 752 ulong mRealBPP; 753 public: 754 RemindEvent (ulong aRealBPP) 755 : mRealBPP (aRealBPP) {} 756 void handle() 757 { 758 vboxProblem().remindAboutWrongColorDepth (mRealBPP, 32); 759 } 760 }; 761 (new RemindEvent (re->bitsPerPixel()))->post(); 762 } 763 } 764 765 void VBoxGLWidget::vboxDoInitDisplay() 766 { 767 vboxDoDeleteDisplay(); 768 VBOXQGL_ASSERTNOERR(); 769 770 mDisplay = glGenLists(1); 771 VBOXQGL_ASSERTNOERR(); 772 glNewList(mDisplay, GL_COMPILE); 773 774 glBindTexture(GL_TEXTURE_2D, mTexture); 775 776 glBegin(GL_QUADS); 777 glTexCoord2d(0, 0); 778 glVertex2d(-1.0, 1.0); 779 glTexCoord2d(0, 1); 780 glVertex2d(-1.0, -1.0); 781 glTexCoord2d(1, 1); 782 glVertex2d(1.0, -1.0); 783 glTexCoord2d(1, 0); 784 glVertex2d(1.0, 1.0); 785 glEnd(); 786 787 glEndList(); 788 VBOXQGL_ASSERTNOERR(); 789 mDisplayInitialized = true; 790 } 791 792 void VBoxGLWidget::vboxDoDeleteDisplay() 793 { 794 if(mDisplayInitialized) 795 { 796 glDeleteLists(mDisplay, 1); 797 mDisplayInitialized = false; 798 } 799 } 800 801 void VBoxQGLFrameBuffer::resizeEvent (VBoxResizeEvent *re) 802 { 803 mWdt = re->width(); 804 mHgt = re->height(); 805 806 vboxWidget()->vboxResizeEvent(re); 807 } 451 /* The class is defined in VBoxFBQGL.cpp */ 808 452 809 453 #endif
Note:
See TracChangeset
for help on using the changeset viewer.