Skip to content

Commit

Permalink
feat: add switch for windiows direct composition rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
tishion committed Feb 28, 2025
1 parent 064eb1f commit 0b4a84c
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 6 deletions.
22 changes: 19 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ option(USE_SANDBOX
"Enable CEF Sandbox"
OFF
)
option(USE_WIN_DCOMPOSITION
"Enabled Windows direct composition for hardware rendering, _WIN32_WINNT >= 0x602 (Windows 8) is required"
OFF
)

# Only works for Windows & Linux, always enabled on macOS
# If enable then:
Expand Down Expand Up @@ -81,7 +85,10 @@ endif()
if("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin")
set(OS_MACOS 1)
set(OS_POSIX 1)
add_definitions(-DOS_MACOS=1 -DOS_POSIX=1)
add_definitions(
-DOS_MACOS=1
-DOS_POSIX=1
)
add_compile_options(
"-g"
"$<$<CONFIG:DEBUG>:-O0>"
Expand All @@ -106,7 +113,6 @@ elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux")
"$<$<CONFIG:RELEASE>:-O3>"
)

# Target architecture.
if(PROJECT_ARCH STREQUAL "x86_64")
# x86 64-bit architecture.
add_compile_options(-m64 -march=x86-64)
Expand All @@ -121,7 +127,17 @@ elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "Windows")

# Disable the sandbox on Windows, because the sandbox.lib is MT which is conflict with Qt
set(USE_SANDBOX OFF CACHE BOOL "Disable sandbox on Windows" FORCE)
add_definitions(-DOS_WINDOWS=1)
add_definitions(
-DOS_WINDOWS=1
-D_WIN32_WINNT=0x601
)

if(USE_WIN_DCOMPOSITION)
add_definitions(
-DENABLE_WINDOWS_DIRECT_COMPOSITION=1
)
endif()

add_compile_options(
/W3
/WX
Expand Down
2 changes: 1 addition & 1 deletion src/win/details/render/hardware/DX11RenderBackend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ DX11RenderBackend::CreateDeviceAndSwapchain()
// Create D3D11 device and context
ComPtr<ID3D11Device> pD3dDevice;
ComPtr<ID3D11DeviceContext> pD3dContext;
#if _WIN32_WINNT >= 0x602
#if WINDOWS_DIRECT_COMPOSITION
HR_CHECK(S_OK == ::D3D11CreateDevice(nullptr,
D3D_DRIVER_TYPE_HARDWARE,
nullptr,
Expand Down
13 changes: 11 additions & 2 deletions src/win/details/render/hardware/DX11RenderBackend.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,17 @@
#include <dxgi1_2.h>
#include <wrl.h>

#define WINDOWS_DIRECT_COMPOSITION 0

#if defined(ENABLE_WINDOWS_DIRECT_COMPOSITION)
#if _WIN32_WINNT >= 0x602
#define WINDOWS_DIRECT_COMPOSITION 1
#else
#error Windows Direct Composition needs _WIN32_WINNT >= 0x602 (Windows 8)
#endif
#endif

#if WINDOWS_DIRECT_COMPOSITION
#include <dcomp.h>
#endif

Expand Down Expand Up @@ -40,8 +50,7 @@ class DX11RenderBackend : public ICefViewRenderer
Microsoft::WRL::ComPtr<ID3D11Device> m_d3dDevice;
Microsoft::WRL::ComPtr<ID3D11DeviceContext> m_d3dContext;

// only works for windows 8
#if _WIN32_WINNT >= 0x602
#if WINDOWS_DIRECT_COMPOSITION
Microsoft::WRL::ComPtr<IDXGISwapChain> m_swapChain;
Microsoft::WRL::ComPtr<IDCompositionDevice> m_dcompositionDevice;
Microsoft::WRL::ComPtr<IDCompositionTarget> m_dcompositionTarget;
Expand Down

0 comments on commit 0b4a84c

Please sign in to comment.