1
0
Fork 0
forked from suyu/suyu

Merge pull request #2529 from lioncash/boot

yuzu/bootmanager: Minor interface tidying
This commit is contained in:
Rodrigo Locatti 2019-06-04 21:35:56 -03:00 committed by GitHub
commit 2ba4aa8a3b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 61 additions and 44 deletions

View file

@ -20,7 +20,7 @@ static Common::Rectangle<T> MaxRectangle(Common::Rectangle<T> window_area,
static_cast<T>(std::round(scale * screen_aspect_ratio))}; static_cast<T>(std::round(scale * screen_aspect_ratio))};
} }
FramebufferLayout DefaultFrameLayout(unsigned width, unsigned height) { FramebufferLayout DefaultFrameLayout(u32 width, u32 height) {
ASSERT(width > 0); ASSERT(width > 0);
ASSERT(height > 0); ASSERT(height > 0);
// The drawing code needs at least somewhat valid values for both screens // The drawing code needs at least somewhat valid values for both screens
@ -29,22 +29,23 @@ FramebufferLayout DefaultFrameLayout(unsigned width, unsigned height) {
const float emulation_aspect_ratio{static_cast<float>(ScreenUndocked::Height) / const float emulation_aspect_ratio{static_cast<float>(ScreenUndocked::Height) /
ScreenUndocked::Width}; ScreenUndocked::Width};
Common::Rectangle<unsigned> screen_window_area{0, 0, width, height}; const auto window_aspect_ratio = static_cast<float>(height) / width;
Common::Rectangle<unsigned> screen = MaxRectangle(screen_window_area, emulation_aspect_ratio);
float window_aspect_ratio = static_cast<float>(height) / width; const Common::Rectangle<u32> screen_window_area{0, 0, width, height};
Common::Rectangle<u32> screen = MaxRectangle(screen_window_area, emulation_aspect_ratio);
if (window_aspect_ratio < emulation_aspect_ratio) { if (window_aspect_ratio < emulation_aspect_ratio) {
screen = screen.TranslateX((screen_window_area.GetWidth() - screen.GetWidth()) / 2); screen = screen.TranslateX((screen_window_area.GetWidth() - screen.GetWidth()) / 2);
} else { } else {
screen = screen.TranslateY((height - screen.GetHeight()) / 2); screen = screen.TranslateY((height - screen.GetHeight()) / 2);
} }
res.screen = screen; res.screen = screen;
return res; return res;
} }
FramebufferLayout FrameLayoutFromResolutionScale(u16 res_scale) { FramebufferLayout FrameLayoutFromResolutionScale(u32 res_scale) {
int width, height; u32 width, height;
if (Settings::values.use_docked_mode) { if (Settings::values.use_docked_mode) {
width = ScreenDocked::WidthDocked * res_scale; width = ScreenDocked::WidthDocked * res_scale;

View file

@ -8,15 +8,22 @@
namespace Layout { namespace Layout {
enum ScreenUndocked : unsigned { Width = 1280, Height = 720 }; enum ScreenUndocked : u32 {
enum ScreenDocked : unsigned { WidthDocked = 1920, HeightDocked = 1080 }; Width = 1280,
Height = 720,
};
enum ScreenDocked : u32 {
WidthDocked = 1920,
HeightDocked = 1080,
};
/// Describes the layout of the window framebuffer /// Describes the layout of the window framebuffer
struct FramebufferLayout { struct FramebufferLayout {
unsigned width{ScreenUndocked::Width}; u32 width{ScreenUndocked::Width};
unsigned height{ScreenUndocked::Height}; u32 height{ScreenUndocked::Height};
Common::Rectangle<unsigned> screen; Common::Rectangle<u32> screen;
/** /**
* Returns the ration of pixel size of the screen, compared to the native size of the undocked * Returns the ration of pixel size of the screen, compared to the native size of the undocked
@ -33,12 +40,12 @@ struct FramebufferLayout {
* @param height Window framebuffer height in pixels * @param height Window framebuffer height in pixels
* @return Newly created FramebufferLayout object with default screen regions initialized * @return Newly created FramebufferLayout object with default screen regions initialized
*/ */
FramebufferLayout DefaultFrameLayout(unsigned width, unsigned height); FramebufferLayout DefaultFrameLayout(u32 width, u32 height);
/** /**
* Convenience method to get frame layout by resolution scale * Convenience method to get frame layout by resolution scale
* @param res_scale resolution scale factor * @param res_scale resolution scale factor
*/ */
FramebufferLayout FrameLayoutFromResolutionScale(u16 res_scale); FramebufferLayout FrameLayoutFromResolutionScale(u32 res_scale);
} // namespace Layout } // namespace Layout

View file

@ -26,6 +26,8 @@
EmuThread::EmuThread(GRenderWindow* render_window) : render_window(render_window) {} EmuThread::EmuThread(GRenderWindow* render_window) : render_window(render_window) {}
EmuThread::~EmuThread() = default;
void EmuThread::run() { void EmuThread::run() {
render_window->MakeCurrent(); render_window->MakeCurrent();
@ -185,7 +187,7 @@ private:
bool do_painting; bool do_painting;
}; };
GRenderWindow::GRenderWindow(QWidget* parent, EmuThread* emu_thread) GRenderWindow::GRenderWindow(GMainWindow* parent, EmuThread* emu_thread)
: QWidget(parent), emu_thread(emu_thread) { : QWidget(parent), emu_thread(emu_thread) {
setWindowTitle(QStringLiteral("yuzu %1 | %2-%3") setWindowTitle(QStringLiteral("yuzu %1 | %2-%3")
.arg(QString::fromUtf8(Common::g_build_name), .arg(QString::fromUtf8(Common::g_build_name),
@ -194,8 +196,7 @@ GRenderWindow::GRenderWindow(QWidget* parent, EmuThread* emu_thread)
setAttribute(Qt::WA_AcceptTouchEvents); setAttribute(Qt::WA_AcceptTouchEvents);
InputCommon::Init(); InputCommon::Init();
connect(this, &GRenderWindow::FirstFrameDisplayed, static_cast<GMainWindow*>(parent), connect(this, &GRenderWindow::FirstFrameDisplayed, parent, &GMainWindow::OnLoadComplete);
&GMainWindow::OnLoadComplete);
} }
GRenderWindow::~GRenderWindow() { GRenderWindow::~GRenderWindow() {
@ -247,9 +248,9 @@ void GRenderWindow::PollEvents() {}
void GRenderWindow::OnFramebufferSizeChanged() { void GRenderWindow::OnFramebufferSizeChanged() {
// Screen changes potentially incur a change in screen DPI, hence we should update the // Screen changes potentially incur a change in screen DPI, hence we should update the
// framebuffer size // framebuffer size
qreal pixelRatio = GetWindowPixelRatio(); const qreal pixel_ratio = GetWindowPixelRatio();
unsigned width = child->QPaintDevice::width() * pixelRatio; const u32 width = child->QPaintDevice::width() * pixel_ratio;
unsigned height = child->QPaintDevice::height() * pixelRatio; const u32 height = child->QPaintDevice::height() * pixel_ratio;
UpdateCurrentFramebufferLayout(width, height); UpdateCurrentFramebufferLayout(width, height);
} }
@ -266,7 +267,7 @@ void GRenderWindow::ForwardKeyReleaseEvent(QKeyEvent* event) {
} }
void GRenderWindow::BackupGeometry() { void GRenderWindow::BackupGeometry() {
geometry = ((QWidget*)this)->saveGeometry(); geometry = QWidget::saveGeometry();
} }
void GRenderWindow::RestoreGeometry() { void GRenderWindow::RestoreGeometry() {
@ -283,9 +284,10 @@ void GRenderWindow::restoreGeometry(const QByteArray& geometry) {
QByteArray GRenderWindow::saveGeometry() { QByteArray GRenderWindow::saveGeometry() {
// If we are a top-level widget, store the current geometry // If we are a top-level widget, store the current geometry
// otherwise, store the last backup // otherwise, store the last backup
if (parent() == nullptr) if (parent() == nullptr) {
return ((QWidget*)this)->saveGeometry(); return QWidget::saveGeometry();
else }
return geometry; return geometry;
} }
@ -294,10 +296,10 @@ qreal GRenderWindow::GetWindowPixelRatio() const {
return windowHandle() ? windowHandle()->screen()->devicePixelRatio() : 1.0f; return windowHandle() ? windowHandle()->screen()->devicePixelRatio() : 1.0f;
} }
std::pair<unsigned, unsigned> GRenderWindow::ScaleTouch(const QPointF pos) const { std::pair<u32, u32> GRenderWindow::ScaleTouch(const QPointF pos) const {
const qreal pixel_ratio = GetWindowPixelRatio(); const qreal pixel_ratio = GetWindowPixelRatio();
return {static_cast<unsigned>(std::max(std::round(pos.x() * pixel_ratio), qreal{0.0})), return {static_cast<u32>(std::max(std::round(pos.x() * pixel_ratio), qreal{0.0})),
static_cast<unsigned>(std::max(std::round(pos.y() * pixel_ratio), qreal{0.0}))}; static_cast<u32>(std::max(std::round(pos.y() * pixel_ratio), qreal{0.0}))};
} }
void GRenderWindow::closeEvent(QCloseEvent* event) { void GRenderWindow::closeEvent(QCloseEvent* event) {
@ -353,7 +355,7 @@ void GRenderWindow::focusOutEvent(QFocusEvent* event) {
InputCommon::GetKeyboard()->ReleaseAllKeys(); InputCommon::GetKeyboard()->ReleaseAllKeys();
} }
void GRenderWindow::OnClientAreaResized(unsigned width, unsigned height) { void GRenderWindow::OnClientAreaResized(u32 width, u32 height) {
NotifyClientAreaSizeChanged(std::make_pair(width, height)); NotifyClientAreaSizeChanged(std::make_pair(width, height));
} }
@ -394,7 +396,7 @@ void GRenderWindow::InitRenderTarget() {
context->setShareContext(shared_context.get()); context->setShareContext(shared_context.get());
context->setFormat(fmt); context->setFormat(fmt);
context->create(); context->create();
fmt.setSwapInterval(false); fmt.setSwapInterval(0);
child = new GGLWidgetInternal(this, shared_context.get()); child = new GGLWidgetInternal(this, shared_context.get());
container = QWidget::createWindowContainer(child, this); container = QWidget::createWindowContainer(child, this);
@ -424,23 +426,29 @@ void GRenderWindow::InitRenderTarget() {
BackupGeometry(); BackupGeometry();
} }
void GRenderWindow::CaptureScreenshot(u16 res_scale, const QString& screenshot_path) { void GRenderWindow::CaptureScreenshot(u32 res_scale, const QString& screenshot_path) {
auto& renderer = Core::System::GetInstance().Renderer(); auto& renderer = Core::System::GetInstance().Renderer();
if (!res_scale) if (res_scale == 0) {
res_scale = VideoCore::GetResolutionScaleFactor(renderer); res_scale = VideoCore::GetResolutionScaleFactor(renderer);
}
const Layout::FramebufferLayout layout{Layout::FrameLayoutFromResolutionScale(res_scale)}; const Layout::FramebufferLayout layout{Layout::FrameLayoutFromResolutionScale(res_scale)};
screenshot_image = QImage(QSize(layout.width, layout.height), QImage::Format_RGB32); screenshot_image = QImage(QSize(layout.width, layout.height), QImage::Format_RGB32);
renderer.RequestScreenshot(screenshot_image.bits(), renderer.RequestScreenshot(
screenshot_image.bits(),
[=] { [=] {
screenshot_image.mirrored(false, true).save(screenshot_path); const std::string std_screenshot_path = screenshot_path.toStdString();
LOG_INFO(Frontend, "The screenshot is saved."); if (screenshot_image.mirrored(false, true).save(screenshot_path)) {
LOG_INFO(Frontend, "Screenshot saved to \"{}\"", std_screenshot_path);
} else {
LOG_ERROR(Frontend, "Failed to save screenshot to \"{}\"", std_screenshot_path);
}
}, },
layout); layout);
} }
void GRenderWindow::OnMinimalClientAreaChangeRequest(std::pair<unsigned, unsigned> minimal_size) { void GRenderWindow::OnMinimalClientAreaChangeRequest(std::pair<u32, u32> minimal_size) {
setMinimumSize(minimal_size.first, minimal_size.second); setMinimumSize(minimal_size.first, minimal_size.second);
} }

View file

@ -27,11 +27,12 @@ namespace VideoCore {
enum class LoadCallbackStage; enum class LoadCallbackStage;
} }
class EmuThread : public QThread { class EmuThread final : public QThread {
Q_OBJECT Q_OBJECT
public: public:
explicit EmuThread(GRenderWindow* render_window); explicit EmuThread(GRenderWindow* render_window);
~EmuThread() override;
/** /**
* Start emulation (on new thread) * Start emulation (on new thread)
@ -114,7 +115,7 @@ class GRenderWindow : public QWidget, public Core::Frontend::EmuWindow {
Q_OBJECT Q_OBJECT
public: public:
GRenderWindow(QWidget* parent, EmuThread* emu_thread); GRenderWindow(GMainWindow* parent, EmuThread* emu_thread);
~GRenderWindow() override; ~GRenderWindow() override;
// EmuWindow implementation // EmuWindow implementation
@ -133,17 +134,17 @@ public:
QByteArray saveGeometry(); // overridden QByteArray saveGeometry(); // overridden
qreal GetWindowPixelRatio() const; qreal GetWindowPixelRatio() const;
std::pair<unsigned, unsigned> ScaleTouch(const QPointF pos) const; std::pair<u32, u32> ScaleTouch(QPointF pos) const;
void closeEvent(QCloseEvent* event) override; void closeEvent(QCloseEvent* event) override;
bool event(QEvent* event) override; bool event(QEvent* event) override;
void focusOutEvent(QFocusEvent* event) override; void focusOutEvent(QFocusEvent* event) override;
void OnClientAreaResized(unsigned width, unsigned height); void OnClientAreaResized(u32 width, u32 height);
void InitRenderTarget(); void InitRenderTarget();
void CaptureScreenshot(u16 res_scale, const QString& screenshot_path); void CaptureScreenshot(u32 res_scale, const QString& screenshot_path);
public slots: public slots:
void moveContext(); // overridden void moveContext(); // overridden
@ -162,7 +163,7 @@ private:
void TouchUpdateEvent(const QTouchEvent* event); void TouchUpdateEvent(const QTouchEvent* event);
void TouchEndEvent(); void TouchEndEvent();
void OnMinimalClientAreaChangeRequest(std::pair<unsigned, unsigned> minimal_size) override; void OnMinimalClientAreaChangeRequest(std::pair<u32, u32> minimal_size) override;
QWidget* container = nullptr; QWidget* container = nullptr;
GGLWidgetInternal* child = nullptr; GGLWidgetInternal* child = nullptr;