/*
 * 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";

package android.os.statsd.display;

import "frameworks/proto_logging/stats/atoms.proto";
import "frameworks/proto_logging/stats/atom_field_options.proto";
import "frameworks/proto_logging/stats/enums/display/display_enums.proto";

option java_package = "com.android.os.display";
option java_multiple_files = true;

extend Atom {
  optional DisplayModeDirectorVoteChanged display_mode_director_vote_changed = 792 [(module) = "framework"];
  optional DisplayEventCallbackOccurred display_event_callback_occurred = 1149 [(module) = "framework"];
  optional DisplayOffloadStateChanged display_offload_state_changed = 1161 [(module) = "framework"];
  optional DisplayOffloadTransitionReported display_offload_transition_reported = 1162 [(module) = "framework"];
  optional DisplayOffloadCycleStats display_offload_cycle_stats = 1163 [(module) = "framework"];
  optional DisplayOffloadSessionStats display_offload_session_stats = 1164 [(module) = "framework"];
  optional DisplayInfoChanged display_info_changed = 1174 [(module) = "framework"];
}

/* Pushed atom for vote status change */
message DisplayModeDirectorVoteChanged {
  // Display id, or -1 if global vote
  optional int32 display_id = 1;
  // Vote priority numeric value, see com.android.server.display.mode.Vote
  optional int32 vote_priority = 2;
  // Vote status
  optional android.display.DisplayModeDirectorVoteStatus vote_status = 3;
  // Vote value, max refresh rate for now
  optional int32 value = 4;
  // Base mode value, -1 if not active
  optional int32 summary_value = 5;
}

/* Pushed atom for display event callback */
message DisplayEventCallbackOccurred {
  // The type of display event that occurred.
  optional android.display.EventType event_type = 1;
  // The UIDs of the clients that received this callback.
  repeated int32 uid = 2 [(is_uid) = true];
  // Number of clients that received this callback.
  optional int32 client_count = 3;
}

/**
 * Logs top-level display offload state changes (offloaded, deoffloaded).
 *
 * Logged from:
 *  frameworks/opt/wear/src/com/android/clockwork/displayoffload/DisplayOffloadService.java
 */
message DisplayOffloadStateChanged {
  // Identifies an offload cycle. A cycle begins when the display switches to an
  // offloaded state and ends when it switches back to a de-offloaded state.
  optional int32 cycle_id = 1;

  // Dimensions for offload sessions that were present in the cycle.
  // Sessions can persist across multiple cycles.
  // All lists must be sorted by (UID, session type, renderer type) tuples.
  repeated int32 session_ids = 2;
  repeated int32 uids = 3 [(is_uid) = true];
  repeated android.display.DisplayOffloadSessionType session_types = 4;
  repeated android.display.DisplayOffloadRendererType renderer_types = 5;

  optional android.display.DisplayOffloadState offload_state = 6;
}

/**
 * Logs cycle-level and session-level transitions.
 * Cycle-level transitions are logged after all cycle's sessions finish their transitions.
 *
 * Logged from:
 *  frameworks/opt/wear/src/com/android/clockwork/displayoffload/DisplayOffloadService.java
 */
message DisplayOffloadTransitionReported {
  // Identifies an offload cycle. A cycle begins when the display switches to an
  // offloaded state and ends when it switches back to a de-offloaded state.
  optional int32 cycle_id = 1;

  // Dimensions for offload sessions that were present in the cycle.
  // Sessions can persist across multiple cycles.
  // All lists must be sorted by (UID, session type, renderer type) tuples.
  // Session-level transitions will contain a single element in the lists.
  repeated int32 session_ids = 2;
  repeated int32 uids = 3 [(is_uid) = true];
  repeated android.display.DisplayOffloadSessionType session_types = 4;
  repeated android.display.DisplayOffloadRendererType renderer_types = 5;

  optional android.display.DisplayOffloadAggregationLevel aggregation_level = 6;

  optional android.display.DisplayOffloadTransitionType transition_type = 7;
  optional android.display.DisplayOffloadTransitionResult transition_result = 8;
  optional int32 transition_time_ms = 9;
}

/**
 * Logs offload cycle stats when offload cycle ends (one atom per cycle).
 *
 * Logged from:
 *  frameworks/opt/wear/src/com/android/clockwork/displayoffload/DisplayOffloadService.java
 */
