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.graphics.Point 19 import android.tools.common.flicker.subject.layers.LayersTraceSubject 20 import com.android.test.SurfaceViewBufferTestBase.Companion.Transform 21 import junit.framework.Assert.assertEquals 22 import org.junit.Assert 23 import org.junit.Assume.assumeFalse 24 import org.junit.Before 25 import org.junit.Test 26 import org.junit.runner.RunWith 27 import org.junit.runners.Parameterized 28 29 @RunWith(Parameterized::class) 30 class InverseDisplayTransformTests(useBlastAdapter: Boolean) : 31 SurfaceTracingTestBase(useBlastAdapter) { 32 @Before 33 override fun setup() { 34 scenarioRule.getScenario().onActivity { 35 it.rotate90() 36 } 37 instrumentation.waitForIdleSync() 38 super.setup() 39 } 40 41 @Test 42 fun testSetBufferScalingMode_freeze_withInvDisplayTransform() { 43 assumeFalse("Blast does not support buffer rejection with Inv display " + 44 "transform since the only user for this hidden api is camera which does not use" + 45 "fixed scaling mode.", useBlastAdapter) 46 47 val rotatedBufferSize = Point(defaultBufferSize.y, defaultBufferSize.x) 48 val trace = withTrace { activity -> 49 // Inverse display transforms are sticky AND they are only consumed by the sf after 50 // a valid buffer has been acquired. 51 activity.mSurfaceProxy.ANativeWindowSetBuffersTransform(Transform.INVERSE_DISPLAY.value) 52 assertEquals(0, activity.mSurfaceProxy.SurfaceDequeueBuffer(0, 1000 /* ms */)) 53 activity.mSurfaceProxy.SurfaceQueueBuffer(0) 54 55 assertEquals(activity.mSurfaceProxy.waitUntilBufferDisplayed(1, 500 /* ms */), 0) 56 activity.mSurfaceProxy.ANativeWindowSetBuffersGeometry(activity.surface!!, 57 rotatedBufferSize, R8G8B8A8_UNORM) 58 assertEquals(0, activity.mSurfaceProxy.SurfaceDequeueBuffer(0, 1000 /* ms */)) 59 assertEquals(0, activity.mSurfaceProxy.SurfaceDequeueBuffer(1, 1000 /* ms */)) 60 // Change buffer size and set scaling mode to freeze 61 activity.mSurfaceProxy.ANativeWindowSetBuffersGeometry(activity.surface!!, Point(0, 0), 62 R8G8B8A8_UNORM) 63 64 // first dequeued buffer does not have the new size so it should be rejected. 65 activity.mSurfaceProxy.ANativeWindowSetBuffersTransform(Transform.ROT_90.value) 66 activity.mSurfaceProxy.SurfaceQueueBuffer(0) 67 activity.mSurfaceProxy.ANativeWindowSetBuffersTransform(0) 68 activity.mSurfaceProxy.SurfaceQueueBuffer(1) 69 assertEquals(activity.mSurfaceProxy.waitUntilBufferDisplayed(3, 500 /* ms */), 0) 70 } 71 72 // verify buffer size is reset to default buffer size 73 LayersTraceSubject(trace).layer("SurfaceView", 1).hasBufferSize(defaultBufferSize) 74 Assert.assertThrows(AssertionError::class.java) { 75 LayersTraceSubject(trace).layer("SurfaceView", 2) 76 } 77 LayersTraceSubject(trace).layer("SurfaceView", 3).hasBufferSize(rotatedBufferSize) 78 } 79 } 80