Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2ddc0b22 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge changes from topic "psc-ndk"

* changes:
  NDK attached choreographer tests
  NDK attached Choreographer from SurfaceControl.
parents a9530eeb 54fe6093
Loading
Loading
Loading
Loading
+1 −0
Original line number Original line Diff line number Diff line
@@ -345,6 +345,7 @@ LIBANDROID_PLATFORM {
    extern "C++" {
    extern "C++" {
        ASurfaceControl_registerSurfaceStatsListener*;
        ASurfaceControl_registerSurfaceStatsListener*;
        ASurfaceControl_unregisterSurfaceStatsListener*;
        ASurfaceControl_unregisterSurfaceStatsListener*;
        ASurfaceControl_getChoreographer*;
        ASurfaceControlStats_getAcquireTime*;
        ASurfaceControlStats_getAcquireTime*;
        ASurfaceControlStats_getFrameNumber*;
        ASurfaceControlStats_getFrameNumber*;
    };
    };
+12 −0
Original line number Original line Diff line number Diff line
@@ -180,6 +180,18 @@ void ASurfaceControl_unregisterSurfaceStatsListener(void* context,
            reinterpret_cast<void*>(func));
            reinterpret_cast<void*>(func));
}
}


AChoreographer* ASurfaceControl_getChoreographer(ASurfaceControl* aSurfaceControl) {
    LOG_ALWAYS_FATAL_IF(aSurfaceControl == nullptr, "aSurfaceControl should not be nullptr");
    SurfaceControl* surfaceControl =
            ASurfaceControl_to_SurfaceControl(reinterpret_cast<ASurfaceControl*>(aSurfaceControl));
    if (!surfaceControl->isValid()) {
        ALOGE("Attempted to get choreographer from invalid surface control");
        return nullptr;
    }
    SurfaceControl_acquire(surfaceControl);
    return reinterpret_cast<AChoreographer*>(surfaceControl->getChoreographer().get());
}

int64_t ASurfaceControlStats_getAcquireTime(ASurfaceControlStats* stats) {
int64_t ASurfaceControlStats_getAcquireTime(ASurfaceControlStats* stats) {
    if (const auto* fence = std::get_if<sp<Fence>>(&stats->acquireTimeOrFence)) {
    if (const auto* fence = std::get_if<sp<Fence>>(&stats->acquireTimeOrFence)) {
        // We got a fence instead of the acquire time due to latch unsignaled.
        // We got a fence instead of the acquire time due to latch unsignaled.
+3 −0
Original line number Original line Diff line number Diff line
@@ -36,6 +36,9 @@ android_test {
        "com.google.android.material_material",
        "com.google.android.material_material",
        "truth-prebuilt",
        "truth-prebuilt",
    ],
    ],
    jni_libs: [
        "libchoreographertests_jni",
    ],
    resource_dirs: ["src/main/res"],
    resource_dirs: ["src/main/res"],
    certificate: "platform",
    certificate: "platform",
    platform_apis: true,
    platform_apis: true,
+44 −0
Original line number Original line Diff line number Diff line
// Copyright 2023 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.

package {
    default_applicable_licenses: ["Android-Apache-2.0"],
}

cc_test_library {
    name: "libchoreographertests_jni",
    cflags: [
        "-Werror",
        "-Wthread-safety",
    ],

    gtest: false,

    srcs: [
        "ChoreographerTestsJniOnLoad.cpp",
        "android_view_tests_ChoreographerNativeTest.cpp",
    ],

    shared_libs: [
        "libandroid",
        "libnativehelper",
        "liblog",
    ],

    header_libs: [
        "libandroid_headers_private",
    ],

    stl: "c++_static",
}
+33 −0
Original line number Original line Diff line number Diff line
/*
 * Copyright 2023 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 <jni.h>

#define LOG_TAG "ChoreographerTestsJniOnLoad"

extern int register_android_android_view_tests_ChoreographerNativeTest(JNIEnv* env);

JNIEXPORT jint JNI_OnLoad(JavaVM* vm, void*) {
    JNIEnv* env = NULL;
    if (vm->GetEnv(reinterpret_cast<void**>(&env), JNI_VERSION_1_6) != JNI_OK) {
        return JNI_ERR;
    }

    if (register_android_android_view_tests_ChoreographerNativeTest(env)) {
        return JNI_ERR;
    }

    return JNI_VERSION_1_6;
}
 No newline at end of file
Loading