message DisplayOffloadCycleStats {
  // Identifies an offload cycle. A cycle begins when the display switches to an
  // offloaded state and ends when it switches back to a de-offloaded state.
  optional int32 cycle_id = 1;

  // Dimensions for offload sessions that were present in the cycle.
  // Sessions can persist across multiple cycles.
  // All lists must be sorted by (UID, session type, renderer type) tuples.
  repeated int32 session_ids = 2;
  repeated int32 uids = 3 [(is_uid) = true];
  repeated android.display.DisplayOffloadSessionType session_types = 4;
  repeated android.display.DisplayOffloadRendererType renderer_types = 5;

  optional int32 offload_cycle_duration_ms = 6;

  // Histogram bins (26): [-inf, 1), [1, 5), [5, 7) ... [167, 200), [200, +inf)
  repeated int32 always_on_display_cpu_and_gpu_draw_time_per_frame_ms = 7
    [(histogram_bin_option).explicit_bins = {
      bin: 1
      bin: 5
      bin: 7
      bin: 9
      bin: 11
      bin: 13
      bin: 15
      bin: 17
      bin: 21
      bin: 25
      bin: 29
      bin: 33
      bin: 37
      bin: 41
      bin: 45
      bin: 50
      bin: 55
      bin: 61
      bin: 67
      bin: 83
      bin: 100
      bin: 133
      bin: 150
      bin: 167
      bin: 200
    }];

  // Histogram bins (26): [-inf, 1), [1, 5), [5, 7) ... [167, 200), [200, +inf)
  repeated int32 false_interactive_cpu_and_gpu_draw_time_per_frame_ms = 8
    [(histogram_bin_option).explicit_bins = {
      bin: 1
      bin: 5
      bin: 7
      bin: 9
      bin: 11
      bin: 13
      bin: 15
      bin: 17
      bin: 21
      bin: 25
      bin: 29
      bin: 33
      bin: 37
      bin: 41
      bin: 45
      bin: 50
      bin: 55
      bin: 61
      bin: 67
      bin: 83
      bin: 100
      bin: 133
      bin: 150
      bin: 167
      bin: 200
    }];

  // Histogram bins (26): [-inf, 1), [1, 5), [5, 7) ... [167, 200), [200, +inf)
  repeated int32 always_on_display_cpu_draw_time_per_frame_ms = 9
    [(histogram_bin_option).explicit_bins = {
      bin: 1
      bin: 5
      bin: 7
      bin: 9
      bin: 11
      bin: 13
      bin: 15
      bin: 17
      bin: 21
      bin: 25
      bin: 29
      bin: 33
      bin: 37
      bin: 41
      bin: 45
      bin: 50
      bin: 55
      bin: 61
      bin: 67
      bin: 83
      bin: 100
      bin: 133
      bin: 150
      bin: 167
      bin: 200
    }];

  // Histogram bins (26): [-inf, 1), [1, 5), [5, 7) ... [167, 200), [200, +inf)
  repeated int32 false_interactive_cpu_draw_time_per_frame_ms = 10
    [(histogram_bin_option).explicit_bins = {
      bin: 1
      bin: 5
      bin: 7
      bin: 9
      bin: 11
      bin: 13
      bin: 15
      bin: 17
      bin: 21
      bin: 25
      bin: 29
      bin: 33
      bin: 37
      bin: 41
      bin: 45
      bin: 50
      bin: 55
      bin: 61
      bin: 67
      bin: 83
      bin: 100
      bin: 133
      bin: 150
      bin: 167
      bin: 200
    }];

  optional float always_on_display_target_fps = 11;
  optional float false_interactive_target_fps = 12;

  // Time to move framebuffer to display hardware, per frame
  optional int32 min_framebuffer_to_display_hw_transfer_time_per_frame_ms = 13;
  optional int32 avg_framebuffer_to_display_hw_transfer_time_per_frame_ms = 14;
  optional int32 max_framebuffer_to_display_hw_transfer_time_per_frame_ms = 15;
  optional int32 var_framebuffer_to_display_hw_transfer_time_per_frame_ms = 16;

  // GPU command queue flush count, GPU driver-driven, per frame
  optional int32 avg_driver_driven_gpu_command_queue_flush_count_per_frame = 17;
  optional int32 max_driver_driven_gpu_command_queue_flush_count_per_frame = 18;

  // GPU command queue flush count, client forced, per frame
  optional int32 avg_client_forced_gpu_command_queue_flush_count_per_frame = 19;
  optional int32 max_client_forced_gpu_command_queue_flush_count_per_frame = 20;

  optional int32 requested_frame_count = 21;
  optional int32 drawn_frame_count = 22;
  optional int32 janky_frame_count = 23;

  // Number of tilt-to-wakes and the time device spent in false-interactive mode after TTW
  optional int32 tilt_to_wake_event_count = 24;
  optional int32 tilt_to_wake_false_interactive_duration_ms = 25;

  optional int32 cache_memory_max_bytes = 26;
  optional int32 cache_offload_cycle_end_bytes = 27;
  optional int32 cache_max_available_memory_block_bytes = 28;
}

