• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 androidx.test.InstrumentationRegistry
22 import org.junit.After
23 import org.junit.Before
24 import org.junit.Rule
25 import org.junit.rules.TestName
26 import org.junit.runners.Parameterized
27 import kotlin.properties.Delegates
28 
29 open class SurfaceViewBufferTestBase(val useBlastAdapter: Boolean) {
30     private var mInitialBlastConfig by Delegates.notNull<Boolean>()
31 
32     val instrumentation: Instrumentation
33         get() = InstrumentationRegistry.getInstrumentation()
34 
35     @get:Rule
36     var mName = TestName()
37 
38     @Before
setupnull39     open fun setup() {
40         mInitialBlastConfig = getBlastAdapterSvEnabled()
41         setBlastAdapterSvEnabled(useBlastAdapter)
42     }
43 
44     @After
teardownnull45     open fun teardown() {
46         setBlastAdapterSvEnabled(mInitialBlastConfig)
47     }
48 
getBlastAdapterSvEnablednull49     private fun getBlastAdapterSvEnabled(): Boolean {
50         return Settings.Global.getInt(instrumentation.context.contentResolver,
51                 "use_blast_adapter_sv", 0) != 0
52     }
53 
setBlastAdapterSvEnablednull54     private fun setBlastAdapterSvEnabled(enable: Boolean) {
55         Settings.Global.putInt(instrumentation.context.contentResolver, "use_blast_adapter_sv",
56                 if (enable) 1 else 0)
57     }
58 
59     companion object {
60         @JvmStatic
61         @Parameterized.Parameters(name = "blast={0}")
datanull62         fun data(): Collection<Array<Any>> {
63             return listOf(
64                     arrayOf(false), // First test:  submit buffers via bufferqueue
65                     arrayOf(true)   // Second test: submit buffers via blast adapter
66             )
67         }
68 
69         const val R8G8B8A8_UNORM = 1
70         val defaultBufferSize = Point(640, 480)
71 
72         // system/window.h definitions
73         enum class ScalingMode() {
74             FREEZE, // = 0
75             SCALE_TO_WINDOW, // =1
76             SCALE_CROP, // = 2
77             NO_SCALE_CROP // = 3
78         }
79 
80         // system/window.h definitions
81         enum class Transform(val value: Int) {
82             /* flip source image horizontally */
83             FLIP_H(1),
84             /* flip source image vertically */
85             FLIP_V(2),
86             /* rotate source image 90 degrees clock-wise, and is applied after TRANSFORM_FLIP_{H|V} */
87             ROT_90(4),
88             /* rotate source image 180 degrees */
89             ROT_180(3),
90             /* rotate source image 270 degrees clock-wise */
91             ROT_270(7),
92             /* transforms source by the inverse transform of the screen it is displayed onto. This
93              * transform is applied last */
94             INVERSE_DISPLAY(0x08)
95         }
96     }
97 }