12#include <private/qguiapplication_p.h>
13#include <private/qblittable_p.h>
15#include <private/qdrawhelper_p.h>
16#include <private/qfont_p.h>
18#ifndef QT_NO_BLITTABLE
23QBlittablePlatformPixmap::QBlittablePlatformPixmap()
24 : QPlatformPixmap(QPlatformPixmap::PixmapType,BlitterClass)
26 , m_devicePixelRatio(1.0)
27#ifdef QT_BLITTER_RASTEROVERLAY
28 ,m_rasterOverlay(0), m_unmergedCopy(0)
31 setSerialNumber(++global_ser_no);
34QBlittablePlatformPixmap::~QBlittablePlatformPixmap()
36#ifdef QT_BLITTER_RASTEROVERLAY
37 delete m_rasterOverlay;
38 delete m_unmergedCopy;
42QBlittable *QBlittablePlatformPixmap::blittable()
const
45 QBlittablePlatformPixmap *that =
const_cast<QBlittablePlatformPixmap *>(
this);
46 that->m_blittable.reset(
this->createBlittable(QSize(w, h), m_alpha));
49 return m_blittable.data();
52void QBlittablePlatformPixmap::setBlittable(QBlittable *blittable)
54 resize(blittable->size().width(),blittable->size().height());
55 m_blittable.reset(blittable);
58void QBlittablePlatformPixmap::resize(
int width,
int height)
60 m_blittable.reset(
nullptr);
61 m_engine.reset(
nullptr);
62 d = QGuiApplication::primaryScreen()->depth();
65 is_null = (w <= 0 || h <= 0);
66 setSerialNumber(++global_ser_no);
69int QBlittablePlatformPixmap::metric(QPaintDevice::PaintDeviceMetric metric)
const
72 case QPaintDevice::PdmWidth:
74 case QPaintDevice::PdmHeight:
76 case QPaintDevice::PdmWidthMM:
77 return qRound(w * 25.4 / qt_defaultDpiX());
78 case QPaintDevice::PdmHeightMM:
79 return qRound(h * 25.4 / qt_defaultDpiY());
80 case QPaintDevice::PdmDepth:
82 case QPaintDevice::PdmDpiX:
83 case QPaintDevice::PdmPhysicalDpiX:
84 return qt_defaultDpiX();
85 case QPaintDevice::PdmDpiY:
86 case QPaintDevice::PdmPhysicalDpiY:
87 return qt_defaultDpiY();
88 case QPaintDevice::PdmDevicePixelRatio:
89 return devicePixelRatio();
90 case QPaintDevice::PdmDevicePixelRatioScaled:
91 return devicePixelRatio() * QPaintDevice::devicePixelRatioFScale();
92 case QPaintDevice::PdmDevicePixelRatioF_EncodedA:
94 case QPaintDevice::PdmDevicePixelRatioF_EncodedB:
95 return QPaintDevice::encodeMetricF(metric, devicePixelRatio());
97 qWarning(
"QRasterPlatformPixmap::metric(): Unhandled metric type %d", metric);
104void QBlittablePlatformPixmap::fill(
const QColor &color)
106 if (blittable()->capabilities() & QBlittable::AlphaFillRectCapability) {
107 blittable()->unlock();
108 blittable()->alphaFillRect(QRectF(0,0,w,h),color,QPainter::CompositionMode_Source);
109 }
else if (color.alpha() == 255 && blittable()->capabilities() & QBlittable::SolidRectCapability) {
110 blittable()->unlock();
111 blittable()->fillRect(QRectF(0,0,w,h),color);
116 if (color.alpha() != 255 && !hasAlphaChannel()) {
117 m_blittable.reset(
nullptr);
118 m_engine.reset(
nullptr);
122 blittable()->lock()->fill(color);
127QImage *QBlittablePlatformPixmap::buffer()
129 return blittable()->lock();
132QImage QBlittablePlatformPixmap::toImage()
const
134 return blittable()->lock()->copy();
137bool QBlittablePlatformPixmap::hasAlphaChannel()
const
139 return blittable()->lock()->hasAlphaChannel();
142void QBlittablePlatformPixmap::fromImage(
const QImage &image,
143 Qt::ImageConversionFlags flags)
145 m_alpha = image.hasAlphaChannel();
146 m_devicePixelRatio = image.devicePixelRatio();
147 resize(image.width(),image.height());
148 markRasterOverlay(QRect(0,0,w,h));
149 QImage *thisImg = buffer();
151 QImage correctFormatPic = image;
152 if (correctFormatPic.format() != thisImg->format())
153 correctFormatPic = correctFormatPic.convertToFormat(thisImg->format(), flags);
155 uchar *mem = thisImg->bits();
156 const uchar *bits = correctFormatPic.constBits();
157 qsizetype bytesCopied = 0;
158 while (bytesCopied < correctFormatPic.sizeInBytes()) {
159 memcpy(mem,bits,correctFormatPic.bytesPerLine());
160 mem += thisImg->bytesPerLine();
161 bits += correctFormatPic.bytesPerLine();
162 bytesCopied+=correctFormatPic.bytesPerLine();
166qreal QBlittablePlatformPixmap::devicePixelRatio()
const
168 return m_devicePixelRatio;
171void QBlittablePlatformPixmap::setDevicePixelRatio(qreal scaleFactor)
173 m_devicePixelRatio = scaleFactor;
176QPaintEngine *QBlittablePlatformPixmap::paintEngine()
const
179 QBlittablePlatformPixmap *that =
const_cast<QBlittablePlatformPixmap *>(
this);
180 that->m_engine.reset(
new QBlitterPaintEngine(that));
182 return m_engine.data();
185#ifdef QT_BLITTER_RASTEROVERLAY
187static bool showRasterOverlay = !qEnvironmentVariableIsEmpty(
"QT_BLITTER_RASTEROVERLAY");
189void QBlittablePlatformPixmap::mergeOverlay()
191 if (m_unmergedCopy || !showRasterOverlay)
193 m_unmergedCopy =
new QImage(buffer()->copy());
194 QPainter p(buffer());
195 p.setCompositionMode(QPainter::CompositionMode_SourceOver);
196 p.drawImage(0,0,*overlay());
200void QBlittablePlatformPixmap::unmergeOverlay()
202 if (!m_unmergedCopy || !showRasterOverlay)
204 QPainter p(buffer());
205 p.setCompositionMode(QPainter::CompositionMode_Source);
206 p.drawImage(0,0,*m_unmergedCopy);
209 delete m_unmergedCopy;
213QImage *QBlittablePlatformPixmap::overlay()
215 if (!m_rasterOverlay||
216 m_rasterOverlay->size() != QSize(w,h)){
217 m_rasterOverlay =
new QImage(w,h,QImage::Format_ARGB32_Premultiplied);
218 m_rasterOverlay->fill(0x00000000);
219 uint color = QRandomGenerator::global()->bounded(11)+7;
220 m_overlayColor = QColor(Qt::GlobalColor(color));
221 m_overlayColor.setAlpha(0x88);
224 return m_rasterOverlay;
227void QBlittablePlatformPixmap::markRasterOverlayImpl(
const QRectF &rect)
229 if (!showRasterOverlay)
231 QRectF transformationRect = clipAndTransformRect(rect);
232 if (!transformationRect.isEmpty()) {
233 QPainter p(overlay());
234 p.setBrush(m_overlayColor);
235 p.setCompositionMode(QPainter::CompositionMode_Source);
236 p.fillRect(transformationRect,QBrush(m_overlayColor));
240void QBlittablePlatformPixmap::unmarkRasterOverlayImpl(
const QRectF &rect)
242 if (!showRasterOverlay)
244 QRectF transformationRect = clipAndTransformRect(rect);
245 if (!transformationRect.isEmpty()) {
246 QPainter p(overlay());
247 QColor color(0x00,0x00,0x00,0x00);
249 p.setCompositionMode(QPainter::CompositionMode_Source);
250 p.fillRect(transformationRect,QBrush(color));
254QRectF QBlittablePlatformPixmap::clipAndTransformRect(
const QRectF &rect)
const
256 QRectF transformationRect = rect;
258 if (m_engine->state()) {
259 transformationRect = m_engine->state()->matrix.mapRect(rect);
260 const QClipData *clipData = m_engine->clip();
262 if (clipData->hasRectClip) {
263 transformationRect &= clipData->clipRect;
264 }
else if (clipData->hasRegionClip) {
265 for (
const QRect &rect : clipData->clipRegion)
266 transformationRect &= rect;
270 return transformationRect;
Combined button and popup list for selecting options.
static QT_BEGIN_NAMESPACE int global_ser_no