1 /* 2 * Copyright (C) 2023 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 android.tools.flicker.subject.layers 18 19 import android.tools.traces.component.IComponentMatcher 20 import android.tools.traces.component.IComponentNameMatcher 21 import android.tools.traces.surfaceflinger.Display 22 import android.tools.traces.surfaceflinger.Layer 23 24 /** Base interface for Layer trace and state assertions */ 25 interface ILayerSubject<LayerSubjectType, RegionSubjectType> { 26 /** Asserts that the current SurfaceFlinger state doesn't contain layers */ isEmptynull27 fun isEmpty(): LayerSubjectType 28 29 /** Asserts that the current SurfaceFlinger state contains layers */ 30 fun isNotEmpty(): LayerSubjectType 31 32 /** 33 * Obtains the region occupied by all layers matching [componentMatcher] 34 * 35 * @param componentMatcher Components to search 36 * @param useCompositionEngineRegionOnly If true, uses only the region calculated from the 37 * Composition Engine (CE) -- visibleRegion in the proto definition. Otherwise, calculates the 38 * visible region when the information is not available from the CE 39 */ 40 fun visibleRegion( 41 componentMatcher: IComponentMatcher? = null, 42 useCompositionEngineRegionOnly: Boolean = true 43 ): RegionSubjectType 44 45 /** 46 * Asserts the state contains a [Layer] matching [componentMatcher]. 47 * 48 * @param componentMatcher Components to search 49 */ 50 fun contains(componentMatcher: IComponentMatcher): LayerSubjectType 51 52 /** 53 * Asserts the state doesn't contain a [Layer] matching [componentMatcher] 54 * 55 * @param componentMatcher Components to search 56 */ 57 fun notContains(componentMatcher: IComponentMatcher): LayerSubjectType 58 59 /** 60 * Asserts that a [Layer] matching [componentMatcher] is visible. 61 * 62 * @param componentMatcher Components to search 63 */ 64 fun isVisible(componentMatcher: IComponentMatcher): LayerSubjectType 65 66 /** 67 * Asserts that a [Layer] matching [componentMatcher] doesn't exist or is invisible. 68 * 69 * @param componentMatcher Components to search 70 */ 71 fun isInvisible(componentMatcher: IComponentMatcher): LayerSubjectType 72 73 /** 74 * Asserts that the entry contains a visible splash screen [Layer] for a [layer] matching 75 * [componentMatcher] 76 * 77 * @param componentMatcher Components to search 78 */ 79 fun isSplashScreenVisibleFor(componentMatcher: IComponentNameMatcher): LayerSubjectType 80 81 /** 82 * Asserts that a [Layer] matching [componentMatcher] has a color set on it. 83 * 84 * @param componentMatcher Components to search 85 */ 86 fun hasColor(componentMatcher: IComponentMatcher): LayerSubjectType 87 88 /** 89 * Asserts that all [Layer]s matching [componentMatcher] have a no color set on them. 90 * 91 * @param componentMatcher Components to search 92 */ 93 fun hasNoColor(componentMatcher: IComponentMatcher): LayerSubjectType 94 95 /** 96 * Asserts that all [Layer]s matching [componentMatcher] have rounded corners. 97 * 98 * @param componentMatcher Components to search 99 */ 100 fun hasRoundedCorners(componentMatcher: IComponentMatcher): LayerSubjectType 101 102 /** 103 * Obtains a [LayerSubject] for the first occurrence of a [Layer] with [Layer.name] containing 104 * [name] in [frameNumber]. 105 * 106 * @return LayerSubject that can be used to make assertions on a single layer matching [name] 107 * and [frameNumber]. 108 */ 109 fun layer(name: String, frameNumber: Long): LayerSubject? 110 111 /** Checks if the state contains at least one [Display] */ 112 fun containsAtLeastOneDisplay(): LayerSubjectType 113 } 114