• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2024 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.wm.shell.compatui.letterbox
18 
19 import com.android.wm.shell.compatui.letterbox.LetterboxControllerStrategy.LetterboxMode.MULTIPLE_SURFACES
20 import com.android.wm.shell.compatui.letterbox.LetterboxControllerStrategy.LetterboxMode.SINGLE_SURFACE
21 import com.android.wm.shell.dagger.WMSingleton
22 import javax.inject.Inject
23 
24 /**
25  * Encapsulate the logic related to the use of a single or multiple surfaces when
26  * implementing letterbox in shell.
27  */
28 @WMSingleton
29 class LetterboxControllerStrategy @Inject constructor(
30     private val letterboxConfiguration: LetterboxConfiguration
31 ) {
32 
33     // Different letterbox implementation modes.
34     enum class LetterboxMode { SINGLE_SURFACE, MULTIPLE_SURFACES }
35 
36     @Volatile
37     private var currentMode: LetterboxMode = SINGLE_SURFACE
38 
configureLetterboxModenull39     fun configureLetterboxMode() {
40         // TODO(b/377875146): Define criteria for switching between [LetterboxMode]s.
41         // At the moment, we use the presence of rounded corners to understand if to use a single
42         // surface or multiple surfaces for the letterbox areas. This rule will change when
43         // considering transparent activities which won't have rounded corners leading to the
44         // [MULTIPLE_SURFACES] option.
45         // The chosen strategy will depend on performance considerations,
46         // including surface memory usage and the impact of the rounded corners solution.
47         currentMode = if (letterboxConfiguration.isLetterboxActivityCornersRounded()) {
48             SINGLE_SURFACE
49         } else {
50             MULTIPLE_SURFACES
51         }
52     }
53 
54     /**
55      * @return The specific mode to use for implementing letterboxing for the given [request].
56      */
getLetterboxImplementationModenull57     fun getLetterboxImplementationMode(): LetterboxMode = currentMode
58 }
59