| 
									
										
										
										
											2012-10-02 09:12:39 +02:00
										 |  |  | /****************************************************************************
 | 
					
						
							| 
									
										
										
										
											2011-02-22 12:08:19 +01:00
										 |  |  | ** | 
					
						
							| 
									
										
										
										
											2016-01-15 14:59:14 +01:00
										 |  |  | ** Copyright (C) 2016 The Qt Company Ltd. | 
					
						
							|  |  |  | ** Contact: https://www.qt.io/licensing/
 | 
					
						
							| 
									
										
										
										
											2011-02-22 12:08:19 +01:00
										 |  |  | ** | 
					
						
							| 
									
										
										
										
											2012-10-02 09:12:39 +02:00
										 |  |  | ** This file is part of Qt Creator. | 
					
						
							| 
									
										
										
										
											2011-02-22 12:08:19 +01:00
										 |  |  | ** | 
					
						
							| 
									
										
										
										
											2012-10-02 09:12:39 +02:00
										 |  |  | ** Commercial License Usage | 
					
						
							|  |  |  | ** Licensees holding valid commercial Qt licenses may use this file in | 
					
						
							|  |  |  | ** accordance with the commercial license agreement provided with the | 
					
						
							|  |  |  | ** Software or, alternatively, in accordance with the terms contained in | 
					
						
							| 
									
										
										
										
											2016-01-15 14:59:14 +01:00
										 |  |  | ** a written agreement between you and The Qt Company. For licensing terms | 
					
						
							|  |  |  | ** and conditions see https://www.qt.io/terms-conditions. For further
 | 
					
						
							|  |  |  | ** information use the contact form at https://www.qt.io/contact-us.
 | 
					
						
							| 
									
										
										
										
											2011-02-22 12:08:19 +01:00
										 |  |  | ** | 
					
						
							| 
									
										
										
										
											2015-09-18 11:34:48 +02:00
										 |  |  | ** GNU General Public License Usage | 
					
						
							|  |  |  | ** Alternatively, this file may be used under the terms of the GNU | 
					
						
							| 
									
										
										
										
											2016-01-15 14:59:14 +01:00
										 |  |  | ** General Public License version 3 as published by the Free Software | 
					
						
							|  |  |  | ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT | 
					
						
							|  |  |  | ** 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-3.0.html.
 | 
					
						
							| 
									
										
										
										
											2011-02-22 12:08:19 +01:00
										 |  |  | ** | 
					
						
							| 
									
										
										
										
											2012-10-02 09:12:39 +02:00
										 |  |  | ****************************************************************************/ | 
					
						
							| 
									
										
										
										
											2011-02-22 12:08:19 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-11-30 21:32:52 +01:00
										 |  |  | #include "imagecontainer.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-07-31 16:45:21 +02:00
										 |  |  | #include "sharedmemory.h"
 | 
					
						
							| 
									
										
										
										
											2012-08-30 17:10:42 +02:00
										 |  |  | #include <QCache>
 | 
					
						
							| 
									
										
										
										
											2013-07-16 17:00:07 +02:00
										 |  |  | #include <QDebug>
 | 
					
						
							| 
									
										
										
										
											2012-08-30 17:10:42 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-09-20 14:25:01 +02:00
										 |  |  | #include <cstring>
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-09-11 15:11:34 +02:00
										 |  |  | #define QTC_ASSERT_STRINGIFY_HELPER(x) #x
 | 
					
						
							|  |  |  | #define QTC_ASSERT_STRINGIFY(x) QTC_ASSERT_STRINGIFY_HELPER(x)
 | 
					
						
							|  |  |  | #define QTC_ASSERT_STRING(cond) qDebug("SOFT ASSERT: \"" cond"\" in file " __FILE__ ", line " QTC_ASSERT_STRINGIFY(__LINE__))
 | 
					
						
							|  |  |  | #define QTC_ASSERT(cond, action) if (cond) {} else { QTC_ASSERT_STRING(#cond); action; } do {} while (0)
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-11-30 21:32:52 +01:00
										 |  |  | namespace QmlDesigner { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-08-05 14:00:21 +02:00
										 |  |  | // using cache as a container which deletes sharedmemory pointers at process exit
 | 
					
						
							| 
									
										
										
										
											2018-07-24 23:56:45 +02:00
										 |  |  | using GlobalSharedMemoryContainer = QCache<qint32, SharedMemory>; | 
					
						
							| 
									
										
										
										
											2014-08-05 14:00:21 +02:00
										 |  |  | Q_GLOBAL_STATIC_WITH_ARGS(GlobalSharedMemoryContainer, globalSharedMemoryContainer, (10000)) | 
					
						
							| 
									
										
										
										
											2012-08-30 17:10:42 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-11-30 21:32:52 +01:00
										 |  |  | ImageContainer::ImageContainer() | 
					
						
							| 
									
										
										
										
											2012-09-11 15:11:34 +02:00
										 |  |  |     : m_instanceId(-1), | 
					
						
							|  |  |  |       m_keyNumber(-2) | 
					
						
							| 
									
										
										
										
											2010-11-30 21:32:52 +01:00
										 |  |  | { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-09-11 15:11:34 +02:00
										 |  |  | ImageContainer::ImageContainer(qint32 instanceId, const QImage &image, qint32 keyNumber) | 
					
						
							| 
									
										
										
										
											2012-08-30 17:10:42 +02:00
										 |  |  |     :  m_image(image), | 
					
						
							| 
									
										
										
										
											2012-09-11 15:11:34 +02:00
										 |  |  |        m_instanceId(instanceId), | 
					
						
							|  |  |  |        m_keyNumber(keyNumber) | 
					
						
							| 
									
										
										
										
											2010-11-30 21:32:52 +01:00
										 |  |  | { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | qint32 ImageContainer::instanceId() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return m_instanceId; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | QImage ImageContainer::image() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return m_image; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-09-11 15:11:34 +02:00
										 |  |  | qint32 ImageContainer::keyNumber() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return m_keyNumber; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void ImageContainer::setImage(const QImage &image) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     QTC_ASSERT(m_image.isNull(), /**/); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     m_image = image; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void ImageContainer::removeSharedMemorys(const QVector<qint32> &keyNumberVector) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2019-07-25 16:58:50 +02:00
										 |  |  |     for (qint32 keyNumber : keyNumberVector) { | 
					
						
							| 
									
										
										
										
											2014-08-05 14:00:21 +02:00
										 |  |  |         SharedMemory *sharedMemory = globalSharedMemoryContainer()->take(keyNumber); | 
					
						
							| 
									
										
										
										
											2012-09-11 15:11:34 +02:00
										 |  |  |         delete sharedMemory; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static const QLatin1String imageKeyTemplateString("Image-%1"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-07-31 16:45:21 +02:00
										 |  |  | static SharedMemory *createSharedMemory(qint32 key, int byteCount) | 
					
						
							| 
									
										
										
										
											2012-08-30 17:10:42 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2014-08-05 14:00:21 +02:00
										 |  |  |     SharedMemory *sharedMemory = (*globalSharedMemoryContainer())[key]; | 
					
						
							| 
									
										
										
										
											2014-07-31 16:45:21 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-24 23:56:45 +02:00
										 |  |  |     if (sharedMemory == nullptr) { | 
					
						
							| 
									
										
										
										
											2014-07-31 16:45:21 +02:00
										 |  |  |         sharedMemory = new SharedMemory(QString(imageKeyTemplateString).arg(key)); | 
					
						
							|  |  |  |         bool sharedMemoryIsCreated = sharedMemory->create(byteCount); | 
					
						
							|  |  |  |         if (sharedMemoryIsCreated) { | 
					
						
							| 
									
										
										
										
											2014-08-05 14:00:21 +02:00
										 |  |  |             globalSharedMemoryContainer()->insert(key, sharedMemory); | 
					
						
							| 
									
										
										
										
											2014-07-31 16:45:21 +02:00
										 |  |  |         } else { | 
					
						
							|  |  |  |             delete sharedMemory; | 
					
						
							| 
									
										
										
										
											2018-07-24 23:56:45 +02:00
										 |  |  |             sharedMemory = nullptr; | 
					
						
							| 
									
										
										
										
											2014-07-31 16:45:21 +02:00
										 |  |  |         } | 
					
						
							|  |  |  |     } else { | 
					
						
							|  |  |  |         bool sharedMemoryIsAttached = sharedMemory->isAttached(); | 
					
						
							|  |  |  |         if (!sharedMemoryIsAttached) | 
					
						
							|  |  |  |             sharedMemoryIsAttached = sharedMemory->attach(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         bool sharedMemorySizeIsSmallerThanByteCount = sharedMemory->size() < byteCount; | 
					
						
							|  |  |  |         bool sharedMemorySizeIsDoubleBiggerThanByteCount = sharedMemory->size() > (byteCount * 2); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (!sharedMemoryIsAttached) { | 
					
						
							|  |  |  |             sharedMemory->create(byteCount); | 
					
						
							|  |  |  |         } else if (sharedMemorySizeIsSmallerThanByteCount || sharedMemorySizeIsDoubleBiggerThanByteCount) { | 
					
						
							|  |  |  |             sharedMemory->detach(); | 
					
						
							|  |  |  |             sharedMemory->create(byteCount); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (!sharedMemory->isAttached()) { | 
					
						
							| 
									
										
										
										
											2014-08-05 14:00:21 +02:00
										 |  |  |             globalSharedMemoryContainer()->remove(key); | 
					
						
							| 
									
										
										
										
											2018-07-24 23:56:45 +02:00
										 |  |  |             sharedMemory = nullptr; | 
					
						
							| 
									
										
										
										
											2014-07-31 16:45:21 +02:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2012-08-30 17:10:42 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-07-31 16:45:21 +02:00
										 |  |  |     return sharedMemory; | 
					
						
							| 
									
										
										
										
											2012-08-30 17:10:42 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-07-31 16:45:21 +02:00
										 |  |  | static void writeSharedMemory(SharedMemory *sharedMemory, const QImage &image) | 
					
						
							| 
									
										
										
										
											2010-11-30 21:32:52 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-09-11 15:11:34 +02:00
										 |  |  |     sharedMemory->lock(); | 
					
						
							| 
									
										
										
										
											2010-11-30 21:32:52 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-10 16:45:59 +01:00
										 |  |  |     qint32 headerData[6]; | 
					
						
							| 
									
										
										
										
											2019-02-26 18:03:03 +01:00
										 |  |  |     headerData[0] = qint32(image.sizeInBytes()); | 
					
						
							| 
									
										
										
										
											2012-09-11 15:11:34 +02:00
										 |  |  |     headerData[1] = image.bytesPerLine(); | 
					
						
							|  |  |  |     headerData[2] = image.size().width(); | 
					
						
							|  |  |  |     headerData[3] = image.size().height(); | 
					
						
							|  |  |  |     headerData[4] = image.format(); | 
					
						
							| 
									
										
										
										
											2020-11-10 16:45:59 +01:00
										 |  |  |     headerData[5] = image.devicePixelRatio() * 100; | 
					
						
							| 
									
										
										
										
											2010-11-30 21:32:52 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-10 16:45:59 +01:00
										 |  |  |     std::memcpy(sharedMemory->data(), headerData, 24); | 
					
						
							|  |  |  |     std::memcpy(reinterpret_cast<char*>(sharedMemory->data()) + 24, image.constBits(), image.sizeInBytes()); | 
					
						
							| 
									
										
										
										
											2012-09-11 15:11:34 +02:00
										 |  |  |     sharedMemory->unlock(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void writeStream(QDataStream &out, const QImage &image) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2010-11-30 21:32:52 +01:00
										 |  |  |     out << qint32(image.bytesPerLine()); | 
					
						
							|  |  |  |     out << image.size(); | 
					
						
							|  |  |  |     out << qint32(image.format()); | 
					
						
							| 
									
										
										
										
											2019-02-26 18:03:03 +01:00
										 |  |  |     out << qint32(image.sizeInBytes()); | 
					
						
							| 
									
										
										
										
											2020-11-10 16:45:59 +01:00
										 |  |  |     out << qint32(image.devicePixelRatio() * 100); | 
					
						
							| 
									
										
										
										
											2019-02-26 18:03:03 +01:00
										 |  |  |     out.writeRawData(reinterpret_cast<const char*>(image.constBits()), image.sizeInBytes()); | 
					
						
							| 
									
										
										
										
											2012-09-11 15:11:34 +02:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2012-08-30 17:10:42 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-09-11 15:11:34 +02:00
										 |  |  | QDataStream &operator<<(QDataStream &out, const ImageContainer &container) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2020-11-10 16:45:59 +01:00
										 |  |  |     const int extraDataSize =  24; | 
					
						
							| 
									
										
										
										
											2017-04-14 09:48:25 +02:00
										 |  |  |     static const bool dontUseSharedMemory = qEnvironmentVariableIsSet("DESIGNER_DONT_USE_SHARED_MEMORY"); | 
					
						
							| 
									
										
										
										
											2012-08-30 17:10:42 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-09-11 15:11:34 +02:00
										 |  |  |     out << container.instanceId(); | 
					
						
							|  |  |  |     out << container.keyNumber(); | 
					
						
							| 
									
										
										
										
											2012-08-30 17:10:42 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-09-11 15:11:34 +02:00
										 |  |  |     const QImage image = container.image(); | 
					
						
							| 
									
										
										
										
											2012-08-30 17:10:42 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-09-11 17:25:27 +02:00
										 |  |  |     if (dontUseSharedMemory) { | 
					
						
							|  |  |  |         out << qint32(0); | 
					
						
							| 
									
										
										
										
											2012-09-11 15:11:34 +02:00
										 |  |  |         writeStream(out, image); | 
					
						
							| 
									
										
										
										
											2012-09-11 17:25:27 +02:00
										 |  |  |     } else { | 
					
						
							| 
									
										
										
										
											2019-02-26 18:03:03 +01:00
										 |  |  |         const qint32 totalSize = qint32(image.sizeInBytes()) + extraDataSize; | 
					
						
							|  |  |  |         SharedMemory *sharedMemory = createSharedMemory(container.keyNumber(), totalSize); | 
					
						
							| 
									
										
										
										
											2012-09-11 17:25:27 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-24 23:56:45 +02:00
										 |  |  |         out << qint32(sharedMemory != nullptr); // send if shared memory is used
 | 
					
						
							| 
									
										
										
										
											2012-09-11 17:25:27 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         if (sharedMemory) | 
					
						
							|  |  |  |             writeSharedMemory(sharedMemory, image); | 
					
						
							|  |  |  |         else | 
					
						
							|  |  |  |             writeStream(out, image); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2010-11-30 21:32:52 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     return out; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-09-11 15:11:34 +02:00
										 |  |  | static void readSharedMemory(qint32 key, ImageContainer &container) | 
					
						
							| 
									
										
										
										
											2012-08-30 17:10:42 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2014-07-31 16:45:21 +02:00
										 |  |  |     SharedMemory sharedMemory(QString(imageKeyTemplateString).arg(key)); | 
					
						
							| 
									
										
										
										
											2012-09-11 15:11:34 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-30 17:10:42 +02:00
										 |  |  |     bool canAttach = sharedMemory.attach(QSharedMemory::ReadOnly); | 
					
						
							| 
									
										
										
										
											2012-09-11 15:11:34 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-10 16:45:59 +01:00
										 |  |  |     if (canAttach && sharedMemory.size() >= 24) | 
					
						
							| 
									
										
										
										
											2012-08-30 17:10:42 +02:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2012-09-05 19:55:06 +02:00
										 |  |  |         sharedMemory.lock(); | 
					
						
							| 
									
										
										
										
											2020-11-10 16:45:59 +01:00
										 |  |  |         qint32 headerData[6]; | 
					
						
							|  |  |  |         std::memcpy(headerData, sharedMemory.constData(), 24); | 
					
						
							| 
									
										
										
										
											2012-09-11 15:11:34 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         qint32 byteCount = headerData[0]; | 
					
						
							|  |  |  | //        qint32 bytesPerLine = headerData[1];
 | 
					
						
							|  |  |  |         qint32 imageWidth = headerData[2]; | 
					
						
							|  |  |  |         qint32 imageHeight = headerData[3]; | 
					
						
							|  |  |  |         qint32 imageFormat = headerData[4]; | 
					
						
							| 
									
										
										
										
											2020-11-10 16:45:59 +01:00
										 |  |  |         qreal pixelRatio = headerData[5] / 100.0; | 
					
						
							| 
									
										
										
										
											2012-09-11 15:11:34 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         QImage image = QImage(imageWidth, imageHeight, QImage::Format(imageFormat)); | 
					
						
							| 
									
										
										
										
											2020-11-10 16:45:59 +01:00
										 |  |  |         image.setDevicePixelRatio(pixelRatio); | 
					
						
							| 
									
										
										
										
											2012-09-11 15:11:34 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-29 09:18:38 +01:00
										 |  |  |         if (image.isNull()) | 
					
						
							|  |  |  |             qDebug() << Q_FUNC_INFO << "Not able to create image:" << imageWidth << imageHeight << imageFormat; | 
					
						
							|  |  |  |         else | 
					
						
							| 
									
										
										
										
											2020-11-10 16:45:59 +01:00
										 |  |  |             std::memcpy(image.bits(), reinterpret_cast<const qint32*>(sharedMemory.constData()) + 6, byteCount); | 
					
						
							| 
									
										
										
										
											2012-09-11 15:11:34 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         container.setImage(image); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-09-05 19:55:06 +02:00
										 |  |  |         sharedMemory.unlock(); | 
					
						
							| 
									
										
										
										
											2014-07-31 16:45:21 +02:00
										 |  |  |         sharedMemory.detach(); | 
					
						
							| 
									
										
										
										
											2012-08-30 17:10:42 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-09-11 15:11:34 +02:00
										 |  |  | static void readStream(QDataStream &in, ImageContainer &container) | 
					
						
							| 
									
										
										
										
											2010-11-30 21:32:52 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-09-11 15:11:34 +02:00
										 |  |  |     qint32 byteCount; | 
					
						
							| 
									
										
										
										
											2010-11-30 21:32:52 +01:00
										 |  |  |     qint32 bytesPerLine; | 
					
						
							|  |  |  |     QSize imageSize; | 
					
						
							| 
									
										
										
										
											2012-09-11 15:11:34 +02:00
										 |  |  |     qint32 imageFormat; | 
					
						
							| 
									
										
										
										
											2020-11-10 16:45:59 +01:00
										 |  |  |     qint32 pixelRatio; | 
					
						
							| 
									
										
										
										
											2010-11-30 21:32:52 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     in >> bytesPerLine; | 
					
						
							|  |  |  |     in >> imageSize; | 
					
						
							| 
									
										
										
										
											2012-09-11 15:11:34 +02:00
										 |  |  |     in >> imageFormat; | 
					
						
							|  |  |  |     in >> byteCount; | 
					
						
							| 
									
										
										
										
											2020-11-16 16:48:27 +01:00
										 |  |  |     in >> pixelRatio; | 
					
						
							| 
									
										
										
										
											2010-11-30 21:32:52 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-09-11 15:11:34 +02:00
										 |  |  |     QImage image = QImage(imageSize, QImage::Format(imageFormat)); | 
					
						
							| 
									
										
										
										
											2012-08-30 17:10:42 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-09-11 15:11:34 +02:00
										 |  |  |     in.readRawData(reinterpret_cast<char*>(image.bits()), byteCount); | 
					
						
							| 
									
										
										
										
											2020-11-10 16:45:59 +01:00
										 |  |  |     image.setDevicePixelRatio(pixelRatio / 100.0); | 
					
						
							| 
									
										
										
										
											2012-09-11 15:11:34 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     container.setImage(image); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | QDataStream &operator>>(QDataStream &in, ImageContainer &container) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     qint32 sharedMemoryIsUsed; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     in >> container.m_instanceId; | 
					
						
							|  |  |  |     in >> container.m_keyNumber; | 
					
						
							|  |  |  |     in >> sharedMemoryIsUsed; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (sharedMemoryIsUsed) { | 
					
						
							|  |  |  |         readSharedMemory(container.keyNumber(), container); | 
					
						
							|  |  |  |     } else | 
					
						
							|  |  |  |         readStream(in, container); | 
					
						
							| 
									
										
										
										
											2010-11-30 21:32:52 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     return in; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-07-04 17:06:31 +02:00
										 |  |  | bool operator ==(const ImageContainer &first, const ImageContainer &second) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return first.m_instanceId == second.m_instanceId | 
					
						
							|  |  |  |             && first.m_image == second.m_image; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool operator <(const ImageContainer &first, const ImageContainer &second) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return first.m_instanceId < second.m_instanceId; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-07-16 17:00:07 +02:00
										 |  |  | QDebug operator <<(QDebug debug, const ImageContainer &container) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return debug.nospace() << "ImageContainer(" | 
					
						
							|  |  |  |                            << "instanceId: " << container.instanceId() << ", " | 
					
						
							|  |  |  |                            << "size: " << container.image().size() << ")"; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-11-30 21:32:52 +01:00
										 |  |  | } // namespace QmlDesigner
 |