1
0
Fork 0
forked from suyu/suyu

yuzu/debugger/graphics_surface: Tidy up SaveSurface

- Use QStringLiteral where applicable.

- Use const where applicable

- Remove unnecessary precondition check (we already assert the pixbuf
  being non null)
This commit is contained in:
Lioncash 2019-04-05 19:32:58 -04:00
parent bbeb859122
commit 845607481c

View file

@ -459,39 +459,38 @@ void GraphicsSurfaceWidget::OnUpdate() {
} }
void GraphicsSurfaceWidget::SaveSurface() { void GraphicsSurfaceWidget::SaveSurface() {
QString png_filter = tr("Portable Network Graphic (*.png)"); const QString png_filter = tr("Portable Network Graphic (*.png)");
QString bin_filter = tr("Binary data (*.bin)"); const QString bin_filter = tr("Binary data (*.bin)");
QString selectedFilter; QString selected_filter;
QString filename = QFileDialog::getSaveFileName( const QString filename = QFileDialog::getSaveFileName(
this, tr("Save Surface"), this, tr("Save Surface"),
QString("texture-0x%1.png").arg(QString::number(surface_address, 16)), QStringLiteral("texture-0x%1.png").arg(QString::number(surface_address, 16)),
QString("%1;;%2").arg(png_filter, bin_filter), &selectedFilter); QStringLiteral("%1;;%2").arg(png_filter, bin_filter), &selected_filter);
if (filename.isEmpty()) { if (filename.isEmpty()) {
// If the user canceled the dialog, don't save anything. // If the user canceled the dialog, don't save anything.
return; return;
} }
if (selectedFilter == png_filter) { if (selected_filter == png_filter) {
const QPixmap* pixmap = surface_picture_label->pixmap(); const QPixmap* const pixmap = surface_picture_label->pixmap();
ASSERT_MSG(pixmap != nullptr, "No pixmap set"); ASSERT_MSG(pixmap != nullptr, "No pixmap set");
QFile file(filename); QFile file(filename);
file.open(QIODevice::WriteOnly); file.open(QIODevice::WriteOnly);
if (pixmap) pixmap->save(&file, "PNG");
pixmap->save(&file, "PNG"); } else if (selected_filter == bin_filter) {
} else if (selectedFilter == bin_filter) {
auto& gpu = Core::System::GetInstance().GPU(); auto& gpu = Core::System::GetInstance().GPU();
std::optional<VAddr> address = gpu.MemoryManager().GpuToCpuAddress(surface_address); const std::optional<VAddr> address = gpu.MemoryManager().GpuToCpuAddress(surface_address);
const u8* buffer = Memory::GetPointer(*address); const u8* const buffer = Memory::GetPointer(*address);
ASSERT_MSG(buffer != nullptr, "Memory not accessible"); ASSERT_MSG(buffer != nullptr, "Memory not accessible");
QFile file(filename); QFile file(filename);
file.open(QIODevice::WriteOnly); file.open(QIODevice::WriteOnly);
int size = surface_width * surface_height * Tegra::Texture::BytesPerPixel(surface_format); const int size = surface_width * surface_height * Tegra::Texture::BytesPerPixel(surface_format);
QByteArray data(reinterpret_cast<const char*>(buffer), size); const QByteArray data(reinterpret_cast<const char*>(buffer), size);
file.write(data); file.write(data);
} else { } else {
UNREACHABLE_MSG("Unhandled filter selected"); UNREACHABLE_MSG("Unhandled filter selected");