Kaynağa Gözat

When manually calling the canvas upload, events will also be prefetched, so that one does not have to wait for the canvas nor have input events starved.

David Piuva 2 yıl önce
ebeveyn
işleme
e4a6e50177
1 değiştirilmiş dosya ile 15 ekleme ve 7 silme
  1. 15 7
      Source/windowManagers/Win32Window.cpp

+ 15 - 7
Source/windowManagers/Win32Window.cpp

@@ -53,6 +53,7 @@ private:
 	// Called before the application fetches events from the input queue
 	// Called before the application fetches events from the input queue
 	//   Closing the window, moving the mouse, pressing a key, et cetera
 	//   Closing the window, moving the mouse, pressing a key, et cetera
 	void prefetchEvents() override;
 	void prefetchEvents() override;
+	void prefetchEvents_impl();
 
 
 	// Called to change the cursor visibility and returning true on success
 	// Called to change the cursor visibility and returning true on success
 	bool setCursorVisibility(bool visible) override;
 	bool setCursorVisibility(bool visible) override;
@@ -517,7 +518,7 @@ static LRESULT CALLBACK WindowProcedure(HWND hwnd, UINT message, WPARAM wParam,
 		}
 		}
 		break;
 		break;
 	case WM_PAINT:
 	case WM_PAINT:
-		parent->queueInputEvent(new dsr::WindowEvent(dsr::WindowEventType::Redraw, parent->windowWidth, parent->windowHeight));
+		//parent->queueInputEvent(new dsr::WindowEvent(dsr::WindowEventType::Redraw, parent->windowWidth, parent->windowHeight));
 		// BeginPaint and EndPaint must be called with the given hwnd to prevent having the redraw message sent again
 		// BeginPaint and EndPaint must be called with the given hwnd to prevent having the redraw message sent again
 		parent->redraw(hwnd, false, false);
 		parent->redraw(hwnd, false, false);
 		// Passing on the event to prevent flooding with more messages. This is only a temporary solution.
 		// Passing on the event to prevent flooding with more messages. This is only a temporary solution.
@@ -542,15 +543,19 @@ static LRESULT CALLBACK WindowProcedure(HWND hwnd, UINT message, WPARAM wParam,
 	return result;
 	return result;
 }
 }
 
 
+void Win32Window::prefetchEvents_impl() {
+	MSG messages;
+	if (IsWindowUnicode(this->hwnd)) {
+		while (PeekMessageW(&messages, NULL, 0, 0, PM_REMOVE)) { TranslateMessage(&messages); DispatchMessage(&messages); }
+	} else {
+		while (PeekMessage(&messages, NULL, 0, 0, PM_REMOVE)) { TranslateMessage(&messages); DispatchMessage(&messages); }
+	}
+}
+
 void Win32Window::prefetchEvents() {
 void Win32Window::prefetchEvents() {
 	// Only prefetch new events if nothing else is locking.
 	// Only prefetch new events if nothing else is locking.
 	if (windowLock.try_lock()) {
 	if (windowLock.try_lock()) {
-		MSG messages;
-		if (IsWindowUnicode(this->hwnd)) {
-			while (PeekMessageW(&messages, NULL, 0, 0, PM_REMOVE)) { TranslateMessage(&messages); DispatchMessage(&messages); }
-		} else {
-			while (PeekMessage(&messages, NULL, 0, 0, PM_REMOVE)) { TranslateMessage(&messages); DispatchMessage(&messages); }
-		}
+		this->prefetchEvents_impl();
 		windowLock.unlock();
 		windowLock.unlock();
 	}
 	}
 }
 }
@@ -594,7 +599,10 @@ void Win32Window::redraw(HWND& hwnd, bool lock, bool swap) {
 	#endif
 	#endif
 
 
 	if (lock) {
 	if (lock) {
+		// Any other requests will have to wait.
 		windowLock.lock();
 		windowLock.lock();
+		// Last chance to prefetch events before uploading the canvas.
+		this->prefetchEvents_impl();
 	}
 	}
 	if (swap) {
 	if (swap) {
 		this->drawIndex = (this->drawIndex + 1) % bufferCount;
 		this->drawIndex = (this->drawIndex + 1) % bufferCount;