1 /* 2 * Copyright (C) 2020 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 package com.android.test 17 18 import android.app.Instrumentation 19 import android.graphics.Point 20 import android.provider.Settings 21 import android.tools.datatypes.Size 22 import android.tools.flicker.subject.layers.LayerSubject 23 import androidx.test.InstrumentationRegistry 24 import org.junit.After 25 import org.junit.Before 26 import org.junit.Rule 27 import org.junit.rules.TestName 28 import org.junit.runners.Parameterized 29 import kotlin.properties.Delegates 30 31 open class SurfaceViewBufferTestBase(val useBlastAdapter: Boolean) { 32 private var mInitialBlastConfig by Delegates.notNull<Boolean>() 33 34 val instrumentation: Instrumentation 35 get() = InstrumentationRegistry.getInstrumentation() 36 37 @get:Rule 38 var mName = TestName() 39 40 @Before setupnull41 open fun setup() { 42 mInitialBlastConfig = getBlastAdapterSvEnabled() 43 setBlastAdapterSvEnabled(useBlastAdapter) 44 } 45 46 @After teardownnull47 open fun teardown() { 48 setBlastAdapterSvEnabled(mInitialBlastConfig) 49 } 50 getBlastAdapterSvEnablednull51 private fun getBlastAdapterSvEnabled(): Boolean { 52 return Settings.Global.getInt(instrumentation.context.contentResolver, 53 "use_blast_adapter_sv", 0) != 0 54 } 55 setBlastAdapterSvEnablednull56 private fun setBlastAdapterSvEnabled(enable: Boolean) { 57 Settings.Global.putInt(instrumentation.context.contentResolver, "use_blast_adapter_sv", 58 if (enable) 1 else 0) 59 } 60 61 companion object { 62 @JvmStatic 63 @Parameterized.Parameters(name = "blast={0}") datanull64 fun data(): Collection<Array<Any>> { 65 return listOf( 66 arrayOf(false), // First test: submit buffers via bufferqueue 67 arrayOf(true) // Second test: submit buffers via blast adapter 68 ) 69 } 70 71 const val R8G8B8A8_UNORM = 1 72 val defaultBufferSize = Point(640, 480) 73 LayerSubjectnull74 fun LayerSubject.hasBufferSize(point: Point) = hasBufferSize(Size.from(point.x, point.y)) 75 76 fun LayerSubject.hasLayerSize(point: Point) = hasLayerSize(Size.from(point.x, point.y)) 77 78 // system/window.h definitions 79 enum class ScalingMode() { 80 FREEZE, // = 0 81 SCALE_TO_WINDOW, // =1 82 SCALE_CROP, // = 2 83 NO_SCALE_CROP // = 3 84 } 85 86 // system/window.h definitions 87 enum class Transform(val value: Int) { 88 /* flip source image horizontally */ 89 FLIP_H(1), 90 /* flip source image vertically */ 91 FLIP_V(2), 92 /* rotate source image 90 degrees clock-wise, and is applied after TRANSFORM_FLIP_{H|V} */ 93 ROT_90(4), 94 /* rotate source image 180 degrees */ 95 ROT_180(3), 96 /* rotate source image 270 degrees clock-wise */ 97 ROT_270(7), 98 /* transforms source by the inverse transform of the screen it is displayed onto. This 99 * transform is applied last */ 100 INVERSE_DISPLAY(0x08) 101 } 102 } 103 }