hiding the devicePixelRato scaling in the nodes
This commit is contained in:
parent
e4ffc3f074
commit
738de14d4c
|
@ -125,7 +125,7 @@ bool Benchmark::run( const QString& dirName )
|
||||||
using namespace QskTextureRenderer;
|
using namespace QskTextureRenderer;
|
||||||
|
|
||||||
const auto textureId = createTextureFromGraphic(
|
const auto textureId = createTextureFromGraphic(
|
||||||
OpenGL, targetSize, graphics[ i ], colorFilter,
|
nullptr, OpenGL, targetSize, graphics[ i ], colorFilter,
|
||||||
Qt::IgnoreAspectRatio );
|
Qt::IgnoreAspectRatio );
|
||||||
|
|
||||||
if ( textureId == 0 )
|
if ( textureId == 0 )
|
||||||
|
@ -151,7 +151,7 @@ bool Benchmark::run( const QString& dirName )
|
||||||
using namespace QskTextureRenderer;
|
using namespace QskTextureRenderer;
|
||||||
|
|
||||||
const auto textureId = createTextureFromGraphic(
|
const auto textureId = createTextureFromGraphic(
|
||||||
Raster, targetSize, graphics[ i ], colorFilter,
|
nullptr, Raster, targetSize, graphics[ i ], colorFilter,
|
||||||
Qt::IgnoreAspectRatio );
|
Qt::IgnoreAspectRatio );
|
||||||
|
|
||||||
if ( textureId == 0 )
|
if ( textureId == 0 )
|
||||||
|
|
|
@ -26,6 +26,28 @@
|
||||||
#include <qquickwindow.h>
|
#include <qquickwindow.h>
|
||||||
#include <qsgsimplerectnode.h>
|
#include <qsgsimplerectnode.h>
|
||||||
|
|
||||||
|
static inline QRectF qskSceneAlignedRect( const QQuickItem* item , const QRectF& rect )
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
Aligning rect according to scene coordinates, so that
|
||||||
|
we don't run into rounding issues downstream, where values
|
||||||
|
will be floored/ceiled ending up with a slightly different
|
||||||
|
aspect ratio.
|
||||||
|
*/
|
||||||
|
|
||||||
|
const auto ratio = item->window()->devicePixelRatio();
|
||||||
|
|
||||||
|
const auto pos = item->mapToScene( rect.topLeft() ) * ratio;
|
||||||
|
const auto size = rect.size() * ratio;
|
||||||
|
|
||||||
|
const qreal x = qRound( pos.x() ) / ratio;
|
||||||
|
const qreal y = qRound( pos.y() ) / ratio;
|
||||||
|
const qreal w = qRound( size.width() ) / ratio;
|
||||||
|
const qreal h = qRound( size.height() ) / ratio;
|
||||||
|
|
||||||
|
return QRectF( item->mapFromScene( QPointF( x, y ) ), QSizeF( w, h ) );
|
||||||
|
}
|
||||||
|
|
||||||
static inline QRectF qskSubControlRect( const QskSkinlet* skinlet,
|
static inline QRectF qskSubControlRect( const QskSkinlet* skinlet,
|
||||||
const QskSkinnable* skinnable, QskAspect::Subcontrol subControl )
|
const QskSkinnable* skinnable, QskAspect::Subcontrol subControl )
|
||||||
{
|
{
|
||||||
|
@ -59,19 +81,7 @@ static inline QSGNode* qskUpdateGraphicNode(
|
||||||
if ( control->testUpdateFlag( QskControl::PreferRasterForTextures ) )
|
if ( control->testUpdateFlag( QskControl::PreferRasterForTextures ) )
|
||||||
mode = QskTextureRenderer::Raster;
|
mode = QskTextureRenderer::Raster;
|
||||||
|
|
||||||
/*
|
const auto r = qskSceneAlignedRect( control, rect );
|
||||||
Aligning the rect according to scene coordinates, so that
|
|
||||||
we don't run into rounding issues downstream, where values
|
|
||||||
will be floored/ceiled ending up with a slightly different
|
|
||||||
aspect ratio.
|
|
||||||
*/
|
|
||||||
QRectF r(
|
|
||||||
control->mapToScene( rect.topLeft() ),
|
|
||||||
rect.size() * control->window()->effectiveDevicePixelRatio() );
|
|
||||||
|
|
||||||
r = qskInnerRect( r );
|
|
||||||
r.moveTopLeft( control->mapFromScene( r.topLeft() ) );
|
|
||||||
|
|
||||||
graphicNode->setGraphic( control->window(), graphic,
|
graphicNode->setGraphic( control->window(), graphic,
|
||||||
colorFilter, mode, r, mirrored );
|
colorFilter, mode, r, mirrored );
|
||||||
|
|
||||||
|
@ -161,20 +171,7 @@ static inline QSGNode* qskUpdateArcNode(
|
||||||
if ( arcNode == nullptr )
|
if ( arcNode == nullptr )
|
||||||
arcNode = new QskArcNode();
|
arcNode = new QskArcNode();
|
||||||
|
|
||||||
auto r = rect;
|
const auto r = qskSceneAlignedRect( control, rect );
|
||||||
#if 1
|
|
||||||
{
|
|
||||||
/*
|
|
||||||
Fiddling around with the pixel ratio should be hidden below QskArcNode.
|
|
||||||
Code will break once QskArcNode is not texture based anymore. TODO ...
|
|
||||||
*/
|
|
||||||
|
|
||||||
const auto ratio = control->window()->effectiveDevicePixelRatio();
|
|
||||||
absoluteMetrics.setWidth( absoluteMetrics.width() * ratio );
|
|
||||||
r.setSize( r.size() * ratio );
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
arcNode->setArcData( r, absoluteMetrics, fillGradient, control->window() );
|
arcNode->setArcData( r, absoluteMetrics, fillGradient, control->window() );
|
||||||
|
|
||||||
return arcNode;
|
return arcNode;
|
||||||
|
|
|
@ -60,7 +60,7 @@ QSGTexture* QskGraphicTextureFactory::createTexture( QQuickWindow* window ) cons
|
||||||
using namespace QskTextureRenderer;
|
using namespace QskTextureRenderer;
|
||||||
|
|
||||||
const uint textureId = createTextureFromGraphic(
|
const uint textureId = createTextureFromGraphic(
|
||||||
QskTextureRenderer::OpenGL, m_size, m_graphic, m_colorFilter,
|
window, QskTextureRenderer::OpenGL, m_size, m_graphic, m_colorFilter,
|
||||||
Qt::IgnoreAspectRatio );
|
Qt::IgnoreAspectRatio );
|
||||||
|
|
||||||
return textureFromId( window, textureId, m_size );
|
return textureFromId( window, textureId, m_size );
|
||||||
|
|
|
@ -78,7 +78,7 @@ void QskGraphicNode::setGraphic(
|
||||||
if ( isTextureDirty )
|
if ( isTextureDirty )
|
||||||
{
|
{
|
||||||
textureId = QskTextureRenderer::createTextureFromGraphic(
|
textureId = QskTextureRenderer::createTextureFromGraphic(
|
||||||
renderMode, textureSize, graphic, colorFilter, Qt::IgnoreAspectRatio );
|
window, renderMode, textureSize, graphic, colorFilter, Qt::IgnoreAspectRatio );
|
||||||
}
|
}
|
||||||
|
|
||||||
QskTextureNode::setTexture( window, rect, textureId, mirrored );
|
QskTextureNode::setTexture( window, rect, textureId, mirrored );
|
||||||
|
|
|
@ -56,7 +56,7 @@ void QskPaintedNode::update( QQuickWindow* window,
|
||||||
{
|
{
|
||||||
PaintHelper helper( this );
|
PaintHelper helper( this );
|
||||||
textureId = QskTextureRenderer::createTexture(
|
textureId = QskTextureRenderer::createTexture(
|
||||||
renderMode, rect.size(), &helper );
|
window, renderMode, rect.size(), &helper );
|
||||||
}
|
}
|
||||||
|
|
||||||
QskTextureNode::setTexture( window, rect, textureId );
|
QskTextureNode::setTexture( window, rect, textureId );
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#include "QskTextureNode.h"
|
#include "QskTextureNode.h"
|
||||||
#include "QskTextureRenderer.h"
|
#include "QskFunctions.h"
|
||||||
|
|
||||||
#include <qopenglfunctions.h>
|
#include <qopenglfunctions.h>
|
||||||
#include <qsggeometry.h>
|
#include <qsggeometry.h>
|
||||||
|
@ -237,7 +237,7 @@ class QskTextureNodePrivate final : public QSGGeometryNodePrivate
|
||||||
|
|
||||||
void setTextureId( QQuickWindow*, uint id );
|
void setTextureId( QQuickWindow*, uint id );
|
||||||
|
|
||||||
void updateTextureGeometry( const QQuickWindow* window )
|
void updateTextureGeometry()
|
||||||
{
|
{
|
||||||
QRectF r( 0, 0, 1, 1 );
|
QRectF r( 0, 0, 1, 1 );
|
||||||
|
|
||||||
|
@ -253,15 +253,7 @@ class QskTextureNodePrivate final : public QSGGeometryNodePrivate
|
||||||
r.setBottom( 0 );
|
r.setBottom( 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
const qreal ratio = window->effectiveDevicePixelRatio();
|
QSGGeometry::updateTexturedRectGeometry( &geometry, rect, r );
|
||||||
|
|
||||||
const qreal x = int( rect.x() / ratio ) * ratio;
|
|
||||||
const qreal y = int( rect.y() / ratio ) * ratio;
|
|
||||||
const qreal w = rect.width() / ratio;
|
|
||||||
const qreal h = rect.height() / ratio;
|
|
||||||
|
|
||||||
QSGGeometry::updateTexturedRectGeometry(
|
|
||||||
&geometry, QRectF( x, y, w, h ), r );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QSGGeometry geometry;
|
QSGGeometry geometry;
|
||||||
|
@ -301,7 +293,7 @@ void QskTextureNode::setTexture( QQuickWindow* window,
|
||||||
d->rect = rect;
|
d->rect = rect;
|
||||||
d->mirrored = mirrored;
|
d->mirrored = mirrored;
|
||||||
|
|
||||||
d->updateTextureGeometry( window );
|
d->updateTextureGeometry();
|
||||||
markDirty( DirtyGeometry );
|
markDirty( DirtyGeometry );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,11 +25,13 @@
|
||||||
#include <qsgtexture_platform.h>
|
#include <qsgtexture_platform.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static uint qskCreateTextureOpenGL(
|
static uint qskCreateTextureOpenGL( QQuickWindow* window,
|
||||||
const QSize& size, QskTextureRenderer::PaintHelper* helper )
|
const QSize& size, QskTextureRenderer::PaintHelper* helper )
|
||||||
{
|
{
|
||||||
const int width = size.width();
|
const auto ratio = window ? window->effectiveDevicePixelRatio() : 1.0;
|
||||||
const int height = size.height();
|
|
||||||
|
const int width = ratio * size.width();
|
||||||
|
const int height = ratio * size.height();
|
||||||
|
|
||||||
QOpenGLFramebufferObjectFormat format1;
|
QOpenGLFramebufferObjectFormat format1;
|
||||||
format1.setAttachment( QOpenGLFramebufferObject::CombinedDepthStencil );
|
format1.setAttachment( QOpenGLFramebufferObject::CombinedDepthStencil );
|
||||||
|
@ -44,6 +46,7 @@ static uint qskCreateTextureOpenGL(
|
||||||
|
|
||||||
{
|
{
|
||||||
QPainter painter( &pd );
|
QPainter painter( &pd );
|
||||||
|
painter.scale( ratio, ratio );
|
||||||
|
|
||||||
painter.setCompositionMode( QPainter::CompositionMode_Source );
|
painter.setCompositionMode( QPainter::CompositionMode_Source );
|
||||||
painter.fillRect( 0, 0, width, height, Qt::transparent );
|
painter.fillRect( 0, 0, width, height, Qt::transparent );
|
||||||
|
@ -77,15 +80,26 @@ static uint qskCreateTextureOpenGL(
|
||||||
return fbo.takeTexture();
|
return fbo.takeTexture();
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint qskCreateTextureRaster(
|
static uint qskCreateTextureRaster( QQuickWindow* window,
|
||||||
const QSize& size, QskTextureRenderer::PaintHelper* helper )
|
const QSize& size, QskTextureRenderer::PaintHelper* helper )
|
||||||
{
|
{
|
||||||
QImage image( size, QImage::Format_RGBA8888_Premultiplied );
|
const auto ratio = window ? window->effectiveDevicePixelRatio() : 1.0;
|
||||||
|
|
||||||
|
QImage image( size * ratio, QImage::Format_RGBA8888_Premultiplied );
|
||||||
image.fill( Qt::transparent );
|
image.fill( Qt::transparent );
|
||||||
|
|
||||||
{
|
{
|
||||||
QPainter painter( &image );
|
QPainter painter( &image );
|
||||||
|
|
||||||
|
/*
|
||||||
|
setting a devicePixelRatio for the image only works for
|
||||||
|
value >= 1.0. So we have to scale manually.
|
||||||
|
*/
|
||||||
|
painter.scale( ratio, ratio );
|
||||||
|
|
||||||
helper->paint( &painter, size );
|
helper->paint( &painter, size );
|
||||||
|
|
||||||
|
image.save( "/tmp/xx.png" );
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto target = QOpenGLTexture::Target2D;
|
const auto target = QOpenGLTexture::Target2D;
|
||||||
|
@ -165,7 +179,8 @@ QskTextureRenderer::PaintHelper::~PaintHelper()
|
||||||
}
|
}
|
||||||
|
|
||||||
uint QskTextureRenderer::createTexture(
|
uint QskTextureRenderer::createTexture(
|
||||||
RenderMode renderMode, const QSize& size, PaintHelper* helper )
|
QQuickWindow* window, RenderMode renderMode,
|
||||||
|
const QSize& size, PaintHelper* helper )
|
||||||
{
|
{
|
||||||
#if QT_VERSION >= QT_VERSION_CHECK( 6, 0, 0 )
|
#if QT_VERSION >= QT_VERSION_CHECK( 6, 0, 0 )
|
||||||
// Qt6.0.0 is buggy when using FBOs. So let's disable it for the moment TODO ...
|
// Qt6.0.0 is buggy when using FBOs. So let's disable it for the moment TODO ...
|
||||||
|
@ -180,13 +195,13 @@ uint QskTextureRenderer::createTexture(
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( renderMode == Raster )
|
if ( renderMode == Raster )
|
||||||
return qskCreateTextureRaster( size, helper );
|
return qskCreateTextureRaster( window, size, helper );
|
||||||
else
|
else
|
||||||
return qskCreateTextureOpenGL( size, helper );
|
return qskCreateTextureOpenGL( window, size, helper );
|
||||||
}
|
}
|
||||||
|
|
||||||
uint QskTextureRenderer::createTextureFromGraphic(
|
uint QskTextureRenderer::createTextureFromGraphic(
|
||||||
RenderMode renderMode, const QSize& size,
|
QQuickWindow* window, RenderMode renderMode, const QSize& size,
|
||||||
const QskGraphic& graphic, const QskColorFilter& colorFilter,
|
const QskGraphic& graphic, const QskColorFilter& colorFilter,
|
||||||
Qt::AspectRatioMode aspectRatioMode )
|
Qt::AspectRatioMode aspectRatioMode )
|
||||||
{
|
{
|
||||||
|
@ -214,5 +229,5 @@ uint QskTextureRenderer::createTextureFromGraphic(
|
||||||
};
|
};
|
||||||
|
|
||||||
PaintHelper helper( graphic, colorFilter, aspectRatioMode );
|
PaintHelper helper( graphic, colorFilter, aspectRatioMode );
|
||||||
return createTexture( renderMode, size, &helper );
|
return createTexture( window, renderMode, size, &helper );
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,10 +42,11 @@ namespace QskTextureRenderer
|
||||||
virtual void paint( QPainter*, const QSize& ) = 0;
|
virtual void paint( QPainter*, const QSize& ) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
QSK_EXPORT uint createTexture( RenderMode, const QSize&, PaintHelper* );
|
QSK_EXPORT uint createTexture(
|
||||||
|
QQuickWindow*, RenderMode, const QSize&, PaintHelper* );
|
||||||
|
|
||||||
QSK_EXPORT uint createTextureFromGraphic(
|
QSK_EXPORT uint createTextureFromGraphic(
|
||||||
RenderMode, const QSize&, const QskGraphic&,
|
QQuickWindow*, RenderMode, const QSize&, const QskGraphic&,
|
||||||
const QskColorFilter&, Qt::AspectRatioMode );
|
const QskColorFilter&, Qt::AspectRatioMode );
|
||||||
|
|
||||||
QSK_EXPORT QSGTexture* textureFromId(
|
QSK_EXPORT QSGTexture* textureFromId(
|
||||||
|
|
Loading…
Reference in New Issue