Skip to content

Commit 4ece037

Browse files
committed
Native ToggleBlurBackdrop
Use private api `MaterialHelperTestApi` in `Microsoft.UI.Private.Media`. Save ~600ms.
1 parent 41d8287 commit 4ece037

File tree

2 files changed

+264
-23
lines changed

2 files changed

+264
-23
lines changed

CollapseLauncher/App.xaml.cs

+2-23
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,11 @@
66
using Hi3Helper.Win32.Native.Enums;
77
using Hi3Helper.Win32.Native.LibraryImport;
88
using Microsoft.UI;
9+
using Microsoft.UI.Private.Media;
910
using Microsoft.UI.Xaml;
10-
using Microsoft.UI.Xaml.Media;
1111
using PhotoSauce.MagicScaler;
1212
using PhotoSauce.NativeCodecs.Libwebp;
1313
using System;
14-
using System.Linq;
1514
using Windows.UI;
1615
using static CollapseLauncher.InnerLauncherConfig;
1716
using static Hi3Helper.Logger;
@@ -150,27 +149,7 @@ protected override void OnLaunched(LaunchActivatedEventArgs args)
150149

151150
public static void ToggleBlurBackdrop(bool useBackdrop = true)
152151
{
153-
// Enumerate the dictionary (MergedDictionaries)
154-
foreach (ResourceDictionary resource in Current!.Resources!.MergedDictionaries!)
155-
{
156-
// Parse the dictionary (ThemeDictionaries) and read the type of KeyValuePair<object, object>,
157-
// then select the value, get the type of ResourceDictionary, then enumerate it
158-
foreach (ResourceDictionary list in resource!
159-
.ThemeDictionaries!
160-
.Select(x => x.Value)
161-
.OfType<ResourceDictionary>())
162-
{
163-
// Parse the dictionary as type of KeyValuePair<object, object>,
164-
// and get the value which has type of AcrylicBrush only, then enumerate it
165-
foreach (AcrylicBrush theme in list
166-
.Select(x => x.Value)
167-
.OfType<AcrylicBrush>())
168-
{
169-
// Set the theme AlwaysUseFallback as per toggle from useBackdrop.
170-
theme.AlwaysUseFallback = !useBackdrop;
171-
}
172-
}
173-
}
152+
MaterialHelperTestApi.SimulateDisabledByPolicy = !useBackdrop;
174153
}
175154
}
176155
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,262 @@
1+
//------------------------------------------------------------------------------
2+
// <auto-generated>
3+
// This file was generated by cswinrt.exe version 2.2.0.241111.1
4+
//
5+
// Changes to this file may cause incorrect behavior and will be lost if
6+
// the code is regenerated.
7+
// </auto-generated>
8+
//------------------------------------------------------------------------------
9+
10+
using System;
11+
using System.Collections;
12+
using System.Collections.Generic;
13+
using System.Collections.ObjectModel;
14+
using System.Diagnostics;
15+
using System.Diagnostics.CodeAnalysis;
16+
using System.Linq.Expressions;
17+
using System.Reflection;
18+
using System.Runtime.CompilerServices;
19+
using System.Runtime.InteropServices;
20+
using WinRT;
21+
using WinRT.Interop;
22+
23+
24+
#pragma warning disable 0169 // warning CS0169: The field '...' is never used
25+
#pragma warning disable 0649 // warning CS0169: Field '...' is never assigned to
26+
#pragma warning disable CA2207, CA1063, CA1033, CA1001, CA2213
27+
28+
namespace Microsoft.UI.Private.Media
29+
{
30+
[global::WinRT.WindowsRuntimeType("MaterialHelperTestApi")][Guid("FFEB6DAD-B1FC-56E7-9820-667BD14B4791")][global::WinRT.WindowsRuntimeHelperType(typeof(global::ABI.Microsoft.UI.Private.Media.IMaterialHelperTestApi))]
31+
internal interface IMaterialHelperTestApi
32+
{
33+
}
34+
[global::WinRT.WindowsRuntimeType("MaterialHelperTestApi")][Guid("7FC11A83-CB9E-50B4-B4B3-645F08552BDA")][global::WinRT.WindowsRuntimeHelperType(typeof(global::ABI.Microsoft.UI.Private.Media.IMaterialHelperTestApiStatics))]
35+
internal interface IMaterialHelperTestApiStatics
36+
{
37+
bool IgnoreAreEffectsFast { get; set; }
38+
bool SimulateDisabledByPolicy { get; set; }
39+
}
40+
[global::WinRT.WindowsRuntimeType("MaterialHelperTestApi")]
41+
[global::WinRT.WindowsRuntimeHelperType(typeof(global::ABI.Microsoft.UI.Private.Media.MaterialHelperTestApi))]
42+
[global::ABI.Microsoft.UI.Private.Media.MaterialHelperTestApiRcwFactory]
43+
[global::WinRT.ProjectedRuntimeClass(typeof(IMaterialHelperTestApi))]
44+
public sealed class MaterialHelperTestApi : global::Microsoft.UI.Xaml.DependencyObject, global::System.Runtime.InteropServices.ICustomQueryInterface, IWinRTObject, IEquatable<MaterialHelperTestApi>
45+
{
46+
private IntPtr ThisPtr => _inner == null ? (((IWinRTObject)this).NativeObject).ThisPtr : _inner.ThisPtr;
47+
48+
private readonly IObjectReference _inner = null;
49+
50+
51+
52+
private IObjectReference _objRef_global__Microsoft_UI_Private_Media_IMaterialHelperTestApi => _inner;
53+
54+
55+
private static volatile IObjectReference ___objRef_global__Microsoft_UI_Private_Media_MaterialHelperTestApi;
56+
private static IObjectReference _objRef_global__Microsoft_UI_Private_Media_MaterialHelperTestApi
57+
{
58+
get
59+
{
60+
var factory = ___objRef_global__Microsoft_UI_Private_Media_MaterialHelperTestApi;
61+
if (factory != null && factory.IsInCurrentContext)
62+
{
63+
return factory;
64+
}
65+
else
66+
{
67+
return ___objRef_global__Microsoft_UI_Private_Media_MaterialHelperTestApi = ActivationFactory.Get("Microsoft.UI.Private.Media.MaterialHelperTestApi");
68+
}
69+
}
70+
}
71+
72+
public MaterialHelperTestApi() :base(global::WinRT.DerivedComposed.Instance)
73+
{
74+
_inner = global::ABI.WinRT.Interop.IActivationFactoryMethods.ActivateInstanceUnsafe(_objRef_global__Microsoft_UI_Private_Media_MaterialHelperTestApi, global::ABI.Microsoft.UI.Private.Media.IMaterialHelperTestApiMethods.IID);
75+
ComWrappersSupport.RegisterObjectForInterface(this, ThisPtr);
76+
ComWrappersHelper.Init(_inner, false);
77+
78+
}
79+
80+
public static I As<I>() => ActivationFactory.Get("Microsoft.UI.Private.Media.MaterialHelperTestApi").AsInterface<I>();
81+
82+
private static volatile IObjectReference ___objRef_global__Microsoft_UI_Private_Media_IMaterialHelperTestApiStatics;
83+
private static IObjectReference _objRef_global__Microsoft_UI_Private_Media_IMaterialHelperTestApiStatics
84+
{
85+
get
86+
{
87+
var factory = ___objRef_global__Microsoft_UI_Private_Media_IMaterialHelperTestApiStatics;
88+
if (factory != null && factory.IsInCurrentContext)
89+
{
90+
return factory;
91+
}
92+
else
93+
{
94+
return ___objRef_global__Microsoft_UI_Private_Media_IMaterialHelperTestApiStatics = ActivationFactory.Get("Microsoft.UI.Private.Media.MaterialHelperTestApi", global::ABI.Microsoft.UI.Private.Media.IMaterialHelperTestApiStaticsMethods.IID);
95+
}
96+
}
97+
}
98+
99+
public static bool IgnoreAreEffectsFast
100+
{
101+
get => global::ABI.Microsoft.UI.Private.Media.IMaterialHelperTestApiStaticsMethods.get_IgnoreAreEffectsFast(_objRef_global__Microsoft_UI_Private_Media_IMaterialHelperTestApiStatics);
102+
set => global::ABI.Microsoft.UI.Private.Media.IMaterialHelperTestApiStaticsMethods.set_IgnoreAreEffectsFast(_objRef_global__Microsoft_UI_Private_Media_IMaterialHelperTestApiStatics, value);
103+
}
104+
105+
public static bool SimulateDisabledByPolicy
106+
{
107+
get => global::ABI.Microsoft.UI.Private.Media.IMaterialHelperTestApiStaticsMethods.get_SimulateDisabledByPolicy(_objRef_global__Microsoft_UI_Private_Media_IMaterialHelperTestApiStatics);
108+
set => global::ABI.Microsoft.UI.Private.Media.IMaterialHelperTestApiStaticsMethods.set_SimulateDisabledByPolicy(_objRef_global__Microsoft_UI_Private_Media_IMaterialHelperTestApiStatics, value);
109+
}
110+
111+
public static new MaterialHelperTestApi FromAbi(IntPtr thisPtr)
112+
{
113+
if (thisPtr == IntPtr.Zero) return null;
114+
return MarshalInspectable<MaterialHelperTestApi>.FromAbi(thisPtr);
115+
}
116+
117+
internal MaterialHelperTestApi(IObjectReference objRef)
118+
: base(global::WinRT.DerivedComposed.Instance)
119+
120+
{
121+
_inner = objRef.As(global::ABI.Microsoft.UI.Private.Media.IMaterialHelperTestApiMethods.IID);
122+
123+
}
124+
125+
126+
public static bool operator ==(MaterialHelperTestApi x, MaterialHelperTestApi y) => (x?.ThisPtr ?? IntPtr.Zero) == (y?.ThisPtr ?? IntPtr.Zero);
127+
public static bool operator !=(MaterialHelperTestApi x, MaterialHelperTestApi y) => !(x == y);
128+
public bool Equals(MaterialHelperTestApi other) => this == other;
129+
public override bool Equals(object obj) => obj is MaterialHelperTestApi that && this == that;
130+
public override int GetHashCode() => ThisPtr.GetHashCode();
131+
132+
133+
bool IWinRTObject.HasUnwrappableNativeObject => true;
134+
IObjectReference IWinRTObject.NativeObject => _inner;
135+
136+
private struct InterfaceTag<I>{};
137+
138+
139+
protected override bool IsOverridableInterface(Guid iid) => base.IsOverridableInterface(iid);
140+
141+
global::System.Runtime.InteropServices.CustomQueryInterfaceResult global::System.Runtime.InteropServices.ICustomQueryInterface.GetInterface(ref Guid iid, out IntPtr ppv)
142+
{
143+
ppv = IntPtr.Zero;
144+
if (IsOverridableInterface(iid) || global::WinRT.Interop.IID.IID_IInspectable == iid)
145+
{
146+
return global::System.Runtime.InteropServices.CustomQueryInterfaceResult.NotHandled;
147+
}
148+
149+
if (((IWinRTObject)this).NativeObject.TryAs(iid, out ppv) >= 0)
150+
{
151+
return global::System.Runtime.InteropServices.CustomQueryInterfaceResult.Handled;
152+
}
153+
154+
return global::System.Runtime.InteropServices.CustomQueryInterfaceResult.NotHandled;
155+
}
156+
}
157+
}
158+
159+
#pragma warning disable CA1416
160+
namespace ABI.Microsoft.UI.Private.Media
161+
{
162+
internal static class IMaterialHelperTestApiMethods
163+
{
164+
165+
166+
167+
public static ref readonly global::System.Guid IID
168+
{
169+
[global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
170+
get
171+
{
172+
global::System.ReadOnlySpan<byte> data = new byte[] { 0xAD, 0x6D, 0xEB, 0xFF, 0xFC, 0xB1, 0xE7, 0x56, 0x98, 0x20, 0x66, 0x7B, 0xD1, 0x4B, 0x47, 0x91 };
173+
return ref global::System.Runtime.CompilerServices.Unsafe.As<byte, global::System.Guid>(ref global::System.Runtime.InteropServices.MemoryMarshal.GetReference(data));
174+
}
175+
}
176+
177+
}
178+
[Guid("FFEB6DAD-B1FC-56E7-9820-667BD14B4791")]
179+
internal interface IMaterialHelperTestApi : global::Microsoft.UI.Private.Media.IMaterialHelperTestApi
180+
{
181+
}
182+
internal static class IMaterialHelperTestApiStaticsMethods
183+
{
184+
185+
internal static unsafe bool get_IgnoreAreEffectsFast(IObjectReference _obj)
186+
{
187+
var ThisPtr = _obj.ThisPtr;
188+
189+
byte __retval = default;
190+
global::WinRT.ExceptionHelpers.ThrowExceptionForHR((*(delegate* unmanaged[Stdcall]<IntPtr, byte*, int>**)ThisPtr)[8](ThisPtr, &__retval));
191+
global::System.GC.KeepAlive(_obj);
192+
return __retval != 0;
193+
}
194+
internal static unsafe void set_IgnoreAreEffectsFast(IObjectReference _obj, bool value)
195+
{
196+
var ThisPtr = _obj.ThisPtr;
197+
198+
global::WinRT.ExceptionHelpers.ThrowExceptionForHR((*(delegate* unmanaged[Stdcall]<IntPtr, byte, int>**)ThisPtr)[9](ThisPtr, (byte)(value ? 1 : 0)));
199+
global::System.GC.KeepAlive(_obj);
200+
}
201+
202+
internal static unsafe bool get_SimulateDisabledByPolicy(IObjectReference _obj)
203+
{
204+
var ThisPtr = _obj.ThisPtr;
205+
206+
byte __retval = default;
207+
global::WinRT.ExceptionHelpers.ThrowExceptionForHR((*(delegate* unmanaged[Stdcall]<IntPtr, byte*, int>**)ThisPtr)[6](ThisPtr, &__retval));
208+
global::System.GC.KeepAlive(_obj);
209+
return __retval != 0;
210+
}
211+
internal static unsafe void set_SimulateDisabledByPolicy(IObjectReference _obj, bool value)
212+
{
213+
var ThisPtr = _obj.ThisPtr;
214+
215+
global::WinRT.ExceptionHelpers.ThrowExceptionForHR((*(delegate* unmanaged[Stdcall]<IntPtr, byte, int>**)ThisPtr)[7](ThisPtr, (byte)(value ? 1 : 0)));
216+
global::System.GC.KeepAlive(_obj);
217+
}
218+
219+
220+
221+
public static ref readonly global::System.Guid IID
222+
{
223+
[global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
224+
get
225+
{
226+
global::System.ReadOnlySpan<byte> data = new byte[] { 0x83, 0x1A, 0xC1, 0x7F, 0x9E, 0xCB, 0xB4, 0x50, 0xB4, 0xB3, 0x64, 0x5F, 0x8, 0x55, 0x2B, 0xDA };
227+
return ref global::System.Runtime.CompilerServices.Unsafe.As<byte, global::System.Guid>(ref global::System.Runtime.InteropServices.MemoryMarshal.GetReference(data));
228+
}
229+
}
230+
231+
}
232+
[Guid("7FC11A83-CB9E-50B4-B4B3-645F08552BDA")]
233+
internal interface IMaterialHelperTestApiStatics : global::Microsoft.UI.Private.Media.IMaterialHelperTestApiStatics
234+
{
235+
}
236+
[global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]
237+
public struct MaterialHelperTestApi
238+
{
239+
240+
public static IObjectReference CreateMarshaler(global::Microsoft.UI.Private.Media.MaterialHelperTestApi obj) => obj is null ? null : MarshalInspectable<global::Microsoft.UI.Private.Media.MaterialHelperTestApi>.CreateMarshaler<IUnknownVftbl>(obj, global::ABI.Microsoft.UI.Private.Media.IMaterialHelperTestApiMethods.IID);
241+
public static ObjectReferenceValue CreateMarshaler2(global::Microsoft.UI.Private.Media.MaterialHelperTestApi obj) => MarshalInspectable<object>.CreateMarshaler2(obj, global::ABI.Microsoft.UI.Private.Media.IMaterialHelperTestApiMethods.IID);
242+
public static IntPtr GetAbi(IObjectReference value) => value is null ? IntPtr.Zero : MarshalInterfaceHelper<object>.GetAbi(value);
243+
public static global::Microsoft.UI.Private.Media.MaterialHelperTestApi FromAbi(IntPtr thisPtr) => global::Microsoft.UI.Private.Media.MaterialHelperTestApi.FromAbi(thisPtr);
244+
public static IntPtr FromManaged(global::Microsoft.UI.Private.Media.MaterialHelperTestApi obj) => obj is null ? IntPtr.Zero : CreateMarshaler2(obj).Detach();
245+
public static unsafe MarshalInterfaceHelper<global::Microsoft.UI.Private.Media.MaterialHelperTestApi>.MarshalerArray CreateMarshalerArray(global::Microsoft.UI.Private.Media.MaterialHelperTestApi[] array) => MarshalInterfaceHelper<global::Microsoft.UI.Private.Media.MaterialHelperTestApi>.CreateMarshalerArray2(array, (o) => CreateMarshaler2(o));
246+
public static (int length, IntPtr data) GetAbiArray(object box) => MarshalInterfaceHelper<global::Microsoft.UI.Private.Media.MaterialHelperTestApi>.GetAbiArray(box);
247+
public static unsafe global::Microsoft.UI.Private.Media.MaterialHelperTestApi[] FromAbiArray(object box) => MarshalInterfaceHelper<global::Microsoft.UI.Private.Media.MaterialHelperTestApi>.FromAbiArray(box, FromAbi);
248+
public static void CopyAbiArray(global::Microsoft.UI.Private.Media.MaterialHelperTestApi[] array, object box) => MarshalInterfaceHelper<global::Microsoft.UI.Private.Media.MaterialHelperTestApi>.CopyAbiArray(array, box, FromAbi);
249+
public static (int length, IntPtr data) FromManagedArray(global::Microsoft.UI.Private.Media.MaterialHelperTestApi[] array) => MarshalInterfaceHelper<global::Microsoft.UI.Private.Media.MaterialHelperTestApi>.FromManagedArray(array, (o) => FromManaged(o));
250+
public static void DisposeMarshaler(IObjectReference value) => MarshalInspectable<object>.DisposeMarshaler(value);
251+
public static void DisposeMarshalerArray(MarshalInterfaceHelper<global::Microsoft.UI.Private.Media.MaterialHelperTestApi>.MarshalerArray array) => MarshalInterfaceHelper<global::Microsoft.UI.Private.Media.MaterialHelperTestApi>.DisposeMarshalerArray(array);
252+
public static void DisposeAbi(IntPtr abi) => MarshalInspectable<object>.DisposeAbi(abi);
253+
public static unsafe void DisposeAbiArray(object box) => MarshalInspectable<object>.DisposeAbiArray(box);
254+
}
255+
[global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]
256+
internal sealed class MaterialHelperTestApiRcwFactoryAttribute : global::WinRT.WinRTImplementationTypeRcwFactoryAttribute
257+
{
258+
public override object CreateInstance(global::WinRT.IInspectable inspectable)
259+
=> new global::Microsoft.UI.Private.Media.MaterialHelperTestApi(inspectable.ObjRef);
260+
}
261+
}
262+
#pragma warning restore CA1416

0 commit comments

Comments
 (0)