xref: /aosp_15_r20/external/perfetto/ui/src/plugins/dev.perfetto.Screenshots/screenshot_panel.ts (revision 6dbdd20afdafa5e3ca9b8809fa73465d530080dc)
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 m from 'mithril';
16import {assertTrue} from '../../base/logging';
17import {exists} from '../../base/utils';
18import {getSlice, SliceDetails} from '../../components/sql_utils/slice';
19import {asSliceSqlId} from '../../components/sql_utils/core_types';
20import {Engine} from '../../trace_processor/engine';
21import {TrackEventDetailsPanel} from '../../public/details_panel';
22import {TrackEventSelection} from '../../public/selection';
23
24export class ScreenshotDetailsPanel implements TrackEventDetailsPanel {
25  private sliceDetails?: SliceDetails;
26
27  constructor(private readonly engine: Engine) {}
28
29  async load(selection: TrackEventSelection) {
30    this.sliceDetails = await getSlice(
31      this.engine,
32      asSliceSqlId(selection.eventId),
33    );
34  }
35
36  render() {
37    if (
38      !exists(this.sliceDetails) ||
39      !exists(this.sliceDetails.args) ||
40      this.sliceDetails.args.length == 0
41    ) {
42      return m('h2', 'Loading Screenshot');
43    }
44    assertTrue(this.sliceDetails.args[0].key == 'screenshot.jpg_image');
45    return m(
46      '.screenshot-panel',
47      m('img', {
48        src: 'data:image/png;base64, ' + this.sliceDetails.args[0].displayValue,
49      }),
50    );
51  }
52}
53