graphics.cpp 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. // Copyright 2014 Citra Emulator Project
  2. // Licensed under GPLv2
  3. // Refer to the license.txt file included.
  4. #include "graphics.hxx"
  5. #include <QListView>
  6. #include <QVBoxLayout>
  7. #include <QDebug>
  8. extern GraphicsDebugger g_debugger;
  9. GPUCommandStreamItemModel::GPUCommandStreamItemModel(QObject* parent) : QAbstractListModel(parent), command_count(0)
  10. {
  11. connect(this, SIGNAL(GXCommandFinished(int)), this, SLOT(OnGXCommandFinishedInternal(int)));
  12. }
  13. int GPUCommandStreamItemModel::rowCount(const QModelIndex& parent) const
  14. {
  15. return command_count;
  16. }
  17. QVariant GPUCommandStreamItemModel::data(const QModelIndex& index, int role) const
  18. {
  19. if (!index.isValid())
  20. return QVariant();
  21. int command_index = index.row();
  22. const GSP_GPU::GXCommand& command = GetDebugger()->ReadGXCommandHistory(command_index);
  23. if (role == Qt::DisplayRole)
  24. {
  25. std::map<GSP_GPU::GXCommandId, const char*> command_names = {
  26. { GSP_GPU::GXCommandId::REQUEST_DMA, "REQUEST_DMA" },
  27. { GSP_GPU::GXCommandId::SET_COMMAND_LIST_FIRST, "SET_COMMAND_LIST_FIRST" },
  28. { GSP_GPU::GXCommandId::SET_MEMORY_FILL, "SET_MEMORY_FILL" },
  29. { GSP_GPU::GXCommandId::SET_DISPLAY_TRANSFER, "SET_DISPLAY_TRANSFER" },
  30. { GSP_GPU::GXCommandId::SET_TEXTURE_COPY, "SET_TEXTURE_COPY" },
  31. { GSP_GPU::GXCommandId::SET_COMMAND_LIST_LAST, "SET_COMMAND_LIST_LAST" }
  32. };
  33. const u32* command_data = reinterpret_cast<const u32*>(&command);
  34. QString str = QString("%1 %2 %3 %4 %5 %6 %7 %8 %9").arg(command_names[command.id])
  35. .arg(command_data[0], 8, 16, QLatin1Char('0'))
  36. .arg(command_data[1], 8, 16, QLatin1Char('0'))
  37. .arg(command_data[2], 8, 16, QLatin1Char('0'))
  38. .arg(command_data[3], 8, 16, QLatin1Char('0'))
  39. .arg(command_data[4], 8, 16, QLatin1Char('0'))
  40. .arg(command_data[5], 8, 16, QLatin1Char('0'))
  41. .arg(command_data[6], 8, 16, QLatin1Char('0'))
  42. .arg(command_data[7], 8, 16, QLatin1Char('0'));
  43. return QVariant(str);
  44. }
  45. else
  46. {
  47. return QVariant();
  48. }
  49. }
  50. void GPUCommandStreamItemModel::GXCommandProcessed(int total_command_count)
  51. {
  52. emit GXCommandFinished(total_command_count);
  53. }
  54. void GPUCommandStreamItemModel::OnGXCommandFinishedInternal(int total_command_count)
  55. {
  56. if (total_command_count == 0)
  57. return;
  58. int prev_command_count = command_count;
  59. command_count = total_command_count;
  60. emit dataChanged(index(prev_command_count,0), index(total_command_count-1,0));
  61. }
  62. GPUCommandStreamWidget::GPUCommandStreamWidget(QWidget* parent) : QDockWidget(tr("Graphics Debugger"), parent)
  63. {
  64. // TODO: set objectName!
  65. GPUCommandStreamItemModel* command_model = new GPUCommandStreamItemModel(this);
  66. g_debugger.RegisterObserver(command_model);
  67. QListView* command_list = new QListView;
  68. command_list->setModel(command_model);
  69. command_list->setFont(QFont("monospace"));
  70. setWidget(command_list);
  71. }