Closed Bug 1356218 Opened 7 years ago Closed 7 years ago

screen.colorDepth always returns primary monitor's color depth

Categories

(Core :: Widget: Win32, defect)

50 Branch
All
Windows 7
defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla55
Tracking Status
firefox55 --- fixed

People

(Reporter: emk, Unassigned)

References

Details

Attachments

(2 files)

Steps to reproduce:
1. Setup a multimonitor system.
2. Set primary monitor's color depth to 32bpp.
3. Set secondary monitor's color depth to 16bpp.
4. Launch Firefox and open an window on the secondary monitor.
5. Get screen.colorDepth (for example using web console).

Actual result:
32

Expected result:
16
Comment on attachment 8857917 [details]
Bug 1356218 - Make screen.colorDepth multi-monitor aware.

https://reviewboard.mozilla.org/r/129948/#review132530

Hm, this patch did not work somehow. Investigating...
Attachment #8857917 - Flags: review?(jmathies)
Comment on attachment 8858275 [details]
Bug 1356218 - Fix nsDeviceContext::GetDepth to use the information from the correct monitor.

https://reviewboard.mozilla.org/r/130262/#review132990

::: gfx/src/nsDeviceContext.cpp:402
(Diff revision 1)
> -    if (mDepth == 0 && mScreenManager) {
> -        nsCOMPtr<nsIScreen> primaryScreen;
> -        mScreenManager->GetPrimaryScreen(getter_AddRefs(primaryScreen));
> -        primaryScreen->GetColorDepth(reinterpret_cast<int32_t *>(&mDepth));
> +    nsCOMPtr<nsIScreen> screen;
> +    FindScreen(getter_AddRefs(screen));
> +    if (screen) {
> +        screen->GetColorDepth(reinterpret_cast<int32_t *>(&aDepth));
>      }

What should we do if FindScreen fails to return a screen here? (Maybe the most correct would be to return NOT_AVAILABLE, and check callers to confirm they will handle failure in a reasonable way.)
Comment on attachment 8858275 [details]
Bug 1356218 - Fix nsDeviceContext::GetDepth to use the information from the correct monitor.

https://reviewboard.mozilla.org/r/130262/#review132990

> What should we do if FindScreen fails to return a screen here? (Maybe the most correct would be to return NOT_AVAILABLE, and check callers to confirm they will handle failure in a reasonable way.)

I made GetDepth infallible. (GetPrimaryScreen will never fail, even in xpcshell or headless)
Comment on attachment 8858275 [details]
Bug 1356218 - Fix nsDeviceContext::GetDepth to use the information from the correct monitor.

https://reviewboard.mozilla.org/r/130262/#review133166
Attachment #8858275 - Flags: review?(jfkthame) → review+
Comment on attachment 8857917 [details]
Bug 1356218 - Make screen.colorDepth multi-monitor aware.

https://reviewboard.mozilla.org/r/129950/#review133360

::: widget/windows/ScreenHelperWin.cpp:73
(Diff revision 4)
>  ScreenHelperWin::RefreshScreens()
>  {
>    MOZ_LOG(sScreenLog, LogLevel::Debug, ("Refreshing screens"));
>  
>    AutoTArray<RefPtr<Screen>, 4> screens;
> -  BOOL result = ::EnumDisplayMonitors(nullptr, nullptr,
> +  HDC hdc = ::CreateDC(L"DISPLAY", nullptr, nullptr, nullptr);

If this fails, is anything going to break here?
Attachment #8857917 - Flags: review?(jmathies) → review+
Comment on attachment 8857917 [details]
Bug 1356218 - Make screen.colorDepth multi-monitor aware.

https://reviewboard.mozilla.org/r/129950/#review133382

::: widget/windows/ScreenHelperWin.cpp:73
(Diff revision 4)
>  ScreenHelperWin::RefreshScreens()
>  {
>    MOZ_LOG(sScreenLog, LogLevel::Debug, ("Refreshing screens"));
>  
>    AutoTArray<RefPtr<Screen>, 4> screens;
> -  BOOL result = ::EnumDisplayMonitors(nullptr, nullptr,
> +  HDC hdc = ::CreateDC(L"DISPLAY", nullptr, nullptr, nullptr);

If by any chance CreateDC fails, it will return NULL. Then CollectMonitors will receive NULL hDCScreen. Then GetDeviceCaps will fail. Then pixelDepth will be zero.

I moved NS_ASSERTION here. But I don't think we need additional checks for the edge case.
Pushed by VYV03354@nifty.ne.jp:
https://hg.mozilla.org/integration/autoland/rev/33856a082922
Make screen.colorDepth multi-monitor aware. r=jimm
https://hg.mozilla.org/integration/autoland/rev/de2c3726bd36
Fix nsDeviceContext::GetDepth to use the information from the correct monitor. r=jfkthame
https://hg.mozilla.org/mozilla-central/rev/33856a082922
https://hg.mozilla.org/mozilla-central/rev/de2c3726bd36
Status: NEW → RESOLVED
Closed: 7 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla55
Depends on: 1533894
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: