2022-04-23 08:59:50 +00:00
|
|
|
// SPDX-FileCopyrightText: Copyright 2019 yuzu Emulator Project
|
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2019-01-17 07:01:00 +00:00
|
|
|
|
2019-01-20 04:03:26 +00:00
|
|
|
#include <unordered_map>
|
2019-01-17 07:01:00 +00:00
|
|
|
#include <QBuffer>
|
|
|
|
#include <QByteArray>
|
2019-01-21 16:20:16 +00:00
|
|
|
#include <QGraphicsOpacityEffect>
|
2019-01-17 07:01:00 +00:00
|
|
|
#include <QIODevice>
|
|
|
|
#include <QImage>
|
|
|
|
#include <QPainter>
|
|
|
|
#include <QPixmap>
|
2019-01-21 16:20:16 +00:00
|
|
|
#include <QPropertyAnimation>
|
2019-01-17 07:01:00 +00:00
|
|
|
#include <QStyleOption>
|
2020-05-15 20:22:27 +00:00
|
|
|
#include "core/frontend/framebuffer_layout.h"
|
2019-01-17 07:01:00 +00:00
|
|
|
#include "core/loader/loader.h"
|
|
|
|
#include "ui_loading_screen.h"
|
2019-01-20 04:03:26 +00:00
|
|
|
#include "video_core/rasterizer_interface.h"
|
2019-01-17 07:01:00 +00:00
|
|
|
#include "yuzu/loading_screen.h"
|
|
|
|
|
2019-01-18 17:02:27 +00:00
|
|
|
// Mingw seems to not have QMovie at all. If QMovie is missing then use a single frame instead of an
|
|
|
|
// showing the full animation
|
|
|
|
#if !YUZU_QT_MOVIE_MISSING
|
|
|
|
#include <QMovie>
|
|
|
|
#endif
|
|
|
|
|
2019-05-20 18:53:40 +00:00
|
|
|
constexpr char PROGRESSBAR_STYLE_PREPARE[] = R"(
|
2019-01-20 22:09:14 +00:00
|
|
|
QProgressBar {}
|
2019-01-21 01:20:21 +00:00
|
|
|
QProgressBar::chunk {})";
|
|
|
|
|
2019-05-20 18:53:40 +00:00
|
|
|
constexpr char PROGRESSBAR_STYLE_BUILD[] = R"(
|
2019-01-20 04:03:26 +00:00
|
|
|
QProgressBar {
|
|
|
|
background-color: black;
|
|
|
|
border: 2px solid white;
|
|
|
|
border-radius: 4px;
|
|
|
|
padding: 2px;
|
|
|
|
}
|
|
|
|
QProgressBar::chunk {
|
2019-01-21 19:38:37 +00:00
|
|
|
background-color: #ff3c28;
|
|
|
|
width: 1px;
|
2019-01-21 01:20:21 +00:00
|
|
|
})";
|
|
|
|
|
2019-05-20 18:53:40 +00:00
|
|
|
constexpr char PROGRESSBAR_STYLE_COMPLETE[] = R"(
|
2019-01-20 04:03:26 +00:00
|
|
|
QProgressBar {
|
2019-01-21 02:14:14 +00:00
|
|
|
background-color: #0ab9e6;
|
2019-01-20 04:03:26 +00:00
|
|
|
border: 2px solid white;
|
|
|
|
border-radius: 4px;
|
|
|
|
padding: 2px;
|
|
|
|
}
|
|
|
|
QProgressBar::chunk {
|
|
|
|
background-color: #ff3c28;
|
2019-01-21 01:20:21 +00:00
|
|
|
})";
|
|
|
|
|
|
|
|
LoadingScreen::LoadingScreen(QWidget* parent)
|
|
|
|
: QWidget(parent), ui(std::make_unique<Ui::LoadingScreen>()),
|
|
|
|
previous_stage(VideoCore::LoadCallbackStage::Complete) {
|
|
|
|
ui->setupUi(this);
|
2020-05-15 20:22:27 +00:00
|
|
|
setMinimumSize(Layout::MinimumSize::Width, Layout::MinimumSize::Height);
|
2019-01-21 01:20:21 +00:00
|
|
|
|
2019-01-21 16:20:16 +00:00
|
|
|
// Create a fade out effect to hide this loading screen widget.
|
|
|
|
// When fading opacity, it will fade to the parent widgets background color, which is why we
|
|
|
|
// create an internal widget named fade_widget that we use the effect on, while keeping the
|
|
|
|
// loading screen widget's background color black. This way we can create a fade to black effect
|
|
|
|
opacity_effect = new QGraphicsOpacityEffect(this);
|
|
|
|
opacity_effect->setOpacity(1);
|
|
|
|
ui->fade_parent->setGraphicsEffect(opacity_effect);
|
|
|
|
fadeout_animation = std::make_unique<QPropertyAnimation>(opacity_effect, "opacity");
|
|
|
|
fadeout_animation->setDuration(500);
|
|
|
|
fadeout_animation->setStartValue(1);
|
|
|
|
fadeout_animation->setEndValue(0);
|
|
|
|
fadeout_animation->setEasingCurve(QEasingCurve::OutBack);
|
|
|
|
|
|
|
|
// After the fade completes, hide the widget and reset the opacity
|
|
|
|
connect(fadeout_animation.get(), &QPropertyAnimation::finished, [this] {
|
|
|
|
hide();
|
|
|
|
opacity_effect->setOpacity(1);
|
|
|
|
emit Hidden();
|
|
|
|
});
|
2019-01-21 01:20:21 +00:00
|
|
|
connect(this, &LoadingScreen::LoadProgress, this, &LoadingScreen::OnLoadProgress,
|
|
|
|
Qt::QueuedConnection);
|
|
|
|
qRegisterMetaType<VideoCore::LoadCallbackStage>();
|
|
|
|
|
|
|
|
stage_translations = {
|
|
|
|
{VideoCore::LoadCallbackStage::Prepare, tr("Loading...")},
|
2019-01-21 01:40:25 +00:00
|
|
|
{VideoCore::LoadCallbackStage::Build, tr("Loading Shaders %1 / %2")},
|
2019-01-21 01:20:21 +00:00
|
|
|
{VideoCore::LoadCallbackStage::Complete, tr("Launching...")},
|
|
|
|
};
|
|
|
|
progressbar_style = {
|
|
|
|
{VideoCore::LoadCallbackStage::Prepare, PROGRESSBAR_STYLE_PREPARE},
|
2019-01-21 01:40:25 +00:00
|
|
|
{VideoCore::LoadCallbackStage::Build, PROGRESSBAR_STYLE_BUILD},
|
2019-01-21 01:20:21 +00:00
|
|
|
{VideoCore::LoadCallbackStage::Complete, PROGRESSBAR_STYLE_COMPLETE},
|
2019-01-20 04:03:26 +00:00
|
|
|
};
|
2019-01-17 07:01:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
LoadingScreen::~LoadingScreen() = default;
|
|
|
|
|
|
|
|
void LoadingScreen::Prepare(Loader::AppLoader& loader) {
|
|
|
|
std::vector<u8> buffer;
|
|
|
|
if (loader.ReadBanner(buffer) == Loader::ResultStatus::Success) {
|
2019-01-18 17:02:27 +00:00
|
|
|
#ifdef YUZU_QT_MOVIE_MISSING
|
|
|
|
QPixmap map;
|
|
|
|
map.loadFromData(buffer.data(), buffer.size());
|
|
|
|
ui->banner->setPixmap(map);
|
|
|
|
#else
|
2019-01-21 16:39:45 +00:00
|
|
|
backing_mem = std::make_unique<QByteArray>(reinterpret_cast<char*>(buffer.data()),
|
|
|
|
static_cast<int>(buffer.size()));
|
2019-01-17 07:01:00 +00:00
|
|
|
backing_buf = std::make_unique<QBuffer>(backing_mem.get());
|
|
|
|
backing_buf->open(QIODevice::ReadOnly);
|
2019-01-20 04:03:26 +00:00
|
|
|
animation = std::make_unique<QMovie>(backing_buf.get(), QByteArray());
|
2019-01-17 07:01:00 +00:00
|
|
|
animation->start();
|
|
|
|
ui->banner->setMovie(animation.get());
|
2019-01-18 17:02:27 +00:00
|
|
|
#endif
|
2019-01-17 07:01:00 +00:00
|
|
|
buffer.clear();
|
|
|
|
}
|
|
|
|
if (loader.ReadLogo(buffer) == Loader::ResultStatus::Success) {
|
|
|
|
QPixmap map;
|
2019-01-21 16:39:45 +00:00
|
|
|
map.loadFromData(buffer.data(), static_cast<uint>(buffer.size()));
|
2019-01-17 07:01:00 +00:00
|
|
|
ui->logo->setPixmap(map);
|
|
|
|
}
|
2019-01-20 04:03:26 +00:00
|
|
|
|
2019-01-21 16:20:16 +00:00
|
|
|
slow_shader_compile_start = false;
|
2019-01-20 22:09:14 +00:00
|
|
|
OnLoadProgress(VideoCore::LoadCallbackStage::Prepare, 0, 0);
|
2019-01-17 07:01:00 +00:00
|
|
|
}
|
|
|
|
|
2019-01-21 16:20:16 +00:00
|
|
|
void LoadingScreen::OnLoadComplete() {
|
|
|
|
fadeout_animation->start(QPropertyAnimation::KeepWhenStopped);
|
|
|
|
}
|
|
|
|
|
2019-01-20 04:03:26 +00:00
|
|
|
void LoadingScreen::OnLoadProgress(VideoCore::LoadCallbackStage stage, std::size_t value,
|
|
|
|
std::size_t total) {
|
|
|
|
using namespace std::chrono;
|
2021-12-02 19:20:43 +00:00
|
|
|
const auto now = steady_clock::now();
|
2019-01-20 04:03:26 +00:00
|
|
|
// reset the timer if the stage changes
|
|
|
|
if (stage != previous_stage) {
|
2019-05-20 18:53:40 +00:00
|
|
|
ui->progress_bar->setStyleSheet(QString::fromUtf8(progressbar_style[stage]));
|
2019-01-21 16:20:16 +00:00
|
|
|
// Hide the progress bar during the prepare stage
|
2019-01-20 22:09:14 +00:00
|
|
|
if (stage == VideoCore::LoadCallbackStage::Prepare) {
|
|
|
|
ui->progress_bar->hide();
|
|
|
|
} else {
|
|
|
|
ui->progress_bar->show();
|
|
|
|
}
|
2019-01-20 04:03:26 +00:00
|
|
|
previous_stage = stage;
|
|
|
|
// reset back to fast shader compiling since the stage changed
|
|
|
|
slow_shader_compile_start = false;
|
|
|
|
}
|
|
|
|
// update the max of the progress bar if the number of shaders change
|
2019-01-17 07:01:00 +00:00
|
|
|
if (total != previous_total) {
|
2019-01-21 16:39:45 +00:00
|
|
|
ui->progress_bar->setMaximum(static_cast<int>(total));
|
2019-01-17 07:01:00 +00:00
|
|
|
previous_total = total;
|
|
|
|
}
|
2019-01-20 04:03:26 +00:00
|
|
|
|
|
|
|
QString estimate;
|
|
|
|
// If theres a drastic slowdown in the rate, then display an estimate
|
2019-01-21 01:22:29 +00:00
|
|
|
if (now - previous_time > milliseconds{50} || slow_shader_compile_start) {
|
2019-01-20 04:03:26 +00:00
|
|
|
if (!slow_shader_compile_start) {
|
2021-12-02 19:20:43 +00:00
|
|
|
slow_shader_start = steady_clock::now();
|
2019-01-20 04:03:26 +00:00
|
|
|
slow_shader_compile_start = true;
|
|
|
|
slow_shader_first_value = value;
|
|
|
|
}
|
|
|
|
// only calculate an estimate time after a second has passed since stage change
|
2019-05-20 18:53:40 +00:00
|
|
|
const auto diff = duration_cast<milliseconds>(now - slow_shader_start);
|
2019-01-20 04:03:26 +00:00
|
|
|
if (diff > seconds{1}) {
|
2019-05-20 18:53:40 +00:00
|
|
|
const auto eta_mseconds =
|
2019-01-20 04:03:26 +00:00
|
|
|
static_cast<long>(static_cast<double>(total - slow_shader_first_value) /
|
|
|
|
(value - slow_shader_first_value) * diff.count());
|
|
|
|
estimate =
|
|
|
|
tr("Estimated Time %1")
|
|
|
|
.arg(QTime(0, 0, 0, 0)
|
|
|
|
.addMSecs(std::max<long>(eta_mseconds - diff.count() + 1000, 1000))
|
2019-05-20 18:53:40 +00:00
|
|
|
.toString(QStringLiteral("mm:ss")));
|
2019-01-20 04:03:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// update labels and progress bar
|
2020-02-29 07:38:20 +00:00
|
|
|
if (stage == VideoCore::LoadCallbackStage::Build) {
|
2019-04-09 14:44:29 +00:00
|
|
|
ui->stage->setText(stage_translations[stage].arg(value).arg(total));
|
|
|
|
} else {
|
|
|
|
ui->stage->setText(stage_translations[stage]);
|
|
|
|
}
|
2019-01-20 04:03:26 +00:00
|
|
|
ui->value->setText(estimate);
|
2019-01-21 16:39:45 +00:00
|
|
|
ui->progress_bar->setValue(static_cast<int>(value));
|
2019-01-20 04:03:26 +00:00
|
|
|
previous_time = now;
|
2019-01-17 07:01:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void LoadingScreen::paintEvent(QPaintEvent* event) {
|
|
|
|
QStyleOption opt;
|
|
|
|
opt.init(this);
|
|
|
|
QPainter p(this);
|
|
|
|
style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this);
|
|
|
|
QWidget::paintEvent(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
void LoadingScreen::Clear() {
|
2019-01-18 17:02:27 +00:00
|
|
|
#ifndef YUZU_QT_MOVIE_MISSING
|
2019-01-17 07:01:00 +00:00
|
|
|
animation.reset();
|
|
|
|
backing_buf.reset();
|
|
|
|
backing_mem.reset();
|
2019-01-18 17:02:27 +00:00
|
|
|
#endif
|
2019-01-17 07:01:00 +00:00
|
|
|
}
|