Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions layersvt/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ if(BUILD_CPUTIMING)
../scripts/generators/cputiming_generator.py
vk_layer_table.cpp
vk_layer_table.h
layer_keep_alive.cpp
json/VkLayer_CPUTiming.json.in
)

Expand Down
12 changes: 12 additions & 0 deletions layersvt/cputiming.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,18 @@

#include "cputiming.h"

#if defined(__ANDROID__)
#include <android/log.h>

__attribute__((constructor)) static void cputiming_layer_init() {
__android_log_print(ANDROID_LOG_WARN, "CPUTiming", "dlopen: CPUTiming library");
}

__attribute__((destructor)) static void cputiming_layer_finish() {
__android_log_print(ANDROID_LOG_WARN, "CPUTiming", "dlclose: CPUTiming library");
}
#endif

CpuTiming& CpuTiming::Get() {
static CpuTiming instance;
return instance;
Expand Down
45 changes: 45 additions & 0 deletions layersvt/layer_keep_alive.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/* Copyright (c) 2015-2023 The Khronos Group Inc.
* Copyright (c) 2015-2023 Valve Corporation
* Copyright (c) 2015-2023 LunarG, Inc.
*
* 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.
*/

#if defined(__ANDROID__)
#include <dlfcn.h>

namespace {

// Anonymous namespace function is NOT exported, keeping it local to each shared object.
// We use a constructor attribute to trigger it when the library is loaded/opened.
void layer_keep_alive_func();

class KeepAlive {
public:
KeepAlive() {
Dl_info info;
// Attempt to find the filename of the library containing this code.
if (dladdr((void*)&layer_keep_alive_func, &info)) {
// Re-open with RTLD_NODELETE to force the library to stay resident.
dlopen(info.dli_fname, RTLD_NODELETE);
}
}
};

__attribute__((constructor)) void layer_keep_alive_func() {
static KeepAlive k;
(void)k;
}

} // namespace
#endif
Loading