This repository has been archived by the owner on Jul 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
uDwmBackdrop.hpp
55 lines (45 loc) · 1.94 KB
/
uDwmBackdrop.hpp
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
#pragma once
#include "udwmPrivates.hpp"
namespace AcrylicEverywhere
{
struct CSharedVisual
{
winrt::com_ptr<uDwmPrivates::CVisual> udwmVisual{ nullptr };
winrt::com_ptr<IDCompositionVisual2> dcompVisual{ nullptr };
winrt::com_ptr<DCompPrivates::InteropCompositionTarget> interopCompositionTarget{ nullptr };
winrt::Windows::UI::Composition::LayerVisual layerVisual{ nullptr };
HRESULT STDMETHODCALLTYPE InitializeDCompAnduDwmVisual(DCompPrivates::IDCompositionDesktopDevicePartner* requestedInteropDCompDevice) try
{
winrt::com_ptr<DCompPrivates::IDCompositionDesktopDevicePartner> interopDCompDevice{ nullptr };
interopDCompDevice.copy_from(requestedInteropDCompDevice);
THROW_IF_FAILED(
interopDCompDevice->CreateSharedResource(
IID_PPV_ARGS(interopCompositionTarget.put())
)
);
auto interopCompositor{ interopDCompDevice.as<winrt::Windows::UI::Composition::Compositor>() };
THROW_IF_FAILED(interopDCompDevice->CreateVisual(dcompVisual.put()));
THROW_IF_FAILED(
dcompVisual->SetCompositeMode(DCOMPOSITION_COMPOSITE_MODE_SOURCE_OVER)
);
THROW_IF_FAILED(
dcompVisual->SetBitmapInterpolationMode(DCOMPOSITION_BITMAP_INTERPOLATION_MODE_LINEAR)
);
THROW_IF_FAILED(
dcompVisual->SetBorderMode(DCOMPOSITION_BORDER_MODE_SOFT)
);
layerVisual = interopCompositor.CreateLayerVisual();
auto interopVisual{ dcompVisual.as<DCompPrivates::IDCompositionVisualPartnerWinRTInterop>() };
interopVisual->GetVisualCollection().InsertAtBottom(layerVisual);
THROW_IF_FAILED(interopCompositionTarget->SetRoot(dcompVisual.get()));
THROW_IF_FAILED(interopDCompDevice->Commit());
wil::unique_handle resourceHandle{ nullptr };
THROW_IF_FAILED(
interopDCompDevice->OpenSharedResourceHandle(interopCompositionTarget.get(), resourceHandle.put())
);
THROW_IF_FAILED(uDwmPrivates::CVisual::CreateFromSharedHandle(resourceHandle.get(), udwmVisual.put()));
return S_OK;
}
CATCH_RETURN()
};
}