Home | History | Annotate | Download | only in measurements
      1 # Copyright 2014 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 from measurements import smoothness_controller
      6 from telemetry.page import page_test
      7 
      8 
      9 class Repaint(page_test.PageTest):
     10   def __init__(self):
     11     super(Repaint, self).__init__('RunRepaint', False)
     12     self._smoothness_controller = None
     13     self._micro_benchmark_id = None
     14 
     15   @classmethod
     16   def AddCommandLineArgs(cls, parser):
     17     parser.add_option('--mode', type='string',
     18                       default='viewport',
     19                       help='Invalidation mode. '
     20                       'Supported values: fixed_size, layer, random, viewport.')
     21     parser.add_option('--width', type='int',
     22                       default=None,
     23                       help='Width of invalidations for fixed_size mode.')
     24     parser.add_option('--height', type='int',
     25                       default=None,
     26                       help='Height of invalidations for fixed_size mode.')
     27 
     28   def CustomizeBrowserOptions(self, options):
     29     options.AppendExtraBrowserArgs([
     30         '--enable-impl-side-painting',
     31         '--enable-threaded-compositing',
     32         '--enable-gpu-benchmarking'
     33     ])
     34 
     35   def WillRunActions(self, page, tab):
     36     tab.WaitForDocumentReadyStateToBeComplete()
     37     self._smoothness_controller = smoothness_controller.SmoothnessController()
     38     self._smoothness_controller.SetUp(page, tab)
     39     self._smoothness_controller.Start(tab)
     40     # Rasterize only what's visible.
     41     tab.ExecuteJavaScript(
     42         'chrome.gpuBenchmarking.setRasterizeOnlyVisibleContent();')
     43 
     44     args = {}
     45     args['mode'] = self.options.mode
     46     if self.options.width:
     47       args['width'] = self.options.width
     48     if self.options.height:
     49       args['height'] = self.options.height
     50 
     51     # Enque benchmark
     52     tab.ExecuteJavaScript("""
     53         window.benchmark_results = {};
     54         window.benchmark_results.id =
     55             chrome.gpuBenchmarking.runMicroBenchmark(
     56                 "invalidation_benchmark",
     57                 function(value) {},
     58                 """ + str(args) + """
     59             );
     60     """)
     61 
     62     self._micro_benchmark_id = tab.EvaluateJavaScript(
     63         'window.benchmark_results.id')
     64     if (not self._micro_benchmark_id):
     65       raise page_test.MeasurementFailure(
     66           'Failed to schedule invalidation_benchmark.')
     67 
     68   def DidRunActions(self, page, tab):
     69     tab.ExecuteJavaScript("""
     70         window.benchmark_results.message_handled =
     71             chrome.gpuBenchmarking.sendMessageToMicroBenchmark(
     72                 """ + str(self._micro_benchmark_id) + """, {
     73                   "notify_done": true
     74                 });
     75     """)
     76     self._smoothness_controller.Stop(tab)
     77 
     78   def ValidateAndMeasurePage(self, page, tab, results):
     79     self._smoothness_controller.AddResults(tab, results)
     80 
     81   def CleanUpAfterPage(self, _, tab):
     82     self._smoothness_controller.CleanUp(tab)
     83