1/*
2 * Copyright 2019, The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *     http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17import {transform, nanos_to_string} from './transform.js'
18
19function transform_transaction(transaction) {
20  return transform({
21    obj: transaction,
22    kind: 'transaction',
23    children:[[transaction.surfaceChange, transform_entry_type('surfaceChange')],
24        [transaction.displayChange, transform_entry_type('displayChange')]],
25    rects: [],
26    visible: false,
27  })
28}
29
30function transform_entry_type(transactionType) {
31  function return_transform(item) {
32    return Object.freeze({
33      obj: item,
34      kind: transactionType,
35      rects: [],
36      visible: false,
37      name: item.name || item.id || nanos_to_string(item.when),
38    });
39  }
40  return transactionType === 'transaction' ? transform_transaction : return_transform;
41}
42
43function transform_entry(entry) {
44  var transactionType = entry.increment;
45  return transform({
46    obj: entry,
47    kind: 'entry',
48    name: nanos_to_string(entry.timeStamp),
49    children: [[[entry[transactionType]], transform_entry_type(transactionType)]],
50    timestamp: entry.timeStamp,
51  });
52}
53
54function transform_transaction_trace(entries) {
55  var r = transform({
56    obj: entries,
57    kind: 'entries',
58    name: 'transactionstrace',
59    children: [
60      [entries.increment, transform_entry],
61    ],
62  })
63  return r;
64}
65
66export {transform_transaction_trace};
67