Hi @Omar Mohamed ,
Thanks for reaching out.
With a DirectComposition swap chain, that scaling mode is generally expected, so it probably makes sense to keep DXGI_SCALING_STRETCH here rather than trying to move to DXGI_SCALING_NONE. The flicker seems to happen because, during resize, the compositor can keep showing the previous frame stretched until a fully rendered frame at the new size is ready.
What may help most here is making sure a complete new frame is produced as quickly as possible after ResizeBuffers(). In your current flow, after resizing you recreate the bitmap and call drawWindow(), but that alone does not look like a full render pass. Since your normal pipeline is BeginDraw(), then draw, then EndDraw(), it would probably be better to run that full sequence immediately after the resize so the new frame can replace the stretched one sooner.
So the flow would likely be: release the old target references, call ResizeBuffers(), recreate the D2D bitmap target, then draw the new frame, end the draw, present it, and finally commit the DirectComposition device. If your EndDraw() wrapper already performs the present internally, then it would make sense to rely on that instead of presenting twice.
I would also consider removing DwmFlush() from the resize path. In this case it may be working against you by forcing synchronization while the old frame is still visible, which can make the transition more noticeable rather than smoother.
Something along these lines may work better, although the exact changes may need to be adjusted a bit to fit the way your project wraps drawing and presentation:
HRESULT hr = d->dxgiSwapChain->ResizeBuffers(
0,
width,
height,
DXGI_FORMAT_UNKNOWN,
0
);
if (SUCCEEDED(hr))
{
CreateD2DBitmap();
d->d2dDeviceContext->BeginDraw();
drawWindow();
hr = d->d2dDeviceContext->EndDraw();
if (SUCCEEDED(hr))
{
d->dxgiSwapChain->Present(1, 0);
if (d->dcompDevice)
d->dcompDevice->Commit();
}
}
Your WM_ERASEBKGND handling already looks good, and releasing the old back-buffer references before ResizeBuffers() still seems like the correct approach. I would also double-check that the window class is not using CS_HREDRAW or CS_VREDRAW, and that the background brush is nullptr, because those can sometimes introduce extra redraws during resizing.
Hope this helps! If my answer was helpful, I would greatly appreciate it if you could follow the instructions here so others with the same problem can benefit as well.