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"
|
2018-10-04 16:15:42 +02:00
|
|
|
#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
|
|
|
|
2022-03-25 10:28:06 +01:00
|
|
|
static inline QskHashValue qskHash(
|
2017-07-21 18:21:34 +02:00
|
|
|
const QskGraphic& graphic, const QskColorFilter& colorFilter,
|
2018-10-04 16:15:42 +02:00
|
|
|
QskTextureRenderer::RenderMode renderMode )
|
2017-07-21 18:21:34 +02:00
|
|
|
{
|
2022-03-25 10:28:06 +01:00
|
|
|
QskHashValue hash = 12000;
|
2017-07-21 18:21:34 +02:00
|
|
|
|
|
|
|
const auto& substitutions = colorFilter.substitutions();
|
|
|
|
if ( substitutions.size() > 0 )
|
|
|
|
{
|
2017-10-17 17:34:00 +02:00
|
|
|
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();
|
2018-01-03 15:44:40 +01:00
|
|
|
|
2019-10-16 10:08:05 +02:00
|
|
|
QSize textureSize;
|
|
|
|
|
2019-12-05 11:26:48 +01:00
|
|
|
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
|
2019-10-16 10:08:05 +02:00
|
|
|
{
|
|
|
|
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;
|
2018-01-03 15:44:40 +01:00
|
|
|
isTextureDirty = true;
|
2017-07-21 18:21:34 +02:00
|
|
|
}
|
|
|
|
|
2020-11-01 15:44:15 +01:00
|
|
|
auto textureId = QskTextureNode::textureId();
|
|
|
|
|
2018-01-03 15:44:40 +01:00
|
|
|
if ( isTextureDirty )
|
2017-07-21 18:21:34 +02:00
|
|
|
{
|
2020-11-01 15:44:15 +01:00
|
|
|
textureId = QskTextureRenderer::createTextureFromGraphic(
|
2021-12-13 16:43:34 +01:00
|
|
|
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
|
|
|
}
|