/*
 * Copyright (C) 2023 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 required 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.
 */

syntax = "proto2";

import "protos/perfetto/trace/android/graphics/rect.proto";

package perfetto.protos;

// ShellTransition messages record information about the shell transitions in
// the system. This is used to track the animations that are created and execute
// through the shell transition system.
message ShellTransition {
  // The unique identifier of the transition.
  optional int32 id = 1;

  // The time the transition was created on the WM side
  // (using SystemClock.elapsedRealtimeNanos())
  optional int64 create_time_ns = 2 [jstype = JS_STRING];
  // The time the transition was sent from the WM side to shell
  // (using SystemClock.elapsedRealtimeNanos())
  optional int64 send_time_ns = 3 [jstype = JS_STRING];
  // The time the transition was dispatched by shell to execute
  // (using SystemClock.elapsedRealtimeNanos())
  optional int64 dispatch_time_ns = 4 [jstype = JS_STRING];
  // If the transition merge was accepted by the transition handler, this
  // contains the time the transition was merged into transition with id
  // `merge_target`.
  // (using SystemClock.elapsedRealtimeNanos())
  optional int64 merge_time_ns = 5 [jstype = JS_STRING];
  // The time shell proposed the transition should be merged to the transition
  // handler into transition with id `merge_target`.
  // (using SystemClock.elapsedRealtimeNanos()).
  optional int64 merge_request_time_ns = 6 [jstype = JS_STRING];
  // If the transition was aborted on the shell side, this is the time that
  // occurred.
  // (using SystemClock.elapsedRealtimeNanos())
  optional int64 shell_abort_time_ns = 7 [jstype = JS_STRING];
  // If the transition was aborted on the wm side, this is the time that
  // occurred.
  // (using SystemClock.elapsedRealtimeNanos())
  optional int64 wm_abort_time_ns = 8 [jstype = JS_STRING];
  // The time WM considers the transition to be complete.
  // (using SystemClock.elapsedRealtimeNanos())
  optional int64 finish_time_ns = 9 [jstype = JS_STRING];

  // The id of the transaction that WM proposed to use as the starting
  // transaction. It contains all the layer changes required to setup the
  // transition and should be executed right at the start of the transition
  // by the transition handler.
  optional uint64 start_transaction_id = 10 [jstype = JS_STRING];
  // The if of the transaction that WM proposed to use as the finish
  // transaction. It contains all the layer changes required to set the final
  // state of the transition.
  optional uint64 finish_transaction_id = 11 [jstype = JS_STRING];

  // The id of the handler that executed the transition. A HandlerMappings
  // message in the trace will contain the mapping of id to a string
  // representation of the handler.
  optional int32 handler = 12;
  // The transition type of this transition (e.g. TO_FRONT, OPEN, CLOSE).
  optional int32 type = 13;

  // The list of changes that are part of this transition.
  repeated Change changes = 14;
  // The id of the transition we have requested to merge or have merged this
  // transition into.
  optional int32 merge_target = 15;

  // The flags set on this transition.
  optional int32 flags = 16;
  // The time the starting window was removed. Tracked because this can
  // happen after the transition finishes, but the app may not yet be visible
  // until the starting window is removed. So in a sense the transition is not
  // finished until the starting window is removed. (b/284302118)
  // (using SystemClock.elapsedRealtimeNanos())
  optional int64 starting_window_remove_time_ns = 17 [jstype = JS_STRING];

  // Contains the information about the windows changed in a transition.
  message Change {
    // The transition mode of this change (e.g. TO_FRONT, CLOSE...)
    optional int32 mode = 1;
    // The layer id of this change.
    optional int32 layer_id = 2;
    // The window id of this change.
    optional int32 window_id = 3;
    // The flags set on this change.
    optional int32 flags = 4;
    // The display id the change is transitioning on before the transition.
    optional int32 start_display_id = 5;
    // The display id the change is transitioning on after the transition.
    optional int32 end_display_id = 6;
    // The rotation of the change before the transition.
    optional int32 start_rotation = 7;
    // The rotation of the change after the transition.
    optional int32 end_rotation = 8;
    // The absolute screen bounds of the change before the transition.
    optional RectProto start_absolute_bounds = 9;
    // The absolute screen bounds of the change after the transition.
    optional RectProto end_absolute_bounds = 10;
  }
}

// Contains mappings from handler ids to string representation of the handlers.
message ShellHandlerMappings {
  repeated ShellHandlerMapping mapping = 1;
}

message ShellHandlerMapping {
  // The id of the handler used in the ShellTransition message.
  optional int32 id = 1;
  // A human readable and meaningful string representation of the handler.
  optional string name = 2;
}
