Browse Source

Faster Win32 image upload based on feedback. Will have to be tested because it now draws padding pixels outside of the window.

David Piuva 5 years ago
parent
commit
3c2ab28e66
1 changed files with 8 additions and 8 deletions
  1. 8 8
      Source/windowManagers/Win32Window.cpp

+ 8 - 8
Source/windowManagers/Win32Window.cpp

@@ -453,16 +453,16 @@ void Win32Window::redraw(HWND& hwnd) {
 	int width = dsr::image_getWidth(this->canvas);
 	int height = dsr::image_getHeight(this->canvas);
 	InvalidateRect(this->hwnd, NULL, false);
-	BITMAP bitmap;
-	HBITMAP sourceBitmapHandle = CreateBitmap(paddedWidth, height, 1, 32, dsr::image_dangerous_getData(this->canvas));
 	PAINTSTRUCT paintStruct;
 	HDC targetContext = BeginPaint(this->hwnd, &paintStruct);
-		HDC sourceContext = CreateCompatibleDC(targetContext);
-		HGDIOBJ sourceBitmap = SelectObject(sourceContext, sourceBitmapHandle);
-		GetObject(sourceBitmapHandle, sizeof(BITMAP), &bitmap);
-		BitBlt(targetContext, 0, 0, width, height, sourceContext, 0, 0, SRCCOPY);
-		SelectObject(sourceContext, sourceBitmap);
-		DeleteDC(sourceContext);
+		BITMAPINFO bmi = {};
+		bmi.bmiHeader.biSize = sizeof(bmi.bmiHeader);
+		bmi.bmiHeader.biWidth = paddedWidth;
+		bmi.bmiHeader.biHeight = -height;
+		bmi.bmiHeader.biPlanes = 1;
+		bmi.bmiHeader.biBitCount = 32;
+		bmi.bmiHeader.biCompression = BI_RGB;
+		SetDIBitsToDevice(targetContext, 0, 0, paddedWidth, height, 0, 0, 0, height, dsr::image_dangerous_getData(this->canvas), &bmi, DIB_RGB_COLORS);
 	EndPaint(this->hwnd, &paintStruct);
 }