1 /****************************************************************************
3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
6 ** This file is part of the plugins of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
42 #ifndef XCBSHAREDBUFFERMANAGER_H
43 #define XCBSHAREDBUFFERMANAGER_H
45 #if defined(QT_USE_XCB_SHARED_GRAPHICS_CACHE)
47 #include <QtCore/qset.h>
48 #include <QtCore/qhash.h>
49 #include <QtCore/qsharedmemory.h>
51 #include <GLES2/gl2.h>
55 #include <EGL/eglext.h>
63 class QXcbSharedBufferManager
73 , currentLineMaxHeight(0)
86 glDeleteTextures(1, &textureId);
95 int currentLineMaxHeight;
100 QSharedMemory *buffer;
107 typedef QHash<QByteArray, QSet<quint32> > PendingItemIds;
109 QXcbSharedBufferManager();
110 ~QXcbSharedBufferManager();
112 void beginSharedBufferAction(const QByteArray &cacheId);
113 void insertItem(quint32 itemId, uchar *data, int itemWidth, int itemHeight);
114 void requestItems(const QSet<quint32> &itemIds);
115 void releaseItems(const QSet<quint32> &itemIds);
116 void endSharedBufferAction();
118 void getBufferForItem(const QByteArray &cacheId, quint32 itemId, Buffer **buffer,
119 int *x, int *y) const;
120 QPair<QByteArray, int> serializeBuffer(QSharedMemory *buffer) const;
122 PendingItemIds pendingItemsInvalidated() const
124 Q_ASSERT_X(m_currentCacheId.isEmpty(), Q_FUNC_INFO,
125 "Call endSharedBufferAction() before accessing data");
126 return m_pendingInvalidatedItems;
129 PendingItemIds pendingItemsReady() const
131 Q_ASSERT_X(m_currentCacheId.isEmpty(), Q_FUNC_INFO,
132 "Call endSharedBufferAction() before accessing data");
133 return m_pendingReadyItems;
136 PendingItemIds pendingItemsMissing() const
138 Q_ASSERT_X(m_currentCacheId.isEmpty(), Q_FUNC_INFO,
139 "Call endSharedBufferAction() before accessing data");
140 return m_pendingMissingItems;
170 Items() : leastRecentlyUsed(0), mostRecentlyUsed(0) {}
172 Item *leastRecentlyUsed;
173 Item *mostRecentlyUsed;
176 QHash<quint32, Item *> items;
179 void findAvailableBuffer(int itemWidth, int itemHeight, Buffer **buffer, int *x, int *y);
180 void recycleItem(Buffer **buffer, int *x, int *y);
181 void copyIntoBuffer(Buffer *buffer, int x, int y, int itemWidth, int itemHeight, uchar *data);
182 void touchBuffer(Buffer *buffer);
183 void deleteLeastRecentlyUsed();
185 Buffer *createNewBuffer(const QByteArray &cacheId, int heightRequired);
186 Buffer *resizeBuffer(Buffer *buffer, const QSize &newSize);
187 Buffer *allocateBuffer(int width, int height);
189 Items *itemsForCache(const QByteArray &cacheId) const;
190 void pushItemToBack(Items *items, Item *item);
191 void touchItem(Items *items, Item *item);
192 void deleteItem(Items *items, Item *item);
193 void recycleItem(const QByteArray &cacheId, Buffer **sharedBuffer, int *glyphX, int *glyphY);
195 QByteArray m_currentCacheId;
197 quint32 m_memoryUsed;
198 Buffer *m_mostRecentlyUsed;
199 Buffer *m_leastRecentlyUsed;
201 mutable QHash<QByteArray, Items *> m_items;
202 QMultiHash<QByteArray, Buffer *> m_buffers;
204 PendingItemIds m_pendingInvalidatedItems;
205 PendingItemIds m_pendingReadyItems;
206 PendingItemIds m_pendingMissingItems;
213 #endif // QT_USE_XCB_SHARED_GRAPHICS_CACHE
215 #endif // XCBSHAREDBUFFERMANAGER_H