diff --git a/CMakeLists.txt b/CMakeLists.txt index aec39c09aa4d9b57ec7ea63e291357e9bf3c612f..31c0f83a0a9e6ef07921c78300828d973c61567d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -364,7 +364,10 @@ elseif (NOT APPLE) else() # APPLE list(APPEND COMMON_SOURCES ${SRC_DIR}/os/macos/updatemanager.mm - ${SRC_DIR}/os/macos/connectivitymonitor.mm) + ${SRC_DIR}/os/macos/connectivitymonitor.mm + ${SRC_DIR}/os/macos/macutils.mm) + list(APPEND COMMON_HEADERS + ${SRC_DIR}/os/macos/macutils.h) if(NOT DEFINED LRC) if(EXISTS ${PROJECT_SOURCE_DIR}/../install/lrc) set(LRC ${PROJECT_SOURCE_DIR}/../install/lrc) diff --git a/src/main.cpp b/src/main.cpp index 7a84dfb482b33961372f6bf63fcb33ad98322da3..0616413f78e481cacdcdeb622b1b108f7760e688 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -29,6 +29,9 @@ #if defined(HAS_VULKAN) #include <QVulkanInstance> #endif +#if defined(Q_OS_MACOS) +#include <os/macos/macutils.h> +#endif #include <clocale> @@ -98,9 +101,12 @@ main(int argc, char* argv[]) auto newArgv = parseInputArgument(argc, argv, qtWebEngineChromiumFlags); MainApplication app(argc, newArgv); - #if defined(Q_OS_MACOS) - QQuickWindow::setGraphicsApi(QSGRendererInterface::MetalRhi); + if (macutils::isMetalSupported()) { + QQuickWindow::setGraphicsApi(QSGRendererInterface::MetalRhi); + } else { + QQuickWindow::setGraphicsApi(QSGRendererInterface::OpenGLRhi); + } #else if (std::invoke([] { #if defined(HAS_VULKAN) diff --git a/src/os/macos/macutils.h b/src/os/macos/macutils.h new file mode 100644 index 0000000000000000000000000000000000000000..ed486ef855bdb7c8d99ae848c4b70c6b031d7124 --- /dev/null +++ b/src/os/macos/macutils.h @@ -0,0 +1,24 @@ +/* + * Copyright (C) 2022 Savoir-faire Linux Inc. + * Author: Kateryna Kostiuk <kateryna.kostiuk@savoirfairelinux.com> + * + * 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; either version 3 of the License, or + * (at your option) any later version. + * + * 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 <http://www.gnu.org/licenses/>. + */ +#pragma once + +class macutils +{ +public: + static bool isMetalSupported(); +}; diff --git a/src/os/macos/macutils.mm b/src/os/macos/macutils.mm new file mode 100644 index 0000000000000000000000000000000000000000..d1f0aea3f014d912fee506f4b7f7a3f8ab8d5ba2 --- /dev/null +++ b/src/os/macos/macutils.mm @@ -0,0 +1,24 @@ +/* + * Copyright (C) 2022 Savoir-faire Linux Inc. + * Author: Kateryna Kostiuk <kateryna.kostiuk@savoirfairelinux.com> + * + * 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; either version 3 of the License, or + * (at your option) any later version. + * + * 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 <http://www.gnu.org/licenses/>. + */ +#include "macutils.h" + +#include <MetalKit/MetalKit.h> + +bool macutils::isMetalSupported() { + return ([[MTLCopyAllDevices() autorelease] count] > 0); +}