home *** CD-ROM | disk | FTP | other *** search
/ Freelog 115 / FreelogNo115-MaiJuin2013.iso / Internet / AvantBrowser / asetup.exe / _data / webkit / chrome.dll / 0 / BINDATA / 541 < prev    next >
Encoding:
Text File  |  2013-04-03  |  17.0 KB  |  520 lines

  1. // Copyright (c) 2011 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4.  
  5. // Copyright (c) 2011 The Chromium Authors. All rights reserved.
  6. // Use of this source code is governed by a BSD-style license that can be
  7. // found in the LICENSE file.
  8. cr.define('gpu', function() {
  9.   /**
  10.    * This class provides a 'bridge' for communicating between javascript and the
  11.    * browser. When run outside of WebUI, e.g. as a regular webpage, it provides
  12.    * synthetic data to assist in testing.
  13.    * @constructor
  14.    */
  15.   function BrowserBridge() {
  16.     // If we are not running inside WebUI, output chrome.send messages
  17.     // to the console to help with quick-iteration debugging.
  18.     this.debugMode_ = (chrome.send === undefined && console.log);
  19.     if (this.debugMode_) {
  20.       var browserBridgeTests = document.createElement('script');
  21.       browserBridgeTests.src = './gpu_internals/browser_bridge_tests.js';
  22.       document.body.appendChild(browserBridgeTests);
  23.     }
  24.  
  25.     this.nextRequestId_ = 0;
  26.     this.pendingCallbacks_ = [];
  27.     this.logMessages_ = [];
  28.  
  29.     // Tell c++ code that we are ready to receive GPU Info.
  30.     if (!this.debugMode_) {
  31.       chrome.send('browserBridgeInitialized');
  32.       this.beginRequestClientInfo_();
  33.       this.beginRequestLogMessages_();
  34.       this.beginRequestCrashList_();
  35.     }
  36.   }
  37.  
  38.   BrowserBridge.prototype = {
  39.     __proto__: cr.EventTarget.prototype,
  40.  
  41.     applySimulatedData_: function applySimulatedData(data) {
  42.       // set up things according to the simulated data
  43.       this.gpuInfo_ = data.gpuInfo;
  44.       this.clientInfo_ = data.clientInfo;
  45.       this.logMessages_ = data.logMessages;
  46.       cr.dispatchSimpleEvent(this, 'gpuInfoUpdate');
  47.       cr.dispatchSimpleEvent(this, 'clientInfoChange');
  48.       cr.dispatchSimpleEvent(this, 'logMessagesChange');
  49.     },
  50.  
  51.     /**
  52.      * Returns true if the page is hosted inside Chrome WebUI
  53.      * Helps have behavior conditional to emulate_webui.py
  54.      */
  55.     get debugMode() {
  56.       return this.debugMode_;
  57.     },
  58.  
  59.     /**
  60.      * Sends a message to the browser with specified args. The
  61.      * browser will reply asynchronously via the provided callback.
  62.      */
  63.     callAsync: function(submessage, args, callback) {
  64.       var requestId = this.nextRequestId_;
  65.       this.nextRequestId_ += 1;
  66.       this.pendingCallbacks_[requestId] = callback;
  67.       if (!args) {
  68.         chrome.send('callAsync', [requestId.toString(), submessage]);
  69.       } else {
  70.         var allArgs = [requestId.toString(), submessage].concat(args);
  71.         chrome.send('callAsync', allArgs);
  72.       }
  73.     },
  74.  
  75.     /**
  76.      * Called by gpu c++ code when client info is ready.
  77.      */
  78.     onCallAsyncReply: function(requestId, args) {
  79.       if (this.pendingCallbacks_[requestId] === undefined) {
  80.         throw new Error('requestId ' + requestId + ' is not pending');
  81.       }
  82.       var callback = this.pendingCallbacks_[requestId];
  83.       callback(args);
  84.       delete this.pendingCallbacks_[requestId];
  85.     },
  86.  
  87.     /**
  88.      * Get gpuInfo data.
  89.      */
  90.     get gpuInfo() {
  91.       return this.gpuInfo_;
  92.     },
  93.  
  94.     /**
  95.      * Called from gpu c++ code when GPU Info is updated.
  96.      */
  97.     onGpuInfoUpdate: function(gpuInfo) {
  98.       this.gpuInfo_ = gpuInfo;
  99.       cr.dispatchSimpleEvent(this, 'gpuInfoUpdate');
  100.     },
  101.  
  102.     /**
  103.      * This function begins a request for the ClientInfo. If it comes back
  104.      * as undefined, then we will issue the request again in 250ms.
  105.      */
  106.     beginRequestClientInfo_: function() {
  107.       this.callAsync('requestClientInfo', undefined, (function(data) {
  108.         if (data === undefined) { // try again in 250 ms
  109.           window.setTimeout(this.beginRequestClientInfo_.bind(this), 250);
  110.         } else {
  111.           this.clientInfo_ = data;
  112.           cr.dispatchSimpleEvent(this, 'clientInfoChange');
  113.         }
  114.       }).bind(this));
  115.     },
  116.  
  117.     /**
  118.      * Returns information about the currently runnign Chrome build.
  119.      */
  120.     get clientInfo() {
  121.       return this.clientInfo_;
  122.     },
  123.  
  124.     /**
  125.      * This function checks for new GPU_LOG messages.
  126.      * If any are found, a refresh is triggered.
  127.      */
  128.     beginRequestLogMessages_: function() {
  129.       this.callAsync('requestLogMessages', undefined,
  130.           (function(messages) {
  131.             if (messages.length != this.logMessages_.length) {
  132.               this.logMessages_ = messages;
  133.               cr.dispatchSimpleEvent(this, 'logMessagesChange');
  134.             }
  135.             // check again in 250 ms
  136.             window.setTimeout(this.beginRequestLogMessages_.bind(this), 250);
  137.           }).bind(this));
  138.     },
  139.  
  140.     /**
  141.      * Returns an array of log messages issued by the GPU process, if any.
  142.      */
  143.     get logMessages() {
  144.       return this.logMessages_;
  145.     },
  146.  
  147.     /**
  148.      * This function checks for previous crash list.
  149.      * If it's not available yet, a refresh is triggered.
  150.      */
  151.     beginRequestCrashList_: function() {
  152.       this.callAsync('requestCrashList', undefined, (function(data) {
  153.         if (data === undefined) { // try again in 250 ms
  154.           window.setTimeout(this.beginRequestCrashList_.bind(this), 250);
  155.         } else {
  156.           this.crashList_ = data;
  157.           cr.dispatchSimpleEvent(this, 'crashListChange');
  158.         }
  159.       }).bind(this));
  160.     },
  161.  
  162.     /**
  163.      * Returns an array of log messages issued by the GPU process, if any.
  164.      */
  165.     get crashList() {
  166.       return this.crashList_;
  167.     }
  168.  
  169.   };
  170.  
  171.   return {
  172.     BrowserBridge: BrowserBridge
  173.   };
  174. });
  175.  
  176. // Copyright (c) 2012 The Chromium Authors. All rights reserved.
  177. // Use of this source code is governed by a BSD-style license that can be
  178. // found in the LICENSE file.
  179.  
  180.  
  181. /**
  182.  * @fileoverview This view displays information on the current GPU
  183.  * hardware.  Its primary usefulness is to allow users to copy-paste
  184.  * their data in an easy to read format for bug reports.
  185.  */
  186. cr.define('gpu', function() {
  187.   /**
  188.    * Provides information on the GPU process and underlying graphics hardware.
  189.    * @constructor
  190.    * @extends {cr.ui.TabPanel}
  191.    */
  192.   var InfoView = cr.ui.define(cr.ui.TabPanel);
  193.  
  194.   InfoView.prototype = {
  195.     __proto__: cr.ui.TabPanel.prototype,
  196.  
  197.     decorate: function() {
  198.       cr.ui.TabPanel.prototype.decorate.apply(this);
  199.  
  200.       browserBridge.addEventListener('gpuInfoUpdate', this.refresh.bind(this));
  201.       browserBridge.addEventListener('logMessagesChange',
  202.                                      this.refresh.bind(this));
  203.       browserBridge.addEventListener('clientInfoChange',
  204.                                      this.refresh.bind(this));
  205.       browserBridge.addEventListener('crashListChange',
  206.                                      this.refresh.bind(this));
  207.       this.refresh();
  208.     },
  209.  
  210.     /**
  211.     * Updates the view based on its currently known data
  212.     */
  213.     refresh: function(data) {
  214.       // Client info
  215.       if (browserBridge.clientInfo) {
  216.         var clientInfo = browserBridge.clientInfo;
  217.         var chromeVersion = clientInfo.version +
  218.             ' (' + clientInfo.official +
  219.             ' ' + clientInfo.cl +
  220.             ') ' + clientInfo.version_mod;
  221.         this.setTable_('client-info', [
  222.           {
  223.             description: 'Data exported',
  224.             value: (new Date()).toLocaleString()
  225.           },
  226.           {
  227.             description: 'Chrome version',
  228.             value: chromeVersion
  229.           },
  230.           {
  231.             description: 'Operating system',
  232.             value: clientInfo.operating_system
  233.           },
  234.           {
  235.             description: 'Software rendering list version',
  236.             value: clientInfo.blacklist_version
  237.           },
  238.           {
  239.             description: 'ANGLE revision',
  240.             value: clientInfo.angle_revision
  241.           },
  242.           {
  243.             description: '2D graphics backend',
  244.             value: clientInfo.graphics_backend
  245.           }]);
  246.       } else {
  247.         this.setText_('client-info', '... loading...');
  248.       }
  249.  
  250.       // Feature map
  251.       var featureLabelMap = {
  252.         '2d_canvas': 'Canvas',
  253.         '3d_css': '3D CSS',
  254.         'css_animation': 'CSS Animation',
  255.         'compositing': 'Compositing',
  256.         'webgl': 'WebGL',
  257.         'multisampling': 'WebGL multisampling',
  258.         'flash_3d': 'Flash 3D',
  259.         'flash_stage3d': 'Flash Stage3D',
  260.         'texture_sharing': 'Texture Sharing',
  261.         'video_decode': 'Video Decode',
  262.         'video': 'Video',
  263.         // GPU Switching
  264.         'gpu_switching': 'GPU Switching',
  265.         'panel_fitting': 'Panel Fitting',
  266.         'force_compositing_mode': 'Force Compositing Mode',
  267.       };
  268.       var statusLabelMap = {
  269.         'disabled_software': 'Software only. Hardware acceleration disabled.',
  270.         'disabled_software_animated': 'Software animated.',
  271.         'disabled_off': 'Unavailable. Hardware acceleration disabled.',
  272.         'software': 'Software rendered. Hardware acceleration not enabled.',
  273.         'unavailable_off': 'Unavailable. Hardware acceleration unavailable',
  274.         'unavailable_software':
  275.             'Software only, hardware acceleration unavailable',
  276.         'enabled_readback': 'Hardware accelerated, but at reduced performance',
  277.         'enabled_force': 'Hardware accelerated on all pages',
  278.         'enabled_threaded': 'Hardware accelerated on demand and threaded',
  279.         'enabled_force_threaded':
  280.             'Hardware accelerated on all pages and threaded',
  281.         'enabled': 'Hardware accelerated',
  282.         'accelerated': 'Accelerated',
  283.         'accelerated_threaded': 'Accelerated and threaded',
  284.         // GPU Switching
  285.         'gpu_switching_automatic': 'Automatic switching',
  286.         'gpu_switching_force_discrete': 'Always on discrete GPU',
  287.         'gpu_switching_force_integrated': 'Always on integrated GPU',
  288.       };
  289.  
  290.       var statusClassMap = {
  291.         'disabled_software': 'feature-yellow',
  292.         'disabled_software_animated': 'feature-yellow',
  293.         'disabled_off': 'feature-red',
  294.         'software': 'feature-yellow',
  295.         'unavailable_off': 'feature-red',
  296.         'unavailable_software': 'feature-yellow',
  297.         'enabled_force': 'feature-green',
  298.         'enabled_readback': 'feature-yellow',
  299.         'enabled_threaded': 'feature-green',
  300.         'enabled_force_threaded': 'feature-green',
  301.         'enabled': 'feature-green',
  302.         'accelerated': 'feature-green',
  303.         'accelerated_threaded': 'feature-green',
  304.         // GPU Switching
  305.         'gpu_switching_automatic': 'feature-green',
  306.         'gpu_switching_force_discrete': 'feature-red',
  307.         'gpu_switching_force_integrated': 'feature-red',
  308.       };
  309.  
  310.       // GPU info, basic
  311.       var diagnosticsDiv = this.querySelector('.diagnostics');
  312.       var diagnosticsLoadingDiv = this.querySelector('.diagnostics-loading');
  313.       var featureStatusList = this.querySelector('.feature-status-list');
  314.       var problemsDiv = this.querySelector('.problems-div');
  315.       var problemsList = this.querySelector('.problems-list');
  316.       var performanceDiv = this.querySelector('.performance-div');
  317.       var gpuInfo = browserBridge.gpuInfo;
  318.       var i;
  319.       if (gpuInfo) {
  320.         // Not using jstemplate here for blacklist status because we construct
  321.         // href from data, which jstemplate can't seem to do.
  322.         if (gpuInfo.featureStatus) {
  323.           // feature status list
  324.           featureStatusList.textContent = '';
  325.           for (i = 0; i < gpuInfo.featureStatus.featureStatus.length;
  326.                i++) {
  327.             var feature = gpuInfo.featureStatus.featureStatus[i];
  328.             var featureEl = document.createElement('li');
  329.  
  330.             var nameEl = document.createElement('span');
  331.             if (!featureLabelMap[feature.name])
  332.               console.log('Missing featureLabel for', feature.name);
  333.             nameEl.textContent = featureLabelMap[feature.name] + ': ';
  334.             featureEl.appendChild(nameEl);
  335.  
  336.             var statusEl = document.createElement('span');
  337.             if (!statusLabelMap[feature.status])
  338.               console.log('Missing statusLabel for', feature.status);
  339.             if (!statusClassMap[feature.status])
  340.               console.log('Missing statusClass for', feature.status);
  341.             statusEl.textContent = statusLabelMap[feature.status];
  342.             statusEl.className = statusClassMap[feature.status];
  343.             featureEl.appendChild(statusEl);
  344.  
  345.             featureStatusList.appendChild(featureEl);
  346.           }
  347.  
  348.           // problems list
  349.           if (gpuInfo.featureStatus.problems.length) {
  350.             problemsDiv.hidden = false;
  351.             problemsList.textContent = '';
  352.             for (i = 0; i < gpuInfo.featureStatus.problems.length; i++) {
  353.               var problem = gpuInfo.featureStatus.problems[i];
  354.               var problemEl = this.createProblemEl_(problem);
  355.               problemsList.appendChild(problemEl);
  356.             }
  357.           } else {
  358.             problemsDiv.hidden = true;
  359.           }
  360.  
  361.         } else {
  362.           featureStatusList.textContent = '';
  363.           problemsList.hidden = true;
  364.         }
  365.         if (gpuInfo.basic_info)
  366.           this.setTable_('basic-info', gpuInfo.basic_info);
  367.         else
  368.           this.setTable_('basic-info', []);
  369.  
  370.         if (gpuInfo.performance_info) {
  371.           performanceDiv.hidden = false;
  372.           this.setTable_('performance-info', gpuInfo.performance_info);
  373.         } else {
  374.           performanceDiv.hidden = true;
  375.         }
  376.  
  377.         if (gpuInfo.diagnostics) {
  378.           diagnosticsDiv.hidden = false;
  379.           diagnosticsLoadingDiv.hidden = true;
  380.           $('diagnostics-table').hidden = false;
  381.           this.setTable_('diagnostics-table', gpuInfo.diagnostics);
  382.         } else if (gpuInfo.diagnostics === null) {
  383.           // gpu_internals.cc sets diagnostics to null when it is being loaded
  384.           diagnosticsDiv.hidden = false;
  385.           diagnosticsLoadingDiv.hidden = false;
  386.           $('diagnostics-table').hidden = true;
  387.         } else {
  388.           diagnosticsDiv.hidden = true;
  389.         }
  390.       } else {
  391.         this.setText_('basic-info', '... loading ...');
  392.         diagnosticsDiv.hidden = true;
  393.         featureStatusList.textContent = '';
  394.         problemsDiv.hidden = true;
  395.       }
  396.  
  397.       // Crash list
  398.       jstProcess(new JsEvalContext({values: browserBridge.crashList}),
  399.                  $('crash-list'));
  400.  
  401.       // Log messages
  402.       jstProcess(new JsEvalContext({values: browserBridge.logMessages}),
  403.                  $('log-messages'));
  404.     },
  405.  
  406.     createProblemEl_: function(problem) {
  407.       var problemEl;
  408.       problemEl = document.createElement('li');
  409.  
  410.       // Description of issue
  411.       var desc = document.createElement('a');
  412.       desc.textContent = problem.description;
  413.       problemEl.appendChild(desc);
  414.  
  415.       // Spacing ':' element
  416.       if (problem.crBugs.length + problem.webkitBugs.length > 0) {
  417.         var tmp = document.createElement('span');
  418.         tmp.textContent = ': ';
  419.         problemEl.appendChild(tmp);
  420.       }
  421.  
  422.       var nbugs = 0;
  423.       var j;
  424.  
  425.       // crBugs
  426.       for (j = 0; j < problem.crBugs.length; ++j) {
  427.         if (nbugs > 0) {
  428.           var tmp = document.createElement('span');
  429.           tmp.textContent = ', ';
  430.           problemEl.appendChild(tmp);
  431.         }
  432.  
  433.         var link = document.createElement('a');
  434.         var bugid = parseInt(problem.crBugs[j]);
  435.         link.textContent = bugid;
  436.         link.href = 'http://crbug.com/' + bugid;
  437.         problemEl.appendChild(link);
  438.         nbugs++;
  439.       }
  440.  
  441.       for (j = 0; j < problem.webkitBugs.length; ++j) {
  442.         if (nbugs > 0) {
  443.           var tmp = document.createElement('span');
  444.           tmp.textContent = ', ';
  445.           problemEl.appendChild(tmp);
  446.         }
  447.  
  448.         var link = document.createElement('a');
  449.         var bugid = parseInt(problem.webkitBugs[j]);
  450.         link.textContent = bugid;
  451.  
  452.         link.href = 'https://bugs.webkit.org/show_bug.cgi?id=' + bugid;
  453.         problemEl.appendChild(link);
  454.         nbugs++;
  455.       }
  456.  
  457.       return problemEl;
  458.     },
  459.  
  460.     setText_: function(outputElementId, text) {
  461.       var peg = document.getElementById(outputElementId);
  462.       peg.textContent = text;
  463.     },
  464.  
  465.     setTable_: function(outputElementId, inputData) {
  466.       var template = jstGetTemplate('info-view-table-template');
  467.       jstProcess(new JsEvalContext({value: inputData}),
  468.                  template);
  469.  
  470.       var peg = document.getElementById(outputElementId);
  471.       if (!peg)
  472.         throw new Error('Node ' + outputElementId + ' not found');
  473.  
  474.       peg.innerHTML = '';
  475.       peg.appendChild(template);
  476.     }
  477.   };
  478.  
  479.   return {
  480.     InfoView: InfoView
  481.   };
  482. });
  483.  
  484.  
  485. var browserBridge;
  486.  
  487. /**
  488.  * Main entry point. called once the page has loaded.
  489.  */
  490. function onLoad() {
  491.   browserBridge = new gpu.BrowserBridge();
  492.  
  493.   // Create the views.
  494.   cr.ui.decorate('#info-view', gpu.InfoView);
  495.  
  496.   // Create the main tab control
  497.   var tabs = $('main-tabs');
  498.   cr.ui.decorate(tabs, cr.ui.TabBox);
  499.  
  500.   // Sync the main-tabs selectedTabs in-sync with the location.
  501.   tabs.addEventListener('selectedChange', function() {
  502.     if (tabs.selectedTab.id) {
  503.       history.pushState('', '', '#' + tabs.selectedTab.id);
  504.     }
  505.   });
  506.   window.onhashchange = function() {
  507.     var cur = window.location.hash;
  508.     if (cur == '#' || cur == '') {
  509.       tabs.selectedTab = $('info-view');
  510.     } else {
  511.       var tab = $(window.location.hash.substr(1));
  512.       if (tab)
  513.         tabs.selectedTab = tab;
  514.     }
  515.   };
  516.   window.onhashchange();
  517. }
  518.  
  519. document.addEventListener('DOMContentLoaded', onLoad);
  520.