1// Copyright (C) 2023 The Android Open Source Project 2// 3// Licensed under the Apache License, Version 2.0 (the "License"); 4// you may not use this file except in compliance with the License. 5// You may obtain a copy of the License at 6// 7// http://www.apache.org/licenses/LICENSE-2.0 8// 9// Unless required by applicable law or agreed to in writing, software 10// distributed under the License is distributed on an "AS IS" BASIS, 11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12// See the License for the specific language governing permissions and 13// limitations under the License. 14 15import {featureFlags} from '../../common/feature_flags'; 16import {PluginContext} from '../../common/plugin_api'; 17import {Selection} from '../../common/state'; 18import {CURRENT_SELECTION_TAG} from '../../frontend/details_panel'; 19import {globals} from '../../frontend/globals'; 20 21import {EventLatencyTrack} from './event_latency_track'; 22import {TopLevelScrollDetailsTab} from './scroll_details_tab'; 23import { 24 TOP_LEVEL_SCROLL_KIND, 25 TopLevelScrollTrack, 26} from './scroll_track'; 27 28export const INPUT_LATENCY_TRACK = 'InputLatency::'; 29export const SCROLL_JANK_PLUGIN_ID = 'perfetto.ScrollJank'; 30export const ENABLE_SCROLL_JANK_PLUGIN_V2 = featureFlags.register({ 31 id: 'enableScrollJankPluginV2', 32 name: 'Enable Scroll Jank plugin V2', 33 description: 'Adds new tracks and visualizations for scroll jank.', 34 defaultValue: false, 35}); 36 37function onDetailsPanelSelectionChange(newSelection?: Selection) { 38 if (newSelection === undefined || 39 newSelection.kind !== TOP_LEVEL_SCROLL_KIND) { 40 return; 41 } 42 const bottomTabList = globals.bottomTabList; 43 if (!bottomTabList) return; 44 bottomTabList.addTab({ 45 kind: TopLevelScrollDetailsTab.kind, 46 tag: CURRENT_SELECTION_TAG, 47 config: { 48 sqlTableName: newSelection.sqlTableName, 49 id: newSelection.id, 50 }, 51 }); 52} 53 54function activate(ctx: PluginContext) { 55 ctx.registerTrack(TopLevelScrollTrack); 56 ctx.registerTrack(EventLatencyTrack); 57 ctx.registerOnDetailsPanelSelectionChange(onDetailsPanelSelectionChange); 58} 59 60export const plugin = { 61 pluginId: SCROLL_JANK_PLUGIN_ID, 62 activate, 63}; 64