qskinny/src/nodes/QskGraphicNode.cpp

78 lines
2.1 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"
2017-07-21 18:21:34 +02:00
static inline uint qskHash(
const QskGraphic& graphic, const QskColorFilter& colorFilter,
QskTextureRenderer::RenderMode renderMode )
2017-07-21 18:21:34 +02:00
{
uint hash = 0;
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
}
const auto& commands = graphic.commands();
if ( commands.size() > 0 )
{
hash = qHash( commands.constData(), hash );
}
hash = qHash( graphic.renderHints(), hash );
const QSizeF sz = graphic.defaultSize();
hash = qHashBits( &sz, sizeof( sz ), hash );
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(
const QskGraphic& graphic, const QskColorFilter& colorFilter,
QskTextureRenderer::RenderMode renderMode, const QRect& rect )
2017-07-21 18:21:34 +02:00
{
bool isTextureDirty = ( QskTextureNode::textureId() == 0 );
if ( !isTextureDirty )
{
const auto oldRect = QskTextureNode::rect();
2018-08-03 08:15:28 +02:00
isTextureDirty = ( rect.width() != static_cast< int >( oldRect.width() ) ) ||
2019-01-04 13:42:16 +01:00
( rect.height() != static_cast< int >( oldRect.height() ) );
}
2017-07-21 18:21:34 +02:00
QskTextureNode::setRect( rect );
const uint hash = qskHash( graphic, colorFilter, renderMode );
if ( hash != m_hash )
{
m_hash = hash;
isTextureDirty = true;
2017-07-21 18:21:34 +02:00
}
if ( isTextureDirty )
2017-07-21 18:21:34 +02:00
{
const uint textureId = QskTextureRenderer::createTextureFromGraphic(
renderMode, rect.size(), graphic, colorFilter, Qt::IgnoreAspectRatio );
2017-07-21 18:21:34 +02:00
QskTextureNode::setTextureId( textureId );
}
}