From 7e94ce8baf771c5916cb9e3a03e24ea5f6505428 Mon Sep 17 00:00:00 2001 From: ALTaleX <2368730049@qq.com> Date: Sat, 5 Oct 2024 18:27:12 +0800 Subject: [PATCH] v1.3 --- OpenGlass/GlassFramework.cpp | 30 ++++---- OpenGlass/GlassRenderer.cpp | 119 ++++++++++---------------------- OpenGlass/Shared.hpp | 2 + OpenGlass/dwmcoreProjection.hpp | 10 ++- 4 files changed, 62 insertions(+), 99 deletions(-) diff --git a/OpenGlass/GlassFramework.cpp b/OpenGlass/GlassFramework.cpp index 43581e5..7f336a8 100644 --- a/OpenGlass/GlassFramework.cpp +++ b/OpenGlass/GlassFramework.cpp @@ -38,6 +38,7 @@ namespace OpenGlass::GlassFramework int g_roundRectRadius{}; UINT g_dwOverlayTestMode{}; + winrt::com_ptr g_hackVisual{ nullptr }; } HRGN WINAPI GlassFramework::MyCreateRoundRectRgn(int x1, int y1, int x2, int y2, int w, int h) @@ -55,21 +56,12 @@ HRESULT STDMETHODCALLTYPE GlassFramework::MyCDrawGeometryInstruction_Create(uDwm { if (g_capturedWindow && g_capturedWindow->GetData()->GetHwnd() != uDwm::GetShellWindowForCurrentDesktop()) { - HRGN region{ GeometryRecorder::GetRegionFromGeometry(geometry) }; - RECT rgnBox{}; - if (GetRgnBox(region, &rgnBox) != NULLREGION && !IsRectEmpty(&rgnBox)) - { - winrt::com_ptr rgnGeometry{ nullptr }; - uDwm::ResourceHelper::CreateGeometryFromHRGN(region, rgnGeometry.put()); - - auto color = - Shared::g_forceAccentColorization ? - dwmcore::Convert_D2D1_COLOR_F_sRGB_To_D2D1_COLOR_F_scRGB(g_capturedWindow->TreatAsActiveWindow() ? Shared::g_accentColor : Shared::g_accentColorInactive) : - g_capturedWindow->GetTitlebarColorizationParameters()->getArgbcolor(); - color.a = g_capturedWindow->TreatAsActiveWindow() ? 0.5f : 0.0f; - RETURN_IF_FAILED(reinterpret_cast(brush)->Update(1.0, color)); - return g_CDrawGeometryInstruction_Create_Org(brush, rgnGeometry.get(), instruction); - } + auto color = + Shared::g_forceAccentColorization ? + dwmcore::Convert_D2D1_COLOR_F_sRGB_To_D2D1_COLOR_F_scRGB(g_capturedWindow->TreatAsActiveWindow() ? Shared::g_accentColor : Shared::g_accentColorInactive) : + g_capturedWindow->GetTitlebarColorizationParameters()->getArgbcolor(); + color.a = g_capturedWindow->TreatAsActiveWindow() ? 0.5f : 0.0f; + RETURN_IF_FAILED(reinterpret_cast(brush)->Update(1.0, color)); } return g_CDrawGeometryInstruction_Create_Org(brush, geometry, instruction); @@ -349,6 +341,10 @@ void GlassFramework::UpdateConfiguration(ConfigurationFramework::UpdateType type Shared::g_accentColor = Utils::FromAbgr(accentColor); Shared::g_accentColorInactive = Utils::FromAbgr(accentColorInactive); } + + Shared::g_enableFullDirty = static_cast(ConfigurationFramework::DwmGetDwordFromHKCUAndHKLM(L"EnableFullDirty")); + Shared::g_enableFullDirty ? g_hackVisual.as()->EnableRedrawRegions() : g_hackVisual.as()->DisableRedrawRegions(); + LOG_IF_FAILED(uDwm::CDesktopManager::s_pDesktopManagerInstance->GetDCompDevice()->Commit()); } auto lock = wil::EnterCriticalSection(uDwm::CDesktopManager::s_csDwmInstance); @@ -380,6 +376,8 @@ HRESULT GlassFramework::Startup() g_dwOverlayTestMode = *dwmcore::CCommonRegistryData::m_dwOverlayTestMode; *dwmcore::CCommonRegistryData::m_dwOverlayTestMode = 0x5; + RETURN_IF_FAILED(uDwm::CDesktopManager::s_pDesktopManagerInstance->GetDCompDevice()->CreateVisual(g_hackVisual.put())); + uDwm::GetAddressFromSymbolMap("CDrawGeometryInstruction::Create", g_CDrawGeometryInstruction_Create_Org); uDwm::GetAddressFromSymbolMap("CTopLevelWindow::UpdateNCAreaBackground", g_CTopLevelWindow_UpdateNCAreaBackground_Org); uDwm::GetAddressFromSymbolMap("CTopLevelWindow::UpdateClientBlur", g_CTopLevelWindow_UpdateClientBlur_Org); @@ -456,4 +454,6 @@ void GlassFramework::Shutdown() VisualManager::RedrawTopLevelWindow(window); LOG_IF_FAILED(window->ValidateVisual()); } + + g_hackVisual = nullptr; } \ No newline at end of file diff --git a/OpenGlass/GlassRenderer.cpp b/OpenGlass/GlassRenderer.cpp index 5a9dedf..a45e884 100644 --- a/OpenGlass/GlassRenderer.cpp +++ b/OpenGlass/GlassRenderer.cpp @@ -11,6 +11,10 @@ using namespace OpenGlass; namespace OpenGlass::GlassRenderer { + bool STDMETHODCALLTYPE MyCSolidColorLegacyMilBrush_IsOfType( + dwmcore::CSolidColorLegacyMilBrush* This, + UINT type + ); HRESULT STDMETHODCALLTYPE MyCRenderData_TryDrawCommandAsDrawList( dwmcore::CResource* This, dwmcore::CDrawingContext* drawingContext, @@ -21,19 +25,6 @@ namespace OpenGlass::GlassRenderer dwmcore::CResource** resources, bool* succeeded ); - HRESULT STDMETHODCALLTYPE MyCRenderData_DrawSolidColorRectangle( - dwmcore::CResource* This, - dwmcore::CDrawingContext* drawingContext, - dwmcore::CResource* drawListEntryBuilder, - bool unknwon, - const D2D1_RECT_F& lprc, - const D2D1_COLOR_F& color - ); - HRESULT STDMETHODCALLTYPE MyCDrawingContext_DrawSolidRectangle( - dwmcore::IDrawingContext* This, - const D2D1_RECT_F& rectangle, - const D2D1_COLOR_F& color - ); HRESULT STDMETHODCALLTYPE MyCDrawingContext_DrawGeometry( dwmcore::IDrawingContext* This, dwmcore::CLegacyMilBrush* brush, @@ -53,10 +44,8 @@ namespace OpenGlass::GlassRenderer ); void STDMETHODCALLTYPE MyCGeometry_Destructor(dwmcore::CGeometry* This); + decltype(&MyCSolidColorLegacyMilBrush_IsOfType) g_CSolidColorLegacyMilBrush_IsOfType_Org{ nullptr }; decltype(&MyCRenderData_TryDrawCommandAsDrawList) g_CRenderData_TryDrawCommandAsDrawList_Org{ nullptr }; - decltype(&MyCRenderData_DrawSolidColorRectangle) g_CRenderData_DrawSolidColorRectangle_Org{ nullptr }; - decltype(&MyCDrawingContext_DrawSolidRectangle) g_CDrawingContext_DrawSolidRectangle_Org{ nullptr }; - decltype(&MyCDrawingContext_DrawSolidRectangle)* g_CDrawingContext_DrawSolidRectangle_Org_Address{ nullptr }; decltype(&MyCDrawingContext_DrawGeometry) g_CDrawingContext_DrawGeometry_Org{ nullptr }; decltype(&MyCDrawingContext_DrawGeometry)* g_CDrawingContext_DrawGeometry_Org_Address{ nullptr }; decltype(&MyID2D1DeviceContext_FillGeometry) g_ID2D1DeviceContext_FillGeometry_Org{ nullptr }; @@ -65,10 +54,19 @@ namespace OpenGlass::GlassRenderer decltype(&MyCGeometry_Destructor) g_CGeometry_Destructor_Org{ nullptr }; PVOID* g_CSolidColorLegacyMilBrush_vftable{ nullptr }; - std::optional g_drawColor{}; IGlassEffect* g_glassEffectNoRef{ nullptr }; ID2D1Device* g_deviceNoRef{ nullptr }; dwmcore::IDrawingContext* g_drawingContextNoRef{ nullptr }; + bool g_solidColorLegacyMilBrush{ false }; +} + +bool STDMETHODCALLTYPE GlassRenderer::MyCSolidColorLegacyMilBrush_IsOfType( + dwmcore::CSolidColorLegacyMilBrush* This, + UINT type +) +{ + g_solidColorLegacyMilBrush = true; + return g_CSolidColorLegacyMilBrush_IsOfType_Org(This, type); } HRESULT STDMETHODCALLTYPE GlassRenderer::MyCRenderData_TryDrawCommandAsDrawList( @@ -82,69 +80,22 @@ HRESULT STDMETHODCALLTYPE GlassRenderer::MyCRenderData_TryDrawCommandAsDrawList( bool* succeeded ) { - g_drawColor = std::nullopt; - HRESULT hr{ g_CRenderData_TryDrawCommandAsDrawList_Org(This, drawingContext, drawListCache, drawListEntryBuilder, unknwon, commandType, resources, succeeded) }; - if (SUCCEEDED(hr) && g_drawColor) - { - *succeeded = false; - } - return hr; -} -HRESULT STDMETHODCALLTYPE GlassRenderer::MyCRenderData_DrawSolidColorRectangle( - dwmcore::CResource* This, - dwmcore::CDrawingContext* drawingContext, - dwmcore::CResource* drawListEntryBuilder, - bool unknwon, - const D2D1_RECT_F& lprc, - const D2D1_COLOR_F& color -) -{ - if ( - color.a != 1.f && - Shared::IsBackdropAllowed() - ) - { - g_drawColor = color; + g_solidColorLegacyMilBrush = false; + auto hr = g_CRenderData_TryDrawCommandAsDrawList_Org(This, drawingContext, drawListCache, drawListEntryBuilder, unknwon, commandType, resources, succeeded); - if (!g_CDrawingContext_DrawSolidRectangle_Org) - { - g_CDrawingContext_DrawSolidRectangle_Org_Address = reinterpret_cast(&(HookHelper::vtbl_of(drawingContext->GetInterface())[2])); - g_CDrawingContext_DrawSolidRectangle_Org = HookHelper::WritePointer(g_CDrawingContext_DrawSolidRectangle_Org_Address, MyCDrawingContext_DrawSolidRectangle); - } + if (SUCCEEDED(hr) && g_solidColorLegacyMilBrush && commandType == 461) + { if (!g_CDrawingContext_DrawGeometry_Org) { g_CDrawingContext_DrawGeometry_Org_Address = reinterpret_cast(&(HookHelper::vtbl_of(drawingContext->GetInterface())[4])); g_CDrawingContext_DrawGeometry_Org = HookHelper::WritePointer(g_CDrawingContext_DrawGeometry_Org_Address, MyCDrawingContext_DrawGeometry); } + *succeeded = false; return S_OK; } - return g_CRenderData_DrawSolidColorRectangle_Org( - This, - drawingContext, - drawListEntryBuilder, - unknwon, - lprc, - color - ); -} - - -HRESULT STDMETHODCALLTYPE GlassRenderer::MyCDrawingContext_DrawSolidRectangle( - dwmcore::IDrawingContext* This, - const D2D1_RECT_F& rectangle, - const D2D1_COLOR_F& color -) -{ - if (!g_drawColor.has_value()) - { - return g_CDrawingContext_DrawSolidRectangle_Org(This, rectangle, color); - } - - D2D1_COLOR_F convertedColor{ dwmcore::Convert_D2D1_COLOR_F_scRGB_To_D2D1_COLOR_F_sRGB(g_drawColor.value()) }; - g_drawColor = std::nullopt; - return g_CDrawingContext_DrawSolidRectangle_Org(This, rectangle, convertedColor); + return hr; } HRESULT STDMETHODCALLTYPE GlassRenderer::MyCDrawingContext_DrawGeometry( @@ -156,15 +107,13 @@ HRESULT STDMETHODCALLTYPE GlassRenderer::MyCDrawingContext_DrawGeometry( if ( !brush || !geometry || - HookHelper::vtbl_of(brush) != g_CSolidColorLegacyMilBrush_vftable || - !g_drawColor.has_value() + HookHelper::vtbl_of(brush) != g_CSolidColorLegacyMilBrush_vftable ) { return g_CDrawingContext_DrawGeometry_Org(This, brush, geometry); } - auto cleanUp = wil::scope_exit([] { g_drawColor = std::nullopt; }); - auto color = dwmcore::Convert_D2D1_COLOR_F_scRGB_To_D2D1_COLOR_F_sRGB(g_drawColor.value()); + auto color = dwmcore::Convert_D2D1_COLOR_F_scRGB_To_D2D1_COLOR_F_sRGB(reinterpret_cast(brush)->GetRealizedColor()); // shape is nullptr or empty dwmcore::CShapePtr geometryShape{}; @@ -296,6 +245,16 @@ HRESULT STDMETHODCALLTYPE GlassRenderer::MyCDirtyRegion__Add( const D2D1_RECT_F& lprc ) { + if (Shared::g_enableFullDirty) + { + return g_CDirtyRegion__Add_Org( + This, + visual, + unknown, + lprc + ); + } + // at high blur radius, there is no need to extend that much, // it will only cause severe flickering float extendAmount{ min(Shared::g_blurAmount * 3.f + 0.5f, 15.5f) }; @@ -379,15 +338,15 @@ void GlassRenderer::UpdateConfiguration(ConfigurationFramework::UpdateType type) HRESULT GlassRenderer::Startup() { dwmcore::GetAddressFromSymbolMap("CRenderData::TryDrawCommandAsDrawList", g_CRenderData_TryDrawCommandAsDrawList_Org); - dwmcore::GetAddressFromSymbolMap("CRenderData::DrawSolidColorRectangle", g_CRenderData_DrawSolidColorRectangle_Org); dwmcore::GetAddressFromSymbolMap("CDirtyRegion::_Add", g_CDirtyRegion__Add_Org); dwmcore::GetAddressFromSymbolMap("CGeometry::~CGeometry", g_CGeometry_Destructor_Org); dwmcore::GetAddressFromSymbolMap("CSolidColorLegacyMilBrush::`vftable'", g_CSolidColorLegacyMilBrush_vftable); + dwmcore::GetAddressFromSymbolMap("CSolidColorLegacyMilBrush::IsOfType", g_CSolidColorLegacyMilBrush_IsOfType_Org); return HookHelper::Detours::Write([]() { + HookHelper::Detours::Attach(&g_CSolidColorLegacyMilBrush_IsOfType_Org, MyCSolidColorLegacyMilBrush_IsOfType); HookHelper::Detours::Attach(&g_CRenderData_TryDrawCommandAsDrawList_Org, MyCRenderData_TryDrawCommandAsDrawList); - HookHelper::Detours::Attach(&g_CRenderData_DrawSolidColorRectangle_Org, MyCRenderData_DrawSolidColorRectangle); HookHelper::Detours::Attach(&g_CDirtyRegion__Add_Org, MyCDirtyRegion__Add); HookHelper::Detours::Attach(&g_CGeometry_Destructor_Org, MyCGeometry_Destructor); }); @@ -397,8 +356,8 @@ void GlassRenderer::Shutdown() { HookHelper::Detours::Write([]() { + HookHelper::Detours::Detach(&g_CSolidColorLegacyMilBrush_IsOfType_Org, MyCSolidColorLegacyMilBrush_IsOfType); HookHelper::Detours::Detach(&g_CRenderData_TryDrawCommandAsDrawList_Org, MyCRenderData_TryDrawCommandAsDrawList); - HookHelper::Detours::Detach(&g_CRenderData_DrawSolidColorRectangle_Org, MyCRenderData_DrawSolidColorRectangle); HookHelper::Detours::Detach(&g_CDirtyRegion__Add_Org, MyCDirtyRegion__Add); HookHelper::Detours::Detach(&g_CGeometry_Destructor_Org, MyCGeometry_Destructor); }); @@ -415,12 +374,6 @@ void GlassRenderer::Shutdown() g_CDrawingContext_DrawGeometry_Org_Address = nullptr; g_CDrawingContext_DrawGeometry_Org = nullptr; } - if (g_CDrawingContext_DrawSolidRectangle_Org) - { - HookHelper::WritePointer(g_CDrawingContext_DrawSolidRectangle_Org_Address, g_CDrawingContext_DrawSolidRectangle_Org); - g_CDrawingContext_DrawSolidRectangle_Org_Address = nullptr; - g_CDrawingContext_DrawSolidRectangle_Org = nullptr; - } GlassEffectFactory::Shutdown(); ReflectionEffect::Reset(); diff --git a/OpenGlass/Shared.hpp b/OpenGlass/Shared.hpp index 9ca1b51..a35dc4e 100644 --- a/OpenGlass/Shared.hpp +++ b/OpenGlass/Shared.hpp @@ -54,4 +54,6 @@ namespace OpenGlass::Shared return true; } + + inline bool g_enableFullDirty{ false }; } \ No newline at end of file diff --git a/OpenGlass/dwmcoreProjection.hpp b/OpenGlass/dwmcoreProjection.hpp index a0d8b25..6ab94db 100644 --- a/OpenGlass/dwmcoreProjection.hpp +++ b/OpenGlass/dwmcoreProjection.hpp @@ -207,6 +207,14 @@ namespace OpenGlass::dwmcore typedef D2D1_MATRIX_5X4_F CMILMatrix; struct CLegacyMilBrush : CResource {}; + struct CSolidColorLegacyMilBrush : CLegacyMilBrush + { + const D2D1_COLOR_F& GetRealizedColor() const + { + return *reinterpret_cast(reinterpret_cast(this) + 88); + } + }; + struct CTransform : CResource {}; struct CShape { @@ -577,13 +585,13 @@ namespace OpenGlass::dwmcore fullyUnDecoratedFunctionName == "CChannel::CombinedGeometryUpdate" || fullyUnDecoratedFunctionName == "CResource::GetOwningProcessId" || fullyUnDecoratedFunctionName == "CRenderData::TryDrawCommandAsDrawList" || - fullyUnDecoratedFunctionName == "CRenderData::DrawSolidColorRectangle" || fullyUnDecoratedFunctionName == "CGeometry::GetShapeData" || fullyUnDecoratedFunctionName == "CGeometry::~CGeometry" || fullyUnDecoratedFunctionName == "CDirtyRegion::SetFullDirty" || fullyUnDecoratedFunctionName == "CDirtyRegion::_Add" || fullyUnDecoratedFunctionName == "CVisual::GetHwnd" || fullyUnDecoratedFunctionName == "CD2DContext::GetClip" || + fullyUnDecoratedFunctionName == "CSolidColorLegacyMilBrush::IsOfType" || ( fullyUnDecoratedFunctionName.starts_with("CDrawingContext::") && fullyUnDecoratedFunctionName != "CDrawingContext::IsOccluded"