VirtualBox

Ignore:
Timestamp:
Sep 5, 2014 6:25:38 PM (10 years ago)
Author:
vboxsync
Message:

3D: Mac OS X host: enable support for offline rendering.

File:
1 edited

Legend:

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

    r50406 r52622  
    66
    77/*
    8  * Copyright (C) 2009-2012 Oracle Corporation
     8 * Copyright (C) 2009-2014 Oracle Corporation
    99 *
    1010 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    1818
    1919
     20#include <IOKit/IOKitLib.h>
    2021#include <OpenGL/OpenGL.h>
    2122#include <ApplicationServices/ApplicationServices.h>
     
    2829#include <iprt/log.h>
    2930
     31#include <iprt/asm.h>
     32#include <iprt/thread.h>
     33
    3034#include <VBox/VBoxOGLTest.h>
     35
     36bool RTCALL VBoxOglIsOfflineRenderingAppropriate()
     37{
     38    /* It is assumed that it is makes sense to enable offline rendering
     39       only in case if host has more than one GPU installed. This routine
     40       counts all the PCI devices in IORegistry which have IOName property
     41       set to "display". If the amount of such devices if greater than one,
     42       it returns TRUE or FALSE otherwise. */
     43
     44    kern_return_t   krc;
     45    io_iterator_t   matchingServices;
     46    CFDictionaryRef pMatchingDictionary;
     47    static bool     fAppropriate = false;
     48
     49    /* In order to do not slowdown 3D engine which can ask about offline rendering several times,
     50       let's cache the result and assume that renderers amount value is constant. Also prevent threads race
     51       on startup. */
     52
     53    static bool volatile fState = false;
     54    if (!ASMAtomicCmpXchgBool(&fState, true, false))
     55    {
     56        while (ASMAtomicReadBool(&fState) != true)
     57            RTThreadSleep(5);
     58
     59        return fAppropriate;
     60    }
     61
     62#define VBOX_OGL_RENDERER_MATCH_KEYS_NUM    (2)
     63
     64    CFStringRef ppDictionaryKeys[VBOX_OGL_RENDERER_MATCH_KEYS_NUM] = { CFSTR(kIOProviderClassKey), CFSTR(kIONameMatchKey) };
     65    CFStringRef ppDictionaryVals[VBOX_OGL_RENDERER_MATCH_KEYS_NUM] = { CFSTR("IOPCIDevice"),       CFSTR("display") };
     66
     67    pMatchingDictionary = CFDictionaryCreate(kCFAllocatorDefault,
     68                                             (const void **)ppDictionaryKeys,
     69                                             (const void **)ppDictionaryVals,
     70                                             VBOX_OGL_RENDERER_MATCH_KEYS_NUM,
     71                                             &kCFTypeDictionaryKeyCallBacks,
     72                                             &kCFTypeDictionaryValueCallBacks);
     73    if (pMatchingDictionary)
     74    {
     75        /* The reference to pMatchingDictionary is consumed by the function below => no IORelease(pMatchingDictionary)! */
     76        krc = IOServiceGetMatchingServices(kIOMasterPortDefault, pMatchingDictionary, &matchingServices);
     77        if (krc == kIOReturnSuccess)
     78        {
     79            io_object_t matchingService;
     80            int         cMatchingServices = 0;
     81
     82            while ((matchingService = IOIteratorNext(matchingServices)) != 0)
     83            {
     84                cMatchingServices++;
     85                IOObjectRelease(matchingService);
     86            }
     87
     88            fAppropriate = (cMatchingServices > 1);
     89
     90            IOObjectRelease(matchingServices);
     91        }
     92
     93    }
     94
     95    LogRel(("OpenGL: Offline rendering support is %s (PID=%d)\n", fAppropriate ? "ON" : "OFF", (int)getpid()));
     96
     97    return fAppropriate;
     98}
    3199
    32100bool RTCALL VBoxOglIs3DAccelerationSupported()
     
    49117        kCGLPFADoubleBuffer,
    50118        kCGLPFAWindow,
     119        VBoxOglIsOfflineRenderingAppropriate() ? kCGLPFAAllowOfflineRenderers : (CGLPixelFormatAttribute)NULL,
    51120        (CGLPixelFormatAttribute)NULL
    52121    };
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