/**
 * Logs offload session stats when offload cycle ends (one atom per offload session that
 * was present on MCU during the cycle, including ineligible and ignored sessions).
 *
 * Logged from:
 *  frameworks/opt/wear/src/com/android/clockwork/displayoffload/DisplayOffloadService.java
 */
message DisplayOffloadSessionStats {
  // Identifies an offload cycle. A cycle begins when the display switches to an
  // offloaded state and ends when it switches back to a de-offloaded state.
  optional int32 cycle_id = 1;

  // Dimensions for an offload session that was present in the cycle.
  // Sessions can persist across multiple cycles.
  optional int32 session_id = 2;
  optional int32 uid = 3 [(is_uid) = true];
  optional android.display.DisplayOffloadSessionType session_type = 4;
  optional android.display.DisplayOffloadRendererType renderer_type = 5;
  optional android.display.DisplayOffloadSessionEligibility eligibility = 6;

  // Fast memory usage
  optional int32 fast_memory_max_bytes = 7;
  optional int32 fast_memory_offload_cycle_end_bytes = 8;
  optional int32 fast_memory_max_available_memory_block_bytes = 9;

  // Regular memory usage
  optional int32 regular_memory_max_bytes = 10;
  optional int32 regular_memory_offload_cycle_end_bytes = 11;
  optional int32 regular_memory_max_available_memory_block_bytes = 12;

  // External memory usage
  optional int32 external_memory_max_bytes = 13;
  optional int32 external_memory_offload_cycle_end_bytes = 14;
  optional int32 external_memory_max_available_memory_block_bytes = 15;

  optional int32 layout_size_bytes = 16;

  // Histogram bins (26): [-inf, 1), [1, 3), [3, 5) .. [47, 49), [49, +inf)
  repeated int32 always_on_display_expression_evaluation_time_per_frame_ms = 17
    [(histogram_bin_option).generated_bins = {
      min: 1
      max: 49
      count: 24
      strategy: LINEAR
    }];

  // Histogram bins (26): [-inf, 1), [1, 2), [2, 3) .. [24, 25), [25, +inf)
  repeated int32 false_interactive_expression_evaluation_time_per_frame_ms = 18
  [(histogram_bin_option).generated_bins = {
    min: 1
    max: 25
    count: 24
    strategy: LINEAR
  }];

  // Histogram bins (26): [-inf, 1), [1, 3), [3, 5) .. [47, 49), [49, +inf)
  repeated int32 always_on_display_renderer_draw_time_per_frame_ms = 19
    [(histogram_bin_option).generated_bins = {
      min: 1
      max: 49
      count: 24
      strategy: LINEAR
    }];

  // Histogram bins (26): [-inf, 1), [1, 2), [2, 3) .. [24, 25), [25, +inf)
  repeated int32 false_interactive_renderer_draw_time_per_frame_ms = 20
    [(histogram_bin_option).generated_bins = {
      min: 1
      max: 25
      count: 24
      strategy: LINEAR
    }];
}

/* Pushed atom for when display information changes */
message DisplayInfoChanged {

  // The number of distinct DisplayInfo groups that changed in this event.
  optional int32 num_display_info_groups_changed = 1;

  // How many times BASIC_PROPERTIES DisplayInfo group changed in this event.
  optional int32 basic_properties_changed = 2;

  // How many times DIMENSIONS_AND_SHAPES DisplayInfo group changed in this event.
  optional int32 dimensions_and_shapes_changed = 3;

  // How many times ORIENTATION_AND_ROTATION DisplayInfo group changed in this event.
  optional int32 orientation_and_rotation_changed = 4;

  // How many times REFRESH_RATE_AND_MODE DisplayInfo group changed in this event.
  optional int32 refresh_rate_and_mode_changed = 5;

  // How many times COLOR_AND_BRIGHTNESS DisplayInfo group changed in this event.
  optional int32 color_and_brightness_changed = 6;

  // How many times STATE DisplayInfo group changed in this event.
  optional int32 state_changed = 7;

  // The source of the event.
  optional android.display.EventSource event_source = 8;

}
