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

Tearing while 'windup' window moves #3

Open
DevonAA opened this issue Jun 28, 2023 · 0 comments
Open

Tearing while 'windup' window moves #3

DevonAA opened this issue Jun 28, 2023 · 0 comments

Comments

@DevonAA
Copy link

DevonAA commented Jun 28, 2023

Not really an issue. More like FYI.

While the 'windup' window is moved with the mouse I get a lot of tearing.
The painted image cuts off and is just white.

I've removed the WM_PAINT message handling and instead try to paint 'instantly'.
That solved the tearing issue. Except if the window is moved into the screen from outside there is still a little bit - but that makes sense because it cannot capture from outside the screens size ahead of time.

I have no clue whether this is a proper fix. Nice demo project Ben :)
Much faster capture than GDI and definitely better and easier than Microsoft docs.

case WM_TIMER:
	//if (dup.CaptureNext())
		//InvalidateRect(hWnd, nullptr, false);
	if (dup.CaptureNext())
	{
		InvalidateRect(hWnd, nullptr, false);
		PAINTSTRUCT ps;
		HDC         hdc = BeginPaint(hWnd, &ps);
		BITMAPINFO  inf;
		memset(&inf, 0, sizeof(inf));
		inf.bmiHeader.biSize        = sizeof(inf.bmiHeader);
		inf.bmiHeader.biWidth       = dup.Latest.Width;
		inf.bmiHeader.biHeight      = -dup.Latest.Height;
		inf.bmiHeader.biPlanes      = 1;
		inf.bmiHeader.biBitCount    = 32;
		inf.bmiHeader.biCompression = BI_RGB;
		void*   bits                = nullptr;
		HDC     srcDC               = CreateCompatibleDC(hdc);
		HBITMAP dib                 = CreateDIBSection(hdc, &inf, 0, &bits, nullptr, 0);
		memcpy(bits, dup.Latest.Buf.data(), dup.Latest.Width * dup.Latest.Height * 4);
		SelectObject(srcDC, dib);
		BitBlt(hdc, 0, 0, dup.Latest.Width, dup.Latest.Height, srcDC, 0, 0, SRCCOPY);
		DeleteObject(dib);
		DeleteObject(srcDC);
		EndPaint(hWnd, &ps);
	}
	break;
/*
case WM_PAINT:{
	PAINTSTRUCT ps;
	HDC         hdc = BeginPaint(hWnd, &ps);
	BITMAPINFO  inf;
	memset(&inf, 0, sizeof(inf));
	inf.bmiHeader.biSize        = sizeof(inf.bmiHeader);
	inf.bmiHeader.biWidth       = dup.Latest.Width;
	inf.bmiHeader.biHeight      = -dup.Latest.Height;
	inf.bmiHeader.biPlanes      = 1;
	inf.bmiHeader.biBitCount    = 32;
	inf.bmiHeader.biCompression = BI_RGB;
	void*   bits                = nullptr;
	HDC     srcDC               = CreateCompatibleDC(hdc);
	HBITMAP dib                 = CreateDIBSection(hdc, &inf, 0, &bits, nullptr, 0);
	memcpy(bits, dup.Latest.Buf.data(), dup.Latest.Width * dup.Latest.Height * 4);
	SelectObject(srcDC, dib);
	BitBlt(hdc, 0, 0, dup.Latest.Width, dup.Latest.Height, srcDC, 0, 0, SRCCOPY);
	DeleteObject(dib);
	DeleteObject(srcDC);
	EndPaint(hWnd, &ps);
} break;
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant