Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit dcc0bab7 authored by Nataniel Borges's avatar Nataniel Borges
Browse files

Update SF dump to use proto3

The C++ implementation of Proto2 writes default values to the protobuf object, whenever they are set in the app. That is, if we write 0 into an integer or float field, the protobuf writes the value 0 in the object.

Proto3 skips default values, even if they are set.

Changing from proto2 to proto3 reduces by ~20% the memory requirement for storing SF traces. It also allows default values to be ignored in Winscope

Test: Record a SF trace. Flash a device. Record another SF trace. Check the trace size and/or open them in winscope version with "display defaults" unchecked.
Change-Id: I69ff09d141f6f31f22a4f5fc90bf58cf222d9aae
parent 27eb509e
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -2125,11 +2125,15 @@ void Layer::writeToProto(LayerProto* layerInfo, LayerVector::StateSet stateSet)
    auto parent = useDrawing ? mDrawingParent.promote() : mCurrentParent.promote();
    if (parent != nullptr) {
        layerInfo->set_parent(parent->sequence);
    } else {
        layerInfo->set_parent(-1);
    }

    auto zOrderRelativeOf = state.zOrderRelativeOf.promote();
    if (zOrderRelativeOf != nullptr) {
        layerInfo->set_z_order_relative_of(zOrderRelativeOf->sequence);
    } else {
        layerInfo->set_z_order_relative_of(-1);
    }

    // XXX getBE().compositionInfo.mBuffer is not protected
