Debian Codegraph @

tests/SurfaceViewBufferTests/src/com/android/test/SharedBufferModeScreenRecordTests.kt

raw
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.Color
19 import android.graphics.Rect
20 import android.os.SystemClock
21 import android.view.cts.surfacevalidator.PixelColor
22 import junit.framework.Assert.assertEquals
23 import org.junit.Assert.assertTrue
24 import org.junit.Test
25 import org.junit.runner.RunWith
26 import org.junit.runners.Parameterized
27
28 @RunWith(Parameterized::class)
29 class SharedBufferModeScreenRecordTests(useBlastAdapter: Boolean) :
30 ScreenRecordTestBase(useBlastAdapter) {
31
32 /** When auto refresh is set, surface flinger will wake up and refresh the display presenting
33 * the latest content in the buffer.
34 */
35 @Test
36 fun testAutoRefresh() {
37 var svBounds = Rect()
38 runOnUiThread {
39 assertEquals(0, it.mSurfaceProxy.NativeWindowSetSharedBufferMode(true))
40 assertEquals(0, it.mSurfaceProxy.NativeWindowSetAutoRefresh(true))
41 assertEquals(0, it.mSurfaceProxy.SurfaceDequeueBuffer(0, 1 /* ms */))
42 it.mSurfaceProxy.SurfaceQueueBuffer(0, false /* freeSlot */)
43 assertEquals(0,
44 it.mSurfaceProxy.waitUntilBufferDisplayed(1, 5000 /* ms */))
45
46 svBounds = Rect(0, 0, it.mSurfaceView!!.width, it.mSurfaceView!!.height)
47 val position = Rect()
48 it.mSurfaceView!!.getBoundsOnScreen(position)
49 svBounds.offsetTo(position.left, position.top)
50
51 // wait for buffers from other layers to be latched and transactions to be processed before
52 // updating the buffer
53 SystemClock.sleep(4000)
54 }
55
56 val result = withScreenRecording(svBounds, PixelColor.RED) {
57 it.mSurfaceProxy.drawBuffer(0, Color.RED)
58 }
59 val failRatio = 1.0f * result.failFrames / (result.failFrames + result.passFrames)
60
61 assertTrue("Error: " + result.failFrames +
62 " incorrect frames observed (out of " + (result.failFrames + result.passFrames) +
63 " frames)", failRatio < 0.05)
64 assertTrue("Error: Did not receive sufficient frame updates expected: >1000 actual:" +
65 result.passFrames, result.passFrames > 1000)
66 }
67 }