* Use a custom, non-allocating map for frame ids * use memory_order_relaxed for the id of heap allocated handles * Added displayPresent time to FrameInfo To do this, we added support for queryFrameTiming() to the backend, as a synchronous API. Then FrameInfo uses it to update the corresponding history entry. displayPresent time can be used to detect "buffer stuffing", i.e. when the GPU gets too much ahead of the display. Currently the information is returned to the user only. Eventually filament will make use of it to determine if a frame skip is mandated. * API BREAK: rename frameTime to gpuFrameDuration * FrameInfo now contains compositor timings - the presentation deadline - the refresh rate from the display - the composition-display latency * set FrameInfo data to INVALID if feature is not supported report presentDeadline properly.
60 lines
1.8 KiB
C++
60 lines
1.8 KiB
C++
/*
|
|
* Copyright (C) 2025 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 "AndroidSwapChainHelper.h"
|
|
#include "AndroidNativeWindow.h"
|
|
|
|
#include <android/native_window.h>
|
|
|
|
#include <cstddef>
|
|
#include <cstdint>
|
|
#include <limits>
|
|
#include <mutex>
|
|
|
|
namespace filament::backend {
|
|
|
|
AndroidSwapChainHelper::AndroidSwapChainHelper() = default;
|
|
|
|
AndroidSwapChainHelper::~AndroidSwapChainHelper() noexcept = default;
|
|
|
|
bool AndroidSwapChainHelper::setPresentFrameId(
|
|
ANativeWindow* anw, uint64_t const frameId) const noexcept {
|
|
uint64_t sysFrameId{};
|
|
int const status = NativeWindow::getNextFrameId(anw, &sysFrameId);
|
|
if (status == 0) {
|
|
std::lock_guard const lock(mLock);
|
|
auto const pos = mFrameIdToSystemFrameId.find(frameId);
|
|
if (pos && *pos != sysFrameId) {
|
|
// we're trying to associate the same frame id to a different frame!
|
|
return false;
|
|
}
|
|
// oldest entry is removed
|
|
mFrameIdToSystemFrameId.insert(frameId, sysFrameId);
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
uint64_t AndroidSwapChainHelper::getFrameId(uint64_t const frameId) const noexcept {
|
|
std::lock_guard const lock(mLock);
|
|
if (auto const* const pos = mFrameIdToSystemFrameId.find(frameId)) {
|
|
return *pos;
|
|
}
|
|
return std::numeric_limits<uint64_t>::max();
|
|
}
|
|
|
|
}
|