From c274ea7cf5e11ade0a5812e3080baa671d012524 Mon Sep 17 00:00:00 2001 From: Eskil Abrahamsen Blomfeldt Date: Fri, 18 Nov 2011 10:24:32 +0100 Subject: Introducing QPlatformSharedGraphicsCache Interface to provide cross-process caching mechanisms in a platform plugin. Can be used for shared glyph caches and icon caches etc. Change-Id: If0d89a0a50bbd6eee05daf908448262ff270fc5b Reviewed-by: Jiang Jiang --- src/gui/kernel/kernel.pri | 6 +- src/gui/kernel/qplatformintegration_qpa.cpp | 11 ++ src/gui/kernel/qplatformintegration_qpa.h | 6 +- .../kernel/qplatformsharedgraphicscache_qpa.cpp | 212 +++++++++++++++++++++ src/gui/kernel/qplatformsharedgraphicscache_qpa.h | 97 ++++++++++ 5 files changed, 329 insertions(+), 3 deletions(-) create mode 100644 src/gui/kernel/qplatformsharedgraphicscache_qpa.cpp create mode 100644 src/gui/kernel/qplatformsharedgraphicscache_qpa.h (limited to 'src/gui') diff --git a/src/gui/kernel/kernel.pri b/src/gui/kernel/kernel.pri index bf552c9991..12cb42c741 100644 --- a/src/gui/kernel/kernel.pri +++ b/src/gui/kernel/kernel.pri @@ -54,7 +54,8 @@ HEADERS += \ kernel/qscreen_p.h \ kernel/qstylehints.h \ kernel/qtouchdevice.h \ - kernel/qtouchdevice_p.h + kernel/qtouchdevice_p.h \ + kernel/qplatformsharedgraphicscache_qpa.h SOURCES += \ kernel/qclipboard_qpa.cpp \ @@ -96,6 +97,7 @@ SOURCES += \ kernel/qscreen.cpp \ kernel/qshortcutmap.cpp \ kernel/qstylehints.cpp \ - kernel/qtouchdevice.cpp + kernel/qtouchdevice.cpp \ + kernel/qplatformsharedgraphicscache_qpa.cpp win32:HEADERS+=kernel/qwindowdefs_win.h diff --git a/src/gui/kernel/qplatformintegration_qpa.cpp b/src/gui/kernel/qplatformintegration_qpa.cpp index 23ecf3add4..d1e267db37 100644 --- a/src/gui/kernel/qplatformintegration_qpa.cpp +++ b/src/gui/kernel/qplatformintegration_qpa.cpp @@ -201,6 +201,17 @@ QPlatformOpenGLContext *QPlatformIntegration::createPlatformOpenGLContext(QOpenG return 0; } +/*! + Factory function for QPlatformSharedGraphicsCache. This function will return 0 if the platform + integration does not support any shared graphics cache mechanism for the given \a cacheId. +*/ +QPlatformSharedGraphicsCache *QPlatformIntegration::createPlatformSharedGraphicsCache(const char *cacheId) const +{ + qWarning("This plugin does not support createPlatformSharedGraphicsBuffer for cacheId: %s!", + cacheId); + return 0; +} + /*! Returns the platforms input context. diff --git a/src/gui/kernel/qplatformintegration_qpa.h b/src/gui/kernel/qplatformintegration_qpa.h index 3975d82288..3043ba801d 100644 --- a/src/gui/kernel/qplatformintegration_qpa.h +++ b/src/gui/kernel/qplatformintegration_qpa.h @@ -65,6 +65,8 @@ class QAbstractEventDispatcher; class QPlatformInputContext; class QPlatformAccessibility; class QPlatformTheme; +class QPlatformDialogHelper; +class QPlatformSharedGraphicsCache; class Q_GUI_EXPORT QPlatformIntegration { @@ -72,7 +74,8 @@ public: enum Capability { ThreadedPixmaps = 1, OpenGL = 2, - ThreadedOpenGL = 3 + ThreadedOpenGL = 3, + SharedGraphicsCache = 4 }; virtual ~QPlatformIntegration() { } @@ -83,6 +86,7 @@ public: virtual QPlatformWindow *createPlatformWindow(QWindow *window) const = 0; virtual QPlatformBackingStore *createPlatformBackingStore(QWindow *window) const = 0; virtual QPlatformOpenGLContext *createPlatformOpenGLContext(QOpenGLContext *context) const; + virtual QPlatformSharedGraphicsCache *createPlatformSharedGraphicsCache(const char *cacheId) const; // Event dispatcher: virtual QAbstractEventDispatcher *guiThreadEventDispatcher() const = 0; diff --git a/src/gui/kernel/qplatformsharedgraphicscache_qpa.cpp b/src/gui/kernel/qplatformsharedgraphicscache_qpa.cpp new file mode 100644 index 0000000000..67a59b0e44 --- /dev/null +++ b/src/gui/kernel/qplatformsharedgraphicscache_qpa.cpp @@ -0,0 +1,212 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtGui module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qplatformsharedgraphicscache_qpa.h" + +QT_BEGIN_NAMESPACE + +/*! + \class QPlatformSharedGraphicsCache + \since 5.0 + \internal + \preliminary + \ingroup qpa + \brief The QPlatformSharedGraphicsCache is an abstraction of a cross-process graphics cache. + + If supported, it is possible to retrieve a QPlatformSharedGraphicsCache object from the + platform integration. This is typically used to store graphical items which should be shared + between several processes. + + Items are requested from the cache by calling requestItems(). If the cache contains the + requested items in the requested cache, the itemsAvailable() signal is emitted with the ID of + the graphical buffer and each item's coordinates inside the buffer. Before requesting items + from a cache, the user must call ensureCacheInitialized() to set the correct parameters for + the cache. + + If the cache does not yet contain the requested items, it will emit a similar itemsMissing() + signal. The client can then call updateItems() with rasterizations of the items and they will be + entered into the shared cache. As the items are rendered into the cache, itemsAvailable() signals + will be emitted for each of the items which have previously been requested and which have not + yet been reported as ready. +*/ + +/*! + \enum BufferType + + Defines how the type of buffer required to contain a cache. + + \value OpenGLTexture The buffer will be allocated in graphics memory, and an OpenGL texture + for a buffer belonging to the cache can be requested using + textureIdForBuffer(). +*/ + +/*! + \enum PixelFormat + + Defines the pixel format of a cache. + + \value Alpha8 The cache will use 8 bits to represent the alpha value of each pixel. If an + OpenGL texture is created for a buffer belong to the cache, it will have the + pixel format GL_ALPHA. +*/ + +/*! + \fn void ensureCacheInitialized(const QByteArray &cacheId, BufferType bufferType, PixelFormat pixelFormat) + + Initializes a cache named \a cacheId if it has not yet been initialized. The \a bufferType and + \a pixelFormat gives the format of the buffers that will be used to contain the items in the + cache. If a cache with the same \a cacheId has previously been initialized, the call will be + ignored. The cache will keep its previously set buffer type and pixel format. +*/ + +/*! + \fn void QPlatformSharedGraphicsCache::requestItems(const QByteArray &cacheId, const QVector &itemIds) + + Requests all the items in \a itemIds from the cache with the name \a cacheId. + + If any or all of the items are available in the cache, one or more itemsAvailable() signals will be + emitted corresponding to the items. If the cache does not contain all of the items in question, + then an itemsMissing() signal will be emitted corresponding to the missing items. The user + is at this point expected to call insertItems() to insert the missing items into the cache. If + the inserted items have previously been requested by the user, at which point an itemsAvailable() + signal will be emitted corresponding to the items. + + Before requesting items from a cache, the user must call ensureCacheInitialized() with the + correct parameters for the cache. +*/ + +/*! + \fn void QPlatformSharedGraphicsCache::insertItems(const QByteArray &cacheId, const QVector &itemIds, const QVector &items) + + Inserts the items in \a itemIds into the cache named \a cacheId. The appearance of + each item is stored in \a items. The format of the QImage objects is expected to match the + pixel format of the cache as it was initialized in ensureCacheInitialized(). + + When the items have been successfully entered into the cache, one or more itemsAvailable() signals + will be emitted for the items. + + If the cache already contains the items, the behavior is implementation-specific. The + implementation may choose to ignore the items or it may overwrite the existing instances in + the cache. Either way, itemsAvailable() signals corresponding to the inserted items will be + emitted. +*/ + +/*! + \fn void QPlatformSharedGraphicsCache::releaseItems(const QByteArray &cacheId, const QVector &itemIds) + + Releases the reference to the items in \a itemIds from the cache named \a cacheId. This should + only be called when all references to the items have been released by the user, and they are no + longer needed. +*/ + +/*! + \fn void itemsMissing(const QByteArray &cacheId, const QVector *itemIds) + + This signal is emitted when requestItems() has been called for one or more items in the + cache named \a cacheId which are not yet available in the cache. The user is then expected to + call insertItems() to update the cache with the respective items, at which point they will + become available to all clients of the shared cache. + + The vector \a itemIds contains the IDs of the items that need to be inserted into the cache. + + \sa itemsAvailable(), insertItems(), requestItems() +*/ + +/*! + \fn void itemsAvailable(const QByteArray &cacheId, void *bufferId, const QSize &bufferSize, const QVector &itemIds, const QVector &positionsInBuffer) + + This signal can be emitted at any time when either requestItems() or insertItems() has been + called by the application for one or more items in the cache named \a cacheId, as long as + releaseItems() has not subsequently been called for the same items. It instructs the application + on where to find the items that have been entered into the cache. When the application receives + a buffer, it is expected to reference it using referenceBuffer() on it if it keeps a reference + to the buffer. + + The \a bufferId is an ID for the buffer that contains the items. The \a bufferId can be + converted to a format usable by the application depending on which format it was given at + initialization. If it is a OpenGLTexture, its texture ID can be requested using the + textureIdForBuffer() function. The dimensions of the buffer are given by \a bufferSize. + + The items provided by the cache are identified in the \a itemIds vector. The + \a positionsInBuffer vector contains the locations inside the buffer of each item. Each entry in + \a positionsInBuffer corresponds to an item in \a itemIds. + + The buffer and the items' locations within the buffer can be considered valid until an + itemsInvalidated() signal has been emitted for the items, or until releaseItems() is called + for the items. + + \sa itemsMissing(), requestItems(), bufferType() +*/ + +/*! + \fn void itemsUpdated(const QByteArray &cacheId, void *bufferId, const QSize &bufferSize, const QVector &itemIds, const QVector &positionsInBuffer) + + This signal is similar in usage to the itemsAvailable() signal, but will be emitted when + the location of a previously requested or inserted item has been updated. The application + must update its data for the respective items and release any references to old buffers held + by the items. + + If the application no longer holds any references to previously referenced items in a given + cache, it should call releaseItems() for these items, at which point it will no longer receive + any itemsUpdated() signal for these items. + + \sa requestItems(), insertItems(), itemsAvailable() +*/ + +/*! + \fn void itemsInvalidated(const QByteArray &cacheId, const QVector &itemIds) + + This signal is emitted when the items given by \a itemIds in the cache named \a cacheId have + been removed from the cache and the previously reported information about them is considered + invalid. It will only be emitted for items for which a buffer has previously been identified + through the itemsAvailable() signal (either as response to a requestItems() call or an + insertItems() call.) + + The application is expected to throw away information about the items in the \a itemIds array + and drop any references it might have to the memory held by the buffer. If the items are still + required by the application, it can re-commit them to the cache using the insertItems() function. + + If the application no longer holds any references to previously referenced items in a given + cache, it should call releaseItems() for these items, at which point it will no longer receive + any itemsInvalidated() signal for these items. +*/ + +QT_END_NAMESPACE diff --git a/src/gui/kernel/qplatformsharedgraphicscache_qpa.h b/src/gui/kernel/qplatformsharedgraphicscache_qpa.h new file mode 100644 index 0000000000..a0661c0ba7 --- /dev/null +++ b/src/gui/kernel/qplatformsharedgraphicscache_qpa.h @@ -0,0 +1,97 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtGui module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QPLATFORMSHAREDGRAPHICSCACHE_QPA_H +#define QPLATFORMSHAREDGRAPHICSCACHE_QPA_H + +#include +#include + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Gui) + +class Q_GUI_EXPORT QPlatformSharedGraphicsCache: public QObject +{ + Q_OBJECT +public: + enum PixelFormat + { + Alpha8 + }; + + enum BufferType + { + OpenGLTexture + }; + + QPlatformSharedGraphicsCache(QObject *parent = 0) : QObject(parent) {} + + Q_INVOKABLE virtual void ensureCacheInitialized(const QByteArray &cacheId, BufferType bufferType, + PixelFormat pixelFormat) = 0; + + Q_INVOKABLE virtual void requestItems(const QByteArray &cacheId, const QVector &itemIds) = 0; + Q_INVOKABLE virtual void insertItems(const QByteArray &cacheId, + const QVector &itemIds, + const QVector &items) = 0; + Q_INVOKABLE virtual void releaseItems(const QByteArray &cacheId, const QVector &itemIds) = 0; + + virtual void serializeBuffer(void *bufferId, QByteArray *serializedData, int *fileDescriptor) const = 0; + virtual uint textureIdForBuffer(void *bufferId) = 0; + virtual void referenceBuffer(void *bufferId) = 0; + virtual bool dereferenceBuffer(void *bufferId) = 0; + +Q_SIGNALS: + void itemsMissing(const QByteArray &cacheId, const QVector &itemIds); + void itemsAvailable(const QByteArray &cacheId, void *bufferId, const QSize &bufferSize, + const QVector &itemIds, const QVector &positionsInBuffer); + void itemsInvalidated(const QByteArray &cacheId, const QVector &itemIds); + void itemsUpdated(const QByteArray &cacheId, void *bufferId, const QSize &bufferSize, + const QVector &itemIds, const QVector &positionsInBuffer); +}; + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif // QPLATFORMSHAREDGRAPHICSCACHE_QPA_H -- cgit v1.2.3