Add nsIGfxInfo::GetMonitor support for Linux. (bug 1175005 part 4, r=nical)
authorDavid Anderson <danderson@mozilla.com>
Wed, 17 Jun 2015 23:12:13 -0700
changeset 267608 f081c464c1e2fe7d3f8aa4c23a6efdfe9156db68
parent 267607 44b74f0b7e1df5c001bd6ccbf4d6081da9b16968
child 267609 d9c8c1d140371a48de0c7e0a9bb724ba517301c7
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)
reviewersnical
bugs1175005
milestone41.0a1
Add nsIGfxInfo::GetMonitor support for Linux. (bug 1175005 part 4, r=nical)
widget/GfxInfoX11.cpp
widget/GfxInfoX11.h
--- a/widget/GfxInfoX11.cpp
+++ b/widget/GfxInfoX11.cpp
@@ -9,16 +9,17 @@
 #include <sys/types.h>
 #include <sys/wait.h>
 #include <errno.h>
 #include <sys/utsname.h>
 #include "nsCRTGlue.h"
 #include "prenv.h"
 
 #include "GfxInfoX11.h"
+#include "mozilla/X11Util.h"
 
 #ifdef MOZ_CRASHREPORTER
 #include "nsExceptionHandler.h"
 #include "nsICrashReporter.h"
 #endif
 
 namespace mozilla {
 namespace widget {
@@ -529,16 +530,44 @@ GfxInfo::GetAdapterSubsysID2(nsAString &
 
 /* readonly attribute boolean isGPU2Active; */
 NS_IMETHODIMP
 GfxInfo::GetIsGPU2Active(bool* aIsGPU2Active)
 {
   return NS_ERROR_FAILURE;
 }
 
+nsresult
+GfxInfo::FindMonitors(JSContext* aCx, JS::HandleObject aOutArray)
+{
+#if defined(MOZ_WIDGET_GTK)
+  // No display in xpcshell mode.
+  if (!gdk_display_get_default()) {
+    return NS_OK;
+  }
+#endif
+
+  // Note: this doesn't support Xinerama. Two physical displays will be
+  // reported as one monitor covering the entire virtual screen.
+  Display* display = DefaultXDisplay();
+  Screen* screen = DefaultScreenOfDisplay(display);
+
+  JS::Rooted<JSObject*> obj(aCx, JS_NewPlainObject(aCx));
+
+  JS::Rooted<JS::Value> screenWidth(aCx, JS::Int32Value(WidthOfScreen(screen)));
+  JS_SetProperty(aCx, obj, "screenWidth", screenWidth);
+
+  JS::Rooted<JS::Value> screenHeight(aCx, JS::Int32Value(HeightOfScreen(screen)));
+  JS_SetProperty(aCx, obj, "screenHeight", screenHeight);
+
+  JS::Rooted<JS::Value> element(aCx, JS::ObjectValue(*obj));
+  JS_SetElement(aCx, aOutArray, 0, element);
+  return NS_OK;
+}
+
 #ifdef DEBUG
 
 // Implement nsIGfxInfoDebug
 // We don't support spoofing anything on Linux
 
 /* void spoofVendorID (in DOMString aVendorID); */
 NS_IMETHODIMP GfxInfo::SpoofVendorID(const nsAString & aVendorID)
 {
--- a/widget/GfxInfoX11.h
+++ b/widget/GfxInfoX11.h
@@ -43,16 +43,18 @@ public:
   using GfxInfoBase::GetFeatureStatus;
   using GfxInfoBase::GetFeatureSuggestedDriverVersion;
   using GfxInfoBase::GetWebGLParameter;
 
   virtual nsresult Init() override;
   
   NS_IMETHOD_(void) GetData() override;
 
+  nsresult FindMonitors(JSContext* cx, JS::HandleObject array) override;
+
 #ifdef DEBUG
   NS_DECL_ISUPPORTS_INHERITED
   NS_DECL_NSIGFXINFODEBUG
 #endif
 
 protected:
   ~GfxInfo() {}