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"
|
2018-10-04 14:15:42 +00:00
|
|
|
#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
|
|
|
|
{
|
2018-10-04 14:15:42 +00:00
|
|
|
const uint textureId = QskTextureRenderer::createTextureFromGraphic(
|
|
|
|
QskTextureRenderer::OpenGL, m_size, m_graphic, m_colorFilter );
|
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 );
|
|
|
|
}
|