+2 −2
Original line number Diff line number Diff line
@@ -199,13 +199,13 @@ void LayerProtoParser::updateChildrenAndRelative(const LayerProto& layerProto,
        }
    }

    if (layerProto.has_parent()) {
    if (layerProto.parent() != -1) {
        if (layerMap.count(layerProto.parent()) > 0) {
            currLayer->parent = layerMap[layerProto.parent()];
        }
    }

    if (layerProto.has_z_order_relative_of()) {
    if (layerProto.z_order_relative_of() != -1) {
        if (layerMap.count(layerProto.z_order_relative_of()) > 0) {
            currLayer->zOrderRelativeOf = layerMap[layerProto.z_order_relative_of()];
        }
+74 −74
Original line number Diff line number Diff line
// Definitions for SurfaceFlinger layers.

syntax = "proto2";
syntax = "proto3";
option optimize_for = LITE_RUNTIME;
package android.surfaceflinger;

// Contains a list of all layers.
message LayersProto {
  repeated LayerProto layers = 1;
  optional SizeProto resolution = 2;
  optional string color_mode = 3;
  optional string color_transform = 4;
  optional int32 global_transform = 5;
  SizeProto resolution = 2;
  string color_mode = 3;
  string color_transform = 4;
  int32 global_transform = 5;
}

// Information about each layer.
message LayerProto {
  // unique id per layer.
  optional int32 id = 1;
  int32 id = 1;
  // unique name per layer.
  optional string name = 2;
  string name = 2;
  // list of children this layer may have. May be empty.
  repeated int32 children = 3;
  // list of layers that are z order relative to this layer.
  repeated int32 relatives = 4;
  // The type of layer, ex Color, Layer
  optional string type = 5;
  optional RegionProto transparent_region = 6;
  optional RegionProto visible_region = 7;
  optional RegionProto damage_region = 8;
  optional uint32 layer_stack = 9;
  string type = 5;
  RegionProto transparent_region = 6;
  RegionProto visible_region = 7;
  RegionProto damage_region = 8;
  uint32 layer_stack = 9;
  // The layer's z order. Can be z order in layer stack, relative to parent,
  // or relative to another layer specified in zOrderRelative.
  optional int32 z = 10;
  int32 z = 10;
  // The layer's position on the display.
  optional PositionProto position = 11;
  PositionProto position = 11;
  // The layer's requested position.
  optional PositionProto requested_position = 12;
  PositionProto requested_position = 12;
  // The layer's size.
  optional SizeProto size = 13;
  SizeProto size = 13;
  // The layer's crop in it's own bounds.
  optional RectProto crop = 14;
  RectProto crop = 14;
  // The layer's crop in it's parent's bounds.
  optional RectProto final_crop = 15 [deprecated=true];
  optional bool is_opaque = 16;
  optional bool invalidate = 17;
  optional string dataspace = 18;
  optional string pixel_format = 19;
  RectProto final_crop = 15 [deprecated=true];
  bool is_opaque = 16;
  bool invalidate = 17;
  string dataspace = 18;
  string pixel_format = 19;
  // The layer's actual color.
  optional ColorProto color = 20;
  ColorProto color = 20;
  // The layer's requested color.
  optional ColorProto requested_color = 21;
  ColorProto requested_color = 21;
  // Can be any combination of
  //    hidden = 0x01
  //    opaque = 0x02,
  //    secure = 0x80,
  optional uint32 flags = 22;
  uint32 flags = 22;
  // The layer's actual transform
  optional TransformProto transform = 23;
  TransformProto transform = 23;
  // The layer's requested transform.
  optional TransformProto requested_transform = 24;
  TransformProto requested_transform = 24;
  // The parent layer. This value can be null if there is no parent.
  optional int32 parent = 25 [default = -1];
  int32 parent = 25;
  // The layer that this layer has a z order relative to. This value can be null.
  optional int32 z_order_relative_of = 26 [default = -1];
  int32 z_order_relative_of = 26;
  // This value can be null if there's nothing to draw.
  optional ActiveBufferProto active_buffer = 27;
  ActiveBufferProto active_buffer = 27;
  // The number of frames available.
  optional int32 queued_frames = 28;
  optional bool refresh_pending = 29;
  int32 queued_frames = 28;
  bool refresh_pending = 29;
  // The layer's composer backend destination frame
  optional RectProto hwc_frame = 30;
  RectProto hwc_frame = 30;
  // The layer's composer backend source crop
  optional FloatRectProto hwc_crop = 31;
  FloatRectProto hwc_crop = 31;
  // The layer's composer backend transform
  optional int32 hwc_transform = 32;
  optional int32 window_type = 33 [deprecated=true];
  optional int32 app_id = 34 [deprecated=true];
  int32 hwc_transform = 32;
  int32 window_type = 33 [deprecated=true];
  int32 app_id = 34 [deprecated=true];
  // The layer's composition type
  optional int32 hwc_composition_type = 35;
  int32 hwc_composition_type = 35;
  // If it's a buffer layer, indicate if the content is protected
  optional bool is_protected = 36;
  bool is_protected = 36;
  // Current frame number being rendered.
  optional uint64 curr_frame = 37;
  uint64 curr_frame = 37;
  // A list of barriers that the layer is waiting to update state.
  repeated BarrierLayerProto barrier_layer = 38;
  // If active_buffer is not null, record its transform.
  optional TransformProto buffer_transform = 39;
  optional int32 effective_scaling_mode = 40;
  TransformProto buffer_transform = 39;
  int32 effective_scaling_mode = 40;
  // Layer's corner radius.
  optional float corner_radius = 41;
  float corner_radius = 41;
  // Metadata map. May be empty.
  map<int32, bytes> metadata = 42;

  optional TransformProto effective_transform = 43;
  optional FloatRectProto source_bounds = 44;
  optional FloatRectProto bounds = 45;
  optional FloatRectProto screen_bounds = 46;
  TransformProto effective_transform = 43;
  FloatRectProto source_bounds = 44;
  FloatRectProto bounds = 45;
  FloatRectProto screen_bounds = 46;
}

message PositionProto {
  optional float x = 1;
  optional float y = 2;
  float x = 1;
  float y = 2;
}

message SizeProto {
  optional int32 w = 1;
  optional int32 h = 2;
  int32 w = 1;
  int32 h = 2;
}

message TransformProto {
  optional float dsdx = 1;
  optional float dtdx = 2;
  optional float dsdy = 3;
  optional float dtdy = 4;
  float dsdx = 1;
  float dtdx = 2;
  float dsdy = 3;
  float dtdy = 4;
}

message RegionProto {
  optional uint64 id = 1;
  uint64 id = 1;
  repeated RectProto rect = 2;
}

message RectProto {
  optional int32 left   = 1;
  optional int32 top    = 2;
  optional int32 right  = 3;
  optional int32 bottom = 4;
  int32 left   = 1;
  int32 top    = 2;
  int32 right  = 3;
  int32 bottom = 4;
}

message FloatRectProto {
  optional float left = 1;
  optional float top = 2;
  optional float right = 3;
  optional float bottom = 4;
  float left = 1;
  float top = 2;
  float right = 3;
  float bottom = 4;
}

message ActiveBufferProto {
  optional uint32 width = 1;
  optional uint32 height = 2;
  optional uint32 stride = 3;
  optional int32 format = 4;
  uint32 width = 1;
  uint32 height = 2;
  uint32 stride = 3;
  int32 format = 4;
}

message ColorProto {
  optional float r = 1;
  optional float g = 2;
  optional float b = 3;
  optional float a = 4;
  float r = 1;
  float g = 2;
  float b = 3;
  float a = 4;
}

message BarrierLayerProto {
  // layer id the barrier is waiting on.
  optional int32 id = 1;
  int32 id = 1;
  // frame number the barrier is waiting on.
  optional uint64 frame_number = 2;
  uint64 frame_number = 2;
}