Avi Drissman | dfd88085 | 2022-09-15 20:11:09 | [diff] [blame] | 1 | # Copyright 2012 The Chromium Authors |
[email protected] | fb2b85d | 2012-09-12 18:45:56 | [diff] [blame] | 2 | # Use of this source code is governed by a BSD-style license that can be |
| 3 | # found in the LICENSE file. |
[email protected] | 0c4d8e5a | 2014-02-17 13:04:36 | [diff] [blame] | 4 | import glob |
[email protected] | fb2b85d | 2012-09-12 18:45:56 | [diff] [blame] | 5 | import os |
[email protected] | fb2b85d | 2012-09-12 18:45:56 | [diff] [blame] | 6 | |
nednguyen | e9321b1 | 2016-04-27 20:47:10 | [diff] [blame] | 7 | from telemetry.page import legacy_page_test |
[email protected] | fb2b85d | 2012-09-12 18:45:56 | [diff] [blame] | 8 | |
[email protected] | 0b209be8 | 2013-07-17 21:33:34 | [diff] [blame] | 9 | |
nednguyen | e9321b1 | 2016-04-27 20:47:10 | [diff] [blame] | 10 | class SkpicturePrinter(legacy_page_test.LegacyPageTest): |
qyearsley | 2e10aec7 | 2016-02-03 17:53:42 | [diff] [blame] | 11 | |
ernstm | 7c0eae7 | 2014-11-19 21:01:40 | [diff] [blame] | 12 | def __init__(self, skp_outdir): |
nednguyen | ff753ad6 | 2015-03-13 18:18:13 | [diff] [blame] | 13 | super(SkpicturePrinter, self).__init__() |
ernstm | 7c0eae7 | 2014-11-19 21:01:40 | [diff] [blame] | 14 | self._skp_outdir = skp_outdir |
[email protected] | fbcf7ab | 2014-03-15 00:55:42 | [diff] [blame] | 15 | |
[email protected] | fb2b85d | 2012-09-12 18:45:56 | [diff] [blame] | 16 | def CustomizeBrowserOptions(self, options): |
[email protected] | 852511c | 2013-09-06 05:51:23 | [diff] [blame] | 17 | options.AppendExtraBrowserArgs(['--enable-gpu-benchmarking', |
| 18 | '--no-sandbox', |
[email protected] | cdb0abe | 2014-07-03 13:13:17 | [diff] [blame] | 19 | '--enable-deferred-image-decoding']) |
[email protected] | fb2b85d | 2012-09-12 18:45:56 | [diff] [blame] | 20 | |
[email protected] | f634a115 | 2014-08-09 08:30:17 | [diff] [blame] | 21 | def ValidateAndMeasurePage(self, page, tab, results): |
[email protected] | 0c4d8e5a | 2014-02-17 13:04:36 | [diff] [blame] | 22 | if tab.browser.platform.GetOSName() in ['android', 'chromeos']: |
nednguyen | e9321b1 | 2016-04-27 20:47:10 | [diff] [blame] | 23 | raise legacy_page_test.MeasurementFailure( |
[email protected] | 0c4d8e5a | 2014-02-17 13:04:36 | [diff] [blame] | 24 | 'SkPicture printing not supported on this platform') |
| 25 | |
[email protected] | fbcf7ab | 2014-03-15 00:55:42 | [diff] [blame] | 26 | outpath = os.path.abspath( |
| 27 | os.path.join(self._skp_outdir, page.file_safe_name)) |
perezju | 2445daf | 2017-01-31 17:39:58 | [diff] [blame] | 28 | # Replace win32 path separator char '\' with '\\'. |
| 29 | outpath = outpath.replace('\\', '\\\\') |
perezju | d42421be | 2017-02-28 09:40:20 | [diff] [blame] | 30 | tab.EvaluateJavaScript( |
perezju | 2445daf | 2017-01-31 17:39:58 | [diff] [blame] | 31 | 'chrome.gpuBenchmarking.printToSkPicture({{ outpath }});', |
| 32 | outpath=outpath) |
[email protected] | 0c4d8e5a | 2014-02-17 13:04:36 | [diff] [blame] | 33 | pictures = glob.glob(os.path.join(outpath, '*.skp')) |
Juan Antonio Navarro Perez | 20d65b2 | 2019-09-05 10:44:00 | [diff] [blame] | 34 | results.AddMeasurement('saved_picture_count', 'count', len(pictures)) |