Add nsIGfxInfo::ListMonitors support for OS X. (bug 1175005 part 3, r=mstange)
authorDavid Anderson <danderson@mozilla.com>
Wed, 17 Jun 2015 23:12:06 -0700
changeset 267607 44b74f0b7e1df5c001bd6ccbf4d6081da9b16968
parent 267606 59a89d5db8f0d80b0703a69345ebffe947326bac
child 267608 f081c464c1e2fe7d3f8aa4c23a6efdfe9156db68
push id4932
push userjlund@mozilla.com
push dateMon, 10 Aug 2015 18:23:06 +0000
treeherdermozilla-esr52@6dd5a4f5f745 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmstange
bugs1175005
milestone41.0a1
Add nsIGfxInfo::ListMonitors support for OS X. (bug 1175005 part 3, r=mstange)
widget/cocoa/GfxInfo.h
widget/cocoa/GfxInfo.mm
--- a/widget/cocoa/GfxInfo.h
+++ b/widget/cocoa/GfxInfo.h
@@ -54,16 +54,18 @@ public:
   NS_DECL_ISUPPORTS_INHERITED
 #ifdef DEBUG
   NS_DECL_NSIGFXINFODEBUG
 #endif
   NS_DECL_NSIGFXINFO2
 
   virtual uint32_t OperatingSystemVersion() override { return mOSXVersion; }
 
+  nsresult FindMonitors(JSContext* cx, JS::HandleObject array) override;
+
 protected:
 
   virtual ~GfxInfo() {}
 
   virtual nsresult GetFeatureStatusImpl(int32_t aFeature, 
                                         int32_t *aStatus, 
                                         nsAString & aSuggestedDriverVersion, 
                                         const nsTArray<GfxDriverInfo>& aDriverInfo,
--- a/widget/cocoa/GfxInfo.mm
+++ b/widget/cocoa/GfxInfo.mm
@@ -374,16 +374,43 @@ GfxInfo::GetFeatureStatusImpl(int32_t aF
         return NS_OK;
       }
     }
   }
 
   return GfxInfoBase::GetFeatureStatusImpl(aFeature, aStatus, aSuggestedDriverVersion, aDriverInfo, &os);
 }
 
+nsresult
+GfxInfo::FindMonitors(JSContext* aCx, JS::HandleObject aOutArray)
+{
+  // Getting the refresh rate is a little hard on OS X. We could use
+  // CVDisplayLinkGetNominalOutputVideoRefreshPeriod, but that's a little
+  // involved. Ideally we could query it from vsync. For now, we leave it out.
+  int32_t deviceCount = 0;
+  for (NSScreen* screen in [NSScreen screens]) {
+    NSRect rect = [screen frame];
+
+    JS::Rooted<JSObject*> obj(aCx, JS_NewPlainObject(aCx));
+
+    JS::Rooted<JS::Value> screenWidth(aCx, JS::Int32Value((int)rect.size.width));
+    JS_SetProperty(aCx, obj, "screenWidth", screenWidth);
+
+    JS::Rooted<JS::Value> screenHeight(aCx, JS::Int32Value((int)rect.size.height));
+    JS_SetProperty(aCx, obj, "screenHeight", screenHeight);
+
+    JS::Rooted<JS::Value> scale(aCx, JS::NumberValue(nsCocoaUtils::GetBackingScaleFactor(screen)));
+    JS_SetProperty(aCx, obj, "scale", scale);
+
+    JS::Rooted<JS::Value> element(aCx, JS::ObjectValue(*obj));
+    JS_SetElement(aCx, aOutArray, deviceCount++, element);
+  }
+  return NS_OK;
+}
+
 #ifdef DEBUG
 
 // Implement nsIGfxInfoDebug
 
 /* void spoofVendorID (in DOMString aVendorID); */
 NS_IMETHODIMP GfxInfo::SpoofVendorID(const nsAString & aVendorID)
 {
   mAdapterVendorID = aVendorID;