devicePixelRatio detection moved to QskTextureRenderer
This commit is contained in:
parent
517f17088a
commit
1f59962360
|
@ -90,21 +90,18 @@ static inline QSGNode* qskUpdateGraphicNode(
|
|||
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() );
|
||||
/*
|
||||
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() * QskTextureRenderer::devicePixelRatio() );
|
||||
|
||||
r = qskInnerRect( sceneRect );
|
||||
r.moveTopLeft( control->mapFromScene( r.topLeft() ) );
|
||||
}
|
||||
r = qskInnerRect( sceneRect );
|
||||
r.moveTopLeft( control->mapFromScene( r.topLeft() ) );
|
||||
}
|
||||
|
||||
graphicNode->setGraphic( graphic, colorFilter, mode, r );
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include "QskTextureNode.h"
|
||||
#include "QskTextureRenderer.h"
|
||||
|
||||
#include <qopenglfunctions.h>
|
||||
#include <qsggeometry.h>
|
||||
|
@ -6,41 +7,6 @@
|
|||
|
||||
#include <private/qsgnode_p.h>
|
||||
|
||||
#if 1
|
||||
|
||||
#include <qguiapplication.h>
|
||||
#include <qquickwindow.h>
|
||||
#include <qscreen.h>
|
||||
#include <qsurface.h>
|
||||
|
||||
static inline qreal qskDevicePixelRatio()
|
||||
{
|
||||
qreal ratio = 1.0;
|
||||
|
||||
const auto context = QOpenGLContext::currentContext();
|
||||
|
||||
if ( context->surface()->surfaceClass() == QSurface::Window )
|
||||
{
|
||||
auto* window = static_cast< QWindow* >( context->surface() );
|
||||
|
||||
if ( auto* quickWindow = qobject_cast< QQuickWindow* >( window ) )
|
||||
ratio = quickWindow->effectiveDevicePixelRatio();
|
||||
else
|
||||
ratio = window->devicePixelRatio();
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( context->screen() )
|
||||
ratio = context->screen()->devicePixelRatio();
|
||||
else
|
||||
ratio = qGuiApp->devicePixelRatio();
|
||||
}
|
||||
|
||||
return ratio;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
namespace
|
||||
{
|
||||
class MaterialShader final : public QSGMaterialShader
|
||||
|
@ -316,7 +282,8 @@ void QskTextureNode::updateTexture()
|
|||
r.setBottom( 0 );
|
||||
}
|
||||
|
||||
const qreal ratio = qskDevicePixelRatio();
|
||||
const qreal ratio = QskTextureRenderer::devicePixelRatio();
|
||||
|
||||
const QRectF rect( d->rect.x(), d->rect.y(),
|
||||
d->rect.width() / ratio, d->rect.height() / ratio );
|
||||
|
||||
|
|
|
@ -18,6 +18,11 @@
|
|||
#include <qimage.h>
|
||||
#include <qpainter.h>
|
||||
|
||||
#include <qguiapplication.h>
|
||||
#include <qquickwindow.h>
|
||||
#include <qscreen.h>
|
||||
#include <qsurface.h>
|
||||
|
||||
static uint qskCreateTextureOpenGL(
|
||||
const QSize& size, QskTextureRenderer::PaintHelper* helper )
|
||||
{
|
||||
|
@ -173,3 +178,36 @@ uint QskTextureRenderer::createTextureFromGraphic(
|
|||
PaintHelper helper( graphic, colorFilter, aspectRatioMode );
|
||||
return createTexture( renderMode, size, &helper );
|
||||
}
|
||||
|
||||
static inline qreal qskOffscreenBufferRatio( const QOpenGLContext* context )
|
||||
{
|
||||
if ( context->screen() )
|
||||
return context->screen()->devicePixelRatio();
|
||||
|
||||
return qGuiApp->devicePixelRatio();
|
||||
}
|
||||
|
||||
qreal QskTextureRenderer::devicePixelRatio( const QOpenGLContext* context )
|
||||
{
|
||||
if ( context == nullptr )
|
||||
context = QOpenGLContext::currentContext();
|
||||
|
||||
qreal ratio = 1.0;
|
||||
|
||||
if ( context->surface()->surfaceClass() == QSurface::Window )
|
||||
{
|
||||
auto* window = static_cast< QWindow* >( context->surface() );
|
||||
|
||||
if ( auto* quickWindow = qobject_cast< QQuickWindow* >( window ) )
|
||||
ratio = quickWindow->effectiveDevicePixelRatio();
|
||||
else
|
||||
ratio = window->devicePixelRatio();
|
||||
}
|
||||
else
|
||||
{
|
||||
ratio = qskOffscreenBufferRatio( context );
|
||||
}
|
||||
|
||||
return ratio;
|
||||
}
|
||||
|
||||
|
|
|
@ -14,6 +14,7 @@ class QskColorFilter;
|
|||
|
||||
class QPainter;
|
||||
class QSize;
|
||||
class QOpenGLContext;
|
||||
|
||||
namespace QskTextureRenderer
|
||||
{
|
||||
|
@ -46,6 +47,8 @@ namespace QskTextureRenderer
|
|||
QSK_EXPORT uint createTextureFromGraphic(
|
||||
RenderMode, const QSize&, const QskGraphic&,
|
||||
const QskColorFilter&, Qt::AspectRatioMode );
|
||||
|
||||
QSK_EXPORT qreal devicePixelRatio( const QOpenGLContext* = nullptr );
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue