diff options
Diffstat (limited to 'src/citra_qt/debugger/profiler.cpp')
| -rw-r--r-- | src/citra_qt/debugger/profiler.cpp | 224 |
1 files changed, 0 insertions, 224 deletions
diff --git a/src/citra_qt/debugger/profiler.cpp b/src/citra_qt/debugger/profiler.cpp deleted file mode 100644 index f060bbe08..000000000 --- a/src/citra_qt/debugger/profiler.cpp +++ /dev/null | |||
| @@ -1,224 +0,0 @@ | |||
| 1 | // Copyright 2015 Citra Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #include <QAction> | ||
| 6 | #include <QLayout> | ||
| 7 | #include <QMouseEvent> | ||
| 8 | #include <QPainter> | ||
| 9 | #include <QString> | ||
| 10 | #include "citra_qt/debugger/profiler.h" | ||
| 11 | #include "citra_qt/util/util.h" | ||
| 12 | #include "common/common_types.h" | ||
| 13 | #include "common/microprofile.h" | ||
| 14 | |||
| 15 | // Include the implementation of the UI in this file. This isn't in microprofile.cpp because the | ||
| 16 | // non-Qt frontends don't need it (and don't implement the UI drawing hooks either). | ||
| 17 | #if MICROPROFILE_ENABLED | ||
| 18 | #define MICROPROFILEUI_IMPL 1 | ||
| 19 | #include "common/microprofileui.h" | ||
| 20 | |||
| 21 | class MicroProfileWidget : public QWidget { | ||
| 22 | public: | ||
| 23 | MicroProfileWidget(QWidget* parent = nullptr); | ||
| 24 | |||
| 25 | protected: | ||
| 26 | void paintEvent(QPaintEvent* ev) override; | ||
| 27 | void showEvent(QShowEvent* ev) override; | ||
| 28 | void hideEvent(QHideEvent* ev) override; | ||
| 29 | |||
| 30 | void mouseMoveEvent(QMouseEvent* ev) override; | ||
| 31 | void mousePressEvent(QMouseEvent* ev) override; | ||
| 32 | void mouseReleaseEvent(QMouseEvent* ev) override; | ||
| 33 | void wheelEvent(QWheelEvent* ev) override; | ||
| 34 | |||
| 35 | void keyPressEvent(QKeyEvent* ev) override; | ||
| 36 | void keyReleaseEvent(QKeyEvent* ev) override; | ||
| 37 | |||
| 38 | private: | ||
| 39 | /// This timer is used to redraw the widget's contents continuously. To save resources, it only | ||
| 40 | /// runs while the widget is visible. | ||
| 41 | QTimer update_timer; | ||
| 42 | /// Scale the coordinate system appropriately when dpi != 96. | ||
| 43 | qreal x_scale = 1.0, y_scale = 1.0; | ||
| 44 | }; | ||
| 45 | |||
| 46 | #endif | ||
| 47 | |||
| 48 | MicroProfileDialog::MicroProfileDialog(QWidget* parent) : QWidget(parent, Qt::Dialog) { | ||
| 49 | setObjectName("MicroProfile"); | ||
| 50 | setWindowTitle(tr("MicroProfile")); | ||
| 51 | resize(1000, 600); | ||
| 52 | // Remove the "?" button from the titlebar and enable the maximize button | ||
| 53 | setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint | Qt::WindowMaximizeButtonHint); | ||
| 54 | |||
| 55 | #if MICROPROFILE_ENABLED | ||
| 56 | |||
| 57 | MicroProfileWidget* widget = new MicroProfileWidget(this); | ||
| 58 | |||
| 59 | QLayout* layout = new QVBoxLayout(this); | ||
| 60 | layout->setContentsMargins(0, 0, 0, 0); | ||
| 61 | layout->addWidget(widget); | ||
| 62 | setLayout(layout); | ||
| 63 | |||
| 64 | // Configure focus so that widget is focusable and the dialog automatically forwards focus to | ||
| 65 | // it. | ||
| 66 | setFocusProxy(widget); | ||
| 67 | widget->setFocusPolicy(Qt::StrongFocus); | ||
| 68 | widget->setFocus(); | ||
| 69 | #endif | ||
| 70 | } | ||
| 71 | |||
| 72 | QAction* MicroProfileDialog::toggleViewAction() { | ||
| 73 | if (toggle_view_action == nullptr) { | ||
| 74 | toggle_view_action = new QAction(windowTitle(), this); | ||
| 75 | toggle_view_action->setCheckable(true); | ||
| 76 | toggle_view_action->setChecked(isVisible()); | ||
| 77 | connect(toggle_view_action, SIGNAL(toggled(bool)), SLOT(setVisible(bool))); | ||
| 78 | } | ||
| 79 | |||
| 80 | return toggle_view_action; | ||
| 81 | } | ||
| 82 | |||
| 83 | void MicroProfileDialog::showEvent(QShowEvent* ev) { | ||
| 84 | if (toggle_view_action) { | ||
| 85 | toggle_view_action->setChecked(isVisible()); | ||
| 86 | } | ||
| 87 | QWidget::showEvent(ev); | ||
| 88 | } | ||
| 89 | |||
| 90 | void MicroProfileDialog::hideEvent(QHideEvent* ev) { | ||
| 91 | if (toggle_view_action) { | ||
| 92 | toggle_view_action->setChecked(isVisible()); | ||
| 93 | } | ||
| 94 | QWidget::hideEvent(ev); | ||
| 95 | } | ||
| 96 | |||
| 97 | #if MICROPROFILE_ENABLED | ||
| 98 | |||
| 99 | /// There's no way to pass a user pointer to MicroProfile, so this variable is used to make the | ||
| 100 | /// QPainter available inside the drawing callbacks. | ||
| 101 | static QPainter* mp_painter = nullptr; | ||
| 102 | |||
| 103 | MicroProfileWidget::MicroProfileWidget(QWidget* parent) : QWidget(parent) { | ||
| 104 | // Send mouse motion events even when not dragging. | ||
| 105 | setMouseTracking(true); | ||
| 106 | |||
| 107 | MicroProfileSetDisplayMode(1); // Timers screen | ||
| 108 | MicroProfileInitUI(); | ||
| 109 | |||
| 110 | connect(&update_timer, SIGNAL(timeout()), SLOT(update())); | ||
| 111 | } | ||
| 112 | |||
| 113 | void MicroProfileWidget::paintEvent(QPaintEvent* ev) { | ||
| 114 | QPainter painter(this); | ||
| 115 | |||
| 116 | // The units used by Microprofile for drawing are based in pixels on a 96 dpi display. | ||
| 117 | x_scale = qreal(painter.device()->logicalDpiX()) / 96.0; | ||
| 118 | y_scale = qreal(painter.device()->logicalDpiY()) / 96.0; | ||
| 119 | painter.scale(x_scale, y_scale); | ||
| 120 | |||
| 121 | painter.setBackground(Qt::black); | ||
| 122 | painter.eraseRect(rect()); | ||
| 123 | |||
| 124 | QFont font = GetMonospaceFont(); | ||
| 125 | font.setPixelSize(MICROPROFILE_TEXT_HEIGHT); | ||
| 126 | painter.setFont(font); | ||
| 127 | |||
| 128 | mp_painter = &painter; | ||
| 129 | MicroProfileDraw(rect().width() / x_scale, rect().height() / y_scale); | ||
| 130 | mp_painter = nullptr; | ||
| 131 | } | ||
| 132 | |||
| 133 | void MicroProfileWidget::showEvent(QShowEvent* ev) { | ||
| 134 | update_timer.start(15); // ~60 Hz | ||
| 135 | QWidget::showEvent(ev); | ||
| 136 | } | ||
| 137 | |||
| 138 | void MicroProfileWidget::hideEvent(QHideEvent* ev) { | ||
| 139 | update_timer.stop(); | ||
| 140 | QWidget::hideEvent(ev); | ||
| 141 | } | ||
| 142 | |||
| 143 | void MicroProfileWidget::mouseMoveEvent(QMouseEvent* ev) { | ||
| 144 | MicroProfileMousePosition(ev->x() / x_scale, ev->y() / y_scale, 0); | ||
| 145 | ev->accept(); | ||
| 146 | } | ||
| 147 | |||
| 148 | void MicroProfileWidget::mousePressEvent(QMouseEvent* ev) { | ||
| 149 | MicroProfileMousePosition(ev->x() / x_scale, ev->y() / y_scale, 0); | ||
| 150 | MicroProfileMouseButton(ev->buttons() & Qt::LeftButton, ev->buttons() & Qt::RightButton); | ||
| 151 | ev->accept(); | ||
| 152 | } | ||
| 153 | |||
| 154 | void MicroProfileWidget::mouseReleaseEvent(QMouseEvent* ev) { | ||
| 155 | MicroProfileMousePosition(ev->x() / x_scale, ev->y() / y_scale, 0); | ||
| 156 | MicroProfileMouseButton(ev->buttons() & Qt::LeftButton, ev->buttons() & Qt::RightButton); | ||
| 157 | ev->accept(); | ||
| 158 | } | ||
| 159 | |||
| 160 | void MicroProfileWidget::wheelEvent(QWheelEvent* ev) { | ||
| 161 | MicroProfileMousePosition(ev->x() / x_scale, ev->y() / y_scale, ev->delta() / 120); | ||
| 162 | ev->accept(); | ||
| 163 | } | ||
| 164 | |||
| 165 | void MicroProfileWidget::keyPressEvent(QKeyEvent* ev) { | ||
| 166 | if (ev->key() == Qt::Key_Control) { | ||
| 167 | // Inform MicroProfile that the user is holding Ctrl. | ||
| 168 | MicroProfileModKey(1); | ||
| 169 | } | ||
| 170 | QWidget::keyPressEvent(ev); | ||
| 171 | } | ||
| 172 | |||
| 173 | void MicroProfileWidget::keyReleaseEvent(QKeyEvent* ev) { | ||
| 174 | if (ev->key() == Qt::Key_Control) { | ||
| 175 | MicroProfileModKey(0); | ||
| 176 | } | ||
| 177 | QWidget::keyReleaseEvent(ev); | ||
| 178 | } | ||
| 179 | |||
| 180 | // These functions are called by MicroProfileDraw to draw the interface elements on the screen. | ||
| 181 | |||
| 182 | void MicroProfileDrawText(int x, int y, u32 hex_color, const char* text, u32 text_length) { | ||
| 183 | // hex_color does not include an alpha, so it must be assumed to be 255 | ||
| 184 | mp_painter->setPen(QColor::fromRgb(hex_color)); | ||
| 185 | |||
| 186 | // It's impossible to draw a string using a monospaced font with a fixed width per cell in a | ||
| 187 | // way that's reliable across different platforms and fonts as far as I (yuriks) can tell, so | ||
| 188 | // draw each character individually in order to precisely control the text advance. | ||
| 189 | for (u32 i = 0; i < text_length; ++i) { | ||
| 190 | // Position the text baseline 1 pixel above the bottom of the text cell, this gives nice | ||
| 191 | // vertical alignment of text for a wide range of tested fonts. | ||
| 192 | mp_painter->drawText(x, y + MICROPROFILE_TEXT_HEIGHT - 2, QChar(text[i])); | ||
| 193 | x += MICROPROFILE_TEXT_WIDTH + 1; | ||
| 194 | } | ||
| 195 | } | ||
| 196 | |||
| 197 | void MicroProfileDrawBox(int left, int top, int right, int bottom, u32 hex_color, | ||
| 198 | MicroProfileBoxType type) { | ||
| 199 | QColor color = QColor::fromRgba(hex_color); | ||
| 200 | QBrush brush = color; | ||
| 201 | if (type == MicroProfileBoxTypeBar) { | ||
| 202 | QLinearGradient gradient(left, top, left, bottom); | ||
| 203 | gradient.setColorAt(0.f, color.lighter(125)); | ||
| 204 | gradient.setColorAt(1.f, color.darker(125)); | ||
| 205 | brush = gradient; | ||
| 206 | } | ||
| 207 | mp_painter->fillRect(left, top, right - left, bottom - top, brush); | ||
| 208 | } | ||
| 209 | |||
| 210 | void MicroProfileDrawLine2D(u32 vertices_length, float* vertices, u32 hex_color) { | ||
| 211 | // Temporary vector used to convert between the float array and QPointF. Marked static to reuse | ||
| 212 | // the allocation across calls. | ||
| 213 | static std::vector<QPointF> point_buf; | ||
| 214 | |||
| 215 | for (u32 i = 0; i < vertices_length; ++i) { | ||
| 216 | point_buf.emplace_back(vertices[i * 2 + 0], vertices[i * 2 + 1]); | ||
| 217 | } | ||
| 218 | |||
| 219 | // hex_color does not include an alpha, so it must be assumed to be 255 | ||
| 220 | mp_painter->setPen(QColor::fromRgb(hex_color)); | ||
| 221 | mp_painter->drawPolyline(point_buf.data(), vertices_length); | ||
| 222 | point_buf.clear(); | ||
| 223 | } | ||
| 224 | #endif | ||