Bug 1178447 - Make gfx sanity test run offscreen. r=dvander, a=kglazko
authorMason Chang <mchang@mozilla.com>
Thu, 02 Jul 2015 12:47:10 -0700
changeset 281448 807f336af403aae079c363cea69d0948ff18d2a2
parent 281447 09219bc6153f5ad217f040d35678198e5b37d8eb
child 281449 4d044caf0289a2324ac611836a259f921a4ca412
push id4932
push userjlund@mozilla.com
push dateMon, 10 Aug 2015 18:23:06 +0000
treeherdermozilla-beta@6dd5a4f5f745 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdvander, kglazko
bugs1178447
milestone41.0a2
Bug 1178447 - Make gfx sanity test run offscreen. r=dvander, a=kglazko
toolkit/components/gfx/SanityTest.js
--- a/toolkit/components/gfx/SanityTest.js
+++ b/toolkit/components/gfx/SanityTest.js
@@ -63,40 +63,16 @@ function reportSnapshotResult(val) {
 function takeWindowSnapshot(win, ctx) {
   // TODO: drawWindow reads back from the gpu's backbuffer, which won't catch issues with presenting
   // the front buffer via the window manager. Ideally we'd use an OS level API for reading back
   // from the desktop itself to get a more accurate test.
   var flags = ctx.DRAWWINDOW_DRAW_CARET | ctx.DRAWWINDOW_DRAW_VIEW | ctx.DRAWWINDOW_USE_WIDGET_LAYERS;
   ctx.drawWindow(win.ownerGlobal, 0, 0, PAGE_WIDTH, PAGE_HEIGHT, "rgb(255,255,255)", flags);
 }
 
-function takeWidgetSnapshot(win, canvas, ctx) {
-  ctx.clearRect(0, 0, canvas.width, canvas.height);
-  ctx.drawWidgetAsOnScreen(win.ownerGlobal);
-}
-
-function testWidgetSnapshot(win, canvas, ctx) {
-  try {
-    takeWidgetSnapshot(win, canvas, ctx);
-    if (verifyVideoRendering(ctx)) {
-      reportSnapshotResult(SNAPSHOT_VIDEO_OK);
-    } else {
-      reportSnapshotResult(SNAPSHOT_VIDEO_FAIL);
-    }
-
-    if (verifyLayersRendering(ctx)) {
-      reportSnapshotResult(SNAPSHOT_LAYERS_OK);
-    } else {
-      reportSnapshotResult(SNAPSHOT_LAYERS_FAIL);
-    }
-  } catch (e) {
-    reportSnapshotResult(SNAPSHOT_ERROR);
-  }
-}
-
 function setTimeout(aMs, aCallback) {
   var timer = Components.classes["@mozilla.org/timer;1"]
               .createInstance(Components.interfaces.nsITimer);
   timer.initWithCallback(aCallback, aMs, Ci.nsITimer.TYPE_ONE_SHOT);
 }
 
 // Verify that all the 4 coloured squares of the video
 // render as expected (with a tolerance of 64 to allow for
@@ -144,25 +120,16 @@ function testCompositor(win, ctx) {
 
 let listener = {
   QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver]),
 
   win: null,
   utils: null,
   canvas: null,
 
-  // State flow:
-  //   onload -> WM_PAINT -> MozAfterPaint -> ready
-  //   WM_PAINT -> onload -> MozAfterPaint -> ready
-  //
-  // We always wait for the low-level paint message because this is what tells
-  // us whether or not the OS has actually started drawing.
-  windowLoaded: false,   // onload event has fired.
-  windowReady: false,    // widget has received an OS-level paint request.
-
   scheduleTest: function(win) {
     this.win = win;
     this.win.onload = this.onWindowLoaded.bind(this);
     this.utils = this.win.QueryInterface(Ci.nsIInterfaceRequestor)
                          .getInterface(Ci.nsIDOMWindowUtils);
 
     let observerService = Cc["@mozilla.org/observer-service;1"].
                           getService(Components.interfaces.nsIObserverService);
@@ -172,74 +139,17 @@ let listener = {
   onWindowLoaded: function() {
     this.canvas = this.win.document.createElementNS("http://www.w3.org/1999/xhtml", "canvas");
     this.canvas.setAttribute("width", PAGE_WIDTH);
     this.canvas.setAttribute("height", PAGE_HEIGHT);
     this.ctx = this.canvas.getContext("2d");
 
     // Perform the compositor backbuffer test, which currently we use for
     // actually deciding whether to enable hardware media decoding.
-    if (!testCompositor(this.win, this.ctx)) {
-      this.endTest();
-      return;
-    }
-
-    // Wait to perform the OS snapshot test. Since this waits for a series of
-    // events to occur, we set a timeout in case nothing happens.
-    setTimeout(OS_SNAPSHOT_TIMEOUT_SEC * 1000, (() => {
-      if (this.win) {
-        reportSnapshotResult(SNAPSHOT_TIMEOUT);
-        this.endTest();
-      }
-    }));
-
-    this.windowLoaded = true;
-    if (this.windowReady) {
-      this.waitForPaintsFlushed();
-    }
-  },
-
-  // Watch for the first OS-level paint message to the window.
-  observe: function(aSubject, aTopic, aData) {
-    if (aSubject != this.win || aTopic != "widget-first-paint") {
-      return;
-    }
-
-    this.windowReady = true;
-    if (this.windowLoaded) {
-      this.waitForPaintsFlushed();
-    }
-  },
-
-  // Wait for all layout-induced paints to flush.
-  waitForPaintsFlushed: function() {
-    // If the test ended prematurely due to a timeout, just ignore the event.
-    if (!this.win) {
-      return;
-    }
-
-    if (this.utils.isMozAfterPaintPending) {
-      let paintListener = (() => {
-        if (this.utils && this.utils.isMozAfterPaintPending) {
-          return;
-        }
-
-        this.win.removeEventListener("MozAfterPaint", paintListener);
-
-        if (this.utils) {
-          // Painting is finished, we will fail the above
-          // isMozAfterPaintPending test now.
-          this.waitForPaintsFlushed();
-        }
-      });
-      this.win.addEventListener("MozAfterPaint", paintListener);
-      return;
-    }
-
-    testWidgetSnapshot(this.win, this.canvas, this.ctx);
+    testCompositor(this.win, this.ctx);
     this.endTest();
   },
 
   endTest: function() {
     if (!this.win) {
       return;
     }
 
@@ -298,13 +208,17 @@ SanityTest.prototype = {
     if (!this.shouldRunTest()) return;
 
     // Open a tiny window to render our test page, and notify us when it's loaded
     var sanityTest = Services.ww.openWindow(null,
         "chrome://gfxsanity/content/sanitytest.html",
         "Test Page",
         "width=" + PAGE_WIDTH + ",height=" + PAGE_HEIGHT + ",chrome,titlebar=0,scrollbars=0",
         null);
+
+    // There's no clean way to have an invisible window and ensure it's always painted.
+    // Instead, move the window far offscreen so it doesn't show up during launch.
+    sanityTest.moveTo(100000000,1000000000);
     listener.scheduleTest(sanityTest);
   },
 };
 
 this.NSGetFactory = XPCOMUtils.generateNSGetFactory([SanityTest]);