diff options
| author | 2020-09-16 19:01:04 -0700 | |
|---|---|---|
| committer | 2020-09-25 19:57:58 +0000 | |
| commit | 57928e6a37e66d9c7405e5a6ed8e0904a14975cd (patch) | |
| tree | 1b5feff88a0abce30f220f0687a68eac2900f04e /tests/SurfaceViewBufferTests/cpp | |
| parent | 4be3ece8e5304601599864b84d5ace13c5c5eaa9 (diff) | |
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
Diffstat (limited to 'tests/SurfaceViewBufferTests/cpp')
| -rw-r--r-- | tests/SurfaceViewBufferTests/cpp/SurfaceProxy.cpp | 102 |
1 files changed, 102 insertions, 0 deletions
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 <android/log.h> +#include <android/native_window.h> +#include <android/native_window_jni.h> +#include <android/window.h> +#include <gui/Surface.h> +#include <jni.h> +#include <system/window.h> +#include <utils/RefBase.h> +#include <cassert> +#include <chrono> +#include <thread> + +#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<android::Surface> surface = static_cast<android::Surface*>(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<android::Surface> surface = static_cast<android::Surface*>(sAnw); + + uint64_t frameNumber = static_cast<uint64_t>(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<std::chrono::seconds>(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 |