summaryrefslogtreecommitdiffstats
path: root/gfx/tests/mochitest/test_acceleration.html
blob: 06a942e8cb294477bb54b91a4281c76c3d2a6a8d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=627498
-->
<head>
  <title>Test hardware acceleration</title>
  <script src="/tests/SimpleTest/SimpleTest.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=627498">Mozilla Bug 627498</a>
<p id="display"></p>
<div id="content" style="display: none">

</div>
<pre id="test">
<script type="application/javascript">

// Make sure that acceleration is enabled/disabled the way we expect it to be
// based on platform.

SimpleTest.waitForExplicitFinish();

addEventListener("pageshow", runTest, false);

function runTest() {
  var Cc = SpecialPowers.Cc;
  var Ci = SpecialPowers.Ci;

  var sysInfo = SpecialPowers.Services.sysinfo;
  var xr = SpecialPowers.Services.appinfo;

  var windows = SpecialPowers.Services.ww.getWindowEnumerator();
  var windowutils;
  var acceleratedWindows = 0;
  var webrenderWindows = 0;
  var layerManagerLog = [];
  while (windows.hasMoreElements()) {
    try {
      windowutils = windows.getNext().windowUtils;
    } catch (e) {
      todo(false, "Bug X - don't expose BFCached pages through window enumerator");
    }
    try {
      var layerManager = windowutils.layerManagerType;
      if (layerManager != "Basic" && layerManager != "WebRender (Software)") {
        acceleratedWindows++;
      }
      if (layerManager.startsWith("WebRender")) {
        webrenderWindows++;
      }
      layerManagerLog.push(layerManager);
    } catch (e) {
      // The window may not have a layer manager, in which case we get an error.
      // Don't count it as an accelerated window.
      dump("Didn't get a layer manager! " + e);
    }
  }

  var osName = sysInfo.getProperty("name");
  switch (osName) {
    case "Darwin": // Mac OS X.
      // We only enable OpenGL layers on machines that don't support QuickDraw
      // plugins. x86-64 architecture is a good proxy for this plugin support.
      if (sysInfo.getProperty("arch") != "x86-64") {
        is(acceleratedWindows, 0, "Acceleration not supported on x86 OS X");
      } else {
        // Workaround for SeaMonkey tinderboxes which don't support acceleration.
        if (navigator.userAgent.match(/ SeaMonkey\//)) {
          if (acceleratedWindows == 0) {
            todo(false, "Acceleration not supported on x86-64 OS X" +
                        " (This is expected on SeaMonkey (tinderboxes).)");
            break;
          }
        }

        isnot(acceleratedWindows, 0, "Acceleration enabled on x86-64 OS X");
      }
      break;

    case "Windows_NT": // Windows.
      var version = parseFloat(sysInfo.getProperty("version"));
      if (version == 5.0) {
        is(acceleratedWindows, 0, "Acceleration not supported on Windows 2000");
      } else {
        // Workaround for SeaMonkey tinderboxes which don't support acceleration.
        if (navigator.userAgent.match(/ SeaMonkey\//)) {
          if (acceleratedWindows == 0) {
            todo(false, "Acceleration not supported on Windows XP or newer" +
                        " (This is expected on SeaMonkey (tinderboxes).)");
            break;
          }
        }

        isnot(acceleratedWindows, 0, "Acceleration enabled on Windows XP or newer");
      }

      var gfxInfo = Cc["@mozilla.org/gfx/info;1"].getService(Ci.nsIGfxInfo);
      if (version < 6.2) {
        ok(!gfxInfo.D2DEnabled, "Direct2D not supported on Windows 2008 or older");
        if (version < 6.1) {
          ok(!gfxInfo.DWriteEnabled, "DirectWrite not supported on Windows 2008 or older");
        } else {
          ok(gfxInfo.DWriteEnabled, "DirectWrite enabled on Windows 7 or newer");
        }
      } else {
        ok(gfxInfo.D2DEnabled, "Direct2D enabled on Windows 8 or newer");
        ok(gfxInfo.DWriteEnabled, "DirectWrite enabled on Windows 7 or newer");
      }

      var shouldGetWR = false;
      try {
        shouldGetWR = SpecialPowers.DOMWindowUtils.isWebRenderRequested;
      } catch (e) {}

      if (shouldGetWR) {
        isnot(webrenderWindows, 0, "WebRender enabled on Windows");
      } else {
        is(webrenderWindows, 0, "WebRender disabled on Windows");
      }
      break;

    case "Linux":
      todo(false, "Acceleration supported on Linux, but only on taskcluster instances (bug 1296086)");
      break;

    default:
      if (xr.OS == "Android") {
        isnot(acceleratedWindows, 0, "Acceleration enabled on Android");
      } else {
        is(acceleratedWindows, 0, "Acceleration not supported on '" + osName + "'");
      }
  }

  SimpleTest.finish();
}

</script>
</pre>
</body>
</html>