2019-01-17 02:01:00 -05:00
|
|
|
// Copyright 2019 yuzu Emulator Project
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
2019-01-19 23:03:26 -05:00
|
|
|
#include <unordered_map>
|
2019-01-17 02:01:00 -05:00
|
|
|
#include <QBuffer>
|
|
|
|
#include <QByteArray>
|
|
|
|
#include <QHBoxLayout>
|
|
|
|
#include <QIODevice>
|
|
|
|
#include <QImage>
|
|
|
|
#include <QLabel>
|
|
|
|
#include <QPainter>
|
|
|
|
#include <QPalette>
|
|
|
|
#include <QPixmap>
|
|
|
|
#include <QProgressBar>
|
|
|
|
#include <QStyleOption>
|
2019-01-19 23:03:26 -05:00
|
|
|
#include <QTime>
|
|
|
|
#include <QtConcurrent/QtConcurrentRun>
|
2019-01-17 02:01:00 -05:00
|
|
|
#include "common/logging/log.h"
|
|
|
|
#include "core/loader/loader.h"
|
|
|
|
#include "ui_loading_screen.h"
|
2019-01-19 23:03:26 -05:00
|
|
|
#include "video_core/rasterizer_interface.h"
|
2019-01-17 02:01:00 -05:00
|
|
|
#include "yuzu/loading_screen.h"
|
|
|
|
|
2019-01-18 12:02:27 -05: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-01-17 02:01:00 -05:00
|
|
|
LoadingScreen::LoadingScreen(QWidget* parent)
|
2019-01-19 23:03:26 -05:00
|
|
|
: QWidget(parent), ui(std::make_unique<Ui::LoadingScreen>()),
|
|
|
|
previous_stage(VideoCore::LoadCallbackStage::Complete) {
|
2019-01-17 02:01:00 -05:00
|
|
|
ui->setupUi(this);
|
2019-01-19 23:03:26 -05:00
|
|
|
|
|
|
|
connect(this, &LoadingScreen::LoadProgress, this, &LoadingScreen::OnLoadProgress,
|
|
|
|
Qt::QueuedConnection);
|
|
|
|
qRegisterMetaType<VideoCore::LoadCallbackStage>();
|
|
|
|
|
|
|
|
stage_translations = {
|
|
|
|
{VideoCore::LoadCallbackStage::Prepare, tr("Loading...")},
|
|
|
|
{VideoCore::LoadCallbackStage::Raw, tr("Preparing Shaders %1 / %2")},
|
|
|
|
{VideoCore::LoadCallbackStage::Binary, tr("Loading Shaders %1 / %2")},
|
|
|
|
{VideoCore::LoadCallbackStage::Complete, tr("Launching...")},
|
|
|
|
};
|
|
|
|
progressbar_style = {
|
|
|
|
{VideoCore::LoadCallbackStage::Prepare,
|
|
|
|
R"(
|
2019-01-20 17:09:14 -05:00
|
|
|
QProgressBar {}
|
|
|
|
QProgressBar::chunk {})"},
|
2019-01-19 23:03:26 -05:00
|
|
|
{VideoCore::LoadCallbackStage::Raw,
|
|
|
|
R"(
|
|
|
|
QProgressBar {
|
|
|
|
background-color: black;
|
|
|
|
border: 2px solid white;
|
|
|
|
border-radius: 4px;
|
|
|
|
padding: 2px;
|
|
|
|
}
|
|
|
|
QProgressBar::chunk {
|
|
|
|
background-color: #0ab9e6;
|
|
|
|
})"},
|
|
|
|
{VideoCore::LoadCallbackStage::Binary,
|
|
|
|
R"(
|
|
|
|
QProgressBar {
|
|
|
|
background-color: black;
|
|
|
|
border: 2px solid white;
|
|
|
|
border-radius: 4px;
|
|
|
|
padding: 2px;
|
|
|
|
}
|
|
|
|
QProgressBar::chunk {
|
|
|
|
background-color: #ff3c28;
|
|
|
|
})"},
|
|
|
|
{VideoCore::LoadCallbackStage::Complete,
|
|
|
|
R"(
|
|
|
|
QProgressBar {
|
|
|
|
background-color: black;
|
|
|
|
border: 2px solid white;
|
|
|
|
border-radius: 4px;
|
|
|
|
padding: 2px;
|
|
|
|
}
|
|
|
|
QProgressBar::chunk {
|
|
|
|
background-color: #ff3c28;
|
|
|
|
})"},
|
|
|
|
};
|
2019-01-17 02:01:00 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
LoadingScreen::~LoadingScreen() = default;
|
|
|
|
|
|
|
|
void LoadingScreen::Prepare(Loader::AppLoader& loader) {
|
|
|
|
std::vector<u8> buffer;
|
|
|
|
if (loader.ReadBanner(buffer) == Loader::ResultStatus::Success) {
|
2019-01-18 12:02:27 -05:00
|
|
|
#ifdef YUZU_QT_MOVIE_MISSING
|
|
|
|
QPixmap map;
|
|
|
|
map.loadFromData(buffer.data(), buffer.size());
|
|
|
|
ui->banner->setPixmap(map);
|
|
|
|
#else
|
2019-01-17 02:01:00 -05:00
|
|
|
backing_mem =
|
|
|
|
std::make_unique<QByteArray>(reinterpret_cast<char*>(buffer.data()), buffer.size());
|
|
|
|
backing_buf = std::make_unique<QBuffer>(backing_mem.get());
|
|
|
|
backing_buf->open(QIODevice::ReadOnly);
|
2019-01-19 23:03:26 -05:00
|
|
|
animation = std::make_unique<QMovie>(backing_buf.get(), QByteArray());
|
2019-01-17 02:01:00 -05:00
|
|
|
animation->start();
|
|
|
|
ui->banner->setMovie(animation.get());
|
2019-01-18 12:02:27 -05:00
|
|
|
#endif
|
2019-01-17 02:01:00 -05:00
|
|
|
buffer.clear();
|
|
|
|
}
|
|
|
|
if (loader.ReadLogo(buffer) == Loader::ResultStatus::Success) {
|
|
|
|
QPixmap map;
|
|
|
|
map.loadFromData(buffer.data(), buffer.size());
|
|
|
|
ui->logo->setPixmap(map);
|
|
|
|
}
|
2019-01-19 23:03:26 -05:00
|
|
|
|
2019-01-20 17:09:14 -05:00
|
|
|
OnLoadProgress(VideoCore::LoadCallbackStage::Prepare, 0, 0);
|
2019-01-17 02:01:00 -05:00
|
|
|
}
|
|
|
|
|
2019-01-19 23:03:26 -05:00
|
|
|
void LoadingScreen::OnLoadProgress(VideoCore::LoadCallbackStage stage, std::size_t value,
|
|
|
|
std::size_t total) {
|
|
|
|
using namespace std::chrono;
|
|
|
|
auto now = high_resolution_clock::now();
|
|
|
|
// reset the timer if the stage changes
|
|
|
|
if (stage != previous_stage) {
|
|
|
|
ui->progress_bar->setStyleSheet(progressbar_style[stage]);
|
2019-01-20 17:09:14 -05:00
|
|
|
if (stage == VideoCore::LoadCallbackStage::Prepare) {
|
|
|
|
ui->progress_bar->hide();
|
|
|
|
} else {
|
|
|
|
ui->progress_bar->show();
|
|
|
|
}
|
2019-01-19 23:03:26 -05: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 02:01:00 -05:00
|
|
|
if (total != previous_total) {
|
|
|
|
ui->progress_bar->setMaximum(total);
|
|
|
|
previous_total = total;
|
|
|
|
}
|
2019-01-19 23:03:26 -05:00
|
|
|
|
|
|
|
QString estimate;
|
|
|
|
// If theres a drastic slowdown in the rate, then display an estimate
|
|
|
|
if (now - previous_time > milliseconds{20}) {
|
|
|
|
if (!slow_shader_compile_start) {
|
|
|
|
slow_shader_start = high_resolution_clock::now();
|
|
|
|
slow_shader_compile_start = true;
|
|
|
|
slow_shader_first_value = value;
|
|
|
|
}
|
|
|
|
// only calculate an estimate time after a second has passed since stage change
|
|
|
|
auto diff = duration_cast<milliseconds>(now - slow_shader_start);
|
|
|
|
if (diff > seconds{1}) {
|
|
|
|
auto eta_mseconds =
|
|
|
|
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))
|
|
|
|
.toString("mm:ss"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// update labels and progress bar
|
|
|
|
ui->stage->setText(stage_translations[stage].arg(value).arg(total));
|
|
|
|
ui->value->setText(estimate);
|
2019-01-17 02:01:00 -05:00
|
|
|
ui->progress_bar->setValue(value);
|
2019-01-19 23:03:26 -05:00
|
|
|
previous_time = now;
|
2019-01-17 02:01:00 -05: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 12:02:27 -05:00
|
|
|
#ifndef YUZU_QT_MOVIE_MISSING
|
2019-01-17 02:01:00 -05:00
|
|
|
animation.reset();
|
|
|
|
backing_buf.reset();
|
|
|
|
backing_mem.reset();
|
2019-01-18 12:02:27 -05:00
|
|
|
#endif
|
2019-01-17 02:01:00 -05:00
|
|
|
}
|