Permalink
Browse files

GE Debugger: Allow image export from previews.

This allows exporting textures and half-drawn surfaces.
  • Loading branch information...
unknownbrackets committed Dec 21, 2017
1 parent 79dc857 commit 092cbc2343679248eb64374258aa25f820ca4788
@@ -21,12 +21,15 @@
#include <vector>
#include "Common/ColorConv.h"
#include "Core/Config.h"
#include "Core/Screenshot.h"
#include "Windows/GEDebugger/GEDebugger.h"
#include "Windows/GEDebugger/SimpleGLWindow.h"
#include "Windows/GEDebugger/CtrlDisplayListView.h"
#include "Windows/GEDebugger/TabDisplayLists.h"
#include "Windows/GEDebugger/TabState.h"
#include "Windows/GEDebugger/TabVertices.h"
#include "Windows/W32Util/ShellUtil.h"
#include "Windows/InputBox.h"
#include "Windows/WindowsHost.h"
#include "Windows/MainWindow.h"
@@ -38,10 +41,11 @@
#include "GPU/Debugger/Breakpoints.h"
#include "GPU/Debugger/Record.h"
#include "GPU/Debugger/Stepping.h"
#include "Core/Config.h"
#include <windowsx.h>
#include <commctrl.h>
const int POPUP_SUBMENU_ID_GEDBG_PREVIEW = 10;
using namespace GPUBreakpoints;
using namespace GPUStepping;
@@ -145,19 +149,45 @@ CGEDebugger::~CGEDebugger() {
void CGEDebugger::SetupPreviews() {
if (primaryWindow == nullptr) {
HMENU subMenu = GetSubMenu(g_hPopupMenus, POPUP_SUBMENU_ID_GEDBG_PREVIEW);
primaryWindow = SimpleGLWindow::GetFrom(GetDlgItem(m_hDlg, IDC_GEDBG_FRAME));
primaryWindow->Initialize(SimpleGLWindow::ALPHA_IGNORE | SimpleGLWindow::RESIZE_SHRINK_CENTER);
primaryWindow->SetHoverCallback([&] (int x, int y) {
PrimaryPreviewHover(x, y);
});
primaryWindow->SetRightClickMenu(subMenu, [&] (int cmd) {
switch (cmd) {
case ID_GEDBG_EXPORT_IMAGE:
PreviewExport(primaryBuffer_);
break;
default:
break;
}
return true;
});
primaryWindow->Clear();
}
if (secondWindow == nullptr) {
HMENU subMenu = GetSubMenu(g_hPopupMenus, POPUP_SUBMENU_ID_GEDBG_PREVIEW);
secondWindow = SimpleGLWindow::GetFrom(GetDlgItem(m_hDlg, IDC_GEDBG_TEX));
secondWindow->Initialize(SimpleGLWindow::ALPHA_BLEND | SimpleGLWindow::RESIZE_SHRINK_CENTER);
secondWindow->SetHoverCallback([&] (int x, int y) {
SecondPreviewHover(x, y);
});
secondWindow->SetRightClickMenu(subMenu, [&] (int cmd) {
switch (cmd) {
case ID_GEDBG_EXPORT_IMAGE:
PreviewExport(secondBuffer_);
break;
default:
break;
}
return true;
});
secondWindow->Clear();
}
}
@@ -194,6 +224,23 @@ void CGEDebugger::DescribeSecondPreview(const GPUgstate &state, wchar_t desc[256
}
}
void CGEDebugger::PreviewExport(const GPUDebugBuffer *dbgBuffer) {
const TCHAR *filter = L"PNG Image (*.png)\0*.png\0JPEG Image (*.jpg)\0*.jpg\0All files\0*.*\0\0";
std::string fn;
if (W32Util::BrowseForFileName(false, GetDlgHandle(), L"Save Preview Image...", nullptr, filter, L"png", fn)) {
ScreenshotFormat fmt = fn.find(".jpg") != fn.npos ? ScreenshotFormat::JPG : ScreenshotFormat::PNG;
u8 *flipbuffer = nullptr;
u32 w = (u32)-1;
u32 h = (u32)-1;
const u8 *buffer = ConvertBufferTo888RGB(*dbgBuffer, flipbuffer, w, h);
if (buffer != nullptr) {
Save888RGBScreenshot(fn.c_str(), fmt, buffer, w, h);
}
delete [] flipbuffer;
}
}
void CGEDebugger::UpdatePreviews() {
auto memLock = Memory::Lock();
if (!PSP_IsInited()) {
@@ -80,6 +80,7 @@ class CGEDebugger : public Dialog {
void DescribeSecondPreview(const GPUgstate &state, wchar_t desc[256]);
void PrimaryPreviewHover(int x, int y);
void SecondPreviewHover(int x, int y);
void PreviewExport(const GPUDebugBuffer *buffer);
void DescribePixel(u32 pix, GPUDebugBufferFormat fmt, int x, int y, wchar_t desc[256]);
void DescribePixelRGBA(u32 pix, GPUDebugBufferFormat fmt, int x, int y, wchar_t desc[256]);
@@ -541,6 +541,22 @@ bool SimpleGLWindow::Leave() {
return true;
}
bool SimpleGLWindow::RightClick(int mouseX, int mouseY) {
if (rightClickCallback_ == nullptr) {
return false;
}
POINT pt{mouseX, mouseY};
ClientToScreen(hWnd_, &pt);
int result = TrackPopupMenuEx(rightClickMenu_, TPM_RIGHTBUTTON | TPM_RETURNCMD, pt.x, pt.y, hWnd_, 0);
if (result != 0) {
rightClickCallback_(result);
}
return true;
}
const u8 *SimpleGLWindow::Reformat(const u8 *data, Format fmt, u32 numPixels) {
if (!reformatBuf_ || reformatBufSize_ < numPixels) {
delete [] reformatBuf_;
@@ -587,6 +603,7 @@ LRESULT CALLBACK SimpleGLWindow::WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPA
switch (msg) {
case WM_LBUTTONDOWN:
case WM_LBUTTONUP:
case WM_RBUTTONUP:
case WM_MOUSEMOVE:
mouseX = GET_X_LPARAM(lParam);
mouseY = GET_Y_LPARAM(lParam);
@@ -633,6 +650,12 @@ LRESULT CALLBACK SimpleGLWindow::WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPA
}
break;
case WM_RBUTTONUP:
if (win->RightClick(mouseX, mouseY)) {
return 0;
}
break;
case WM_MOUSELEAVE:
if (win->Leave()) {
return 0;
@@ -645,4 +668,4 @@ LRESULT CALLBACK SimpleGLWindow::WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPA
}
return DefWindowProc(hwnd, msg, wParam, lParam);
}
}
@@ -110,6 +110,11 @@ struct SimpleGLWindow {
hoverCallback_ = hoverCallback;
}
void SetRightClickMenu(HMENU menu, std::function<void(int)> callback) {
rightClickCallback_ = callback;
rightClickMenu_ = menu;
}
static void RegisterClass();
protected:
void SetupGL();
@@ -122,6 +127,7 @@ struct SimpleGLWindow {
bool DragEnd(int mouseX, int mouseY);
bool Hover(int mouseX, int mouseY);
bool Leave();
bool RightClick(int mouseX, int mouseY);
bool ToggleZoom();
const u8 *Reformat(const u8 *data, Format fmt, u32 numPixels);
@@ -157,4 +163,6 @@ struct SimpleGLWindow {
u32 reformatBufSize_;
std::function<void(int, int)> hoverCallback_;
std::function<void(int)> rightClickCallback_;
HMENU rightClickMenu_;
};
View
@@ -654,6 +654,10 @@ BEGIN
MENUITEM "Toggle Breakpoint", ID_DISASM_TOGGLEBREAKPOINT
MENUITEM "Add Watch", ID_GEDBG_WATCH
END
POPUP "gepreviewoptions"
BEGIN
MENUITEM "Export Image...", ID_GEDBG_EXPORT_IMAGE
END
END
#endif // English (United States) resources
View
@@ -334,6 +334,7 @@
#define ID_FILE_DUMPAUDIO 40167
#define ID_HELP_GITHUB 40168
#define IDC_GEDBG_RECORD 40169
#define ID_GEDBG_EXPORT_IMAGE 40170
// Dummy option to let the buffered rendering hotkey cycle through all the options.
#define ID_OPTIONS_BUFFEREDRENDERINGDUMMY 40500
@@ -346,7 +347,7 @@
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 256
#define _APS_NEXT_COMMAND_VALUE 40170
#define _APS_NEXT_COMMAND_VALUE 40171
#define _APS_NEXT_CONTROL_VALUE 1200
#define _APS_NEXT_SYMED_VALUE 101
#endif

0 comments on commit 092cbc2

Please sign in to comment.