qskinny/src/graphic/QskGraphicTextureFactory.cpp

52 lines
1.4 KiB
C++
Raw Normal View History

2017-07-21 16:21:34 +00:00
/******************************************************************************
* QSkinny - Copyright (C) 2016 Uwe Rathmann
* This file may be used under the terms of the QSkinny License, Version 1.0
*****************************************************************************/
#include "QskGraphicTextureFactory.h"
#include "QskTextureRenderer.h"
2017-07-21 16:21:34 +00:00
2018-07-19 12:10:48 +00:00
#include <qquickwindow.h>
2017-07-21 16:21:34 +00:00
QskGraphicTextureFactory::QskGraphicTextureFactory()
{
}
QskGraphicTextureFactory::QskGraphicTextureFactory(
2018-08-03 06:15:28 +00:00
const QskGraphic& graphic, const QSize& size )
: m_graphic( graphic )
, m_size( size )
2017-07-21 16:21:34 +00:00
{
}
QskGraphicTextureFactory::~QskGraphicTextureFactory()
{
}
QSGTexture* QskGraphicTextureFactory::createTexture( QQuickWindow* window ) const
{
const uint textureId = QskTextureRenderer::createTextureFromGraphic(
QskTextureRenderer::OpenGL, m_size, m_graphic, m_colorFilter,
Qt::IgnoreAspectRatio );
2017-07-21 16:21:34 +00:00
const auto flags = static_cast< QQuickWindow::CreateTextureOptions >(
QQuickWindow::TextureHasAlphaChannel | QQuickWindow::TextureOwnsGLTexture );
return window->createTextureFromId( textureId, m_size, flags );
}
QSize QskGraphicTextureFactory::textureSize() const
{
return m_size;
}
int QskGraphicTextureFactory::textureByteCount() const
{
return m_size.width() * m_size.height() * 4;
}
QImage QskGraphicTextureFactory::image() const
{
return m_graphic.toImage( m_size, Qt::KeepAspectRatio );
}