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

Commit 02d89d42 authored by Massimo Carli's avatar Massimo Carli Committed by Android (Google) Code Review
Browse files

Merge "[13/n] Implement MixedLetterboxController" into main

parents f2638c8a 51f207ec
Loading
Loading
Loading
Loading
+52 −0
Original line number Diff line number Diff line
/*
 * Copyright 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.wm.shell.compatui.letterbox

import com.android.wm.shell.dagger.WMSingleton
import javax.inject.Inject

/**
 * Encapsulate the logic related to the use of a single or multiple surfaces when
 * implementing letterbox in shell.
 */
@WMSingleton
class LetterboxControllerStrategy @Inject constructor() {

    // Different letterbox implementation modes.
    enum class LetterboxMode { SINGLE_SURFACE, MULTIPLE_SURFACES }

    @Volatile
    private var currentMode: LetterboxMode = LetterboxMode.SINGLE_SURFACE

    fun configureLetterboxMode() {
        // TODO(b/377875146): Define criteria for switching between [LetterboxMode]s.
        currentMode = if (android.os.SystemProperties.getInt(
                "multi_interface",
                0
            ) == 0
        ) {
            LetterboxMode.SINGLE_SURFACE
        } else {
            LetterboxMode.MULTIPLE_SURFACES
        }
    }

