From 57928e6a37e66d9c7405e5a6ed8e0904a14975cd Mon Sep 17 00:00:00 2001 From: Vishnu Nair Date: Wed, 16 Sep 2020 19:01:04 -0700 Subject: Verify SurfaceView BlastBufferQueue behavior Initial code to easily configure buffer producers to generate buffers with different properties inorder exercise and validate BlastBufferQueue adapter. The test captures surface flinger traces and verifies properties of a single buffer. This will allow us to verify buffer presentation order, buffer rejection, buffer properties and so on. Test: atest SurfaceViewBufferTests Bug: 168504870 Change-Id: I9714d7b6f5ffbe5fecca5d93e8184f0e6ac2b4c1 --- tests/SurfaceViewBufferTests/cpp/SurfaceProxy.cpp | 102 ++++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 tests/SurfaceViewBufferTests/cpp/SurfaceProxy.cpp (limited to 'tests/SurfaceViewBufferTests/cpp') diff --git a/tests/SurfaceViewBufferTests/cpp/SurfaceProxy.cpp b/tests/SurfaceViewBufferTests/cpp/SurfaceProxy.cpp new file mode 100644 index 000000000000..0c86524293e7 --- /dev/null +++ b/tests/SurfaceViewBufferTests/cpp/SurfaceProxy.cpp @@ -0,0 +1,102 @@ +/* + * Copyright (C) 2020 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define TAG "SurfaceViewBufferTests" +#define LOGE(...) __android_log_print(ANDROID_LOG_ERROR, TAG, __VA_ARGS__) + +extern "C" { +int i = 0; +static ANativeWindow* sAnw; + +JNIEXPORT jint JNICALL Java_com_android_test_SurfaceProxy_setSurface(JNIEnv* env, jclass, + jobject surfaceObject) { + sAnw = ANativeWindow_fromSurface(env, surfaceObject); + assert(sAnw); + android::sp surface = static_cast(sAnw); + surface->enableFrameTimestamps(true); + return 0; +} + +JNIEXPORT jint JNICALL Java_com_android_test_SurfaceProxy_waitUntilBufferDisplayed( + JNIEnv*, jclass, jint jFrameNumber, jint timeoutSec) { + using namespace std::chrono_literals; + assert(sAnw); + android::sp surface = static_cast(sAnw); + + uint64_t frameNumber = static_cast(jFrameNumber); + nsecs_t outRequestedPresentTime, outAcquireTime, outLatchTime, outFirstRefreshStartTime; + nsecs_t outLastRefreshStartTime, outGlCompositionDoneTime, outDequeueReadyTime; + nsecs_t outDisplayPresentTime = -1; + nsecs_t outReleaseTime; + + auto start = std::chrono::steady_clock::now(); + while (outDisplayPresentTime < 0) { + std::this_thread::sleep_for(8ms); + surface->getFrameTimestamps(frameNumber, &outRequestedPresentTime, &outAcquireTime, + &outLatchTime, &outFirstRefreshStartTime, + &outLastRefreshStartTime, &outGlCompositionDoneTime, + &outDisplayPresentTime, &outDequeueReadyTime, &outReleaseTime); + if (outDisplayPresentTime < 0) { + auto end = std::chrono::steady_clock::now(); + if (std::chrono::duration_cast(end - start).count() > + timeoutSec) { + return -1; + } + } + } + return 0; +} + +JNIEXPORT jint JNICALL Java_com_android_test_SurfaceProxy_draw(JNIEnv*, jclass) { + assert(sAnw); + ANativeWindow_Buffer outBuffer; + ANativeWindow_lock(sAnw, &outBuffer, nullptr); + return 0; +} + +JNIEXPORT jint JNICALL Java_com_android_test_SurfaceProxy_ANativeWindowLock(JNIEnv*, jclass) { + assert(sAnw); + ANativeWindow_Buffer outBuffer; + ANativeWindow_lock(sAnw, &outBuffer, nullptr); + return 0; +} + +JNIEXPORT jint JNICALL Java_com_android_test_SurfaceProxy_ANativeWindowUnlockAndPost(JNIEnv*, + jclass) { + assert(sAnw); + ANativeWindow_unlockAndPost(sAnw); + return 0; +} + +JNIEXPORT jint JNICALL Java_com_android_test_SurfaceProxy_ANativeWindowSetBuffersGeometry( + JNIEnv* /* env */, jclass /* clazz */, jobject /* surfaceObject */, jint w, jint h, + jint format) { + assert(sAnw); + return ANativeWindow_setBuffersGeometry(sAnw, w, h, format); +} +} \ No newline at end of file -- cgit v1.2.3-59-g8ed1b