option optimize_for = LITE_RUNTIME;

package mir.protobuf;

// Outside of the IPC code no-one should care as this is all wrapped up.
// But for the following result messages we either populate the "real"
// attributes or, in the case of an error, the error attribute. So the
// attributes are all "optional" (or "repeated").

message ConnectParameters {
  required string application_name = 1;
}

message SurfaceParameters {
  required int32 width = 1;
  required int32 height = 2;
  required int32 pixel_format = 3;
  required int32 buffer_usage = 4;
  optional string surface_name = 5;
  optional uint32 output_id = 6;

  optional int32 type = 7;
  optional int32 state = 8;
  optional int32 pref_orientation = 9;
  optional int32 parent_id = 10;
  
  optional Rectangle aux_rect = 11;
  optional int32 edge_attachment = 12;

  optional int32 min_width = 13;
  optional int32 min_height = 14;
  optional int32 max_width = 15;
  optional int32 max_height = 16;
  optional int32 width_inc = 17;
  optional int32 height_inc = 18;
  optional SurfaceAspectRatio min_aspect = 19;
  optional SurfaceAspectRatio max_aspect = 20;

  optional PersistentSurfaceId parent_persistent_id = 21;
  repeated Rectangle input_shape = 22;
  optional int32 shell_chrome = 24;
}

message SurfaceAspectRatio
{
    required uint32 width  = 1;
    required uint32 height = 2;
}

// If and when we break our protocol backward-compatibility, this could be
// merged with SurfaceParameters...
message SurfaceSpecification {
  optional int32 width = 1;
  optional int32 height = 2;
  optional int32 pixel_format = 3;
  optional int32 buffer_usage = 4;
  optional string name = 5;
  optional uint32 output_id = 6;
  optional int32 type = 7;
  optional int32 state = 8;
  optional int32 preferred_orientation = 9;
  optional int32 parent_id = 10;
  optional Rectangle aux_rect = 11;
  optional int32 edge_attachment = 12;

  optional int32 min_width = 13;
  optional int32 min_height = 14;
  optional int32 max_width = 15;
  optional int32 max_height = 16;

  optional int32 width_inc = 17;
  optional int32 height_inc = 18;
  optional SurfaceAspectRatio min_aspect = 19;
  optional SurfaceAspectRatio max_aspect = 20;

  repeated StreamConfiguration stream = 21; 

  optional PersistentSurfaceId parent_persistent_id = 22;
  repeated Rectangle input_shape = 23;
  optional int32 shell_chrome = 24;
}

message StreamConfiguration {
  optional BufferStreamId id = 1;
  optional int32 displacement_x = 2;
  optional int32 displacement_y = 3;
  optional int32 swapinterval = 4;
  optional float scale = 5;

  optional int32 width = 6;
  optional int32 height = 7;

  optional string error = 127;
};

message SurfaceModifications {
  required SurfaceId surface_id = 1;
  required SurfaceSpecification surface_specification = 2;
}

message SurfaceId {
  required int32 value = 1;
};

message PersistentSurfaceId {
  optional string value = 1;

  optional string error = 127;
};

message BufferStreamId {
  required int32 value = 1;
};

message BufferStreamParameters {
    required int32 width = 1;
    required int32 height = 2;
    required int32 pixel_format = 3;
    required int32 buffer_usage = 4;
};

message BufferAllocation {
  optional BufferStreamId id = 1;
  repeated BufferStreamParameters buffer_requests = 2;  
};

message BufferRelease {
  repeated Buffer buffers = 1;  
  optional BufferStreamId id = 2;
};

message BufferRequest {
  optional BufferStreamId id = 1;
  optional Buffer buffer = 2;
};

message Buffer {
  optional int32 buffer_id = 1;
  repeated sint32 fd = 2;
  repeated int32  data = 3;
  optional int32  fds_on_side_channel = 4;
  optional int32  stride = 5;
  optional uint32 flags = 6;
  optional int32  width = 7;
  optional int32  height = 8;

  optional string error = 127;
}

message ModuleProperties
{
    required string name = 1;
    required uint32 major_version = 2;
    required uint32 minor_version = 3;
    required uint32 micro_version = 4;
    required string file = 5;
};


message Platform {
  repeated sint32 fd = 1;
  repeated int32  data = 2;
  optional int32  fds_on_side_channel = 3;
  optional ModuleProperties graphics_module = 4;

  optional string error = 127;
}

message DisplayCard {
    required uint32 card_id = 1;
    required uint32 max_simultaneous_outputs = 2;
}

message DisplayMode {
    optional uint32 vertical_resolution = 1;
    optional uint32 horizontal_resolution = 2;
    optional double refresh_rate = 3;
}

