/*
 * Copyright (C) 2022 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless optional by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/*
    This file is a snapshot of
    frameworks/base/core/proto/android/server/windowmanagertransitiontrace.proto
    before it got moved to external/perfetto as part of the winscope-to-perfetto
   migration.
 */
syntax = "proto2";

package com.android.server.wm.shell;

option java_multiple_files = true;

/* Represents a file full of transition entries.
   Encoded, it should start with 0x09 0x54 0x52 0x4E 0x54 0x52 0x41 0x43 0x45
   (.TRNTRACE), such that it can be easily identified. */
message TransitionTraceProto {
  /* constant; MAGIC_NUMBER = (long) MAGIC_NUMBER_H << 32 |
     MagicNumber.MAGIC_NUMBER_L (this is needed because enums have to be 32 bits
     and there's no nice way to put 64bit constants into .proto files. */
  enum MagicNumber {
    INVALID = 0;
    MAGIC_NUMBER_L = 0x544e5254; /* TRNT (little-endian ASCII) */
    MAGIC_NUMBER_H = 0x45434152; /* RACE (little-endian ASCII) */
  }

  // Must be the first field, set to value in MagicNumber
  optional fixed64 magic_number = 1;
  repeated Transition transitions = 2;

  /* offset between real-time clock and elapsed time clock in nanoseconds.
   Calculated as: 1000000 * System.currentTimeMillis() -
   SystemClock.elapsedRealtimeNanos() */
  optional fixed64 real_to_elapsed_time_offset_nanos = 3;
}

message Transition {
  optional int32 id = 1;
  optional uint64 start_transaction_id = 2;
  optional uint64 finish_transaction_id = 3;
  optional int64 create_time_ns = 4;
  optional int64 send_time_ns = 5;
  optional int64 finish_time_ns = 6;
  optional int32 type = 7;
  repeated Target targets = 8;
  optional int32 flags = 9;
  optional int64 abort_time_ns = 10;
  optional int64 starting_window_remove_time_ns = 11;
}

message Target {
  optional int32 mode = 1;
  optional int32 layer_id = 2;
  optional int32 window_id = 3;  // Not dumped in always on tracing
  optional int32 flags = 4;
}
