Loading services/surfaceflinger/Tracing/TransactionProtoParser.cpp +136 −64 Original line number Diff line number Diff line Loading @@ -22,9 +22,9 @@ namespace android::surfaceflinger { proto::TransactionState TransactionProtoParser::toProto( const TransactionState& t, std::function<int32_t(const sp<IBinder>&)> getLayerId, std::function<int32_t(const sp<IBinder>&)> getDisplayId) { proto::TransactionState TransactionProtoParser::toProto(const TransactionState& t, LayerHandleToIdFn getLayerId, DisplayHandleToIdFn getDisplayId) { proto::TransactionState proto; proto.set_pid(t.originPid); proto.set_uid(t.originUid); Loading @@ -42,10 +42,38 @@ proto::TransactionState TransactionProtoParser::toProto( return proto; } proto::LayerState TransactionProtoParser::toProto( const layer_state_t& layer, std::function<int32_t(const sp<IBinder>&)> getLayerId) { proto::TransactionState TransactionProtoParser::toProto( std::vector<std::pair<int32_t /* layerId */, TracingLayerState>> states) { proto::TransactionState proto; for (auto& [layerId, state] : states) { proto::LayerState layerProto = toProto(state, nullptr); if (layerProto.has_buffer_data()) { proto::LayerState_BufferData* bufferProto = layerProto.mutable_buffer_data(); bufferProto->set_buffer_id(state.bufferId); bufferProto->set_width(state.bufferWidth); bufferProto->set_height(state.bufferHeight); } layerProto.set_has_sideband_stream(state.hasSidebandStream); layerProto.set_layer_id(state.layerId); layerProto.set_parent_id(state.parentId); layerProto.set_relative_parent_id(state.relativeParentId); if (layerProto.has_window_info_handle()) { layerProto.mutable_window_info_handle()->set_crop_layer_id(state.inputCropId); } proto.mutable_layer_changes()->Add(std::move(layerProto)); } return proto; } proto::LayerState TransactionProtoParser::toProto(const layer_state_t& layer, LayerHandleToIdFn getLayerId) { proto::LayerState proto; if (getLayerId != nullptr) { proto.set_layer_id(getLayerId(layer.surface)); } else { proto.set_layer_id(layer.layerId); } proto.set_what(layer.what); if (layer.what & layer_state_t::ePositionChanged) { Loading Loading @@ -130,13 +158,13 @@ proto::LayerState TransactionProtoParser::toProto( } } if (layer.what & layer_state_t::eReparent) { if ((layer.what & layer_state_t::eReparent) && getLayerId != nullptr) { int32_t layerId = layer.parentSurfaceControlForChild ? getLayerId(layer.parentSurfaceControlForChild->getHandle()) : -1; proto.set_parent_id(layerId); } if (layer.what & layer_state_t::eRelativeLayerChanged) { if ((layer.what & layer_state_t::eRelativeLayerChanged) && getLayerId != nullptr) { int32_t layerId = layer.relativeLayerSurfaceControl ? getLayerId(layer.relativeLayerSurfaceControl->getHandle()) : -1; Loading Loading @@ -164,8 +192,12 @@ proto::LayerState TransactionProtoParser::toProto( transformProto->set_ty(inputInfo->transform.ty()); windowInfoProto->set_replace_touchable_region_with_crop( inputInfo->replaceTouchableRegionWithCrop); if (getLayerId != nullptr) { windowInfoProto->set_crop_layer_id( getLayerId(inputInfo->touchableRegionCropHandle.promote())); } else { windowInfoProto->set_crop_layer_id(-1); } } } if (layer.what & layer_state_t::eBackgroundColorChanged) { Loading Loading @@ -212,11 +244,13 @@ proto::LayerState TransactionProtoParser::toProto( return proto; } proto::DisplayState TransactionProtoParser::toProto( const DisplayState& display, std::function<int32_t(const sp<IBinder>&)> getDisplayId) { proto::DisplayState TransactionProtoParser::toProto(const DisplayState& display, DisplayHandleToIdFn getDisplayId) { proto::DisplayState proto; proto.set_what(display.what); if (getDisplayId != nullptr) { proto.set_id(getDisplayId(display.token)); } if (display.what & DisplayState::eLayerStackChanged) { proto.set_layer_stack(display.layerStack.id); Loading @@ -238,9 +272,18 @@ proto::DisplayState TransactionProtoParser::toProto( return proto; } TransactionState TransactionProtoParser::fromProto( const proto::TransactionState& proto, std::function<sp<IBinder>(int32_t)> getLayerHandle, std::function<sp<IBinder>(int32_t)> getDisplayHandle) { proto::LayerCreationArgs TransactionProtoParser::toProto(const TracingLayerCreationArgs& args) { proto::LayerCreationArgs proto; proto.set_layer_id(args.layerId); proto.set_name(args.name); proto.set_flags(args.flags); proto.set_parent_id(args.parentId); return proto; } TransactionState TransactionProtoParser::fromProto(const proto::TransactionState& proto, LayerIdToHandleFn getLayerHandle, DisplayIdToHandleFn getDisplayHandle) { TransactionState t; t.originPid = proto.pid(); t.originUid = proto.uid(); Loading @@ -251,7 +294,7 @@ TransactionState TransactionProtoParser::fromProto( t.states.reserve(static_cast<size_t>(layerCount)); for (int i = 0; i < layerCount; i++) { ComposerState s; s.state = std::move(fromProto(proto.layer_changes(i), getLayerHandle)); fromProto(proto.layer_changes(i), getLayerHandle, s.state); t.states.add(s); } Loading @@ -263,88 +306,116 @@ TransactionState TransactionProtoParser::fromProto( return t; } layer_state_t TransactionProtoParser::fromProto( const proto::LayerState& proto, std::function<sp<IBinder>(int32_t)> getLayerHandle) { layer_state_t layer; void TransactionProtoParser::fromProto(const proto::LayerCreationArgs& proto, TracingLayerCreationArgs& outArgs) { outArgs.layerId = proto.layer_id(); outArgs.name = proto.name(); outArgs.flags = proto.flags(); outArgs.parentId = proto.parent_id(); } void TransactionProtoParser::fromProto(const proto::LayerState& proto, LayerIdToHandleFn getLayerHandle, TracingLayerState& outState) { fromProto(proto, getLayerHandle, static_cast<layer_state_t&>(outState)); if (proto.what() & layer_state_t::eReparent) { outState.parentId = proto.parent_id(); } if (proto.what() & layer_state_t::eRelativeLayerChanged) { outState.relativeParentId = proto.relative_parent_id(); } if (proto.what() & layer_state_t::eInputInfoChanged) { outState.inputCropId = proto.window_info_handle().crop_layer_id(); } if (proto.what() & layer_state_t::eBufferChanged) { const proto::LayerState_BufferData& bufferProto = proto.buffer_data(); outState.bufferId = bufferProto.buffer_id(); outState.bufferWidth = bufferProto.width(); outState.bufferHeight = bufferProto.height(); } if (proto.what() & layer_state_t::eSidebandStreamChanged) { outState.hasSidebandStream = proto.has_sideband_stream(); } } void TransactionProtoParser::fromProto(const proto::LayerState& proto, LayerIdToHandleFn getLayerHandle, layer_state_t& layer) { layer.layerId = proto.layer_id(); layer.what = proto.what(); layer.what |= proto.what(); if (layer.what & layer_state_t::ePositionChanged) { if (getLayerHandle != nullptr) { layer.surface = getLayerHandle(layer.layerId); } if (proto.what() & layer_state_t::ePositionChanged) { layer.x = proto.x(); layer.y = proto.y(); } if (layer.what & layer_state_t::eLayerChanged) { if (proto.what() & layer_state_t::eLayerChanged) { layer.z = proto.z(); } if (layer.what & layer_state_t::eSizeChanged) { if (proto.what() & layer_state_t::eSizeChanged) { layer.w = proto.w(); layer.h = proto.h(); } if (layer.what & layer_state_t::eLayerStackChanged) { if (proto.what() & layer_state_t::eLayerStackChanged) { layer.layerStack.id = proto.layer_stack(); } if (layer.what & layer_state_t::eFlagsChanged) { if (proto.what() & layer_state_t::eFlagsChanged) { layer.flags = proto.flags(); layer.mask = proto.mask(); } if (layer.what & layer_state_t::eMatrixChanged) { if (proto.what() & layer_state_t::eMatrixChanged) { const proto::LayerState_Matrix22& matrixProto = proto.matrix(); layer.matrix.dsdx = matrixProto.dsdx(); layer.matrix.dsdy = matrixProto.dsdy(); layer.matrix.dtdx = matrixProto.dtdx(); layer.matrix.dtdy = matrixProto.dtdy(); } if (layer.what & layer_state_t::eCornerRadiusChanged) { if (proto.what() & layer_state_t::eCornerRadiusChanged) { layer.cornerRadius = proto.corner_radius(); } if (layer.what & layer_state_t::eBackgroundBlurRadiusChanged) { if (proto.what() & layer_state_t::eBackgroundBlurRadiusChanged) { layer.backgroundBlurRadius = proto.background_blur_radius(); } if (layer.what & layer_state_t::eAlphaChanged) { if (proto.what() & layer_state_t::eAlphaChanged) { layer.alpha = proto.alpha(); } if (layer.what & layer_state_t::eColorChanged) { if (proto.what() & layer_state_t::eColorChanged) { const proto::LayerState_Color3& colorProto = proto.color(); layer.color.r = colorProto.r(); layer.color.g = colorProto.g(); layer.color.b = colorProto.b(); } if (layer.what & layer_state_t::eTransparentRegionChanged) { if (proto.what() & layer_state_t::eTransparentRegionChanged) { LayerProtoHelper::readFromProto(proto.transparent_region(), layer.transparentRegion); } if (layer.what & layer_state_t::eTransformChanged) { if (proto.what() & layer_state_t::eTransformChanged) { layer.transform = proto.transform(); } if (layer.what & layer_state_t::eTransformToDisplayInverseChanged) { if (proto.what() & layer_state_t::eTransformToDisplayInverseChanged) { layer.transformToDisplayInverse = proto.transform_to_display_inverse(); } if (layer.what & layer_state_t::eCropChanged) { if (proto.what() & layer_state_t::eCropChanged) { LayerProtoHelper::readFromProto(proto.crop(), layer.crop); } if (layer.what & layer_state_t::eBufferChanged) { if (proto.what() & layer_state_t::eBufferChanged) { const proto::LayerState_BufferData& bufferProto = proto.buffer_data(); layer.bufferData.buffer = new GraphicBuffer(bufferProto.width(), bufferProto.height(), HAL_PIXEL_FORMAT_RGBA_8888, 1, 0); layer.bufferData.frameNumber = bufferProto.frame_number(); layer.bufferData.flags = Flags<BufferData::BufferDataChange>(bufferProto.flags()); layer.bufferData.cachedBuffer.id = bufferProto.cached_buffer_id(); } if (layer.what & layer_state_t::eSidebandStreamChanged) { native_handle_t* handle = native_handle_create(0, 0); layer.sidebandStream = proto.has_sideband_stream() ? NativeHandle::create(handle, true) : nullptr; } if (layer.what & layer_state_t::eApiChanged) { if (proto.what() & layer_state_t::eApiChanged) { layer.api = proto.api(); } if (layer.what & layer_state_t::eColorTransformChanged) { if (proto.what() & layer_state_t::eColorTransformChanged) { LayerProtoHelper::readFromProto(proto.color_transform(), layer.colorTransform); } if (layer.what & layer_state_t::eBlurRegionsChanged) { if (proto.what() & layer_state_t::eBlurRegionsChanged) { layer.blurRegions.reserve(static_cast<size_t>(proto.blur_regions_size())); for (int i = 0; i < proto.blur_regions_size(); i++) { android::BlurRegion region; Loading @@ -353,20 +424,20 @@ layer_state_t TransactionProtoParser::fromProto( } } if (layer.what & layer_state_t::eReparent) { if ((proto.what() & layer_state_t::eReparent) && (getLayerHandle != nullptr)) { int32_t layerId = proto.parent_id(); layer.parentSurfaceControlForChild = new SurfaceControl(SurfaceComposerClient::getDefault(), getLayerHandle(layerId), nullptr, layerId); } if (layer.what & layer_state_t::eRelativeLayerChanged) { if ((proto.what() & layer_state_t::eRelativeLayerChanged) && (getLayerHandle != nullptr)) { int32_t layerId = proto.relative_parent_id(); layer.relativeLayerSurfaceControl = new SurfaceControl(SurfaceComposerClient::getDefault(), getLayerHandle(layerId), nullptr, layerId); } if ((layer.what & layer_state_t::eInputInfoChanged) && proto.has_window_info_handle()) { if ((proto.what() & layer_state_t::eInputInfoChanged) && proto.has_window_info_handle()) { gui::WindowInfo inputInfo; const proto::LayerState_WindowInfo& windowInfoProto = proto.window_info_handle(); Loading @@ -385,10 +456,12 @@ layer_state_t TransactionProtoParser::fromProto( inputInfo.replaceTouchableRegionWithCrop = windowInfoProto.replace_touchable_region_with_crop(); int32_t layerId = windowInfoProto.crop_layer_id(); if (getLayerHandle != nullptr) { inputInfo.touchableRegionCropHandle = getLayerHandle(layerId); } layer.windowInfoHandle = sp<gui::WindowInfoHandle>::make(inputInfo); } if (layer.what & layer_state_t::eBackgroundColorChanged) { if (proto.what() & layer_state_t::eBackgroundColorChanged) { layer.bgColorAlpha = proto.bg_color_alpha(); layer.bgColorDataspace = static_cast<ui::Dataspace>(proto.bg_color_dataspace()); const proto::LayerState_Color3& colorProto = proto.color(); Loading @@ -396,44 +469,43 @@ layer_state_t TransactionProtoParser::fromProto( layer.color.g = colorProto.g(); layer.color.b = colorProto.b(); } if (layer.what & layer_state_t::eColorSpaceAgnosticChanged) { if (proto.what() & layer_state_t::eColorSpaceAgnosticChanged) { layer.colorSpaceAgnostic = proto.color_space_agnostic(); } if (layer.what & layer_state_t::eShadowRadiusChanged) { if (proto.what() & layer_state_t::eShadowRadiusChanged) { layer.shadowRadius = proto.shadow_radius(); } if (layer.what & layer_state_t::eFrameRateSelectionPriority) { if (proto.what() & layer_state_t::eFrameRateSelectionPriority) { layer.frameRateSelectionPriority = proto.frame_rate_selection_priority(); } if (layer.what & layer_state_t::eFrameRateChanged) { if (proto.what() & layer_state_t::eFrameRateChanged) { layer.frameRate = proto.frame_rate(); layer.frameRateCompatibility = static_cast<int8_t>(proto.frame_rate_compatibility()); layer.changeFrameRateStrategy = static_cast<int8_t>(proto.change_frame_rate_strategy()); } if (layer.what & layer_state_t::eFixedTransformHintChanged) { if (proto.what() & layer_state_t::eFixedTransformHintChanged) { layer.fixedTransformHint = static_cast<ui::Transform::RotationFlags>(proto.fixed_transform_hint()); } if (layer.what & layer_state_t::eAutoRefreshChanged) { if (proto.what() & layer_state_t::eAutoRefreshChanged) { layer.autoRefresh = proto.auto_refresh(); } if (layer.what & layer_state_t::eTrustedOverlayChanged) { if (proto.what() & layer_state_t::eTrustedOverlayChanged) { layer.isTrustedOverlay = proto.is_trusted_overlay(); } if (layer.what & layer_state_t::eBufferCropChanged) { if (proto.what() & layer_state_t::eBufferCropChanged) { LayerProtoHelper::readFromProto(proto.buffer_crop(), layer.bufferCrop); } if (layer.what & layer_state_t::eDestinationFrameChanged) { if (proto.what() & layer_state_t::eDestinationFrameChanged) { LayerProtoHelper::readFromProto(proto.destination_frame(), layer.destinationFrame); } if (layer.what & layer_state_t::eDropInputModeChanged) { if (proto.what() & layer_state_t::eDropInputModeChanged) { layer.dropInputMode = static_cast<gui::DropInputMode>(proto.drop_input_mode()); } return layer; } DisplayState TransactionProtoParser::fromProto( const proto::DisplayState& proto, std::function<sp<IBinder>(int32_t)> getDisplayHandle) { DisplayState TransactionProtoParser::fromProto(const proto::DisplayState& proto, DisplayIdToHandleFn getDisplayHandle) { DisplayState display; display.what = proto.what(); display.token = getDisplayHandle(proto.id()); Loading services/surfaceflinger/Tracing/TransactionProtoParser.h +41 −12 Original line number Diff line number Diff line Loading @@ -21,24 +21,53 @@ #include "TransactionState.h" namespace android::surfaceflinger { struct TracingLayerCreationArgs { int32_t layerId; std::string name; uint32_t flags; int32_t parentId; }; struct TracingLayerState : layer_state_t { uint64_t bufferId; uint32_t bufferHeight; uint32_t bufferWidth; bool hasSidebandStream; int32_t parentId; int32_t relativeParentId; int32_t inputCropId; std::string name; uint32_t layerCreationFlags; }; class TransactionProtoParser { public: typedef std::function<sp<IBinder>(int32_t)> LayerIdToHandleFn; typedef std::function<sp<IBinder>(int32_t)> DisplayIdToHandleFn; typedef std::function<int32_t(const sp<IBinder>&)> LayerHandleToIdFn; typedef std::function<int32_t(const sp<IBinder>&)> DisplayHandleToIdFn; static proto::TransactionState toProto(const TransactionState&, LayerHandleToIdFn getLayerIdFn, DisplayHandleToIdFn getDisplayIdFn); static proto::TransactionState toProto( const TransactionState&, std::function<int32_t(const sp<IBinder>&)> getLayerIdFn, std::function<int32_t(const sp<IBinder>&)> getDisplayIdFn); std::vector<std::pair<int32_t /* layerId */, TracingLayerState>>); static proto::LayerCreationArgs toProto(const TracingLayerCreationArgs& args); static TransactionState fromProto(const proto::TransactionState&, std::function<sp<IBinder>(int32_t)> getLayerHandleFn, std::function<sp<IBinder>(int32_t)> getDisplayHandleFn); LayerIdToHandleFn getLayerHandleFn, DisplayIdToHandleFn getDisplayHandleFn); static void fromProto(const proto::LayerState&, LayerIdToHandleFn getLayerHandleFn, TracingLayerState& outState); static void fromProto(const proto::LayerCreationArgs&, TracingLayerCreationArgs& outArgs); private: static proto::LayerState toProto(const layer_state_t&, std::function<int32_t(const sp<IBinder>&)> getLayerId); static proto::DisplayState toProto(const DisplayState&, std::function<int32_t(const sp<IBinder>&)> getDisplayId); static layer_state_t fromProto(const proto::LayerState&, std::function<sp<IBinder>(int32_t)> getLayerHandle); static DisplayState fromProto(const proto::DisplayState&, std::function<sp<IBinder>(int32_t)> getDisplayHandle); static proto::LayerState toProto(const layer_state_t&, LayerHandleToIdFn getLayerId); static proto::DisplayState toProto(const DisplayState&, DisplayHandleToIdFn getDisplayId); static void fromProto(const proto::LayerState&, LayerIdToHandleFn getLayerHandle, layer_state_t& out); static DisplayState fromProto(const proto::DisplayState&, DisplayIdToHandleFn getDisplayHandle); }; } // namespace android::surfaceflinger No newline at end of file services/surfaceflinger/layerproto/transactions.proto +63 −56 Original line number Diff line number Diff line Loading @@ -39,21 +39,28 @@ message TransactionTraceFile { } message TransactionTraceEntry { int64 elapsed_time = 1; int64 elapsed_realtime_nanos = 1; int64 vsync_id = 2; repeated TransactionState transactions = 3; repeated LayerCreationArgs new_layers = 4; repeated DisplayState new_displays = 5; } message LayerCreationArgs { int32 layer_id = 1; string name = 2; uint32 flags = 3; int32 parent_id = 4; } message TransactionState { string tag = 2; int32 pid = 3; int32 uid = 4; int64 vsync_id = 5; int32 input_event_id = 6; int64 post_time = 7; repeated LayerState layer_changes = 9; repeated DisplayState new_displays = 10; repeated DisplayState display_changes = 11; int32 pid = 1; int32 uid = 2; int64 vsync_id = 3; int32 input_event_id = 4; int64 post_time = 5; repeated LayerState layer_changes = 6; repeated DisplayState display_changes = 7; } // Keep insync with layer_state_t Loading Loading @@ -130,8 +137,8 @@ message LayerState { eLayerSecure = 0x80; eEnableBackpressure = 0x100; }; uint32 flags = 10; uint32 mask = 11; uint32 flags = 9; uint32 mask = 10; message Matrix22 { float dsdx = 1; Loading @@ -139,29 +146,29 @@ message LayerState { float dtdy = 3; float dsdy = 4; }; Matrix22 matrix = 12; float corner_radius = 13; uint32 background_blur_radius = 14; int32 parent_id = 15; int32 relative_parent_id = 16; Matrix22 matrix = 11; float corner_radius = 12; uint32 background_blur_radius = 13; int32 parent_id = 14; int32 relative_parent_id = 15; float alpha = 50; float alpha = 16; message Color3 { float r = 1; float g = 2; float b = 3; } Color3 color = 18; RegionProto transparent_region = 19; uint32 transform = 20; bool transform_to_display_inverse = 21; RectProto crop = 49; Color3 color = 17; RegionProto transparent_region = 18; uint32 transform = 19; bool transform_to_display_inverse = 20; RectProto crop = 21; message BufferData { uint64 buffer_id = 1; uint32 width = 2; uint32 height = 3; uint64 frame_number = 5; uint64 frame_number = 4; enum BufferDataChange { BufferDataChangeNone = 0; Loading @@ -169,14 +176,14 @@ message LayerState { frameNumberChanged = 0x02; cachedBufferChanged = 0x04; } uint32 flags = 6; uint64 cached_buffer_id = 7; uint32 flags = 5; uint64 cached_buffer_id = 6; } BufferData buffer_data = 23; int32 api = 24; bool has_sideband_stream = 25; ColorTransformProto color_transform = 26; repeated BlurRegion blur_regions = 27; BufferData buffer_data = 22; int32 api = 23; bool has_sideband_stream = 24; ColorTransformProto color_transform = 25; repeated BlurRegion blur_regions = 26; message Transform { float dsdx = 1; Loading @@ -189,38 +196,38 @@ message LayerState { message WindowInfo { uint32 layout_params_flags = 1; int32 layout_params_type = 2; RegionProto touchable_region = 4; int32 surface_inset = 5; bool focusable = 8; bool has_wallpaper = 9; float global_scale_factor = 10; int32 crop_layer_id = 13; bool replace_touchable_region_with_crop = 14; RectProto touchable_region_crop = 15; Transform transform = 16; RegionProto touchable_region = 3; int32 surface_inset = 4; bool focusable = 5; bool has_wallpaper = 6; float global_scale_factor = 7; int32 crop_layer_id = 8; bool replace_touchable_region_with_crop = 9; RectProto touchable_region_crop = 10; Transform transform = 11; } WindowInfo window_info_handle = 28; float bg_color_alpha = 31; int32 bg_color_dataspace = 32; bool color_space_agnostic = 33; float shadow_radius = 34; int32 frame_rate_selection_priority = 35; float frame_rate = 36; int32 frame_rate_compatibility = 37; int32 change_frame_rate_strategy = 38; uint32 fixed_transform_hint = 39; uint64 frame_number = 40; bool auto_refresh = 41; bool is_trusted_overlay = 42; RectProto buffer_crop = 44; RectProto destination_frame = 45; WindowInfo window_info_handle = 27; float bg_color_alpha = 28; int32 bg_color_dataspace = 29; bool color_space_agnostic = 30; float shadow_radius = 31; int32 frame_rate_selection_priority = 32; float frame_rate = 33; int32 frame_rate_compatibility = 34; int32 change_frame_rate_strategy = 35; uint32 fixed_transform_hint = 36; uint64 frame_number = 37; bool auto_refresh = 38; bool is_trusted_overlay = 39; RectProto buffer_crop = 40; RectProto destination_frame = 41; enum DropInputMode { NONE = 0; ALL = 1; OBSCURED = 2; }; DropInputMode drop_input_mode = 48; DropInputMode drop_input_mode = 42; } message DisplayState { Loading services/surfaceflinger/tests/unittests/TransactionProtoParserTest.cpp +4 −4 File changed.Preview size limit exceeded, changes collapsed. Show changes Loading
services/surfaceflinger/Tracing/TransactionProtoParser.cpp +136 −64 Original line number Diff line number Diff line Loading @@ -22,9 +22,9 @@ namespace android::surfaceflinger { proto::TransactionState TransactionProtoParser::toProto( const TransactionState& t, std::function<int32_t(const sp<IBinder>&)> getLayerId, std::function<int32_t(const sp<IBinder>&)> getDisplayId) { proto::TransactionState TransactionProtoParser::toProto(const TransactionState& t, LayerHandleToIdFn getLayerId, DisplayHandleToIdFn getDisplayId) { proto::TransactionState proto; proto.set_pid(t.originPid); proto.set_uid(t.originUid); Loading @@ -42,10 +42,38 @@ proto::TransactionState TransactionProtoParser::toProto( return proto; } proto::LayerState TransactionProtoParser::toProto( const layer_state_t& layer, std::function<int32_t(const sp<IBinder>&)> getLayerId) { proto::TransactionState TransactionProtoParser::toProto( std::vector<std::pair<int32_t /* layerId */, TracingLayerState>> states) { proto::TransactionState proto; for (auto& [layerId, state] : states) { proto::LayerState layerProto = toProto(state, nullptr); if (layerProto.has_buffer_data()) { proto::LayerState_BufferData* bufferProto = layerProto.mutable_buffer_data(); bufferProto->set_buffer_id(state.bufferId); bufferProto->set_width(state.bufferWidth); bufferProto->set_height(state.bufferHeight); } layerProto.set_has_sideband_stream(state.hasSidebandStream); layerProto.set_layer_id(state.layerId); layerProto.set_parent_id(state.parentId); layerProto.set_relative_parent_id(state.relativeParentId); if (layerProto.has_window_info_handle()) { layerProto.mutable_window_info_handle()->set_crop_layer_id(state.inputCropId); } proto.mutable_layer_changes()->Add(std::move(layerProto)); } return proto; } proto::LayerState TransactionProtoParser::toProto(const layer_state_t& layer, LayerHandleToIdFn getLayerId) { proto::LayerState proto; if (getLayerId != nullptr) { proto.set_layer_id(getLayerId(layer.surface)); } else { proto.set_layer_id(layer.layerId); } proto.set_what(layer.what); if (layer.what & layer_state_t::ePositionChanged) { Loading Loading @@ -130,13 +158,13 @@ proto::LayerState TransactionProtoParser::toProto( } } if (layer.what & layer_state_t::eReparent) { if ((layer.what & layer_state_t::eReparent) && getLayerId != nullptr) { int32_t layerId = layer.parentSurfaceControlForChild ? getLayerId(layer.parentSurfaceControlForChild->getHandle()) : -1; proto.set_parent_id(layerId); } if (layer.what & layer_state_t::eRelativeLayerChanged) { if ((layer.what & layer_state_t::eRelativeLayerChanged) && getLayerId != nullptr) { int32_t layerId = layer.relativeLayerSurfaceControl ? getLayerId(layer.relativeLayerSurfaceControl->getHandle()) : -1; Loading Loading @@ -164,8 +192,12 @@ proto::LayerState TransactionProtoParser::toProto( transformProto->set_ty(inputInfo->transform.ty()); windowInfoProto->set_replace_touchable_region_with_crop( inputInfo->replaceTouchableRegionWithCrop); if (getLayerId != nullptr) { windowInfoProto->set_crop_layer_id( getLayerId(inputInfo->touchableRegionCropHandle.promote())); } else { windowInfoProto->set_crop_layer_id(-1); } } } if (layer.what & layer_state_t::eBackgroundColorChanged) { Loading Loading @@ -212,11 +244,13 @@ proto::LayerState TransactionProtoParser::toProto( return proto; } proto::DisplayState TransactionProtoParser::toProto( const DisplayState& display, std::function<int32_t(const sp<IBinder>&)> getDisplayId) { proto::DisplayState TransactionProtoParser::toProto(const DisplayState& display, DisplayHandleToIdFn getDisplayId) { proto::DisplayState proto; proto.set_what(display.what); if (getDisplayId != nullptr) { proto.set_id(getDisplayId(display.token)); } if (display.what & DisplayState::eLayerStackChanged) { proto.set_layer_stack(display.layerStack.id); Loading @@ -238,9 +272,18 @@ proto::DisplayState TransactionProtoParser::toProto( return proto; } TransactionState TransactionProtoParser::fromProto( const proto::TransactionState& proto, std::function<sp<IBinder>(int32_t)> getLayerHandle, std::function<sp<IBinder>(int32_t)> getDisplayHandle) { proto::LayerCreationArgs TransactionProtoParser::toProto(const TracingLayerCreationArgs& args) { proto::LayerCreationArgs proto; proto.set_layer_id(args.layerId); proto.set_name(args.name); proto.set_flags(args.flags); proto.set_parent_id(args.parentId); return proto; } TransactionState TransactionProtoParser::fromProto(const proto::TransactionState& proto, LayerIdToHandleFn getLayerHandle, DisplayIdToHandleFn getDisplayHandle) { TransactionState t; t.originPid = proto.pid(); t.originUid = proto.uid(); Loading @@ -251,7 +294,7 @@ TransactionState TransactionProtoParser::fromProto( t.states.reserve(static_cast<size_t>(layerCount)); for (int i = 0; i < layerCount; i++) { ComposerState s; s.state = std::move(fromProto(proto.layer_changes(i), getLayerHandle)); fromProto(proto.layer_changes(i), getLayerHandle, s.state); t.states.add(s); } Loading @@ -263,88 +306,116 @@ TransactionState TransactionProtoParser::fromProto( return t; } layer_state_t TransactionProtoParser::fromProto( const proto::LayerState& proto, std::function<sp<IBinder>(int32_t)> getLayerHandle) { layer_state_t layer; void TransactionProtoParser::fromProto(const proto::LayerCreationArgs& proto, TracingLayerCreationArgs& outArgs) { outArgs.layerId = proto.layer_id(); outArgs.name = proto.name(); outArgs.flags = proto.flags(); outArgs.parentId = proto.parent_id(); } void TransactionProtoParser::fromProto(const proto::LayerState& proto, LayerIdToHandleFn getLayerHandle, TracingLayerState& outState) { fromProto(proto, getLayerHandle, static_cast<layer_state_t&>(outState)); if (proto.what() & layer_state_t::eReparent) { outState.parentId = proto.parent_id(); } if (proto.what() & layer_state_t::eRelativeLayerChanged) { outState.relativeParentId = proto.relative_parent_id(); } if (proto.what() & layer_state_t::eInputInfoChanged) { outState.inputCropId = proto.window_info_handle().crop_layer_id(); } if (proto.what() & layer_state_t::eBufferChanged) { const proto::LayerState_BufferData& bufferProto = proto.buffer_data(); outState.bufferId = bufferProto.buffer_id(); outState.bufferWidth = bufferProto.width(); outState.bufferHeight = bufferProto.height(); } if (proto.what() & layer_state_t::eSidebandStreamChanged) { outState.hasSidebandStream = proto.has_sideband_stream(); } } void TransactionProtoParser::fromProto(const proto::LayerState& proto, LayerIdToHandleFn getLayerHandle, layer_state_t& layer) { layer.layerId = proto.layer_id(); layer.what = proto.what(); layer.what |= proto.what(); if (layer.what & layer_state_t::ePositionChanged) { if (getLayerHandle != nullptr) { layer.surface = getLayerHandle(layer.layerId); } if (proto.what() & layer_state_t::ePositionChanged) { layer.x = proto.x(); layer.y = proto.y(); } if (layer.what & layer_state_t::eLayerChanged) { if (proto.what() & layer_state_t::eLayerChanged) { layer.z = proto.z(); } if (layer.what & layer_state_t::eSizeChanged) { if (proto.what() & layer_state_t::eSizeChanged) { layer.w = proto.w(); layer.h = proto.h(); } if (layer.what & layer_state_t::eLayerStackChanged) { if (proto.what() & layer_state_t::eLayerStackChanged) { layer.layerStack.id = proto.layer_stack(); } if (layer.what & layer_state_t::eFlagsChanged) { if (proto.what() & layer_state_t::eFlagsChanged) { layer.flags = proto.flags(); layer.mask = proto.mask(); } if (layer.what & layer_state_t::eMatrixChanged) { if (proto.what() & layer_state_t::eMatrixChanged) { const proto::LayerState_Matrix22& matrixProto = proto.matrix(); layer.matrix.dsdx = matrixProto.dsdx(); layer.matrix.dsdy = matrixProto.dsdy(); layer.matrix.dtdx = matrixProto.dtdx(); layer.matrix.dtdy = matrixProto.dtdy(); } if (layer.what & layer_state_t::eCornerRadiusChanged) { if (proto.what() & layer_state_t::eCornerRadiusChanged) { layer.cornerRadius = proto.corner_radius(); } if (layer.what & layer_state_t::eBackgroundBlurRadiusChanged) { if (proto.what() & layer_state_t::eBackgroundBlurRadiusChanged) { layer.backgroundBlurRadius = proto.background_blur_radius(); } if (layer.what & layer_state_t::eAlphaChanged) { if (proto.what() & layer_state_t::eAlphaChanged) { layer.alpha = proto.alpha(); } if (layer.what & layer_state_t::eColorChanged) { if (proto.what() & layer_state_t::eColorChanged) { const proto::LayerState_Color3& colorProto = proto.color(); layer.color.r = colorProto.r(); layer.color.g = colorProto.g(); layer.color.b = colorProto.b(); } if (layer.what & layer_state_t::eTransparentRegionChanged) { if (proto.what() & layer_state_t::eTransparentRegionChanged) { LayerProtoHelper::readFromProto(proto.transparent_region(), layer.transparentRegion); } if (layer.what & layer_state_t::eTransformChanged) { if (proto.what() & layer_state_t::eTransformChanged) { layer.transform = proto.transform(); } if (layer.what & layer_state_t::eTransformToDisplayInverseChanged) { if (proto.what() & layer_state_t::eTransformToDisplayInverseChanged) { layer.transformToDisplayInverse = proto.transform_to_display_inverse(); } if (layer.what & layer_state_t::eCropChanged) { if (proto.what() & layer_state_t::eCropChanged) { LayerProtoHelper::readFromProto(proto.crop(), layer.crop); } if (layer.what & layer_state_t::eBufferChanged) { if (proto.what() & layer_state_t::eBufferChanged) { const proto::LayerState_BufferData& bufferProto = proto.buffer_data(); layer.bufferData.buffer = new GraphicBuffer(bufferProto.width(), bufferProto.height(), HAL_PIXEL_FORMAT_RGBA_8888, 1, 0); layer.bufferData.frameNumber = bufferProto.frame_number(); layer.bufferData.flags = Flags<BufferData::BufferDataChange>(bufferProto.flags()); layer.bufferData.cachedBuffer.id = bufferProto.cached_buffer_id(); } if (layer.what & layer_state_t::eSidebandStreamChanged) { native_handle_t* handle = native_handle_create(0, 0); layer.sidebandStream = proto.has_sideband_stream() ? NativeHandle::create(handle, true) : nullptr; } if (layer.what & layer_state_t::eApiChanged) { if (proto.what() & layer_state_t::eApiChanged) { layer.api = proto.api(); } if (layer.what & layer_state_t::eColorTransformChanged) { if (proto.what() & layer_state_t::eColorTransformChanged) { LayerProtoHelper::readFromProto(proto.color_transform(), layer.colorTransform); } if (layer.what & layer_state_t::eBlurRegionsChanged) { if (proto.what() & layer_state_t::eBlurRegionsChanged) { layer.blurRegions.reserve(static_cast<size_t>(proto.blur_regions_size())); for (int i = 0; i < proto.blur_regions_size(); i++) { android::BlurRegion region; Loading @@ -353,20 +424,20 @@ layer_state_t TransactionProtoParser::fromProto( } } if (layer.what & layer_state_t::eReparent) { if ((proto.what() & layer_state_t::eReparent) && (getLayerHandle != nullptr)) { int32_t layerId = proto.parent_id(); layer.parentSurfaceControlForChild = new SurfaceControl(SurfaceComposerClient::getDefault(), getLayerHandle(layerId), nullptr, layerId); } if (layer.what & layer_state_t::eRelativeLayerChanged) { if ((proto.what() & layer_state_t::eRelativeLayerChanged) && (getLayerHandle != nullptr)) { int32_t layerId = proto.relative_parent_id(); layer.relativeLayerSurfaceControl = new SurfaceControl(SurfaceComposerClient::getDefault(), getLayerHandle(layerId), nullptr, layerId); } if ((layer.what & layer_state_t::eInputInfoChanged) && proto.has_window_info_handle()) { if ((proto.what() & layer_state_t::eInputInfoChanged) && proto.has_window_info_handle()) { gui::WindowInfo inputInfo; const proto::LayerState_WindowInfo& windowInfoProto = proto.window_info_handle(); Loading @@ -385,10 +456,12 @@ layer_state_t TransactionProtoParser::fromProto( inputInfo.replaceTouchableRegionWithCrop = windowInfoProto.replace_touchable_region_with_crop(); int32_t layerId = windowInfoProto.crop_layer_id(); if (getLayerHandle != nullptr) { inputInfo.touchableRegionCropHandle = getLayerHandle(layerId); } layer.windowInfoHandle = sp<gui::WindowInfoHandle>::make(inputInfo); } if (layer.what & layer_state_t::eBackgroundColorChanged) { if (proto.what() & layer_state_t::eBackgroundColorChanged) { layer.bgColorAlpha = proto.bg_color_alpha(); layer.bgColorDataspace = static_cast<ui::Dataspace>(proto.bg_color_dataspace()); const proto::LayerState_Color3& colorProto = proto.color(); Loading @@ -396,44 +469,43 @@ layer_state_t TransactionProtoParser::fromProto( layer.color.g = colorProto.g(); layer.color.b = colorProto.b(); } if (layer.what & layer_state_t::eColorSpaceAgnosticChanged) { if (proto.what() & layer_state_t::eColorSpaceAgnosticChanged) { layer.colorSpaceAgnostic = proto.color_space_agnostic(); } if (layer.what & layer_state_t::eShadowRadiusChanged) { if (proto.what() & layer_state_t::eShadowRadiusChanged) { layer.shadowRadius = proto.shadow_radius(); } if (layer.what & layer_state_t::eFrameRateSelectionPriority) { if (proto.what() & layer_state_t::eFrameRateSelectionPriority) { layer.frameRateSelectionPriority = proto.frame_rate_selection_priority(); } if (layer.what & layer_state_t::eFrameRateChanged) { if (proto.what() & layer_state_t::eFrameRateChanged) { layer.frameRate = proto.frame_rate(); layer.frameRateCompatibility = static_cast<int8_t>(proto.frame_rate_compatibility()); layer.changeFrameRateStrategy = static_cast<int8_t>(proto.change_frame_rate_strategy()); } if (layer.what & layer_state_t::eFixedTransformHintChanged) { if (proto.what() & layer_state_t::eFixedTransformHintChanged) { layer.fixedTransformHint = static_cast<ui::Transform::RotationFlags>(proto.fixed_transform_hint()); } if (layer.what & layer_state_t::eAutoRefreshChanged) { if (proto.what() & layer_state_t::eAutoRefreshChanged) { layer.autoRefresh = proto.auto_refresh(); } if (layer.what & layer_state_t::eTrustedOverlayChanged) { if (proto.what() & layer_state_t::eTrustedOverlayChanged) { layer.isTrustedOverlay = proto.is_trusted_overlay(); } if (layer.what & layer_state_t::eBufferCropChanged) { if (proto.what() & layer_state_t::eBufferCropChanged) { LayerProtoHelper::readFromProto(proto.buffer_crop(), layer.bufferCrop); } if (layer.what & layer_state_t::eDestinationFrameChanged) { if (proto.what() & layer_state_t::eDestinationFrameChanged) { LayerProtoHelper::readFromProto(proto.destination_frame(), layer.destinationFrame); } if (layer.what & layer_state_t::eDropInputModeChanged) { if (proto.what() & layer_state_t::eDropInputModeChanged) { layer.dropInputMode = static_cast<gui::DropInputMode>(proto.drop_input_mode()); } return layer; } DisplayState TransactionProtoParser::fromProto( const proto::DisplayState& proto, std::function<sp<IBinder>(int32_t)> getDisplayHandle) { DisplayState TransactionProtoParser::fromProto(const proto::DisplayState& proto, DisplayIdToHandleFn getDisplayHandle) { DisplayState display; display.what = proto.what(); display.token = getDisplayHandle(proto.id()); Loading
services/surfaceflinger/Tracing/TransactionProtoParser.h +41 −12 Original line number Diff line number Diff line Loading @@ -21,24 +21,53 @@ #include "TransactionState.h" namespace android::surfaceflinger { struct TracingLayerCreationArgs { int32_t layerId; std::string name; uint32_t flags; int32_t parentId; }; struct TracingLayerState : layer_state_t { uint64_t bufferId; uint32_t bufferHeight; uint32_t bufferWidth; bool hasSidebandStream; int32_t parentId; int32_t relativeParentId; int32_t inputCropId; std::string name; uint32_t layerCreationFlags; }; class TransactionProtoParser { public: typedef std::function<sp<IBinder>(int32_t)> LayerIdToHandleFn; typedef std::function<sp<IBinder>(int32_t)> DisplayIdToHandleFn; typedef std::function<int32_t(const sp<IBinder>&)> LayerHandleToIdFn; typedef std::function<int32_t(const sp<IBinder>&)> DisplayHandleToIdFn; static proto::TransactionState toProto(const TransactionState&, LayerHandleToIdFn getLayerIdFn, DisplayHandleToIdFn getDisplayIdFn); static proto::TransactionState toProto( const TransactionState&, std::function<int32_t(const sp<IBinder>&)> getLayerIdFn, std::function<int32_t(const sp<IBinder>&)> getDisplayIdFn); std::vector<std::pair<int32_t /* layerId */, TracingLayerState>>); static proto::LayerCreationArgs toProto(const TracingLayerCreationArgs& args); static TransactionState fromProto(const proto::TransactionState&, std::function<sp<IBinder>(int32_t)> getLayerHandleFn, std::function<sp<IBinder>(int32_t)> getDisplayHandleFn); LayerIdToHandleFn getLayerHandleFn, DisplayIdToHandleFn getDisplayHandleFn); static void fromProto(const proto::LayerState&, LayerIdToHandleFn getLayerHandleFn, TracingLayerState& outState); static void fromProto(const proto::LayerCreationArgs&, TracingLayerCreationArgs& outArgs); private: static proto::LayerState toProto(const layer_state_t&, std::function<int32_t(const sp<IBinder>&)> getLayerId); static proto::DisplayState toProto(const DisplayState&, std::function<int32_t(const sp<IBinder>&)> getDisplayId); static layer_state_t fromProto(const proto::LayerState&, std::function<sp<IBinder>(int32_t)> getLayerHandle); static DisplayState fromProto(const proto::DisplayState&, std::function<sp<IBinder>(int32_t)> getDisplayHandle); static proto::LayerState toProto(const layer_state_t&, LayerHandleToIdFn getLayerId); static proto::DisplayState toProto(const DisplayState&, DisplayHandleToIdFn getDisplayId); static void fromProto(const proto::LayerState&, LayerIdToHandleFn getLayerHandle, layer_state_t& out); static DisplayState fromProto(const proto::DisplayState&, DisplayIdToHandleFn getDisplayHandle); }; } // namespace android::surfaceflinger No newline at end of file
services/surfaceflinger/layerproto/transactions.proto +63 −56 Original line number Diff line number Diff line Loading @@ -39,21 +39,28 @@ message TransactionTraceFile { } message TransactionTraceEntry { int64 elapsed_time = 1; int64 elapsed_realtime_nanos = 1; int64 vsync_id = 2; repeated TransactionState transactions = 3; repeated LayerCreationArgs new_layers = 4; repeated DisplayState new_displays = 5; } message LayerCreationArgs { int32 layer_id = 1; string name = 2; uint32 flags = 3; int32 parent_id = 4; } message TransactionState { string tag = 2; int32 pid = 3; int32 uid = 4; int64 vsync_id = 5; int32 input_event_id = 6; int64 post_time = 7; repeated LayerState layer_changes = 9; repeated DisplayState new_displays = 10; repeated DisplayState display_changes = 11; int32 pid = 1; int32 uid = 2; int64 vsync_id = 3; int32 input_event_id = 4; int64 post_time = 5; repeated LayerState layer_changes = 6; repeated DisplayState display_changes = 7; } // Keep insync with layer_state_t Loading Loading @@ -130,8 +137,8 @@ message LayerState { eLayerSecure = 0x80; eEnableBackpressure = 0x100; }; uint32 flags = 10; uint32 mask = 11; uint32 flags = 9; uint32 mask = 10; message Matrix22 { float dsdx = 1; Loading @@ -139,29 +146,29 @@ message LayerState { float dtdy = 3; float dsdy = 4; }; Matrix22 matrix = 12; float corner_radius = 13; uint32 background_blur_radius = 14; int32 parent_id = 15; int32 relative_parent_id = 16; Matrix22 matrix = 11; float corner_radius = 12; uint32 background_blur_radius = 13; int32 parent_id = 14; int32 relative_parent_id = 15; float alpha = 50; float alpha = 16; message Color3 { float r = 1; float g = 2; float b = 3; } Color3 color = 18; RegionProto transparent_region = 19; uint32 transform = 20; bool transform_to_display_inverse = 21; RectProto crop = 49; Color3 color = 17; RegionProto transparent_region = 18; uint32 transform = 19; bool transform_to_display_inverse = 20; RectProto crop = 21; message BufferData { uint64 buffer_id = 1; uint32 width = 2; uint32 height = 3; uint64 frame_number = 5; uint64 frame_number = 4; enum BufferDataChange { BufferDataChangeNone = 0; Loading @@ -169,14 +176,14 @@ message LayerState { frameNumberChanged = 0x02; cachedBufferChanged = 0x04; } uint32 flags = 6; uint64 cached_buffer_id = 7; uint32 flags = 5; uint64 cached_buffer_id = 6; } BufferData buffer_data = 23; int32 api = 24; bool has_sideband_stream = 25; ColorTransformProto color_transform = 26; repeated BlurRegion blur_regions = 27; BufferData buffer_data = 22; int32 api = 23; bool has_sideband_stream = 24; ColorTransformProto color_transform = 25; repeated BlurRegion blur_regions = 26; message Transform { float dsdx = 1; Loading @@ -189,38 +196,38 @@ message LayerState { message WindowInfo { uint32 layout_params_flags = 1; int32 layout_params_type = 2; RegionProto touchable_region = 4; int32 surface_inset = 5; bool focusable = 8; bool has_wallpaper = 9; float global_scale_factor = 10; int32 crop_layer_id = 13; bool replace_touchable_region_with_crop = 14; RectProto touchable_region_crop = 15; Transform transform = 16; RegionProto touchable_region = 3; int32 surface_inset = 4; bool focusable = 5; bool has_wallpaper = 6; float global_scale_factor = 7; int32 crop_layer_id = 8; bool replace_touchable_region_with_crop = 9; RectProto touchable_region_crop = 10; Transform transform = 11; } WindowInfo window_info_handle = 28; float bg_color_alpha = 31; int32 bg_color_dataspace = 32; bool color_space_agnostic = 33; float shadow_radius = 34; int32 frame_rate_selection_priority = 35; float frame_rate = 36; int32 frame_rate_compatibility = 37; int32 change_frame_rate_strategy = 38; uint32 fixed_transform_hint = 39; uint64 frame_number = 40; bool auto_refresh = 41; bool is_trusted_overlay = 42; RectProto buffer_crop = 44; RectProto destination_frame = 45; WindowInfo window_info_handle = 27; float bg_color_alpha = 28; int32 bg_color_dataspace = 29; bool color_space_agnostic = 30; float shadow_radius = 31; int32 frame_rate_selection_priority = 32; float frame_rate = 33; int32 frame_rate_compatibility = 34; int32 change_frame_rate_strategy = 35; uint32 fixed_transform_hint = 36; uint64 frame_number = 37; bool auto_refresh = 38; bool is_trusted_overlay = 39; RectProto buffer_crop = 40; RectProto destination_frame = 41; enum DropInputMode { NONE = 0; ALL = 1; OBSCURED = 2; }; DropInputMode drop_input_mode = 48; DropInputMode drop_input_mode = 42; } message DisplayState { Loading
services/surfaceflinger/tests/unittests/TransactionProtoParserTest.cpp +4 −4 File changed.Preview size limit exceeded, changes collapsed. Show changes