diff --git a/skiko/src/awtMain/cpp/windows/DCompLibrary.cc b/skiko/src/awtMain/cpp/windows/DCompLibrary.cc new file mode 100644 index 000000000..7cbbdd1cf --- /dev/null +++ b/skiko/src/awtMain/cpp/windows/DCompLibrary.cc @@ -0,0 +1,24 @@ +#include "DCompLibrary.h" + +namespace DCompLibrary { + static HINSTANCE getLibrary() { + static HINSTANCE library = LoadLibrary("dcomp.dll"); + return library; + } + + HRESULT DCompositionCreateDevice( + IDXGIDevice *dxgiDevice, + REFIID iid, + void **dcompositionDevice + ) { + HINSTANCE library = getLibrary(); + + if (library != nullptr) { + typedef HRESULT(WINAPI * PROC_DCompositionCreateDevice)(IDXGIDevice * dxgiDevice, REFIID iid, void **dcompositionDevice); + static auto compositionCreateDevice = (PROC_DCompositionCreateDevice) GetProcAddress(library, "DCompositionCreateDevice"); + return compositionCreateDevice(dxgiDevice, iid, dcompositionDevice); + } else { + return E_FAIL; + } + } +} diff --git a/skiko/src/awtMain/cpp/windows/DCompLibrary.h b/skiko/src/awtMain/cpp/windows/DCompLibrary.h new file mode 100644 index 000000000..8a0df3ec3 --- /dev/null +++ b/skiko/src/awtMain/cpp/windows/DCompLibrary.h @@ -0,0 +1,11 @@ +#pragma once + +#include + +namespace DCompLibrary { + HRESULT DCompositionCreateDevice( + IDXGIDevice *dxgiDevice, + REFIID iid, + void **dcompositionDevice + ); +} diff --git a/skiko/src/awtMain/cpp/windows/directXRedrawer.cc b/skiko/src/awtMain/cpp/windows/directXRedrawer.cc index db7a1489c..18b02f098 100644 --- a/skiko/src/awtMain/cpp/windows/directXRedrawer.cc +++ b/skiko/src/awtMain/cpp/windows/directXRedrawer.cc @@ -12,6 +12,7 @@ #include "SkSurface.h" #include "include/gpu/ganesh/SkSurfaceGanesh.h" #include "../common/interop.hh" +#include "DCompLibrary.h" #include "d3d/GrD3DTypes.h" #include @@ -20,9 +21,6 @@ #include #include -#include -#pragma comment(lib, "dcomp.lib") - const int BuffersCount = 2; class DirectXDevice @@ -95,7 +93,7 @@ class DirectXDevice HRESULT result = swapChainFactory4->CreateSwapChainForComposition(queue.get(), &swapChainDesc, nullptr, swapChain1); if (FAILED(result)) { return result; } - result = DCompositionCreateDevice(0, IID_PPV_ARGS(&dcDevice)); + result = DCompLibrary::DCompositionCreateDevice(0, IID_PPV_ARGS(&dcDevice)); if (FAILED(result)) { return result; } result = dcDevice->CreateTargetForHwnd(hWnd, true, &dcTarget); if (FAILED(result)) { return result; }