qskinny/src/nodes/QskGraphicNode.cpp

86 lines
2.4 KiB
C++
Raw Normal View History

2018-08-03 08:15:28 +02:00
/******************************************************************************
* QSkinny - Copyright (C) 2016 Uwe Rathmann
* This file may be used under the terms of the QSkinny License, Version 1.0
*****************************************************************************/
2017-07-21 18:21:34 +02:00
#include "QskGraphicNode.h"
#include "QskGraphic.h"
#include "QskColorFilter.h"
2020-10-20 17:46:22 +02:00
#include "QskPainterCommand.h"
2017-07-21 18:21:34 +02:00
static inline QskHashValue qskHash(
2017-07-21 18:21:34 +02:00
const QskGraphic& graphic, const QskColorFilter& colorFilter,
QskTextureRenderer::RenderMode renderMode )
2017-07-21 18:21:34 +02:00
{
QskHashValue hash = 12000;
2017-07-21 18:21:34 +02:00
const auto& substitutions = colorFilter.substitutions();
if ( substitutions.size() > 0 )
{
hash = qHashBits( substitutions.constData(),
2018-08-03 08:15:28 +02:00
substitutions.size() * sizeof( substitutions[ 0 ] ), hash );
2017-07-21 18:21:34 +02:00
}
2021-02-05 13:21:35 +01:00
hash = graphic.hash( hash );
2017-07-21 18:21:34 +02:00
hash = qHash( renderMode, hash );
return hash;
}
2018-08-03 08:15:28 +02:00
QskGraphicNode::QskGraphicNode()
: m_hash( 0 )
2017-07-21 18:21:34 +02:00
{
}
QskGraphicNode::~QskGraphicNode()
{
}
void QskGraphicNode::setGraphic(
2020-11-01 15:44:15 +01:00
QQuickWindow* window, const QskGraphic& graphic, const QskColorFilter& colorFilter,
QskTextureRenderer::RenderMode renderMode, const QRectF& rect,
Qt::Orientations mirrored )
2017-07-21 18:21:34 +02:00
{
2020-10-26 18:06:06 +01:00
bool isTextureDirty = isNull();
QSize textureSize;
if ( graphic.commandTypes() == QskGraphic::RasterData )
{
/*
simple raster data - usually a QImage/QPixmap only.
There is no benefit in rescaling it into the target rectangle
by the CPU and creating a new texture.
*/
textureSize = graphic.defaultSize().toSize();
}
else
{
textureSize = rect.size().toSize();
if ( !isTextureDirty )
{
const auto oldRect = QskTextureNode::rect();
isTextureDirty = ( rect.width() != static_cast< int >( oldRect.width() ) ) ||
( rect.height() != static_cast< int >( oldRect.height() ) );
}
}
2017-07-21 18:21:34 +02:00
2020-11-01 15:44:15 +01:00
const auto hash = qskHash( graphic, colorFilter, renderMode );
2017-07-21 18:21:34 +02:00
if ( hash != m_hash )
{
m_hash = hash;
isTextureDirty = true;
2017-07-21 18:21:34 +02:00
}
2020-11-01 15:44:15 +01:00
auto textureId = QskTextureNode::textureId();
if ( isTextureDirty )
2017-07-21 18:21:34 +02:00
{
2020-11-01 15:44:15 +01:00
textureId = QskTextureRenderer::createTextureFromGraphic(
window, renderMode, textureSize, graphic, colorFilter, Qt::IgnoreAspectRatio );
2017-07-21 18:21:34 +02:00
}
2020-11-01 15:44:15 +01:00
QskTextureNode::setTexture( window, rect, textureId, mirrored );
2017-07-21 18:21:34 +02:00
}