Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Provide monitor list, display size, refresh rate, and more for Windows #164460

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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

9AZX
Copy link

@9AZX 9AZX commented Mar 2, 2025

This PR enhances the Windows implementation by adding support for retrieving display properties, available displays, refresh rate, dpi, size, and more.

Fixes: #160660, #125939

Pre-launch Checklist

@github-actions github-actions bot added engine flutter/engine repository. See also e: labels. platform-windows Building on or for Windows specifically a: desktop Running on desktop labels Mar 2, 2025
@9AZX 9AZX force-pushed the windows_displays_monitor branch from b9dd753 to 71f9c40 Compare March 11, 2025 10:49
@loic-sharma loic-sharma self-requested a review March 24, 2025 17:18
@9AZX 9AZX force-pushed the windows_displays_monitor branch from 71f9c40 to 6d71dc3 Compare April 3, 2025 09:20
@flutter-dashboard
Copy link

This pull request executed golden file tests, but it has not been updated in a while (20+ days). Test results from Gold expire after as many days, so this pull request will need to be updated with a fresh commit in order to get results from Gold.

For more guidance, visit Writing a golden file test for package:flutter.

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.


// Notifies the engine about a display update.
void UpdateDisplay(const FlutterEngineDisplay* displays,
size_t displays_length);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally FlutterWindowsEngine should be a high-level C++ API. Could we make this accept a vector and have the implementation convert the vector into a pointer + size?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed !

@loic-sharma
Copy link
Member

loic-sharma commented Apr 28, 2025

@9AZX Apologies for the long response time. This is looking great! I left some minor nitpicks. Feel free to tag me when this is ready for another review.

}
}

if (!displays.empty()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you explain why you skip UpdateDisplay if there are no displays?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI, you have a test failure: https://logs.chromium.org/logs/flutter/buildbucket/cr-buildbucket/8718619884078032065/+/u/test:_Host_Tests_for_host_debug_test/stdout

Note: Google Test filter = FlutterWindowsEngineTest.RunDoesExpectedInitialization
[==========] Running 1 test from 1 test suite.
[----------] Global test environment set-up.
[----------] 1 test from FlutterWindowsEngineTest
[ RUN      ] FlutterWindowsEngineTest.RunDoesExpectedInitialization
../../../flutter/shell/platform/windows/flutter_windows_engine_unittests.cc(165): error: Value of: notify_display_update_called
  Actual: false
Expected: true

The test verifies that update display is called at startup:

// And it should send display info.
bool notify_display_update_called = false;
modifier.SetFrameInterval(16600000); // 60 fps.
modifier.embedder_api().NotifyDisplayUpdate = MOCK_ENGINE_PROC(
NotifyDisplayUpdate,
([&notify_display_update_called, engine_instance = engine.get()](
FLUTTER_API_SYMBOL(FlutterEngine) raw_engine,
const FlutterEngineDisplaysUpdateType update_type,
const FlutterEngineDisplay* embedder_displays,
size_t display_count) {
EXPECT_EQ(update_type, kFlutterEngineDisplaysUpdateTypeStartup);
EXPECT_EQ(display_count, 1);
FlutterEngineDisplay display = embedder_displays[0];
EXPECT_EQ(display.display_id, 0);
EXPECT_EQ(display.single_display, true);
EXPECT_EQ(std::floor(display.refresh_rate), 60.0);
notify_display_update_called = true;
return kSuccess;
}));

You will likely need to pass in a windows proc table that provides a display.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I initially thought skipping UpdateDisplay when there’s no display would prevent propagating invalid or incomplete info to the engine. I checked the macOS and Linux implementation and indeed it does not skip, so this can be removed :)

@9AZX 9AZX force-pushed the windows_displays_monitor branch 4 times, most recently from 5269092 to 086194e Compare May 1, 2025 07:51
@9AZX 9AZX force-pushed the windows_displays_monitor branch from 086194e to 2ec4e8f Compare May 1, 2025 07:52
@loic-sharma
Copy link
Member

FYI you have the some test failures: https://logs.chromium.org/logs/flutter/buildbucket/cr-buildbucket/8716084517876313281/+/u/test:_test:_Host_Tests_for_host_debug_unopt/stdout

[151/610] FlutterWindowsEngineTest.RunHeadless (943 ms)
[INFO:flutter/testing/test_timeout_listener.cc(75)] Test timeout of 300 seconds per test case will be enforced.
Note: Google Test filter = FlutterWindowsEngineTest.RunHeadless
[==========] Running 1 test from 1 test suite.
[----------] Global test environment set-up.
[----------] 1 test from FlutterWindowsEngineTest
[ RUN      ] FlutterWindowsEngineTest.RunHeadless
WARN: Renderer11.cpp:972 (initializeD3DDevice): Failed creating Debug D3D11 device - falling back to release runtime.
WARN: Renderer11.cpp:972 (initializeD3DDevice): Failed creating Debug D3D11 device - falling back to release runtime.
[FATAL:flutter/shell/common/display_manager.cc(27)] Check failed: !displays.empty().
[151/610] FlutterWindowsEngineTest.RunHeadless returned/aborted with exit code 3 (943 ms)
[152/610] FlutterWindowsEngineTest.PlatformMessageRespondOnDifferentThread (882 ms)
[INFO:flutter/testing/test_timeout_listener.cc(75)] Test timeout of 300 seconds per test case will be enforced.
Note: Google Test filter = FlutterWindowsEngineTest.PlatformMessageRespondOnDifferentThread

FYI, you can run these tests locally on your machine by running out/flutter_windows_unittests.exe.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a: desktop Running on desktop engine flutter/engine repository. See also e: labels. platform-windows Building on or for Windows specifically
Projects
None yet
Development

Successfully merging this pull request may close these issues.

WidgetsBinding.instance.platformDispatcher.displays.first.size returns Size(0.0, 0.0) zero on Windows
2 participants