message DisplayOutput {
  repeated uint32 pixel_format = 1;
  optional uint32 current_format = 2;
  repeated DisplayMode mode = 3;
  optional uint32 current_mode = 4;
  optional sint32 position_x = 5;
  optional sint32 position_y = 6;
  optional uint32 card_id = 7;
  optional uint32 output_id = 8;
  optional uint32 connected = 9;
  optional uint32 used = 10;
  optional uint32 physical_width_mm = 11;
  optional uint32 physical_height_mm = 12;
  optional uint32 type = 13;
  optional uint32 preferred_mode = 14;
  optional uint32 power_mode = 15;
  optional sint32 orientation = 16;
  optional float scale_factor = 17;
  optional uint32 form_factor = 18;
}

message Connection {
  optional Platform platform = 1;
//  optional DisplayInfo display_info = 2;
  repeated DisplayOutput display_output = 3;
  optional DisplayConfiguration display_configuration = 4;
  repeated uint32 surface_pixel_format = 5;
  repeated InputDeviceInfo input_devices = 6;

  optional string error = 127;
}

message BufferStream {
  optional BufferStreamId id = 1;
  optional int32 pixel_format = 2;
  optional int32 buffer_usage = 3;
  optional Buffer buffer = 4;
  
  optional string error = 127;
}

message Surface {
  optional SurfaceId id = 1;
  optional int32 width = 2;
  optional int32 height = 3;
  optional int32 pixel_format = 4;
  optional int32 buffer_usage = 5;
  optional Buffer buffer = 6;

  repeated sint32 fd = 7;
  optional int32 fds_on_side_channel = 8;
  
  repeated SurfaceSetting attributes = 9;
  
  optional BufferStream buffer_stream = 10;

  optional string error = 127;
}

message Void {
  optional string error = 127;
}

message SurfaceSetting {
  optional SurfaceId surfaceid = 1;
  optional int32     attrib = 2;
  optional int32     ivalue = 3;
  // optional string    svalue = 4;  // Expected for future use
  optional string error = 127;
}

message Event {
  optional bytes raw = 1;  // MirEvent structure
}

message DisplayConfiguration {
  repeated DisplayOutput display_output = 1;
  repeated DisplayCard   display_card = 2;
  optional string error = 127;
}

message LifecycleEvent {
  required uint32 new_state = 1; // State transition
  optional string error = 127;
}

message PingEvent {
  optional int32 serial = 1;  // Identifier for this ping
}

message EventSequence {
  repeated Event event = 1;
  optional DisplayConfiguration display_configuration = 2;
  optional LifecycleEvent lifecycle_event = 3;
  optional BufferRequest buffer_request = 4;
  optional PingEvent ping_event = 5;
  repeated InputDeviceInfo input_devices = 6;

  optional string error = 127;
}

message Rectangle {
  required int32 left = 1;
  required int32 top = 2;
  required uint32 width = 3;
  required uint32 height = 4;
}

message ScreencastParameters {
  required Rectangle region = 1;
  required uint32 width = 2;
  required uint32 height = 3;
  required int32 pixel_format = 4;
}

message ScreencastId {
  required uint32 value = 1;
}

message Screencast {
  optional ScreencastId screencast_id = 1;
  optional Buffer buffer = 2;
  optional BufferStream buffer_stream = 3;
  optional string error = 127;
}

message CursorSetting {
  required SurfaceId surfaceid = 1;
  // No name is interpreted as disabled cursor.
  optional string name = 2;
  // If we supply a buffer stream we must supply hotspot x and y
  optional BufferStreamId buffer_stream = 3;
  optional int32 hotspot_x = 4;
  optional int32 hotspot_y = 5;
}

message SocketFDRequest {
  required int32 number = 1;
}

message SocketFD {
  repeated sint32 fd = 1;
  optional int32  fds_on_side_channel = 2;

  optional string error = 127;
}

message PromptSessionParameters {
  required int32 application_pid = 1;
}

message PlatformOperationMessage {
  optional uint32 opcode = 1;
  optional bytes data = 2;
  repeated sint32 fd = 3;
  optional int32  fds_on_side_channel = 4;

  optional string error = 127;
}

message CoordinateTranslationRequest {
  required SurfaceId surfaceid = 1;
  required int32 x = 2;
  required int32 y = 3;
}

message CoordinateTranslationResponse {
  optional int32 x = 1;
  optional int32 y = 2;

  optional string error = 127;
}

message Cookie {
  required bytes cookie = 1;
}

message RaiseRequest {
  required Cookie cookie = 1;
  required SurfaceId surface_id = 2;
}

message InputDeviceInfo {
  optional int64 id = 1;
  optional uint32 capabilities = 2;
  optional string name = 3;
  optional string unique_id = 4;
}
