manually scaling textures according to window coordinates
This commit is contained in:
parent
c539e3bb24
commit
8fd6910ca4
@ -57,37 +57,43 @@ static inline QSGNode* qskFindNodeByFlag( QSGNode* parent, int nodeRole )
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
static qreal qskDevicePixelRatio( const QskSkinnable* skinnable )
|
||||
{
|
||||
if ( auto control = skinnable->owningControl() )
|
||||
{
|
||||
if ( auto window = control->window() )
|
||||
return window->effectiveDevicePixelRatio();
|
||||
}
|
||||
|
||||
return qGuiApp->devicePixelRatio();
|
||||
}
|
||||
|
||||
static inline QSGNode* qskUpdateGraphicNode(
|
||||
const QskSkinnable* skinnable, QSGNode* node,
|
||||
const QskGraphic& graphic, const QskColorFilter& colorFilter,
|
||||
const QRect& rect )
|
||||
const QRectF& rect )
|
||||
{
|
||||
if ( rect.isEmpty() )
|
||||
return nullptr;
|
||||
|
||||
auto mode = QskTextureRenderer::OpenGL;
|
||||
|
||||
const auto control = skinnable->owningControl();
|
||||
if ( control && control->testControlFlag( QskControl::PreferRasterForTextures ) )
|
||||
mode = QskTextureRenderer::Raster;
|
||||
|
||||
auto graphicNode = static_cast< QskGraphicNode* >( node );
|
||||
if ( graphicNode == nullptr )
|
||||
graphicNode = new QskGraphicNode();
|
||||
|
||||
const qreal ratio = qskDevicePixelRatio( skinnable );
|
||||
const QRect r( rect.x(), rect.y(), ratio * rect.width(), ratio * rect.height() );
|
||||
QRectF r = rect;
|
||||
|
||||
if ( const auto control = skinnable->owningControl() )
|
||||
{
|
||||
if ( control->testControlFlag( QskControl::PreferRasterForTextures ) )
|
||||
mode = QskTextureRenderer::Raster;
|
||||
|
||||
if ( auto window = control->window() )
|
||||
{
|
||||
/*
|
||||
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.
|
||||
*/
|
||||
const QRectF sceneRect(
|
||||
control->mapToScene( r.topLeft() ),
|
||||
r.size() * window->effectiveDevicePixelRatio() );
|
||||
|
||||
r = qskInnerRect( sceneRect );
|
||||
r.moveTopLeft( control->mapFromScene( r.topLeft() ) );
|
||||
}
|
||||
}
|
||||
|
||||
graphicNode->setGraphic( graphic, colorFilter, mode, r );
|
||||
|
||||
@ -538,12 +544,10 @@ QSGNode* QskSkinlet::updateGraphicNode(
|
||||
if ( graphic.isNull() )
|
||||
return nullptr;
|
||||
|
||||
const QSizeF scaledSize = graphic.defaultSize().scaled(
|
||||
const QSizeF size = graphic.defaultSize().scaled(
|
||||
rect.size(), Qt::KeepAspectRatio );
|
||||
|
||||
const QRect r = qskAlignedRect( qskInnerRect( rect ),
|
||||
int( scaledSize.width() ), int( scaledSize.height() ), alignment );
|
||||
|
||||
const QRectF r = qskAlignedRectF( rect, size.width(), size.height(), alignment );
|
||||
return qskUpdateGraphicNode( skinnable, node, graphic, colorFilter, r );
|
||||
}
|
||||
|
||||
@ -555,8 +559,7 @@ QSGNode* QskSkinlet::updateGraphicNode(
|
||||
if ( graphic.isNull() )
|
||||
return nullptr;
|
||||
|
||||
return qskUpdateGraphicNode( skinnable, node,
|
||||
graphic, colorFilter, rect.toAlignedRect() );
|
||||
return qskUpdateGraphicNode( skinnable, node, graphic, colorFilter, rect );
|
||||
}
|
||||
|
||||
#include "moc_QskSkinlet.cpp"
|
||||
|
@ -47,7 +47,7 @@ QskGraphicNode::~QskGraphicNode()
|
||||
|
||||
void QskGraphicNode::setGraphic(
|
||||
const QskGraphic& graphic, const QskColorFilter& colorFilter,
|
||||
QskTextureRenderer::RenderMode renderMode, const QRect& rect )
|
||||
QskTextureRenderer::RenderMode renderMode, const QRectF& rect )
|
||||
{
|
||||
bool isTextureDirty = ( QskTextureNode::textureId() == 0 );
|
||||
|
||||
@ -70,7 +70,7 @@ void QskGraphicNode::setGraphic(
|
||||
if ( isTextureDirty )
|
||||
{
|
||||
const uint textureId = QskTextureRenderer::createTextureFromGraphic(
|
||||
renderMode, rect.size(), graphic, colorFilter, Qt::IgnoreAspectRatio );
|
||||
renderMode, rect.size().toSize(), graphic, colorFilter, Qt::IgnoreAspectRatio );
|
||||
|
||||
QskTextureNode::setTextureId( textureId );
|
||||
}
|
||||
|
@ -19,7 +19,7 @@ class QSK_EXPORT QskGraphicNode : public QskTextureNode
|
||||
~QskGraphicNode() override;
|
||||
|
||||
void setGraphic( const QskGraphic&, const QskColorFilter&,
|
||||
QskTextureRenderer::RenderMode, const QRect& );
|
||||
QskTextureRenderer::RenderMode, const QRectF& );
|
||||
|
||||
private:
|
||||
void setTextureId( int ) = delete;
|
||||
|
@ -316,11 +316,9 @@ void QskTextureNode::updateTexture()
|
||||
r.setBottom( 0 );
|
||||
}
|
||||
|
||||
#if 1
|
||||
const qreal ratio = qskDevicePixelRatio();
|
||||
const QRect rect( d->rect.x(), d->rect.y(),
|
||||
const QRectF rect( d->rect.x(), d->rect.y(),
|
||||
d->rect.width() / ratio, d->rect.height() / ratio );
|
||||
#endif
|
||||
|
||||
QSGGeometry::updateTexturedRectGeometry( &d->geometry, rect, r );
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user