Bug 1356218 - Make screen.colorDepth multi-monitor aware. r=jimm draft
authorMasatoshi Kimura <VYV03354@nifty.ne.jp>
Tue, 18 Apr 2017 00:21:55 +0900
changeset 563696 932e17cc61ba1a7344b1740ed14ece0484200e32
parent 563687 05c212a94183838f12feebb2c3fd483a6eec18c2
child 563697 c798db446d28c0621d38fb65a5345300ace8cca7
push id54385
push userVYV03354@nifty.ne.jp
push dateMon, 17 Apr 2017 15:24:13 +0000
reviewersjimm
bugs1356218
milestone55.0a1
Bug 1356218 - Make screen.colorDepth multi-monitor aware. r=jimm MozReview-Commit-ID: JrQL23DgZsw
widget/windows/ScreenHelperWin.cpp
--- a/widget/windows/ScreenHelperWin.cpp
+++ b/widget/windows/ScreenHelperWin.cpp
@@ -11,17 +11,17 @@
 #include "WinUtils.h"
 
 static LazyLogModule sScreenLog("WidgetScreen");
 
 namespace mozilla {
 namespace widget {
 
 BOOL CALLBACK
-CollectMonitors(HMONITOR aMon, HDC, LPRECT, LPARAM ioParam)
+CollectMonitors(HMONITOR aMon, HDC hDCScreen, LPRECT, LPARAM ioParam)
 {
   auto screens = reinterpret_cast<nsTArray<RefPtr<Screen>>*>(ioParam);
   BOOL success = FALSE;
   MONITORINFO info;
   info.cbSize = sizeof(MONITORINFO);
   success = ::GetMonitorInfoW(aMon, &info);
   if (!success) {
     MOZ_LOG(sScreenLog, LogLevel::Error, ("GetMonitorInfoW failed"));
@@ -36,21 +36,17 @@ CollectMonitors(HMONITOR aMon, HDC, LPRE
   }
   CSSToLayoutDeviceScale defaultCssScaleFactor(scale);
   LayoutDeviceIntRect rect(info.rcMonitor.left, info.rcMonitor.top,
                            info.rcMonitor.right - info.rcMonitor.left,
                            info.rcMonitor.bottom - info.rcMonitor.top);
   LayoutDeviceIntRect availRect(info.rcWork.left, info.rcWork.top,
                                 info.rcWork.right - info.rcWork.left,
                                 info.rcWork.bottom - info.rcWork.top);
-  //XXX not sure how to get this info for multiple monitors, this might be ok...
-  HDC hDCScreen = ::GetDC(nullptr);
-  NS_ASSERTION(hDCScreen,"GetDC Failure");
   uint32_t pixelDepth = ::GetDeviceCaps(hDCScreen, BITSPIXEL);
-  ::ReleaseDC(nullptr, hDCScreen);
   if (pixelDepth == 32) {
     // If a device uses 32 bits per pixel, it's still only using 8 bits
     // per color component, which is what our callers want to know.
     // (Some devices report 32 and some devices report 24.)
     pixelDepth = 24;
   }
   MOZ_LOG(sScreenLog, LogLevel::Debug, ("New screen [%d %d %d %d %d %f]",
                                         rect.x, rect.y, rect.width, rect.height,
@@ -68,19 +64,22 @@ CollectMonitors(HMONITOR aMon, HDC, LPRE
 }
 
 void
 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);
+  NS_ASSERTION(hdc,"CreateDC Failure");
+  BOOL result = ::EnumDisplayMonitors(hdc, nullptr,
                                       (MONITORENUMPROC)CollectMonitors,
                                       (LPARAM)&screens);
+  ::DeleteDC(hdc);
   if (!result) {
     NS_WARNING("Unable to EnumDisplayMonitors");
   }
   ScreenManager& screenManager = ScreenManager::GetSingleton();
   screenManager.Refresh(Move(screens));
 }
 
 } // namespace widget