diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-11 08:17:27 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-11 08:17:27 +0000 |
commit | f215e02bf85f68d3a6106c2a1f4f7f063f819064 (patch) | |
tree | 6bb5b92c046312c4e95ac2620b10ddf482d3fa8b /src/VBox/Main/src-helper-apps/OpenGLTest | |
parent | Initial commit. (diff) | |
download | virtualbox-f215e02bf85f68d3a6106c2a1f4f7f063f819064.tar.xz virtualbox-f215e02bf85f68d3a6106c2a1f4f7f063f819064.zip |
Adding upstream version 7.0.14-dfsg.upstream/7.0.14-dfsg
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
7 files changed, 1841 insertions, 0 deletions
diff --git a/src/VBox/Main/src-helper-apps/OpenGLTest/Makefile.kmk b/src/VBox/Main/src-helper-apps/OpenGLTest/Makefile.kmk new file mode 100644 index 00000000..f35d21df --- /dev/null +++ b/src/VBox/Main/src-helper-apps/OpenGLTest/Makefile.kmk @@ -0,0 +1,107 @@ +# $Id: Makefile.kmk $ +## @file +# Sub-Makefile for the OpenGLTest helper app. +# + +# +# Copyright (C) 2008-2023 Oracle and/or its affiliates. +# +# This file is part of VirtualBox base platform packages, as +# available from https://www.virtualbox.org. +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation, in version 3 of the +# License. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, see <https://www.gnu.org/licenses>. +# +# SPDX-License-Identifier: GPL-3.0-only +# + +SUB_DEPTH = ../../../../.. +include $(KBUILD_PATH)/subheader.kmk + + +# +# VBoxOGLTest - Library that VBoxSVC is linked with. +# +# On darwin this does the whole job, while on the other platforms it just +# starts VBoxTestOGL. +# +LIBRARIES += VBoxOGLTest +VBoxOGLTest_TEMPLATE := VBoxR3Dll +ifneq ($(KBUILD_TARGET),darwin) + VBoxOGLTest_SOURCES := OpenGLTest.cpp +else + VBoxOGLTest_SOURCES.darwin := OpenGLTestDarwin.cpp + VBoxOGLTest_CXXFLAGS.darwin = $(VBOX_GCC_Wno-deprecated-declarations) +endif + + +# +# VBoxTestOGL - OpenGL support test app. +# Note! Doesn't link with VBOX_WITH_DEBUG_VCC_CRT defined because it uses Qt. +# +if defined(VBOX_WITH_QTGUI) \ + && (defined(VBOX_WITH_VMSVGA3D) || defined(VBOX_WITH_VIDEOHWACCEL)) \ + && !defined(VBOX_WITH_DEBUG_VCC_CRT) \ + && "$(KBUILD_TARGET)" != "darwin" + ifdef VBOX_WITH_VIDEOHWACCEL + ifndef VBOX_WITH_QT6 + USES += qt5 + else + USES += qt6 + endif + endif + PROGRAMS += VBoxTestOGL + VBoxTestOGL_TEMPLATE = $(if $(VBOX_WITH_VIDEOHWACCEL),$(if $(VBOX_WITH_HARDENING),VBoxQtGuiDll,VBoxQtGuiExe),VBoxMainExe) + VBoxTestOGL_DEFS.win = _WIN32_WINNT=0x0500 WINDOWS=1 + VBoxTestOGL_DEFS.linux = Linux=1 _GNU_SOURCE + VBoxTestOGL_DEFS.solaris = SunOS=1 _GNU_SOURCE #GLEXT_64_TYPES_DEFINED + VBoxTestOGL_DEFS.freebsd = FreeBSD=1 _GNU_SOURCE + ifdef VBOX_WITH_AUTOMATIC_DEFS_QUOTING + VBoxTestOGL_DEFS = VBOX_BUILD_TARGET="$(KBUILD_TARGET).$(KBUILD_TARGET_ARCH)" + else + VBoxTestOGL_DEFS = VBOX_BUILD_TARGET=\"$(KBUILD_TARGET).$(KBUILD_TARGET_ARCH)\" + endif + VBoxTestOGL_SOURCES = OpenGLTestApp.cpp + VBoxTestOGL_SOURCES.win = VBoxTestOGL.rc + VBoxTestOGL_LIBS = \ + $(LIB_RUNTIME) + if1of ($(KBUILD_TARGET), freebsd linux netbsd openbsd solaris) # the X11 gang + VBoxTestOGL_LIBS += \ + X11 \ + Xext + VBoxTestOGL_LIBPATH = \ + $(VBOX_LIBPATH_X11) + endif + + ifdef VBOX_WITH_VIDEOHWACCEL + VBoxTestOGL_DEFS += VBOX_WITH_VIDEOHWACCEL + VBoxTestOGL_QT_MODULES = Core Gui OpenGL Widgets + ifdef VBOX_WITH_QT6 + VBoxTestOGL_QT_MODULES += OpenGLWidgets + endif + if1of ($(KBUILD_TARGET), solaris linux freebsd) + VBoxTestOGL_LIBS += xcb GL pthread dl + endif + VBoxTestOGL_LIBS.win += $(PATH_SDK_$(VBOX_WINPSDK)_LIB)/Opengl32.lib + VBoxTestOGL_SOURCES += VBoxGLSupportInfo.cpp + endif + + # Don't let ld strip out explicitly linked libraries even when they are not needed. + # This was causing some dynamic library loading problems in case of indirect dependencies + # in systems where RUNPATH instead of RPATH is utilized. + VBoxTestOGL_LDFLAGS.linux = -Wl,--no-as-needed + VBoxTestOGL_LDFLAGS.win = /SUBSYSTEM:windows +endif + +include $(FILE_KBUILD_SUB_FOOTER) + diff --git a/src/VBox/Main/src-helper-apps/OpenGLTest/OpenGLTest.cpp b/src/VBox/Main/src-helper-apps/OpenGLTest/OpenGLTest.cpp new file mode 100644 index 00000000..80c5bdcd --- /dev/null +++ b/src/VBox/Main/src-helper-apps/OpenGLTest/OpenGLTest.cpp @@ -0,0 +1,109 @@ +/* $Id: OpenGLTest.cpp $ */ +/** @file + * VBox host opengl support test - generic implementation. + */ + +/* + * Copyright (C) 2009-2023 Oracle and/or its affiliates. + * + * This file is part of VirtualBox base platform packages, as + * available from https://www.virtualbox.org. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, in version 3 of the + * License. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see <https://www.gnu.org/licenses>. + * + * SPDX-License-Identifier: GPL-3.0-only + */ + +#include <VBox/err.h> +#include <iprt/assert.h> +#include <iprt/env.h> +#include <iprt/param.h> +#include <iprt/path.h> +#include <iprt/process.h> +#include <iprt/string.h> +#include <iprt/time.h> +#include <iprt/thread.h> +#include <iprt/env.h> +#include <iprt/log.h> + +#include <VBox/VBoxOGL.h> + +bool RTCALL VBoxOglIs3DAccelerationSupported(void) +{ + if (RTEnvExist("VBOX_3D_FORCE_SUPPORTED")) + { + LogRel(("VBOX_3D_FORCE_SUPPORTED is specified, skipping 3D test, and treating as supported\n")); + return true; + } + + static char pszVBoxPath[RTPATH_MAX]; + const char *papszArgs[4] = { NULL, "-test", "3D", NULL}; + +#ifdef __SANITIZE_ADDRESS__ + /* The OpenGL test tool contains a number of memory leaks which cause it to + * return failure when run with ASAN unless we disable the leak detector. */ + RTENV env; + if (RT_FAILURE(RTEnvClone(&env, RTENV_DEFAULT))) + return false; + RTEnvPutEx(env, "ASAN_OPTIONS=detect_leaks=0"); /* If this fails we will notice later */ +#endif + int vrc = RTPathExecDir(pszVBoxPath, RTPATH_MAX); + AssertRCReturn(vrc, false); +#if defined(RT_OS_WINDOWS) || defined(RT_OS_OS2) + vrc = RTPathAppend(pszVBoxPath, RTPATH_MAX, "VBoxTestOGL.exe"); +#else + vrc = RTPathAppend(pszVBoxPath, RTPATH_MAX, "VBoxTestOGL"); +#endif + papszArgs[0] = pszVBoxPath; /* argv[0] */ + AssertRCReturn(vrc, false); + + RTPROCESS Process; +#ifndef __SANITIZE_ADDRESS__ + vrc = RTProcCreate(pszVBoxPath, papszArgs, RTENV_DEFAULT, 0, &Process); +#else + vrc = RTProcCreate(pszVBoxPath, papszArgs, env, 0, &Process); + RTEnvDestroy(env); +#endif + if (RT_FAILURE(vrc)) + return false; + + uint64_t StartTS = RTTimeMilliTS(); + + RTPROCSTATUS ProcStatus = {0}; + while (1) + { + vrc = RTProcWait(Process, RTPROCWAIT_FLAGS_NOBLOCK, &ProcStatus); + if (vrc != VERR_PROCESS_RUNNING) + break; + +#ifndef DEBUG_misha + if (RTTimeMilliTS() - StartTS > 30*1000 /* 30 sec */) + { + RTProcTerminate(Process); + RTThreadSleep(100); + RTProcWait(Process, RTPROCWAIT_FLAGS_NOBLOCK, &ProcStatus); + return false; + } +#endif + RTThreadSleep(100); + } + + if (RT_SUCCESS(vrc)) + if ( ProcStatus.enmReason == RTPROCEXITREASON_NORMAL + && ProcStatus.iStatus == 0) + return true; + + return false; +} + diff --git a/src/VBox/Main/src-helper-apps/OpenGLTest/OpenGLTestApp.cpp b/src/VBox/Main/src-helper-apps/OpenGLTest/OpenGLTestApp.cpp new file mode 100644 index 00000000..b3f00aeb --- /dev/null +++ b/src/VBox/Main/src-helper-apps/OpenGLTest/OpenGLTestApp.cpp @@ -0,0 +1,526 @@ +/* $Id: OpenGLTestApp.cpp $ */ +/** @file + * VBox host opengl support test application. + */ + +/* + * Copyright (C) 2009-2023 Oracle and/or its affiliates. + * + * This file is part of VirtualBox base platform packages, as + * available from https://www.virtualbox.org. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, in version 3 of the + * License. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see <https://www.gnu.org/licenses>. + * + * SPDX-License-Identifier: GPL-3.0-only + */ + +#include <iprt/assert.h> +#include <iprt/buildconfig.h> +#include <iprt/errcore.h> +#include <iprt/getopt.h> +#include <iprt/initterm.h> +#include <iprt/ldr.h> +#include <iprt/message.h> +#include <iprt/stream.h> +#ifdef RT_OS_WINDOWS +# include <iprt/win/windows.h> +#endif +#if !defined(RT_OS_WINDOWS) && !defined(RT_OS_OS2) +# include <sys/resource.h> +# include <fcntl.h> +# include <unistd.h> +#endif + +#include <string.h> + +#define VBOXGLTEST_WITH_LOGGING /** @todo r=andy Is this intentional? */ + +#ifdef VBOXGLTEST_WITH_LOGGING +# include "package-generated.h" + +# include <iprt/log.h> +# include <iprt/param.h> +# include <iprt/time.h> +# include <iprt/system.h> +# include <iprt/process.h> +# include <iprt/env.h> + +# include <VBox/log.h> +# include <VBox/version.h> +#endif /* VBOXGLTEST_WITH_LOGGING */ + +#ifndef RT_OS_WINDOWS +# include <GL/gl.h> /* For GLubyte and friends. */ +#endif + +#ifdef VBOX_WITH_VIDEOHWACCEL +# include <QApplication> +# if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) && defined(RT_OS_WINDOWS) +# include <QGLWidget> /* for GL headers on windows */ +# endif +# include <VBox/VBoxGL2D.h> +#endif + +/** + * The OpenGL methods to look for when checking 3D presence. + */ +static const char * const g_apszOglMethods[] = +{ +#ifdef RT_OS_WINDOWS + "wglCreateContext", + "wglDeleteContext", + "wglMakeCurrent", + "wglShareLists", +#elif defined(RT_OS_LINUX) || defined(RT_OS_FREEBSD) || defined(RT_OS_SOLARIS) + "glXQueryVersion", + "glXChooseVisual", + "glXCreateContext", + "glXMakeCurrent", + "glXDestroyContext", +#endif + "glAlphaFunc", + "glBindTexture", + "glBlendFunc", + "glClear", + "glClearColor", + "glClearDepth", + "glClearStencil", + "glClipPlane", + "glColorMask", + "glColorPointer", + "glCullFace", + "glDeleteTextures", + "glDepthFunc", + "glDepthMask", + "glDepthRange", + "glDisable", + "glDisableClientState", + "glDrawArrays", + "glDrawElements", + "glEnable", + "glEnableClientState", + "glFogf", + "glFogfv", + "glFogi", + "glFrontFace", + "glGenTextures", + "glGetBooleanv", + "glGetError", + "glGetFloatv", + "glGetIntegerv", + "glGetString", + "glGetTexImage", + "glLightModelfv", + "glLightf", + "glLightfv", + "glLineWidth", + "glLoadIdentity", + "glLoadMatrixf", + "glMaterialfv", + "glMatrixMode", + "glMultMatrixf", + "glNormalPointer", + "glPixelStorei", + "glPointSize", + "glPolygonMode", + "glPolygonOffset", + "glPopAttrib", + "glPopMatrix", + "glPushAttrib", + "glPushMatrix", + "glScissor", + "glShadeModel", + "glStencilFunc", + "glStencilMask", + "glStencilOp", + "glTexCoordPointer", + "glTexImage2D", + "glTexParameterf", + "glTexParameterfv", + "glTexParameteri", + "glTexSubImage2D", + "glVertexPointer", + "glViewport" +}; + + +/** + * Tries to resolve the given OpenGL symbol. + * + * @returns Pointer to the symbol or nULL on error. + * @param pszSymbol The symbol to resolve. + */ +DECLINLINE(PFNRT) vboxTestOglGetProc(const char *pszSymbol) +{ + int vrc; + +#ifdef RT_OS_WINDOWS + static RTLDRMOD s_hOpenGL32 = NULL; + if (s_hOpenGL32 == NULL) + { + vrc = RTLdrLoadSystem("opengl32", /* fNoUnload = */ true, &s_hOpenGL32); + if (RT_FAILURE(vrc)) + s_hOpenGL32 = NULL; + } + + typedef PROC (WINAPI *PFNWGLGETPROCADDRESS)(LPCSTR); + static PFNWGLGETPROCADDRESS s_wglGetProcAddress = NULL; + if (s_wglGetProcAddress == NULL) + { + if (s_hOpenGL32 != NULL) + { + vrc = RTLdrGetSymbol(s_hOpenGL32, "wglGetProcAddress", (void **)&s_wglGetProcAddress); + if (RT_FAILURE(vrc)) + s_wglGetProcAddress = NULL; + } + } + + if (s_wglGetProcAddress) + { + /* Khronos: [on failure] "some implementations will return other values. 1, 2, and 3 are used, as well as -1". */ + PFNRT p = (PFNRT)s_wglGetProcAddress(pszSymbol); + if (RT_VALID_PTR(p)) + return p; + + /* Might be an exported symbol. */ + vrc = RTLdrGetSymbol(s_hOpenGL32, pszSymbol, (void **)&p); + if (RT_SUCCESS(vrc)) + return p; + } +#else /* The X11 gang */ + static RTLDRMOD s_hGL = NULL; + if (s_hGL == NULL) + { + static const char s_szLibGL[] = "libGL.so.1"; + vrc = RTLdrLoadEx(s_szLibGL, &s_hGL, RTLDRLOAD_FLAGS_GLOBAL | RTLDRLOAD_FLAGS_NO_UNLOAD, NULL); + if (RT_FAILURE(vrc)) + { + s_hGL = NULL; + return NULL; + } + } + + typedef PFNRT (* PFNGLXGETPROCADDRESS)(const GLubyte * procName); + static PFNGLXGETPROCADDRESS s_glXGetProcAddress = NULL; + if (s_glXGetProcAddress == NULL) + { + vrc = RTLdrGetSymbol(s_hGL, "glXGetProcAddress", (void **)&s_glXGetProcAddress); + if (RT_FAILURE(vrc)) + { + s_glXGetProcAddress = NULL; + return NULL; + } + } + + PFNRT p = s_glXGetProcAddress((const GLubyte *)pszSymbol); + if (RT_VALID_PTR(p)) + return p; + + /* Might be an exported symbol. */ + vrc = RTLdrGetSymbol(s_hGL, pszSymbol, (void **)&p); + if (RT_SUCCESS(vrc)) + return p; +#endif + + return NULL; +} + +static int vboxCheck3DAccelerationSupported() +{ + LogRel(("Testing 3D Support:\n")); + + for (uint32_t i = 0; i < RT_ELEMENTS(g_apszOglMethods); i++) + { + PFNRT pfn = vboxTestOglGetProc(g_apszOglMethods[i]); + if (!pfn) + { + LogRel(("Testing 3D Failed\n")); + return 1; + } + } + + LogRel(("Testing 3D Succeeded!\n")); + return 0; +} + +#ifdef VBOX_WITH_VIDEOHWACCEL +static int vboxCheck2DVideoAccelerationSupported() +{ + LogRel(("Testing 2D Support:\n")); + char *apszDummyArgs[] = { (char *)"GLTest", NULL }; + int cDummyArgs = RT_ELEMENTS(apszDummyArgs) - 1; + QApplication app(cDummyArgs, apszDummyArgs); + + VBoxGLTmpContext ctx; + const MY_QOpenGLContext *pContext = ctx.makeCurrent(); + if (pContext) + { + VBoxVHWAInfo supportInfo; + supportInfo.init(pContext); + if (supportInfo.isVHWASupported()) + { + LogRel(("Testing 2D Succeeded!\n")); + return 0; + } + } + else + { + LogRel(("Failed to create gl context\n")); + } + LogRel(("Testing 2D Failed\n")); + return 1; +} +#endif + +#ifdef VBOXGLTEST_WITH_LOGGING +static int vboxInitLogging(const char *pszFilename, bool bGenNameSuffix) +{ + PRTLOGGER loggerRelease; + static const char * const s_apszGroups[] = VBOX_LOGGROUP_NAMES; + RTUINT fFlags = RTLOGFLAGS_PREFIX_TIME_PROG; +#if defined(RT_OS_WINDOWS) || defined(RT_OS_OS2) + fFlags |= RTLOGFLAGS_USECRLF; +#endif + const char * pszFilenameFmt; + RTLOGDEST enmLogDest; + if(pszFilename) + { + if(bGenNameSuffix) + pszFilenameFmt = "%s.%ld.log"; + else + pszFilenameFmt = "%s"; + enmLogDest = RTLOGDEST_FILE; + } + else + { + pszFilenameFmt = NULL; + enmLogDest = RTLOGDEST_STDOUT; + } + + + int vrc = RTLogCreateEx(&loggerRelease, "VBOX_RELEASE_LOG", fFlags, "all", RT_ELEMENTS(s_apszGroups), s_apszGroups, UINT32_MAX, + 0 /*cBufDescs*/, NULL /*paBufDescs*/, enmLogDest, + NULL /*pfnBeginEnd*/, 0 /*cHistory*/, 0 /*cbHistoryFileMax*/, 0 /*uHistoryTimeMax*/, + NULL /*pOutputIf*/, NULL /*pvOutputIfUser*/, + NULL /*pErrInfo*/, pszFilenameFmt, pszFilename, RTTimeMilliTS()); + if (RT_SUCCESS(vrc)) + { + /* some introductory information */ + RTTIMESPEC timeSpec; + char szTmp[256]; + RTTimeSpecToString(RTTimeNow(&timeSpec), szTmp, sizeof(szTmp)); + RTLogRelLogger(loggerRelease, 0, ~0U, + "VBoxTestGL %s r%u %s (%s %s) release log\n" +#ifdef VBOX_BLEEDING_EDGE + "EXPERIMENTAL build " VBOX_BLEEDING_EDGE "\n" +#endif + "Log opened %s\n", + VBOX_VERSION_STRING, RTBldCfgRevision(), VBOX_BUILD_TARGET, + __DATE__, __TIME__, szTmp); + + vrc = RTSystemQueryOSInfo(RTSYSOSINFO_PRODUCT, szTmp, sizeof(szTmp)); + if (RT_SUCCESS(vrc) || vrc == VERR_BUFFER_OVERFLOW) + RTLogRelLogger(loggerRelease, 0, ~0U, "OS Product: %s\n", szTmp); + vrc = RTSystemQueryOSInfo(RTSYSOSINFO_RELEASE, szTmp, sizeof(szTmp)); + if (RT_SUCCESS(vrc) || vrc == VERR_BUFFER_OVERFLOW) + RTLogRelLogger(loggerRelease, 0, ~0U, "OS Release: %s\n", szTmp); + vrc = RTSystemQueryOSInfo(RTSYSOSINFO_VERSION, szTmp, sizeof(szTmp)); + if (RT_SUCCESS(vrc) || vrc == VERR_BUFFER_OVERFLOW) + RTLogRelLogger(loggerRelease, 0, ~0U, "OS Version: %s\n", szTmp); + vrc = RTSystemQueryOSInfo(RTSYSOSINFO_SERVICE_PACK, szTmp, sizeof(szTmp)); + if (RT_SUCCESS(vrc) || vrc == VERR_BUFFER_OVERFLOW) + RTLogRelLogger(loggerRelease, 0, ~0U, "OS Service Pack: %s\n", szTmp); +// RTLogRelLogger(loggerRelease, 0, ~0U, "Host RAM: %uMB RAM, available: %uMB\n", +// uHostRamMb, uHostRamAvailMb); + /* the package type is interesting for Linux distributions */ + char szExecName[RTPATH_MAX]; + char *pszExecName = RTProcGetExecutablePath(szExecName, sizeof(szExecName)); + RTLogRelLogger(loggerRelease, 0, ~0U, + "Executable: %s\n" + "Process ID: %u\n" + "Package type: %s" +#ifdef VBOX_OSE + " (OSE)" +#endif + "\n", + pszExecName ? pszExecName : "unknown", + RTProcSelf(), + VBOX_PACKAGE_STRING); + + /* register this logger as the release logger */ + RTLogRelSetDefaultInstance(loggerRelease); + + return VINF_SUCCESS; + } + + return vrc; +} +#endif + +static int vboxInitQuietMode() +{ +#if !defined(RT_OS_WINDOWS) && !defined(RT_OS_OS2) + /* This small test application might crash on some hosts. Do never + * generate a core dump as most likely some OpenGL library is + * responsible. */ + struct rlimit lim = { 0, 0 }; + setrlimit(RLIMIT_CORE, &lim); + + /* Redirect stderr to /dev/null */ + int fd = open("/dev/null", O_WRONLY); + if (fd != -1) + dup2(fd, STDERR_FILENO); +#endif + return 0; +} + +int main(int argc, char **argv) +{ + RTR3InitExe(argc, &argv, 0); + + int vrc = 0; + if (argc < 2) + { + /* backwards compatibility: check 3D */ + vrc = vboxCheck3DAccelerationSupported(); + } + else + { + static const RTGETOPTDEF s_aOptionDefs[] = + { + { "--test", 't', RTGETOPT_REQ_STRING }, + { "-test", 't', RTGETOPT_REQ_STRING }, +#ifdef VBOXGLTEST_WITH_LOGGING + { "--log", 'l', RTGETOPT_REQ_STRING }, + { "--log-to-stdout", 'L', RTGETOPT_REQ_NOTHING }, +#endif + }; + + RTGETOPTSTATE State; + vrc = RTGetOptInit(&State, argc, argv, &s_aOptionDefs[0], RT_ELEMENTS(s_aOptionDefs), 1, 0); + AssertRCReturn(vrc, 49); + +#ifdef VBOX_WITH_VIDEOHWACCEL + bool fTest2D = false; +#endif + bool fTest3D = false; +#ifdef VBOXGLTEST_WITH_LOGGING + bool fLog = false; + bool fLogSuffix = false; + const char * pLog = NULL; +#endif + + for (;;) + { + RTGETOPTUNION Val; + vrc = RTGetOpt(&State, &Val); + if (!vrc) + break; + switch (vrc) + { + case 't': + if (!strcmp(Val.psz, "3D") || !strcmp(Val.psz, "3d")) + fTest3D = true; +#ifdef VBOX_WITH_VIDEOHWACCEL + else if (!strcmp(Val.psz, "2D") || !strcmp(Val.psz, "2d")) + fTest2D = true; +#endif + else + return RTMsgErrorExit(RTEXITCODE_FAILURE, "Unknown test: %s", Val.psz); + break; + +#ifdef VBOXGLTEST_WITH_LOGGING + case 'l': + fLog = true; + pLog = Val.psz; + break; + case 'L': + fLog = true; + pLog = NULL; + break; +#endif + case 'h': + RTPrintf(VBOX_PRODUCT " Helper for testing 2D/3D OpenGL capabilities %u.%u.%u\n" + "Copyright (C) 2009-" VBOX_C_YEAR " " VBOX_VENDOR "\n" + "\n" + "Parameters:\n" +#ifdef VBOX_WITH_VIDEOHWACCEL + " --test 2D test for 2D (video) OpenGL capabilities\n" +#endif + " --test 3D test for 3D OpenGL capabilities\n" +#ifdef VBOXGLTEST_WITH_LOGGING + " --log <log_file_name> log the GL test result to the given file\n" + " --log-to-stdout log the GL test result to stdout\n" + "\n" + "Logging can alternatively be enabled by specifying the VBOXGLTEST_LOG=<log_file_name> env variable\n" + +#endif + "\n", + RTBldCfgVersionMajor(), RTBldCfgVersionMinor(), RTBldCfgVersionBuild()); + return RTEXITCODE_SUCCESS; + + case 'V': + RTPrintf("$Revision: 155484 $\n"); + return RTEXITCODE_SUCCESS; + + case VERR_GETOPT_UNKNOWN_OPTION: + case VINF_GETOPT_NOT_OPTION: + default: + return RTGetOptPrintError(vrc, &Val); + } + } + + /* + * Init logging and output. + */ +#ifdef VBOXGLTEST_WITH_LOGGING + if (!fLog) + { + /* check the VBOXGLTEST_LOG env var */ + pLog = RTEnvGet("VBOXGLTEST_LOG"); + if(pLog) + fLog = true; + fLogSuffix = true; + } + if (fLog) + vrc = vboxInitLogging(pLog, fLogSuffix); + else +#endif + vrc = vboxInitQuietMode(); + + /* + * Do the job. + */ + if (!vrc && fTest3D) + vrc = vboxCheck3DAccelerationSupported(); + +#ifdef VBOX_WITH_VIDEOHWACCEL + if (!vrc && fTest2D) + vrc = vboxCheck2DVideoAccelerationSupported(); +#endif + } + + /*RTR3Term();*/ + return vrc; + +} + +#ifdef RT_OS_WINDOWS +extern "C" int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd) +{ + RT_NOREF(hInstance, hPrevInstance, lpCmdLine, nShowCmd); + return main(__argc, __argv); +} +#endif + diff --git a/src/VBox/Main/src-helper-apps/OpenGLTest/OpenGLTestDarwin.cpp b/src/VBox/Main/src-helper-apps/OpenGLTest/OpenGLTestDarwin.cpp new file mode 100644 index 00000000..7ee1c313 --- /dev/null +++ b/src/VBox/Main/src-helper-apps/OpenGLTest/OpenGLTestDarwin.cpp @@ -0,0 +1,183 @@ +/* $Id: OpenGLTestDarwin.cpp $ */ +/** @file + * VBox host opengl support test + */ + +/* + * Copyright (C) 2009-2023 Oracle and/or its affiliates. + * + * This file is part of VirtualBox base platform packages, as + * available from https://www.virtualbox.org. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, in version 3 of the + * License. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see <https://www.gnu.org/licenses>. + * + * SPDX-License-Identifier: GPL-3.0-only + */ + + +/********************************************************************************************************************************* +* Header Files * +*********************************************************************************************************************************/ +#include <VBox/VBoxOGL.h> + +#include <IOKit/IOKitLib.h> +#include <OpenGL/OpenGL.h> +#include <ApplicationServices/ApplicationServices.h> +#include <OpenGL/gl.h> +#include <OpenGL/glu.h> + +#include <iprt/env.h> +#include <iprt/log.h> +#include <iprt/once.h> + + + +/** + * @callback_method_impl{FNRTONCE, + * For determining the cached VBoxOglIsOfflineRenderingAppropriate result.} + */ +static DECLCALLBACK(int32_t) vboxOglIsOfflineRenderingAppropriateOnce(void *pvUser) +{ + bool *pfAppropriate = (bool *)pvUser; + + /* It is assumed that it is makes sense to enable offline rendering + only in case if host has more than one GPU installed. This routine + counts all the PCI devices in IORegistry which have IOName property + set to "display". If the number of such devices is greater than one, + it sets pfAppropriate to TRUE, otherwise to FALSE. */ + + CFStringRef apKeyStrings[] = { CFSTR(kIOProviderClassKey), CFSTR(kIONameMatchKey) }; + CFStringRef apValueStrings[] = { CFSTR("IOPCIDevice"), CFSTR("display") }; + Assert(RT_ELEMENTS(apKeyStrings) == RT_ELEMENTS(apValueStrings)); + + CFDictionaryRef pMatchingDictionary = CFDictionaryCreate(kCFAllocatorDefault, + (const void **)apKeyStrings, + (const void **)apValueStrings, + RT_ELEMENTS(apKeyStrings), + &kCFTypeDictionaryKeyCallBacks, + &kCFTypeDictionaryValueCallBacks); + if (pMatchingDictionary) + { + /* The reference to pMatchingDictionary is consumed by the function below => no IORelease(pMatchingDictionary)! */ + io_iterator_t matchingServices; + kern_return_t krc = IOServiceGetMatchingServices(kIOMasterPortDefault, pMatchingDictionary, &matchingServices); + if (krc == kIOReturnSuccess) + { + io_object_t matchingService; + int cMatchingServices = 0; + + while ((matchingService = IOIteratorNext(matchingServices)) != 0) + { + cMatchingServices++; + IOObjectRelease(matchingService); + } + + *pfAppropriate = cMatchingServices > 1; + + IOObjectRelease(matchingServices); + } + } + + LogRel(("OpenGL: Offline rendering support is %s (pid=%d)\n", *pfAppropriate ? "ON" : "OFF", (int)getpid())); + return VINF_SUCCESS; +} + + +bool RTCALL VBoxOglIsOfflineRenderingAppropriate(void) +{ + /* In order to do not slowdown 3D engine which can ask about offline rendering several times, + let's cache the result and assume that renderers amount value is constant. Use the IPRT + execute once construct to make sure there aren't any threading issues. */ + static RTONCE s_Once = RTONCE_INITIALIZER; + static bool s_fCached = false; + int vrc = RTOnce(&s_Once, vboxOglIsOfflineRenderingAppropriateOnce, &s_fCached); + AssertRC(vrc); + return s_fCached; +} + + +bool RTCALL VBoxOglIs3DAccelerationSupported(void) +{ + if (RTEnvExist("VBOX_3D_FORCE_SUPPORTED")) + { + LogRel(("VBOX_3D_FORCE_SUPPORTED is specified, skipping 3D test, and treating as supported\n")); + return true; + } + + CGOpenGLDisplayMask cglDisplayMask = CGDisplayIDToOpenGLDisplayMask(CGMainDisplayID()); + CGLPixelFormatAttribute aAttribs[] = + { + kCGLPFADisplayMask, + (CGLPixelFormatAttribute)cglDisplayMask, + kCGLPFAAccelerated, + kCGLPFADoubleBuffer, + VBoxOglIsOfflineRenderingAppropriate() ? kCGLPFAAllowOfflineRenderers : (CGLPixelFormatAttribute)NULL, + (CGLPixelFormatAttribute)NULL + }; + CGLPixelFormatObj pPixelFormat = NULL; + GLint cPixelFormatsIgnored = 0; + CGLError rcCgl = CGLChoosePixelFormat(aAttribs, &pPixelFormat, &cPixelFormatsIgnored); + if (rcCgl != kCGLNoError) + { + LogRel(("OpenGL Info: 3D test unable to choose pixel format (rcCgl=0x%X)\n", rcCgl)); + return false; + } + + if (pPixelFormat) + { + CGLContextObj pCglContext = 0; + rcCgl = CGLCreateContext(pPixelFormat, NULL, &pCglContext); + CGLDestroyPixelFormat(pPixelFormat); + + if (rcCgl != kCGLNoError) + { + LogRel(("OpenGL Info: 3D test unable to create context (rcCgl=0x%X)\n", rcCgl)); + return false; + } + + if (pCglContext) + { + GLboolean isSupported = GL_TRUE; + + /* + * In the Cocoa port we depend on the GL_EXT_framebuffer_object & + * the GL_EXT_texture_rectangle extension. If they are not + * available, disable 3D support. + */ +#pragma clang diagnostic ignored "-Wdeprecated-declarations" /* gluCheckExtension deprecated since 10.10 - use MetalKit. */ + CGLSetCurrentContext(pCglContext); + const GLubyte *pszExts = glGetString(GL_EXTENSIONS); + isSupported = gluCheckExtension((const GLubyte *)"GL_EXT_framebuffer_object", pszExts); + if (isSupported) + { + isSupported = gluCheckExtension((const GLubyte *)"GL_EXT_texture_rectangle", pszExts); + if (!isSupported) + LogRel(("OpenGL Info: 3D test found that GL_EXT_texture_rectangle extension not supported.\n")); + } + else + LogRel(("OpenGL Info: 3D test found that GL_EXT_framebuffer_object extension not supported.\n")); + + CGLDestroyContext(pCglContext); + LogRel(("OpenGL Info: 3D test %spassed\n", isSupported == GL_TRUE ? "" : "not ")); + return isSupported == GL_TRUE; + } + + LogRel(("OpenGL Info: 3D test unable to create context (internal error).\n")); + } + else + LogRel(("OpenGL Info: 3D test unable to choose pixel format (internal error).\n")); + + return false; +} + diff --git a/src/VBox/Main/src-helper-apps/OpenGLTest/VBoxFBOverlayCommon.h b/src/VBox/Main/src-helper-apps/OpenGLTest/VBoxFBOverlayCommon.h new file mode 100644 index 00000000..1d86050b --- /dev/null +++ b/src/VBox/Main/src-helper-apps/OpenGLTest/VBoxFBOverlayCommon.h @@ -0,0 +1,131 @@ +/* $Id: VBoxFBOverlayCommon.h $ */ +/** @file + * VBox Qt GUI - VBoxFrameBuffer Overlay classes declarations. + */ + +/* + * Copyright (C) 2009-2023 Oracle and/or its affiliates. + * + * This file is part of VirtualBox base platform packages, as + * available from https://www.virtualbox.org. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, in version 3 of the + * License. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see <https://www.gnu.org/licenses>. + * + * SPDX-License-Identifier: GPL-3.0-only + */ + +#ifndef MAIN_INCLUDED_SRC_src_helper_apps_OpenGLTest_VBoxFBOverlayCommon_h +#define MAIN_INCLUDED_SRC_src_helper_apps_OpenGLTest_VBoxFBOverlayCommon_h +#ifndef RT_WITHOUT_PRAGMA_ONCE +# pragma once +#endif + +#if 0 //defined(DEBUG_misha) +DECLINLINE(VOID) vboxDbgPrintF(LPCSTR szString, ...) +{ + char szBuffer[4096] = {0}; + va_list pArgList; + va_start(pArgList, szString); + _vsnprintf(szBuffer, sizeof(szBuffer) / sizeof(szBuffer[0]), szString, pArgList); + va_end(pArgList); + + OutputDebugStringA(szBuffer); +} + +# include "iprt/stream.h" +# define VBOXQGLLOG(_m) RTPrintf _m +# define VBOXQGLLOGREL(_m) do { RTPrintf _m ; LogRel( _m ); } while(0) +# define VBOXQGLDBGPRINT(_m) vboxDbgPrintF _m +#else +# define VBOXQGLLOG(_m) do {}while(0) +# define VBOXQGLLOGREL(_m) LogRel( _m ) +# define VBOXQGLDBGPRINT(_m) do {}while(0) +#endif +#define VBOXQGLLOG_ENTER(_m) do {}while(0) +//do{VBOXQGLLOG(("==>[%s]:", __FUNCTION__)); VBOXQGLLOG(_m);}while(0) +#define VBOXQGLLOG_EXIT(_m) do {}while(0) +//do{VBOXQGLLOG(("<==[%s]:", __FUNCTION__)); VBOXQGLLOG(_m);}while(0) +#ifdef DEBUG + #define VBOXQGL_ASSERTNOERR() \ + do { GLenum err = glGetError(); \ + if(err != GL_NO_ERROR) VBOXQGLLOG(("gl error occurred (0x%x)\n", err)); \ + Assert(err == GL_NO_ERROR); \ + }while(0) + + #define VBOXQGL_CHECKERR(_op) \ + do { \ + glGetError(); \ + _op \ + VBOXQGL_ASSERTNOERR(); \ + }while(0) +#else + #define VBOXQGL_ASSERTNOERR() \ + do {}while(0) + + #define VBOXQGL_CHECKERR(_op) \ + do { \ + _op \ + }while(0) +#endif + +#ifdef DEBUG +#include <iprt/time.h> + +#define VBOXGETTIME() RTTimeNanoTS() + +#define VBOXPRINTDIF(_nano, _m) do{\ + uint64_t cur = VBOXGETTIME(); NOREF(cur); \ + VBOXQGLLOG(_m); \ + VBOXQGLLOG(("(%Lu)\n", cur - (_nano))); \ + }while(0) + +class VBoxVHWADbgTimeCounter +{ +public: + VBoxVHWADbgTimeCounter(const char* msg) {mTime = VBOXGETTIME(); mMsg=msg;} + ~VBoxVHWADbgTimeCounter() {VBOXPRINTDIF(mTime, (mMsg));} +private: + uint64_t mTime; + const char* mMsg; +}; + +#define VBOXQGLLOG_METHODTIME(_m) VBoxVHWADbgTimeCounter _dbgTimeCounter(_m) + +#define VBOXQG_CHECKCONTEXT() \ + { \ + const GLubyte * str; \ + VBOXQGL_CHECKERR( \ + str = glGetString(GL_VERSION); \ + ); \ + Assert(str); \ + if(str) \ + { \ + Assert(str[0]); \ + } \ + } +#else +#define VBOXQGLLOG_METHODTIME(_m) +#define VBOXQG_CHECKCONTEXT() do{}while(0) +#endif + +#define VBOXQGLLOG_QRECT(_p, _pr, _s) do{\ + VBOXQGLLOG((_p " x(%d), y(%d), w(%d), h(%d)" _s, (_pr)->x(), (_pr)->y(), (_pr)->width(), (_pr)->height()));\ + }while(0) + +#define VBOXQGLLOG_CKEY(_p, _pck, _s) do{\ + VBOXQGLLOG((_p " l(0x%x), u(0x%x)" _s, (_pck)->lower(), (_pck)->upper()));\ + }while(0) + +#endif /* !MAIN_INCLUDED_SRC_src_helper_apps_OpenGLTest_VBoxFBOverlayCommon_h */ + diff --git a/src/VBox/Main/src-helper-apps/OpenGLTest/VBoxGLSupportInfo.cpp b/src/VBox/Main/src-helper-apps/OpenGLTest/VBoxGLSupportInfo.cpp new file mode 100644 index 00000000..539eba29 --- /dev/null +++ b/src/VBox/Main/src-helper-apps/OpenGLTest/VBoxGLSupportInfo.cpp @@ -0,0 +1,724 @@ +/* $Id: VBoxGLSupportInfo.cpp $ */ +/** @file + * VBox Qt GUI - OpenGL support info used for 2D support detection. + */ + +/* + * Copyright (C) 2009-2023 Oracle and/or its affiliates. + * + * This file is part of VirtualBox base platform packages, as + * available from https://www.virtualbox.org. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, in version 3 of the + * License. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see <https://www.gnu.org/licenses>. + * + * SPDX-License-Identifier: GPL-3.0-only + */ + +#ifdef RT_OS_WINDOWS +# include <iprt/win/windows.h> /* QGLWidget drags in Windows.h; -Wall forces us to use wrapper. */ +# include <iprt/stdint.h> /* QGLWidget drags in stdint.h; -Wall forces us to use wrapper. */ +#endif + +#include <QGuiApplication> /* For QT_VERSION */ +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) +# include <QMainWindow> +# include <QOpenGLWidget> +# include <QOpenGLContext> +#else +# include <QGLWidget> +#endif + +#include <iprt/assert.h> +#include <iprt/log.h> +#include <iprt/env.h> +#include <iprt/param.h> +#include <iprt/path.h> +#include <iprt/process.h> +#include <iprt/string.h> +#include <iprt/time.h> +#include <iprt/thread.h> + +#include <VBox/VBoxGL2D.h> +#include "VBoxFBOverlayCommon.h" +#include <iprt/err.h> + + +/*****************/ + +/* functions */ + +PFNVBOXVHWA_ACTIVE_TEXTURE vboxglActiveTexture = NULL; +PFNVBOXVHWA_MULTI_TEX_COORD2I vboxglMultiTexCoord2i = NULL; +PFNVBOXVHWA_MULTI_TEX_COORD2D vboxglMultiTexCoord2d = NULL; +PFNVBOXVHWA_MULTI_TEX_COORD2F vboxglMultiTexCoord2f = NULL; + + +PFNVBOXVHWA_CREATE_SHADER vboxglCreateShader = NULL; +PFNVBOXVHWA_SHADER_SOURCE vboxglShaderSource = NULL; +PFNVBOXVHWA_COMPILE_SHADER vboxglCompileShader = NULL; +PFNVBOXVHWA_DELETE_SHADER vboxglDeleteShader = NULL; + +PFNVBOXVHWA_CREATE_PROGRAM vboxglCreateProgram = NULL; +PFNVBOXVHWA_ATTACH_SHADER vboxglAttachShader = NULL; +PFNVBOXVHWA_DETACH_SHADER vboxglDetachShader = NULL; +PFNVBOXVHWA_LINK_PROGRAM vboxglLinkProgram = NULL; +PFNVBOXVHWA_USE_PROGRAM vboxglUseProgram = NULL; +PFNVBOXVHWA_DELETE_PROGRAM vboxglDeleteProgram = NULL; + +PFNVBOXVHWA_IS_SHADER vboxglIsShader = NULL; +PFNVBOXVHWA_GET_SHADERIV vboxglGetShaderiv = NULL; +PFNVBOXVHWA_IS_PROGRAM vboxglIsProgram = NULL; +PFNVBOXVHWA_GET_PROGRAMIV vboxglGetProgramiv = NULL; +PFNVBOXVHWA_GET_ATTACHED_SHADERS vboxglGetAttachedShaders = NULL; +PFNVBOXVHWA_GET_SHADER_INFO_LOG vboxglGetShaderInfoLog = NULL; +PFNVBOXVHWA_GET_PROGRAM_INFO_LOG vboxglGetProgramInfoLog = NULL; + +PFNVBOXVHWA_GET_UNIFORM_LOCATION vboxglGetUniformLocation = NULL; + +PFNVBOXVHWA_UNIFORM1F vboxglUniform1f = NULL; +PFNVBOXVHWA_UNIFORM2F vboxglUniform2f = NULL; +PFNVBOXVHWA_UNIFORM3F vboxglUniform3f = NULL; +PFNVBOXVHWA_UNIFORM4F vboxglUniform4f = NULL; + +PFNVBOXVHWA_UNIFORM1I vboxglUniform1i = NULL; +PFNVBOXVHWA_UNIFORM2I vboxglUniform2i = NULL; +PFNVBOXVHWA_UNIFORM3I vboxglUniform3i = NULL; +PFNVBOXVHWA_UNIFORM4I vboxglUniform4i = NULL; + +PFNVBOXVHWA_GEN_BUFFERS vboxglGenBuffers = NULL; +PFNVBOXVHWA_DELETE_BUFFERS vboxglDeleteBuffers = NULL; +PFNVBOXVHWA_BIND_BUFFER vboxglBindBuffer = NULL; +PFNVBOXVHWA_BUFFER_DATA vboxglBufferData = NULL; +PFNVBOXVHWA_MAP_BUFFER vboxglMapBuffer = NULL; +PFNVBOXVHWA_UNMAP_BUFFER vboxglUnmapBuffer = NULL; + +PFNVBOXVHWA_IS_FRAMEBUFFER vboxglIsFramebuffer = NULL; +PFNVBOXVHWA_BIND_FRAMEBUFFER vboxglBindFramebuffer = NULL; +PFNVBOXVHWA_DELETE_FRAMEBUFFERS vboxglDeleteFramebuffers = NULL; +PFNVBOXVHWA_GEN_FRAMEBUFFERS vboxglGenFramebuffers = NULL; +PFNVBOXVHWA_CHECK_FRAMEBUFFER_STATUS vboxglCheckFramebufferStatus = NULL; +PFNVBOXVHWA_FRAMEBUFFER_TEXTURE1D vboxglFramebufferTexture1D = NULL; +PFNVBOXVHWA_FRAMEBUFFER_TEXTURE2D vboxglFramebufferTexture2D = NULL; +PFNVBOXVHWA_FRAMEBUFFER_TEXTURE3D vboxglFramebufferTexture3D = NULL; +PFNVBOXVHWA_GET_FRAMEBUFFER_ATTACHMENT_PARAMETRIV vboxglGetFramebufferAttachmentParameteriv = NULL; + +#define VBOXVHWA_GETPROCADDRESS(_c, _t, _n) ((_t)(uintptr_t)(_c).getProcAddress(_n)) + +#define VBOXVHWA_PFNINIT_SAME(_c, _t, _v, _rc) \ + do { \ + if((vboxgl##_v = VBOXVHWA_GETPROCADDRESS(_c, _t, "gl"#_v)) == NULL) \ + { \ + VBOXQGLLOGREL(("ERROR: '%s' function not found\n", "gl"#_v));\ + AssertBreakpoint(); \ + if((vboxgl##_v = VBOXVHWA_GETPROCADDRESS(_c, _t, "gl"#_v"ARB")) == NULL) \ + { \ + VBOXQGLLOGREL(("ERROR: '%s' function not found\n", "gl"#_v"ARB"));\ + AssertBreakpoint(); \ + if((vboxgl##_v = VBOXVHWA_GETPROCADDRESS(_c, _t, "gl"#_v"EXT")) == NULL) \ + { \ + VBOXQGLLOGREL(("ERROR: '%s' function not found\n", "gl"#_v"EXT"));\ + AssertBreakpoint(); \ + (_rc)++; \ + } \ + } \ + } \ + }while(0) + +#define VBOXVHWA_PFNINIT(_c, _t, _v, _f,_rc) \ + do { \ + if((vboxgl##_v = VBOXVHWA_GETPROCADDRESS(_c, _t, "gl"#_f)) == NULL) \ + { \ + VBOXQGLLOGREL(("ERROR: '%s' function is not found\n", "gl"#_f));\ + AssertBreakpoint(); \ + (_rc)++; \ + } \ + }while(0) + +#define VBOXVHWA_PFNINIT_OBJECT_ARB(_c, _t, _v, _rc) \ + do { \ + if((vboxgl##_v = VBOXVHWA_GETPROCADDRESS(_c, _t, "gl"#_v"ObjectARB")) == NULL) \ + { \ + VBOXQGLLOGREL(("ERROR: '%s' function is not found\n", "gl"#_v"ObjectARB"));\ + AssertBreakpoint(); \ + (_rc)++; \ + } \ + }while(0) + +#define VBOXVHWA_PFNINIT_ARB(_c, _t, _v, _rc) \ + do { \ + if((vboxgl##_v = VBOXVHWA_GETPROCADDRESS(_c, _t, "gl"#_v"ARB")) == NULL) \ + { \ + VBOXQGLLOGREL(("ERROR: '%s' function is not found\n", "gl"#_v"ARB"));\ + AssertBreakpoint(); \ + (_rc)++; \ + } \ + }while(0) + +#define VBOXVHWA_PFNINIT_EXT(_c, _t, _v, _rc) \ + do { \ + if((vboxgl##_v = VBOXVHWA_GETPROCADDRESS(_c, _t, "gl"#_v"EXT")) == NULL) \ + { \ + VBOXQGLLOGREL(("ERROR: '%s' function is not found\n", "gl"#_v"EXT"));\ + AssertBreakpoint(); \ + (_rc)++; \ + } \ + }while(0) + +static int vboxVHWAGlParseSubver(const GLubyte * ver, const GLubyte ** pNext, bool bSpacePrefixAllowed) +{ + int val = 0; + + for(;;++ver) + { + if(*ver >= '0' && *ver <= '9') + { + if(!val) + { + if(*ver == '0') + continue; + } + else + { + val *= 10; + } + val += *ver - '0'; + } + else if(*ver == '.') + { + *pNext = ver+1; + break; + } + else if(*ver == '\0') + { + *pNext = NULL; + break; + } + else if(*ver == ' ' || *ver == '\t' || *ver == 0x0d || *ver == 0x0a) + { + if(bSpacePrefixAllowed) + { + if(!val) + { + continue; + } + } + + /* treat this as the end ov version string */ + *pNext = NULL; + break; + } + else + { + Assert(0); + val = -1; + break; + } + } + + return val; +} + +/* static */ +int VBoxGLInfo::parseVersion(const GLubyte * ver) +{ + int iVer = vboxVHWAGlParseSubver(ver, &ver, true); + if(iVer) + { + iVer <<= 16; + if(ver) + { + int tmp = vboxVHWAGlParseSubver(ver, &ver, false); + if(tmp >= 0) + { + iVer |= tmp << 8; + if(ver) + { + tmp = vboxVHWAGlParseSubver(ver, &ver, false); + if(tmp >= 0) + { + iVer |= tmp; + } + else + { + Assert(0); + iVer = -1; + } + } + } + else + { + Assert(0); + iVer = -1; + } + } + } + return iVer; +} + +void VBoxGLInfo::init(const MY_QOpenGLContext *pContext) +{ + if (mInitialized) + return; + + mInitialized = true; + +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) + if (!QGLFormat::hasOpenGL()) + { + VBOXQGLLOGREL (("no gl support available\n")); + return; + } +#endif + +// pContext->makeCurrent(); + + const GLubyte * str; + VBOXQGL_CHECKERR( + str = glGetString(GL_VERSION); + ); + + if (str) + { + VBOXQGLLOGREL (("gl version string: 0%s\n", str)); + + mGLVersion = parseVersion (str); + Assert(mGLVersion > 0); + if(mGLVersion < 0) + { + mGLVersion = 0; + } + else + { + VBOXQGLLOGREL (("gl version: 0x%x\n", mGLVersion)); + VBOXQGL_CHECKERR( + str = glGetString (GL_EXTENSIONS); + ); + + VBOXQGLLOGREL (("gl extensions: %s\n", str)); + + const char * pos = strstr((const char *)str, "GL_ARB_multitexture"); + m_GL_ARB_multitexture = pos != NULL; + VBOXQGLLOGREL (("GL_ARB_multitexture: %d\n", m_GL_ARB_multitexture)); + + pos = strstr((const char *)str, "GL_ARB_shader_objects"); + m_GL_ARB_shader_objects = pos != NULL; + VBOXQGLLOGREL (("GL_ARB_shader_objects: %d\n", m_GL_ARB_shader_objects)); + + pos = strstr((const char *)str, "GL_ARB_fragment_shader"); + m_GL_ARB_fragment_shader = pos != NULL; + VBOXQGLLOGREL (("GL_ARB_fragment_shader: %d\n", m_GL_ARB_fragment_shader)); + + pos = strstr((const char *)str, "GL_ARB_pixel_buffer_object"); + m_GL_ARB_pixel_buffer_object = pos != NULL; + VBOXQGLLOGREL (("GL_ARB_pixel_buffer_object: %d\n", m_GL_ARB_pixel_buffer_object)); + + pos = strstr((const char *)str, "GL_ARB_texture_rectangle"); + m_GL_ARB_texture_rectangle = pos != NULL; + VBOXQGLLOGREL (("GL_ARB_texture_rectangle: %d\n", m_GL_ARB_texture_rectangle)); + + pos = strstr((const char *)str, "GL_EXT_texture_rectangle"); + m_GL_EXT_texture_rectangle = pos != NULL; + VBOXQGLLOGREL (("GL_EXT_texture_rectangle: %d\n", m_GL_EXT_texture_rectangle)); + + pos = strstr((const char *)str, "GL_NV_texture_rectangle"); + m_GL_NV_texture_rectangle = pos != NULL; + VBOXQGLLOGREL (("GL_NV_texture_rectangle: %d\n", m_GL_NV_texture_rectangle)); + + pos = strstr((const char *)str, "GL_ARB_texture_non_power_of_two"); + m_GL_ARB_texture_non_power_of_two = pos != NULL; + VBOXQGLLOGREL (("GL_ARB_texture_non_power_of_two: %d\n", m_GL_ARB_texture_non_power_of_two)); + + pos = strstr((const char *)str, "GL_EXT_framebuffer_object"); + m_GL_EXT_framebuffer_object = pos != NULL; + VBOXQGLLOGREL (("GL_EXT_framebuffer_object: %d\n", m_GL_EXT_framebuffer_object)); + + + initExtSupport(*pContext); + } + } + else + { + VBOXQGLLOGREL (("failed to make the context current, treating as unsupported\n")); + } +} + +void VBoxGLInfo::initExtSupport(const MY_QOpenGLContext &context) +{ + int vrc = VINF_SUCCESS; + do + { + mMultiTexNumSupported = 1; /* default, 1 means not supported */ + if(mGLVersion >= 0x010201) /* ogl >= 1.2.1 */ + { + VBOXVHWA_PFNINIT_SAME(context, PFNVBOXVHWA_ACTIVE_TEXTURE, ActiveTexture, vrc); + VBOXVHWA_PFNINIT_SAME(context, PFNVBOXVHWA_MULTI_TEX_COORD2I, MultiTexCoord2i, vrc); + VBOXVHWA_PFNINIT_SAME(context, PFNVBOXVHWA_MULTI_TEX_COORD2D, MultiTexCoord2d, vrc); + VBOXVHWA_PFNINIT_SAME(context, PFNVBOXVHWA_MULTI_TEX_COORD2F, MultiTexCoord2f, vrc); + } + else if(m_GL_ARB_multitexture) + { + VBOXVHWA_PFNINIT_ARB(context, PFNVBOXVHWA_ACTIVE_TEXTURE, ActiveTexture, vrc); + VBOXVHWA_PFNINIT_ARB(context, PFNVBOXVHWA_MULTI_TEX_COORD2I, MultiTexCoord2i, vrc); + VBOXVHWA_PFNINIT_ARB(context, PFNVBOXVHWA_MULTI_TEX_COORD2D, MultiTexCoord2d, vrc); + VBOXVHWA_PFNINIT_ARB(context, PFNVBOXVHWA_MULTI_TEX_COORD2F, MultiTexCoord2f, vrc); + } + else + { + break; + } + + if(RT_FAILURE(vrc)) + break; + + GLint maxCoords, maxUnits; + glGetIntegerv(GL_MAX_TEXTURE_COORDS, &maxCoords); + glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &maxUnits); + + VBOXQGLLOGREL(("Max Tex Coords (%d), Img Units (%d)\n", maxCoords, maxUnits)); + /* take the minimum of those */ + if(maxUnits < maxCoords) + maxCoords = maxUnits; + if(maxUnits < 2) + { + VBOXQGLLOGREL(("Max Tex Coord or Img Units < 2 disabling MultiTex support\n")); + break; + } + + mMultiTexNumSupported = maxUnits; + }while(0); + + + do + { + vrc = 0; + mPBOSupported = false; + + if(m_GL_ARB_pixel_buffer_object) + { + VBOXVHWA_PFNINIT_ARB(context, PFNVBOXVHWA_GEN_BUFFERS, GenBuffers, vrc); + VBOXVHWA_PFNINIT_ARB(context, PFNVBOXVHWA_DELETE_BUFFERS, DeleteBuffers, vrc); + VBOXVHWA_PFNINIT_ARB(context, PFNVBOXVHWA_BIND_BUFFER, BindBuffer, vrc); + VBOXVHWA_PFNINIT_ARB(context, PFNVBOXVHWA_BUFFER_DATA, BufferData, vrc); + VBOXVHWA_PFNINIT_ARB(context, PFNVBOXVHWA_MAP_BUFFER, MapBuffer, vrc); + VBOXVHWA_PFNINIT_ARB(context, PFNVBOXVHWA_UNMAP_BUFFER, UnmapBuffer, vrc); + } + else + { + break; + } + + if(RT_FAILURE(vrc)) + break; + + mPBOSupported = true; + } while(0); + + do + { + vrc = 0; + mFragmentShaderSupported = false; + + if(mGLVersion >= 0x020000) /* if ogl >= 2.0*/ + { + VBOXVHWA_PFNINIT_SAME(context, PFNVBOXVHWA_CREATE_SHADER, CreateShader, vrc); + VBOXVHWA_PFNINIT_SAME(context, PFNVBOXVHWA_SHADER_SOURCE, ShaderSource, vrc); + VBOXVHWA_PFNINIT_SAME(context, PFNVBOXVHWA_COMPILE_SHADER, CompileShader, vrc); + VBOXVHWA_PFNINIT_SAME(context, PFNVBOXVHWA_DELETE_SHADER, DeleteShader, vrc); + + VBOXVHWA_PFNINIT_SAME(context, PFNVBOXVHWA_CREATE_PROGRAM, CreateProgram, vrc); + VBOXVHWA_PFNINIT_SAME(context, PFNVBOXVHWA_ATTACH_SHADER, AttachShader, vrc); + VBOXVHWA_PFNINIT_SAME(context, PFNVBOXVHWA_DETACH_SHADER, DetachShader, vrc); + VBOXVHWA_PFNINIT_SAME(context, PFNVBOXVHWA_LINK_PROGRAM, LinkProgram, vrc); + VBOXVHWA_PFNINIT_SAME(context, PFNVBOXVHWA_USE_PROGRAM, UseProgram, vrc); + VBOXVHWA_PFNINIT_SAME(context, PFNVBOXVHWA_DELETE_PROGRAM, DeleteProgram, vrc); + + VBOXVHWA_PFNINIT_SAME(context, PFNVBOXVHWA_IS_SHADER, IsShader, vrc); + VBOXVHWA_PFNINIT_SAME(context, PFNVBOXVHWA_GET_SHADERIV, GetShaderiv, vrc); + VBOXVHWA_PFNINIT_SAME(context, PFNVBOXVHWA_IS_PROGRAM, IsProgram, vrc); + VBOXVHWA_PFNINIT_SAME(context, PFNVBOXVHWA_GET_PROGRAMIV, GetProgramiv, vrc); + VBOXVHWA_PFNINIT_SAME(context, PFNVBOXVHWA_GET_ATTACHED_SHADERS, GetAttachedShaders, vrc); + VBOXVHWA_PFNINIT_SAME(context, PFNVBOXVHWA_GET_SHADER_INFO_LOG, GetShaderInfoLog, vrc); + VBOXVHWA_PFNINIT_SAME(context, PFNVBOXVHWA_GET_PROGRAM_INFO_LOG, GetProgramInfoLog, vrc); + + VBOXVHWA_PFNINIT_SAME(context, PFNVBOXVHWA_GET_UNIFORM_LOCATION, GetUniformLocation, vrc); + + VBOXVHWA_PFNINIT_SAME(context, PFNVBOXVHWA_UNIFORM1F, Uniform1f, vrc); + VBOXVHWA_PFNINIT_SAME(context, PFNVBOXVHWA_UNIFORM2F, Uniform2f, vrc); + VBOXVHWA_PFNINIT_SAME(context, PFNVBOXVHWA_UNIFORM3F, Uniform3f, vrc); + VBOXVHWA_PFNINIT_SAME(context, PFNVBOXVHWA_UNIFORM4F, Uniform4f, vrc); + + VBOXVHWA_PFNINIT_SAME(context, PFNVBOXVHWA_UNIFORM1I, Uniform1i, vrc); + VBOXVHWA_PFNINIT_SAME(context, PFNVBOXVHWA_UNIFORM2I, Uniform2i, vrc); + VBOXVHWA_PFNINIT_SAME(context, PFNVBOXVHWA_UNIFORM3I, Uniform3i, vrc); + VBOXVHWA_PFNINIT_SAME(context, PFNVBOXVHWA_UNIFORM4I, Uniform4i, vrc); + } + else if(m_GL_ARB_shader_objects && m_GL_ARB_fragment_shader) + { + VBOXVHWA_PFNINIT_OBJECT_ARB(context, PFNVBOXVHWA_CREATE_SHADER, CreateShader, vrc); + VBOXVHWA_PFNINIT_ARB(context, PFNVBOXVHWA_SHADER_SOURCE, ShaderSource, vrc); + VBOXVHWA_PFNINIT_ARB(context, PFNVBOXVHWA_COMPILE_SHADER, CompileShader, vrc); + VBOXVHWA_PFNINIT(context, PFNVBOXVHWA_DELETE_SHADER, DeleteShader, DeleteObjectARB, vrc); + + VBOXVHWA_PFNINIT_OBJECT_ARB(context, PFNVBOXVHWA_CREATE_PROGRAM, CreateProgram, vrc); + VBOXVHWA_PFNINIT(context, PFNVBOXVHWA_ATTACH_SHADER, AttachShader, AttachObjectARB, vrc); + VBOXVHWA_PFNINIT(context, PFNVBOXVHWA_DETACH_SHADER, DetachShader, DetachObjectARB, vrc); + VBOXVHWA_PFNINIT_ARB(context, PFNVBOXVHWA_LINK_PROGRAM, LinkProgram, vrc); + VBOXVHWA_PFNINIT_OBJECT_ARB(context, PFNVBOXVHWA_USE_PROGRAM, UseProgram, vrc); + VBOXVHWA_PFNINIT(context, PFNVBOXVHWA_DELETE_PROGRAM, DeleteProgram, DeleteObjectARB, vrc); + + /// @todo VBOXVHWA_PFNINIT(PFNVBOXVHWA_IS_SHADER, IsShader, vrc); + VBOXVHWA_PFNINIT(context, PFNVBOXVHWA_GET_SHADERIV, GetShaderiv, GetObjectParameterivARB, vrc); + /// @todo VBOXVHWA_PFNINIT(PFNVBOXVHWA_IS_PROGRAM, IsProgram, vrc); + VBOXVHWA_PFNINIT(context, PFNVBOXVHWA_GET_PROGRAMIV, GetProgramiv, GetObjectParameterivARB, vrc); + VBOXVHWA_PFNINIT(context, PFNVBOXVHWA_GET_ATTACHED_SHADERS, GetAttachedShaders, GetAttachedObjectsARB, vrc); + VBOXVHWA_PFNINIT(context, PFNVBOXVHWA_GET_SHADER_INFO_LOG, GetShaderInfoLog, GetInfoLogARB, vrc); + VBOXVHWA_PFNINIT(context, PFNVBOXVHWA_GET_PROGRAM_INFO_LOG, GetProgramInfoLog, GetInfoLogARB, vrc); + + VBOXVHWA_PFNINIT_ARB(context, PFNVBOXVHWA_GET_UNIFORM_LOCATION, GetUniformLocation, vrc); + + VBOXVHWA_PFNINIT_ARB(context, PFNVBOXVHWA_UNIFORM1F, Uniform1f, vrc); + VBOXVHWA_PFNINIT_ARB(context, PFNVBOXVHWA_UNIFORM2F, Uniform2f, vrc); + VBOXVHWA_PFNINIT_ARB(context, PFNVBOXVHWA_UNIFORM3F, Uniform3f, vrc); + VBOXVHWA_PFNINIT_ARB(context, PFNVBOXVHWA_UNIFORM4F, Uniform4f, vrc); + + VBOXVHWA_PFNINIT_ARB(context, PFNVBOXVHWA_UNIFORM1I, Uniform1i, vrc); + VBOXVHWA_PFNINIT_ARB(context, PFNVBOXVHWA_UNIFORM2I, Uniform2i, vrc); + VBOXVHWA_PFNINIT_ARB(context, PFNVBOXVHWA_UNIFORM3I, Uniform3i, vrc); + VBOXVHWA_PFNINIT_ARB(context, PFNVBOXVHWA_UNIFORM4I, Uniform4i, vrc); + } + else + { + break; + } + + if(RT_FAILURE(vrc)) + break; + + mFragmentShaderSupported = true; + } while(0); + + do + { + vrc = 0; + mFBOSupported = false; + + if(m_GL_EXT_framebuffer_object) + { + VBOXVHWA_PFNINIT_EXT(context, PFNVBOXVHWA_IS_FRAMEBUFFER, IsFramebuffer, vrc); + VBOXVHWA_PFNINIT_EXT(context, PFNVBOXVHWA_BIND_FRAMEBUFFER, BindFramebuffer, vrc); + VBOXVHWA_PFNINIT_EXT(context, PFNVBOXVHWA_DELETE_FRAMEBUFFERS, DeleteFramebuffers, vrc); + VBOXVHWA_PFNINIT_EXT(context, PFNVBOXVHWA_GEN_FRAMEBUFFERS, GenFramebuffers, vrc); + VBOXVHWA_PFNINIT_EXT(context, PFNVBOXVHWA_CHECK_FRAMEBUFFER_STATUS, CheckFramebufferStatus, vrc); + VBOXVHWA_PFNINIT_EXT(context, PFNVBOXVHWA_FRAMEBUFFER_TEXTURE1D, FramebufferTexture1D, vrc); + VBOXVHWA_PFNINIT_EXT(context, PFNVBOXVHWA_FRAMEBUFFER_TEXTURE2D, FramebufferTexture2D, vrc); + VBOXVHWA_PFNINIT_EXT(context, PFNVBOXVHWA_FRAMEBUFFER_TEXTURE3D, FramebufferTexture3D, vrc); + VBOXVHWA_PFNINIT_EXT(context, PFNVBOXVHWA_GET_FRAMEBUFFER_ATTACHMENT_PARAMETRIV, GetFramebufferAttachmentParameteriv, vrc); + } + else + { + break; + } + + if(RT_FAILURE(vrc)) + break; + + mFBOSupported = true; + } while(0); + + if(m_GL_ARB_texture_rectangle || m_GL_EXT_texture_rectangle || m_GL_NV_texture_rectangle) + { + mTextureRectangleSupported = true; + } + else + { + mTextureRectangleSupported = false; + } + + mTextureNP2Supported = m_GL_ARB_texture_non_power_of_two; +} + +void VBoxVHWAInfo::init(const MY_QOpenGLContext *pContext) +{ + if(mInitialized) + return; + + mInitialized = true; + + mglInfo.init(pContext); + + if(mglInfo.isFragmentShaderSupported() && mglInfo.isTextureRectangleSupported()) + { + uint32_t num = 0; + mFourccSupportedList[num++] = FOURCC_AYUV; + mFourccSupportedList[num++] = FOURCC_UYVY; + mFourccSupportedList[num++] = FOURCC_YUY2; + if(mglInfo.getMultiTexNumSupported() >= 4) + { + /* YV12 currently requires 3 units (for each color component) + * + 1 unit for dst texture for color-keying + 3 units for each color component + * TODO: we could store YV12 data in one texture to eliminate this requirement*/ + mFourccSupportedList[num++] = FOURCC_YV12; + } + + Assert(num <= VBOXVHWA_NUMFOURCC); + mFourccSupportedCount = num; + } + else + { + mFourccSupportedCount = 0; + } +} + +bool VBoxVHWAInfo::isVHWASupported() const +{ + if(mglInfo.getGLVersion() <= 0) + { + /* error occurred while gl info initialization */ + VBOXQGLLOGREL(("2D not supported: gl version info not initialized properly\n")); + return false; + } + +#ifndef DEBUGVHWASTRICT + /* in case we do not support shaders & multitexturing we can not support dst colorkey, + * no sense to report Video Acceleration supported */ + if(!mglInfo.isFragmentShaderSupported()) + { + VBOXQGLLOGREL(("2D not supported: fragment shader unsupported\n")); + return false; + } +#endif + if(mglInfo.getMultiTexNumSupported() < 2) + { + VBOXQGLLOGREL(("2D not supported: multitexture unsupported\n")); + return false; + } + + /* color conversion now supported only GL_TEXTURE_RECTANGLE + * in this case only stretching is accelerated + * report as unsupported, TODO: probably should report as supported for stretch acceleration */ + if(!mglInfo.isTextureRectangleSupported()) + { + VBOXQGLLOGREL(("2D not supported: texture rectangle unsupported\n")); + return false; + } + + VBOXQGLLOGREL(("2D is supported!\n")); + return true; +} + +/* static */ +bool VBoxVHWAInfo::checkVHWASupport() +{ +#if defined(RT_OS_WINDOWS) || defined(RT_OS_LINUX) || defined(RT_OS_FREEBSD) + static char pszVBoxPath[RTPATH_MAX]; + const char *papszArgs[] = { NULL, "-test", "2D", NULL}; + + int vrc = RTPathExecDir(pszVBoxPath, RTPATH_MAX); AssertRCReturn(vrc, false); +# if defined(RT_OS_WINDOWS) || defined(RT_OS_OS2) + vrc = RTPathAppend(pszVBoxPath, RTPATH_MAX, "VBoxTestOGL.exe"); +# else + vrc = RTPathAppend(pszVBoxPath, RTPATH_MAX, "VBoxTestOGL"); +# endif + papszArgs[0] = pszVBoxPath; /* argv[0] */ + AssertRCReturn(vrc, false); + + RTPROCESS Process; + vrc = RTProcCreate(pszVBoxPath, papszArgs, RTENV_DEFAULT, 0, &Process); + if (RT_FAILURE(vrc)) + { + VBOXQGLLOGREL(("2D support test failed: failed to create a test process\n")); + return false; + } + + uint64_t const StartTS = RTTimeMilliTS(); + + RTPROCSTATUS ProcStatus = {0}; + while (1) + { + vrc = RTProcWait(Process, RTPROCWAIT_FLAGS_NOBLOCK, &ProcStatus); + if (vrc != VERR_PROCESS_RUNNING) + break; + + if (RTTimeMilliTS() - StartTS > 30*1000 /* 30 sec */) + { + RTProcTerminate(Process); + RTThreadSleep(100); + RTProcWait(Process, RTPROCWAIT_FLAGS_NOBLOCK, &ProcStatus); + VBOXQGLLOGREL(("2D support test failed: the test did not complete within 30 sec\n")); + return false; + } + RTThreadSleep(100); + } + + if (RT_SUCCESS(vrc)) + { + if ((ProcStatus.enmReason==RTPROCEXITREASON_NORMAL) && (ProcStatus.iStatus==0)) + { + VBOXQGLLOGREL(("2D support test succeeded\n")); + return true; + } + } + + VBOXQGLLOGREL(("2D support test failed: err code (%Rra)\n", vrc)); + + return false; +#else + /** @todo test & enable external app approach*/ + VBoxGLTmpContext ctx; + const MY_QOpenGLContext *pContext = ctx.makeCurrent(); + Assert(pContext); + if (pContext) + { + VBoxVHWAInfo info; + info.init(pContext); + return info.isVHWASupported(); + } + return false; +#endif +} + +VBoxGLTmpContext::VBoxGLTmpContext() +{ +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + mWidget = new MY_QOpenGLWidget(/*new QMainWindow()*/); +#else + if (QGLFormat::hasOpenGL()) + mWidget = new MY_QOpenGLWidget(); + else + mWidget = NULL; +#endif +} + +VBoxGLTmpContext::~VBoxGLTmpContext() +{ + if (mWidget) + { + delete mWidget; + mWidget = NULL; + } +} + +const MY_QOpenGLContext *VBoxGLTmpContext::makeCurrent() +{ + if (mWidget) + { +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + mWidget->grabFramebuffer(); /* This is a hack to trigger GL initialization or context() will return NULL. */ +#endif + mWidget->makeCurrent(); + return mWidget->context(); + } + return NULL; +} + diff --git a/src/VBox/Main/src-helper-apps/OpenGLTest/VBoxTestOGL.rc b/src/VBox/Main/src-helper-apps/OpenGLTest/VBoxTestOGL.rc new file mode 100644 index 00000000..48cbc4e2 --- /dev/null +++ b/src/VBox/Main/src-helper-apps/OpenGLTest/VBoxTestOGL.rc @@ -0,0 +1,61 @@ +/* $Id: VBoxTestOGL.rc $ */ +/** @file + * VBoxTestOGL - Resource file containing version info and icon. + */ + +/* + * Copyright (C) 2015-2023 Oracle and/or its affiliates. + * + * This file is part of VirtualBox base platform packages, as + * available from https://www.virtualbox.org. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, in version 3 of the + * License. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see <https://www.gnu.org/licenses>. + * + * SPDX-License-Identifier: GPL-3.0-only + */ + +#include <windows.h> +#include <VBox/version.h> + +LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US + +VS_VERSION_INFO VERSIONINFO + FILEVERSION VBOX_RC_FILE_VERSION + PRODUCTVERSION VBOX_RC_FILE_VERSION + FILEFLAGSMASK VS_FFI_FILEFLAGSMASK + FILEFLAGS VBOX_RC_FILE_FLAGS + FILEOS VBOX_RC_FILE_OS + FILETYPE VBOX_RC_TYPE_APP + FILESUBTYPE VFT2_UNKNOWN +BEGIN + BLOCK "StringFileInfo" + BEGIN + BLOCK "040904b0" // Lang=US English, CharSet=Unicode + BEGIN + VALUE "FileDescription", "VirtualBox OpenGL Test Tool\0" + VALUE "InternalName", "VBoxTestOGL\0" + VALUE "OriginalFilename", "VBoxTestOGL.exe\0" + VALUE "CompanyName", VBOX_RC_COMPANY_NAME + VALUE "FileVersion", VBOX_RC_FILE_VERSION_STR + VALUE "LegalCopyright", VBOX_RC_LEGAL_COPYRIGHT + VALUE "ProductName", VBOX_RC_PRODUCT_NAME_STR + VALUE "ProductVersion", VBOX_RC_PRODUCT_VERSION_STR + VBOX_RC_MORE_STRINGS + END + END + BLOCK "VarFileInfo" + BEGIN + VALUE "Translation", 0x409, 1200 + END +END |