mirror of
https://github.com/Blinue/Magpie.git
synced 2026-06-24 02:04:10 +00:00
feat: 添加 Renderer 和 DeviceResources
This commit is contained in:
parent
f07972be3d
commit
a68083c68f
12 changed files with 141 additions and 13 deletions
|
|
@ -316,7 +316,7 @@ bool ScalingService::_StartScale(HWND hWnd, const Profile& profile) {
|
|||
options.IsSimulateExclusiveFullscreen(settings.IsSimulateExclusiveFullscreen());
|
||||
|
||||
_isAutoScaling = profile.isAutoScale;
|
||||
_ScalingRuntime->Start(hWnd, options);
|
||||
_ScalingRuntime->Start(hWnd, std::move(options));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
|||
32
src/Magpie.Core/DeviceResources.cpp
Normal file
32
src/Magpie.Core/DeviceResources.cpp
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
#include "pch.h"
|
||||
#include "DeviceResources.h"
|
||||
#include "ScalingOptions.h"
|
||||
|
||||
namespace Magpie::Core {
|
||||
|
||||
bool DeviceResources::Initialize(HWND /*hwndScaling*/, const ScalingOptions& /*options*/) noexcept {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool DeviceResources::IsDebugLayersAvailable() noexcept {
|
||||
#ifdef _DEBUG
|
||||
static bool result = SUCCEEDED(D3D11CreateDevice(
|
||||
nullptr,
|
||||
D3D_DRIVER_TYPE_NULL, // There is no need to create a real hardware device.
|
||||
nullptr,
|
||||
D3D11_CREATE_DEVICE_DEBUG, // Check for the SDK layers.
|
||||
nullptr, // Any feature level will do.
|
||||
0,
|
||||
D3D11_SDK_VERSION,
|
||||
nullptr, // No need to keep the D3D device reference.
|
||||
nullptr, // No need to know the feature level.
|
||||
nullptr // No need to keep the D3D device context reference.
|
||||
));
|
||||
return result;
|
||||
#else
|
||||
// Relaese 配置不使用调试层
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
}
|
||||
18
src/Magpie.Core/DeviceResources.h
Normal file
18
src/Magpie.Core/DeviceResources.h
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
#pragma once
|
||||
|
||||
namespace Magpie::Core {
|
||||
|
||||
struct ScalingOptions;
|
||||
|
||||
class DeviceResources {
|
||||
public:
|
||||
DeviceResources() noexcept = default;
|
||||
DeviceResources(const DeviceResources&) = delete;
|
||||
DeviceResources(DeviceResources&&) noexcept = default;
|
||||
|
||||
bool Initialize(HWND hwndScaling, const ScalingOptions& options) noexcept;
|
||||
|
||||
static bool IsDebugLayersAvailable() noexcept;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
@ -80,6 +80,7 @@
|
|||
<ItemGroup>
|
||||
<ClInclude Include="DDS.h" />
|
||||
<ClInclude Include="DDSLoderHelpers.h" />
|
||||
<ClInclude Include="DeviceResources.h" />
|
||||
<ClInclude Include="DirectXHelper.h" />
|
||||
<ClInclude Include="EffectCacheManager.h" />
|
||||
<ClInclude Include="EffectCompiler.h" />
|
||||
|
|
@ -90,6 +91,7 @@
|
|||
<ClInclude Include="ImGuiHelper.h" />
|
||||
<ClInclude Include="include\Magpie.Core.h" />
|
||||
<ClInclude Include="LoggerHelper.h" />
|
||||
<ClInclude Include="Renderer.h" />
|
||||
<ClInclude Include="ScalingOptions.h" />
|
||||
<ClInclude Include="ScalingRuntime.h" />
|
||||
<ClInclude Include="pch.h" />
|
||||
|
|
@ -100,6 +102,7 @@
|
|||
<ClInclude Include="YasHelper.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="DeviceResources.cpp" />
|
||||
<ClCompile Include="DirectXHelper.cpp" />
|
||||
<ClCompile Include="DllMain.cpp" />
|
||||
<ClCompile Include="EffectCacheManager.cpp" />
|
||||
|
|
@ -110,6 +113,7 @@
|
|||
<ClCompile Include="pch.cpp">
|
||||
<PrecompiledHeader>Create</PrecompiledHeader>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Renderer.cpp" />
|
||||
<ClCompile Include="ScalingRuntime.cpp" />
|
||||
<ClCompile Include="ScalingWindow.cpp" />
|
||||
<ClCompile Include="TextureLoader.cpp" />
|
||||
|
|
|
|||
|
|
@ -66,6 +66,8 @@
|
|||
</ClInclude>
|
||||
<ClInclude Include="WindowBase.h" />
|
||||
<ClInclude Include="ScalingWindow.h" />
|
||||
<ClInclude Include="Renderer.h" />
|
||||
<ClInclude Include="DeviceResources.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="ScalingRuntime.cpp" />
|
||||
|
|
@ -92,6 +94,8 @@
|
|||
<Filter>Overlay</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="ScalingWindow.cpp" />
|
||||
<ClCompile Include="Renderer.cpp" />
|
||||
<ClCompile Include="DeviceResources.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ResourceCompile Include="Magpie.Core.rc">
|
||||
|
|
|
|||
24
src/Magpie.Core/Renderer.cpp
Normal file
24
src/Magpie.Core/Renderer.cpp
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
#include "pch.h"
|
||||
#include "Renderer.h"
|
||||
#include "DeviceResources.h"
|
||||
#include "ScalingOptions.h"
|
||||
|
||||
namespace Magpie::Core {
|
||||
|
||||
Renderer::Renderer() noexcept {}
|
||||
|
||||
Renderer::~Renderer() noexcept {}
|
||||
|
||||
bool Renderer::Initialize(HWND hwndScaling, const ScalingOptions& options) noexcept {
|
||||
_deviceResources = std::make_unique<DeviceResources>();
|
||||
if (!_deviceResources->Initialize(hwndScaling, options)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void Renderer::Render() noexcept {
|
||||
}
|
||||
|
||||
}
|
||||
24
src/Magpie.Core/Renderer.h
Normal file
24
src/Magpie.Core/Renderer.h
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
#pragma once
|
||||
|
||||
namespace Magpie::Core {
|
||||
|
||||
struct ScalingOptions;
|
||||
class DeviceResources;
|
||||
|
||||
class Renderer {
|
||||
public:
|
||||
Renderer() noexcept;
|
||||
~Renderer() noexcept;
|
||||
|
||||
Renderer(const Renderer&) = delete;
|
||||
Renderer(Renderer&&) noexcept = default;
|
||||
|
||||
bool Initialize(HWND hwndScaling, const ScalingOptions& options) noexcept;
|
||||
|
||||
void Render() noexcept;
|
||||
|
||||
private:
|
||||
std::unique_ptr<DeviceResources> _deviceResources;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
@ -23,7 +23,7 @@ ScalingRuntime::~ScalingRuntime() {
|
|||
}
|
||||
}
|
||||
|
||||
void ScalingRuntime::Start(HWND hwndSrc, const ScalingOptions& options) {
|
||||
void ScalingRuntime::Start(HWND hwndSrc, ScalingOptions&& options) {
|
||||
if (_isRunning) {
|
||||
return;
|
||||
}
|
||||
|
|
@ -31,9 +31,9 @@ void ScalingRuntime::Start(HWND hwndSrc, const ScalingOptions& options) {
|
|||
_IsRunning(true);
|
||||
|
||||
_EnsureDispatcherQueue();
|
||||
_dqc.DispatcherQueue().TryEnqueue([this, hwndSrc, options(options)]() mutable {
|
||||
_dqc.DispatcherQueue().TryEnqueue([this, hwndSrc, options(std::move(options))]() mutable {
|
||||
_scalingWindow = std::make_unique<ScalingWindow>();
|
||||
_scalingWindow->Create(GetModuleHandle(nullptr));
|
||||
_scalingWindow->Create(GetModuleHandle(nullptr), std::move(options));
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ public:
|
|||
return _isRunning ? _hwndSrc : 0;
|
||||
}
|
||||
|
||||
void Start(HWND hwndSrc, const ScalingOptions& options);
|
||||
void Start(HWND hwndSrc, ScalingOptions&& options);
|
||||
|
||||
void ToggleOverlay();
|
||||
|
||||
|
|
|
|||
|
|
@ -2,10 +2,15 @@
|
|||
#include "ScalingWindow.h"
|
||||
#include "CommonSharedConstants.h"
|
||||
#include "Logger.h"
|
||||
#include "Renderer.h"
|
||||
|
||||
namespace Magpie::Core {
|
||||
|
||||
bool ScalingWindow::Create(HINSTANCE hInstance) noexcept {
|
||||
ScalingWindow::ScalingWindow() noexcept {}
|
||||
|
||||
ScalingWindow::~ScalingWindow() noexcept {}
|
||||
|
||||
bool ScalingWindow::Create(HINSTANCE hInstance, ScalingOptions&& options) noexcept {
|
||||
static const int _ = [](HINSTANCE hInstance) {
|
||||
WNDCLASSEXW wcex{};
|
||||
wcex.cbSize = sizeof(wcex);
|
||||
|
|
@ -30,23 +35,28 @@ bool ScalingWindow::Create(HINSTANCE hInstance) noexcept {
|
|||
this
|
||||
);
|
||||
|
||||
if (!Handle()) {
|
||||
if (!_hWnd) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// 设置窗口不透明
|
||||
// 不完全透明时可关闭 DirectFlip
|
||||
if (!SetLayeredWindowAttributes(Handle(), 0, 255, LWA_ALPHA)) {
|
||||
if (!SetLayeredWindowAttributes(_hWnd, 0, 255, LWA_ALPHA)) {
|
||||
Logger::Get().Win32Error("SetLayeredWindowAttributes 失败");
|
||||
}
|
||||
|
||||
ShowWindow(Handle(), SW_SHOWMAXIMIZED);
|
||||
_renderer = std::make_unique<Renderer>();
|
||||
if (!_renderer->Initialize(_hWnd, options)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ShowWindow(_hWnd, SW_SHOWMAXIMIZED);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void ScalingWindow::Render() noexcept {
|
||||
|
||||
_renderer->Render();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,13 +3,22 @@
|
|||
|
||||
namespace Magpie::Core {
|
||||
|
||||
struct ScalingOptions;
|
||||
class Renderer;
|
||||
|
||||
class ScalingWindow : public WindowBase<ScalingWindow> {
|
||||
friend class base_type;
|
||||
|
||||
public:
|
||||
bool Create(HINSTANCE hInstance) noexcept;
|
||||
ScalingWindow() noexcept;
|
||||
~ScalingWindow() noexcept;
|
||||
|
||||
bool Create(HINSTANCE hInstance, ScalingOptions&& options) noexcept;
|
||||
|
||||
void Render() noexcept;
|
||||
|
||||
private:
|
||||
std::unique_ptr<Renderer> _renderer;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,11 @@ namespace Magpie::Core {
|
|||
template <typename T>
|
||||
class WindowBase {
|
||||
public:
|
||||
virtual ~WindowBase() {
|
||||
WindowBase() noexcept = default;
|
||||
WindowBase(const WindowBase&) = delete;
|
||||
WindowBase(WindowBase&&) noexcept = default;
|
||||
|
||||
virtual ~WindowBase() noexcept {
|
||||
Destroy();
|
||||
}
|
||||
|
||||
|
|
@ -51,7 +55,6 @@ protected:
|
|||
return DefWindowProc(_hWnd, msg, wParam, lParam);
|
||||
}
|
||||
|
||||
private:
|
||||
HWND _hWnd = NULL;
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue