| <!DOCTYPE html> |
| <!-- |
| Copyright (c) 2015 The Chromium Authors. All rights reserved. |
| Use of this source code is governed by a BSD-style license that can be |
| found in the LICENSE file. |
| --> |
| <link rel="import" href="/base/base.html"> |
| <link rel="import" href="/core/auditor.html"> |
| <link rel="import" href="/extras/audits/android_app.html"> |
| <link rel="import" href="/extras/audits/android_surface_flinger.html"> |
| <link rel="import" href="/extras/audits/utils.html"> |
| |
| <script> |
| 'use strict'; |
| |
| /** |
| * @fileoverview Class for managing android-specific model meta data, |
| * such as rendering apps, frames rendered, and SurfaceFlinger. |
| */ |
| tv.exportTo('tv.e.audits', function() { |
| var AndroidApp = tv.e.audits.AndroidApp; |
| var AndroidSurfaceFlinger = tv.e.audits.AndroidSurfaceFlinger; |
| |
| var IMPORTANT_SURFACE_FLINGER_SLICES = { |
| 'doComposition' : true, |
| 'updateTexImage' : true, |
| 'postFramebuffer' : true |
| }; |
| var IMPORTANT_UI_THREAD_SLICES = { |
| 'performTraversals' : true, |
| 'deliverInputEvent' : true |
| }; |
| var IMPORTANT_RENDER_THREAD_SLICES = { |
| 'doFrame' : true |
| }; |
| |
| function iterateImportantThreadSlices(thread, important, callback) { |
| if (!thread) |
| return; |
| |
| thread.sliceGroup.slices.forEach(function(slice) { |
| if (slice.title in important) |
| callback(slice); |
| }); |
| } |
| |
| /** |
| * Model for Android-specific data. |
| * @constructor |
| */ |
| function AndroidModelHelper(model) { |
| this.model = model; |
| this.apps = []; |
| this.surfaceFlinger = undefined; |
| |
| var processes = model.getAllProcesses(); |
| for (var i = 0; i < processes.length && !this.surfaceFlinger; i++) { |
| this.surfaceFlinger = |
| AndroidSurfaceFlinger.createForProcessIfPossible(processes[i]); |
| } |
| |
| model.getAllProcesses().forEach(function(process) { |
| var app = AndroidApp.createForProcessIfPossible( |
| process, this.surfaceFlinger); |
| if (app) |
| this.apps.push(app); |
| }, this); |
| }; |
| |
| AndroidModelHelper.prototype = { |
| iterateImportantSlices: function(callback) { |
| if (this.surfaceFlinger) { |
| iterateImportantThreadSlices( |
| this.surfaceFlinger.thread, |
| IMPORTANT_SURFACE_FLINGER_SLICES, |
| callback); |
| } |
| |
| this.apps.forEach(function(app) { |
| iterateImportantThreadSlices( |
| app.uiThread, |
| IMPORTANT_UI_THREAD_SLICES, |
| callback); |
| iterateImportantThreadSlices( |
| app.renderThread, |
| IMPORTANT_RENDER_THREAD_SLICES, |
| callback); |
| }); |
| } |
| }; |
| |
| return { |
| AndroidModelHelper: AndroidModelHelper |
| }; |
| }); |
| </script> |