-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWin32ThreadedApplicationService.h
131 lines (110 loc) · 4.93 KB
/
Win32ThreadedApplicationService.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/*
Copyright (c) 2015-2021 hkrn All rights reserved
This file is part of emapp component and it's licensed under Mozilla Public License. see LICENSE.md for more details.
*/
#pragma once
#ifndef NANOEM_EMAPP_WIN32_WIN32THREADEDAPPLICATIONSERVICE_H_
#define NANOEM_EMAPP_WIN32_WIN32THREADEDAPPLICATIONSERVICE_H_
#include "emapp/ThreadedApplicationService.h"
#include <atomic>
#include "imgui/imgui.h"
struct ID3D11DepthStencilView;
struct ID3D11RenderTargetView;
struct ID3D11Texture2D;
namespace nanoem {
class IVideoRecorder;
namespace win32 {
class Win32ThreadedApplicationService final : public ThreadedApplicationService {
public:
#if defined(IMGUI_HAS_VIEWPORT)
struct ViewportData {
enum MessageType {
kMessageTypeCreateWindow = WM_USER,
kMessageTypeDestroyWindow,
kMessageTypeShowWindow,
kMessageTypeSetWindowPos,
kMessageTypeGetWindowPos,
kMessageTypeSetWindowSize,
kMessageTypeGetWindowSize,
kMessageTypeSetWindowFocus,
kMessageTypeGetWindowFocus,
kMessageTypeGetWindowMinimized,
kMessageTypeSetWindowTitle,
kMessageTypeSetWindowAlpha,
kMessageTypeUpdateWindow,
kMessageTypeGetDpiScale,
kMessageTypeOnChangedViewport,
kMessageTypeSetIMEInputPos,
};
ViewportData();
~ViewportData();
void destroyWindow();
void takeWindowStyle(ImGuiViewportFlags flags);
void wait();
void signal();
static LONG width(const RECT &rect) noexcept;
static LONG height(const RECT &rect) noexcept;
static ImVec2 size(const RECT &rect) noexcept;
static RECT rect(const ImGuiViewport *viewport) noexcept;
static void getWindowStyle(ImGuiViewportFlags flags, DWORD &style, DWORD &styleEx) noexcept;
static void sendMessage(MessageType type, const void *input) noexcept;
static void sendMessage(MessageType type, const void *input, void *output) noexcept;
static void sendMessage(MessageType type, const void *input, const void *output) noexcept;
HWND m_windowHandle = nullptr;
HANDLE m_eventHandle = nullptr;
DWORD m_style = 0;
DWORD m_styleEx = 0;
bool m_windowHandleOwned = false;
};
#endif /* IMGUI_HAS_VIEWPORT */
static const nanoem_f32_t kStandardDPIValue;
static const wchar_t kRegisterClassName[];
static void installUnhandledExceptionHandler();
static void getPluginPath(const wchar_t *executablePath, wchar_t *path, DWORD size);
static const wchar_t *sharedRedoFilePath();
static nanoem_f32_t calculateDevicePixelRatio();
static nanoem_f32_t calculateDevicePixelRatio(HMONITOR monitor);
static JSON_Value *loadJSONConfig(const wchar_t *executablePath);
Win32ThreadedApplicationService(const JSON_Value *config);
~Win32ThreadedApplicationService();
int run() override;
void setDisplaySyncEnabled(bool value);
void requestUpdatingAllMonitors();
void requestViewportWindowClose(HWND window);
void requestViewportWindowMove(HWND window);
void requestViewportWindowResize(HWND window);
private:
IAudioPlayer *createAudioPlayer() override;
IBackgroundVideoRenderer *createBackgroundVideoRenderer() override;
IDebugCapture *createDebugCapture() override;
Project::IRendererCapability *createRendererCapability() override;
Project::ISkinDeformerFactory *createSkinDeformerFactory() override;
IVideoRecorder *createVideoRecorder() override;
bool hasVideoRecorder() const noexcept override;
bool isRendererAvailable(const char *value) const noexcept override;
void destroyVideoRecorder(IVideoRecorder *videoRecorder) override;
void handleSetupGraphicsEngine(sg_desc &desc) override;
void handleInitializeApplication() override;
void handleNewProject() override;
void handleTerminateApplication() override;
void postEmptyApplicationEvent() override;
void presentDefaultPass(const Project *project) override;
URI recoverableRedoFileURI() const override;
void createDefaultRenderTarget(const Vector2UI16 &devicePixelWindowSize) override;
void resizeDefaultRenderTarget(const Vector2UI16 &devicePixelWindowSize, const Project *project) override;
void destroyDefaultRenderTarget() override;
void setupNewProject();
void updateAllMonitors();
ID3D11Texture2D *m_d3d11RenderTargetTexture = nullptr;
ID3D11RenderTargetView *m_d3d11RenderTargetView = nullptr;
ID3D11Texture2D *m_d3d11DepthStencilTexture = nullptr;
ID3D11DepthStencilView *m_d3d11DepthStencilView = nullptr;
std::atomic<HWND> m_requestWindowClose;
std::atomic<HWND> m_requestWindowMove;
std::atomic<HWND> m_requestWindowResize;
std::atomic<UINT> m_displaySyncInterval;
bool m_requestUpdatingAllMonitors = false;
};
} /* namespace win32 */
} /* namespace nanoem */
#endif /* NANOEM_EMAPP_WIN32_WIN32THREADEDAPPLICATIONSERVICE_H_ */