VirtualBox

Changeset 51677 in vbox for trunk/src/VBox/Frontends/VBoxSDL


Ignore:
Timestamp:
Jun 20, 2014 12:58:01 PM (11 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
94447
Message:

VBoxSDL: option to run a separate VM process.

Location:
trunk/src/VBox/Frontends/VBoxSDL
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VBoxSDL/Framebuffer.cpp

    r51670 r51677  
    7474// Constructor / destructor
    7575//
     76
     77VBoxSDLFB::VBoxSDLFB()
     78{
     79}
     80
     81HRESULT VBoxSDLFB::FinalConstruct()
     82{
     83    return 0;
     84}
     85
     86void VBoxSDLFB::FinalRelease()
     87{
     88    return;
     89}
    7690
    7791/**
     
    87101 * @param iFixedHeight   fixed SDL height (-1 means not set)
    88102 */
    89 VBoxSDLFB::VBoxSDLFB(uint32_t uScreenId,
     103HRESULT VBoxSDLFB::init(uint32_t uScreenId,
    90104                     bool fFullscreen, bool fResizable, bool fShowSDLConfig,
    91105                     bool fKeepHostRes, uint32_t u32FixedWidth,
     
    95109    int rc;
    96110    LogFlow(("VBoxSDLFB::VBoxSDLFB\n"));
    97 
    98 #if defined (RT_OS_WINDOWS)
    99     refcnt = 0;
    100 #endif
    101111
    102112    mScreenId       = uScreenId;
     
    140150    Assert(mScreen);
    141151    mfInitialized = true;
     152#ifdef RT_OS_WINDOWS
     153    HRESULT hr = CoCreateFreeThreadedMarshaler(this, //GetControllingUnknown(),
     154                                             &m_pUnkMarshaler.p);
     155    Log(("CoCreateFreeThreadedMarshaler hr %08X\n", hr));
     156#endif
     157
     158    return 0;
    142159}
    143160
  • trunk/src/VBox/Frontends/VBoxSDL/Framebuffer.h

    r51670 r51677  
    4242class VBoxSDLFBOverlay;
    4343
    44 class VBoxSDLFB :
     44class ATL_NO_VTABLE VBoxSDLFB :
     45    public CComObjectRootEx<CComMultiThreadModel>,
    4546    VBOX_SCRIPTABLE_IMPL(IFramebuffer)
    4647{
    4748public:
    48     VBoxSDLFB(uint32_t uScreenId,
    49               bool fFullscreen = false, bool fResizable = true, bool fShowSDLConfig = false,
    50               bool fKeepHostRes = false, uint32_t u32FixedWidth = ~(uint32_t)0,
    51               uint32_t u32FixedHeight = ~(uint32_t)0, uint32_t u32FixedBPP = ~(uint32_t)0,
    52               bool fUpdateImage = false);
    53     virtual ~VBoxSDLFB();
     49    VBoxSDLFB();
     50    ~VBoxSDLFB();
     51
     52    HRESULT init(uint32_t uScreenId,
     53                 bool fFullscreen, bool fResizable, bool fShowSDLConfig,
     54                 bool fKeepHostRes, uint32_t u32FixedWidth,
     55                 uint32_t u32FixedHeight, uint32_t u32FixedBPP,
     56                 bool fUpdateImage);
    5457
    5558    static bool init(bool fShowSDLConfig);
    5659    static void uninit();
    5760
    58 #ifdef RT_OS_WINDOWS
    59     STDMETHOD_(ULONG, AddRef)()
    60     {
    61         return ::InterlockedIncrement (&refcnt);
    62     }
    63     STDMETHOD_(ULONG, Release)()
    64     {
    65         long cnt = ::InterlockedDecrement (&refcnt);
    66         if (cnt == 0)
    67             delete this;
    68         return cnt;
    69     }
    70 #endif
    71     VBOX_SCRIPTABLE_DISPATCH_IMPL(IFramebuffer)
    72 
    73     NS_DECL_ISUPPORTS
     61    DECLARE_NOT_AGGREGATABLE(VBoxSDLFB)
     62
     63    DECLARE_PROTECT_FINAL_CONSTRUCT()
     64
     65    BEGIN_COM_MAP(VBoxSDLFB)
     66        COM_INTERFACE_ENTRY(IFramebuffer)
     67        COM_INTERFACE_ENTRY2(IDispatch,IFramebuffer)
     68        COM_INTERFACE_ENTRY_AGGREGATE(IID_IMarshal, m_pUnkMarshaler.p)
     69    END_COM_MAP()
     70
     71    HRESULT FinalConstruct();
     72    void FinalRelease();
    7473
    7574    STDMETHOD(COMGETTER(Width))(ULONG *width);
     
    194193
    195194#endif
    196 #ifdef RT_OS_WINDOWS
    197     long refcnt;
    198 #endif
     195
    199196    SDL_Surface *mSurfVRAM;
    200197
     
    207204    ComPtr<IDisplaySourceBitmap> mpPendingSourceBitmap;
    208205    bool mfUpdates;
     206
     207#ifdef RT_OS_WINDOWS
     208     CComPtr <IUnknown>   m_pUnkMarshaler;
     209#endif
    209210};
    210211
  • trunk/src/VBox/Frontends/VBoxSDL/VBoxSDL.cpp

    r51547 r51677  
    55
    66/*
    7  * Copyright (C) 2006-2013 Oracle Corporation
     7 * Copyright (C) 2006-2014 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    207207
    208208static ULONG       gcMonitors = 1;
    209 static VBoxSDLFB  *gpFramebuffer[64];
     209static ComObjPtr<VBoxSDLFB> gpFramebuffer[64];
    210210static SDL_Cursor *gpDefaultCursor = NULL;
    211211#ifdef VBOXSDL_WITH_X11
     
    602602    RTPrintf("Usage:\n"
    603603             "  --startvm <uuid|name>    Virtual machine to start, either UUID or name\n"
     604             "  --separate               Run a separate VM process or attach to a running VM\n"
    604605             "  --hda <file>             Set temporary first hard disk to file\n"
    605606             "  --fda <file>             Set temporary first floppy disk to file\n"
     
    823824    Guid uuidVM;
    824825    char *vmName = NULL;
     826    bool fSeparate = false;
    825827    DeviceType_T bootDevice = DeviceType_Null;
    826828    uint32_t memorySize = 0;
     
    976978            }
    977979        }
     980        else if (   !strcmp(argv[curArg], "--separate")
     981                 || !strcmp(argv[curArg], "-separate"))
     982        {
     983            fSeparate = true;
     984        }
    978985        else if (   !strcmp(argv[curArg], "--comment")
    979986                 || !strcmp(argv[curArg], "-comment"))
     
    14821489    }
    14831490
    1484     rc = pMachine->LockMachine(pSession, LockType_VM);
     1491    if (fSeparate)
     1492    {
     1493        MachineState_T machineState = MachineState_Null;
     1494        pMachine->COMGETTER(State)(&machineState);
     1495        if (   machineState == MachineState_Running
     1496            || machineState == MachineState_Teleporting
     1497            || machineState == MachineState_LiveSnapshotting
     1498            || machineState == MachineState_Paused
     1499            || machineState == MachineState_TeleportingPausedVM
     1500           )
     1501        {
     1502            RTPrintf("VM is already running.\n");
     1503        }
     1504        else
     1505        {
     1506            ComPtr<IProgress> progress;
     1507            rc = pMachine->LaunchVMProcess(pSession, Bstr("headless").raw(), NULL, progress.asOutParam());
     1508            if (SUCCEEDED(rc) && !progress.isNull())
     1509            {
     1510                RTPrintf("Waiting for VM to power on...\n");
     1511                rc = progress->WaitForCompletion(-1);
     1512                if (SUCCEEDED(rc))
     1513                {
     1514                    BOOL completed = true;
     1515                    rc = progress->COMGETTER(Completed)(&completed);
     1516                    if (SUCCEEDED(rc))
     1517                    {
     1518                        LONG iRc;
     1519                        rc = progress->COMGETTER(ResultCode)(&iRc);
     1520                        if (SUCCEEDED(rc))
     1521                        {
     1522                            if (FAILED(iRc))
     1523                            {
     1524                                ProgressErrorInfo info(progress);
     1525                                com::GluePrintErrorInfo(info);
     1526                            }
     1527                            else
     1528                            {
     1529                                RTPrintf("VM has been successfully started.\n");
     1530                                /* LaunchVMProcess obtains a shared lock on the machine.
     1531                                 * Unlock it here, because the lock will be obtained below
     1532                                 * in the common code path as for already running VM.
     1533                                 */
     1534                                pSession->UnlockMachine();
     1535                            }
     1536                        }
     1537                    }
     1538                }
     1539            }
     1540        }
     1541        if (FAILED(rc))
     1542        {
     1543            RTPrintf("Error: failed to power up VM! No error text available.\n");
     1544            goto leave;
     1545        }
     1546
     1547        rc = pMachine->LockMachine(pSession, LockType_Shared);
     1548    }
     1549    else
     1550    {
     1551        rc = pMachine->LockMachine(pSession, LockType_VM);
     1552    }
     1553
    14851554    if (FAILED(rc))
    14861555    {
     
    15091578        goto leave;
    15101579    }
     1580
    15111581    // get the VM console
    15121582    pSession->COMGETTER(Console)(gpConsole.asOutParam());
     
    18571927    {
    18581928        // create our SDL framebuffer instance
    1859         gpFramebuffer[i] = new VBoxSDLFB(i, fFullscreen, fResizable, fShowSDLConfig, false,
    1860                                          fixedWidth, fixedHeight, fixedBPP);
    1861 
    1862         if (!gpFramebuffer[i])
     1929        gpFramebuffer[i].createObject();
     1930        rc = gpFramebuffer[i]->init(i, fFullscreen, fResizable, fShowSDLConfig, false,
     1931                                    fixedWidth, fixedHeight, fixedBPP, fSeparate);
     1932        if (FAILED(rc))
    18631933        {
    18641934            RTPrintf("Error: could not create framebuffer object!\n");
     
    19442014            goto leave;
    19452015        }
     2016        ULONG dummy;
    19462017        LONG xOrigin, yOrigin;
    1947         rc = gpDisplay->GetScreenResolution(i, NULL, NULL, NULL, &xOrigin, &yOrigin);
     2018        rc = gpDisplay->GetScreenResolution(i, &dummy, &dummy, &dummy, &xOrigin, &yOrigin);
    19482019        gpFramebuffer[i]->setOrigin(xOrigin, yOrigin);
    19492020    }
     
    21302201    SDL_Event event;
    21312202
    2132     LogFlow(("Powering up the VM...\n"));
    2133     rc = gpConsole->PowerUp(gpProgress.asOutParam());
    2134     if (rc != S_OK)
    2135     {
    2136         com::ErrorInfo info(gpConsole, COM_IIDOF(IConsole));
    2137         if (info.isBasicAvailable())
    2138             PrintError("Failed to power up VM", info.getText().raw());
    2139         else
    2140             RTPrintf("Error: failed to power up VM! No error text available.\n");
    2141         goto leave;
     2203    if (!fSeparate)
     2204    {
     2205        LogFlow(("Powering up the VM...\n"));
     2206        rc = gpConsole->PowerUp(gpProgress.asOutParam());
     2207        if (rc != S_OK)
     2208        {
     2209            com::ErrorInfo info(gpConsole, COM_IIDOF(IConsole));
     2210            if (info.isBasicAvailable())
     2211                PrintError("Failed to power up VM", info.getText().raw());
     2212            else
     2213                RTPrintf("Error: failed to power up VM! No error text available.\n");
     2214            goto leave;
     2215        }
    21422216    }
    21432217
     
    22202294                        gpFramebuffer[event.user.code]->notifyChange(event.user.code);
    22212295                        /* update xOrigin, yOrigin -> mouse */
    2222                         rc = gpDisplay->GetScreenResolution(event.user.code, NULL, NULL, NULL, &xOrigin, &yOrigin);
     2296                        ULONG dummy;
     2297                        rc = gpDisplay->GetScreenResolution(event.user.code, &dummy, &dummy, &dummy, &xOrigin, &yOrigin);
    22232298                        gpFramebuffer[event.user.code]->setOrigin(xOrigin, yOrigin);
    22242299                        break;
     
    23062381        RTPrintf("Error: could not get mouse object!\n");
    23072382        goto leave;
     2383    }
     2384
     2385    if (fSeparate && gpMouse)
     2386    {
     2387        LogFlow(("Fetching mouse caps\n"));
     2388
     2389        /* Fetch current mouse status, etc */
     2390        gpMouse->COMGETTER(AbsoluteSupported)(&gfAbsoluteMouseGuest);
     2391        gpMouse->COMGETTER(RelativeSupported)(&gfRelativeMouseGuest);
     2392        gpMouse->COMGETTER(NeedsHostCursor)(&gfGuestNeedsHostCursor);
     2393
     2394        HandleGuestCapsChanged();
    23082395    }
    23092396
     
    27022789                gpFramebuffer[event.user.code]->notifyChange(event.user.code);
    27032790                /* update xOrigin, yOrigin -> mouse */
    2704                 rc = gpDisplay->GetScreenResolution(event.user.code, NULL, NULL, NULL, &xOrigin, &yOrigin);
     2791                ULONG dummy;
     2792                rc = gpDisplay->GetScreenResolution(event.user.code, &dummy, &dummy, &dummy, &xOrigin, &yOrigin);
    27052793                gpFramebuffer[event.user.code]->setOrigin(xOrigin, yOrigin);
    27062794                break;
     
    28082896        machineState = MachineState_Aborted;
    28092897
    2810     /*
    2811      * Turn off the VM if it's running
    2812      */
    2813     if (   gpConsole
    2814         && (   machineState == MachineState_Running
    2815             || machineState == MachineState_Teleporting
    2816             || machineState == MachineState_LiveSnapshotting
    2817             /** @todo power off paused VMs too? */
     2898    if (!fSeparate)
     2899    {
     2900        /*
     2901         * Turn off the VM if it's running
     2902         */
     2903        if (   gpConsole
     2904            && (   machineState == MachineState_Running
     2905                || machineState == MachineState_Teleporting
     2906                || machineState == MachineState_LiveSnapshotting
     2907                /** @todo power off paused VMs too? */
     2908               )
    28182909           )
    2819        )
    2820     do
    2821     {
    2822         pConsoleListener->getWrapped()->ignorePowerOffEvents(true);
    2823         ComPtr<IProgress> pProgress;
    2824         CHECK_ERROR_BREAK(gpConsole, PowerDown(pProgress.asOutParam()));
    2825         CHECK_ERROR_BREAK(pProgress, WaitForCompletion(-1));
    2826         BOOL completed;
    2827         CHECK_ERROR_BREAK(pProgress, COMGETTER(Completed)(&completed));
    2828         ASSERT(completed);
    2829         LONG hrc;
    2830         CHECK_ERROR_BREAK(pProgress, COMGETTER(ResultCode)(&hrc));
    2831         if (FAILED(hrc))
    2832         {
    2833             com::ErrorInfo info;
    2834             if (info.isFullAvailable())
    2835                 PrintError("Failed to power down VM",
    2836                            info.getText().raw(), info.getComponent().raw());
    2837             else
    2838                 RTPrintf("Failed to power down virtual machine! No error information available (rc = 0x%x).\n", hrc);
    2839             break;
    2840         }
    2841     } while (0);
     2910        do
     2911        {
     2912            pConsoleListener->getWrapped()->ignorePowerOffEvents(true);
     2913            ComPtr<IProgress> pProgress;
     2914            CHECK_ERROR_BREAK(gpConsole, PowerDown(pProgress.asOutParam()));
     2915            CHECK_ERROR_BREAK(pProgress, WaitForCompletion(-1));
     2916            BOOL completed;
     2917            CHECK_ERROR_BREAK(pProgress, COMGETTER(Completed)(&completed));
     2918            ASSERT(completed);
     2919            LONG hrc;
     2920            CHECK_ERROR_BREAK(pProgress, COMGETTER(ResultCode)(&hrc));
     2921            if (FAILED(hrc))
     2922            {
     2923                com::ErrorInfo info;
     2924                if (info.isFullAvailable())
     2925                    PrintError("Failed to power down VM",
     2926                               info.getText().raw(), info.getComponent().raw());
     2927                else
     2928                    RTPrintf("Failed to power down virtual machine! No error information available (rc = 0x%x).\n", hrc);
     2929                break;
     2930            }
     2931        } while (0);
     2932    }
    28422933
    28432934    /* unregister Console listener */
     
    28592950    {
    28602951        rc = gpMachine->DiscardSettings();
    2861         AssertComRC(rc);
     2952        AssertMsg(SUCCEEDED(rc), ("DiscardSettings %Rhrc, machineState %d\n", rc, machineState));
    28622953    }
    28632954
Note: See TracChangeset for help on using the changeset viewer.

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