    /**
     * @return The specific mode to use for implementing letterboxing for the given [request].
     */
    fun getLetterboxImplementationMode(): LetterboxMode = currentMode
}
+3 −2
Original line number Diff line number Diff line
@@ -35,7 +35,8 @@ class LetterboxTransitionObserver(
    shellInit: ShellInit,
    private val transitions: Transitions,
    private val letterboxController: LetterboxController,
    private val transitionStateHolder: TransitionStateHolder
    private val transitionStateHolder: TransitionStateHolder,
    private val letterboxModeStrategy: LetterboxControllerStrategy
) : Transitions.TransitionObserver {

    companion object {
@@ -63,7 +64,6 @@ class LetterboxTransitionObserver(
        // We recognise the operation to execute and delegate to the LetterboxController
        // the related operation.
        // TODO(b/377875151): Identify Desktop Windowing Transactions.
        // TODO(b/377857898): Handling multiple surfaces
        // TODO(b/371500295): Handle input events detection.
        for (change in info.changes) {
            change.taskInfo?.let { ti ->
@@ -83,6 +83,7 @@ class LetterboxTransitionObserver(
                    } else {
                        val isTopActivityLetterboxed = ti.appCompatTaskInfo.isTopActivityLetterboxed
                        if (isTopActivityLetterboxed) {
                            letterboxModeStrategy.configureLetterboxMode()
                            createLetterboxSurface(
                                key,
                                startTransaction,
+68 −0
Original line number Diff line number Diff line
/*
 * Copyright 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.wm.shell.compatui.letterbox

import android.graphics.Rect
import android.view.SurfaceControl
import android.view.SurfaceControl.Transaction

/**
 * Creates a [LetterboxController] which is the composition of other two [LetterboxController].
 * It basically invokes the method on both of them.
 */
infix fun LetterboxController.append(other: LetterboxController) = object : LetterboxController {
    override fun createLetterboxSurface(
        key: LetterboxKey,
        transaction: Transaction,
        parentLeash: SurfaceControl
    ) {
        this@append.createLetterboxSurface(key, transaction, parentLeash)
        other.createLetterboxSurface(key, transaction, parentLeash)
    }

    override fun destroyLetterboxSurface(
        key: LetterboxKey,
        transaction: Transaction
    ) {
        this@append.destroyLetterboxSurface(key, transaction)
        other.destroyLetterboxSurface(key, transaction)
    }

    override fun updateLetterboxSurfaceVisibility(
        key: LetterboxKey,
        transaction: Transaction,
        visible: Boolean
    ) {
        this@append.updateLetterboxSurfaceVisibility(key, transaction, visible)
        other.updateLetterboxSurfaceVisibility(key, transaction, visible)
    }

    override fun updateLetterboxSurfaceBounds(
        key: LetterboxKey,
        transaction: Transaction,
        taskBounds: Rect,
        activityBounds: Rect
    ) {
        this@append.updateLetterboxSurfaceBounds(key, transaction, taskBounds, activityBounds)
        other.updateLetterboxSurfaceBounds(key, transaction, taskBounds, activityBounds)
    }

    override fun dump() {
        this@append.dump()
        other.dump()
    }
}
+54 −0
Original line number Diff line number Diff line
/*
 * Copyright 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.wm.shell.compatui.letterbox

import android.view.SurfaceControl
import android.view.SurfaceControl.Transaction
import com.android.wm.shell.compatui.letterbox.LetterboxControllerStrategy.LetterboxMode.MULTIPLE_SURFACES
import com.android.wm.shell.compatui.letterbox.LetterboxControllerStrategy.LetterboxMode.SINGLE_SURFACE
import com.android.wm.shell.dagger.WMSingleton
import javax.inject.Inject

/**
 * [LetterboxController] implementation working as coordinator of other [LetterboxController]
 * implementations.
 */
@WMSingleton
class MixedLetterboxController @Inject constructor(
    private val singleSurfaceController: SingleSurfaceLetterboxController,
    private val multipleSurfaceController: MultiSurfaceLetterboxController,
    private val controllerStrategy: LetterboxControllerStrategy
) : LetterboxController by singleSurfaceController append multipleSurfaceController {

    override fun createLetterboxSurface(
        key: LetterboxKey,
        transaction: Transaction,
        parentLeash: SurfaceControl
    ) {
        when (controllerStrategy.getLetterboxImplementationMode()) {
            SINGLE_SURFACE -> {
                multipleSurfaceController.destroyLetterboxSurface(key, transaction)
                singleSurfaceController.createLetterboxSurface(key, transaction, parentLeash)
            }

            MULTIPLE_SURFACES -> {
                singleSurfaceController.destroyLetterboxSurface(key, transaction)
                multipleSurfaceController.createLetterboxSurface(key, transaction, parentLeash)
            }
        }
    }
}
+6 −4
Original line number Diff line number Diff line
@@ -74,8 +74,9 @@ import com.android.wm.shell.common.split.SplitState;
import com.android.wm.shell.common.transition.TransitionStateHolder;
import com.android.wm.shell.compatui.letterbox.LetterboxCommandHandler;
import com.android.wm.shell.compatui.letterbox.LetterboxController;
import com.android.wm.shell.compatui.letterbox.LetterboxControllerStrategy;
import com.android.wm.shell.compatui.letterbox.LetterboxTransitionObserver;
import com.android.wm.shell.compatui.letterbox.SingleSurfaceLetterboxController;
import com.android.wm.shell.compatui.letterbox.MixedLetterboxController;
import com.android.wm.shell.dagger.back.ShellBackAnimationModule;
import com.android.wm.shell.dagger.pip.PipModule;
import com.android.wm.shell.desktopmode.CloseDesktopTaskTransitionHandler;
@@ -1338,14 +1339,15 @@ public abstract class WMShellModule {
            @NonNull ShellInit shellInit,
            @NonNull Transitions transitions,
            @NonNull LetterboxController letterboxController,
            @NonNull TransitionStateHolder transitionStateHolder
            @NonNull TransitionStateHolder transitionStateHolder,
            @NonNull LetterboxControllerStrategy letterboxControllerStrategy
    ) {
        return new LetterboxTransitionObserver(shellInit, transitions, letterboxController,
                transitionStateHolder);
                transitionStateHolder, letterboxControllerStrategy);
    }

    @WMSingleton
    @Binds
    abstract LetterboxController bindsLetterboxController(
            SingleSurfaceLetterboxController letterboxController);
            MixedLetterboxController letterboxController);
}
Loading