kill the emulation painting engine with fire

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2016-07-03 01:24:48 +00:00
parent 6e0f5e5e06
commit e438721dff
8 changed files with 2 additions and 518 deletions

View file

@ -7,7 +7,6 @@ set(GUI_HEADERS
${CMAKE_CURRENT_SOURCE_DIR}/painting/qcolormap.h
${CMAKE_CURRENT_SOURCE_DIR}/painting/qcosmeticstroker_p.h
${CMAKE_CURRENT_SOURCE_DIR}/painting/qdrawutil.h
${CMAKE_CURRENT_SOURCE_DIR}/painting/qemulationpaintengine_p.h
${CMAKE_CURRENT_SOURCE_DIR}/painting/qgraphicssystem_p.h
${CMAKE_CURRENT_SOURCE_DIR}/painting/qgraphicssystemex_p.h
${CMAKE_CURRENT_SOURCE_DIR}/painting/qmatrix.h
@ -80,7 +79,6 @@ set(GUI_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/painting/qcosmeticstroker.cpp
${CMAKE_CURRENT_SOURCE_DIR}/painting/qcssutil.cpp
${CMAKE_CURRENT_SOURCE_DIR}/painting/qdrawutil.cpp
${CMAKE_CURRENT_SOURCE_DIR}/painting/qemulationpaintengine.cpp
${CMAKE_CURRENT_SOURCE_DIR}/painting/qgraphicssystem.cpp
${CMAKE_CURRENT_SOURCE_DIR}/painting/qmatrix.cpp
${CMAKE_CURRENT_SOURCE_DIR}/painting/qmemrotate.cpp

View file

@ -1,334 +0,0 @@
/****************************************************************************
**
** Copyright (C) 2015 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing/
**
** This file is part of the QtGui module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** 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
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see http://www.qt.io/terms-conditions. For further
** information use the contact form at http://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** As a special exception, The Qt Company gives you certain additional
** rights. These rights are described in The Qt Company 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.
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include <qemulationpaintengine_p.h>
#include <qpainter_p.h>
#include <qtextengine_p.h>
#include <qdebug.h>
QT_BEGIN_NAMESPACE
QEmulationPaintEngine::QEmulationPaintEngine(QPaintEngineEx *engine)
: real_engine(engine)
{
QPaintEngine::state = real_engine->state();
}
QPaintEngine::Type QEmulationPaintEngine::type() const
{
return real_engine->type();
}
bool QEmulationPaintEngine::begin(QPaintDevice *)
{
return true;
}
bool QEmulationPaintEngine::end()
{
return true;
}
QPainterState *QEmulationPaintEngine::createState(QPainterState *orig) const
{
return real_engine->createState(orig);
}
void QEmulationPaintEngine::fill(const QVectorPath &path, const QBrush &brush)
{
QPainterState *s = state();
if (s->bgMode == Qt::OpaqueMode) {
Qt::BrushStyle style = brush.style();
if (style >= Qt::Dense1Pattern && style <= Qt::DiagCrossPattern)
real_engine->fill(path, s->bgBrush);
}
Qt::BrushStyle style = qbrush_style(brush);
if (style >= Qt::LinearGradientPattern && style <= Qt::ConicalGradientPattern) {
const QGradient *g = brush.gradient();
if (g->coordinateMode() > QGradient::LogicalMode) {
if (g->coordinateMode() == QGradient::StretchToDeviceMode) {
QBrush copy = brush;
QTransform mat = copy.transform();
mat.scale(real_engine->painter()->device()->width(), real_engine->painter()->device()->height());
copy.setTransform(mat);
real_engine->fill(path, copy);
return;
} else if (g->coordinateMode() == QGradient::ObjectBoundingMode) {
QBrush copy = brush;
QTransform mat = copy.transform();
QRectF r = path.controlPointRect();
mat.translate(r.x(), r.y());
mat.scale(r.width(), r.height());
copy.setTransform(mat);
real_engine->fill(path, copy);
return;
}
}
}
real_engine->fill(path, brush);
}
void QEmulationPaintEngine::stroke(const QVectorPath &path, const QPen &pen)
{
QPainterState *s = state();
if (s->bgMode == Qt::OpaqueMode && pen.style() > Qt::SolidLine) {
QPen bgPen = pen;
bgPen.setBrush(s->bgBrush);
bgPen.setStyle(Qt::SolidLine);
real_engine->stroke(path, bgPen);
}
QBrush brush = pen.brush();
QPen copy = pen;
Qt::BrushStyle style = qbrush_style(brush);
if (style >= Qt::LinearGradientPattern && style <= Qt::ConicalGradientPattern) {
const QGradient *g = brush.gradient();
if (g->coordinateMode() > QGradient::LogicalMode) {
if (g->coordinateMode() == QGradient::StretchToDeviceMode) {
QTransform mat = brush.transform();
mat.scale(real_engine->painter()->device()->width(), real_engine->painter()->device()->height());
brush.setTransform(mat);
copy.setBrush(brush);
real_engine->stroke(path, copy);
return;
} else if (g->coordinateMode() == QGradient::ObjectBoundingMode) {
QTransform mat = brush.transform();
QRectF r = path.controlPointRect();
mat.translate(r.x(), r.y());
mat.scale(r.width(), r.height());
brush.setTransform(mat);
copy.setBrush(brush);
real_engine->stroke(path, copy);
return;
}
}
}
real_engine->stroke(path, pen);
}
void QEmulationPaintEngine::clip(const QVectorPath &path, Qt::ClipOperation op)
{
real_engine->clip(path, op);
}
void QEmulationPaintEngine::drawPixmap(const QRectF &r, const QPixmap &pm, const QRectF &sr)
{
if (state()->bgMode == Qt::OpaqueMode && pm.isQBitmap())
fillBGRect(r);
real_engine->drawPixmap(r, pm, sr);
}
void QEmulationPaintEngine::drawTextItem(const QPointF &p, const QTextItem &textItem)
{
if (state()->bgMode == Qt::OpaqueMode) {
const QTextItemInt &ti = static_cast<const QTextItemInt &>(textItem);
QRectF rect(p.x(), p.y() - ti.ascent.toReal(), ti.width.toReal(), (ti.ascent + ti.descent + 1).toReal());
fillBGRect(rect);
}
QPainterState *s = state();
Qt::BrushStyle style = qbrush_style(s->pen.brush());
if (style >= Qt::LinearGradientPattern && style <= Qt::ConicalGradientPattern)
{
QPen savedPen = s->pen;
QGradient g = *s->pen.brush().gradient();
if (g.coordinateMode() > QGradient::LogicalMode) {
QTransform mat = s->pen.brush().transform();
if (g.coordinateMode() == QGradient::StretchToDeviceMode) {
mat.scale(real_engine->painter()->device()->width(), real_engine->painter()->device()->height());
} else if (g.coordinateMode() == QGradient::ObjectBoundingMode) {
const QTextItemInt &ti = static_cast<const QTextItemInt &>(textItem);
QRectF r(p.x(), p.y() - ti.ascent.toReal(), ti.width.toReal(), (ti.ascent + ti.descent + 1).toReal());
mat.translate(r.x(), r.y());
mat.scale(r.width(), r.height());
}
g.setCoordinateMode(QGradient::LogicalMode);
QBrush brush(g);
brush.setTransform(mat);
s->pen.setBrush(brush);
penChanged();
real_engine->drawTextItem(p, textItem);
s->pen = savedPen;
penChanged();
return;
}
}
real_engine->drawTextItem(p, textItem);
}
void QEmulationPaintEngine::drawStaticTextItem(QStaticTextItem *item)
{
real_engine->drawStaticTextItem(item);
}
void QEmulationPaintEngine::drawTiledPixmap(const QRectF &r, const QPixmap &pixmap, const QPointF &s)
{
if (state()->bgMode == Qt::OpaqueMode && pixmap.isQBitmap())
fillBGRect(r);
real_engine->drawTiledPixmap(r, pixmap, s);
}
void QEmulationPaintEngine::drawImage(const QRectF &r, const QImage &pm, const QRectF &sr, Qt::ImageConversionFlags flags)
{
real_engine->drawImage(r, pm, sr, flags);
}
void QEmulationPaintEngine::drawPixmapFragments(const QPainter::PixmapFragment *fragments, int fragmentCount, const QPixmap &pixmap,
QPainter::PixmapFragmentHints hints)
{
if (state()->bgMode == Qt::OpaqueMode && pixmap.isQBitmap()) {
qreal oldOpacity = real_engine->state()->opacity;
QTransform oldTransform = real_engine->state()->matrix;
for (int i = 0; i < fragmentCount; ++i) {
QTransform transform = oldTransform;
transform.translate(fragments[i].x, fragments[i].y);
transform.rotate(fragments[i].rotation);
real_engine->state()->opacity = oldOpacity * fragments[i].opacity;
real_engine->state()->matrix = transform;
real_engine->opacityChanged();
real_engine->transformChanged();
qreal w = fragments[i].scaleX * fragments[i].width;
qreal h = fragments[i].scaleY * fragments[i].height;
fillBGRect(QRectF(-0.5 * w, -0.5 * h, w, h));
}
real_engine->state()->opacity = oldOpacity;
real_engine->state()->matrix = oldTransform;
real_engine->opacityChanged();
real_engine->transformChanged();
}
real_engine->drawPixmapFragments(fragments, fragmentCount, pixmap, hints);
}
void QEmulationPaintEngine::drawPixmapFragments(const QRectF *targetRects, const QRectF *sourceRects, int fragmentCount, const QPixmap &pixmap,
QPainter::PixmapFragmentHints hints)
{
if (state()->bgMode == Qt::OpaqueMode && pixmap.isQBitmap()) {
for (int i = 0; i < fragmentCount; ++i)
fillBGRect(targetRects[i]);
}
real_engine->drawPixmapFragments(targetRects, sourceRects, fragmentCount, pixmap, hints);
}
void QEmulationPaintEngine::clipEnabledChanged()
{
real_engine->clipEnabledChanged();
}
void QEmulationPaintEngine::penChanged()
{
real_engine->penChanged();
}
void QEmulationPaintEngine::brushChanged()
{
real_engine->brushChanged();
}
void QEmulationPaintEngine::brushOriginChanged()
{
real_engine->brushOriginChanged();
}
void QEmulationPaintEngine::opacityChanged()
{
real_engine->opacityChanged();
}
void QEmulationPaintEngine::compositionModeChanged()
{
real_engine->compositionModeChanged();
}
void QEmulationPaintEngine::renderHintsChanged()
{
real_engine->renderHintsChanged();
}
void QEmulationPaintEngine::transformChanged()
{
real_engine->transformChanged();
}
void QEmulationPaintEngine::setState(QPainterState *s)
{
QPaintEngine::state = s;
real_engine->setState(s);
}
void QEmulationPaintEngine::beginNativePainting()
{
real_engine->beginNativePainting();
}
void QEmulationPaintEngine::endNativePainting()
{
real_engine->endNativePainting();
}
void QEmulationPaintEngine::fillBGRect(const QRectF &r)
{
qreal pts[] = { r.x(), r.y(), r.x() + r.width(), r.y(),
r.x() + r.width(), r.y() + r.height(), r.x(), r.y() + r.height() };
QVectorPath vp(pts, 4, 0, QVectorPath::RectangleHint);
real_engine->fill(vp, state()->bgBrush);
}
QT_END_NAMESPACE

View file

@ -1,117 +0,0 @@
/****************************************************************************
**
** Copyright (C) 2015 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing/
**
** This file is part of the QtGui module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** 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
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see http://www.qt.io/terms-conditions. For further
** information use the contact form at http://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** As a special exception, The Qt Company gives you certain additional
** rights. These rights are described in The Qt Company 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.
**
** $QT_END_LICENSE$
**
****************************************************************************/
#ifndef QEMULATIONPAINTENGINE_P_H
#define QEMULATIONPAINTENGINE_P_H
//
// W A R N I N G
// -------------
//
// This file is not part of the Qt API. It exists purely as an
// implementation detail. This header file may change from version to
// version without notice, or even be removed.
//
// We mean it.
//
#include <qpaintengineex_p.h>
QT_BEGIN_HEADER
QT_BEGIN_NAMESPACE
class QEmulationPaintEngine : public QPaintEngineEx
{
public:
QEmulationPaintEngine(QPaintEngineEx *engine);
virtual bool begin(QPaintDevice *pdev);
virtual bool end();
virtual Type type() const;
virtual QPainterState *createState(QPainterState *orig) const;
virtual void fill(const QVectorPath &path, const QBrush &brush);
virtual void stroke(const QVectorPath &path, const QPen &pen);
virtual void clip(const QVectorPath &path, Qt::ClipOperation op);
virtual void drawPixmap(const QRectF &r, const QPixmap &pm, const QRectF &sr);
virtual void drawTextItem(const QPointF &p, const QTextItem &textItem);
virtual void drawStaticTextItem(QStaticTextItem *item);
virtual void drawTiledPixmap(const QRectF &r, const QPixmap &pixmap, const QPointF &s);
virtual void drawImage(const QRectF &r, const QImage &pm, const QRectF &sr, Qt::ImageConversionFlags flags);
virtual void drawPixmapFragments(const QPainter::PixmapFragment *fragments, int fragmentCount, const QPixmap &pixmap,
QPainter::PixmapFragmentHints hints);
virtual void drawPixmapFragments(const QRectF *targetRects, const QRectF *sourceRects, int fragmentCount, const QPixmap &pixmap,
QPainter::PixmapFragmentHints hints);
virtual void clipEnabledChanged();
virtual void penChanged();
virtual void brushChanged();
virtual void brushOriginChanged();
virtual void opacityChanged();
virtual void compositionModeChanged();
virtual void renderHintsChanged();
virtual void transformChanged();
virtual void setState(QPainterState *s);
virtual void beginNativePainting();
virtual void endNativePainting();
virtual uint flags() const {return QPaintEngineEx::IsEmulationEngine | QPaintEngineEx::DoNotEmulate;}
inline QPainterState *state() { return (QPainterState *)QPaintEngine::state; }
inline const QPainterState *state() const { return (const QPainterState *)QPaintEngine::state; }
QPaintEngineEx *real_engine;
private:
void fillBGRect(const QRectF &r);
};
QT_END_NAMESPACE
QT_END_HEADER
#endif

View file

@ -42,7 +42,6 @@
#include <qpainterpath_p.h>
#include <qpaintbuffer_p.h>
#include <qfontengine_p.h>
#include <qemulationpaintengine_p.h>
#include <qimage_p.h>
#include <qstatictext.h>
#include <qstatictext_p.h>

View file

@ -409,7 +409,6 @@ public:
virtual void drawStaticTextItem(QStaticTextItem *staticTextItem);
virtual void setState(QPainterState *s);
virtual uint flags() const {return QPaintEngineEx::DoNotEmulate;}
QPaintBufferPrivate *buffer;

View file

@ -221,13 +221,6 @@ public:
// that will be requested, and not just the "type".
virtual QPixmapFilter *pixmapFilter(int /*type*/, const QPixmapFilter * /*prototype*/) { return 0; }
// These flags are needed in the implementation of paint buffers.
enum Flags
{
DoNotEmulate = 0x01, // If set, QPainter will not wrap this engine in an emulation engine.
IsEmulationEngine = 0x02 // If set, this object is a QEmulationEngine.
};
virtual uint flags() const {return 0;}
virtual bool supportsTransformations(qreal pixelSize, const QTransform &m) const;
protected:

View file

@ -66,7 +66,6 @@
#include <qfontengine_p.h>
#include <qpaintengine_p.h>
#include <qemulationpaintengine_p.h>
#include <qpainterpath_p.h>
#include <qtextengine_p.h>
#include <qwidget_p.h>
@ -173,40 +172,9 @@ static bool qt_painter_thread_test(int devType, const char *what, bool extraCond
}
#endif
void QPainterPrivate::checkEmulation()
{
Q_ASSERT(extended);
if (extended->flags() & QPaintEngineEx::DoNotEmulate)
return;
bool doEmulation = false;
if (state->bgMode == Qt::OpaqueMode)
doEmulation = true;
const QGradient *bg = state->brush.gradient();
if (bg && bg->coordinateMode() > QGradient::LogicalMode)
doEmulation = true;
const QGradient *pg = qpen_brush(state->pen).gradient();
if (pg && pg->coordinateMode() > QGradient::LogicalMode)
doEmulation = true;
if (doEmulation) {
if (extended != emulationEngine) {
if (!emulationEngine)
emulationEngine = new QEmulationPaintEngine(extended);
extended = emulationEngine;
extended->setState(state);
}
} else if (emulationEngine == extended) {
extended = emulationEngine->real_engine;
}
}
QPainterPrivate::~QPainterPrivate()
{
delete emulationEngine;
for (int i=0; i<states.size(); ++i)
delete states.at(i);
@ -337,12 +305,6 @@ void QPainterPrivate::detachPainterPrivate(QPainter *q)
q->restore();
q->d_ptr.take();
q->d_ptr.reset(original);
if (emulationEngine) {
extended = emulationEngine->real_engine;
delete emulationEngine;
emulationEngine = 0;
}
}
@ -1638,7 +1600,6 @@ void QPainter::restore()
d->txinv = false;
if (d->extended) {
d->checkEmulation();
d->extended->setState(d->state);
delete tmp;
return;
@ -1780,8 +1741,6 @@ bool QPainter::begin(QPaintDevice *pd)
d->device = pd;
d->extended = d->engine->isExtended() ? static_cast<QPaintEngineEx *>(d->engine) : 0;
if (d->emulationEngine)
d->emulationEngine->real_engine = d->extended;
// Setup new state...
Q_ASSERT(!d->state);
@ -1967,11 +1926,6 @@ bool QPainter::end()
delete d->engine;
}
if (d->emulationEngine) {
delete d->emulationEngine;
d->emulationEngine = 0;
}
if (d->extended) {
d->extended = 0;
}
@ -3886,9 +3840,7 @@ void QPainter::setBackgroundMode(Qt::BGMode mode)
return;
d->state->bgMode = mode;
if (d->extended) {
d->checkEmulation();
} else {
if (!d->extended) {
d->state->dirtyFlags |= QPaintEngine::DirtyBackgroundMode;
}
}
@ -3972,7 +3924,6 @@ void QPainter::setPen(const QPen &pen)
d->state->pen = pen;
if (d->extended) {
d->checkEmulation();
d->extended->penChanged();
return;
}
@ -4054,7 +4005,6 @@ void QPainter::setBrush(const QBrush &brush)
if (d->extended) {
d->state->brush = brush;
d->checkEmulation();
d->extended->brushChanged();
return;
}

View file

@ -191,8 +191,7 @@ class QPainterPrivate
public:
QPainterPrivate(QPainter *painter)
: q_ptr(painter), d_ptrs(0), state(0), dummyState(0), txinv(0), inDestructor(false), d_ptrs_size(0),
refcount(1), device(0), original_device(0), helper_device(0), engine(0), emulationEngine(0),
extended(0)
refcount(1), device(0), original_device(0), helper_device(0), engine(0), extended(0)
{
}
@ -244,8 +243,6 @@ public:
return state->pen.style() != Qt::NoPen && state->pen.width() == 0 ? 1 : 0;
}
void checkEmulation();
static QPainterPrivate *get(QPainter *painter)
{
return painter->d_ptr.data();
@ -259,7 +256,6 @@ public:
QPaintDevice *original_device;
QPaintDevice *helper_device;
QPaintEngine *engine;
QEmulationPaintEngine *emulationEngine;
QPaintEngineEx *extended;
QBrush colorBrush; // for fill with solid color
};