VirtualBox

Changeset 3438 in vbox for trunk/src/VBox/HostServices


Ignore:
Timestamp:
Jul 5, 2007 9:00:44 AM (18 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
22648
Message:

Window creation needs to be done in DrvSetPixelFormat

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/HostServices/SharedOpenGL/glwindrv.cpp

    r3435 r3438  
    146146    HGLRC glrc = 0;
    147147
    148     OGL_CMD(DrvCreateContext, 6);
    149     OGL_PARAM(HDC, hdc);
     148    OGL_CMD(DrvCreateContext, 1);
     149    OGL_PARAM(HDC, hdc);
     150
     151    Log(("DrvCreateContext %x\n", hdc));
     152    Assert(VBOX_OGL_GUEST_TO_HOST_HDC(hdc));
     153    glrc = wglCreateContext(pClient->hdc);
     154
     155    pClient->lastretval    = (uint64_t)glrc;
     156    pClient->fHasLastError = true;
     157    pClient->ulLastError   = GetLastError();
     158}
     159
     160void vboxglDrvSetContext(VBOXOGLCTX *pClient, uint8_t *pCmdBuffer)
     161{
     162    OGL_CMD(DrvSetContext, 2);
     163    OGL_PARAM(HDC, hdc);
     164    OGL_PARAM(HGLRC, hglrc);
     165
     166    Log(("DrvSetyContext %x %x\n", hdc, hglrc));
     167    pClient->lastretval = wglMakeCurrent(VBOX_OGL_GUEST_TO_HOST_HDC(hdc), hglrc);
     168    if (!pClient->lastretval)
     169        Log(("wglMakeCurrent failed with %d\n", GetLastError()));
     170
     171    pClient->fHasLastError = true;
     172    pClient->ulLastError   = GetLastError();
     173}
     174
     175void vboxglDrvCopyContext(VBOXOGLCTX *pClient, uint8_t *pCmdBuffer)
     176{
     177    OGL_CMD(DrvDeleteContext, 3);
     178    OGL_PARAM(HGLRC, hglrcSrc);
     179    OGL_PARAM(HGLRC, hglrcDst);
     180    OGL_PARAM(UINT,  mask);
     181    Log(("DrvCopyContext %x %x %x\n", hglrcSrc, hglrcDst, mask));
     182    pClient->lastretval = wglCopyContext(hglrcSrc, hglrcDst, mask);
     183    if (!pClient->lastretval)
     184        Log(("wglCopyContext failed with %d\n", GetLastError()));
     185
     186    pClient->fHasLastError = true;
     187    pClient->ulLastError   = GetLastError();
     188}
     189
     190void vboxglDrvReleaseContext(VBOXOGLCTX *pClient, uint8_t *pCmdBuffer)
     191{
     192    OGL_CMD(DrvReleaseContext, 1);
     193    OGL_PARAM(HGLRC, hglrc);
     194
     195    Log(("DrvReleaseContext %x\n", hglrc));
     196    /* clear current selection */
     197    pClient->lastretval = wglMakeCurrent(VBOX_OGL_GUEST_TO_HOST_HDC(hdc), NULL);
     198    if (!pClient->lastretval)
     199        Log(("wglMakeCurrent failed with %d\n", GetLastError()));
     200    pClient->fHasLastError = true;
     201    pClient->ulLastError   = GetLastError();
     202}
     203
     204void vboxglDrvDeleteContext(VBOXOGLCTX *pClient, uint8_t *pCmdBuffer)
     205{
     206    OGL_CMD(DrvDeleteContext, 1);
     207    OGL_PARAM(HGLRC, hglrc);
     208
     209    Log(("DrvDeleteContext %x\n", hglrc));
     210    pClient->lastretval = wglDeleteContext(hglrc);
     211    if (!pClient->lastretval)
     212        Log(("wglDeleteContext failed with %d\n", GetLastError()));
     213    pClient->fHasLastError = true;
     214    pClient->ulLastError   = GetLastError();
     215}
     216
     217void vboxglDrvCreateLayerContext(VBOXOGLCTX *pClient, uint8_t *pCmdBuffer)
     218{
     219    HGLRC glrc = 0;
     220
     221    OGL_CMD(DrvCreateLayerContext, 2);
     222    OGL_PARAM(HDC, hdc);
     223    OGL_PARAM(int, iLayerPlane);
     224
     225    Log(("DrvCreateLayerContext %x %d\n", hdc, iLayerPlane));
     226    Assert(VBOX_OGL_GUEST_TO_HOST_HDC(hdc));
     227    glrc = wglCreateLayerContext(VBOX_OGL_GUEST_TO_HOST_HDC(hdc), iLayerPlane);
     228
     229    pClient->lastretval    = (uint64_t)glrc;
     230    pClient->fHasLastError = true;
     231    pClient->ulLastError   = GetLastError();
     232}
     233
     234void vboxglDrvShareLists(VBOXOGLCTX *pClient, uint8_t *pCmdBuffer)
     235{
     236    OGL_CMD(DrvShareLists, 3);
     237    OGL_PARAM(HGLRC, hglrc1);
     238    OGL_PARAM(HGLRC, hglrc2);
     239
     240    Log(("DrvShareLists %x %x\n", hglrc1, hglrc2));
     241    pClient->lastretval = wglShareLists(hglrc1, hglrc2);
     242    pClient->fHasLastError = true;
     243    pClient->ulLastError   = GetLastError();
     244}
     245
     246
     247void vboxglDrvRealizeLayerPalette(VBOXOGLCTX *pClient, uint8_t *pCmdBuffer)
     248{
     249    OGL_CMD(DrvRealizeLayerPalette, 3);
     250    OGL_PARAM(HDC, hdc);
     251    OGL_PARAM(int, iLayerPlane);
     252    OGL_PARAM(BOOL, bRealize);
     253    Log(("DrvRealizeLayerPalette %x %d %d\n", hdc, iLayerPlane, bRealize));
     254    pClient->lastretval = wglRealizeLayerPalette(VBOX_OGL_GUEST_TO_HOST_HDC(hdc), iLayerPlane, bRealize);
     255    pClient->fHasLastError = true;
     256    pClient->ulLastError   = GetLastError();
     257}
     258
     259void vboxglDrvSwapLayerBuffers(VBOXOGLCTX *pClient, uint8_t *pCmdBuffer)
     260{
     261    OGL_CMD(DrvSwapLayerBuffers, 2);
     262    OGL_PARAM(HDC, hdc);
     263    OGL_PARAM(UINT, fuPlanes);
     264    Log(("DrvSwapLayerBuffers %x %d\n", hdc, fuPlanes));
     265    pClient->lastretval = wglSwapLayerBuffers(VBOX_OGL_GUEST_TO_HOST_HDC(hdc), fuPlanes);
     266    pClient->fHasLastError = true;
     267    pClient->ulLastError   = GetLastError();
     268}
     269
     270void vboxglDrvSetPixelFormat(VBOXOGLCTX *pClient, uint8_t *pCmdBuffer)
     271{
     272    int rc;
     273    PIXELFORMATDESCRIPTOR pfd;
     274
     275    OGL_CMD(DrvSetPixelFormat, 4);
     276    OGL_PARAM(HDC, hdc);
     277    OGL_PARAM(int, iPixelFormat);
    150278    OGL_PARAM(uint32_t, cx);
    151279    OGL_PARAM(uint32_t, cy);
    152     OGL_PARAM(BYTE, cColorBits);
    153     OGL_PARAM(BYTE, iPixelType);
    154     OGL_PARAM(BYTE, cDepthBits);
    155 
    156     Log(("DrvCreateContext %x (%d,%d) bpp=%d type=%x depth=%d\n", hdc, cx, cy, cColorBits, iPixelType, cDepthBits));
     280
    157281#ifdef VBOX_OGL_DEBUG_WINDOW_OUTPUT
    158282    if (!pClient->hwnd)
     
    162286            RTThreadSleep(100);
    163287    }
    164     SetWindowPos(pClient->hwnd, NULL, 0, 0, cx, cy, SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOOWNERZORDER);
    165 
    166     PIXELFORMATDESCRIPTOR pfd = {0};
    167     int format;
     288    RECT rect;
     289    rect.bottom = 0;
     290    rect.left   = 0;
     291    rect.right  = cx;
     292    rect.top    = cy;
     293    /* Convert client rectangel to window rectangle */
     294    AdjustWindowRect(&rect, WS_CAPTION | WS_POPUPWINDOW | WS_VISIBLE, FALSE);
     295    SetWindowPos(pClient->hwnd, NULL, 0, 0, rect.right - rect.left, rect.top - rect.bottom, SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOOWNERZORDER);
    168296
    169297    pClient->hdc = GetDC(pClient->hwnd);
    170298
    171     pfd.nSize       = sizeof(pfd);
    172     pfd.nVersion    = 1;
    173     pfd.dwFlags     = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
    174     pfd.iPixelType  = iPixelType;
    175     pfd.cColorBits  = cColorBits;
    176     pfd.cDepthBits  = cDepthBits;
    177     pfd.iLayerType  = PFD_MAIN_PLANE;
    178     uint32_t lasterr = glGetError();
    179     format = ChoosePixelFormat(pClient->hdc, &pfd);
    180     SetPixelFormat(pClient->hdc, format, &pfd);
    181 
    182     glrc = wglCreateContext(pClient->hdc);
    183     Assert(glrc);
    184 #else
    185     AssertFailed();
    186     glrc = 0;
    187 #endif
    188 
    189     pClient->lastretval    = (uint64_t)glrc;
    190     pClient->fHasLastError = true;
    191     pClient->ulLastError   = GetLastError();
    192 }
    193 
    194 void vboxglDrvSetContext(VBOXOGLCTX *pClient, uint8_t *pCmdBuffer)
    195 {
    196     OGL_CMD(DrvSetContext, 2);
    197     OGL_PARAM(HDC, hdc);
    198     OGL_PARAM(HGLRC, hglrc);
    199 
    200     Log(("DrvSetyContext %x %x\n", hdc, hglrc));
    201 #ifdef VBOX_OGL_DEBUG_WINDOW_OUTPUT
    202     pClient->lastretval = wglMakeCurrent(pClient->hdc, hglrc);
    203     if (!pClient->lastretval)
    204         Log(("wglMakeCurrent failed with %d\n", GetLastError()));
    205 #else
    206     AssertFailed();
    207 #endif
    208     pClient->fHasLastError = true;
    209     pClient->ulLastError   = GetLastError();
    210 }
    211 
    212 void vboxglDrvCopyContext(VBOXOGLCTX *pClient, uint8_t *pCmdBuffer)
    213 {
    214     OGL_CMD(DrvDeleteContext, 3);
    215     OGL_PARAM(HGLRC, hglrcSrc);
    216     OGL_PARAM(HGLRC, hglrcDst);
    217     OGL_PARAM(UINT,  mask);
    218     Log(("DrvCopyContext %x %x %x\n", hglrcSrc, hglrcDst, mask));
    219     pClient->lastretval = wglCopyContext(hglrcSrc, hglrcDst, mask);
    220     if (!pClient->lastretval)
    221         Log(("wglCopyContext failed with %d\n", GetLastError()));
    222 
    223     pClient->fHasLastError = true;
    224     pClient->ulLastError   = GetLastError();
    225 }
    226 
    227 void vboxglDrvReleaseContext(VBOXOGLCTX *pClient, uint8_t *pCmdBuffer)
    228 {
    229     OGL_CMD(DrvReleaseContext, 1);
    230     OGL_PARAM(HGLRC, hglrc);
    231 
    232     Log(("DrvReleaseContext %x\n", hglrc));
    233     /* clear current selection */
    234     pClient->lastretval = wglMakeCurrent(pClient->hdc, NULL);
    235     if (!pClient->lastretval)
    236         Log(("wglMakeCurrent failed with %d\n", GetLastError()));
    237     pClient->fHasLastError = true;
    238     pClient->ulLastError   = GetLastError();
    239 }
    240 
    241 void vboxglDrvDeleteContext(VBOXOGLCTX *pClient, uint8_t *pCmdBuffer)
    242 {
    243     OGL_CMD(DrvDeleteContext, 1);
    244     OGL_PARAM(HGLRC, hglrc);
    245 
    246     Log(("DrvDeleteContext %x\n", hglrc));
    247     pClient->lastretval = wglDeleteContext(hglrc);
    248     if (!pClient->lastretval)
    249         Log(("wglDeleteContext failed with %d\n", GetLastError()));
    250     pClient->fHasLastError = true;
    251     pClient->ulLastError   = GetLastError();
    252 }
    253 
    254 void vboxglDrvCreateLayerContext(VBOXOGLCTX *pClient, uint8_t *pCmdBuffer)
    255 {
    256     HGLRC glrc = 0;
    257 
    258     OGL_CMD(DrvCreateLayerContext, 7);
    259     OGL_PARAM(HDC, hdc);
    260     OGL_PARAM(int, iLayerPlane);
    261     OGL_PARAM(uint32_t, cx);
    262     OGL_PARAM(uint32_t, cy);
    263     OGL_PARAM(BYTE, cColorBits);
    264     OGL_PARAM(BYTE, iPixelType);
    265     OGL_PARAM(BYTE, cDepthBits);
    266 
    267     Log(("DrvCreateLayerContext %x (%d,%d) bpp=%d type=%x depth=%d\n", hdc, cx, cy, cColorBits, iPixelType, cDepthBits));
    268 #ifdef VBOX_OGL_DEBUG_WINDOW_OUTPUT
    269     if (!pClient->hwnd)
    270     {
    271             pClient->hwnd= CreateWindow("VBoxOGL", "VirtualBox OpenGL",
    272                                             WS_CAPTION | WS_POPUPWINDOW | WS_VISIBLE,
    273                                             0, 0, cx, cy,
    274                                             NULL, NULL, 0, NULL);       
    275     }
    276     else
    277     {
    278         SetWindowPos(pClient->hwnd, NULL, 0, 0, cx, cy, SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOOWNERZORDER);
    279     }
    280     PIXELFORMATDESCRIPTOR pfd = {0};
    281     int format;
    282 
    283     pClient->hdc = GetDC(pClient->hwnd);
    284 
    285     pfd.nSize       = sizeof(pfd);
    286     pfd.nVersion    = 1;
    287     pfd.dwFlags     = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
    288     pfd.iPixelType  = iPixelType;
    289     pfd.cColorBits  = cColorBits;
    290     pfd.cDepthBits  = cDepthBits;
    291     pfd.iLayerType  = PFD_MAIN_PLANE;
    292     format = ChoosePixelFormat(pClient->hdc, &pfd);
    293     SetPixelFormat(pClient->hdc, format, &pfd);
    294 
    295     glrc = wglCreateLayerContext(pClient->hdc, iLayerPlane);
    296 #else
    297     AssertFailed();
    298 #endif
    299 
    300     pClient->lastretval    = (uint64_t)glrc;
    301     pClient->fHasLastError = true;
    302     pClient->ulLastError   = GetLastError();
    303 }
    304 
    305 void vboxglDrvShareLists(VBOXOGLCTX *pClient, uint8_t *pCmdBuffer)
    306 {
    307     OGL_CMD(DrvShareLists, 3);
    308     OGL_PARAM(HGLRC, hglrc1);
    309     OGL_PARAM(HGLRC, hglrc2);
    310 
    311     Log(("DrvShareLists %x %x\n", hglrc1, hglrc2));
    312     pClient->lastretval = wglShareLists(hglrc1, hglrc2);
    313     pClient->fHasLastError = true;
    314     pClient->ulLastError   = GetLastError();
    315 }
    316 
    317 
    318 void vboxglDrvRealizeLayerPalette(VBOXOGLCTX *pClient, uint8_t *pCmdBuffer)
    319 {
    320     OGL_CMD(DrvRealizeLayerPalette, 3);
    321     OGL_PARAM(HDC, hdc);
    322     OGL_PARAM(int, iLayerPlane);
    323     OGL_PARAM(BOOL, bRealize);
    324     Log(("DrvRealizeLayerPalette %x %d %d\n", hdc, iLayerPlane, bRealize));
    325     pClient->lastretval = wglRealizeLayerPalette(VBOX_OGL_GUEST_TO_HOST_HDC(hdc), iLayerPlane, bRealize);
    326     pClient->fHasLastError = true;
    327     pClient->ulLastError   = GetLastError();
    328 }
    329 
    330 void vboxglDrvSwapLayerBuffers(VBOXOGLCTX *pClient, uint8_t *pCmdBuffer)
    331 {
    332     OGL_CMD(DrvSwapLayerBuffers, 2);
    333     OGL_PARAM(HDC, hdc);
    334     OGL_PARAM(UINT, fuPlanes);
    335     Log(("DrvSwapLayerBuffers %x %d\n", hdc, fuPlanes));
    336     pClient->lastretval = wglSwapLayerBuffers(VBOX_OGL_GUEST_TO_HOST_HDC(hdc), fuPlanes);
    337     pClient->fHasLastError = true;
    338     pClient->ulLastError   = GetLastError();
    339 }
    340 
    341 void vboxglDrvSetPixelFormat(VBOXOGLCTX *pClient, uint8_t *pCmdBuffer)
    342 {
    343     int rc;
    344     PIXELFORMATDESCRIPTOR pfd;
    345 
    346     OGL_CMD(DrvSetPixelFormat, 2);
    347     OGL_PARAM(HDC, hdc);
    348     OGL_PARAM(int, iPixelFormat);
    349 
    350     Log(("DrvSetPixelFormat %x %d\n", hdc, iPixelFormat));
    351299    rc = DescribePixelFormat(VBOX_OGL_GUEST_TO_HOST_HDC(hdc), iPixelFormat, sizeof(pfd), &pfd);
    352300    if (rc)
     
    359307        pClient->lastretval = 0;
    360308    }
     309
     310#else
     311    AssertFailed();
     312#endif
     313
     314    Log(("DrvSetPixelFormat %x %d (%d,%d)\n", hdc, iPixelFormat, cx, cy));
    361315    pClient->fHasLastError = true;
    362316    pClient->ulLastError   = GetLastError();
Note: See TracChangeset for help on using the changeset viewer.

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