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