Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement NvAPI_GetAssociatedNvidiaDisplayHandle #175

Merged
merged 1 commit into from
May 26, 2024
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
18 changes: 18 additions & 0 deletions src/nvapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,24 @@ extern "C" {
return Ok(n);
}

NvAPI_Status __cdecl NvAPI_GetAssociatedNvidiaDisplayHandle(const char* szDisplayName, NvDisplayHandle* pNvDispHandle) {
constexpr auto n = __func__;

if (nvapiAdapterRegistry == nullptr)
return ApiNotInitialized(n);

if (szDisplayName == nullptr)
return InvalidArgument(n);

auto output = nvapiAdapterRegistry->FindOutput(szDisplayName);
if (output == nullptr)
return NvidiaDeviceNotFound(n);

*pNvDispHandle = reinterpret_cast<NvDisplayHandle>(output);

return Ok(n);
}

NvAPI_Status __cdecl NvAPI_GetInterfaceVersionString(NvAPI_ShortString szDesc) {
constexpr auto n = __func__;

Expand Down
1 change: 1 addition & 0 deletions src/nvapi_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ extern "C" {
INSERT_AND_RETURN_WHEN_EQUALS(NvAPI_EnumNvidiaDisplayHandle)
INSERT_AND_RETURN_WHEN_EQUALS(NvAPI_EnumNvidiaUnAttachedDisplayHandle)
INSERT_AND_RETURN_WHEN_EQUALS(NvAPI_GetAssociatedNvidiaDisplayName)
INSERT_AND_RETURN_WHEN_EQUALS(NvAPI_GetAssociatedNvidiaDisplayHandle)
INSERT_AND_RETURN_WHEN_EQUALS(NvAPI_GetInterfaceVersionString)
INSERT_AND_RETURN_WHEN_EQUALS(NvAPI_GetErrorMessage)
INSERT_AND_RETURN_WHEN_EQUALS(NvAPI_Unload)
Expand Down
22 changes: 22 additions & 0 deletions tests/nvapi_sysinfo_topo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,28 @@ TEST_CASE("Topology methods succeed", "[.sysinfo-topo]") {
REQUIRE(NvAPI_GetAssociatedNvidiaDisplayName(handle4, name4) == NVAPI_INVALID_ARGUMENT);
}

SECTION("GetAssociatedNvidiaDisplayHandle succeeds") {
NvDisplayHandle handle1 = nullptr;
NvDisplayHandle handle2 = nullptr;
NvDisplayHandle handle3 = nullptr;
REQUIRE(NvAPI_EnumNvidiaDisplayHandle(0U, &handle1) == NVAPI_OK);
REQUIRE(NvAPI_EnumNvidiaDisplayHandle(1U, &handle2) == NVAPI_OK);
REQUIRE(NvAPI_EnumNvidiaDisplayHandle(2U, &handle3) == NVAPI_OK);

NvDisplayHandle handle;

REQUIRE(NvAPI_GetAssociatedNvidiaDisplayHandle("Output1", &handle) == NVAPI_OK);
REQUIRE(handle == handle1);

REQUIRE(NvAPI_GetAssociatedNvidiaDisplayHandle("Output2", &handle) == NVAPI_OK);
REQUIRE(handle == handle2);

REQUIRE(NvAPI_GetAssociatedNvidiaDisplayHandle("Output3", &handle) == NVAPI_OK);
REQUIRE(handle == handle3);

REQUIRE(NvAPI_GetAssociatedNvidiaDisplayHandle("Output4", &handle) == NVAPI_NVIDIA_DEVICE_NOT_FOUND);
}

SECTION("GetGDIPrimaryDisplayId succeeds") {
NvU32 displayId;
REQUIRE(NvAPI_DISP_GetGDIPrimaryDisplayId(&displayId) == NVAPI_NVIDIA_DEVICE_NOT_FOUND); // MONITORINFO.dwFlags isn't mocked
Expand Down