[nvnflinger] unstub AdjustRefcount (#120)
Co-authored-by: Maufeat <sahyno1996@gmail.com> Reviewed-on: #120 Co-authored-by: Maufeat <maufeat@eden-emu.dev> Co-committed-by: Maufeat <maufeat@eden-emu.dev>
This commit is contained in:
parent
5de03f47df
commit
410e782291
4 changed files with 53 additions and 12 deletions
|
@ -728,22 +728,26 @@ Status BufferQueueProducer::Connect(const std::shared_ptr<IProducerListener>& li
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://android.googlesource.com/platform/frameworks/native/%2B/master/libs/gui/BufferQueueProducer.cpp#1457
|
||||||
Status BufferQueueProducer::Disconnect(NativeWindowApi api) {
|
Status BufferQueueProducer::Disconnect(NativeWindowApi api) {
|
||||||
LOG_DEBUG(Service_Nvnflinger, "api = {}", api);
|
LOG_DEBUG(Service_Nvnflinger, "disconnect api = {}", api);
|
||||||
|
|
||||||
Status status = Status::NoError;
|
|
||||||
std::shared_ptr<IConsumerListener> listener;
|
std::shared_ptr<IConsumerListener> listener;
|
||||||
|
Status status = Status::NoError;
|
||||||
|
|
||||||
{
|
{
|
||||||
std::scoped_lock lock{core->mutex};
|
std::scoped_lock lock{core->mutex};
|
||||||
|
|
||||||
core->WaitWhileAllocatingLocked();
|
core->WaitWhileAllocatingLocked();
|
||||||
|
|
||||||
if (core->is_abandoned) {
|
if (core->is_abandoned) {
|
||||||
// Disconnecting after the surface has been abandoned is a no-op.
|
|
||||||
return Status::NoError;
|
return Status::NoError;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (core->connected_api == NativeWindowApi::NoConnectedApi) {
|
||||||
|
LOG_DEBUG(Service_Nvnflinger, "disconnect: not connected (req = {})", api);
|
||||||
|
return Status::NoInit;
|
||||||
|
}
|
||||||
|
|
||||||
switch (api) {
|
switch (api) {
|
||||||
case NativeWindowApi::Egl:
|
case NativeWindowApi::Egl:
|
||||||
case NativeWindowApi::Cpu:
|
case NativeWindowApi::Cpu:
|
||||||
|
@ -758,20 +762,20 @@ Status BufferQueueProducer::Disconnect(NativeWindowApi api) {
|
||||||
buffer_wait_event->Signal();
|
buffer_wait_event->Signal();
|
||||||
listener = core->consumer_listener;
|
listener = core->consumer_listener;
|
||||||
} else {
|
} else {
|
||||||
LOG_ERROR(Service_Nvnflinger, "still connected to another api (cur = {} req = {})",
|
LOG_ERROR(Service_Nvnflinger,
|
||||||
|
"disconnect: still connected to another api (cur = {} req = {})",
|
||||||
core->connected_api, api);
|
core->connected_api, api);
|
||||||
status = Status::BadValue;
|
status = Status::BadValue;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
LOG_ERROR(Service_Nvnflinger, "unknown api = {}", api);
|
LOG_ERROR(Service_Nvnflinger, "disconnect: unknown api = {}", api);
|
||||||
status = Status::BadValue;
|
status = Status::BadValue;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Call back without lock held
|
if (listener) {
|
||||||
if (listener != nullptr) {
|
|
||||||
listener->OnBuffersReleased();
|
listener->OnBuffersReleased();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -40,17 +40,22 @@ Result IHOSBinderDriver::TransactParcel(s32 binder_id, u32 transaction_id,
|
||||||
}
|
}
|
||||||
|
|
||||||
Result IHOSBinderDriver::AdjustRefcount(s32 binder_id, s32 addval, s32 type) {
|
Result IHOSBinderDriver::AdjustRefcount(s32 binder_id, s32 addval, s32 type) {
|
||||||
LOG_WARNING(Service_VI, "(STUBBED) called id={}, addval={}, type={}", binder_id, addval, type);
|
LOG_DEBUG(Service_VI, "called id={}, addval={}, type={}", binder_id, addval, type);
|
||||||
|
R_UNLESS(type == 0 || type == 1, ResultUnknown);
|
||||||
|
m_server->AdjustRefcount(binder_id, addval, type == 1);
|
||||||
R_SUCCEED();
|
R_SUCCEED();
|
||||||
}
|
}
|
||||||
|
|
||||||
Result IHOSBinderDriver::GetNativeHandle(s32 binder_id, u32 type_id,
|
Result IHOSBinderDriver::GetNativeHandle(s32 binder_id, u32 type_id,
|
||||||
OutCopyHandle<Kernel::KReadableEvent> out_handle) {
|
OutCopyHandle<Kernel::KReadableEvent> out_handle) {
|
||||||
LOG_WARNING(Service_VI, "(STUBBED) called id={}, type_id={}", binder_id, type_id);
|
LOG_DEBUG(Service_VI, "called id={}, type_id={}", binder_id, type_id);
|
||||||
|
|
||||||
const auto binder = m_server->TryGetBinder(binder_id);
|
const auto binder = m_server->TryGetBinder(binder_id);
|
||||||
R_UNLESS(binder != nullptr, ResultUnknown);
|
R_UNLESS(binder != nullptr, ResultUnknown);
|
||||||
|
|
||||||
|
auto native_handle = binder->GetNativeHandle(type_id);
|
||||||
|
R_UNLESS(native_handle != nullptr, ResultUnknown);
|
||||||
|
|
||||||
*out_handle = binder->GetNativeHandle(type_id);
|
*out_handle = binder->GetNativeHandle(type_id);
|
||||||
|
|
||||||
R_SUCCEED();
|
R_SUCCEED();
|
||||||
|
|
|
@ -17,6 +17,7 @@ s32 HosBinderDriverServer::RegisterBinder(std::shared_ptr<android::IBinder>&& bi
|
||||||
last_id++;
|
last_id++;
|
||||||
|
|
||||||
binders[last_id] = std::move(binder);
|
binders[last_id] = std::move(binder);
|
||||||
|
refcounts[last_id] = {}; // strong = 1, weak = 0
|
||||||
|
|
||||||
return last_id;
|
return last_id;
|
||||||
}
|
}
|
||||||
|
@ -25,6 +26,29 @@ void HosBinderDriverServer::UnregisterBinder(s32 binder_id) {
|
||||||
std::scoped_lock lk{lock};
|
std::scoped_lock lk{lock};
|
||||||
|
|
||||||
binders.erase(binder_id);
|
binders.erase(binder_id);
|
||||||
|
refcounts.erase(binder_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
void HosBinderDriverServer::AdjustRefcount(s32 binder_id, s32 delta, bool is_weak) {
|
||||||
|
std::scoped_lock lk{lock};
|
||||||
|
|
||||||
|
auto search_rc = refcounts.find(binder_id);
|
||||||
|
if (search_rc == refcounts.end()) {
|
||||||
|
LOG_WARNING(Service_VI, "AdjustRefcount called for unknown binder id {}", binder_id);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto& rc = search_rc->second;
|
||||||
|
s32& counter = is_weak ? rc.weak : rc.strong;
|
||||||
|
counter += delta;
|
||||||
|
|
||||||
|
if (counter < 0)
|
||||||
|
counter = 0;
|
||||||
|
|
||||||
|
if (rc.strong == 0 && rc.weak == 0) {
|
||||||
|
binders.erase(binder_id);
|
||||||
|
refcounts.erase(search_rc);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<android::IBinder> HosBinderDriverServer::TryGetBinder(s32 id) const {
|
std::shared_ptr<android::IBinder> HosBinderDriverServer::TryGetBinder(s32 id) const {
|
||||||
|
|
|
@ -26,10 +26,18 @@ public:
|
||||||
|
|
||||||
std::shared_ptr<android::IBinder> TryGetBinder(s32 id) const;
|
std::shared_ptr<android::IBinder> TryGetBinder(s32 id) const;
|
||||||
|
|
||||||
|
void AdjustRefcount(s32 binder_id, s32 delta, bool is_weak);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::unordered_map<s32, std::shared_ptr<android::IBinder>> binders;
|
struct RefCounts {
|
||||||
|
s32 strong{1};
|
||||||
|
s32 weak{0};
|
||||||
|
};
|
||||||
|
|
||||||
mutable std::mutex lock;
|
mutable std::mutex lock;
|
||||||
s32 last_id{};
|
s32 last_id = 0;
|
||||||
|
std::unordered_map<s32, std::shared_ptr<android::IBinder>> binders;
|
||||||
|
std::unordered_map<s32, RefCounts> refcounts;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Service::Nvnflinger
|
} // namespace Service::Nvnflinger
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue