loading_screen.h 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. // SPDX-FileCopyrightText: Copyright 2019 yuzu Emulator Project
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. #pragma once
  4. #include <chrono>
  5. #include <memory>
  6. #include <QString>
  7. #include <QWidget>
  8. #include <QtGlobal>
  9. #if !QT_CONFIG(movie)
  10. #define YUZU_QT_MOVIE_MISSING 1
  11. #endif
  12. namespace Loader {
  13. class AppLoader;
  14. }
  15. namespace Ui {
  16. class LoadingScreen;
  17. }
  18. namespace VideoCore {
  19. enum class LoadCallbackStage;
  20. }
  21. class QBuffer;
  22. class QByteArray;
  23. class QGraphicsOpacityEffect;
  24. class QMovie;
  25. class QPropertyAnimation;
  26. class LoadingScreen : public QWidget {
  27. Q_OBJECT
  28. public:
  29. explicit LoadingScreen(QWidget* parent = nullptr);
  30. ~LoadingScreen();
  31. /// Call before showing the loading screen to load the widgets with the logo and banner for the
  32. /// currently loaded application.
  33. void Prepare(Loader::AppLoader& loader);
  34. /// After the loading screen is hidden, the owner of this class can call this to clean up any
  35. /// used resources such as the logo and banner.
  36. void Clear();
  37. /// Slot used to update the status of the progress bar
  38. void OnLoadProgress(VideoCore::LoadCallbackStage stage, std::size_t value, std::size_t total);
  39. /// Hides the LoadingScreen with a fade out effect
  40. void OnLoadComplete();
  41. // In order to use a custom widget with a stylesheet, you need to override the paintEvent
  42. // See https://wiki.qt.io/How_to_Change_the_Background_Color_of_QWidget
  43. void paintEvent(QPaintEvent* event) override;
  44. signals:
  45. void LoadProgress(VideoCore::LoadCallbackStage stage, std::size_t value, std::size_t total);
  46. /// Signals that this widget is completely hidden now and should be replaced with the other
  47. /// widget
  48. void Hidden();
  49. private:
  50. #ifndef YUZU_QT_MOVIE_MISSING
  51. std::unique_ptr<QMovie> animation;
  52. std::unique_ptr<QBuffer> backing_buf;
  53. std::unique_ptr<QByteArray> backing_mem;
  54. #endif
  55. std::unique_ptr<Ui::LoadingScreen> ui;
  56. std::size_t previous_total = 0;
  57. VideoCore::LoadCallbackStage previous_stage;
  58. QGraphicsOpacityEffect* opacity_effect = nullptr;
  59. std::unique_ptr<QPropertyAnimation> fadeout_animation;
  60. // Definitions for the differences in text and styling for each stage
  61. std::unordered_map<VideoCore::LoadCallbackStage, const char*> progressbar_style;
  62. std::unordered_map<VideoCore::LoadCallbackStage, QString> stage_translations;
  63. // newly generated shaders are added to the end of the file, so when loading and compiling
  64. // shaders, it will start quickly but end slow if new shaders were added since previous launch.
  65. // These variables are used to detect the change in speed so we can generate an ETA
  66. bool slow_shader_compile_start = false;
  67. std::chrono::steady_clock::time_point slow_shader_start;
  68. std::chrono::steady_clock::time_point previous_time;
  69. std::size_t slow_shader_first_value = 0;
  70. };
  71. #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
  72. Q_DECLARE_METATYPE(VideoCore::LoadCallbackStage);
  73. #endif