2015-12-07 04:06:12 +01:00
|
|
|
// Copyright 2015 Citra Emulator Project
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
2023-03-27 13:29:17 +02:00
|
|
|
#include "core/core.h"
|
2018-08-24 15:18:46 +02:00
|
|
|
#include "core/frontend/emu_window.h"
|
2023-03-27 13:29:17 +02:00
|
|
|
#include "core/tracer/recorder.h"
|
|
|
|
#include "video_core/debug_utils/debug_utils.h"
|
2016-09-21 08:52:38 +02:00
|
|
|
#include "video_core/renderer_base.h"
|
2015-12-07 04:06:12 +01:00
|
|
|
|
2023-03-27 13:29:17 +02:00
|
|
|
namespace VideoCore {
|
|
|
|
|
|
|
|
RendererBase::RendererBase(Core::System& system_, Frontend::EmuWindow& window,
|
|
|
|
Frontend::EmuWindow* secondary_window_)
|
|
|
|
: system{system_}, render_window{window}, secondary_window{secondary_window_} {}
|
2022-11-17 16:37:30 +01:00
|
|
|
|
2018-08-24 15:18:46 +02:00
|
|
|
RendererBase::~RendererBase() = default;
|
2022-11-17 16:37:30 +01:00
|
|
|
|
2023-03-30 13:24:49 +02:00
|
|
|
u32 RendererBase::GetResolutionScaleFactor() {
|
|
|
|
const auto graphics_api = Settings::values.graphics_api.GetValue();
|
|
|
|
if (graphics_api == Settings::GraphicsAPI::Software) {
|
|
|
|
// Software renderer always render at native resolution
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
const u32 scale_factor = Settings::values.resolution_factor.GetValue();
|
|
|
|
return scale_factor != 0 ? scale_factor
|
|
|
|
: render_window.GetFramebufferLayout().GetScalingRatio();
|
|
|
|
}
|
|
|
|
|
2019-07-22 20:58:54 +02:00
|
|
|
void RendererBase::UpdateCurrentFramebufferLayout(bool is_portrait_mode) {
|
2022-11-17 16:37:30 +01:00
|
|
|
const auto update_layout = [is_portrait_mode](Frontend::EmuWindow& window) {
|
|
|
|
const Layout::FramebufferLayout& layout = window.GetFramebufferLayout();
|
|
|
|
window.UpdateCurrentFramebufferLayout(layout.width, layout.height, is_portrait_mode);
|
|
|
|
};
|
|
|
|
update_layout(render_window);
|
|
|
|
if (secondary_window) {
|
|
|
|
update_layout(*secondary_window);
|
|
|
|
}
|
2018-08-24 15:18:46 +02:00
|
|
|
}
|
|
|
|
|
2023-03-27 13:29:17 +02:00
|
|
|
void RendererBase::EndFrame() {
|
|
|
|
current_frame++;
|
|
|
|
|
|
|
|
system.perf_stats->EndSystemFrame();
|
|
|
|
|
|
|
|
render_window.PollEvents();
|
|
|
|
|
|
|
|
system.frame_limiter.DoFrameLimiting(system.CoreTiming().GetGlobalTimeUs());
|
|
|
|
system.perf_stats->BeginSystemFrame();
|
2015-12-07 04:06:12 +01:00
|
|
|
|
2023-03-27 13:29:17 +02:00
|
|
|
if (Pica::g_debug_context && Pica::g_debug_context->recorder) {
|
|
|
|
Pica::g_debug_context->recorder->FrameFinished();
|
2015-12-07 04:06:12 +01:00
|
|
|
}
|
|
|
|
}
|
2020-04-11 11:28:52 +02:00
|
|
|
|
2023-03-27 13:29:17 +02:00
|
|
|
bool RendererBase::IsScreenshotPending() const {
|
2023-03-30 13:24:49 +02:00
|
|
|
return settings.screenshot_requested;
|
2020-04-11 11:28:52 +02:00
|
|
|
}
|
2023-03-27 13:29:17 +02:00
|
|
|
|
|
|
|
void RendererBase::RequestScreenshot(void* data, std::function<void()> callback,
|
|
|
|
const Layout::FramebufferLayout& layout) {
|
2023-03-30 13:24:49 +02:00
|
|
|
if (settings.screenshot_requested) {
|
2023-03-27 13:29:17 +02:00
|
|
|
LOG_ERROR(Render, "A screenshot is already requested or in progress, ignoring the request");
|
|
|
|
return;
|
|
|
|
}
|
2023-03-30 13:24:49 +02:00
|
|
|
settings.screenshot_bits = data;
|
|
|
|
settings.screenshot_complete_callback = callback;
|
|
|
|
settings.screenshot_framebuffer_layout = layout;
|
|
|
|
settings.screenshot_requested = true;
|
2023-03-27 13:29:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace VideoCore
|