1/* 2 * Copyright (C) 2022 Huawei Device Co., Ltd. 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 */ 15 16import { ColorUtils } from '../../component/trace/base/ColorUtils.js'; 17import { 18 hiPerf, 19 HiPerfStruct, 20 PerfRender, 21 RequestMessage, 22} from './ProcedureWorkerCommon.js'; 23import { TraceRow } from '../../component/trace/base/TraceRow.js'; 24 25export class HiperfProcessRender extends PerfRender { 26 renderMainThread(hiPerfProcessReq: any, row: TraceRow<HiPerfProcessStruct>): void { 27 let list = row.dataList; 28 let filter = row.dataListCache; 29 let groupBy10MS = hiPerfProcessReq.scale > 30_000_000; 30 if (list && row.dataList2.length === 0) { 31 row.dataList2 = HiPerfProcessStruct.groupBy10MS(list, hiPerfProcessReq.intervalPerf); 32 } 33 hiPerf( 34 list, 35 row.dataList2, 36 filter, 37 TraceRow.range?.startNS ?? 0, 38 TraceRow.range?.endNS ?? 0, 39 row.frame, 40 groupBy10MS, 41 hiPerfProcessReq.useCache || (TraceRow.range?.refresh ?? false) 42 ); 43 hiPerfProcessReq.context.beginPath(); 44 hiPerfProcessReq.context.fillStyle = ColorUtils.FUNC_COLOR[0]; 45 hiPerfProcessReq.context.strokeStyle = ColorUtils.FUNC_COLOR[0]; 46 let normalPath = new Path2D(); 47 let specPath = new Path2D(); 48 let offset = groupBy10MS ? 0 : 3; 49 let find = false; 50 for (let re of filter) { 51 HiPerfProcessStruct.draw(hiPerfProcessReq.context, normalPath, specPath, re, groupBy10MS); 52 if (row.isHover) { 53 if (re.frame && row.hoverX >= re.frame.x - offset && row.hoverX <= re.frame.x + re.frame.width + offset) { 54 HiPerfProcessStruct.hoverStruct = re; 55 find = true; 56 } 57 } 58 } 59 if (!find && row.isHover) { 60 HiPerfProcessStruct.hoverStruct = undefined; 61 } 62 if (groupBy10MS) { 63 hiPerfProcessReq.context.fill(normalPath); 64 } else { 65 hiPerfProcessReq.context.stroke(normalPath); 66 HiPerfStruct.drawSpecialPath(hiPerfProcessReq.context, specPath); 67 } 68 hiPerfProcessReq.context.closePath(); 69 } 70 71 render(hiPerfProcessRequest: RequestMessage, list: Array<any>, filter: Array<any>, dataList2: Array<any>): void {} 72} 73 74export class HiPerfProcessStruct extends HiPerfStruct { 75 static hoverStruct: HiPerfProcessStruct | undefined; 76 static selectStruct: HiPerfProcessStruct | undefined; 77} 78