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

Commit f055241b authored by archisha's avatar archisha
Browse files

Adding a modifier to add perfetto marker for the measure and layout

phases of compose.

Bug: 330122992
Flag: NA
Test: NA
Change-Id: If86590291ee602f7ea20874928edbfa2cf3e53dd
parent 4ac36ca5
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -38,6 +38,7 @@ android_library {
        "androidx.compose.material3_material3-window-size-class",
        "androidx.savedstate_savedstate",
        "androidx.window_window",
        "//frameworks/libs/systemui:tracinglib-platform",
    ],

    kotlincflags: ["-Xjvm-default=all"],
+32 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2024 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.
 */

package com.android.compose.modifiers

import androidx.compose.ui.Modifier
import androidx.compose.ui.layout.layout
import androidx.compose.ui.unit.IntOffset
import com.android.app.tracing.traceSection

/** Adds perfetto markers for the measure + layout stages. */
inline fun Modifier.measureTracer(crossinline traceNameProducer: () -> String): Modifier {
    return layout { measurable, constraints ->
        traceSection(traceNameProducer) {
            val placeable = measurable.measure(constraints)
            layout(placeable.width, placeable.height) { placeable.placeRelative(IntOffset.Zero) }
        }
    }
}