| 1 | /****************************************************************************
|
|---|
| 2 | **
|
|---|
| 3 | ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
|---|
| 4 | ** All rights reserved.
|
|---|
| 5 | ** Contact: Nokia Corporation ([email protected])
|
|---|
| 6 | **
|
|---|
| 7 | ** This file is part of the QtGui module of the Qt Toolkit.
|
|---|
| 8 | **
|
|---|
| 9 | ** $QT_BEGIN_LICENSE:LGPL$
|
|---|
| 10 | ** Commercial Usage
|
|---|
| 11 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
|---|
| 12 | ** accordance with the Qt Commercial License Agreement provided with the
|
|---|
| 13 | ** Software or, alternatively, in accordance with the terms contained in
|
|---|
| 14 | ** a written agreement between you and Nokia.
|
|---|
| 15 | **
|
|---|
| 16 | ** GNU Lesser General Public License Usage
|
|---|
| 17 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
|---|
| 18 | ** General Public License version 2.1 as published by the Free Software
|
|---|
| 19 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
|---|
| 20 | ** packaging of this file. Please review the following information to
|
|---|
| 21 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
|---|
| 22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|---|
| 23 | **
|
|---|
| 24 | ** In addition, as a special exception, Nokia gives you certain additional
|
|---|
| 25 | ** rights. These rights are described in the Nokia Qt LGPL Exception
|
|---|
| 26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|---|
| 27 | **
|
|---|
| 28 | ** GNU General Public License Usage
|
|---|
| 29 | ** Alternatively, this file may be used under the terms of the GNU
|
|---|
| 30 | ** General Public License version 3.0 as published by the Free Software
|
|---|
| 31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
|---|
| 32 | ** packaging of this file. Please review the following information to
|
|---|
| 33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
|---|
| 34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
|---|
| 35 | **
|
|---|
| 36 | ** If you have questions regarding the use of this file, please contact
|
|---|
| 37 | ** Nokia at [email protected].
|
|---|
| 38 | ** $QT_END_LICENSE$
|
|---|
| 39 | **
|
|---|
| 40 | ****************************************************************************/
|
|---|
| 41 |
|
|---|
| 42 | #include <private/qgraphicssystem_runtime_p.h>
|
|---|
| 43 | #include <private/qgraphicssystem_raster_p.h>
|
|---|
| 44 | #include <private/qgraphicssystemfactory_p.h>
|
|---|
| 45 | #include <private/qapplication_p.h>
|
|---|
| 46 | #include <private/qwidget_p.h>
|
|---|
| 47 | #include <QtCore/QDebug>
|
|---|
| 48 | #include <QtCore/QTimer>
|
|---|
| 49 | #include <QtGui/QBitmap>
|
|---|
| 50 |
|
|---|
| 51 | QT_BEGIN_NAMESPACE
|
|---|
| 52 |
|
|---|
| 53 | static int qt_pixmap_serial = 0;
|
|---|
| 54 |
|
|---|
| 55 | #define READBACK(f) \
|
|---|
| 56 | f \
|
|---|
| 57 | readBackInfo();
|
|---|
| 58 |
|
|---|
| 59 |
|
|---|
| 60 | class QDeferredGraphicsSystemChange : public QObject
|
|---|
| 61 | {
|
|---|
| 62 | Q_OBJECT
|
|---|
| 63 |
|
|---|
| 64 | public:
|
|---|
| 65 | QDeferredGraphicsSystemChange(QRuntimeGraphicsSystem *gs, const QString& graphicsSystemName)
|
|---|
| 66 | : m_graphicsSystem(gs), m_graphicsSystemName(graphicsSystemName)
|
|---|
| 67 | {
|
|---|
| 68 | }
|
|---|
| 69 |
|
|---|
| 70 | void launch()
|
|---|
| 71 | {
|
|---|
| 72 | QTimer::singleShot(0, this, SLOT(doChange()));
|
|---|
| 73 | }
|
|---|
| 74 |
|
|---|
| 75 | private slots:
|
|---|
| 76 |
|
|---|
| 77 | void doChange()
|
|---|
| 78 | {
|
|---|
| 79 | m_graphicsSystem->setGraphicsSystem(m_graphicsSystemName);
|
|---|
| 80 | deleteLater();
|
|---|
| 81 | }
|
|---|
| 82 |
|
|---|
| 83 | private:
|
|---|
| 84 |
|
|---|
| 85 | QRuntimeGraphicsSystem *m_graphicsSystem;
|
|---|
| 86 | QString m_graphicsSystemName;
|
|---|
| 87 | };
|
|---|
| 88 |
|
|---|
| 89 | QRuntimePixmapData::QRuntimePixmapData(const QRuntimeGraphicsSystem *gs, PixelType type)
|
|---|
| 90 | : QPixmapData(type, RuntimeClass), m_graphicsSystem(gs)
|
|---|
| 91 | {
|
|---|
| 92 | setSerialNumber(++qt_pixmap_serial);
|
|---|
| 93 | }
|
|---|
| 94 |
|
|---|
| 95 | QRuntimePixmapData::~QRuntimePixmapData()
|
|---|
| 96 | {
|
|---|
| 97 | if (QApplicationPrivate::graphics_system)
|
|---|
| 98 | m_graphicsSystem->removePixmapData(this);
|
|---|
| 99 | delete m_data;
|
|---|
| 100 | }
|
|---|
| 101 |
|
|---|
| 102 | void QRuntimePixmapData::readBackInfo()
|
|---|
| 103 | {
|
|---|
| 104 | w = m_data->width();
|
|---|
| 105 | h = m_data->height();
|
|---|
| 106 | d = m_data->depth();
|
|---|
| 107 | is_null = m_data->isNull();
|
|---|
| 108 | }
|
|---|
| 109 |
|
|---|
| 110 |
|
|---|
| 111 | QPixmapData *QRuntimePixmapData::createCompatiblePixmapData() const
|
|---|
| 112 | {
|
|---|
| 113 | QRuntimePixmapData *rtData = new QRuntimePixmapData(m_graphicsSystem, pixelType());
|
|---|
| 114 | rtData->m_data = m_data->createCompatiblePixmapData();
|
|---|
| 115 | return rtData;
|
|---|
| 116 | }
|
|---|
| 117 |
|
|---|
| 118 |
|
|---|
| 119 | void QRuntimePixmapData::resize(int width, int height)
|
|---|
| 120 | {
|
|---|
| 121 | READBACK(
|
|---|
| 122 | m_data->resize(width, height);
|
|---|
| 123 | )
|
|---|
| 124 | }
|
|---|
| 125 |
|
|---|
| 126 |
|
|---|
| 127 | void QRuntimePixmapData::fromImage(const QImage &image,
|
|---|
| 128 | Qt::ImageConversionFlags flags)
|
|---|
| 129 | {
|
|---|
| 130 | READBACK(
|
|---|
| 131 | m_data->fromImage(image, flags);
|
|---|
| 132 | )
|
|---|
| 133 | }
|
|---|
| 134 |
|
|---|
| 135 |
|
|---|
| 136 | bool QRuntimePixmapData::fromFile(const QString &filename, const char *format,
|
|---|
| 137 | Qt::ImageConversionFlags flags)
|
|---|
|
|---|