1# Copyright 2013 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"""Scirra WebGL and Canvas2D rendering benchmark suite. 6 7The Scirra WebGL performance test measures the number of 2D triangles 8represented onscreen when the animation reaches the 30 FPS threshold. 9""" 10 11import os 12 13from telemetry import test 14from telemetry.page import page_measurement 15from telemetry.page import page_set 16 17 18class ScirraMeasurement(page_measurement.PageMeasurement): 19 20 def WillNavigateToPage(self, page, tab): 21 page.script_to_evaluate_on_commit = 'window.sprites = 0;' 22 23 def MeasurePage(self, _, tab, results): 24 object_count = '$objectcount$' 25 fps = '$fps$' 26 tickcount = '$tickcount$' 27 # For http://www.scirra.com/labs/renderperf3/, JavaScript generated by 28 # Construct 2 has different variables for Objects, fps and tickcount. 29 if 'renderperf3' in tab.url: 30 object_count = '$d' 31 fps = 'Rb' 32 tickcount = 'Ff' 33 34 # Updates object count variable, when the FPS reaches 30 threshold and 35 # tickcounts to reach value greater than 500(just to stablize frames). 36 js_is_done = """ 37 var IsTestDone = function() { 38 if (window.cr_getC2Runtime().%(tickcount)s > 500 && 39 window.cr_getC2Runtime().%(fps)s == 30) { 40 window.sprites = window.cr_getC2Runtime().%(object_count)s; 41 return true; 42 } else { 43 return false; 44 } 45 }; 46 IsTestDone(); 47 """ % {'tickcount': tickcount, 'fps': fps, 'object_count': object_count} 48 tab.WaitForJavaScriptExpression(js_is_done, 300) 49 total = int(tab.EvaluateJavaScript('window.sprites')) 50 results.Add('Count', 'count', total) 51 52 53class ScirraBenchmark(test.Test): 54 """WebGL and Canvas2D rendering benchmark suite.""" 55 test = ScirraMeasurement 56 def CreatePageSet(self, options): 57 return page_set.PageSet.FromDict({ 58 'archive_data_file': '../page_sets/data/scirra.json', 59 'make_javascript_deterministic': False, 60 'pages': [ 61 { 'url': 'http://www.scirra.com/labs/renderperf3/'}, 62 { 'url': 'http://www.scirra.com/demos/c2/renderperfgl/'}, 63 { 'url': 'http://www.scirra.com/demos/c2/renderperf2d/'} 64 ] 65 }, os.path.abspath(__file__)) 66 67