diff options
Diffstat (limited to 'src/gui/opengl/qopenglprogrambinarycache.cpp')
-rw-r--r-- | src/gui/opengl/qopenglprogrambinarycache.cpp | 101 |
1 files changed, 62 insertions, 39 deletions
diff --git a/src/gui/opengl/qopenglprogrambinarycache.cpp b/src/gui/opengl/qopenglprogrambinarycache.cpp index 64217d470d..dd1462018f 100644 --- a/src/gui/opengl/qopenglprogrambinarycache.cpp +++ b/src/gui/opengl/qopenglprogrambinarycache.cpp @@ -1,12 +1,11 @@ /**************************************************************************** ** -** Copyright (C) 2021 The Qt Company Ltd. +** Copyright (C) 2016 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the QtGui module of the Qt Toolkit. ** -** $QT_BEGIN_LICENSE:COMM$ -** +** $QT_BEGIN_LICENSE:LGPL$ ** Commercial License Usage ** Licensees holding valid commercial Qt licenses may use this file in ** accordance with the commercial license agreement provided with the @@ -15,25 +14,26 @@ ** and conditions see https://www.qt.io/terms-conditions. For further ** information use the contact form at https://www.qt.io/contact-us. ** -** $QT_END_LICENSE$ -** -** -** -** -** -** -** -** -** -** -** -** -** -** -** -** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. ** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. ** +** $QT_END_LICENSE$ ** ****************************************************************************/ @@ -120,20 +120,24 @@ QOpenGLProgramBinaryCache::QOpenGLProgramBinaryCache() { const QString subPath = QLatin1String("/qtshadercache-") + QSysInfo::buildAbi() + QLatin1Char('/'); const QString sharedCachePath = QStandardPaths::writableLocation(QStandardPaths::GenericCacheLocation); + m_globalCacheDir = sharedCachePath + subPath; + m_localCacheDir = QStandardPaths::writableLocation(QStandardPaths::CacheLocation) + subPath; + if (!sharedCachePath.isEmpty()) { - m_cacheDir = sharedCachePath + subPath; - m_cacheWritable = qt_ensureWritableDir(m_cacheDir); + m_currentCacheDir = m_globalCacheDir; + m_cacheWritable = qt_ensureWritableDir(m_currentCacheDir); } if (!m_cacheWritable) { - m_cacheDir = QStandardPaths::writableLocation(QStandardPaths::CacheLocation) + subPath; - m_cacheWritable = qt_ensureWritableDir(m_cacheDir); + m_currentCacheDir = m_localCacheDir; + m_cacheWritable = qt_ensureWritableDir(m_currentCacheDir); } - qCDebug(lcOpenGLProgramDiskCache, "Cache location '%s' writable = %d", qPrintable(m_cacheDir), m_cacheWritable); + + qCDebug(lcOpenGLProgramDiskCache, "Cache location '%s' writable = %d", qPrintable(m_currentCacheDir), m_cacheWritable); } QString QOpenGLProgramBinaryCache::cacheFileName(const QByteArray &cacheKey) const { - return m_cacheDir + QString::fromUtf8(cacheKey); + return m_currentCacheDir + QString::fromUtf8(cacheKey); } #define BASE_HEADER_SIZE (int(4 * sizeof(quint32))) @@ -362,6 +366,25 @@ static inline void writeStr(uchar **p, const QByteArray &str) *p += str.size(); } +static inline bool writeFile(const QString &filename, const QByteArray &data) +{ +#if QT_CONFIG(temporaryfile) + QSaveFile f(filename); + if (f.open(QIODevice::WriteOnly | QIODevice::Truncate)) { + f.write(data); + if (f.commit()) + return true; + } +#else + QFile f(filename); + if (f.open(QIODevice::WriteOnly | QIODevice::Truncate)) { + if (f.write(data) == data.length()) + return true; + } +#endif + return false; +} + void QOpenGLProgramBinaryCache::save(const QByteArray &cacheKey, uint programId) { if (!m_cacheWritable) @@ -428,20 +451,20 @@ void QOpenGLProgramBinaryCache::save(const QByteArray &cacheKey, uint programId) writeUInt(&blobFormatPtr, blobFormat); -#if QT_CONFIG(temporaryfile) - QSaveFile f(cacheFileName(cacheKey)); - if (f.open(QIODevice::WriteOnly | QIODevice::Truncate)) { - f.write(blob); - if (!f.commit()) -#else - QFile f(cacheFileName(cacheKey)); - if (f.open(QIODevice::WriteOnly | QIODevice::Truncate)) { - if (f.write(blob) < blob.length()) -#endif - qCDebug(lcOpenGLProgramDiskCache, "Failed to write %s to shader cache", qPrintable(f.fileName())); - } else { - qCDebug(lcOpenGLProgramDiskCache, "Failed to create %s in shader cache", qPrintable(f.fileName())); + QString filename = cacheFileName(cacheKey); + bool ok = writeFile(filename, blob); + if (!ok && m_currentCacheDir == m_globalCacheDir) { + m_currentCacheDir = m_localCacheDir; + m_cacheWritable = qt_ensureWritableDir(m_currentCacheDir); + qCDebug(lcOpenGLProgramDiskCache, "Cache location changed to '%s' writable = %d", + qPrintable(m_currentCacheDir), m_cacheWritable); + if (m_cacheWritable) { + filename = cacheFileName(cacheKey); + ok = writeFile(filename, blob); + } } + if (!ok) + qCDebug(lcOpenGLProgramDiskCache, "Failed to write %s to shader cache", qPrintable(filename)); } #if defined(QT_OPENGL_ES_2) |