Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
hrydgard
GitHub Repository: hrydgard/ppsspp
Path: blob/master/UI/DevScreens.cpp
5659 views
1
// Copyright (c) 2013- PPSSPP Project.
2
3
// This program is free software: you can redistribute it and/or modify
4
// it under the terms of the GNU General Public License as published by
5
// the Free Software Foundation, version 2.0 or later versions.
6
7
// This program is distributed in the hope that it will be useful,
8
// but WITHOUT ANY WARRANTY; without even the implied warranty of
9
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
// GNU General Public License 2.0 for more details.
11
12
// A copy of the GPL 2.0 should have been included with the program.
13
// If not, see http://www.gnu.org/licenses/
14
15
// Official git repository and contact information can be found at
16
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
17
18
// Hack around name collisions between UI and xlib
19
// Only affects this file.
20
#undef VK_USE_PLATFORM_XLIB_KHR
21
#undef VK_USE_PLATFORM_XCB_KHR
22
#undef VK_USE_PLATFORM_DIRECTFB_EXT
23
#undef VK_USE_PLATFORM_XLIB_XRANDR_EXT
24
25
#include <algorithm>
26
#include <cstring>
27
28
#include "ppsspp_config.h"
29
30
#include "Common/Common.h"
31
#include "Common/System/Display.h"
32
#include "Common/System/OSD.h"
33
#include "Common/Audio/AudioBackend.h"
34
35
#include "Common/File/AndroidStorage.h"
36
#include "Common/Data/Text/I18n.h"
37
#include "Common/Data/Text/Parsers.h"
38
#include "Common/Data/Encoding/Utf8.h"
39
#include "Common/Net/HTTPClient.h"
40
#include "Common/UI/Context.h"
41
#include "Common/UI/PopupScreens.h"
42
#include "Common/UI/View.h"
43
#include "Common/UI/ViewGroup.h"
44
#include "Common/UI/UI.h"
45
#include "Common/UI/IconCache.h"
46
#include "Common/Render/Text/draw_text.h"
47
#include "Common/Profiler/Profiler.h"
48
49
#include "Common/Log/LogManager.h"
50
#include "Common/CPUDetect.h"
51
#include "Common/StringUtils.h"
52
#include "Common/GPU/ShaderWriter.h"
53
54
#include "Core/WebServer.h"
55
#include "Core/MemMap.h"
56
#include "Core/Config.h"
57
#include "Core/ConfigValues.h"
58
#include "Core/System.h"
59
#include "Core/Reporting.h"
60
#include "Core/CoreParameter.h"
61
#include "Core/HLE/sceKernel.h" // GPI/GPO
62
#include "Core/MIPS/MIPSTables.h"
63
#include "Core/MIPS/JitCommon/JitBlockCache.h"
64
#include "Core/MIPS/JitCommon/JitCommon.h"
65
#include "Core/MIPS/JitCommon/JitState.h"
66
#include "GPU/Debugger/Record.h"
67
#include "GPU/GPUCommon.h"
68
#include "GPU/GPUState.h"
69
#include "UI/BaseScreens.h"
70
#include "UI/DevScreens.h"
71
#include "UI/MainScreen.h"
72
#include "UI/EmuScreen.h"
73
#include "UI/OnScreenDisplay.h"
74
#include "UI/ControlMappingScreen.h"
75
#include "UI/DeveloperToolsScreen.h"
76
#include "UI/JitCompareScreen.h"
77
#include "android/jni/app-android.h"
78
79
80
static const char *logLevelList[] = {
81
"Notice",
82
"Error",
83
"Warn",
84
"Info",
85
"Debug",
86
"Verb."
87
};
88
89
static const char *g_debugOverlayList[] = {
90
"Off",
91
"Debug stats",
92
"Draw Frametimes Graph",
93
"Frame timing",
94
#ifdef USE_PROFILER
95
"Frame profile",
96
#endif
97
"Control Debug",
98
"Audio Debug",
99
"GPU Profile",
100
"GPU Allocator Viewer",
101
"Framebuffer List",
102
};
103
104
void AddOverlayList(UI::ViewGroup *items, ScreenManager *screenManager) {
105
using namespace UI;
106
auto dev = GetI18NCategory(I18NCat::DEVELOPER);
107
int numOverlays = ARRAY_SIZE(g_debugOverlayList);
108
if (!(g_Config.iGPUBackend == (int)GPUBackend::VULKAN || g_Config.iGPUBackend == (int)GPUBackend::OPENGL)) {
109
numOverlays -= 2; // skip the last 2.
110
}
111
items->Add(new PopupMultiChoice((int *)&g_Config.iDebugOverlay, dev->T("Debug overlay"), g_debugOverlayList, 0, numOverlays, I18NCat::DEVELOPER, screenManager));
112
}
113
114
void SaveFrameDump() {
115
if (!gpuDebug) {
116
return;
117
}
118
gpuDebug->GetRecorder()->RecordNextFrame([](const Path &dumpPath) {
119
NOTICE_LOG(Log::System, "Frame dump created at '%s'", dumpPath.c_str());
120
if (System_GetPropertyBool(SYSPROP_CAN_SHOW_FILE)) {
121
System_ShowFileInFolder(dumpPath);
122
} else {
123
g_OSD.Show(OSDType::MESSAGE_SUCCESS, dumpPath.ToVisualString(), 7.0f);
124
}
125
});
126
}
127
128
void DevMenuScreen::CreatePopupContents(UI::ViewGroup *parent) {
129
using namespace UI;
130
auto dev = GetI18NCategory(I18NCat::DEVELOPER);
131
auto sy = GetI18NCategory(I18NCat::SYSTEM);
132
133
ScrollView *scroll = new ScrollView(ORIENT_VERTICAL, new LinearLayoutParams(FILL_PARENT, WRAP_CONTENT, 1.0f));
134
LinearLayout *items = new LinearLayout(ORIENT_VERTICAL);
135
136
items->Add(new Choice(dev->T("Log View")))->OnClick.Add([this](UI::EventParams & e) {
137
UpdateUIState(UISTATE_PAUSEMENU);
138
screenManager()->push(new LogViewScreen());
139
});
140
141
items->Add(new Choice(dev->T("Logging Channels")))->OnClick.Add([this](UI::EventParams & e) {
142
UpdateUIState(UISTATE_PAUSEMENU);
143
screenManager()->push(new LogConfigScreen());
144
});
145
146
items->Add(new Choice(dev->T("Debugger")))->OnClick.Add([](UI::EventParams &e) {
147
g_Config.bShowImDebugger = !g_Config.bShowImDebugger;
148
});
149
150
if (WebServerRunning(WebServerFlags::DEBUGGER)) {
151
items->Add(new Choice(dev->T("Remote debugger")))->OnClick.Add([](UI::EventParams &e) {
152
int port = g_Config.iRemoteISOPort; // Also used for serving a local remote debugger.
153
if (g_Config.bRemoteDebuggerLocal) {
154
// TODO: Need to modify this URL to add /cpu when we upgrade to the latest version of the web debugger.
155
char uri[64];
156
snprintf(uri, sizeof(uri), "http://localhost:%d/debugger/", port);
157
System_LaunchUrl(LaunchUrlType::BROWSER_URL, uri);
158
} else {
159
System_LaunchUrl(LaunchUrlType::BROWSER_URL, "http://ppsspp-debugger.unknownbrackets.org/cpu"); // NOTE: https doesn't work
160
}
161
});
162
}
163
164
items->Add(new Choice(sy->T("Developer Tools")))->OnClick.Handle(this, &DevMenuScreen::OnDeveloperTools);
165
166
// Debug overlay
167
AddOverlayList(items, screenManager());
168
169
items->Add(new Choice(dev->T("Jit Compare")))->OnClick.Handle(this, &DevMenuScreen::OnJitCompare);
170
items->Add(new Choice(dev->T("Shader Viewer")))->OnClick.Handle(this, &DevMenuScreen::OnShaderView);
171
172
items->Add(new Choice(dev->T("Toggle Freeze")))->OnClick.Add([](UI::EventParams &e) {
173
if (PSP_CoreParameter().frozen) {
174
PSP_CoreParameter().frozen = false;
175
} else {
176
PSP_CoreParameter().freezeNext = true;
177
}
178
});
179
180
items->Add(new Choice(dev->T("Reset limited logging")))->OnClick.Handle(this, &DevMenuScreen::OnResetLimitedLogging);
181
182
items->Add(new Choice(dev->T("GPI/GPO switches/LEDs")))->OnClick.Add([=](UI::EventParams &e) {
183
screenManager()->push(new GPIGPOScreen(dev->T("GPI/GPO switches/LEDs")));
184
});
185
186
if (PSP_CoreParameter().fileType != IdentifiedFileType::PPSSPP_GE_DUMP) {
187
items->Add(new Choice(dev->T("Create frame dump")))->OnClick.Add([](UI::EventParams &e) {
188
SaveFrameDump();
189
});
190
}
191
192
// This one is not very useful these days, and only really on desktop. Hide it on other platforms.
193
if (System_GetPropertyInt(SYSPROP_DEVICE_TYPE) == DEVICE_TYPE_DESKTOP) {
194
items->Add(new Choice(dev->T("Dump next frame to log")))->OnClick.Add([](UI::EventParams &e) {
195
gpu->DumpNextFrame();
196
});
197
}
198
199
scroll->Add(items);
200
parent->Add(scroll);
201
202
g_logManager.EnableOutput(LogOutput::RingBuffer);
203
}
204
205
void DevMenuScreen::OnResetLimitedLogging(UI::EventParams &e) {
206
Reporting::ResetCounts();
207
}
208
209
void DevMenuScreen::OnDeveloperTools(UI::EventParams &e) {
210
UpdateUIState(UISTATE_PAUSEMENU);
211
screenManager()->push(new DeveloperToolsScreen(gamePath_));
212
}
213
214
void DevMenuScreen::OnJitCompare(UI::EventParams &e) {
215
UpdateUIState(UISTATE_PAUSEMENU);
216
screenManager()->push(new JitCompareScreen());
217
}
218
219
void DevMenuScreen::OnShaderView(UI::EventParams &e) {
220
UpdateUIState(UISTATE_PAUSEMENU);
221
if (gpu) // Avoid crashing if chosen while the game is being loaded.
222
screenManager()->push(new ShaderListScreen());
223
}
224
225
void DevMenuScreen::dialogFinished(const Screen *dialog, DialogResult result) {
226
UpdateUIState(UISTATE_INGAME);
227
// Close when a subscreen got closed.
228
// TODO: a bug in screenmanager causes this not to work here.
229
// TriggerFinish(DR_OK);
230
}
231
232
void GPIGPOScreen::CreatePopupContents(UI::ViewGroup *parent) {
233
using namespace UI;
234
auto dev = GetI18NCategory(I18NCat::DEVELOPER);
235
parent->Add(new CheckBox(&g_Config.bShowGPOLEDs, dev->T("Show GPO LEDs")));
236
for (int i = 0; i < 8; i++) {
237
std::string name = ApplySafeSubstitutions(dev->T("GPI switch %1"), i);
238
parent->Add(new BitCheckBox(&g_GPIBits, 1 << i, name));
239
}
240
}
241
242
void LogViewScreen::UpdateLog() {
243
using namespace UI;
244
const RingbufferLog &ring = g_logManager.GetRingbuffer();
245
vert_->Clear();
246
247
// TODO: Direct rendering without TextViews.
248
for (int i = ring.GetCount() - 1; i >= 0; i--) {
249
TextView *v = vert_->Add(new TextView(StripSpaces(ring.TextAt(i)), FLAG_DYNAMIC_ASCII, true));
250
uint32_t color = LogManager::GetLevelColor(ring.LevelAt(i));
251
v->SetTextColor(0xFF000000 | color);
252
}
253
toBottom_ = true;
254
}
255
256
void LogViewScreen::update() {
257
UIBaseDialogScreen::update();
258
if (toBottom_) {
259
toBottom_ = false;
260
scroll_->ScrollToBottom();
261
}
262
}
263
264
void LogViewScreen::CreateViews() {
265
using namespace UI;
266
auto di = GetI18NCategory(I18NCat::DIALOG);
267
268
LinearLayout *outer = new LinearLayout(ORIENT_VERTICAL, new LinearLayoutParams(FILL_PARENT, WRAP_CONTENT));
269
root_ = outer;
270
271
scroll_ = outer->Add(new ScrollView(ORIENT_VERTICAL, new LinearLayoutParams(1.0)));
272
LinearLayout *bottom = outer->Add(new LinearLayout(ORIENT_HORIZONTAL, new LayoutParams(FILL_PARENT, WRAP_CONTENT)));
273
bottom->Add(new Button(di->T("Back")))->OnClick.Handle<UIScreen>(this, &UIScreen::OnBack);
274
275
vert_ = scroll_->Add(new LinearLayout(ORIENT_VERTICAL, new LinearLayoutParams(FILL_PARENT, WRAP_CONTENT)));
276
vert_->SetSpacing(0);
277
278
UpdateLog();
279
}
280
281
std::string_view LogConfigScreen::GetTitle() const {
282
auto dev = GetI18NCategory(I18NCat::DEVELOPER);
283
return dev->T("Logging Channels");
284
}
285
286
void LogConfigScreen::CreateSettingsViews(UI::ViewGroup *parent) {
287
using namespace UI;
288
289
auto di = GetI18NCategory(I18NCat::DIALOG);
290
auto dev = GetI18NCategory(I18NCat::DEVELOPER);
291
292
parent->Add(new Choice(di->T("Toggle All")))->OnClick.Handle(this, &LogConfigScreen::OnToggleAll);
293
parent->Add(new Choice(di->T("Enable All")))->OnClick.Handle(this, &LogConfigScreen::OnEnableAll);
294
parent->Add(new Choice(di->T("Disable All")))->OnClick.Handle(this, &LogConfigScreen::OnDisableAll);
295
parent->Add(new Choice(dev->T("Log Level")))->OnClick.Handle(this, &LogConfigScreen::OnLogLevel);
296
}
297
298
void LogConfigScreen::CreateContentViews(UI::ViewGroup *parent) {
299
using namespace UI;
300
301
auto di = GetI18NCategory(I18NCat::DIALOG);
302
auto dev = GetI18NCategory(I18NCat::DEVELOPER);
303
304
int cellSize = 350;
305
306
UI::GridLayoutSettings gridsettings(cellSize, 64, 5);
307
gridsettings.fillCells = true;
308
GridLayout *grid = parent->Add(new GridLayoutList(gridsettings, new LayoutParams(FILL_PARENT, WRAP_CONTENT)));
309
310
for (int i = 0; i < LogManager::GetNumChannels(); i++) {
311
Log type = (Log)i;
312
LogChannel *chan = g_logManager.GetLogChannel(type);
313
LinearLayout *row = new LinearLayout(ORIENT_HORIZONTAL, new LinearLayoutParams(cellSize - 50, WRAP_CONTENT));
314
row->SetSpacing(0);
315
row->Add(new CheckBox(&chan->enabled, "", "", new LinearLayoutParams(50, WRAP_CONTENT)));
316
row->Add(new PopupMultiChoice((int *)&chan->level, LogManager::GetLogTypeName(type), logLevelList, 1, 6, I18NCat::NONE, screenManager(), new LinearLayoutParams(1.0)));
317
grid->Add(row);
318
}
319
}
320
321
void LogConfigScreen::OnToggleAll(UI::EventParams &e) {
322
for (int i = 0; i < LogManager::GetNumChannels(); i++) {
323
LogChannel *chan = g_logManager.GetLogChannel((Log)i);
324
chan->enabled = !chan->enabled;
325
}
326
}
327
328
void LogConfigScreen::OnEnableAll(UI::EventParams &e) {
329
for (int i = 0; i < LogManager::GetNumChannels(); i++) {
330
LogChannel *chan = g_logManager.GetLogChannel((Log)i);
331
chan->enabled = true;
332
}
333
}
334
335
void LogConfigScreen::OnDisableAll(UI::EventParams &e) {
336
for (int i = 0; i < LogManager::GetNumChannels(); i++) {
337
LogChannel *chan = g_logManager.GetLogChannel((Log)i);
338
chan->enabled = false;
339
}
340
}
341
342
void LogConfigScreen::OnLogLevelChange(UI::EventParams &e) {
343
RecreateViews();
344
}
345
346
void LogConfigScreen::OnLogLevel(UI::EventParams &e) {
347
auto dev = GetI18NCategory(I18NCat::DEVELOPER);
348
349
auto logLevelScreen = new LogLevelScreen(dev->T("Log Level"));
350
logLevelScreen->OnChoice.Handle(this, &LogConfigScreen::OnLogLevelChange);
351
if (e.v)
352
logLevelScreen->SetPopupOrigin(e.v);
353
screenManager()->push(logLevelScreen);
354
}
355
356
LogLevelScreen::LogLevelScreen(std::string_view title) : ListPopupScreen(title) {
357
int NUMLOGLEVEL = 6;
358
std::vector<std::string> list;
359
for (int i = 0; i < NUMLOGLEVEL; ++i) {
360
list.push_back(logLevelList[i]);
361
}
362
adaptor_ = UI::StringVectorListAdaptor(list, -1);
363
364
// CreateViews takes care of, well, that.
365
}
366
367
void LogLevelScreen::OnCompleted(DialogResult result) {
368
if (result != DR_OK)
369
return;
370
int selected = listView_->GetSelected();
371
372
for (int i = 0; i < LogManager::GetNumChannels(); ++i) {
373
Log type = (Log)i;
374
LogChannel *chan = g_logManager.GetLogChannel(type);
375
if (chan->enabled)
376
chan->level = (LogLevel)(selected + 1);
377
}
378
}
379
380
struct JitDisableFlag {
381
MIPSComp::JitDisable flag;
382
const char *name;
383
};
384
385
// Please do not try to translate these :)
386
static const JitDisableFlag jitDisableFlags[] = {
387
{ MIPSComp::JitDisable::ALU, "ALU" },
388
{ MIPSComp::JitDisable::ALU_IMM, "ALU_IMM" },
389
{ MIPSComp::JitDisable::ALU_BIT, "ALU_BIT" },
390
{ MIPSComp::JitDisable::MULDIV, "MULDIV" },
391
{ MIPSComp::JitDisable::FPU, "FPU" },
392
{ MIPSComp::JitDisable::FPU_COMP, "FPU_COMP" },
393
{ MIPSComp::JitDisable::FPU_XFER, "FPU_XFER" },
394
{ MIPSComp::JitDisable::VFPU_VEC, "VFPU_VEC" },
395
{ MIPSComp::JitDisable::VFPU_MTX_VTFM, "VFPU_MTX_VTFM" },
396
{ MIPSComp::JitDisable::VFPU_MTX_VMSCL, "VFPU_MTX_VMSCL" },
397
{ MIPSComp::JitDisable::VFPU_MTX_VMMUL, "VFPU_MTX_VMMUL" },
398
{ MIPSComp::JitDisable::VFPU_MTX_VMMOV, "VFPU_MTX_VMMOV" },
399
{ MIPSComp::JitDisable::VFPU_COMP, "VFPU_COMP" },
400
{ MIPSComp::JitDisable::VFPU_XFER, "VFPU_XFER" },
401
{ MIPSComp::JitDisable::LSU, "LSU" },
402
{ MIPSComp::JitDisable::LSU_UNALIGNED, "LSU_UNALIGNED" },
403
{ MIPSComp::JitDisable::LSU_FPU, "LSU_FPU" },
404
{ MIPSComp::JitDisable::LSU_VFPU, "LSU_VFPU" },
405
{ MIPSComp::JitDisable::SIMD, "SIMD" },
406
{ MIPSComp::JitDisable::BLOCKLINK, "Block Linking" },
407
{ MIPSComp::JitDisable::POINTERIFY, "Pointerify" },
408
{ MIPSComp::JitDisable::STATIC_ALLOC, "Static regalloc" },
409
{ MIPSComp::JitDisable::CACHE_POINTERS, "Cached pointers" },
410
{ MIPSComp::JitDisable::REGALLOC_GPR, "GPR Regalloc across instructions" },
411
{ MIPSComp::JitDisable::REGALLOC_FPR, "FPR Regalloc across instructions" },
412
};
413
414
void JitDebugScreen::CreateViews() {
415
using namespace UI;
416
417
auto di = GetI18NCategory(I18NCat::DIALOG);
418
auto dev = GetI18NCategory(I18NCat::DEVELOPER);
419
420
root_ = new ScrollView(ORIENT_VERTICAL);
421
422
LinearLayout *vert = root_->Add(new LinearLayout(ORIENT_VERTICAL, new LinearLayoutParams(FILL_PARENT, WRAP_CONTENT)));
423
vert->SetSpacing(0);
424
425
LinearLayout *topbar = new LinearLayout(ORIENT_HORIZONTAL);
426
topbar->Add(new Choice(ImageID("I_NAVIGATE_BACK")))->OnClick.Handle<UIScreen>(this, &UIScreen::OnBack);
427
topbar->Add(new Choice(di->T("Disable All")))->OnClick.Handle(this, &JitDebugScreen::OnDisableAll);
428
topbar->Add(new Choice(di->T("Enable All")))->OnClick.Handle(this, &JitDebugScreen::OnEnableAll);
429
430
vert->Add(topbar);
431
vert->Add(new ItemHeader(dev->T("Disabled JIT functionality")));
432
433
for (auto flag : jitDisableFlags) {
434
// Do not add translation of these.
435
vert->Add(new BitCheckBox(&g_Config.uJitDisableFlags, (uint32_t)flag.flag, flag.name));
436
}
437
}
438
439
void JitDebugScreen::OnEnableAll(UI::EventParams &e) {
440
g_Config.uJitDisableFlags &= ~(uint32_t)MIPSComp::JitDisable::ALL_FLAGS;
441
}
442
443
void JitDebugScreen::OnDisableAll(UI::EventParams &e) {
444
g_Config.uJitDisableFlags |= (uint32_t)MIPSComp::JitDisable::ALL_FLAGS;
445
}
446
447
int ShaderListScreen::ListShaders(DebugShaderType shaderType, UI::LinearLayout *view) {
448
using namespace UI;
449
std::vector<std::string> shaderIds_ = gpu->DebugGetShaderIDs(shaderType);
450
int count = 0;
451
for (const auto &id : shaderIds_) {
452
Choice *choice = view->Add(new Choice(gpu->DebugGetShaderString(id, shaderType, SHADER_STRING_SHORT_DESC)));
453
choice->SetTag(id);
454
choice->SetDrawTextFlags(FLAG_DYNAMIC_ASCII);
455
choice->OnClick.Handle(this, &ShaderListScreen::OnShaderClick);
456
count++;
457
}
458
return count;
459
}
460
461
struct { DebugShaderType type; const char *name; } shaderTypes[] = {
462
{ SHADER_TYPE_VERTEX, "Vertex" },
463
{ SHADER_TYPE_FRAGMENT, "Fragment" },
464
{ SHADER_TYPE_GEOMETRY, "Geometry" },
465
{ SHADER_TYPE_VERTEXLOADER, "VertexLoader" },
466
{ SHADER_TYPE_PIPELINE, "Pipeline" },
467
{ SHADER_TYPE_TEXTURE, "Texture" },
468
{ SHADER_TYPE_SAMPLER, "Sampler" },
469
};
470
471
void ShaderListScreen::CreateTabs() {
472
using namespace UI;
473
474
for (size_t i = 0; i < ARRAY_SIZE(shaderTypes); i++) {
475
int count = (int)gpu->DebugGetShaderIDs(shaderTypes[i].type).size();
476
AddTab(shaderTypes[i].name, StringFromFormat("%s (%d)", shaderTypes[i].name, count), [this, i](UI::LinearLayout *tabContent) {
477
LinearLayout *shaderList = new LinearLayoutList(ORIENT_VERTICAL, new LayoutParams(FILL_PARENT, WRAP_CONTENT));
478
int count = ListShaders(shaderTypes[i].type, shaderList);
479
tabContent->Add(shaderList);
480
});
481
}
482
}
483
484
void ShaderListScreen::OnShaderClick(UI::EventParams &e) {
485
using namespace UI;
486
std::string id = e.v->Tag();
487
DebugShaderType type = shaderTypes[GetCurrentTab()].type;
488
screenManager()->push(new ShaderViewScreen(id, type));
489
}
490
491
void ShaderViewScreen::CreateViews() {
492
using namespace UI;
493
494
auto di = GetI18NCategory(I18NCat::DIALOG);
495
496
LinearLayout *layout = new LinearLayout(ORIENT_VERTICAL);
497
root_ = layout;
498
499
LinearLayout *topbar = new LinearLayout(ORIENT_HORIZONTAL);
500
topbar->Add(new Choice(ImageID("I_NAVIGATE_BACK"), new LinearLayoutParams()))->OnClick.Handle<UIScreen>(this, &UIScreen::OnBack);
501
topbar->Add(new Choice(ImageID("I_FILE_COPY"), new LinearLayoutParams()))->OnClick.Add([this](UI::EventParams &e) {
502
System_CopyStringToClipboard(gpu->DebugGetShaderString(id_, type_, SHADER_STRING_SHORT_DESC));
503
});
504
topbar->Add(new TextView(gpu->DebugGetShaderString(id_, type_, SHADER_STRING_SHORT_DESC), FLAG_DYNAMIC_ASCII | FLAG_WRAP_TEXT, false));
505
layout->Add(topbar);
506
507
ScrollView *scroll = new ScrollView(ORIENT_VERTICAL, new LinearLayoutParams(1.0));
508
scroll->SetTag("DevShaderView");
509
layout->Add(scroll);
510
511
LinearLayout *lineLayout = new LinearLayoutList(ORIENT_VERTICAL, new LinearLayoutParams(FILL_PARENT, WRAP_CONTENT));
512
lineLayout->SetSpacing(0.0);
513
scroll->Add(lineLayout);
514
515
std::vector<std::string> lines;
516
SplitString(gpu->DebugGetShaderString(id_, type_, SHADER_STRING_SOURCE_CODE), '\n', lines);
517
518
for (const auto &line : lines) {
519
lineLayout->Add(new TextView(line, FLAG_DYNAMIC_ASCII | FLAG_WRAP_TEXT, true));
520
}
521
}
522
523
bool ShaderViewScreen::key(const KeyInput &ki) {
524
if (ki.flags & KeyInputFlags::CHAR) {
525
if (ki.unicodeChar == 'C' || ki.unicodeChar == 'c') {
526
System_CopyStringToClipboard(gpu->DebugGetShaderString(id_, type_, SHADER_STRING_SHORT_DESC));
527
}
528
}
529
return UIBaseDialogScreen::key(ki);
530
}
531
532
533
const std::string framedumpsBaseUrl = "http://framedump.ppsspp.org/repro/";
534
535
FrameDumpTestScreen::~FrameDumpTestScreen() {
536
g_DownloadManager.CancelAll();
537
}
538
539
void FrameDumpTestScreen::CreateTabs() {
540
using namespace UI;
541
542
auto di = GetI18NCategory(I18NCat::DIALOG);
543
auto dev = GetI18NCategory(I18NCat::DEVELOPER);
544
545
AddTab("General", dev->T("Dumps"), [this](UI::LinearLayout *parent) {
546
parent->Add(new ItemHeader("GE Frame Dumps"));
547
548
for (auto &file : files_) {
549
std::string url = framedumpsBaseUrl + file;
550
Choice *c = parent->Add(new Choice(file));
551
c->SetTag(url);
552
c->OnClick.Handle<FrameDumpTestScreen>(this, &FrameDumpTestScreen::OnLoadDump);
553
}
554
});
555
556
EnsureTabs();
557
}
558
559
void FrameDumpTestScreen::OnLoadDump(UI::EventParams &params) {
560
Path url = Path(params.v->Tag());
561
INFO_LOG(Log::Common, "Trying to launch '%s'", url.c_str());
562
// Our disc streaming functionality detects the URL and takes over and handles loading framedumps well,
563
// except for some reason the game ID.
564
// TODO: Fix that since it can be important for compat settings.
565
screenManager()->switchScreen(new EmuScreen(url));
566
}
567
568
void FrameDumpTestScreen::update() {
569
UIScreen::update();
570
571
if (!listing_) {
572
const char *acceptMime = "text/html, */*; q=0.8";
573
listing_ = g_DownloadManager.StartDownload(framedumpsBaseUrl, Path(), http::RequestFlags::ProgressBar | http::RequestFlags::ProgressBarDelayed, acceptMime);
574
}
575
576
if (listing_ && listing_->Done() && files_.empty()) {
577
if (listing_->ResultCode() == 200) {
578
std::string listingHtml;
579
listing_->buffer().TakeAll(&listingHtml);
580
581
std::vector<std::string> lines;
582
// We rely slightly on nginx listing format here. Not great.
583
SplitString(listingHtml, '\n', lines);
584
for (auto &line : lines) {
585
std::string trimmed(StripSpaces(line));
586
if (startsWith(trimmed, "<a href=\"")) {
587
trimmed = trimmed.substr(strlen("<a href=\""));
588
size_t offset = trimmed.find('\"');
589
if (offset != std::string::npos) {
590
trimmed = trimmed.substr(0, offset);
591
if (endsWith(trimmed, ".ppdmp")) {
592
INFO_LOG(Log::Common, "Found ppdmp: '%s'", trimmed.c_str());
593
files_.push_back(trimmed);
594
}
595
}
596
}
597
}
598
} else {
599
// something went bad. Too lazy to make UI, so let's just finish this screen.
600
TriggerFinish(DialogResult::DR_CANCEL);
601
}
602
RecreateViews();
603
}
604
}
605
606
void TouchTestScreen::touch(const TouchInput &touch) {
607
UIBaseDialogScreen::touch(touch);
608
if (touch.flags & TouchInputFlags::DOWN) {
609
bool found = false;
610
for (int i = 0; i < MAX_TOUCH_POINTS; i++) {
611
if (touches_[i].id == touch.id) {
612
WARN_LOG(Log::System, "Double touch");
613
touches_[i].x = touch.x;
614
touches_[i].y = touch.y;
615
found = true;
616
}
617
}
618
if (!found) {
619
for (int i = 0; i < MAX_TOUCH_POINTS; i++) {
620
if (touches_[i].id == -1) {
621
touches_[i].id = touch.id;
622
touches_[i].x = touch.x;
623
touches_[i].y = touch.y;
624
break;
625
}
626
}
627
}
628
}
629
if (touch.flags & TouchInputFlags::MOVE) {
630
bool found = false;
631
for (int i = 0; i < MAX_TOUCH_POINTS; i++) {
632
if (touches_[i].id == touch.id) {
633
touches_[i].x = touch.x;
634
touches_[i].y = touch.y;
635
found = true;
636
}
637
}
638
if (!found && touch.buttons) {
639
WARN_LOG(Log::System, "Move with buttons %d without touch down: %d", touch.buttons, touch.id);
640
}
641
}
642
if (touch.flags & TouchInputFlags::UP) {
643
bool found = false;
644
for (int i = 0; i < MAX_TOUCH_POINTS; i++) {
645
if (touches_[i].id == touch.id) {
646
found = true;
647
touches_[i].id = -1;
648
break;
649
}
650
}
651
if (!found) {
652
WARN_LOG(Log::System, "Touch release without touch down");
653
}
654
}
655
}
656
657
// TODO: Move this screen out into its own file.
658
void TouchTestScreen::CreateViews() {
659
using namespace UI;
660
661
auto di = GetI18NCategory(I18NCat::DIALOG);
662
auto gr = GetI18NCategory(I18NCat::GRAPHICS);
663
root_ = new LinearLayout(ORIENT_VERTICAL);
664
LinearLayout *theTwo = new LinearLayout(ORIENT_VERTICAL, new LinearLayoutParams(1.0f));
665
666
// TODO: This one should use DYNAMIC_ASCII. Though doesn't matter much.
667
lastKeyEvents_ = theTwo->Add(new TextView("-", new LayoutParams(FILL_PARENT, WRAP_CONTENT)));
668
669
root_->Add(theTwo);
670
671
#if !PPSSPP_PLATFORM(UWP)
672
static const char *renderingBackend[] = { "OpenGL", "(n/a)", "Direct3D 11", "Vulkan" };
673
PopupMultiChoice *renderingBackendChoice = root_->Add(new PopupMultiChoice(&g_Config.iGPUBackend, gr->T("Backend"), renderingBackend, (int)GPUBackend::OPENGL, ARRAY_SIZE(renderingBackend), I18NCat::GRAPHICS, screenManager()));
674
renderingBackendChoice->OnChoice.Handle(this, &TouchTestScreen::OnRenderingBackend);
675
676
if (!g_Config.IsBackendEnabled(GPUBackend::OPENGL))
677
renderingBackendChoice->HideChoice((int)GPUBackend::OPENGL);
678
renderingBackendChoice->HideChoice(1); // previously D3D9
679
if (!g_Config.IsBackendEnabled(GPUBackend::DIRECT3D11))
680
renderingBackendChoice->HideChoice((int)GPUBackend::DIRECT3D11);
681
if (!g_Config.IsBackendEnabled(GPUBackend::VULKAN))
682
renderingBackendChoice->HideChoice((int)GPUBackend::VULKAN);
683
#endif
684
685
#if PPSSPP_PLATFORM(ANDROID)
686
root_->Add(new Choice(gr->T("Recreate Activity")))->OnClick.Handle(this, &TouchTestScreen::OnRecreateActivity);
687
#endif
688
root_->Add(new Button(di->T("Back"), new LinearLayoutParams(FILL_PARENT, 64, Margins(10, 0))))->OnClick.Handle<UIScreen>(this, &UIScreen::OnBack);
689
}
690
691
void TouchTestScreen::UpdateLogView() {
692
while (keyEventLog_.size() > 8) {
693
keyEventLog_.erase(keyEventLog_.begin());
694
}
695
696
std::string text;
697
for (auto &iter : keyEventLog_) {
698
text += iter + "\n";
699
}
700
701
if (lastKeyEvents_) {
702
lastKeyEvents_->SetText(text);
703
}
704
}
705
706
bool TouchTestScreen::key(const KeyInput &key) {
707
UIScreen::key(key);
708
char buf[512];
709
snprintf(buf, sizeof(buf), "%s (%d) Device ID: %d [%s%s%s%s]", KeyMap::GetKeyName(key.keyCode).c_str(), key.keyCode, key.deviceId,
710
(key.flags & KeyInputFlags::IS_REPEAT) ? "REP" : "",
711
(key.flags & KeyInputFlags::UP) ? "UP" : "",
712
(key.flags & KeyInputFlags::DOWN) ? "DOWN" : "",
713
(key.flags & KeyInputFlags::CHAR) ? "CHAR" : "");
714
keyEventLog_.push_back(buf);
715
UpdateLogView();
716
return true;
717
}
718
719
void TouchTestScreen::axis(const AxisInput &axis) {
720
if (axis.deviceId == DEVICE_ID_MOUSE && (axis.axisId == JOYSTICK_AXIS_MOUSE_REL_X || axis.axisId == JOYSTICK_AXIS_MOUSE_REL_Y)) {
721
// These spam a lot, don't log for now.
722
return;
723
}
724
725
char buf[512];
726
snprintf(buf, sizeof(buf), "Axis: %s (%d) (value %1.3f) Device ID: %d",
727
KeyMap::GetAxisName(axis.axisId).c_str(), axis.axisId, axis.value, axis.deviceId);
728
729
keyEventLog_.push_back(buf);
730
if (keyEventLog_.size() > 8) {
731
keyEventLog_.erase(keyEventLog_.begin());
732
}
733
UpdateLogView();
734
}
735
736
void TouchTestScreen::DrawForeground(UIContext &dc) {
737
Bounds bounds = dc.GetLayoutBounds();
738
739
double now = dc.FrameStartTime();
740
double delta = now - lastFrameTime_;
741
lastFrameTime_ = now;
742
743
dc.BeginNoTex();
744
for (int i = 0; i < MAX_TOUCH_POINTS; i++) {
745
if (touches_[i].id != -1) {
746
dc.Draw()->Circle(touches_[i].x, touches_[i].y, 100.0, 3.0, 80, 0.0f, 0xFFFFFFFF, 1.0);
747
}
748
}
749
dc.Flush();
750
751
dc.Begin();
752
753
char buffer[4096];
754
for (int i = 0; i < MAX_TOUCH_POINTS; i++) {
755
if (touches_[i].id != -1) {
756
dc.Draw()->Circle(touches_[i].x, touches_[i].y, 100.0, 3.0, 80, 0.0f, 0xFFFFFFFF, 1.0);
757
snprintf(buffer, sizeof(buffer), "%0.1fx%0.1f", touches_[i].x, touches_[i].y);
758
dc.DrawText(buffer, touches_[i].x, touches_[i].y + (touches_[i].y > g_display.dp_yres - 100.0f ? -135.0f : 95.0f), 0xFFFFFFFF, ALIGN_HCENTER | FLAG_DYNAMIC_ASCII);
759
}
760
}
761
762
char extra_debug[2048]{};
763
truncate_cpy(extra_debug, Android_GetInputDeviceDebugString());
764
765
snprintf(buffer, sizeof(buffer),
766
"display_res: %dx%d\n"
767
"dp_res: %dx%d pixel_res: %dx%d\n"
768
"dpi_scale: %0.3fx%0.3f\n"
769
"dpi_scale_real: %0.3fx%0.3f\n"
770
"delta: %0.2f ms fps: %0.3f\n%s",
771
(int)System_GetPropertyInt(SYSPROP_DISPLAY_XRES), (int)System_GetPropertyInt(SYSPROP_DISPLAY_YRES),
772
g_display.dp_xres, g_display.dp_yres, g_display.pixel_xres, g_display.pixel_yres,
773
g_display.dpi_scale_x, g_display.dpi_scale_y,
774
g_display.dpi_scale_real_x, g_display.dpi_scale_real_y,
775
delta * 1000.0, 1.0 / delta,
776
extra_debug);
777
778
// On Android, also add joystick debug data.
779
dc.DrawTextShadow(buffer, bounds.centerX(), bounds.y + 20.0f, 0xFFFFFFFF, FLAG_DYNAMIC_ASCII);
780
dc.Flush();
781
}
782
783
void RecreateActivity() {
784
const int SYSTEM_JELLYBEAN = 16;
785
if (System_GetPropertyInt(SYSPROP_SYSTEMVERSION) >= SYSTEM_JELLYBEAN) {
786
INFO_LOG(Log::System, "Sending recreate");
787
System_Notify(SystemNotification::FORCE_RECREATE_ACTIVITY);
788
INFO_LOG(Log::System, "Got back from recreate");
789
} else {
790
auto gr = GetI18NCategory(I18NCat::GRAPHICS);
791
System_Toast(gr->T_cstr("Must Restart", "You must restart PPSSPP for this change to take effect"));
792
}
793
}
794
795
void TouchTestScreen::OnImmersiveModeChange(UI::EventParams &e) {
796
System_Notify(SystemNotification::IMMERSIVE_MODE_CHANGE);
797
if (g_Config.iAndroidHwScale != 0) {
798
RecreateActivity();
799
}
800
}
801
802
void TouchTestScreen::OnRenderingBackend(UI::EventParams &e) {
803
g_Config.Save("GameSettingsScreen::RenderingBackend");
804
System_RestartApp("--touchscreentest");
805
}
806
807
void TouchTestScreen::OnRecreateActivity(UI::EventParams &e) {
808
RecreateActivity();
809
}
810
811