Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: Some cleanup is needed when closing the window #1

Closed
wangwenx190 opened this issue Jul 11, 2021 · 7 comments
Closed

BUG: Some cleanup is needed when closing the window #1

wangwenx190 opened this issue Jul 11, 2021 · 7 comments
Labels
good first issue Good for newcomers

Comments

@wangwenx190
Copy link

Hi, bro, thanks for the fantastic repo! It's quite impressive!

But when I was debugging this repo in Qt Creator, I got some warning messages when the window is closing:

DXGI WARNING: Process is terminating. Using simple reporting. Please call ReportLiveObjects() at runtime for standard reporting. [ STATE_CREATION WARNING #0: ]
DXGI WARNING: Live Producer at 0x0000025575ED72E8, Refcount: 4. [ STATE_CREATION WARNING #0: ]

Looks like some cleanup is needed at window shutdown. Do you have any clue of how to fix it?

BTW, I'm using a 4K monitor and I set scale factor to 250%, I found that the acrylic background is too large. But if I set dpi awareness to PerMonitorV2 programtically, it looks normal again. Maybe you should fix this as well. But using the manifest file is easier.

@selastingeorge
Copy link
Owner

selastingeorge commented Jul 11, 2021

Bro, I have noticed the issue about DXGI warning earlier, i think it is from the D3D11, any way I will look into it. and I will also add the dpi awareness. Did you make it work on QT, will you be able to draw anything on top of the acrylic

@selastingeorge
Copy link
Owner

Bro I have updated the code, Added DPI Awareness and Fixed the memory leak.

@selastingeorge selastingeorge added the good first issue Good for newcomers label Jul 11, 2021
@wangwenx190
Copy link
Author

Thanks for your great work!

@wangwenx190
Copy link
Author

Did you make it work on QT, will you be able to draw anything on top of the acrylic

I'm porting this repo to Qt and is making some progress indeed. I'm not able to draw on top of the acrylic either. My solution is creating two windows, one is the real window but have a transparent background, the other is the acrylic window, then place the acrylic window under the real window. I hooked the real window's WndProc function to make the acrylic window sync it's position with the real window. Once it's done, I'll let you know.

@selastingeorge
Copy link
Owner

Did you make it work on QT, will you be able to draw anything on top of the acrylic

I'm porting this repo to Qt and is making some progress indeed. I'm not able to draw on top of the acrylic either. My solution is creating two windows, one is the real window but have a transparent background, the other is the acrylic window, then place the acrylic window under the real window. I hooked the real window's WndProc function to make the acrylic window sync it's position with the real window. Once it's done, I'll let you know.

Ya i tried this method with WPF, I was actually able to draw contents on top, but syncing the position is too slow. There is one other way also to overcome this problem. there is an easy way to draw on top of acrylic, there is a method in Direct composition to copy the contents of one window to another (i mean the visual like DWM thumbnail). then all you need to do is forward all events from one window to another.

I will explain you with a demo.

IDCompositionDevice::CreateSurfaceFromHwnd() : with this function you can copy all the contents in a window to another same as DWMThumbnail. but in the case of dwm thumbnail you will not be able to alter the visual rendered to window, but it is possible in this method.

CreateSurfaceFromHwnd() takes two parameter hwnd and IUnknown.

HRESULT hr = S_OK;
IDCompositionVisual *pVisual = nullptr;
IUnknown *pSurface = nullptr;

// Create a visual. g_pDevice is the IDCompositionDevice pointer of a 
// device object created earlier.
hr = g_pDevice->CreateVisual(&pVisual);

if (SUCCEEDED(hr))
{
    // Create a surface that contains the image of the layered child 
    // window identified by the g_hwndChild window handle (HWND). 
    hr = g_pDevice->CreateSurfaceFromHwnd(g_hwndChild, &pSurface);
}

if (SUCCEEDED(hr))
{
    // Set the content of the Control child visual.
    hr = pVisual->SetContent(pSurface);
}

with this code you can get the content of a window into IDCompositionVisual, in this repo the acrylic is actually rendered to a visual.so it is possible to overlap the window visual on top of acrylic visual. See this part of my code.

case AcrylicCompositor::BACKDROP_SOURCE_HOSTBACKDROP:
rootVisual->AddVisual(desktopWindowVisual.Get(), false, NULL);
rootVisual->AddVisual(topLevelWindowVisual.Get(), true, desktopWindowVisual.Get());
rootVisual->AddVisual(fallbackVisual.Get(), true, topLevelWindowVisual.Get());
break;

Here the AddVisual() adds another visuals into the root visual, the first parameter is the visual to be added, the second parameter is a Boolean which specifies whether to place top of another visual or not. the third parameter is the previous visual.(which means the new visual will overlap the previous visual).

This will help you to create the visual of one window and place on top of other, but the both windows should be of the same program (thread)

The you must forward all events from one window to another (i mean all click,drag etc..)

@wangwenx190
Copy link
Author

Thanks for your detailed reply, I really learned a lot! But it seems your solution also needs two windows, or am I misunderstand something?
Anyway, if my solution goes to an dead end, I'll try your solution.

@selastingeorge
Copy link
Owner

selastingeorge commented Jul 12, 2021

Thanks for your detailed reply, I really learned a lot! But it seems your solution also needs two windows, or am I misunderstand something?
Anyway, if my solution goes to an dead end, I'll try your solution.

you need two windows but it will remove the sync delay, it is really fast like DWM Thumbnail, and to reduce the memory usage you can use DWMA_CLOAK attribute for the original window. works really better than overlapping window. Haven't you tried winrt acrylic, its easier than this, i will upload a sample later

join here : Discord Channel, we can have a lot of discussions there

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants