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
5import time
6
7from measurements import smoothness
8from telemetry.page import page_test
9from telemetry.value import scalar
10
11
12class RecordPerArea(page_test.PageTest):
13  def __init__(self):
14    super(RecordPerArea, self).__init__('', True)
15
16  def AddCommandLineArgs(self, parser):
17    parser.add_option('--start-wait-time', type='float',
18                      default=2,
19                      help='Wait time before the benchmark is started '
20                      '(must be long enought to load all content)')
21
22  def CustomizeBrowserOptions(self, options):
23    smoothness.Smoothness.CustomizeBrowserOptions(options)
24    options.AppendExtraBrowserArgs([
25        '--enable-impl-side-painting',
26        '--enable-threaded-compositing',
27        '--enable-gpu-benchmarking'
28    ])
29
30  def ValidateAndMeasurePage(self, page, tab, results):
31    # Wait until the page has loaded and come to a somewhat steady state.
32    # Needs to be adjusted for every device (~2 seconds for workstation).
33    time.sleep(self.options.start_wait_time)
34
35    # Enqueue benchmark
36    tab.ExecuteJavaScript("""
37        window.benchmark_results = {};
38        window.benchmark_results.done = false;
39        chrome.gpuBenchmarking.runMicroBenchmark(
40            "picture_record_benchmark",
41            function(value) {
42              window.benchmark_results.done = true;
43              window.benchmark_results.results = value;
44            }, [{width: 1, height: 1},
45                {width: 250, height: 250},
46                {width: 500, height: 500},
47                {width: 750, height: 750},
48                {width: 1000, height: 1000},
49                {width: 256, height: 1024},
50                {width: 1024, height: 256}]);
51    """)
52
53    tab.WaitForJavaScriptExpression('window.benchmark_results.done', 300)
54
55    all_data = tab.EvaluateJavaScript('window.benchmark_results.results')
56    for data in all_data:
57      width = data['width']
58      height = data['height']
59      area = width * height
60      time_ms = data['time_ms']
61
62      results.AddValue(scalar.ScalarValue(
63          results.current_page, 'area_%07d_%dx%d' % (area, width, height),
64          'ms', time_ms))
65