1// Copyright (C) 2024 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 {Trace} from '../../public/trace'; 16import {LONG, NUM, STR} from '../../trace_processor/query_result'; 17import {ColorScheme} from '../../base/color_scheme'; 18import {JANK_COLOR} from './jank_colors'; 19import {getColorForSlice, makeColorScheme} from '../../components/colorizer'; 20import {HSLColor} from '../../base/color'; 21import {ScrollTimelineDetailsPanel} from './scroll_timeline_details_panel'; 22import { 23 ScrollTimelineModel, 24 ScrollUpdateClassification, 25} from './scroll_timeline_model'; 26import {DatasetSliceTrack} from '../../components/tracks/dataset_slice_track'; 27import {SourceDataset} from '../../trace_processor/dataset'; 28 29const INDIGO = makeColorScheme(new HSLColor([231, 48, 48])); 30const GRAY = makeColorScheme(new HSLColor([0, 0, 62])); 31const DARK_GREEN = makeColorScheme(new HSLColor([120, 44, 34])); 32const TEAL = makeColorScheme(new HSLColor([187, 90, 42])); 33 34function toColorScheme( 35 classification: ScrollUpdateClassification, 36): ColorScheme | undefined { 37 switch (classification) { 38 case ScrollUpdateClassification.DEFAULT: 39 return INDIGO; 40 case ScrollUpdateClassification.JANKY: 41 return JANK_COLOR; 42 case ScrollUpdateClassification.COALESCED: 43 return GRAY; 44 case ScrollUpdateClassification.FIRST_SCROLL_UPDATE_IN_FRAME: 45 return DARK_GREEN; 46 case ScrollUpdateClassification.INERTIAL: 47 return TEAL; 48 case ScrollUpdateClassification.STEP: 49 return undefined; 50 } 51} 52 53export function createScrollTimelineTrack( 54 trace: Trace, 55 model: ScrollTimelineModel, 56) { 57 return new DatasetSliceTrack({ 58 trace, 59 uri: model.trackUri, 60 dataset: new SourceDataset({ 61 src: model.tableName, 62 schema: { 63 id: NUM, 64 ts: LONG, 65 dur: LONG, 66 name: STR, 67 classification: NUM, 68 depth: NUM, 69 }, 70 }), 71 colorizer: (row) => { 72 return toColorScheme(row.classification) ?? getColorForSlice(row.name); 73 }, 74 detailsPanel: (row) => { 75 return new ScrollTimelineDetailsPanel(trace, model, row.id); 76 }, 77 }); 78} 79