devicePixelRatio detection moved to QskTextureRenderer
This commit is contained in:
parent
517f17088a
commit
1f59962360
|
@ -90,8 +90,6 @@ static inline QSGNode* qskUpdateGraphicNode(
|
||||||
if ( control->testControlFlag( QskControl::PreferRasterForTextures ) )
|
if ( control->testControlFlag( QskControl::PreferRasterForTextures ) )
|
||||||
mode = QskTextureRenderer::Raster;
|
mode = QskTextureRenderer::Raster;
|
||||||
|
|
||||||
if ( auto window = control->window() )
|
|
||||||
{
|
|
||||||
/*
|
/*
|
||||||
Aligning the rect according to scene coordinates, so that
|
Aligning the rect according to scene coordinates, so that
|
||||||
we don't run into rounding issues downstream, where values
|
we don't run into rounding issues downstream, where values
|
||||||
|
@ -100,12 +98,11 @@ static inline QSGNode* qskUpdateGraphicNode(
|
||||||
*/
|
*/
|
||||||
const QRectF sceneRect(
|
const QRectF sceneRect(
|
||||||
control->mapToScene( r.topLeft() ),
|
control->mapToScene( r.topLeft() ),
|
||||||
r.size() * window->effectiveDevicePixelRatio() );
|
r.size() * QskTextureRenderer::devicePixelRatio() );
|
||||||
|
|
||||||
r = qskInnerRect( sceneRect );
|
r = qskInnerRect( sceneRect );
|
||||||
r.moveTopLeft( control->mapFromScene( r.topLeft() ) );
|
r.moveTopLeft( control->mapFromScene( r.topLeft() ) );
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
graphicNode->setGraphic( graphic, colorFilter, mode, r );
|
graphicNode->setGraphic( graphic, colorFilter, mode, r );
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
#include "QskTextureNode.h"
|
#include "QskTextureNode.h"
|
||||||
|
#include "QskTextureRenderer.h"
|
||||||
|
|
||||||
#include <qopenglfunctions.h>
|
#include <qopenglfunctions.h>
|
||||||
#include <qsggeometry.h>
|
#include <qsggeometry.h>
|
||||||
|
@ -6,41 +7,6 @@
|
||||||
|
|
||||||
#include <private/qsgnode_p.h>
|
#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
|
namespace
|
||||||
{
|
{
|
||||||
class MaterialShader final : public QSGMaterialShader
|
class MaterialShader final : public QSGMaterialShader
|
||||||
|
@ -316,7 +282,8 @@ void QskTextureNode::updateTexture()
|
||||||
r.setBottom( 0 );
|
r.setBottom( 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
const qreal ratio = qskDevicePixelRatio();
|
const qreal ratio = QskTextureRenderer::devicePixelRatio();
|
||||||
|
|
||||||
const QRectF rect( d->rect.x(), d->rect.y(),
|
const QRectF rect( d->rect.x(), d->rect.y(),
|
||||||
d->rect.width() / ratio, d->rect.height() / ratio );
|
d->rect.width() / ratio, d->rect.height() / ratio );
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,11 @@
|
||||||
#include <qimage.h>
|
#include <qimage.h>
|
||||||
#include <qpainter.h>
|
#include <qpainter.h>
|
||||||
|
|
||||||
|
#include <qguiapplication.h>
|
||||||
|
#include <qquickwindow.h>
|
||||||
|
#include <qscreen.h>
|
||||||
|
#include <qsurface.h>
|
||||||
|
|
||||||
static uint qskCreateTextureOpenGL(
|
static uint qskCreateTextureOpenGL(
|
||||||
const QSize& size, QskTextureRenderer::PaintHelper* helper )
|
const QSize& size, QskTextureRenderer::PaintHelper* helper )
|
||||||
{
|
{
|
||||||
|
@ -173,3 +178,36 @@ uint QskTextureRenderer::createTextureFromGraphic(
|
||||||
PaintHelper helper( graphic, colorFilter, aspectRatioMode );
|
PaintHelper helper( graphic, colorFilter, aspectRatioMode );
|
||||||
return createTexture( renderMode, size, &helper );
|
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 QPainter;
|
||||||
class QSize;
|
class QSize;
|
||||||
|
class QOpenGLContext;
|
||||||
|
|
||||||
namespace QskTextureRenderer
|
namespace QskTextureRenderer
|
||||||
{
|
{
|
||||||
|
@ -46,6 +47,8 @@ namespace QskTextureRenderer
|
||||||
QSK_EXPORT uint createTextureFromGraphic(
|
QSK_EXPORT uint createTextureFromGraphic(
|
||||||
RenderMode, const QSize&, const QskGraphic&,
|
RenderMode, const QSize&, const QskGraphic&,
|
||||||
const QskColorFilter&, Qt::AspectRatioMode );
|
const QskColorFilter&, Qt::AspectRatioMode );
|
||||||
|
|
||||||
|
QSK_EXPORT qreal devicePixelRatio( const QOpenGLContext* = nullptr );
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue