1 // Copyright 2014 Citra Emulator Project
2 // Licensed under GPLv2 or any later version
3 // Refer to the license.txt file included.
4 
5 #pragma once
6 
7 #include <QLabel>
8 #include <QPushButton>
9 #include "citra_qt/debugger/graphics/graphics_breakpoint_observer.h"
10 
11 class QComboBox;
12 class QSpinBox;
13 class CSpinBox;
14 
15 class GraphicsSurfaceWidget;
16 
17 class SurfacePicture : public QLabel {
18     Q_OBJECT
19 
20 public:
21     explicit SurfacePicture(QWidget* parent = nullptr,
22                             GraphicsSurfaceWidget* surface_widget = nullptr);
23     ~SurfacePicture() override;
24 
25 protected slots:
26     void mouseMoveEvent(QMouseEvent* event) override;
27     void mousePressEvent(QMouseEvent* event) override;
28 
29 private:
30     GraphicsSurfaceWidget* surface_widget;
31 };
32 
33 class GraphicsSurfaceWidget : public BreakPointObserverDock {
34     Q_OBJECT
35 
36     using Event = Pica::DebugContext::Event;
37 
38     enum class Source {
39         ColorBuffer = 0,
40         DepthBuffer = 1,
41         StencilBuffer = 2,
42         Texture0 = 3,
43         Texture1 = 4,
44         Texture2 = 5,
45         Custom = 6,
46     };
47 
48     enum class Format {
49         // These must match the TextureFormat type!
50         RGBA8 = 0,
51         RGB8 = 1,
52         RGB5A1 = 2,
53         RGB565 = 3,
54         RGBA4 = 4,
55         IA8 = 5,
56         RG8 = 6, ///< @note Also called HILO8 in 3DBrew.
57         I8 = 7,
58         A8 = 8,
59         IA4 = 9,
60         I4 = 10,
61         A4 = 11,
62         ETC1 = 12, // compressed
63         ETC1A4 = 13,
64         MaxTextureFormat = 13,
65         D16 = 14,
66         D24 = 15,
67         D24X8 = 16,
68         X24S8 = 17,
69         Unknown = 18,
70     };
71 
72     static unsigned int NibblesPerPixel(Format format);
73 
74 public:
75     explicit GraphicsSurfaceWidget(std::shared_ptr<Pica::DebugContext> debug_context,
76                                    QWidget* parent = nullptr);
77     void Pick(int x, int y);
78 
79 public slots:
80     void OnSurfaceSourceChanged(int new_value);
81     void OnSurfaceAddressChanged(qint64 new_value);
82     void OnSurfaceWidthChanged(int new_value);
83     void OnSurfaceHeightChanged(int new_value);
84     void OnSurfaceFormatChanged(int new_value);
85     void OnSurfacePickerXChanged(int new_value);
86     void OnSurfacePickerYChanged(int new_value);
87     void OnUpdate();
88 
89 signals:
90     void Update();
91 
92 private:
93     void OnBreakPointHit(Pica::DebugContext::Event event, void* data) override;
94     void OnResumed() override;
95 
96     void SaveSurface();
97 
98     QComboBox* surface_source_list;
99     CSpinBox* surface_address_control;
100     QSpinBox* surface_width_control;
101     QSpinBox* surface_height_control;
102     QComboBox* surface_format_control;
103 
104     SurfacePicture* surface_picture_label;
105     QSpinBox* surface_picker_x_control;
106     QSpinBox* surface_picker_y_control;
107     QLabel* surface_info_label;
108     QPushButton* save_surface;
109 
110     Source surface_source;
111     unsigned surface_address;
112     unsigned surface_width;
113     unsigned surface_height;
114     Format surface_format;
115     int surface_picker_x = 0;
116     int surface_picker_y = 0;
117 };
118