Skip to content

Commit e3b85a6

Browse files
committed
fixes
fix #129 fix #128 fix #126
1 parent 031d849 commit e3b85a6

File tree

7 files changed

+67
-37
lines changed

7 files changed

+67
-37
lines changed

OpenGlass/GlassRenderer.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ HRESULT STDMETHODCALLTYPE GlassRenderer::MyCDrawingContext_DrawGeometry(
428428
{
429429
if (
430430
glassCoverageSet->IsFullyCovered(
431-
occlusionConctext->PageInPixelsRectToDeviceRect(shapeWorldBounds),
431+
shapeWorldBounds,
432432
drawingContext->GetD2DContextOwner()->GetCurrentZ()
433433
)
434434
)
@@ -443,6 +443,9 @@ HRESULT STDMETHODCALLTYPE GlassRenderer::MyCDrawingContext_DrawGeometry(
443443
g_glassInput.params.optimization = Shared::g_blurOptimization;
444444
}
445445

446+
// temporary disable zero copy
447+
// 2025/5/26
448+
g_glassInput.zeroCopyAllowed = false;
446449
if (g_glassInput.zeroCopyAllowed)
447450
{
448451
winrt::com_ptr<ID2D1ColorContext> colorContext;
@@ -468,9 +471,6 @@ HRESULT STDMETHODCALLTYPE GlassRenderer::MyCDrawingContext_DrawGeometry(
468471
g_glassInput.zeroCopyAllowed = false;
469472
}
470473
}
471-
// temporary disable zero copy
472-
// 2025/5/26
473-
g_glassInput.zeroCopyAllowed = false;
474474

475475
g_glassInput.sourceBitmap = sharedAtlasBitmap.get() ? sharedAtlasBitmap.get() : renderTargetBitmap.get();
476476
g_glassInput.rectangles = std::span{ rectangles.get(), rectanglesCount };

OpenGlass/GlassSafetyZone.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ namespace OpenGlass::GlassSafetyZone
8484
dwmcore::CDrawingContext* This,
8585
const D2D1_RECT_F& rectangle,
8686
dwmcore::COcclusionContext* occlusionContext,
87-
bool enableSuperSample,
87+
bool useSuperSample,
8888
T&& callback
8989
);
9090
HRESULT STDMETHODCALLTYPE MyCDrawingContext_DrawVisualTree_Win10(
@@ -93,15 +93,15 @@ namespace OpenGlass::GlassSafetyZone
9393
const D2D1_RECT_F& rectangle,
9494
dwmcore::COcclusionContext* occlusionContext,
9595
int clearMode,
96-
bool enableSuperSample
96+
bool useSuperSample
9797
);
9898
HRESULT STDMETHODCALLTYPE MyCDrawingContext_DrawVisualTree_Win11(
9999
dwmcore::CDrawingContext* This,
100100
dwmcore::CVisualTree* tree,
101101
const D2D1_RECT_F& rectangle,
102102
dwmcore::COcclusionContext* occlusionContext,
103103
int clearMode,
104-
bool enableSuperSample,
104+
bool useSuperSample,
105105
dwmcore::CVisual* visualOverride
106106
);
107107

@@ -701,7 +701,7 @@ HRESULT STDMETHODCALLTYPE GlassSafetyZone::MyCDrawingContext_DrawVisualTree(
701701
dwmcore::CDrawingContext* This,
702702
const D2D1_RECT_F& rectangle,
703703
dwmcore::COcclusionContext* occlusionContext,
704-
bool enableSuperSample,
704+
bool useSuperSample,
705705
T&& callback
706706
)
707707
{
@@ -716,8 +716,7 @@ HRESULT STDMETHODCALLTYPE GlassSafetyZone::MyCDrawingContext_DrawVisualTree(
716716

717717
if (
718718
!occlusionContext ||
719-
occlusionContext->GetFrameId() != dwmcore::GetCurrentFrameId() ||
720-
enableSuperSample
719+
occlusionContext->GetFrameId() != dwmcore::GetCurrentFrameId()
721720
)
722721
{
723722
break;
@@ -781,7 +780,8 @@ HRESULT STDMETHODCALLTYPE GlassSafetyZone::MyCDrawingContext_DrawVisualTree(
781780
renderTargetBitmap.get(),
782781
This->GetDeviceTransform()->GetD2DMatrix(),
783782
rectangle,
784-
extendedAmount
783+
extendedAmount,
784+
useSuperSample
785785
)
786786
)
787787
)
@@ -813,14 +813,14 @@ HRESULT STDMETHODCALLTYPE GlassSafetyZone::MyCDrawingContext_DrawVisualTree_Win1
813813
const D2D1_RECT_F& rectangle,
814814
dwmcore::COcclusionContext* occlusionContext,
815815
int clearMode,
816-
bool enableSuperSample
816+
bool useSuperSample
817817
)
818818
{
819819
return MyCDrawingContext_DrawVisualTree(
820820
This,
821821
rectangle,
822822
occlusionContext,
823-
enableSuperSample,
823+
useSuperSample,
824824
[=](const D2D1_RECT_F& replacedRectangle)
825825
{
826826
return reinterpret_cast<decltype(&MyCDrawingContext_DrawVisualTree_Win10)>(g_CDrawingContext_DrawVisualTree_Org)(
@@ -829,7 +829,7 @@ HRESULT STDMETHODCALLTYPE GlassSafetyZone::MyCDrawingContext_DrawVisualTree_Win1
829829
replacedRectangle,
830830
occlusionContext,
831831
clearMode,
832-
enableSuperSample
832+
useSuperSample
833833
);
834834
}
835835
);
@@ -840,15 +840,15 @@ HRESULT STDMETHODCALLTYPE GlassSafetyZone::MyCDrawingContext_DrawVisualTree_Win1
840840
const D2D1_RECT_F& rectangle,
841841
dwmcore::COcclusionContext* occlusionContext,
842842
int clearMode,
843-
bool enableSuperSample,
843+
bool useSuperSample,
844844
dwmcore::CVisual* visualOverride
845845
)
846846
{
847847
return MyCDrawingContext_DrawVisualTree(
848848
This,
849849
rectangle,
850850
occlusionContext,
851-
enableSuperSample,
851+
useSuperSample,
852852
[=](const D2D1_RECT_F& replacedRectangle)
853853
{
854854
return reinterpret_cast<decltype(&MyCDrawingContext_DrawVisualTree_Win11)>(g_CDrawingContext_DrawVisualTree_Org)(
@@ -857,7 +857,7 @@ HRESULT STDMETHODCALLTYPE GlassSafetyZone::MyCDrawingContext_DrawVisualTree_Win1
857857
replacedRectangle,
858858
occlusionContext,
859859
clearMode,
860-
enableSuperSample,
860+
useSuperSample,
861861
visualOverride
862862
);
863863
}

OpenGlass/GlassSafetyZoneLayer.cpp

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ HRESULT CGlassSafetyZoneLayer::Push(
99
ID2D1Bitmap1* renderTargetBitmap,
1010
const D2D1_MATRIX_3X2_F& deviceTransform,
1111
const D2D1_RECT_F& originalPixelRectangle,
12-
float extendedAmount
12+
float extendedAmount,
13+
[[maybe_unused]] bool useSuperSample
1314
)
1415
{
1516
m_renderTargetBitmap.copy_from(renderTargetBitmap);
@@ -26,19 +27,25 @@ HRESULT CGlassSafetyZoneLayer::Push(
2627
targetSize.height
2728
};
2829

29-
auto originalDeviceRectangle = RectF::TransformRect(originalPixelRectangle, deviceTransform);
30+
D2D1_RECT_F originalDeviceRectangle;
3031
D2D1_RECT_F extendedDeviceRectangle;
3132

33+
originalDeviceRectangle = RectF::TransformRect(originalPixelRectangle, deviceTransform);
3234
originalDeviceRectangle.left = std::floor(originalDeviceRectangle.left);
3335
originalDeviceRectangle.top = std::floor(originalDeviceRectangle.top);
3436
originalDeviceRectangle.right = std::ceil(originalDeviceRectangle.right);
3537
originalDeviceRectangle.bottom = std::ceil(originalDeviceRectangle.bottom);
3638
RectF::IntersectUnsafe(originalDeviceRectangle, targetRect);
3739

38-
extendedDeviceRectangle.left = std::floor(originalDeviceRectangle.left - extendedAmount);
39-
extendedDeviceRectangle.top = std::floor(originalDeviceRectangle.top - extendedAmount);
40-
extendedDeviceRectangle.right = std::ceil(originalDeviceRectangle.right + extendedAmount);
41-
extendedDeviceRectangle.bottom = std::ceil(originalDeviceRectangle.bottom + extendedAmount);
40+
extendedDeviceRectangle.left = originalPixelRectangle.left - extendedAmount;
41+
extendedDeviceRectangle.top = originalPixelRectangle.top - extendedAmount;
42+
extendedDeviceRectangle.right = originalPixelRectangle.right + extendedAmount;
43+
extendedDeviceRectangle.bottom = originalPixelRectangle.bottom + extendedAmount;
44+
extendedDeviceRectangle = RectF::TransformRect(extendedDeviceRectangle, deviceTransform);
45+
extendedDeviceRectangle.left = std::floor(extendedDeviceRectangle.left);
46+
extendedDeviceRectangle.top = std::floor(extendedDeviceRectangle.top);
47+
extendedDeviceRectangle.right = std::ceil(extendedDeviceRectangle.right);
48+
extendedDeviceRectangle.bottom = std::ceil(extendedDeviceRectangle.bottom);
4249
RectF::IntersectUnsafe(extendedDeviceRectangle, targetRect);
4350

4451
m_safetyZoneBounds[0] =
@@ -70,16 +77,27 @@ HRESULT CGlassSafetyZoneLayer::Push(
7077
static_cast<UINT32>(extendedDeviceRectangle.bottom)
7178
};
7279

80+
D2D1_RECT_F extendedRectangle
81+
{
82+
0.f,
83+
0.f,
84+
extendedAmount,
85+
extendedAmount
86+
};
87+
extendedRectangle = RectF::TransformRect(extendedRectangle, deviceTransform);
88+
const auto actualExtendedAmountX = wil::rect_width(extendedRectangle);
89+
const auto actualExtendedAmountY = wil::rect_height(extendedRectangle);
90+
7391
m_safetyZoneBufferVertical.Resize(
7492
D2D1::SizeU(
75-
static_cast<UINT32>(std::ceil(extendedAmount)) * 2,
76-
static_cast<UINT32>(std::ceil(targetSize.height + extendedAmount))
93+
static_cast<UINT32>(std::ceil(actualExtendedAmountX)) * 2,
94+
static_cast<UINT32>(std::ceil(targetSize.height + actualExtendedAmountY))
7795
)
7896
);
7997
m_safetyZoneBufferHorizon.Resize(
8098
D2D1::SizeU(
81-
static_cast<UINT32>(std::ceil(targetSize.width + extendedAmount)),
82-
static_cast<UINT32>(std::ceil(extendedAmount)) * 2
99+
static_cast<UINT32>(std::ceil(targetSize.width + actualExtendedAmountX)),
100+
static_cast<UINT32>(std::ceil(actualExtendedAmountY)) * 2
83101
)
84102
);
85103

OpenGlass/GlassSafetyZoneLayer.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ namespace OpenGlass
1616
ID2D1Bitmap1* renderTargetBitmap,
1717
const D2D1_MATRIX_3X2_F& deviceTransform,
1818
const D2D1_RECT_F& originalPixelRectangle,
19-
float extendedAmount
19+
float extendedAmount,
20+
bool useSuperSample
2021
);
2122
void Pop();
2223
void Reset();

OpenGlass/GlassService.cpp

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -317,17 +317,12 @@ HRESULT GlassService::RunInjectionThread()
317317
it++;
318318
}
319319
}
320-
DWORD activeSessionId{ 0ul };
321-
if (activeSessionId = WTSGetActiveConsoleSessionId(); activeSessionId == 0xFFFFFFFF)
322-
{
323-
goto wait_until_next_cycle;
324-
}
325320
if (g_injectionThreadStatus == ThreadStatus::Paused)
326321
{
327322
goto wait_until_next_cycle;
328323
}
329324

330-
WalkDwmProcesses([&hr, activeSessionId](DWORD processId) -> bool
325+
WalkDwmProcesses([&hr](DWORD processId) -> bool
331326
{
332327
if (g_injectionThreadStatus == ThreadStatus::Paused)
333328
{
@@ -339,7 +334,22 @@ HRESULT GlassService::RunInjectionThread()
339334
{
340335
return true;
341336
}
342-
if (activeSessionId != sessionId)
337+
DWORD bytesReturned{};
338+
wil::unique_wtsmem_ptr<WTS_CONNECTSTATE_CLASS> buffer{};
339+
if (
340+
!WTSQuerySessionInformationW(
341+
WTS_CURRENT_SERVER_HANDLE,
342+
sessionId,
343+
WTSConnectState,
344+
reinterpret_cast<LPWSTR*>(&buffer),
345+
&bytesReturned
346+
) ||
347+
!buffer ||
348+
(
349+
*buffer != WTSActive &&
350+
*buffer != WTSConnected
351+
)
352+
)
343353
{
344354
return true;
345355
}

OpenGlass/OpenGlass.rc

0 Bytes
Binary file not shown.

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@ This utility returns the full glass effect to the window frame, just like [glass
2121
2. Run `install.cmd` as administrator, this will create a scheduled task for you to run the OpenGlass host process which will inject DLL into DWM for you and also maintains that user settings are correctly loaded.
2222
3. Run `startup.cmd` as administrator, this will run the host process manually.
2323
4. When you use it for the first time or just after updating your system, OpenGlass will try to download the symbol files and you will see its symbol downloading dialog, just be patient for about 15s. When the symbol files are ready, enjoy!
24-
5. When you want to stop using OpenGlass or update the version of OpenGlass, running `shutdown.cmd` will remove the effects of OpenGlass for you and exit the host process. At this time, you can either replace the OpenGlass files or continue to run `uninstall.cmd` and manually delete the remaining files to complete the uninstallation.
25-
6. When you experience a crash, OpenGlass is supposed to generate a large memory dump file in the `dumps` directory of the folder where it is located, please submit it to the developer if possible, this can help fix known or potential issues.
24+
5. If OpenGlass is unable to download symbols, you can try running the `symchk-prepare-symbols.cmd`.
25+
6. When you want to stop using OpenGlass or update the version of OpenGlass, running `shutdown.cmd` will remove the effects of OpenGlass for you and exit the host process. At this time, you can either replace the OpenGlass files or continue to run `uninstall.cmd` and manually delete the remaining files to complete the uninstallation.
26+
7. When you experience a crash, OpenGlass is supposed to generate a large memory dump file in the `dumps` directory of the folder where it is located, please submit it to the developer if possible, this can help fix known or potential issues.
2627

2728
## What are the DWM symbols and where to get them? <br>I see "Your DWM is incompatible" message. What to do?
2829

0 commit comments

Comments
 (0)