2020-08-03 13:27:42 -04:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2019-2020 by Savoir-faire Linux
|
|
|
|
* Author: Andreas Traczyk <andreas.traczyk@savoirfairelinux.com>
|
|
|
|
* Author: Mingrui Zhang <mingrui.zhang@savoirfairelinux.com>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "distantrenderer.h"
|
|
|
|
|
|
|
|
#include "lrcinstance.h"
|
|
|
|
|
2020-09-10 17:40:51 -04:00
|
|
|
DistantRenderer::DistantRenderer(QQuickItem* parent)
|
2020-08-03 13:27:42 -04:00
|
|
|
: QQuickPaintedItem(parent)
|
|
|
|
{
|
|
|
|
setAntialiasing(true);
|
|
|
|
setFillColor(Qt::black);
|
|
|
|
setRenderTarget(QQuickPaintedItem::FramebufferObject);
|
|
|
|
setPerformanceHint(QQuickPaintedItem::FastFBOResizing);
|
|
|
|
|
2021-03-11 13:30:45 -05:00
|
|
|
connect(this, &DistantRenderer::lrcInstanceChanged, [this] {
|
2021-04-01 17:05:40 -04:00
|
|
|
if (lrcInstance_) {
|
2021-03-11 13:30:45 -05:00
|
|
|
connect(lrcInstance_->renderer(),
|
|
|
|
&RenderManager::distantFrameUpdated,
|
|
|
|
[this](const QString& id) {
|
|
|
|
if (distantRenderId_ == id)
|
|
|
|
update(QRect(0, 0, width(), height()));
|
|
|
|
});
|
2021-04-01 17:05:40 -04:00
|
|
|
|
|
|
|
connect(lrcInstance_->renderer(),
|
|
|
|
&RenderManager::distantRenderingStopped,
|
|
|
|
[this](const QString& id) {
|
|
|
|
if (distantRenderId_ == id)
|
|
|
|
update(QRect(0, 0, width(), height()));
|
|
|
|
});
|
|
|
|
}
|
2020-08-03 13:27:42 -04:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
DistantRenderer::~DistantRenderer() {}
|
|
|
|
|
|
|
|
void
|
2020-09-10 17:40:51 -04:00
|
|
|
DistantRenderer::setRendererId(const QString& id)
|
2020-08-03 13:27:42 -04:00
|
|
|
{
|
|
|
|
distantRenderId_ = id;
|
2021-04-01 17:05:40 -04:00
|
|
|
// Note: Force a paint to update frame as we change the renderer
|
|
|
|
update(QRect(0, 0, width(), height()));
|
2020-08-03 13:27:42 -04:00
|
|
|
}
|
|
|
|
|
2021-05-14 13:02:45 -04:00
|
|
|
QString
|
|
|
|
DistantRenderer::rendererId()
|
|
|
|
{
|
|
|
|
return distantRenderId_;
|
|
|
|
}
|
|
|
|
|
2020-07-24 15:15:47 -04:00
|
|
|
int
|
|
|
|
DistantRenderer::getXOffset() const
|
|
|
|
{
|
|
|
|
return xOffset_;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
DistantRenderer::getYOffset() const
|
|
|
|
{
|
|
|
|
return yOffset_;
|
|
|
|
}
|
|
|
|
|
|
|
|
double
|
|
|
|
DistantRenderer::getScaledWidth() const
|
|
|
|
{
|
|
|
|
return scaledWidth_;
|
|
|
|
}
|
|
|
|
|
|
|
|
double
|
|
|
|
DistantRenderer::getScaledHeight() const
|
|
|
|
{
|
|
|
|
return scaledHeight_;
|
|
|
|
}
|
|
|
|
|
2020-08-03 13:27:42 -04:00
|
|
|
void
|
2020-09-10 17:40:51 -04:00
|
|
|
DistantRenderer::paint(QPainter* painter)
|
2020-08-03 13:27:42 -04:00
|
|
|
{
|
2021-03-11 13:30:45 -05:00
|
|
|
lrcInstance_->renderer()->drawFrame(distantRenderId_, [this, painter](QImage* distantImage) {
|
2020-11-26 15:05:01 +01:00
|
|
|
if (distantImage) {
|
2021-04-29 11:23:18 -04:00
|
|
|
painter->setRenderHint(QPainter::Antialiasing);
|
|
|
|
painter->setRenderHint(QPainter::SmoothPixmapTransform);
|
|
|
|
|
|
|
|
auto scaledDistant = distantImage->scaled(size().toSize(),
|
|
|
|
Qt::KeepAspectRatio,
|
|
|
|
Qt::SmoothTransformation);
|
2020-11-26 15:05:01 +01:00
|
|
|
auto tempScaledWidth = static_cast<int>(scaledWidth_ * 1000);
|
|
|
|
auto tempScaledHeight = static_cast<int>(scaledHeight_ * 1000);
|
|
|
|
auto tempXOffset = xOffset_;
|
|
|
|
auto tempYOffset = yOffset_;
|
|
|
|
scaledWidth_ = static_cast<double>(scaledDistant.width())
|
|
|
|
/ static_cast<double>(distantImage->width());
|
|
|
|
scaledHeight_ = static_cast<double>(scaledDistant.height())
|
|
|
|
/ static_cast<double>(distantImage->height());
|
|
|
|
xOffset_ = (width() - scaledDistant.width()) / 2;
|
|
|
|
yOffset_ = (height() - scaledDistant.height()) / 2;
|
|
|
|
if (tempXOffset != xOffset_ or tempYOffset != yOffset_
|
|
|
|
or static_cast<int>(scaledWidth_ * 1000) != tempScaledWidth
|
|
|
|
or static_cast<int>(scaledHeight_ * 1000) != tempScaledHeight) {
|
2021-03-29 16:51:53 -04:00
|
|
|
Q_EMIT offsetChanged();
|
2020-11-26 15:05:01 +01:00
|
|
|
}
|
|
|
|
painter->drawImage(QRect(xOffset_,
|
|
|
|
yOffset_,
|
|
|
|
scaledDistant.width(),
|
|
|
|
scaledDistant.height()),
|
|
|
|
scaledDistant);
|
2020-07-24 15:15:47 -04:00
|
|
|
}
|
2020-11-26 15:05:01 +01:00
|
|
|
});
|
2020-11-03 17:28:25 -05:00
|
|
|
}
|