[Windows] Fix GDI resource leaks in the software fallback path (flutter/engine#34574)
Updates `FlutterWindowWin32::OnBitmapSurfaceUpdated` to release the device context using `ReleaseDC`. Fixes: https://github.com/flutter/flutter/issues/107368
This commit is contained in:
@@ -249,7 +249,7 @@ void FlutterWindowWin32::OnResetImeComposing() {
|
||||
bool FlutterWindowWin32::OnBitmapSurfaceUpdated(const void* allocation,
|
||||
size_t row_bytes,
|
||||
size_t height) {
|
||||
HDC dc = ::GetDC(std::get<HWND>(GetRenderTarget()));
|
||||
HDC dc = ::GetDC(GetWindowHandle());
|
||||
BITMAPINFO bmi;
|
||||
memset(&bmi, 0, sizeof(bmi));
|
||||
bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
|
||||
@@ -261,6 +261,7 @@ bool FlutterWindowWin32::OnBitmapSurfaceUpdated(const void* allocation,
|
||||
bmi.bmiHeader.biSizeImage = 0;
|
||||
int ret = SetDIBitsToDevice(dc, 0, 0, row_bytes / 4, height, 0, 0, 0, height,
|
||||
allocation, &bmi, DIB_RGB_COLORS);
|
||||
::ReleaseDC(GetWindowHandle(), dc);
|
||||
return ret != 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -211,6 +211,20 @@ TEST(FlutterWindowWin32Test, CreateDestroy) {
|
||||
ASSERT_TRUE(TRUE);
|
||||
}
|
||||
|
||||
TEST(FlutterWindowWin32Test, OnBitmapSurfaceUpdated) {
|
||||
FlutterWindowWin32 win32window(100, 100);
|
||||
int old_handle_count = GetGuiResources(GetCurrentProcess(), GR_GDIOBJECTS);
|
||||
|
||||
constexpr size_t row_bytes = 100 * 4;
|
||||
constexpr size_t height = 100;
|
||||
std::array<char, row_bytes * height> allocation;
|
||||
win32window.OnBitmapSurfaceUpdated(allocation.data(), row_bytes, height);
|
||||
|
||||
int new_handle_count = GetGuiResources(GetCurrentProcess(), GR_GDIOBJECTS);
|
||||
// Check GDI resources leak
|
||||
EXPECT_EQ(old_handle_count, new_handle_count);
|
||||
}
|
||||
|
||||
// Tests that composing rect updates are transformed from Flutter logical
|
||||
// coordinates to device coordinates and passed to the text input manager
|
||||
// when the DPI scale is 100% (96 DPI).
|
||||
|
||||
Reference in New Issue
Block a user