diff --git a/linux/kwin_gpu_interposer.cpp b/linux/kwin_gpu_interposer.cpp index 94928c8..08d4872 100644 --- a/linux/kwin_gpu_interposer.cpp +++ b/linux/kwin_gpu_interposer.cpp @@ -1,7 +1,3 @@ -#include -#include -#include - #include #include #include @@ -10,20 +6,23 @@ #include #include #include +#include +#include +#include #include #include #include #include #include +#include #include #include - -#include #include #ifdef VIBESHINE_KWIN_NATIVE_ALLOCATOR - #include #include "kwin_native_abi.h" + + #include #endif namespace { @@ -48,10 +47,12 @@ namespace { std::atomic hooks_enabled {false}; std::atomic native_hooks_enabled {false}; std::mutex render_fds_mutex; + struct allocator_fds { int render; int kms; }; + std::unordered_map owned_render_fds; thread_local bool software_allocation = false; @@ -69,13 +70,15 @@ namespace { // GraphicsBufferOptions is a C++ ABI. Only read the layout of the exact // KWin library whose public headers were used to build this bridge. const auto probe = vibeshine::kwin::probe_native_abi( - native_allocate_symbol, VIBESHINE_KWIN_NATIVE_LIBRARY_NAME); + native_allocate_symbol, + VIBESHINE_KWIN_NATIVE_LIBRARY_NAME + ); if (report_failure) { vibeshine::kwin::report_native_abi_failure(stderr, probe, VIBESHINE_KWIN_NATIVE_LIBRARY_NAME); } return probe.result == vibeshine::kwin::native_abi_result::compatible; #else - (void)report_failure; + (void) report_failure; #endif return false; } @@ -95,14 +98,14 @@ namespace { bool is_vibeshine_display(const drmDevicePtr device) { return device && device->bustype == DRM_BUS_FAUX && device->businfo.faux && - std::strcmp(device->businfo.faux->name, "vibeshine") == 0; + std::strcmp(device->businfo.faux->name, "vibeshine") == 0; } bool is_nvidia_render_device(const drmDevicePtr device) { return device && device->bustype == DRM_BUS_PCI && device->businfo.pci && - device->deviceinfo.pci && device->deviceinfo.pci->vendor_id == 0x10de && - (device->available_nodes & (1 << DRM_NODE_RENDER)) != 0 && - device->nodes && device->nodes[DRM_NODE_RENDER]; + device->deviceinfo.pci && device->deviceinfo.pci->vendor_id == 0x10de && + (device->available_nodes & (1 << DRM_NODE_RENDER)) != 0 && + device->nodes && device->nodes[DRM_NODE_RENDER]; } std::optional parse_pci_device(const char *value) { @@ -111,8 +114,7 @@ namespace { unsigned int device = 0; unsigned int function = 0; char trailing = '\0'; - if (std::sscanf(value, "%x:%x:%x.%x%c", &domain, &bus, &device, &function, &trailing) != 4 || - domain > 0xffff || bus > 0xff || device > 0x1f || function > 7) { + if (std::sscanf(value, "%x:%x:%x.%x%c", &domain, &bus, &device, &function, &trailing) != 4 || domain > 0xffff || bus > 0xff || device > 0x1f || function > 7) { return std::nullopt; } return drmPciBusInfo { @@ -125,23 +127,24 @@ namespace { bool pci_matches(const drmPciBusInfo &actual, const drmPciBusInfo &expected) { return actual.domain == expected.domain && actual.bus == expected.bus && - actual.dev == expected.dev && actual.func == expected.func; + actual.dev == expected.dev && actual.func == expected.func; } bool pci_precedes(const drmPciBusInfo &left, const drmPciBusInfo &right) { return std::tie(left.domain, left.bus, left.dev, left.func) < - std::tie(right.domain, right.bus, right.dev, right.func); + std::tie(right.domain, right.bus, right.dev, right.func); } drmDevicePtr select_render_device(drmDevicePtr devices[], const int count) { const auto *configured_value = std::getenv(kRenderPciEnvironment.data()); const auto configured = configured_value && *configured_value ? - parse_pci_device(configured_value) : std::optional {}; + parse_pci_device(configured_value) : + std::optional {}; if (configured_value && *configured_value && !configured) { if (!ambiguous_gpu_logged.exchange(true, std::memory_order_relaxed)) { constexpr char message[] = "[vibeshine-kwin-gpu] invalid VIBESHINE_KWIN_RENDER_PCI; refusing virtual GPU association\n"; - (void)write(STDERR_FILENO, message, sizeof(message) - 1); + (void) write(STDERR_FILENO, message, sizeof(message) - 1); } return nullptr; } @@ -149,8 +152,7 @@ namespace { int matches = 0; for (int index = 0; index < count; ++index) { auto *const candidate = devices[index]; - if (!is_nvidia_render_device(candidate) || - (configured && !pci_matches(*candidate->businfo.pci, *configured))) { + if (!is_nvidia_render_device(candidate) || (configured && !pci_matches(*candidate->businfo.pci, *configured))) { continue; } if (!selected || pci_precedes(*candidate->businfo.pci, *selected->businfo.pci)) { @@ -164,7 +166,7 @@ namespace { if (matches > 1 && !ambiguous_gpu_logged.exchange(true, std::memory_order_relaxed)) { constexpr char message[] = "[vibeshine-kwin-gpu] multiple NVIDIA render devices found; using lowest PCI address for virtual outputs unless VIBESHINE_KWIN_RENDER_PCI selects another\n"; - (void)write(STDERR_FILENO, message, sizeof(message) - 1); + (void) write(STDERR_FILENO, message, sizeof(message) - 1); } // GBM allocators are created before KWin chooses its primary renderer. // A stable PCI default avoids software-only virtual outputs on headless @@ -205,8 +207,8 @@ namespace { // the verified real render node for the selected PCI device. drmDevicePtr opened = nullptr; const bool matches = drmGetNodeTypeFromFd(fd) == DRM_NODE_RENDER && - get_device(fd, 0, &opened) == 0 && is_nvidia_render_device(opened) && - pci_matches(*opened->businfo.pci, identity); + get_device(fd, 0, &opened) == 0 && is_nvidia_render_device(opened) && + pci_matches(*opened->businfo.pci, identity); drmFreeDevice(&opened); if (!matches) { close(fd); @@ -220,12 +222,9 @@ namespace { return; } char message[224] {}; - const auto length = std::snprintf(message, sizeof(message), - "[vibeshine-kwin-gpu] virtual GBM uses NVIDIA render node %04x:%02x:%02x.%u; seat DRM devices unchanged\n", - identity.domain, identity.bus, identity.dev, identity.func); + const auto length = std::snprintf(message, sizeof(message), "[vibeshine-kwin-gpu] virtual GBM uses NVIDIA render node %04x:%02x:%02x.%u; seat DRM devices unchanged\n", identity.domain, identity.bus, identity.dev, identity.func); if (length > 0) { - (void)write(STDERR_FILENO, message, - std::min(static_cast(length), sizeof(message) - 1)); + (void) write(STDERR_FILENO, message, std::min(static_cast(length), sizeof(message) - 1)); } } @@ -251,12 +250,9 @@ namespace { * * @param lookup Dynamic symbol lookup, injectable for routing tests. */ - void configure_allocator_routing(void *(*lookup)(void *, const char *), - bool native_abi_compatible = native_allocator_runtime_compatible()) { - const bool legacy_allocator = lookup(RTLD_DEFAULT, - "_ZN4KWin26GbmGraphicsBufferAllocatorC1EP10gbm_devicem") != nullptr; - const bool native_allocator = lookup(RTLD_DEFAULT, - "_ZN4KWin26GbmGraphicsBufferAllocatorC1EPNS_9DrmDeviceE") != nullptr; + void configure_allocator_routing(void *(*lookup)(void *, const char *), bool native_abi_compatible = native_allocator_runtime_compatible()) { + const bool legacy_allocator = lookup(RTLD_DEFAULT, "_ZN4KWin26GbmGraphicsBufferAllocatorC1EP10gbm_devicem") != nullptr; + const bool native_allocator = lookup(RTLD_DEFAULT, "_ZN4KWin26GbmGraphicsBufferAllocatorC1EPNS_9DrmDeviceE") != nullptr; bool native_supported = false; #ifdef VIBESHINE_KWIN_NATIVE_ALLOCATOR native_supported = native_allocator && !legacy_allocator && native_abi_compatible; @@ -264,13 +260,13 @@ namespace { native_hooks_enabled.store(native_supported, std::memory_order_release); hooks_enabled.store((legacy_allocator && !native_allocator) || native_supported, std::memory_order_release); // Always clear the preload, including when the native KMS allocator wins. - (void)unsetenv("LD_PRELOAD"); - (void)unsetenv(kPreloadActiveEnvironment.data()); + (void) unsetenv("LD_PRELOAD"); + (void) unsetenv(kPreloadActiveEnvironment.data()); if (!hooks_enabled.load(std::memory_order_acquire)) { - (void)native_allocator_runtime_compatible(true); + (void) native_allocator_runtime_compatible(true); constexpr char message[] = "[vibeshine-kwin-gpu] preserving native KMS allocator for current KWin ABI\n"; - (void)write(STDERR_FILENO, message, sizeof(message) - 1); + (void) write(STDERR_FILENO, message, sizeof(message) - 1); } } @@ -280,7 +276,7 @@ namespace { } configure_allocator_routing(dlsym); } -} +} // namespace extern "C" gbm_device *gbm_create_device(const int fd) { const auto function = resolve_real_function(real_gbm_create_device, "gbm_create_device"); @@ -299,7 +295,7 @@ extern "C" gbm_device *gbm_create_device(const int fd) { const auto get_device = resolve_real_function(real_drm_get_device2, "drmGetDevice2"); drmDevicePtr device = nullptr; const bool virtual_display = get_device && get_device(fd, 0, &device) == 0 && - is_vibeshine_display(device); + is_vibeshine_display(device); drmFreeDevice(&device); if (!virtual_display) { return pass_through(); @@ -381,8 +377,7 @@ extern "C" int gbm_device_get_fd(gbm_device *device) { } #ifdef VIBESHINE_KWIN_NATIVE_ALLOCATOR -extern "C" void *vibeshine_kwin_render_device(const void *, drmDevicePtr) - asm("_ZNK4KWin10GpuManager26findCompatibleRenderDeviceEP10_drmDevice"); +extern "C" void *vibeshine_kwin_render_device(const void *, drmDevicePtr) asm("_ZNK4KWin10GpuManager26findCompatibleRenderDeviceEP10_drmDevice"); extern "C" void *vibeshine_kwin_render_device(const void *manager, drmDevicePtr device) { const auto function = resolve_real_function(real_native_render_device, native_render_device_symbol); @@ -400,8 +395,7 @@ extern "C" void *vibeshine_kwin_render_device(const void *manager, drmDevicePtr drmDevicePtr render = nullptr; const auto get_device = resolve_real_function(real_drm_get_device2, "drmGetDevice2"); void *selected = nullptr; - if (get_device && get_device(fd, 0, &render) == 0 && is_nvidia_render_device(render) && - pci_matches(*render->businfo.pci, identity)) { + if (get_device && get_device(fd, 0, &render) == 0 && is_nvidia_render_device(render) && pci_matches(*render->businfo.pci, identity)) { selected = function(manager, render); } drmFreeDevice(&render); @@ -414,8 +408,7 @@ extern "C" void *vibeshine_kwin_render_device(const void *manager, drmDevicePtr return function(manager, device); } -extern "C" KWin::GraphicsBuffer *vibeshine_kwin_allocate(void *, const KWin::GraphicsBufferOptions &) - asm("_ZN4KWin26GbmGraphicsBufferAllocator8allocateERKNS_21GraphicsBufferOptionsE"); +extern "C" KWin::GraphicsBuffer *vibeshine_kwin_allocate(void *, const KWin::GraphicsBufferOptions &) asm("_ZN4KWin26GbmGraphicsBufferAllocator8allocateERKNS_21GraphicsBufferOptionsE"); extern "C" KWin::GraphicsBuffer *vibeshine_kwin_allocate(void *allocator, const KWin::GraphicsBufferOptions &options) { const auto function = resolve_real_function(real_native_allocate, native_allocate_symbol); @@ -428,10 +421,15 @@ extern "C" KWin::GraphicsBuffer *vibeshine_kwin_allocate(void *allocator, const } const bool previous = software_allocation; software_allocation = options.software; + struct restore_scope { bool previous; - ~restore_scope() { software_allocation = previous; } + + ~restore_scope() { + software_allocation = previous; + } } restore {previous}; + return function(allocator, options); } #endif diff --git a/linux/kwin_native_abi.h b/linux/kwin_native_abi.h index b0b9c17..58a0b09 100644 --- a/linux/kwin_native_abi.h +++ b/linux/kwin_native_abi.h @@ -1,12 +1,11 @@ #pragma once -#include -#include - #include #include #include #include +#include +#include namespace vibeshine::kwin { enum class native_abi_result { @@ -26,10 +25,12 @@ namespace vibeshine::kwin { // symlink that has changed since load; realpath describes its current target, // not necessarily the mapped DSO. Do not report this as loaded identity. inline native_abi_probe probe_native_abi( - const char *symbol, const char *expected_library, + const char *symbol, + const char *expected_library, void *(*lookup)(void *, const char *) = dlsym, int (*address)(const void *, Dl_info *) = dladdr, - char *(*resolve)(const char *, char *) = realpath) { + char *(*resolve)(const char *, char *) = realpath + ) { native_abi_probe probe {native_abi_result::missing_allocator}; const auto allocator = lookup(RTLD_NEXT, symbol); if (!allocator) { @@ -51,12 +52,12 @@ namespace vibeshine::kwin { } std::snprintf(probe.resolved_library.data(), probe.resolved_library.size(), "%s", name + 1); probe.result = std::strcmp(name + 1, expected_library) == 0 ? - native_abi_result::compatible : native_abi_result::different_library; + native_abi_result::compatible : + native_abi_result::different_library; return probe; } - inline void report_native_abi_failure(FILE *output, const native_abi_probe &probe, - const char *expected_library) { + inline void report_native_abi_failure(FILE *output, const native_abi_probe &probe, const char *expected_library) { if (probe.result == native_abi_result::compatible) { return; } @@ -75,11 +76,12 @@ namespace vibeshine::kwin { break; } std::fprintf(output, - "[vibeshine-kwin-gpu] native GPU bridge disabled: %s (built for %s; resolved current pathname %s; mapped library identity unverified). " - "Keeping native KMS allocation; virtual capture may fall back to CPU upload. " - "Install a bridge package rebuilt against the installed KWin, then log out and back in or reboot. " - "Restarting the streaming service alone does not reload the compositor bridge.\n", - reason, expected_library, - probe.resolved_library[0] ? probe.resolved_library.data() : "unknown"); + "[vibeshine-kwin-gpu] native GPU bridge disabled: %s (built for %s; resolved current pathname %s; mapped library identity unverified). " + "Keeping native KMS allocation; virtual capture may fall back to CPU upload. " + "Install a bridge package rebuilt against the installed KWin, then log out and back in or reboot. " + "Restarting the streaming service alone does not reload the compositor bridge.\n", + reason, + expected_library, + probe.resolved_library[0] ? probe.resolved_library.data() : "unknown"); } -} +} // namespace vibeshine::kwin diff --git a/linux/vibeshine-drm/.clang-format b/linux/vibeshine-drm/.clang-format new file mode 100644 index 0000000..6a3de86 --- /dev/null +++ b/linux/vibeshine-drm/.clang-format @@ -0,0 +1,808 @@ +# SPDX-License-Identifier: GPL-2.0 +# +# clang-format configuration file. Intended for clang-format >= 11. +# +# For more information, see: +# +# Documentation/dev-tools/clang-format.rst +# https://clang.llvm.org/docs/ClangFormat.html +# https://clang.llvm.org/docs/ClangFormatStyleOptions.html +# +--- +AccessModifierOffset: -4 +AlignAfterOpenBracket: Align +AlignConsecutiveAssignments: false +AlignConsecutiveDeclarations: false +AlignEscapedNewlines: Left +AlignOperands: true +AlignTrailingComments: false +AllowAllParametersOfDeclarationOnNextLine: false +AllowShortBlocksOnASingleLine: false +AllowShortCaseLabelsOnASingleLine: false +AllowShortFunctionsOnASingleLine: None +AllowShortIfStatementsOnASingleLine: false +AllowShortLoopsOnASingleLine: false +AlwaysBreakAfterDefinitionReturnType: None +AlwaysBreakAfterReturnType: None +AlwaysBreakBeforeMultilineStrings: false +AlwaysBreakTemplateDeclarations: false +BinPackArguments: true +BinPackParameters: true +BraceWrapping: + AfterClass: false + AfterControlStatement: false + AfterEnum: false + AfterFunction: true + AfterNamespace: true + AfterObjCDeclaration: false + AfterStruct: false + AfterUnion: false + AfterExternBlock: false + BeforeCatch: false + BeforeElse: false + IndentBraces: false + SplitEmptyFunction: true + SplitEmptyRecord: true + SplitEmptyNamespace: true +BreakBeforeBinaryOperators: None +BreakBeforeBraces: Custom +BreakBeforeInheritanceComma: false +BreakBeforeTernaryOperators: false +BreakConstructorInitializersBeforeComma: false +BreakConstructorInitializers: BeforeComma +BreakAfterJavaFieldAnnotations: false +BreakStringLiterals: false +ColumnLimit: 80 +CommentPragmas: '^ IWYU pragma:' +CompactNamespaces: false +ConstructorInitializerAllOnOneLineOrOnePerLine: false +ConstructorInitializerIndentWidth: 8 +ContinuationIndentWidth: 8 +Cpp11BracedListStyle: false +DerivePointerAlignment: false +DisableFormat: false +ExperimentalAutoDetectBinPacking: false +FixNamespaceComments: false + +# Taken from: +# git grep -h '^#define [^[:space:]]*for_each[^[:space:]]*(' include/ tools/ \ +# | sed "s,^#define \([^[:space:]]*for_each[^[:space:]]*\)(.*$, - '\1'," \ +# | LC_ALL=C sort -u +ForEachMacros: + - '__ata_qc_for_each' + - '__bio_for_each_bvec' + - '__bio_for_each_segment' + - '__evlist__for_each_entry' + - '__evlist__for_each_entry_continue' + - '__evlist__for_each_entry_from' + - '__evlist__for_each_entry_reverse' + - '__evlist__for_each_entry_safe' + - '__for_each_mem_range' + - '__for_each_mem_range_rev' + - '__for_each_thread' + - '__hlist_for_each_rcu' + - '__map__for_each_symbol_by_name' + - '__pci_bus_for_each_res0' + - '__pci_bus_for_each_res1' + - '__pci_dev_for_each_res0' + - '__pci_dev_for_each_res1' + - '__perf_evlist__for_each_entry' + - '__perf_evlist__for_each_entry_reverse' + - '__perf_evlist__for_each_entry_safe' + - '__rq_for_each_bio' + - '__shost_for_each_device' + - '__sym_for_each' + - '_for_each_counter' + - 'apei_estatus_for_each_section' + - 'ata_for_each_dev' + - 'ata_for_each_link' + - 'ata_qc_for_each' + - 'ata_qc_for_each_raw' + - 'ata_qc_for_each_with_internal' + - 'ax25_for_each' + - 'ax25_uid_for_each' + - 'bio_for_each_bvec' + - 'bio_for_each_bvec_all' + - 'bio_for_each_folio_all' + - 'bio_for_each_integrity_vec' + - 'bio_for_each_segment' + - 'bio_for_each_segment_all' + - 'bio_list_for_each' + - 'bip_for_each_vec' + - 'bond_for_each_slave' + - 'bond_for_each_slave_rcu' + - 'bpf_for_each' + - 'bpf_for_each_reg_in_vstate' + - 'bpf_for_each_reg_in_vstate_mask' + - 'bpf_for_each_spilled_reg' + - 'bpf_object__for_each_map' + - 'bpf_object__for_each_program' + - 'btree_for_each_safe128' + - 'btree_for_each_safe32' + - 'btree_for_each_safe64' + - 'btree_for_each_safel' + - 'card_for_each_dev' + - 'cgroup_taskset_for_each' + - 'cgroup_taskset_for_each_leader' + - 'cpu_aggr_map__for_each_idx' + - 'cpufreq_for_each_efficient_entry_idx' + - 'cpufreq_for_each_entry' + - 'cpufreq_for_each_entry_idx' + - 'cpufreq_for_each_valid_entry' + - 'cpufreq_for_each_valid_entry_idx' + - 'css_for_each_child' + - 'css_for_each_descendant_post' + - 'css_for_each_descendant_pre' + - 'damon_for_each_region' + - 'damon_for_each_region_from' + - 'damon_for_each_region_safe' + - 'damon_for_each_scheme' + - 'damon_for_each_scheme_safe' + - 'damon_for_each_target' + - 'damon_for_each_target_safe' + - 'damos_for_each_core_filter' + - 'damos_for_each_core_filter_safe' + - 'damos_for_each_ops_filter' + - 'damos_for_each_ops_filter_safe' + - 'damos_for_each_quota_goal' + - 'damos_for_each_quota_goal_safe' + - 'data__for_each_file' + - 'data__for_each_file_new' + - 'data__for_each_file_start' + - 'def_for_each_cpu' + - 'device_for_each_child_node' + - 'device_for_each_child_node_scoped' + - 'dma_fence_array_for_each' + - 'dma_fence_chain_for_each' + - 'dma_fence_unwrap_for_each' + - 'dma_resv_for_each_fence' + - 'dma_resv_for_each_fence_unlocked' + - 'do_for_each_ftrace_op' + - 'drm_atomic_crtc_for_each_plane' + - 'drm_atomic_crtc_state_for_each_plane' + - 'drm_atomic_crtc_state_for_each_plane_state' + - 'drm_atomic_for_each_plane_damage' + - 'drm_client_for_each_connector_iter' + - 'drm_client_for_each_modeset' + - 'drm_connector_for_each_possible_encoder' + - 'drm_exec_for_each_locked_object' + - 'drm_exec_for_each_locked_object_reverse' + - 'drm_for_each_bridge_in_chain_scoped' + - 'drm_for_each_connector_iter' + - 'drm_for_each_crtc' + - 'drm_for_each_crtc_reverse' + - 'drm_for_each_encoder' + - 'drm_for_each_encoder_mask' + - 'drm_for_each_fb' + - 'drm_for_each_legacy_plane' + - 'drm_for_each_plane' + - 'drm_for_each_plane_mask' + - 'drm_for_each_privobj' + - 'drm_gem_for_each_gpuvm_bo' + - 'drm_gem_for_each_gpuvm_bo_safe' + - 'drm_gpusvm_for_each_range' + - 'drm_gpuva_for_each_op' + - 'drm_gpuva_for_each_op_from_reverse' + - 'drm_gpuva_for_each_op_reverse' + - 'drm_gpuva_for_each_op_safe' + - 'drm_gpuvm_bo_for_each_va' + - 'drm_gpuvm_bo_for_each_va_safe' + - 'drm_gpuvm_for_each_va' + - 'drm_gpuvm_for_each_va_range' + - 'drm_gpuvm_for_each_va_range_safe' + - 'drm_gpuvm_for_each_va_safe' + - 'drm_mm_for_each_hole' + - 'drm_mm_for_each_node' + - 'drm_mm_for_each_node_in_range' + - 'drm_mm_for_each_node_safe' + - 'dsa_switch_for_each_available_port' + - 'dsa_switch_for_each_cpu_port' + - 'dsa_switch_for_each_cpu_port_continue_reverse' + - 'dsa_switch_for_each_port' + - 'dsa_switch_for_each_port_continue_reverse' + - 'dsa_switch_for_each_port_safe' + - 'dsa_switch_for_each_user_port' + - 'dsa_switch_for_each_user_port_continue_reverse' + - 'dsa_tree_for_each_cpu_port' + - 'dsa_tree_for_each_user_port' + - 'dsa_tree_for_each_user_port_continue_reverse' + - 'dso__for_each_symbol' + - 'elf_hash_for_each_possible' + - 'elf_symtab__for_each_symbol' + - 'evlist__for_each_cpu' + - 'evlist__for_each_entry' + - 'evlist__for_each_entry_continue' + - 'evlist__for_each_entry_from' + - 'evlist__for_each_entry_reverse' + - 'evlist__for_each_entry_safe' + - 'flow_action_for_each' + - 'for_each_acpi_consumer_dev' + - 'for_each_acpi_dev_match' + - 'for_each_active_dev_scope' + - 'for_each_active_drhd_unit' + - 'for_each_active_iommu' + - 'for_each_active_irq' + - 'for_each_active_route' + - 'for_each_aggr_pgid' + - 'for_each_alloc_capable_rdt_resource' + - 'for_each_and_bit' + - 'for_each_andnot_bit' + - 'for_each_available_child_of_node' + - 'for_each_available_child_of_node_scoped' + - 'for_each_bench' + - 'for_each_bio' + - 'for_each_board_func_rsrc' + - 'for_each_btf_ext_rec' + - 'for_each_btf_ext_sec' + - 'for_each_bvec' + - 'for_each_capable_rdt_resource' + - 'for_each_card_auxs' + - 'for_each_card_auxs_safe' + - 'for_each_card_components' + - 'for_each_card_dapms' + - 'for_each_card_pre_auxs' + - 'for_each_card_prelinks' + - 'for_each_card_rtds' + - 'for_each_card_rtds_safe' + - 'for_each_card_widgets' + - 'for_each_card_widgets_safe' + - 'for_each_cgroup_storage_type' + - 'for_each_child_of_node' + - 'for_each_child_of_node_scoped' + - 'for_each_child_of_node_with_prefix' + - 'for_each_clear_bit' + - 'for_each_clear_bit_from' + - 'for_each_clear_bitrange' + - 'for_each_clear_bitrange_from' + - 'for_each_cmd' + - 'for_each_cmsghdr' + - 'for_each_collection' + - 'for_each_comp_order' + - 'for_each_compatible_node' + - 'for_each_compatible_node_scoped' + - 'for_each_component_dais' + - 'for_each_component_dais_safe' + - 'for_each_conduit' + - 'for_each_console' + - 'for_each_console_srcu' + - 'for_each_cpu' + - 'for_each_cpu_and' + - 'for_each_cpu_andnot' + - 'for_each_cpu_from' + - 'for_each_cpu_or' + - 'for_each_cpu_wrap' + - 'for_each_dapm_widgets' + - 'for_each_dedup_cand' + - 'for_each_dev_addr' + - 'for_each_dev_scope' + - 'for_each_dma_cap_mask' + - 'for_each_dpcm_be' + - 'for_each_dpcm_be_rollback' + - 'for_each_dpcm_be_safe' + - 'for_each_dpcm_fe' + - 'for_each_drhd_unit' + - 'for_each_dss_dev' + - 'for_each_efi_memory_desc' + - 'for_each_efi_memory_desc_in_map' + - 'for_each_element' + - 'for_each_element_extid' + - 'for_each_element_id' + - 'for_each_enabled_cpu' + - 'for_each_endpoint_of_node' + - 'for_each_event' + - 'for_each_event_tps' + - 'for_each_evictable_lru' + - 'for_each_fib6_node_rt_rcu' + - 'for_each_fib6_walker_rt' + - 'for_each_file_lock' + - 'for_each_free_mem_range' + - 'for_each_free_mem_range_reverse' + - 'for_each_func_rsrc' + - 'for_each_gpiochip_node' + - 'for_each_group_evsel' + - 'for_each_group_evsel_head' + - 'for_each_group_member' + - 'for_each_group_member_head' + - 'for_each_hstate' + - 'for_each_hwgpio' + - 'for_each_hwgpio_in_range' + - 'for_each_if' + - 'for_each_inject_fn' + - 'for_each_insn' + - 'for_each_insn_op_loc' + - 'for_each_insn_prefix' + - 'for_each_intid' + - 'for_each_iommu' + - 'for_each_ip_tunnel_rcu' + - 'for_each_irq_desc' + - 'for_each_irq_nr' + - 'for_each_lang' + - 'for_each_link_ch_maps' + - 'for_each_link_codecs' + - 'for_each_link_cpus' + - 'for_each_link_platforms' + - 'for_each_lru' + - 'for_each_matching_node' + - 'for_each_matching_node_and_match' + - 'for_each_media_entity_data_link' + - 'for_each_mem_pfn_range' + - 'for_each_mem_range' + - 'for_each_mem_range_rev' + - 'for_each_mem_region' + - 'for_each_member' + - 'for_each_memory' + - 'for_each_migratetype_order' + - 'for_each_missing_reg' + - 'for_each_mle_subelement' + - 'for_each_mod_mem_type' + - 'for_each_mon_capable_rdt_resource' + - 'for_each_mp_bvec' + - 'for_each_net' + - 'for_each_net_continue_reverse' + - 'for_each_net_rcu' + - 'for_each_netdev' + - 'for_each_netdev_continue' + - 'for_each_netdev_continue_rcu' + - 'for_each_netdev_continue_reverse' + - 'for_each_netdev_dump' + - 'for_each_netdev_feature' + - 'for_each_netdev_in_bond_rcu' + - 'for_each_netdev_rcu' + - 'for_each_netdev_reverse' + - 'for_each_netdev_safe' + - 'for_each_new_connector_in_state' + - 'for_each_new_crtc_in_state' + - 'for_each_new_mst_mgr_in_state' + - 'for_each_new_plane_in_state' + - 'for_each_new_plane_in_state_reverse' + - 'for_each_new_private_obj_in_state' + - 'for_each_new_reg' + - 'for_each_nhlt_endpoint' + - 'for_each_nhlt_endpoint_fmtcfg' + - 'for_each_nhlt_fmtcfg' + - 'for_each_node' + - 'for_each_node_by_name' + - 'for_each_node_by_type' + - 'for_each_node_mask' + - 'for_each_node_numadist' + - 'for_each_node_state' + - 'for_each_node_with_cpus' + - 'for_each_node_with_property' + - 'for_each_nonreserved_multicast_dest_pgid' + - 'for_each_numa_hop_mask' + - 'for_each_of_allnodes' + - 'for_each_of_allnodes_from' + - 'for_each_of_cpu_node' + - 'for_each_of_graph_port' + - 'for_each_of_graph_port_endpoint' + - 'for_each_of_pci_range' + - 'for_each_old_connector_in_state' + - 'for_each_old_crtc_in_state' + - 'for_each_old_mst_mgr_in_state' + - 'for_each_old_plane_in_state' + - 'for_each_old_private_obj_in_state' + - 'for_each_oldnew_connector_in_state' + - 'for_each_oldnew_crtc_in_state' + - 'for_each_oldnew_mst_mgr_in_state' + - 'for_each_oldnew_plane_in_state' + - 'for_each_oldnew_plane_in_state_reverse' + - 'for_each_oldnew_private_obj_in_state' + - 'for_each_online_cpu' + - 'for_each_online_cpu_wrap' + - 'for_each_online_node' + - 'for_each_online_pgdat' + - 'for_each_or_bit' + - 'for_each_page_ext' + - 'for_each_path' + - 'for_each_pci_bridge' + - 'for_each_pci_dev' + - 'for_each_pcm_streams' + - 'for_each_physmem_range' + - 'for_each_populated_zone' + - 'for_each_possible_cpu' + - 'for_each_possible_cpu_wrap' + - 'for_each_present_blessed_reg' + - 'for_each_present_cpu' + - 'for_each_present_section_nr' + - 'for_each_prime_number' + - 'for_each_prime_number_from' + - 'for_each_probe_cache_entry' + - 'for_each_process' + - 'for_each_process_thread' + - 'for_each_prop_codec_conf' + - 'for_each_prop_dai_codec' + - 'for_each_prop_dai_cpu' + - 'for_each_prop_dlc_codecs' + - 'for_each_prop_dlc_cpus' + - 'for_each_prop_dlc_platforms' + - 'for_each_property_of_node' + - 'for_each_pt_level_entry' + - 'for_each_rdt_resource' + - 'for_each_reg' + - 'for_each_reg_filtered' + - 'for_each_reloc' + - 'for_each_reloc_from' + - 'for_each_requested_gpio' + - 'for_each_requested_gpio_in_range' + - 'for_each_reserved_child_of_node' + - 'for_each_reserved_mem_range' + - 'for_each_reserved_mem_region' + - 'for_each_rtd_ch_maps' + - 'for_each_rtd_codec_dais' + - 'for_each_rtd_components' + - 'for_each_rtd_cpu_dais' + - 'for_each_rtd_dais' + - 'for_each_rtd_dais_reverse' + - 'for_each_sband_iftype_data' + - 'for_each_script' + - 'for_each_sec' + - 'for_each_set_bit' + - 'for_each_set_bit_from' + - 'for_each_set_bit_wrap' + - 'for_each_set_bitrange' + - 'for_each_set_bitrange_from' + - 'for_each_set_clump8' + - 'for_each_sg' + - 'for_each_sg_dma_page' + - 'for_each_sg_page' + - 'for_each_sgtable_dma_page' + - 'for_each_sgtable_dma_sg' + - 'for_each_sgtable_page' + - 'for_each_sgtable_sg' + - 'for_each_sibling_event' + - 'for_each_sta_active_link' + - 'for_each_subelement' + - 'for_each_subelement_extid' + - 'for_each_subelement_id' + - 'for_each_sublist' + - 'for_each_subsystem' + - 'for_each_suite' + - 'for_each_supported_activate_fn' + - 'for_each_supported_inject_fn' + - 'for_each_sym' + - 'for_each_thread' + - 'for_each_token' + - 'for_each_unicast_dest_pgid' + - 'for_each_valid_link' + - 'for_each_vif_active_link' + - 'for_each_vma' + - 'for_each_vma_range' + - 'for_each_vsi' + - 'for_each_wakeup_source' + - 'for_each_zone' + - 'for_each_zone_zonelist' + - 'for_each_zone_zonelist_nodemask' + - 'func_for_each_insn' + - 'fwnode_for_each_available_child_node' + - 'fwnode_for_each_child_node' + - 'fwnode_for_each_parent_node' + - 'fwnode_graph_for_each_endpoint' + - 'gadget_for_each_ep' + - 'genradix_for_each' + - 'genradix_for_each_from' + - 'genradix_for_each_reverse' + - 'guard' + - 'hash_for_each' + - 'hash_for_each_possible' + - 'hash_for_each_possible_rcu' + - 'hash_for_each_possible_rcu_notrace' + - 'hash_for_each_possible_safe' + - 'hash_for_each_rcu' + - 'hash_for_each_safe' + - 'hashmap__for_each_entry' + - 'hashmap__for_each_entry_safe' + - 'hashmap__for_each_key_entry' + - 'hashmap__for_each_key_entry_safe' + - 'hctx_for_each_ctx' + - 'hists__for_each_format' + - 'hists__for_each_sort_list' + - 'hlist_bl_for_each_entry' + - 'hlist_bl_for_each_entry_rcu' + - 'hlist_bl_for_each_entry_safe' + - 'hlist_for_each' + - 'hlist_for_each_entry' + - 'hlist_for_each_entry_continue' + - 'hlist_for_each_entry_continue_rcu' + - 'hlist_for_each_entry_continue_rcu_bh' + - 'hlist_for_each_entry_from' + - 'hlist_for_each_entry_from_rcu' + - 'hlist_for_each_entry_rcu' + - 'hlist_for_each_entry_rcu_bh' + - 'hlist_for_each_entry_rcu_notrace' + - 'hlist_for_each_entry_safe' + - 'hlist_for_each_entry_srcu' + - 'hlist_for_each_safe' + - 'hlist_nulls_for_each_entry' + - 'hlist_nulls_for_each_entry_from' + - 'hlist_nulls_for_each_entry_rcu' + - 'hlist_nulls_for_each_entry_safe' + - 'i3c_bus_for_each_i2cdev' + - 'i3c_bus_for_each_i3cdev' + - 'idr_for_each_entry' + - 'idr_for_each_entry_continue' + - 'idr_for_each_entry_continue_ul' + - 'idr_for_each_entry_ul' + - 'iio_for_each_active_channel' + - 'in_dev_for_each_ifa_rcu' + - 'in_dev_for_each_ifa_rtnl' + - 'in_dev_for_each_ifa_rtnl_net' + - 'inet_bind_bucket_for_each' + - 'interval_tree_for_each_span' + - 'intlist__for_each_entry' + - 'intlist__for_each_entry_safe' + - 'kcore_copy__for_each_phdr' + - 'key_for_each' + - 'key_for_each_safe' + - 'klp_for_each_func' + - 'klp_for_each_func_safe' + - 'klp_for_each_func_static' + - 'klp_for_each_object' + - 'klp_for_each_object_safe' + - 'klp_for_each_object_static' + - 'kunit_suite_for_each_test_case' + - 'kvm_for_each_memslot' + - 'kvm_for_each_memslot_in_gfn_range' + - 'kvm_for_each_vcpu' + - 'libbpf_nla_for_each_attr' + - 'list_for_each' + - 'list_for_each_codec' + - 'list_for_each_codec_safe' + - 'list_for_each_continue' + - 'list_for_each_entry' + - 'list_for_each_entry_continue' + - 'list_for_each_entry_continue_rcu' + - 'list_for_each_entry_continue_reverse' + - 'list_for_each_entry_from' + - 'list_for_each_entry_from_rcu' + - 'list_for_each_entry_from_reverse' + - 'list_for_each_entry_lockless' + - 'list_for_each_entry_rcu' + - 'list_for_each_entry_reverse' + - 'list_for_each_entry_safe' + - 'list_for_each_entry_safe_continue' + - 'list_for_each_entry_safe_from' + - 'list_for_each_entry_safe_reverse' + - 'list_for_each_entry_srcu' + - 'list_for_each_from' + - 'list_for_each_prev' + - 'list_for_each_prev_safe' + - 'list_for_each_rcu' + - 'list_for_each_safe' + - 'llist_for_each' + - 'llist_for_each_entry' + - 'llist_for_each_entry_safe' + - 'llist_for_each_safe' + - 'lwq_for_each_safe' + - 'map__for_each_symbol' + - 'map__for_each_symbol_by_name' + - 'mas_for_each' + - 'mas_for_each_rev' + - 'mci_for_each_dimm' + - 'media_device_for_each_entity' + - 'media_device_for_each_intf' + - 'media_device_for_each_link' + - 'media_device_for_each_pad' + - 'media_entity_for_each_pad' + - 'media_pipeline_for_each_entity' + - 'media_pipeline_for_each_pad' + - 'mlx5_lag_for_each_peer_mdev' + - 'mptcp_for_each_subflow' + - 'msi_domain_for_each_desc' + - 'msi_for_each_desc' + - 'mt_for_each' + - 'nanddev_io_for_each_block' + - 'nanddev_io_for_each_page' + - 'neigh_for_each_in_bucket' + - 'neigh_for_each_in_bucket_rcu' + - 'neigh_for_each_in_bucket_safe' + - 'netdev_for_each_lower_dev' + - 'netdev_for_each_lower_private' + - 'netdev_for_each_lower_private_rcu' + - 'netdev_for_each_mc_addr' + - 'netdev_for_each_synced_mc_addr' + - 'netdev_for_each_synced_uc_addr' + - 'netdev_for_each_uc_addr' + - 'netdev_for_each_upper_dev_rcu' + - 'netdev_hw_addr_list_for_each' + - 'nft_rule_for_each_expr' + - 'nla_for_each_attr' + - 'nla_for_each_attr_type' + - 'nla_for_each_nested' + - 'nla_for_each_nested_type' + - 'nlmsg_for_each_attr' + - 'nlmsg_for_each_msg' + - 'nr_neigh_for_each' + - 'nr_neigh_for_each_safe' + - 'nr_node_for_each' + - 'nr_node_for_each_safe' + - 'of_for_each_phandle' + - 'of_property_for_each_string' + - 'of_property_for_each_u32' + - 'pci_bus_for_each_resource' + - 'pci_dev_for_each_resource' + - 'pcl_for_each_chunk' + - 'pcl_for_each_segment' + - 'pcm_for_each_format' + - 'perf_config_items__for_each_entry' + - 'perf_config_sections__for_each_entry' + - 'perf_config_set__for_each_entry' + - 'perf_cpu_map__for_each_cpu' + - 'perf_cpu_map__for_each_cpu_skip_any' + - 'perf_cpu_map__for_each_idx' + - 'perf_evlist__for_each_entry' + - 'perf_evlist__for_each_entry_reverse' + - 'perf_evlist__for_each_entry_safe' + - 'perf_evlist__for_each_evsel' + - 'perf_evlist__for_each_mmap' + - 'perf_evsel_for_each_per_thread_period_safe' + - 'perf_hpp_list__for_each_format' + - 'perf_hpp_list__for_each_format_safe' + - 'perf_hpp_list__for_each_sort_list' + - 'perf_hpp_list__for_each_sort_list_safe' + - 'plist_for_each' + - 'plist_for_each_continue' + - 'plist_for_each_entry' + - 'plist_for_each_entry_continue' + - 'plist_for_each_entry_safe' + - 'plist_for_each_safe' + - 'pnp_for_each_card' + - 'pnp_for_each_dev' + - 'protocol_for_each_card' + - 'protocol_for_each_dev' + - 'queue_for_each_hw_ctx' + - 'radix_tree_for_each_slot' + - 'radix_tree_for_each_tagged' + - 'rb_for_each' + - 'rbtree_postorder_for_each_entry_safe' + - 'rdma_for_each_block' + - 'rdma_for_each_port' + - 'rdma_umem_for_each_dma_block' + - 'resource_list_for_each_entry' + - 'resource_list_for_each_entry_safe' + - 'rhl_for_each_entry_rcu' + - 'rhl_for_each_rcu' + - 'rht_for_each' + - 'rht_for_each_entry' + - 'rht_for_each_entry_from' + - 'rht_for_each_entry_rcu' + - 'rht_for_each_entry_rcu_from' + - 'rht_for_each_entry_safe' + - 'rht_for_each_from' + - 'rht_for_each_rcu' + - 'rht_for_each_rcu_from' + - 'rq_for_each_bvec' + - 'rq_for_each_segment' + - 'rq_list_for_each' + - 'rq_list_for_each_safe' + - 'sample_read_group__for_each' + - 'scoped_guard' + - 'scsi_for_each_prot_sg' + - 'scsi_for_each_sg' + - 'sctp_for_each_hentry' + - 'sctp_skb_for_each' + - 'sec_for_each_insn' + - 'sec_for_each_insn_continue' + - 'sec_for_each_insn_from' + - 'sec_for_each_sym' + - 'shdma_for_each_chan' + - 'shost_for_each_device' + - 'sk_for_each' + - 'sk_for_each_bound' + - 'sk_for_each_bound_safe' + - 'sk_for_each_entry_offset_rcu' + - 'sk_for_each_from' + - 'sk_for_each_rcu' + - 'sk_for_each_safe' + - 'sk_nulls_for_each' + - 'sk_nulls_for_each_from' + - 'sk_nulls_for_each_rcu' + - 'snd_array_for_each' + - 'snd_pcm_group_for_each_entry' + - 'snd_soc_dapm_widget_for_each_path' + - 'snd_soc_dapm_widget_for_each_path_safe' + - 'snd_soc_dapm_widget_for_each_sink_path' + - 'snd_soc_dapm_widget_for_each_source_path' + - 'sparsebit_for_each_set_range' + - 'strlist__for_each_entry' + - 'strlist__for_each_entry_safe' + - 'sym_for_each_insn' + - 'sym_for_each_insn_continue_reverse' + - 'symbols__for_each_entry' + - 'tb_property_for_each' + - 'tcf_act_for_each_action' + - 'tcf_exts_for_each_action' + - 'test_suite__for_each_test_case' + - 'tool_pmu__for_each_event' + - 'ttm_bo_lru_for_each_reserved_guarded' + - 'ttm_resource_manager_for_each_res' + - 'udp_lrpa_for_each_entry_rcu' + - 'udp_portaddr_for_each_entry' + - 'udp_portaddr_for_each_entry_rcu' + - 'usb_hub_for_each_child' + - 'v4l2_device_for_each_subdev' + - 'v4l2_m2m_for_each_dst_buf' + - 'v4l2_m2m_for_each_dst_buf_safe' + - 'v4l2_m2m_for_each_src_buf' + - 'v4l2_m2m_for_each_src_buf_safe' + - 'virtio_device_for_each_vq' + - 'vkms_config_for_each_connector' + - 'vkms_config_for_each_crtc' + - 'vkms_config_for_each_encoder' + - 'vkms_config_for_each_plane' + - 'vkms_config_connector_for_each_possible_encoder' + - 'vkms_config_encoder_for_each_possible_crtc' + - 'vkms_config_plane_for_each_possible_crtc' + - 'while_for_each_ftrace_op' + - 'workloads__for_each' + - 'xa_for_each' + - 'xa_for_each_marked' + - 'xa_for_each_range' + - 'xa_for_each_start' + - 'xas_for_each' + - 'xas_for_each_conflict' + - 'xas_for_each_marked' + - 'xbc_array_for_each_value' + - 'xbc_for_each_key_value' + - 'xbc_node_for_each_array_value' + - 'xbc_node_for_each_child' + - 'xbc_node_for_each_key_value' + - 'xbc_node_for_each_subkey' + - 'ynl_attr_for_each' + - 'ynl_attr_for_each_nested' + - 'ynl_attr_for_each_payload' + - 'zorro_for_each_dev' + - 'zpci_bus_for_each' + +IncludeBlocks: Preserve +IncludeCategories: + - Regex: '.*' + Priority: 1 +IncludeIsMainRegex: '(Test)?$' +IndentCaseLabels: false +IndentGotoLabels: false +IndentPPDirectives: None +IndentWidth: 8 +IndentWrappedFunctionNames: false +JavaScriptQuotes: Leave +JavaScriptWrapImports: true +KeepEmptyLinesAtTheStartOfBlocks: false +MacroBlockBegin: '' +MacroBlockEnd: '' +MaxEmptyLinesToKeep: 1 +NamespaceIndentation: None +ObjCBinPackProtocolList: Auto +ObjCBlockIndentWidth: 8 +ObjCSpaceAfterProperty: true +ObjCSpaceBeforeProtocolList: true + +# Taken from git's rules +PenaltyBreakAssignment: 10 +PenaltyBreakBeforeFirstCallParameter: 30 +PenaltyBreakComment: 10 +PenaltyBreakFirstLessLess: 0 +PenaltyBreakString: 10 +PenaltyExcessCharacter: 100 +PenaltyReturnTypeOnItsOwnLine: 60 + +PointerAlignment: Right +ReflowComments: false +SortIncludes: false +SortUsingDeclarations: false +SpaceAfterCStyleCast: false +SpaceAfterTemplateKeyword: true +SpaceBeforeAssignmentOperators: true +SpaceBeforeCtorInitializerColon: true +SpaceBeforeInheritanceColon: true +SpaceBeforeParens: ControlStatementsExceptForEachMacros +SpaceBeforeRangeBasedForLoopColon: true +SpaceInEmptyParentheses: false +SpacesBeforeTrailingComments: 1 +SpacesInAngles: false +SpacesInContainerLiterals: false +SpacesInCStyleCastParentheses: false +SpacesInParentheses: false +SpacesInSquareBrackets: false +Standard: Cpp03 +TabWidth: 8 +UseTab: Always +... diff --git a/linux/vibeshine-drm/generate_hdr_edid.py b/linux/vibeshine-drm/generate_hdr_edid.py index bb6424b..c11c363 100755 --- a/linux/vibeshine-drm/generate_hdr_edid.py +++ b/linux/vibeshine-drm/generate_hdr_edid.py @@ -78,9 +78,11 @@ def header(edid: bytes) -> str: "/* Generated by generate_hdr_edid.py; do not edit manually. */\n" "#ifndef VIBESHINE_HDR_EDID_H\n" "#define VIBESHINE_HDR_EDID_H\n\n" + "/* clang-format off */\n" "static const unsigned char vibeshine_hdr_edid[] = {\n" + "\n".join(rows) + "\n};\n" + "/* clang-format on */\n" "static const unsigned int vibeshine_hdr_edid_len = sizeof(vibeshine_hdr_edid);\n\n" "#endif\n" ) diff --git a/linux/vibeshine-drm/vibeshine_drm_capture.h b/linux/vibeshine-drm/vibeshine_drm_capture.h index 115c51c..7952d66 100644 --- a/linux/vibeshine-drm/vibeshine_drm_capture.h +++ b/linux/vibeshine-drm/vibeshine_drm_capture.h @@ -12,28 +12,33 @@ struct vibeshine_capture_state { unsigned int readers; unsigned int retiring; }; -static inline bool vibeshine_capture_acquire(struct vibeshine_capture_state *state, bool stopping) +static inline bool +vibeshine_capture_acquire(struct vibeshine_capture_state *state, bool stopping) { - if (stopping || state->retiring || state->readers >= VIBESHINE_CAPTURE_MAX_READERS) + if (stopping || state->retiring || + state->readers >= VIBESHINE_CAPTURE_MAX_READERS) return false; state->readers++; return true; } -static inline bool vibeshine_capture_release(struct vibeshine_capture_state *state) +static inline bool +vibeshine_capture_release(struct vibeshine_capture_state *state) { if (!state->readers) return false; state->readers--; return true; } -static inline bool vibeshine_capture_retire(struct vibeshine_capture_state *state, bool nonblock) +static inline bool +vibeshine_capture_retire(struct vibeshine_capture_state *state, bool nonblock) { if (state->readers && !nonblock) return false; state->retiring++; return true; } -static inline bool vibeshine_capture_publish(struct vibeshine_capture_state *state) +static inline bool +vibeshine_capture_publish(struct vibeshine_capture_state *state) { if (!state->retiring) return false; diff --git a/linux/vibeshine-drm/vibeshine_drm_change.h b/linux/vibeshine-drm/vibeshine_drm_change.h index a40031a..b192565 100644 --- a/linux/vibeshine-drm/vibeshine_drm_change.h +++ b/linux/vibeshine-drm/vibeshine_drm_change.h @@ -75,8 +75,7 @@ struct vibeshine_drm_connector_snapshot { unsigned int privacy_screen_sw_state; }; -static inline bool -vibeshine_drm_plane_changes_scanout( +static inline bool vibeshine_drm_plane_changes_scanout( const struct vibeshine_drm_plane_snapshot *old_state, const struct vibeshine_drm_plane_snapshot *new_state) { @@ -109,8 +108,7 @@ vibeshine_drm_plane_changes_scanout( return new_state->content_update; } -static inline bool -vibeshine_drm_crtc_changes_scanout( +static inline bool vibeshine_drm_crtc_changes_scanout( const struct vibeshine_drm_crtc_snapshot *old_state, const struct vibeshine_drm_crtc_snapshot *new_state) { @@ -131,8 +129,7 @@ vibeshine_drm_crtc_changes_scanout( new_state->color_mgmt_changed; } -static inline bool -vibeshine_drm_connector_changes_scanout( +static inline bool vibeshine_drm_connector_changes_scanout( const struct vibeshine_drm_connector_snapshot *old_state, const struct vibeshine_drm_connector_snapshot *new_state) { @@ -140,9 +137,11 @@ vibeshine_drm_connector_changes_scanout( old_state->self_refresh_aware != new_state->self_refresh_aware || old_state->crtc != new_state->crtc || old_state->best_encoder != new_state->best_encoder || - old_state->hdr_output_metadata != new_state->hdr_output_metadata || + old_state->hdr_output_metadata != + new_state->hdr_output_metadata || old_state->link_status != new_state->link_status || - old_state->picture_aspect_ratio != new_state->picture_aspect_ratio || + old_state->picture_aspect_ratio != + new_state->picture_aspect_ratio || old_state->content_type != new_state->content_type || old_state->hdcp_content_type != new_state->hdcp_content_type || old_state->scaling_mode != new_state->scaling_mode || @@ -150,7 +149,8 @@ vibeshine_drm_connector_changes_scanout( old_state->colorspace != new_state->colorspace || old_state->max_requested_bpc != new_state->max_requested_bpc || old_state->max_bpc != new_state->max_bpc || - old_state->privacy_screen_sw_state != new_state->privacy_screen_sw_state; + old_state->privacy_screen_sw_state != + new_state->privacy_screen_sw_state; } #endif /* _VIBESHINE_DRM_CHANGE_H_ */ diff --git a/linux/vibeshine-drm/vibeshine_drm_dumb.c b/linux/vibeshine-drm/vibeshine_drm_dumb.c index c998fa6..1b1ca8a 100644 --- a/linux/vibeshine-drm/vibeshine_drm_dumb.c +++ b/linux/vibeshine-drm/vibeshine_drm_dumb.c @@ -10,7 +10,7 @@ #include "vibeshine_drm_dumb.h" int vkms_dumb_create(struct drm_file *file, struct drm_device *dev, - struct drm_mode_create_dumb *args) + struct drm_mode_create_dumb *args) { struct drm_mode_create_dumb allocation = *args; u32 pitch_bits, size; diff --git a/linux/vibeshine-drm/vibeshine_drm_dumb.h b/linux/vibeshine-drm/vibeshine_drm_dumb.h index 632ec2d..ac90100 100644 --- a/linux/vibeshine-drm/vibeshine_drm_dumb.h +++ b/linux/vibeshine-drm/vibeshine_drm_dumb.h @@ -13,7 +13,6 @@ int vkms_dumb_create(struct drm_file *file, struct drm_device *dev, /* Shared registration for the module and the production-component tests. */ #define VIBESHINE_DRM_SHMEM_DRIVER_OPS \ - VIBESHINE_DRM_SHMEM_PRIME_DRIVER_OPS, \ - .dumb_create = vkms_dumb_create + VIBESHINE_DRM_SHMEM_PRIME_DRIVER_OPS, .dumb_create = vkms_dumb_create #endif /* _VIBESHINE_DRM_DUMB_H_ */ diff --git a/linux/vibeshine-drm/vibeshine_drm_mode.h b/linux/vibeshine-drm/vibeshine_drm_mode.h index 4d9505b..502f65b 100644 --- a/linux/vibeshine-drm/vibeshine_drm_mode.h +++ b/linux/vibeshine-drm/vibeshine_drm_mode.h @@ -16,15 +16,15 @@ struct vibeshine_drm_requested_mode { static inline int vibeshine_drm_requested_mode_valid( const struct vibeshine_drm_requested_mode *mode) { - return mode->width >= 64 && mode->width <= 8192 && - mode->height >= 64 && mode->height <= 8192 && + return mode->width >= 64 && mode->width <= 8192 && mode->height >= 64 && + mode->height <= 8192 && mode->refresh_millihz >= VIBESHINE_DRM_MIN_REFRESH_MILLIHZ && mode->refresh_millihz <= VIBESHINE_DRM_MAX_REFRESH_MILLIHZ; } -static inline int vibeshine_drm_doubled_mode( - const struct vibeshine_drm_requested_mode *mode, - struct vibeshine_drm_requested_mode *doubled) +static inline int +vibeshine_drm_doubled_mode(const struct vibeshine_drm_requested_mode *mode, + struct vibeshine_drm_requested_mode *doubled) { if (!vibeshine_drm_requested_mode_valid(mode) || mode->refresh_millihz > VIBESHINE_DRM_MAX_REFRESH_MILLIHZ / 2) diff --git a/linux/vibeshine-drm/vibeshine_drm_present.h b/linux/vibeshine-drm/vibeshine_drm_present.h index 9e7a4c3..aec0ec8 100644 --- a/linux/vibeshine-drm/vibeshine_drm_present.h +++ b/linux/vibeshine-drm/vibeshine_drm_present.h @@ -24,9 +24,9 @@ vibeshine_drm_present_timing_arm(struct vibeshine_drm_present_timing *timing) timing->pending = true; } -static inline bool -vibeshine_drm_present_timing_complete(struct vibeshine_drm_present_timing *timing, - bool flip_complete, __u64 event_timestamp_ns) +static inline bool vibeshine_drm_present_timing_complete( + struct vibeshine_drm_present_timing *timing, bool flip_complete, + __u64 event_timestamp_ns) { if (!timing->pending || !flip_complete || !event_timestamp_ns) return false; @@ -37,11 +37,12 @@ vibeshine_drm_present_timing_complete(struct vibeshine_drm_present_timing *timin static inline __u64 vibeshine_drm_present_timing_finish(struct vibeshine_drm_present_timing *timing, - __u64 fallback_timestamp_ns) + __u64 fallback_timestamp_ns) { /* Disarm even on a flip timeout; a later event must not alter this frame. */ timing->pending = false; - return timing->timestamp_ns ? timing->timestamp_ns : fallback_timestamp_ns; + return timing->timestamp_ns ? timing->timestamp_ns : + fallback_timestamp_ns; } enum vibeshine_drm_present_wait_decision_e { @@ -50,8 +51,8 @@ enum vibeshine_drm_present_wait_decision_e { VIBESHINE_DRM_PRESENT_REJECT_BUSY, }; -static inline bool -vibeshine_drm_present_request_valid(const struct vibeshine_drm_wait_present *request) +static inline bool vibeshine_drm_present_request_valid( + const struct vibeshine_drm_wait_present *request) { return request->abi_version == VIBESHINE_DRM_PRESENT_ABI_VERSION && request->timeout_ms <= VIBESHINE_DRM_PRESENT_MAX_TIMEOUT_MS && @@ -59,9 +60,9 @@ vibeshine_drm_present_request_valid(const struct vibeshine_drm_wait_present *req } static inline enum vibeshine_drm_present_wait_decision_e -vibeshine_drm_present_decide_wait(const struct vibeshine_drm_wait_present *request, - __u64 current_sequence, - unsigned int waiter_count) +vibeshine_drm_present_decide_wait( + const struct vibeshine_drm_wait_present *request, + __u64 current_sequence, unsigned int waiter_count) { /* * A completed sequence is immediately consumable even when a newer atomic @@ -76,17 +77,15 @@ vibeshine_drm_present_decide_wait(const struct vibeshine_drm_wait_present *reque return VIBESHINE_DRM_PRESENT_REGISTER_WAITER; } -static inline void -vibeshine_drm_present_complete_response(struct vibeshine_drm_wait_present *request, - __u64 requested_sequence, - __u64 current_sequence, - __u64 timestamp_ns, - bool presentation_pending) +static inline void vibeshine_drm_present_complete_response( + struct vibeshine_drm_wait_present *request, __u64 requested_sequence, + __u64 current_sequence, __u64 timestamp_ns, bool presentation_pending) { request->sequence = current_sequence; request->timestamp_ns = timestamp_ns; request->flags = current_sequence != requested_sequence ? - VIBESHINE_DRM_PRESENT_CHANGED : VIBESHINE_DRM_PRESENT_TIMEOUT; + VIBESHINE_DRM_PRESENT_CHANGED : + VIBESHINE_DRM_PRESENT_TIMEOUT; if (presentation_pending) request->flags |= VIBESHINE_DRM_PRESENT_PENDING; } diff --git a/linux/vibeshine-drm/vibeshine_drm_vrr.h b/linux/vibeshine-drm/vibeshine_drm_vrr.h index 4c9e040..9dfd2d6 100644 --- a/linux/vibeshine-drm/vibeshine_drm_vrr.h +++ b/linux/vibeshine-drm/vibeshine_drm_vrr.h @@ -11,8 +11,8 @@ */ static inline unsigned long long vibeshine_drm_vrr_presentation_deadline_ns(unsigned long long previous_ns, - unsigned long long now_ns, - unsigned long long period_ns) + unsigned long long now_ns, + unsigned long long period_ns) { unsigned long long deadline_ns; diff --git a/linux/vibeshine-drm/vibeshine_hdr_edid.h b/linux/vibeshine-drm/vibeshine_hdr_edid.h index 0925492..2d42e6c 100644 --- a/linux/vibeshine-drm/vibeshine_hdr_edid.h +++ b/linux/vibeshine-drm/vibeshine_hdr_edid.h @@ -2,6 +2,7 @@ #ifndef VIBESHINE_HDR_EDID_H #define VIBESHINE_HDR_EDID_H +/* clang-format off */ static const unsigned char vibeshine_hdr_edid[] = { 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x58, 0x53, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x20, 0x01, 0x03, 0x80, 0x3c, 0x22, 0x78, @@ -26,6 +27,7 @@ static const unsigned char vibeshine_hdr_edid[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xde, }; +/* clang-format on */ static const unsigned int vibeshine_hdr_edid_len = sizeof(vibeshine_hdr_edid); #endif diff --git a/linux/vibeshine-drm/vkms_capture.c b/linux/vibeshine-drm/vkms_capture.c index 38a6bc3..21fc8ff 100644 --- a/linux/vibeshine-drm/vkms_capture.c +++ b/linux/vibeshine-drm/vkms_capture.c @@ -31,7 +31,8 @@ struct vkms_capture_lease *vkms_capture_lease_alloc(void) return lease; } -void vkms_capture_lease_begin(struct vkms_capture_lease *lease, struct vkms_output *output) +void vkms_capture_lease_begin(struct vkms_capture_lease *lease, + struct vkms_output *output) { lockdep_assert_held(&output->present_lock); lease->output = output; @@ -40,7 +41,8 @@ void vkms_capture_lease_begin(struct vkms_capture_lease *lease, struct vkms_outp static void vkms_capture_lease_release(struct kref *ref) { - struct vkms_capture_lease *lease = container_of(ref, struct vkms_capture_lease, refs); + struct vkms_capture_lease *lease = + container_of(ref, struct vkms_capture_lease, refs); struct vkms_output *output = lease->output; if (output) { unsigned long flags; @@ -68,16 +70,19 @@ void vkms_capture_wait(struct vkms_output *output) wait_event(output->capture_waitq, !READ_ONCE(output->capture.readers)); } -static int capture_attach(struct dma_buf *buf, struct dma_buf_attachment *attachment) +static int capture_attach(struct dma_buf *buf, + struct dma_buf_attachment *attachment) { struct vkms_capture_buffer *capture = buf->priv; - struct dma_buf_attachment *backing = dma_buf_attach(capture->backing, attachment->dev); + struct dma_buf_attachment *backing = + dma_buf_attach(capture->backing, attachment->dev); if (IS_ERR(backing)) return PTR_ERR(backing); attachment->priv = backing; return 0; } -static void capture_detach(struct dma_buf *buf, struct dma_buf_attachment *attachment) +static void capture_detach(struct dma_buf *buf, + struct dma_buf_attachment *attachment) { struct vkms_capture_buffer *capture = buf->priv; dma_buf_detach(capture->backing, attachment->priv); @@ -87,7 +92,8 @@ static struct sg_table *capture_map(struct dma_buf_attachment *attachment, { return dma_buf_map_attachment(attachment->priv, direction); } -static void capture_unmap(struct dma_buf_attachment *attachment, struct sg_table *table, +static void capture_unmap(struct dma_buf_attachment *attachment, + struct sg_table *table, enum dma_data_direction direction) { dma_buf_unmap_attachment(attachment->priv, table, direction); @@ -103,13 +109,14 @@ static void capture_release(struct dma_buf *buf) kfree(capture); } static const struct dma_buf_ops capture_ops = { - .attach = capture_attach, - .detach = capture_detach, - .map_dma_buf = capture_map, - .unmap_dma_buf = capture_unmap, - .release = capture_release, + .attach = capture_attach, + .detach = capture_detach, + .map_dma_buf = capture_map, + .unmap_dma_buf = capture_unmap, + .release = capture_release, }; -struct dma_buf *vkms_capture_wrap(struct dma_buf *backing, struct vkms_capture_lease *lease) +struct dma_buf *vkms_capture_wrap(struct dma_buf *backing, + struct vkms_capture_lease *lease) { DEFINE_DMA_BUF_EXPORT_INFO(info); struct vkms_capture_buffer *capture; diff --git a/linux/vibeshine-drm/vkms_capture.h b/linux/vibeshine-drm/vkms_capture.h index a668911..c7d8274 100644 --- a/linux/vibeshine-drm/vkms_capture.h +++ b/linux/vibeshine-drm/vkms_capture.h @@ -6,9 +6,11 @@ struct vkms_output; struct vkms_capture_lease; /* Called with present_lock held; allocation must precede taking that lock. */ struct vkms_capture_lease *vkms_capture_lease_alloc(void); -void vkms_capture_lease_begin(struct vkms_capture_lease *, struct vkms_output *); +void vkms_capture_lease_begin(struct vkms_capture_lease *, + struct vkms_output *); void vkms_capture_lease_put(struct vkms_capture_lease *); /* Consumes backing even on error. The exported object owns a lease reference. */ void vkms_capture_wait(struct vkms_output *); -struct dma_buf *vkms_capture_wrap(struct dma_buf *backing, struct vkms_capture_lease *); +struct dma_buf *vkms_capture_wrap(struct dma_buf *backing, + struct vkms_capture_lease *); #endif diff --git a/linux/vibeshine-drm/vkms_colorop.c b/linux/vibeshine-drm/vkms_colorop.c index e174f77..d200856 100644 --- a/linux/vibeshine-drm/vkms_colorop.c +++ b/linux/vibeshine-drm/vkms_colorop.c @@ -15,9 +15,8 @@ #if VIBESHINE_DRM_HAS_COLOR_PIPELINE -static const u64 supported_tfs = - BIT(DRM_COLOROP_1D_CURVE_SRGB_EOTF) | - BIT(DRM_COLOROP_1D_CURVE_SRGB_INV_EOTF); +static const u64 supported_tfs = BIT(DRM_COLOROP_1D_CURVE_SRGB_EOTF) | + BIT(DRM_COLOROP_1D_CURVE_SRGB_INV_EOTF); static const struct drm_colorop_funcs vkms_colorop_funcs = { .destroy = drm_colorop_destroy, @@ -25,7 +24,8 @@ static const struct drm_colorop_funcs vkms_colorop_funcs = { #define MAX_COLOR_PIPELINE_OPS 4 -static int vkms_initialize_color_pipeline(struct drm_plane *plane, struct drm_prop_enum_list *list) +static int vkms_initialize_color_pipeline(struct drm_plane *plane, + struct drm_prop_enum_list *list) { struct drm_colorop *ops[MAX_COLOR_PIPELINE_OPS]; struct drm_device *dev = plane->dev; @@ -42,7 +42,8 @@ static int vkms_initialize_color_pipeline(struct drm_plane *plane, struct drm_pr goto cleanup; } - ret = drm_plane_colorop_curve_1d_init(dev, ops[i], plane, &vkms_colorop_funcs, + ret = drm_plane_colorop_curve_1d_init(dev, ops[i], plane, + &vkms_colorop_funcs, supported_tfs, DRM_COLOROP_FLAG_ALLOW_BYPASS); if (ret) @@ -60,7 +61,8 @@ static int vkms_initialize_color_pipeline(struct drm_plane *plane, struct drm_pr goto cleanup; } - ret = drm_plane_colorop_ctm_3x4_init(dev, ops[i], plane, &vkms_colorop_funcs, + ret = drm_plane_colorop_ctm_3x4_init(dev, ops[i], plane, + &vkms_colorop_funcs, DRM_COLOROP_FLAG_ALLOW_BYPASS); if (ret) goto cleanup; @@ -77,7 +79,8 @@ static int vkms_initialize_color_pipeline(struct drm_plane *plane, struct drm_pr goto cleanup; } - ret = drm_plane_colorop_ctm_3x4_init(dev, ops[i], plane, &vkms_colorop_funcs, + ret = drm_plane_colorop_ctm_3x4_init(dev, ops[i], plane, + &vkms_colorop_funcs, DRM_COLOROP_FLAG_ALLOW_BYPASS); if (ret) goto cleanup; @@ -94,7 +97,8 @@ static int vkms_initialize_color_pipeline(struct drm_plane *plane, struct drm_pr goto cleanup; } - ret = drm_plane_colorop_curve_1d_init(dev, ops[i], plane, &vkms_colorop_funcs, + ret = drm_plane_colorop_curve_1d_init(dev, ops[i], plane, + &vkms_colorop_funcs, supported_tfs, DRM_COLOROP_FLAG_ALLOW_BYPASS); if (ret) @@ -102,7 +106,8 @@ static int vkms_initialize_color_pipeline(struct drm_plane *plane, struct drm_pr drm_colorop_set_next_property(ops[i - 1], ops[i]); - list->name = kasprintf(GFP_KERNEL, "Color Pipeline %d", ops[0]->base.id); + list->name = + kasprintf(GFP_KERNEL, "Color Pipeline %d", ops[0]->base.id); return 0; diff --git a/linux/vibeshine-drm/vkms_composer.c b/linux/vibeshine-drm/vkms_composer.c index ea119d4..278d0c7 100644 --- a/linux/vibeshine-drm/vkms_composer.c +++ b/linux/vibeshine-drm/vkms_composer.c @@ -46,7 +46,8 @@ static u16 pre_mul_blend_channel(u16 src, u16 dst, u16 alpha) * completely opaque background. */ static void pre_mul_alpha_blend(const struct line_buffer *stage_buffer, - struct line_buffer *output_buffer, int x_start, int pixel_count) + struct line_buffer *output_buffer, int x_start, + int pixel_count) { struct pixel_argb_u16 *out = &output_buffer->pixels[x_start]; const struct pixel_argb_u16 *in = &stage_buffer->pixels[x_start]; @@ -59,7 +60,6 @@ static void pre_mul_alpha_blend(const struct line_buffer *stage_buffer, } } - static void fill_background(const struct pixel_argb_u16 *background_color, struct line_buffer *output_buffer) { @@ -78,14 +78,16 @@ VISIBLE_IF_KUNIT u16 lerp_u16(u16 a, u16 b, s64 t) return drm_fixp2int_round(a_fp + delta); } -VISIBLE_IF_KUNIT s64 get_lut_index(const struct vkms_color_lut *lut, u16 channel_value) +VISIBLE_IF_KUNIT s64 get_lut_index(const struct vkms_color_lut *lut, + u16 channel_value) { s64 color_channel_fp = drm_int2fixp(channel_value); return drm_fixp_mul(color_channel_fp, lut->channel_value2index_ratio); } -VISIBLE_IF_KUNIT u16 apply_lut_to_channel_value(const struct vkms_color_lut *lut, u16 channel_value, +VISIBLE_IF_KUNIT u16 apply_lut_to_channel_value(const struct vkms_color_lut *lut, + u16 channel_value, enum lut_channel channel) { s64 lut_index = get_lut_index(lut, channel_value); @@ -103,7 +105,8 @@ VISIBLE_IF_KUNIT u16 apply_lut_to_channel_value(const struct vkms_color_lut *lut /* We're at the end of the LUT array, use same value for ceil and floor */ ceil_lut_value = floor_lut_value; else - ceil_lut_value = (__u16 *)&lut->base[drm_fixp2int_ceil(lut_index)]; + ceil_lut_value = + (__u16 *)&lut->base[drm_fixp2int_ceil(lut_index)]; floor_channel_value = floor_lut_value[channel]; ceil_channel_value = ceil_lut_value[channel]; @@ -112,8 +115,8 @@ VISIBLE_IF_KUNIT u16 apply_lut_to_channel_value(const struct vkms_color_lut *lut lut_index & DRM_FIXED_DECIMAL_MASK); } - -static void apply_lut(const struct vkms_crtc_state *crtc_state, struct line_buffer *output_buffer) +static void apply_lut(const struct vkms_crtc_state *crtc_state, + struct line_buffer *output_buffer) { if (!crtc_state->gamma_lut.base) return; @@ -124,9 +127,12 @@ static void apply_lut(const struct vkms_crtc_state *crtc_state, struct line_buff for (size_t x = 0; x < output_buffer->n_pixels; x++) { struct pixel_argb_u16 *pixel = &output_buffer->pixels[x]; - pixel->r = apply_lut_to_channel_value(&crtc_state->gamma_lut, pixel->r, LUT_RED); - pixel->g = apply_lut_to_channel_value(&crtc_state->gamma_lut, pixel->g, LUT_GREEN); - pixel->b = apply_lut_to_channel_value(&crtc_state->gamma_lut, pixel->b, LUT_BLUE); + pixel->r = apply_lut_to_channel_value(&crtc_state->gamma_lut, + pixel->r, LUT_RED); + pixel->g = apply_lut_to_channel_value(&crtc_state->gamma_lut, + pixel->g, LUT_GREEN); + pixel->b = apply_lut_to_channel_value(&crtc_state->gamma_lut, + pixel->b, LUT_BLUE); } } @@ -161,7 +167,8 @@ VISIBLE_IF_KUNIT void apply_3x4_matrix(struct pixel_argb_s32 *pixel, pixel->b = drm_fixp2int_round(bf); } -static void apply_colorop(struct pixel_argb_s32 *pixel, struct drm_colorop *colorop) +static void apply_colorop(struct pixel_argb_s32 *pixel, + struct drm_colorop *colorop) { struct drm_colorop_state *colorop_state = colorop->state; struct drm_device *dev = colorop->dev; @@ -169,14 +176,20 @@ static void apply_colorop(struct pixel_argb_s32 *pixel, struct drm_colorop *colo if (colorop->type == DRM_COLOROP_1D_CURVE) { switch (colorop_state->curve_1d_type) { case DRM_COLOROP_1D_CURVE_SRGB_INV_EOTF: - pixel->r = apply_lut_to_channel_value(&srgb_inv_eotf, pixel->r, LUT_RED); - pixel->g = apply_lut_to_channel_value(&srgb_inv_eotf, pixel->g, LUT_GREEN); - pixel->b = apply_lut_to_channel_value(&srgb_inv_eotf, pixel->b, LUT_BLUE); + pixel->r = apply_lut_to_channel_value( + &srgb_inv_eotf, pixel->r, LUT_RED); + pixel->g = apply_lut_to_channel_value( + &srgb_inv_eotf, pixel->g, LUT_GREEN); + pixel->b = apply_lut_to_channel_value( + &srgb_inv_eotf, pixel->b, LUT_BLUE); break; case DRM_COLOROP_1D_CURVE_SRGB_EOTF: - pixel->r = apply_lut_to_channel_value(&srgb_eotf, pixel->r, LUT_RED); - pixel->g = apply_lut_to_channel_value(&srgb_eotf, pixel->g, LUT_GREEN); - pixel->b = apply_lut_to_channel_value(&srgb_eotf, pixel->b, LUT_BLUE); + pixel->r = apply_lut_to_channel_value( + &srgb_eotf, pixel->r, LUT_RED); + pixel->g = apply_lut_to_channel_value( + &srgb_eotf, pixel->g, LUT_GREEN); + pixel->b = apply_lut_to_channel_value( + &srgb_eotf, pixel->b, LUT_BLUE); break; default: drm_WARN_ONCE(dev, true, @@ -187,17 +200,20 @@ static void apply_colorop(struct pixel_argb_s32 *pixel, struct drm_colorop *colo } else if (colorop->type == DRM_COLOROP_CTM_3X4) { if (colorop_state->data) apply_3x4_matrix(pixel, - (struct drm_color_ctm_3x4 *)colorop_state->data->data); + (struct drm_color_ctm_3x4 *) + colorop_state->data->data); } } -static void pre_blend_color_transform(const struct vkms_plane_state *plane_state, - struct line_buffer *output_buffer) +static void +pre_blend_color_transform(const struct vkms_plane_state *plane_state, + struct line_buffer *output_buffer) { struct pixel_argb_s32 pixel; for (size_t x = 0; x < output_buffer->n_pixels; x++) { - struct drm_colorop *colorop = plane_state->base.base.color_pipeline; + struct drm_colorop *colorop = + plane_state->base.base.color_pipeline; /* * Some operations, such as applying a BT709 encoding matrix, @@ -236,8 +252,9 @@ static void pre_blend_color_transform(const struct vkms_plane_state *plane_state } } #else -static void pre_blend_color_transform(const struct vkms_plane_state *plane_state, - struct line_buffer *output_buffer) +static void +pre_blend_color_transform(const struct vkms_plane_state *plane_state, + struct line_buffer *output_buffer) { (void)plane_state; (void)output_buffer; @@ -284,7 +301,8 @@ static enum pixel_read_direction direction_for_rotation(unsigned int rotation) else if (y == -1 && x == 0) return READ_BOTTOM_TO_TOP; - WARN_ONCE(true, "The inverse of the rotation gives an incorrect direction."); + WARN_ONCE(true, + "The inverse of the rotation gives an incorrect direction."); return READ_LEFT_TO_RIGHT; } @@ -308,8 +326,9 @@ static enum pixel_read_direction direction_for_rotation(unsigned int rotation) */ static void clamp_line_coordinates(enum pixel_read_direction direction, const struct vkms_plane_state *current_plane, - const struct drm_rect *src_line, int *src_x_start, - int *src_y_start, int *dst_x_start, int *pixel_count) + const struct drm_rect *src_line, + int *src_x_start, int *src_y_start, + int *dst_x_start, int *pixel_count) { /* By default the start points are correct */ *src_x_start = src_line->x1; @@ -342,9 +361,11 @@ static void clamp_line_coordinates(enum pixel_read_direction direction, *dst_x_start -= *src_x_start; *src_x_start = 0; } - if (*src_x_start + *pixel_count > current_plane->frame_info->fb->width) - *pixel_count = max(0, (int)current_plane->frame_info->fb->width - - *src_x_start); + if (*src_x_start + *pixel_count > + current_plane->frame_info->fb->width) + *pixel_count = max( + 0, (int)current_plane->frame_info->fb->width - + *src_x_start); break; case READ_BOTTOM_TO_TOP: case READ_TOP_TO_BOTTOM: @@ -353,9 +374,11 @@ static void clamp_line_coordinates(enum pixel_read_direction direction, *dst_x_start -= *src_y_start; *src_y_start = 0; } - if (*src_y_start + *pixel_count > current_plane->frame_info->fb->height) - *pixel_count = max(0, (int)current_plane->frame_info->fb->height - - *src_y_start); + if (*src_y_start + *pixel_count > + current_plane->frame_info->fb->height) + *pixel_count = max( + 0, (int)current_plane->frame_info->fb->height - + *src_y_start); break; } } @@ -386,9 +409,9 @@ static void blend_line(struct vkms_plane_state *current_plane, int y, * destination framebuffer, and then drm_rect_* helpers are used to * compute the correct position into the source framebuffer. */ - dst_line = DRM_RECT_INIT(current_plane->frame_info->dst.x1, y, - drm_rect_width(¤t_plane->frame_info->dst), - 1); + dst_line = DRM_RECT_INIT( + current_plane->frame_info->dst.x1, y, + drm_rect_width(¤t_plane->frame_info->dst), 1); drm_rect_fp_to_int(&tmp_src, ¤t_plane->frame_info->src); @@ -427,8 +450,9 @@ static void blend_line(struct vkms_plane_state *current_plane, int y, direction_for_rotation(current_plane->frame_info->rotation); /* [2]: Compute and clamp the number of pixel to read */ - clamp_line_coordinates(direction, current_plane, &src_line, &src_x_start, &src_y_start, - &dst_x_start, &pixel_count); + clamp_line_coordinates(direction, current_plane, &src_line, + &src_x_start, &src_y_start, &dst_x_start, + &pixel_count); if (pixel_count <= 0) { /* Nothing to read, so avoid multiple function calls */ @@ -457,11 +481,12 @@ static void blend_line(struct vkms_plane_state *current_plane, int y, * inside the source buffer [2] and we don't write outside the stage * buffer [1]. */ - current_plane->pixel_read_line(current_plane, src_x_start, src_y_start, direction, - pixel_count, &stage_buffer->pixels[dst_x_start]); + current_plane->pixel_read_line(current_plane, src_x_start, src_y_start, + direction, pixel_count, + &stage_buffer->pixels[dst_x_start]); pre_blend_color_transform(current_plane, stage_buffer); - pre_mul_alpha_blend(stage_buffer, output_buffer, - dst_x_start, pixel_count); + pre_mul_alpha_blend(stage_buffer, output_buffer, dst_x_start, + pixel_count); } /** @@ -478,8 +503,8 @@ static void blend_line(struct vkms_plane_state *current_plane, int y, * and, if necessary, convert and store the output to the writeback buffer. */ static void blend(struct vkms_writeback_job *wb, - struct vkms_crtc_state *crtc_state, - u32 *crc32, struct line_buffer *stage_buffer, + struct vkms_crtc_state *crtc_state, u32 *crc32, + struct line_buffer *stage_buffer, struct line_buffer *output_buffer, size_t row_size) { struct vkms_plane_state **plane = crtc_state->active_planes; @@ -512,12 +537,14 @@ static void blend(struct vkms_writeback_job *wb, /* The active planes are composed associatively in z-order. */ for (size_t i = 0; i < n_active_planes; i++) { - blend_line(plane[i], y, crtc_x_limit, stage_buffer, output_buffer); + blend_line(plane[i], y, crtc_x_limit, stage_buffer, + output_buffer); } apply_lut(crtc_state, output_buffer); - *crc32 = crc32_le(*crc32, (void *)output_buffer->pixels, row_size); + *crc32 = crc32_le(*crc32, (void *)output_buffer->pixels, + row_size); if (wb) vkms_writeback_row(wb, output_buffer, y); @@ -553,8 +580,7 @@ static int check_iosys_map(struct vkms_crtc_state *crtc_state) } static int compose_active_planes(struct vkms_writeback_job *active_wb, - struct vkms_crtc_state *crtc_state, - u32 *crc32) + struct vkms_crtc_state *crtc_state, u32 *crc32) { size_t line_width, pixel_size = sizeof(struct pixel_argb_u16); struct line_buffer output_buffer, stage_buffer; @@ -586,13 +612,14 @@ static int compose_active_planes(struct vkms_writeback_job *active_wb, output_buffer.pixels = kvmalloc(line_width * pixel_size, GFP_KERNEL); if (!output_buffer.pixels) { - DRM_ERROR("Cannot allocate memory for intermediate line buffer"); + DRM_ERROR( + "Cannot allocate memory for intermediate line buffer"); ret = -ENOMEM; goto free_stage_buffer; } - blend(active_wb, crtc_state, crc32, &stage_buffer, - &output_buffer, line_width * pixel_size); + blend(active_wb, crtc_state, crc32, &stage_buffer, &output_buffer, + line_width * pixel_size); kvfree(output_buffer.pixels); free_stage_buffer: @@ -612,9 +639,8 @@ static int compose_active_planes(struct vkms_writeback_job *active_wb, */ void vkms_composer_worker(struct work_struct *work) { - struct vkms_crtc_state *crtc_state = container_of(work, - struct vkms_crtc_state, - composer_work); + struct vkms_crtc_state *crtc_state = + container_of(work, struct vkms_crtc_state, composer_work); struct drm_crtc *crtc = crtc_state->base.crtc; struct vkms_writeback_job *active_wb = crtc_state->active_writeback; struct vkms_output *out = drm_crtc_to_vkms_output(crtc); @@ -636,12 +662,15 @@ void vkms_composer_worker(struct work_struct *work) s64 max_lut_index_fp; s64 u16_max_fp = drm_int2fixp(0xffff); - crtc_state->gamma_lut.base = (struct drm_color_lut *)crtc->state->gamma_lut->data; + crtc_state->gamma_lut.base = + (struct drm_color_lut *)crtc->state->gamma_lut->data; crtc_state->gamma_lut.lut_length = - crtc->state->gamma_lut->length / sizeof(struct drm_color_lut); - max_lut_index_fp = drm_int2fixp(crtc_state->gamma_lut.lut_length - 1); - crtc_state->gamma_lut.channel_value2index_ratio = drm_fixp_div(max_lut_index_fp, - u16_max_fp); + crtc->state->gamma_lut->length / + sizeof(struct drm_color_lut); + max_lut_index_fp = + drm_int2fixp(crtc_state->gamma_lut.lut_length - 1); + crtc_state->gamma_lut.channel_value2index_ratio = + drm_fixp_div(max_lut_index_fp, u16_max_fp); } else { crtc_state->gamma_lut.base = NULL; @@ -680,8 +709,7 @@ void vkms_composer_worker(struct work_struct *work) static const char *const pipe_crc_sources[] = { "auto" }; -const char *const *vkms_get_crc_sources(struct drm_crtc *crtc, - size_t *count) +const char *const *vkms_get_crc_sources(struct drm_crtc *crtc, size_t *count) { *count = ARRAY_SIZE(pipe_crc_sources); return pipe_crc_sources; diff --git a/linux/vibeshine-drm/vkms_composer.h b/linux/vibeshine-drm/vkms_composer.h index 04dd564..3907c56 100644 --- a/linux/vibeshine-drm/vkms_composer.h +++ b/linux/vibeshine-drm/vkms_composer.h @@ -10,19 +10,15 @@ * This enum is related to the positions of the variables inside * `struct drm_color_lut`, so the order of both needs to be the same. */ -enum lut_channel { - LUT_RED = 0, - LUT_GREEN, - LUT_BLUE, - LUT_RESERVED -}; +enum lut_channel { LUT_RED = 0, LUT_GREEN, LUT_BLUE, LUT_RESERVED }; #if IS_ENABLED(CONFIG_KUNIT) u16 lerp_u16(u16 a, u16 b, s64 t); s64 get_lut_index(const struct vkms_color_lut *lut, u16 channel_value); -u16 apply_lut_to_channel_value(const struct vkms_color_lut *lut, u16 channel_value, - enum lut_channel channel); -void apply_3x4_matrix(struct pixel_argb_s32 *pixel, const struct drm_color_ctm_3x4 *matrix); +u16 apply_lut_to_channel_value(const struct vkms_color_lut *lut, + u16 channel_value, enum lut_channel channel); +void apply_3x4_matrix(struct pixel_argb_s32 *pixel, + const struct drm_color_ctm_3x4 *matrix); #endif #endif /* _VKMS_COMPOSER_H_ */ diff --git a/linux/vibeshine-drm/vkms_config.c b/linux/vibeshine-drm/vkms_config.c index e227290..4f856c4 100644 --- a/linux/vibeshine-drm/vkms_config.c +++ b/linux/vibeshine-drm/vkms_config.c @@ -59,7 +59,8 @@ struct vkms_config *vkms_config_default_create(bool enable_cursor, if (vkms_config_plane_attach_crtc(plane_cfg, crtc_cfg)) goto err_alloc; - vkms_config_plane_set_default_pipeline(plane_cfg, enable_plane_pipeline); + vkms_config_plane_set_default_pipeline(plane_cfg, + enable_plane_pipeline); if (enable_overlay) { for (n = 0; n < NUM_OVERLAY_PLANES; n++) { @@ -69,7 +70,8 @@ struct vkms_config *vkms_config_default_create(bool enable_cursor, vkms_config_plane_set_type(plane_cfg, DRM_PLANE_TYPE_OVERLAY); - vkms_config_plane_set_default_pipeline(plane_cfg, enable_plane_pipeline); + vkms_config_plane_set_default_pipeline( + plane_cfg, enable_plane_pipeline); if (vkms_config_plane_attach_crtc(plane_cfg, crtc_cfg)) goto err_alloc; @@ -82,7 +84,8 @@ struct vkms_config *vkms_config_default_create(bool enable_cursor, goto err_alloc; vkms_config_plane_set_type(plane_cfg, DRM_PLANE_TYPE_CURSOR); - vkms_config_plane_set_default_pipeline(plane_cfg, enable_plane_pipeline); + vkms_config_plane_set_default_pipeline(plane_cfg, + enable_plane_pipeline); if (vkms_config_plane_attach_crtc(plane_cfg, crtc_cfg)) goto err_alloc; @@ -130,10 +133,12 @@ void vkms_config_destroy(struct vkms_config *config) list_for_each_entry_safe(crtc_cfg, crtc_tmp, &config->crtcs, link) vkms_config_destroy_crtc(config, crtc_cfg); - list_for_each_entry_safe(encoder_cfg, encoder_tmp, &config->encoders, link) + list_for_each_entry_safe(encoder_cfg, encoder_tmp, &config->encoders, + link) vkms_config_destroy_encoder(config, encoder_cfg); - list_for_each_entry_safe(connector_cfg, connector_tmp, &config->connectors, link) + list_for_each_entry_safe(connector_cfg, connector_tmp, + &config->connectors, link) vkms_config_destroy_connector(connector_cfg); kfree_const(config->dev_name); @@ -147,7 +152,8 @@ static bool valid_plane_number(const struct vkms_config *config) n_planes = list_count_nodes((struct list_head *)&config->planes); if (n_planes <= 0 || n_planes >= 32) { - drm_info(dev, "The number of planes must be between 1 and 31\n"); + drm_info(dev, + "The number of planes must be between 1 and 31\n"); return false; } @@ -169,20 +175,23 @@ static bool valid_planes_for_crtc(const struct vkms_config *config, type = vkms_config_plane_get_type(plane_cfg); - vkms_config_plane_for_each_possible_crtc(plane_cfg, idx, possible_crtc) { + vkms_config_plane_for_each_possible_crtc(plane_cfg, idx, + possible_crtc) { if (possible_crtc != crtc_cfg) continue; if (type == DRM_PLANE_TYPE_PRIMARY) { if (has_primary_plane) { - drm_info(dev, "Multiple primary planes\n"); + drm_info(dev, + "Multiple primary planes\n"); return false; } has_primary_plane = true; } else if (type == DRM_PLANE_TYPE_CURSOR) { if (has_cursor_plane) { - drm_info(dev, "Multiple cursor planes\n"); + drm_info(dev, + "Multiple cursor planes\n"); return false; } @@ -206,7 +215,9 @@ static bool valid_plane_possible_crtcs(const struct vkms_config *config) vkms_config_for_each_plane(config, plane_cfg) { if (xa_empty(&plane_cfg->possible_crtcs)) { - drm_info(dev, "All planes must have at least one possible CRTC\n"); + drm_info( + dev, + "All planes must have at least one possible CRTC\n"); return false; } } @@ -235,7 +246,8 @@ static bool valid_encoder_number(const struct vkms_config *config) n_encoders = list_count_nodes((struct list_head *)&config->encoders); if (n_encoders <= 0 || n_encoders >= 32) { - drm_info(dev, "The number of encoders must be between 1 and 31\n"); + drm_info(dev, + "The number of encoders must be between 1 and 31\n"); return false; } @@ -250,7 +262,9 @@ static bool valid_encoder_possible_crtcs(const struct vkms_config *config) vkms_config_for_each_encoder(config, encoder_cfg) { if (xa_empty(&encoder_cfg->possible_crtcs)) { - drm_info(dev, "All encoders must have at least one possible CRTC\n"); + drm_info( + dev, + "All encoders must have at least one possible CRTC\n"); return false; } } @@ -262,15 +276,17 @@ static bool valid_encoder_possible_crtcs(const struct vkms_config *config) struct vkms_config_crtc *possible_crtc; unsigned long idx = 0; - vkms_config_encoder_for_each_possible_crtc(encoder_cfg, - idx, possible_crtc) { + vkms_config_encoder_for_each_possible_crtc( + encoder_cfg, idx, possible_crtc) { if (possible_crtc == crtc_cfg) crtc_has_encoder = true; } } if (!crtc_has_encoder) { - drm_info(dev, "All CRTCs must have at least one possible encoder\n"); + drm_info( + dev, + "All CRTCs must have at least one possible encoder\n"); return false; } } @@ -283,9 +299,11 @@ static bool valid_connector_number(const struct vkms_config *config) struct drm_device *dev = config->dev ? &config->dev->drm : NULL; size_t n_connectors; - n_connectors = list_count_nodes((struct list_head *)&config->connectors); + n_connectors = + list_count_nodes((struct list_head *)&config->connectors); if (n_connectors <= 0 || n_connectors >= 32) { - drm_info(dev, "The number of connectors must be between 1 and 31\n"); + drm_info(dev, + "The number of connectors must be between 1 and 31\n"); return false; } @@ -299,8 +317,9 @@ static bool valid_connector_possible_encoders(const struct vkms_config *config) vkms_config_for_each_connector(config, connector_cfg) { if (xa_empty(&connector_cfg->possible_encoders)) { - drm_info(dev, - "All connectors must have at least one possible encoder\n"); + drm_info( + dev, + "All connectors must have at least one possible encoder\n"); return false; } } @@ -366,8 +385,8 @@ void vkms_config_destroy_plane(struct vkms_config_plane *plane_cfg) kfree(plane_cfg); } -int __must_check vkms_config_plane_attach_crtc(struct vkms_config_plane *plane_cfg, - struct vkms_config_crtc *crtc_cfg) +int __must_check vkms_config_plane_attach_crtc( + struct vkms_config_plane *plane_cfg, struct vkms_config_crtc *crtc_cfg) { struct vkms_config_crtc *possible_crtc; unsigned long idx = 0; @@ -376,7 +395,8 @@ int __must_check vkms_config_plane_attach_crtc(struct vkms_config_plane *plane_c if (plane_cfg->config != crtc_cfg->config) return -EINVAL; - vkms_config_plane_for_each_possible_crtc(plane_cfg, idx, possible_crtc) { + vkms_config_plane_for_each_possible_crtc(plane_cfg, idx, + possible_crtc) { if (possible_crtc == crtc_cfg) return -EEXIST; } @@ -391,7 +411,8 @@ void vkms_config_plane_detach_crtc(struct vkms_config_plane *plane_cfg, struct vkms_config_crtc *possible_crtc; unsigned long idx = 0; - vkms_config_plane_for_each_possible_crtc(plane_cfg, idx, possible_crtc) { + vkms_config_plane_for_each_possible_crtc(plane_cfg, idx, + possible_crtc) { if (possible_crtc == crtc_cfg) xa_erase(&plane_cfg->possible_crtcs, idx); } @@ -439,9 +460,10 @@ void vkms_config_destroy_crtc(struct vkms_config *config, * Returns: * The first plane found attached to @crtc_cfg with the type @type. */ -static struct vkms_config_plane *vkms_config_crtc_get_plane(const struct vkms_config *config, - struct vkms_config_crtc *crtc_cfg, - enum drm_plane_type type) +static struct vkms_config_plane * +vkms_config_crtc_get_plane(const struct vkms_config *config, + struct vkms_config_crtc *crtc_cfg, + enum drm_plane_type type) { struct vkms_config_plane *plane_cfg; struct vkms_config_crtc *possible_crtc; @@ -451,7 +473,8 @@ static struct vkms_config_plane *vkms_config_crtc_get_plane(const struct vkms_co vkms_config_for_each_plane(config, plane_cfg) { current_type = vkms_config_plane_get_type(plane_cfg); - vkms_config_plane_for_each_possible_crtc(plane_cfg, idx, possible_crtc) { + vkms_config_plane_for_each_possible_crtc(plane_cfg, idx, + possible_crtc) { if (possible_crtc == crtc_cfg && current_type == type) return plane_cfg; } @@ -460,19 +483,24 @@ static struct vkms_config_plane *vkms_config_crtc_get_plane(const struct vkms_co return NULL; } -struct vkms_config_plane *vkms_config_crtc_primary_plane(const struct vkms_config *config, - struct vkms_config_crtc *crtc_cfg) +struct vkms_config_plane * +vkms_config_crtc_primary_plane(const struct vkms_config *config, + struct vkms_config_crtc *crtc_cfg) { - return vkms_config_crtc_get_plane(config, crtc_cfg, DRM_PLANE_TYPE_PRIMARY); + return vkms_config_crtc_get_plane(config, crtc_cfg, + DRM_PLANE_TYPE_PRIMARY); } -struct vkms_config_plane *vkms_config_crtc_cursor_plane(const struct vkms_config *config, - struct vkms_config_crtc *crtc_cfg) +struct vkms_config_plane * +vkms_config_crtc_cursor_plane(const struct vkms_config *config, + struct vkms_config_crtc *crtc_cfg) { - return vkms_config_crtc_get_plane(config, crtc_cfg, DRM_PLANE_TYPE_CURSOR); + return vkms_config_crtc_get_plane(config, crtc_cfg, + DRM_PLANE_TYPE_CURSOR); } -struct vkms_config_encoder *vkms_config_create_encoder(struct vkms_config *config) +struct vkms_config_encoder * +vkms_config_create_encoder(struct vkms_config *config) { struct vkms_config_encoder *encoder_cfg; @@ -494,15 +522,17 @@ void vkms_config_destroy_encoder(struct vkms_config *config, struct vkms_config_connector *connector_cfg; vkms_config_for_each_connector(config, connector_cfg) - vkms_config_connector_detach_encoder(connector_cfg, encoder_cfg); + vkms_config_connector_detach_encoder(connector_cfg, + encoder_cfg); xa_destroy(&encoder_cfg->possible_crtcs); list_del(&encoder_cfg->link); kfree(encoder_cfg); } -int __must_check vkms_config_encoder_attach_crtc(struct vkms_config_encoder *encoder_cfg, - struct vkms_config_crtc *crtc_cfg) +int __must_check +vkms_config_encoder_attach_crtc(struct vkms_config_encoder *encoder_cfg, + struct vkms_config_crtc *crtc_cfg) { struct vkms_config_crtc *possible_crtc; unsigned long idx = 0; @@ -511,7 +541,8 @@ int __must_check vkms_config_encoder_attach_crtc(struct vkms_config_encoder *enc if (encoder_cfg->config != crtc_cfg->config) return -EINVAL; - vkms_config_encoder_for_each_possible_crtc(encoder_cfg, idx, possible_crtc) { + vkms_config_encoder_for_each_possible_crtc(encoder_cfg, idx, + possible_crtc) { if (possible_crtc == crtc_cfg) return -EEXIST; } @@ -526,13 +557,15 @@ void vkms_config_encoder_detach_crtc(struct vkms_config_encoder *encoder_cfg, struct vkms_config_crtc *possible_crtc; unsigned long idx = 0; - vkms_config_encoder_for_each_possible_crtc(encoder_cfg, idx, possible_crtc) { + vkms_config_encoder_for_each_possible_crtc(encoder_cfg, idx, + possible_crtc) { if (possible_crtc == crtc_cfg) xa_erase(&encoder_cfg->possible_crtcs, idx); } } -struct vkms_config_connector *vkms_config_create_connector(struct vkms_config *config) +struct vkms_config_connector * +vkms_config_create_connector(struct vkms_config *config) { struct vkms_config_connector *connector_cfg; @@ -556,8 +589,9 @@ void vkms_config_destroy_connector(struct vkms_config_connector *connector_cfg) kfree(connector_cfg); } -int __must_check vkms_config_connector_attach_encoder(struct vkms_config_connector *connector_cfg, - struct vkms_config_encoder *encoder_cfg) +int __must_check vkms_config_connector_attach_encoder( + struct vkms_config_connector *connector_cfg, + struct vkms_config_encoder *encoder_cfg) { struct vkms_config_encoder *possible_encoder; unsigned long idx = 0; @@ -576,8 +610,9 @@ int __must_check vkms_config_connector_attach_encoder(struct vkms_config_connect encoder_cfg, xa_limit_32b, GFP_KERNEL); } -void vkms_config_connector_detach_encoder(struct vkms_config_connector *connector_cfg, - struct vkms_config_encoder *encoder_cfg) +void vkms_config_connector_detach_encoder( + struct vkms_config_connector *connector_cfg, + struct vkms_config_encoder *encoder_cfg) { struct vkms_config_encoder *possible_encoder; unsigned long idx = 0; diff --git a/linux/vibeshine-drm/vkms_config.h b/linux/vibeshine-drm/vkms_config.h index 88b86c3..ccd501c 100644 --- a/linux/vibeshine-drm/vkms_config.h +++ b/linux/vibeshine-drm/vkms_config.h @@ -165,7 +165,8 @@ struct vkms_config_connector { * @idx: Index of the cursor * @possible_crtc: &struct vkms_config_crtc pointer used as cursor */ -#define vkms_config_plane_for_each_possible_crtc(plane_cfg, idx, possible_crtc) \ +#define vkms_config_plane_for_each_possible_crtc(plane_cfg, idx, \ + possible_crtc) \ xa_for_each(&(plane_cfg)->possible_crtcs, idx, (possible_crtc)) /** @@ -175,7 +176,8 @@ struct vkms_config_connector { * @idx: Index of the cursor * @possible_crtc: &struct vkms_config_crtc pointer used as cursor */ -#define vkms_config_encoder_for_each_possible_crtc(encoder_cfg, idx, possible_crtc) \ +#define vkms_config_encoder_for_each_possible_crtc(encoder_cfg, idx, \ + possible_crtc) \ xa_for_each(&(encoder_cfg)->possible_crtcs, idx, (possible_crtc)) /** @@ -185,8 +187,10 @@ struct vkms_config_connector { * @idx: Index of the cursor * @possible_encoder: &struct vkms_config_encoder pointer used as cursor */ -#define vkms_config_connector_for_each_possible_encoder(connector_cfg, idx, possible_encoder) \ - xa_for_each(&(connector_cfg)->possible_encoders, idx, (possible_encoder)) +#define vkms_config_connector_for_each_possible_encoder(connector_cfg, idx, \ + possible_encoder) \ + xa_for_each(&(connector_cfg)->possible_encoders, idx, \ + (possible_encoder)) /** * vkms_config_create() - Create a new VKMS configuration @@ -211,7 +215,7 @@ struct vkms_config *vkms_config_create(const char *dev_name); struct vkms_config *vkms_config_default_create(bool enable_cursor, bool enable_writeback, bool enable_overlay, - bool enable_plane_pipeline); + bool enable_plane_pipeline); /** * vkms_config_get() - Hold a VKMS configuration reference @@ -329,8 +333,8 @@ vkms_config_plane_set_default_pipeline(struct vkms_config_plane *plane_cfg, * @plane_cfg: Plane to attach * @crtc_cfg: CRTC to attach @plane_cfg to */ -int __must_check vkms_config_plane_attach_crtc(struct vkms_config_plane *plane_cfg, - struct vkms_config_crtc *crtc_cfg); +int __must_check vkms_config_plane_attach_crtc( + struct vkms_config_plane *plane_cfg, struct vkms_config_crtc *crtc_cfg); /** * vkms_config_plane_detach_crtc - Detach a plane from a CRTC @@ -391,8 +395,9 @@ vkms_config_crtc_set_writeback(struct vkms_config_crtc *crtc_cfg, * Returns: * The primary plane or NULL if none is assigned yet. */ -struct vkms_config_plane *vkms_config_crtc_primary_plane(const struct vkms_config *config, - struct vkms_config_crtc *crtc_cfg); +struct vkms_config_plane * +vkms_config_crtc_primary_plane(const struct vkms_config *config, + struct vkms_config_crtc *crtc_cfg); /** * vkms_config_crtc_cursor_plane() - Return the cursor plane for a CRTC @@ -405,8 +410,9 @@ struct vkms_config_plane *vkms_config_crtc_primary_plane(const struct vkms_confi * Returns: * The cursor plane or NULL if none is assigned yet. */ -struct vkms_config_plane *vkms_config_crtc_cursor_plane(const struct vkms_config *config, - struct vkms_config_crtc *crtc_cfg); +struct vkms_config_plane * +vkms_config_crtc_cursor_plane(const struct vkms_config *config, + struct vkms_config_crtc *crtc_cfg); /** * vkms_config_create_encoder() - Add a new encoder configuration @@ -416,7 +422,8 @@ struct vkms_config_plane *vkms_config_crtc_cursor_plane(const struct vkms_config * The new encoder configuration or an error. Call vkms_config_destroy_encoder() * to free the returned encoder configuration. */ -struct vkms_config_encoder *vkms_config_create_encoder(struct vkms_config *config); +struct vkms_config_encoder * +vkms_config_create_encoder(struct vkms_config *config); /** * vkms_config_destroy_encoder() - Remove and free a encoder configuration @@ -431,8 +438,9 @@ void vkms_config_destroy_encoder(struct vkms_config *config, * @encoder_cfg: Encoder to attach * @crtc_cfg: CRTC to attach @encoder_cfg to */ -int __must_check vkms_config_encoder_attach_crtc(struct vkms_config_encoder *encoder_cfg, - struct vkms_config_crtc *crtc_cfg); +int __must_check +vkms_config_encoder_attach_crtc(struct vkms_config_encoder *encoder_cfg, + struct vkms_config_crtc *crtc_cfg); /** * vkms_config_encoder_detach_crtc - Detach a encoder from a CRTC @@ -450,7 +458,8 @@ void vkms_config_encoder_detach_crtc(struct vkms_config_encoder *encoder_cfg, * The new connector configuration or an error. Call * vkms_config_destroy_connector() to free the returned connector configuration. */ -struct vkms_config_connector *vkms_config_create_connector(struct vkms_config *config); +struct vkms_config_connector * +vkms_config_create_connector(struct vkms_config *config); /** * vkms_config_destroy_connector() - Remove and free a connector configuration @@ -463,16 +472,18 @@ void vkms_config_destroy_connector(struct vkms_config_connector *connector_cfg); * @connector_cfg: Connector to attach * @encoder_cfg: Encoder to attach @connector_cfg to */ -int __must_check vkms_config_connector_attach_encoder(struct vkms_config_connector *connector_cfg, - struct vkms_config_encoder *encoder_cfg); +int __must_check vkms_config_connector_attach_encoder( + struct vkms_config_connector *connector_cfg, + struct vkms_config_encoder *encoder_cfg); /** * vkms_config_connector_detach_encoder - Detach a connector from an encoder * @connector_cfg: Connector to detach * @encoder_cfg: Encoder to detach @connector_cfg from */ -void vkms_config_connector_detach_encoder(struct vkms_config_connector *connector_cfg, - struct vkms_config_encoder *encoder_cfg); +void vkms_config_connector_detach_encoder( + struct vkms_config_connector *connector_cfg, + struct vkms_config_encoder *encoder_cfg); /** * vkms_config_connector_get_status() - Return the status of the connector diff --git a/linux/vibeshine-drm/vkms_configfs.c b/linux/vibeshine-drm/vkms_configfs.c index 1dbd149..2c3fc4c 100644 --- a/linux/vibeshine-drm/vkms_configfs.c +++ b/linux/vibeshine-drm/vkms_configfs.c @@ -103,7 +103,7 @@ struct vkms_configfs_connector { struct vkms_config_connector *config; }; -#define device_item_to_vkms_configfs_device(item) \ +#define device_item_to_vkms_configfs_device(item) \ container_of(to_config_group((item)), struct vkms_configfs_device, \ group) @@ -113,26 +113,26 @@ struct vkms_configfs_connector { #define plane_item_to_vkms_configfs_plane(item) \ container_of(to_config_group((item)), struct vkms_configfs_plane, group) -#define plane_possible_crtcs_item_to_vkms_configfs_plane(item) \ +#define plane_possible_crtcs_item_to_vkms_configfs_plane(item) \ container_of(to_config_group((item)), struct vkms_configfs_plane, \ possible_crtcs_group) #define crtc_item_to_vkms_configfs_crtc(item) \ container_of(to_config_group((item)), struct vkms_configfs_crtc, group) -#define encoder_item_to_vkms_configfs_encoder(item) \ +#define encoder_item_to_vkms_configfs_encoder(item) \ container_of(to_config_group((item)), struct vkms_configfs_encoder, \ group) -#define encoder_possible_crtcs_item_to_vkms_configfs_encoder(item) \ +#define encoder_possible_crtcs_item_to_vkms_configfs_encoder(item) \ container_of(to_config_group((item)), struct vkms_configfs_encoder, \ possible_crtcs_group) -#define connector_item_to_vkms_configfs_connector(item) \ +#define connector_item_to_vkms_configfs_connector(item) \ container_of(to_config_group((item)), struct vkms_configfs_connector, \ group) -#define connector_possible_encoders_item_to_vkms_configfs_connector(item) \ +#define connector_possible_encoders_item_to_vkms_configfs_connector(item) \ container_of(to_config_group((item)), struct vkms_configfs_connector, \ possible_encoders_group) @@ -194,13 +194,13 @@ static void crtc_release(struct config_item *item) } static struct configfs_item_operations crtc_item_operations = { - .release = &crtc_release, + .release = &crtc_release, }; static const struct config_item_type crtc_item_type = { - .ct_attrs = crtc_item_attrs, - .ct_item_ops = &crtc_item_operations, - .ct_owner = THIS_MODULE, + .ct_attrs = crtc_item_attrs, + .ct_item_ops = &crtc_item_operations, + .ct_owner = THIS_MODULE, }; static struct config_group *make_crtc_group(struct config_group *group, @@ -229,19 +229,20 @@ static struct config_group *make_crtc_group(struct config_group *group, return ERR_PTR(ret); } - config_group_init_type_name(&crtc->group, name, &crtc_item_type); + config_group_init_type_name(&crtc->group, name, + &crtc_item_type); } return &crtc->group; } static struct configfs_group_operations crtcs_group_operations = { - .make_group = &make_crtc_group, + .make_group = &make_crtc_group, }; static const struct config_item_type crtc_group_type = { - .ct_group_ops = &crtcs_group_operations, - .ct_owner = THIS_MODULE, + .ct_group_ops = &crtcs_group_operations, + .ct_owner = THIS_MODULE, }; static int plane_possible_crtcs_allow_link(struct config_item *src, @@ -261,7 +262,8 @@ static int plane_possible_crtcs_allow_link(struct config_item *src, if (plane->dev->enabled) return -EBUSY; - ret = vkms_config_plane_attach_crtc(plane->config, crtc->config); + ret = vkms_config_plane_attach_crtc(plane->config, + crtc->config); } return ret; @@ -281,13 +283,13 @@ static void plane_possible_crtcs_drop_link(struct config_item *src, } static struct configfs_item_operations plane_possible_crtcs_item_operations = { - .allow_link = plane_possible_crtcs_allow_link, - .drop_link = plane_possible_crtcs_drop_link, + .allow_link = plane_possible_crtcs_allow_link, + .drop_link = plane_possible_crtcs_drop_link, }; static const struct config_item_type plane_possible_crtcs_group_type = { - .ct_item_ops = &plane_possible_crtcs_item_operations, - .ct_owner = THIS_MODULE, + .ct_item_ops = &plane_possible_crtcs_item_operations, + .ct_owner = THIS_MODULE, }; static ssize_t plane_type_show(struct config_item *item, char *page) @@ -350,13 +352,13 @@ static void plane_release(struct config_item *item) } static struct configfs_item_operations plane_item_operations = { - .release = &plane_release, + .release = &plane_release, }; static const struct config_item_type plane_item_type = { - .ct_attrs = plane_item_attrs, - .ct_item_ops = &plane_item_operations, - .ct_owner = THIS_MODULE, + .ct_attrs = plane_item_attrs, + .ct_item_ops = &plane_item_operations, + .ct_owner = THIS_MODULE, }; static struct config_group *make_plane_group(struct config_group *group, @@ -385,7 +387,8 @@ static struct config_group *make_plane_group(struct config_group *group, return ERR_PTR(ret); } - config_group_init_type_name(&plane->group, name, &plane_item_type); + config_group_init_type_name(&plane->group, name, + &plane_item_type); config_group_init_type_name(&plane->possible_crtcs_group, "possible_crtcs", @@ -398,12 +401,12 @@ static struct config_group *make_plane_group(struct config_group *group, } static struct configfs_group_operations planes_group_operations = { - .make_group = &make_plane_group, + .make_group = &make_plane_group, }; static const struct config_item_type plane_group_type = { - .ct_group_ops = &planes_group_operations, - .ct_owner = THIS_MODULE, + .ct_group_ops = &planes_group_operations, + .ct_owner = THIS_MODULE, }; static int encoder_possible_crtcs_allow_link(struct config_item *src, @@ -423,7 +426,8 @@ static int encoder_possible_crtcs_allow_link(struct config_item *src, if (encoder->dev->enabled) return -EBUSY; - ret = vkms_config_encoder_attach_crtc(encoder->config, crtc->config); + ret = vkms_config_encoder_attach_crtc(encoder->config, + crtc->config); } return ret; @@ -443,13 +447,13 @@ static void encoder_possible_crtcs_drop_link(struct config_item *src, } static struct configfs_item_operations encoder_possible_crtcs_item_operations = { - .allow_link = encoder_possible_crtcs_allow_link, - .drop_link = encoder_possible_crtcs_drop_link, + .allow_link = encoder_possible_crtcs_allow_link, + .drop_link = encoder_possible_crtcs_drop_link, }; static const struct config_item_type encoder_possible_crtcs_group_type = { - .ct_item_ops = &encoder_possible_crtcs_item_operations, - .ct_owner = THIS_MODULE, + .ct_item_ops = &encoder_possible_crtcs_item_operations, + .ct_owner = THIS_MODULE, }; static void encoder_release(struct config_item *item) @@ -461,18 +465,19 @@ static void encoder_release(struct config_item *item) lock = &encoder->dev->lock; scoped_guard(mutex, lock) { - vkms_config_destroy_encoder(encoder->dev->config, encoder->config); + vkms_config_destroy_encoder(encoder->dev->config, + encoder->config); kfree(encoder); } } static struct configfs_item_operations encoder_item_operations = { - .release = &encoder_release, + .release = &encoder_release, }; static const struct config_item_type encoder_item_type = { - .ct_item_ops = &encoder_item_operations, - .ct_owner = THIS_MODULE, + .ct_item_ops = &encoder_item_operations, + .ct_owner = THIS_MODULE, }; static struct config_group *make_encoder_group(struct config_group *group, @@ -515,12 +520,12 @@ static struct config_group *make_encoder_group(struct config_group *group, } static struct configfs_group_operations encoders_group_operations = { - .make_group = &make_encoder_group, + .make_group = &make_encoder_group, }; static const struct config_item_type encoder_group_type = { - .ct_group_ops = &encoders_group_operations, - .ct_owner = THIS_MODULE, + .ct_group_ops = &encoders_group_operations, + .ct_owner = THIS_MODULE, }; static ssize_t connector_status_show(struct config_item *item, char *page) @@ -556,8 +561,10 @@ static ssize_t connector_status_store(struct config_item *item, vkms_config_connector_set_status(connector->config, status); if (connector->dev->enabled) { - vkms_connector_set_status(connector->config->connector, status); - vkms_trigger_connector_hotplug(connector->dev->config->dev); + vkms_connector_set_status(connector->config->connector, + status); + vkms_trigger_connector_hotplug( + connector->dev->config->dev); } } @@ -585,7 +592,8 @@ static ssize_t connector_drm_name_show(struct config_item *item, char *page) CONFIGFS_ATTR_RO(connector_, drm_name); -static ssize_t connector_requested_mode_show(struct config_item *item, char *page) +static ssize_t connector_requested_mode_show(struct config_item *item, + char *page) { struct vkms_configfs_connector *connector; struct vibeshine_drm_requested_mode mode; @@ -613,8 +621,10 @@ static ssize_t connector_requested_mode_store(struct config_item *item, scoped_guard(mutex, &connector->dev->lock) { connector->config->requested_mode = mode; if (connector->dev->enabled) { - vkms_connector_set_requested_mode(connector->config->connector, &mode); - vkms_trigger_connector_hotplug(connector->dev->config->dev); + vkms_connector_set_requested_mode( + connector->config->connector, &mode); + vkms_trigger_connector_hotplug( + connector->dev->config->dev); } } return count; @@ -644,13 +654,13 @@ static void connector_release(struct config_item *item) } static struct configfs_item_operations connector_item_operations = { - .release = &connector_release, + .release = &connector_release, }; static const struct config_item_type connector_item_type = { - .ct_attrs = connector_item_attrs, - .ct_item_ops = &connector_item_operations, - .ct_owner = THIS_MODULE, + .ct_attrs = connector_item_attrs, + .ct_item_ops = &connector_item_operations, + .ct_owner = THIS_MODULE, }; static int connector_possible_encoders_allow_link(struct config_item *src, @@ -663,7 +673,8 @@ static int connector_possible_encoders_allow_link(struct config_item *src, if (target->ci_type != &encoder_item_type) return -EINVAL; - connector = connector_possible_encoders_item_to_vkms_configfs_connector(src); + connector = connector_possible_encoders_item_to_vkms_configfs_connector( + src); encoder = encoder_item_to_vkms_configfs_encoder(target); scoped_guard(mutex, &connector->dev->lock) { @@ -683,7 +694,8 @@ static void connector_possible_encoders_drop_link(struct config_item *src, struct vkms_configfs_connector *connector; struct vkms_configfs_encoder *encoder; - connector = connector_possible_encoders_item_to_vkms_configfs_connector(src); + connector = connector_possible_encoders_item_to_vkms_configfs_connector( + src); encoder = encoder_item_to_vkms_configfs_encoder(target); scoped_guard(mutex, &connector->dev->lock) { @@ -692,14 +704,15 @@ static void connector_possible_encoders_drop_link(struct config_item *src, } } -static struct configfs_item_operations connector_possible_encoders_item_operations = { - .allow_link = connector_possible_encoders_allow_link, - .drop_link = connector_possible_encoders_drop_link, -}; +static struct configfs_item_operations + connector_possible_encoders_item_operations = { + .allow_link = connector_possible_encoders_allow_link, + .drop_link = connector_possible_encoders_drop_link, + }; static const struct config_item_type connector_possible_encoders_group_type = { - .ct_item_ops = &connector_possible_encoders_item_operations, - .ct_owner = THIS_MODULE, + .ct_item_ops = &connector_possible_encoders_item_operations, + .ct_owner = THIS_MODULE, }; static struct config_group *make_connector_group(struct config_group *group, @@ -731,9 +744,10 @@ static struct config_group *make_connector_group(struct config_group *group, config_group_init_type_name(&connector->group, name, &connector_item_type); - config_group_init_type_name(&connector->possible_encoders_group, - "possible_encoders", - &connector_possible_encoders_group_type); + config_group_init_type_name( + &connector->possible_encoders_group, + "possible_encoders", + &connector_possible_encoders_group_type); configfs_add_default_group(&connector->possible_encoders_group, &connector->group); } @@ -742,12 +756,12 @@ static struct config_group *make_connector_group(struct config_group *group, } static struct configfs_group_operations connectors_group_operations = { - .make_group = &make_connector_group, + .make_group = &make_connector_group, }; static const struct config_item_type connector_group_type = { - .ct_group_ops = &connectors_group_operations, - .ct_owner = THIS_MODULE, + .ct_group_ops = &connectors_group_operations, + .ct_owner = THIS_MODULE, }; static ssize_t device_enabled_show(struct config_item *item, char *page) @@ -823,13 +837,13 @@ static void device_release(struct config_item *item) } static struct configfs_item_operations device_item_operations = { - .release = &device_release, + .release = &device_release, }; static const struct config_item_type device_item_type = { - .ct_attrs = device_item_attrs, - .ct_item_ops = &device_item_operations, - .ct_owner = THIS_MODULE, + .ct_attrs = device_item_attrs, + .ct_item_ops = &device_item_operations, + .ct_owner = THIS_MODULE, }; static struct config_group *make_device_group(struct config_group *group, @@ -879,8 +893,8 @@ static struct configfs_group_operations device_group_ops = { }; static const struct config_item_type device_group_type = { - .ct_group_ops = &device_group_ops, - .ct_owner = THIS_MODULE, + .ct_group_ops = &device_group_ops, + .ct_owner = THIS_MODULE, }; static struct configfs_subsystem vkms_subsys = { diff --git a/linux/vibeshine-drm/vkms_connector.c b/linux/vibeshine-drm/vkms_connector.c index d71752c..b1648ea 100644 --- a/linux/vibeshine-drm/vkms_connector.c +++ b/linux/vibeshine-drm/vkms_connector.c @@ -10,8 +10,8 @@ #include "vkms_connector.h" #include "vibeshine_hdr_edid.h" -static enum drm_connector_status vkms_connector_detect(struct drm_connector *connector, - bool force) +static enum drm_connector_status +vkms_connector_detect(struct drm_connector *connector, bool force) { struct vkms_connector *vkms_connector; @@ -30,14 +30,14 @@ static const struct drm_connector_funcs vkms_connector_funcs = { static int vkms_conn_get_modes(struct drm_connector *connector) { const struct drm_edid *drm_edid; - struct vkms_connector *vkms = drm_connector_to_vkms_connector(connector); + struct vkms_connector *vkms = + drm_connector_to_vkms_connector(connector); struct vibeshine_drm_requested_mode requested, doubled; struct drm_display_mode *entry; unsigned long flags; int count; - drm_edid = drm_edid_alloc(vibeshine_hdr_edid, - vibeshine_hdr_edid_len); + drm_edid = drm_edid_alloc(vibeshine_hdr_edid, vibeshine_hdr_edid_len); if (drm_edid) { drm_edid_connector_update(connector, drm_edid); count = drm_edid_connector_add_modes(connector); @@ -104,7 +104,8 @@ static int vkms_conn_get_modes(struct drm_connector *connector) return count; } -static struct drm_encoder *vkms_conn_best_encoder(struct drm_connector *connector) +static struct drm_encoder * +vkms_conn_best_encoder(struct drm_connector *connector) { struct drm_encoder *encoder; @@ -115,7 +116,7 @@ static struct drm_encoder *vkms_conn_best_encoder(struct drm_connector *connecto } static const struct drm_connector_helper_funcs vkms_conn_helper_funcs = { - .get_modes = vkms_conn_get_modes, + .get_modes = vkms_conn_get_modes, .best_encoder = vkms_conn_best_encoder, }; @@ -153,9 +154,8 @@ struct vkms_connector *vkms_connector_init(struct vkms_device *vkmsdev, return ERR_PTR(ret); drm_connector_attach_hdr_output_metadata_property(&connector->base); ret = drm_mode_create_hdmi_colorspace_property( - &connector->base, - BIT(DRM_MODE_COLORIMETRY_BT2020_RGB) | - BIT(DRM_MODE_COLORIMETRY_BT2020_YCC)); + &connector->base, BIT(DRM_MODE_COLORIMETRY_BT2020_RGB) | + BIT(DRM_MODE_COLORIMETRY_BT2020_YCC)); if (ret) return ERR_PTR(ret); ret = drm_connector_attach_colorspace_property(&connector->base); diff --git a/linux/vibeshine-drm/vkms_crtc.c b/linux/vibeshine-drm/vkms_crtc.c index b39bcbd..b8d1d50 100644 --- a/linux/vibeshine-drm/vkms_crtc.c +++ b/linux/vibeshine-drm/vkms_crtc.c @@ -57,8 +57,8 @@ static bool vkms_crtc_handle_vblank(struct drm_crtc *crtc) timestamp_ns = ktime_to_ns(vblank_time); if (!timestamp_ns) timestamp_ns = ktime_get_ns(); - vibeshine_drm_present_timing_complete(&present_state->present_timing, - true, timestamp_ns); + vibeshine_drm_present_timing_complete( + &present_state->present_timing, true, timestamp_ns); output->pending_present_state = NULL; } @@ -75,8 +75,9 @@ static bool vkms_crtc_handle_vblank(struct drm_crtc *crtc) if (!state->crc_pending) state->frame_start = frame; else - DRM_DEBUG_DRIVER("crc worker falling behind, frame_start: %llu, frame_end: %llu\n", - state->frame_start, frame); + DRM_DEBUG_DRIVER( + "crc worker falling behind, frame_start: %llu, frame_end: %llu\n", + state->frame_start, frame); state->frame_end = frame; state->crc_pending = true; spin_unlock_irqrestore(&output->composer_lock, flags); @@ -98,8 +99,8 @@ static bool vkms_crtc_handle_vblank_timeout(struct drm_crtc *crtc) static enum hrtimer_restart vkms_vrr_vblank_simulate(struct hrtimer *timer) { - struct vkms_output *output = container_of(timer, struct vkms_output, - vrr_hrtimer); + struct vkms_output *output = + container_of(timer, struct vkms_output, vrr_hrtimer); vkms_crtc_handle_vblank(&output->crtc); return HRTIMER_NORESTART; @@ -129,8 +130,8 @@ static void vkms_schedule_vrr_vblank(struct drm_crtc *crtc) static enum hrtimer_restart vkms_vblank_simulate(struct hrtimer *timer) { - struct vkms_output *output = container_of(timer, struct vkms_output, - vblank_hrtimer); + struct vkms_output *output = + container_of(timer, struct vkms_output, vblank_hrtimer); unsigned long flags; bool restart; u64 ret_overrun; @@ -141,8 +142,8 @@ static enum hrtimer_restart vkms_vblank_simulate(struct hrtimer *timer) spin_unlock_irqrestore(&output->vblank_timer_lock, flags); return HRTIMER_NORESTART; } - ret_overrun = hrtimer_forward_now(&output->vblank_hrtimer, - output->period_ns); + ret_overrun = + hrtimer_forward_now(&output->vblank_hrtimer, output->period_ns); spin_unlock_irqrestore(&output->vblank_timer_lock, flags); if (ret_overrun != 1) DRM_DEBUG_DRIVER("vblank timer overrun\n"); @@ -169,7 +170,8 @@ static int vkms_enable_vblank(struct drm_crtc *crtc) spin_lock_irqsave(&output->vblank_timer_lock, flags); output->period_ns = ktime_set(0, vblank->framedur_ns); output->vblank_timer_enabled = true; - hrtimer_start(&output->vblank_hrtimer, output->period_ns, HRTIMER_MODE_REL); + hrtimer_start(&output->vblank_hrtimer, output->period_ns, + HRTIMER_MODE_REL); spin_unlock_irqrestore(&output->vblank_timer_lock, flags); return 0; @@ -241,8 +243,7 @@ static u32 vkms_crtc_get_vblank_counter(struct drm_crtc *crtc) } static bool vkms_crtc_get_vblank_timestamp(struct drm_crtc *crtc, - int *max_error, - ktime_t *vblank_time, + int *max_error, ktime_t *vblank_time, bool in_vblank_irq) { struct vkms_output *output = drm_crtc_to_vkms_output(crtc); @@ -292,22 +293,22 @@ static bool vkms_crtc_get_vblank_timestamp(struct drm_crtc *crtc, } static const struct drm_crtc_funcs vkms_crtc_funcs = { - .set_config = drm_atomic_helper_set_config, - .page_flip = drm_atomic_helper_page_flip, - .reset = vkms_atomic_crtc_reset, + .set_config = drm_atomic_helper_set_config, + .page_flip = drm_atomic_helper_page_flip, + .reset = vkms_atomic_crtc_reset, .atomic_duplicate_state = vkms_atomic_crtc_duplicate_state, - .atomic_destroy_state = vkms_atomic_crtc_destroy_state, - .get_vblank_counter = vkms_crtc_get_vblank_counter, - .enable_vblank = vkms_enable_vblank, - .disable_vblank = vkms_disable_vblank, - .get_vblank_timestamp = vkms_crtc_get_vblank_timestamp, + .atomic_destroy_state = vkms_atomic_crtc_destroy_state, + .get_vblank_counter = vkms_crtc_get_vblank_counter, + .enable_vblank = vkms_enable_vblank, + .disable_vblank = vkms_disable_vblank, + .get_vblank_timestamp = vkms_crtc_get_vblank_timestamp, }; static int vkms_crtc_atomic_check(struct drm_crtc *crtc, struct drm_atomic_commit *state) { - struct drm_crtc_state *crtc_state = drm_atomic_get_new_crtc_state(state, - crtc); + struct drm_crtc_state *crtc_state = + drm_atomic_get_new_crtc_state(state, crtc); struct vkms_crtc_state *vkms_state = to_vkms_crtc_state(crtc_state); struct drm_plane *plane; struct drm_plane_state *plane_state; @@ -321,7 +322,8 @@ static int vkms_crtc_atomic_check(struct drm_crtc *crtc, return ret; drm_for_each_plane_mask(plane, crtc->dev, crtc_state->plane_mask) { - plane_state = drm_atomic_get_new_plane_state(crtc_state->state, plane); + plane_state = drm_atomic_get_new_plane_state(crtc_state->state, + plane); WARN_ON(!plane_state); if (!plane_state->visible) @@ -337,7 +339,8 @@ static int vkms_crtc_atomic_check(struct drm_crtc *crtc, i = 0; drm_for_each_plane_mask(plane, crtc->dev, crtc_state->plane_mask) { - plane_state = drm_atomic_get_new_plane_state(crtc_state->state, plane); + plane_state = drm_atomic_get_new_plane_state(crtc_state->state, + plane); if (!plane_state->visible) continue; @@ -384,20 +387,23 @@ static void vkms_crtc_atomic_flush(struct drm_crtc *crtc, if (drm_crtc_vblank_get(crtc) != 0) { /* No scheduled vblank: timestamp the immediate completion. */ - vibeshine_drm_present_timing_complete(&vkms_state->present_timing, - true, ktime_get_ns()); + vibeshine_drm_present_timing_complete( + &vkms_state->present_timing, true, + ktime_get_ns()); drm_crtc_send_vblank_event(crtc, crtc->state->event); } else { /* Only track an event wired to this commit's flip completion. */ if (vkms_state->base.commit && crtc->state->event->base.completion == - &vkms_state->base.commit->flip_done) { + &vkms_state->base.commit->flip_done) { /* hw_done follows publication, serializing this slot. */ - WARN_ON_ONCE(vkms_output->pending_present_state); + WARN_ON_ONCE( + vkms_output->pending_present_state); vkms_output->pending_present_state = vkms_state; } else { - vibeshine_drm_present_timing_complete(&vkms_state->present_timing, - true, ktime_get_ns()); + vibeshine_drm_present_timing_complete( + &vkms_state->present_timing, true, + ktime_get_ns()); } drm_crtc_arm_vblank_event(crtc, crtc->state->event); #if VIBESHINE_DRM_HAS_VBLANK_HELPER @@ -410,8 +416,8 @@ static void vkms_crtc_atomic_flush(struct drm_crtc *crtc, crtc->state->event = NULL; } else { /* Unsynchronized/no-event commits complete at the state update. */ - vibeshine_drm_present_timing_complete(&vkms_state->present_timing, - true, ktime_get_ns()); + vibeshine_drm_present_timing_complete( + &vkms_state->present_timing, true, ktime_get_ns()); } vkms_output->composer_state = to_vkms_crtc_state(crtc->state); @@ -448,8 +454,9 @@ static void vkms_crtc_atomic_enable(struct drm_crtc *crtc, /* drm_crtc_vblank_on() starts the timer after the initial atomic flush. */ if (crtc->state->vrr_enabled) { - atomic64_set(&drm_crtc_to_vkms_output(crtc)->vrr_vblank_timestamp_ns, - ktime_get_ns()); + atomic64_set( + &drm_crtc_to_vkms_output(crtc)->vrr_vblank_timestamp_ns, + ktime_get_ns()); vkms_disable_vblank(crtc); hrtimer_cancel(&drm_crtc_to_vkms_output(crtc)->vblank_hrtimer); } @@ -477,15 +484,15 @@ static void vkms_crtc_atomic_disable(struct drm_crtc *crtc, } static const struct drm_crtc_helper_funcs vkms_crtc_helper_funcs = { - .atomic_check = vkms_crtc_atomic_check, - .atomic_begin = vkms_crtc_atomic_begin, - .atomic_flush = vkms_crtc_atomic_flush, - .atomic_enable = vkms_crtc_atomic_enable, - .atomic_disable = vkms_crtc_atomic_disable, + .atomic_check = vkms_crtc_atomic_check, + .atomic_begin = vkms_crtc_atomic_begin, + .atomic_flush = vkms_crtc_atomic_flush, + .atomic_enable = vkms_crtc_atomic_enable, + .atomic_disable = vkms_crtc_atomic_disable, }; u64 vkms_crtc_take_present_timestamp(struct vkms_output *output, - struct drm_crtc_state *crtc_state) + struct drm_crtc_state *crtc_state) { struct vkms_crtc_state *vkms_state; u64 timestamp_ns; @@ -497,8 +504,8 @@ u64 vkms_crtc_take_present_timestamp(struct vkms_output *output, /* Also detach on timeout, before the atomic state can be destroyed. */ if (output->pending_present_state == vkms_state) output->pending_present_state = NULL; - timestamp_ns = vibeshine_drm_present_timing_finish(&vkms_state->present_timing, - ktime_get_ns()); + timestamp_ns = vibeshine_drm_present_timing_finish( + &vkms_state->present_timing, ktime_get_ns()); spin_unlock_irq(&output->lock); return timestamp_ns; } @@ -539,7 +546,8 @@ static void vkms_vblank_timer_cleanup(struct drm_device *dev, void *data) #endif } -struct vkms_output *vkms_crtc_init(struct drm_device *dev, struct drm_plane *primary, +struct vkms_output *vkms_crtc_init(struct drm_device *dev, + struct drm_plane *primary, struct drm_plane *cursor) { struct vkms_output *vkms_out; @@ -554,7 +562,8 @@ struct vkms_output *vkms_crtc_init(struct drm_device *dev, struct drm_plane *pri return vkms_out; } vkms_out->present_trace = kvcalloc(VIBESHINE_DRM_TRACE_HISTORY_SIZE, - sizeof(*vkms_out->present_trace), GFP_KERNEL); + sizeof(*vkms_out->present_trace), + GFP_KERNEL); if (!vkms_out->present_trace) return ERR_PTR(-ENOMEM); ret = drmm_add_action_or_reset(dev, vkms_present_trace_cleanup, @@ -587,7 +596,8 @@ struct vkms_output *vkms_crtc_init(struct drm_device *dev, struct drm_plane *pri hrtimer_setup(&vkms_out->vrr_hrtimer, &vkms_vrr_vblank_simulate, CLOCK_MONOTONIC, HRTIMER_MODE_ABS); #endif - ret = drmm_add_action_or_reset(dev, vkms_vblank_timer_cleanup, vkms_out); + ret = drmm_add_action_or_reset(dev, vkms_vblank_timer_cleanup, + vkms_out); if (ret) return ERR_PTR(ret); atomic64_set(&vkms_out->synthetic_vblank_counter, 0); @@ -604,7 +614,8 @@ struct vkms_output *vkms_crtc_init(struct drm_device *dev, struct drm_plane *pri if (ret) return ERR_PTR(ret); - vkms_out->composer_workq = drmm_alloc_ordered_workqueue(dev, "vkms_composer", 0); + vkms_out->composer_workq = + drmm_alloc_ordered_workqueue(dev, "vkms_composer", 0); if (IS_ERR(vkms_out->composer_workq)) return ERR_CAST(vkms_out->composer_workq); diff --git a/linux/vibeshine-drm/vkms_drv.c b/linux/vibeshine-drm/vkms_drv.c index 4b3d582..53643bc 100644 --- a/linux/vibeshine-drm/vkms_drv.c +++ b/linux/vibeshine-drm/vkms_drv.c @@ -55,10 +55,10 @@ #include "vibeshine_drm_compat.h" #include "vibeshine_drm_version.h" -#define DRIVER_NAME "vibeshine_drm" -#define DRIVER_DESC "Vibeshine HDR Virtual Display" -#define DRIVER_MAJOR 1 -#define DRIVER_MINOR 5 +#define DRIVER_NAME "vibeshine_drm" +#define DRIVER_DESC "Vibeshine HDR Virtual Display" +#define DRIVER_MAJOR 1 +#define DRIVER_MINOR 5 static struct vkms_config *default_config; @@ -68,7 +68,8 @@ MODULE_PARM_DESC(enable_cursor, "Enable/Disable cursor support"); static bool enable_writeback; module_param_named(enable_writeback, enable_writeback, bool, 0444); -MODULE_PARM_DESC(enable_writeback, "Enable/Disable writeback connector support"); +MODULE_PARM_DESC(enable_writeback, + "Enable/Disable writeback connector support"); static bool enable_overlay; module_param_named(enable_overlay, enable_overlay, bool, 0444); @@ -76,15 +77,18 @@ MODULE_PARM_DESC(enable_overlay, "Enable/Disable overlay support"); static bool enable_plane_pipeline; module_param_named(enable_plane_pipeline, enable_plane_pipeline, bool, 0444); -MODULE_PARM_DESC(enable_plane_pipeline, "Enable/Disable plane pipeline support"); +MODULE_PARM_DESC(enable_plane_pipeline, + "Enable/Disable plane pipeline support"); static bool create_default_dev = true; module_param_named(create_default_dev, create_default_dev, bool, 0444); MODULE_PARM_DESC(create_default_dev, "Create or not the default VKMS device"); -static long vkms_ioctl(struct file *file, unsigned int command, unsigned long argument); +static long vkms_ioctl(struct file *file, unsigned int command, + unsigned long argument); #ifdef CONFIG_COMPAT -static long vkms_compat_ioctl(struct file *file, unsigned int command, unsigned long argument); +static long vkms_compat_ioctl(struct file *file, unsigned int command, + unsigned long argument); #endif static const struct file_operations vkms_driver_fops = { @@ -105,13 +109,13 @@ static const struct file_operations vkms_driver_fops = { .fop_flags = FOP_UNSIGNED_OFFSET, }; -#define DRM_IOCTL_VIBESHINE_WAIT_PRESENT \ +#define DRM_IOCTL_VIBESHINE_WAIT_PRESENT \ DRM_IOWR(DRM_COMMAND_BASE + DRM_VIBESHINE_WAIT_PRESENT, \ struct vibeshine_drm_wait_present) -#define DRM_IOCTL_VIBESHINE_GET_FRAME \ +#define DRM_IOCTL_VIBESHINE_GET_FRAME \ DRM_IOWR(DRM_COMMAND_BASE + DRM_VIBESHINE_GET_FRAME, \ struct vibeshine_drm_frame) -#define DRM_IOCTL_VIBESHINE_GET_PRESENT_TRACE \ +#define DRM_IOCTL_VIBESHINE_GET_PRESENT_TRACE \ DRM_IOWR(DRM_COMMAND_BASE + DRM_VIBESHINE_GET_PRESENT_TRACE, \ struct vibeshine_drm_present_trace) @@ -144,8 +148,8 @@ static int vkms_wait_present_ioctl(struct drm_device *dev, void *data, request, atomic64_read(&output->present_sequence), output->present_waiters)) { case VIBESHINE_DRM_PRESENT_REJECT_BUSY: - spin_unlock_irq(&output->present_lock); - return -EBUSY; + spin_unlock_irq(&output->present_lock); + return -EBUSY; case VIBESHINE_DRM_PRESENT_REGISTER_WAITER: output->present_waiters++; waiter_registered = true; @@ -158,7 +162,8 @@ static int vkms_wait_present_ioctl(struct drm_device *dev, void *data, if (waiter_registered) { wait_result = wait_event_interruptible_timeout( output->present_waitq, - atomic64_read(&output->present_sequence) != requested_sequence, + atomic64_read(&output->present_sequence) != + requested_sequence, msecs_to_jiffies(request->timeout_ms)); spin_lock_irq(&output->present_lock); @@ -190,8 +195,8 @@ static bool vkms_frame_request_valid(const struct vibeshine_drm_frame *request) return !memcmp(request, &expected, sizeof(expected)); } -static bool -vkms_present_trace_request_valid(const struct vibeshine_drm_present_trace *request) +static bool vkms_present_trace_request_valid( + const struct vibeshine_drm_present_trace *request) { struct vibeshine_drm_present_trace expected = { .abi_version = VIBESHINE_DRM_TRACE_ABI_VERSION, @@ -228,7 +233,8 @@ static int vkms_get_present_trace_ioctl(struct drm_device *dev, void *data, current_sequence = atomic64_read(&output->present_sequence); first_sequence = request->after_sequence + 1; if (current_sequence >= VIBESHINE_DRM_TRACE_HISTORY_SIZE) { - u64 oldest_sequence = current_sequence - VIBESHINE_DRM_TRACE_HISTORY_SIZE + 1; + u64 oldest_sequence = + current_sequence - VIBESHINE_DRM_TRACE_HISTORY_SIZE + 1; if (first_sequence < oldest_sequence) { first_sequence = oldest_sequence; @@ -263,14 +269,16 @@ struct vkms_frame_export { bool include_color; }; -static int vkms_export_read_fence(struct dma_buf *dma_buf, struct vkms_frame_fds *fds) +static int vkms_export_read_fence(struct dma_buf *dma_buf, + struct vkms_frame_fds *fds) { struct dma_fence *fence; struct sync_file *sync_file; int number; int ret; - ret = dma_resv_get_singleton(dma_buf->resv, DMA_RESV_USAGE_WRITE, &fence); + ret = dma_resv_get_singleton(dma_buf->resv, DMA_RESV_USAGE_WRITE, + &fence); if (ret) return ret; if (!fence) @@ -285,7 +293,7 @@ static int vkms_export_read_fence(struct dma_buf *dma_buf, struct vkms_frame_fds } static struct dma_buf *vkms_get_frame_dmabuf(struct drm_file *file_priv, - struct drm_gem_object *obj) + struct drm_gem_object *obj) { struct dma_buf *dma_buf; u32 handle; @@ -314,7 +322,7 @@ static struct dma_buf *vkms_get_frame_dmabuf(struct drm_file *file_priv, return ERR_PTR(ret); dma_buf = drm_gem_prime_handle_to_dmabuf(obj->dev, file_priv, handle, - DRM_CLOEXEC | DRM_RDWR); + DRM_CLOEXEC | DRM_RDWR); drm_gem_handle_delete(file_priv, handle); return dma_buf; } @@ -338,7 +346,8 @@ u64 vkms_framebuffer_modifier(struct drm_framebuffer *fb) { /* Plain AddFB2's zero modifier does not describe imported storage. */ return vkms_framebuffer_has_implicit_import(fb) ? - DRM_FORMAT_MOD_INVALID : fb->modifier; + DRM_FORMAT_MOD_INVALID : + fb->modifier; } static int vkms_get_frame(struct drm_device *dev, void *data, @@ -375,9 +384,13 @@ static int vkms_get_frame(struct drm_device *dev, void *data, } spin_lock_irq(&output->present_lock); - if (leased && !vibeshine_capture_acquire(&output->capture, - READ_ONCE(drm_device_to_vkms_device(dev)->capture_stopping) || - !READ_ONCE(drm_device_to_vkms_device(dev)->accepting_commits))) { + if (leased && + !vibeshine_capture_acquire( + &output->capture, + READ_ONCE( + drm_device_to_vkms_device(dev)->capture_stopping) || + !READ_ONCE(drm_device_to_vkms_device(dev) + ->accepting_commits))) { spin_unlock_irq(&output->present_lock); vkms_capture_lease_put(lease); return -EBUSY; @@ -386,7 +399,8 @@ static int vkms_get_frame(struct drm_device *dev, void *data, request->timestamp_ns = output->present_timestamp_ns; if (export->include_color) { request->reserved_u32 = output->present_color; - memcpy(request->reserved, output->present_hdr_metadata, sizeof(request->reserved)); + memcpy(request->reserved, output->present_hdr_metadata, + sizeof(request->reserved)); } if (output->present_fb) { fb = output->present_fb; @@ -411,7 +425,7 @@ static int vkms_get_frame(struct drm_device *dev, void *data, } request->flags = VIBESHINE_DRM_FRAME_READY | - (leased ? VIBESHINE_DRM_FRAME_LEASED : 0); + (leased ? VIBESHINE_DRM_FRAME_LEASED : 0); request->width = fb->width; request->height = fb->height; request->fourcc = fb->format->format; @@ -440,8 +454,8 @@ static int vkms_get_frame(struct drm_device *dev, void *data, goto out; } } - request->dma_buf_fds[i] = vkms_frame_reserve_fd(&export->descriptors, - dma_buf->file); + request->dma_buf_fds[i] = vkms_frame_reserve_fd( + &export->descriptors, dma_buf->file); if (request->dma_buf_fds[i] < 0) { ret = request->dma_buf_fds[i]; dma_buf_put(dma_buf); @@ -456,7 +470,8 @@ static int vkms_get_frame(struct drm_device *dev, void *data, * remaining implicit write fence for explicit-sync importers; -1 means * no wait is required. */ - request->sync_file_fds[i] = vkms_export_read_fence(dma_buf, &export->descriptors); + request->sync_file_fds[i] = + vkms_export_read_fence(dma_buf, &export->descriptors); dma_buf_put(dma_buf); if (request->sync_file_fds[i] < -1) { ret = request->sync_file_fds[i]; @@ -471,21 +486,26 @@ static int vkms_get_frame(struct drm_device *dev, void *data, return ret; } -static int vkms_get_frame_ioctl(struct drm_device *dev, void *data, struct drm_file *file_priv) +static int vkms_get_frame_ioctl(struct drm_device *dev, void *data, + struct drm_file *file_priv) { return vkms_get_frame(dev, data, file_priv, false); } -#define DRM_IOCTL_VIBESHINE_GET_FRAME_LEASED \ - DRM_IOWR(DRM_COMMAND_BASE + DRM_VIBESHINE_GET_FRAME_LEASED, struct vibeshine_drm_frame) -static int vkms_get_frame_leased_ioctl(struct drm_device *dev, void *data, struct drm_file *file_priv) +#define DRM_IOCTL_VIBESHINE_GET_FRAME_LEASED \ + DRM_IOWR(DRM_COMMAND_BASE + DRM_VIBESHINE_GET_FRAME_LEASED, \ + struct vibeshine_drm_frame) +static int vkms_get_frame_leased_ioctl(struct drm_device *dev, void *data, + struct drm_file *file_priv) { return vkms_get_frame(dev, data, file_priv, true); } -#define DRM_IOCTL_VIBESHINE_GET_FRAME_COLOR \ - DRM_IOWR(DRM_COMMAND_BASE + DRM_VIBESHINE_GET_FRAME_COLOR, struct vibeshine_drm_frame) -static int vkms_get_frame_color_ioctl(struct drm_device *dev, void *data, struct drm_file *file_priv) +#define DRM_IOCTL_VIBESHINE_GET_FRAME_COLOR \ + DRM_IOWR(DRM_COMMAND_BASE + DRM_VIBESHINE_GET_FRAME_COLOR, \ + struct vibeshine_drm_frame) +static int vkms_get_frame_color_ioctl(struct drm_device *dev, void *data, + struct drm_file *file_priv) { struct vkms_frame_export *export = data; int ret; @@ -509,9 +529,12 @@ static long vkms_frame_ioctl(struct file *file, unsigned int command, { struct vkms_frame_export export = {}; struct drm_file *client = file->private_data; - drm_ioctl_t *operation = command == DRM_IOCTL_VIBESHINE_GET_FRAME_COLOR ? - vkms_get_frame_color_ioctl : (command == DRM_IOCTL_VIBESHINE_GET_FRAME_LEASED ? - vkms_get_frame_leased_ioctl : vkms_get_frame_ioctl); + drm_ioctl_t *operation = + command == DRM_IOCTL_VIBESHINE_GET_FRAME_COLOR ? + vkms_get_frame_color_ioctl : + (command == DRM_IOCTL_VIBESHINE_GET_FRAME_LEASED ? + vkms_get_frame_leased_ioctl : + vkms_get_frame_ioctl); void __user *reply = (void __user *)argument; int entered; long result; @@ -531,11 +554,12 @@ static long vkms_frame_ioctl(struct file *file, unsigned int command, static bool vkms_is_frame_ioctl(unsigned int command) { return command == DRM_IOCTL_VIBESHINE_GET_FRAME || - command == DRM_IOCTL_VIBESHINE_GET_FRAME_LEASED || - command == DRM_IOCTL_VIBESHINE_GET_FRAME_COLOR; + command == DRM_IOCTL_VIBESHINE_GET_FRAME_LEASED || + command == DRM_IOCTL_VIBESHINE_GET_FRAME_COLOR; } -static long vkms_ioctl(struct file *file, unsigned int command, unsigned long argument) +static long vkms_ioctl(struct file *file, unsigned int command, + unsigned long argument) { if (vkms_is_frame_ioctl(command)) return vkms_frame_ioctl(file, command, argument); @@ -548,7 +572,8 @@ static long vkms_compat_ioctl(struct file *file, unsigned int command, { /* Both private structures use fixed-width fields and have identical layout. */ if (vkms_is_frame_ioctl(command)) - return vkms_frame_ioctl(file, command, (unsigned long)compat_ptr(argument)); + return vkms_frame_ioctl(file, command, + (unsigned long)compat_ptr(argument)); return drm_compat_ioctl(file, command, argument); } #endif @@ -558,7 +583,8 @@ static const struct drm_ioctl_desc vkms_ioctls[] = { DRM_IOCTL_DEF_DRV(VIBESHINE_GET_FRAME_LEASED, drm_invalid_op, 0), DRM_IOCTL_DEF_DRV(VIBESHINE_WAIT_PRESENT, vkms_wait_present_ioctl, 0), DRM_IOCTL_DEF_DRV(VIBESHINE_GET_FRAME, drm_invalid_op, 0), - DRM_IOCTL_DEF_DRV(VIBESHINE_GET_PRESENT_TRACE, vkms_get_present_trace_ioctl, 0), + DRM_IOCTL_DEF_DRV(VIBESHINE_GET_PRESENT_TRACE, + vkms_get_present_trace_ioctl, 0), }; static bool vkms_commit_touches_crtc(struct drm_atomic_commit *state, @@ -584,20 +610,21 @@ static bool vkms_commit_touches_crtc(struct drm_atomic_commit *state, return true; } - for_each_oldnew_connector_in_state(state, connector, - old_connector_state, - new_connector_state, i) { - if ((old_connector_state && old_connector_state->crtc == target) || - (new_connector_state && new_connector_state->crtc == target)) + for_each_oldnew_connector_in_state( + state, connector, old_connector_state, new_connector_state, i) { + if ((old_connector_state && + old_connector_state->crtc == target) || + (new_connector_state && + new_connector_state->crtc == target)) return true; } return false; } -static void vkms_snapshot_plane_state( - struct drm_plane_state *state, - struct vibeshine_drm_plane_snapshot *snapshot) +static void +vkms_snapshot_plane_state(struct drm_plane_state *state, + struct vibeshine_drm_plane_snapshot *snapshot) { memset(snapshot, 0, sizeof(*snapshot)); if (!state) @@ -633,9 +660,9 @@ static void vkms_snapshot_plane_state( snapshot->scaling_filter = state->scaling_filter; } -static void vkms_snapshot_crtc_state( - const struct drm_crtc_state *state, - struct vibeshine_drm_crtc_snapshot *snapshot) +static void +vkms_snapshot_crtc_state(const struct drm_crtc_state *state, + struct vibeshine_drm_crtc_snapshot *snapshot) { memset(snapshot, 0, sizeof(*snapshot)); if (!state) @@ -662,9 +689,9 @@ static void vkms_snapshot_crtc_state( snapshot->vrr_enabled = state->vrr_enabled; } -static void vkms_snapshot_connector_state( - const struct drm_connector_state *state, - struct vibeshine_drm_connector_snapshot *snapshot) +static void +vkms_snapshot_connector_state(const struct drm_connector_state *state, + struct vibeshine_drm_connector_snapshot *snapshot) { memset(snapshot, 0, sizeof(*snapshot)); if (!state) @@ -674,7 +701,8 @@ static void vkms_snapshot_connector_state( snapshot->self_refresh_aware = state->self_refresh_aware; snapshot->crtc = (unsigned long)state->crtc; snapshot->best_encoder = (unsigned long)state->best_encoder; - snapshot->hdr_output_metadata = (unsigned long)state->hdr_output_metadata; + snapshot->hdr_output_metadata = + (unsigned long)state->hdr_output_metadata; snapshot->link_status = state->link_status; snapshot->picture_aspect_ratio = state->picture_aspect_ratio; snapshot->content_type = state->content_type; @@ -706,7 +734,8 @@ static bool vkms_commit_changes_crtc(struct drm_atomic_commit *state, continue; vkms_snapshot_crtc_state(old_crtc_state, &old_snapshot); vkms_snapshot_crtc_state(new_crtc_state, &new_snapshot); - if (vibeshine_drm_crtc_changes_scanout(&old_snapshot, &new_snapshot)) + if (vibeshine_drm_crtc_changes_scanout(&old_snapshot, + &new_snapshot)) return true; } @@ -719,21 +748,27 @@ static bool vkms_commit_changes_crtc(struct drm_atomic_commit *state, continue; vkms_snapshot_plane_state(old_plane_state, &old_snapshot); vkms_snapshot_plane_state(new_plane_state, &new_snapshot); - if (vibeshine_drm_plane_changes_scanout(&old_snapshot, &new_snapshot)) + if (vibeshine_drm_plane_changes_scanout(&old_snapshot, + &new_snapshot)) return true; } - for_each_oldnew_connector_in_state(state, connector, - old_connector_state, - new_connector_state, i) { - struct vibeshine_drm_connector_snapshot old_snapshot, new_snapshot; + for_each_oldnew_connector_in_state( + state, connector, old_connector_state, new_connector_state, i) { + struct vibeshine_drm_connector_snapshot old_snapshot, + new_snapshot; - if ((!old_connector_state || old_connector_state->crtc != target) && - (!new_connector_state || new_connector_state->crtc != target)) + if ((!old_connector_state || + old_connector_state->crtc != target) && + (!new_connector_state || + new_connector_state->crtc != target)) continue; - vkms_snapshot_connector_state(old_connector_state, &old_snapshot); - vkms_snapshot_connector_state(new_connector_state, &new_snapshot); - if (vibeshine_drm_connector_changes_scanout(&old_snapshot, &new_snapshot)) + vkms_snapshot_connector_state(old_connector_state, + &old_snapshot); + vkms_snapshot_connector_state(new_connector_state, + &new_snapshot); + if (vibeshine_drm_connector_changes_scanout(&old_snapshot, + &new_snapshot)) return true; } @@ -743,30 +778,37 @@ static bool vkms_commit_changes_crtc(struct drm_atomic_commit *state, /* Connector colour belongs to the completed presentation, not to a later * live connector state. The commit retains its blobs until this copy ends. * Called under present_lock; never retain a pointer into the atomic state. */ -static void vkms_publish_color(struct drm_atomic_commit *state, struct drm_crtc *crtc, +static void vkms_publish_color(struct drm_atomic_commit *state, + struct drm_crtc *crtc, struct vkms_output *output) { struct drm_connector *connector; struct drm_connector_state *old_state, *new_state; int i; - BUILD_BUG_ON(sizeof(struct hdr_output_metadata) != sizeof(output->present_hdr_metadata)); - for_each_oldnew_connector_in_state(state, connector, old_state, new_state, i) { + BUILD_BUG_ON(sizeof(struct hdr_output_metadata) != + sizeof(output->present_hdr_metadata)); + for_each_oldnew_connector_in_state(state, connector, old_state, + new_state, i) { const struct hdr_output_metadata *hdr; if (!new_state || new_state->crtc != crtc) continue; output->present_color = VIBESHINE_DRM_COLOR_UNKNOWN; - memset(output->present_hdr_metadata, 0, sizeof(output->present_hdr_metadata)); + memset(output->present_hdr_metadata, 0, + sizeof(output->present_hdr_metadata)); if (!new_state->hdr_output_metadata) { - if (new_state->colorspace == DRM_MODE_COLORIMETRY_DEFAULT) - output->present_color = VIBESHINE_DRM_COLOR_SRGB; + if (new_state->colorspace == + DRM_MODE_COLORIMETRY_DEFAULT) + output->present_color = + VIBESHINE_DRM_COLOR_SRGB; continue; } if (new_state->hdr_output_metadata->length != sizeof(*hdr)) continue; hdr = new_state->hdr_output_metadata->data; - if (hdr->metadata_type != 0 || hdr->hdmi_metadata_type1.metadata_type != 0 || + if (hdr->metadata_type != 0 || + hdr->hdmi_metadata_type1.metadata_type != 0 || hdr->hdmi_metadata_type1.eotf != 2 || new_state->colorspace != DRM_MODE_COLORIMETRY_BT2020_RGB) continue; @@ -793,11 +835,13 @@ static void vkms_signal_presented_crtcs(struct drm_atomic_commit *state) scanout_changed = vkms_commit_changes_crtc(state, crtc); output = drm_crtc_to_vkms_output(crtc); - primary_state = drm_atomic_get_new_plane_state(state, crtc->primary); + primary_state = + drm_atomic_get_new_plane_state(state, crtc->primary); crtc_state = drm_atomic_get_new_crtc_state(state, crtc); - presentation_timestamp_ns = vkms_crtc_take_present_timestamp(output, - crtc_state); - if (primary_state && primary_state->fb && primary_state->visible) { + presentation_timestamp_ns = + vkms_crtc_take_present_timestamp(output, crtc_state); + if (primary_state && primary_state->fb && + primary_state->visible) { new_present_fb = primary_state->fb; drm_framebuffer_get(new_present_fb); } @@ -806,18 +850,24 @@ static void vkms_signal_presented_crtcs(struct drm_atomic_commit *state) u64 completed_sequence; struct vibeshine_drm_trace_event *trace_event; - if (primary_state || (crtc_state && !crtc_state->active)) { + if (primary_state || + (crtc_state && !crtc_state->active)) { old_present_fb = output->present_fb; output->present_fb = new_present_fb; new_present_fb = NULL; } vkms_publish_color(state, crtc, output); - output->present_timestamp_ns = presentation_timestamp_ns; - completed_sequence = atomic64_inc_return(&output->present_sequence); - trace_event = &output->present_trace[(completed_sequence - 1) % - VIBESHINE_DRM_TRACE_HISTORY_SIZE]; + output->present_timestamp_ns = + presentation_timestamp_ns; + completed_sequence = + atomic64_inc_return(&output->present_sequence); + trace_event = + &output->present_trace + [(completed_sequence - 1) % + VIBESHINE_DRM_TRACE_HISTORY_SIZE]; trace_event->sequence = completed_sequence; - trace_event->timestamp_ns = output->present_timestamp_ns; + trace_event->timestamp_ns = + output->present_timestamp_ns; } WARN_ON_ONCE(!vibeshine_capture_publish(&output->capture)); if (WARN_ON_ONCE(atomic_read(&output->pending_commits) <= 0)) @@ -848,7 +898,8 @@ static void vkms_update_pending_crtcs(struct drm_atomic_commit *state, bool add) if (add) { atomic_inc(&output->pending_commits); } else { - if (WARN_ON_ONCE(atomic_read(&output->pending_commits) <= 0)) + if (WARN_ON_ONCE( + atomic_read(&output->pending_commits) <= 0)) atomic_set(&output->pending_commits, 0); else atomic_dec(&output->pending_commits); @@ -858,7 +909,8 @@ static void vkms_update_pending_crtcs(struct drm_atomic_commit *state, bool add) } } -static void vkms_mark_presentation_content_updates(struct drm_atomic_commit *state) +static void +vkms_mark_presentation_content_updates(struct drm_atomic_commit *state) { struct drm_plane_state *new_plane_state; struct drm_plane *plane; @@ -870,7 +922,8 @@ static void vkms_mark_presentation_content_updates(struct drm_atomic_commit *sta * Both are consumed before commit_tail decides whether scanout changed. */ for_each_new_plane_in_state(state, plane, new_plane_state, i) - to_vkms_plane_state(new_plane_state)->presentation_content_update = + to_vkms_plane_state(new_plane_state) + ->presentation_content_update = new_plane_state->fence != NULL; } @@ -909,7 +962,8 @@ static void vkms_atomic_commit_tail(struct drm_atomic_commit *old_state) drm_atomic_helper_commit_hw_done(old_state); for_each_old_crtc_in_state(old_state, crtc, old_crtc_state, i) { - struct vkms_crtc_state *vkms_state = to_vkms_crtc_state(old_crtc_state); + struct vkms_crtc_state *vkms_state = + to_vkms_crtc_state(old_crtc_state); flush_work(&vkms_state->composer_work); } @@ -918,31 +972,34 @@ static void vkms_atomic_commit_tail(struct drm_atomic_commit *old_state) } static const struct drm_driver vkms_driver = { - .driver_features = DRIVER_MODESET | DRIVER_ATOMIC | DRIVER_GEM, - .fops = &vkms_driver_fops, - .ioctls = vkms_ioctls, - .num_ioctls = ARRAY_SIZE(vkms_ioctls), + .driver_features = DRIVER_MODESET | DRIVER_ATOMIC | DRIVER_GEM, + .fops = &vkms_driver_fops, + .ioctls = vkms_ioctls, + .num_ioctls = ARRAY_SIZE(vkms_ioctls), VIBESHINE_DRM_SHMEM_DRIVER_OPS, DRM_FBDEV_SHMEM_DRIVER_OPS, - .name = DRIVER_NAME, - .desc = DRIVER_DESC, - .major = DRIVER_MAJOR, - .minor = DRIVER_MINOR, + .name = DRIVER_NAME, + .desc = DRIVER_DESC, + .major = DRIVER_MAJOR, + .minor = DRIVER_MINOR, }; -static int vkms_atomic_check(struct drm_device *dev, struct drm_atomic_commit *state) +static int vkms_atomic_check(struct drm_device *dev, + struct drm_atomic_commit *state) { struct drm_crtc *crtc; struct drm_crtc_state *new_crtc_state; int i; for_each_new_crtc_in_state(state, crtc, new_crtc_state, i) { - if (!new_crtc_state->gamma_lut || !new_crtc_state->color_mgmt_changed) + if (!new_crtc_state->gamma_lut || + !new_crtc_state->color_mgmt_changed) continue; - if (new_crtc_state->gamma_lut->length / sizeof(struct drm_color_lut *) - > VKMS_LUT_SIZE) + if (new_crtc_state->gamma_lut->length / + sizeof(struct drm_color_lut *) > + VKMS_LUT_SIZE) return -EINVAL; } @@ -952,7 +1009,8 @@ static int vkms_atomic_check(struct drm_device *dev, struct drm_atomic_commit *s /* Reserve every touched output before the helper swaps state. The commit lock * serializes reservations and rollback; present_lock serializes each reservation * with capture acquisition. Never wait for a lease held by the ioctl caller. */ -static int vkms_reserve_capture_outputs(struct drm_atomic_commit *state, bool nonblock) +static int vkms_reserve_capture_outputs(struct drm_atomic_commit *state, + bool nonblock) { struct drm_crtc *crtc; struct drm_crtc *failed = NULL; @@ -1115,7 +1173,8 @@ static int vkms_drain_capture(struct vkms_device *vkmsdev) remaining = (long)(deadline - jiffies); if (remaining <= 0) return -EBUSY; - result = wait_event_interruptible_timeout(output->capture_waitq, + result = wait_event_interruptible_timeout( + output->capture_waitq, !READ_ONCE(output->capture.readers), remaining); if (result < 0) return result; @@ -1173,7 +1232,8 @@ static int vkms_quiesce(struct vkms_device *vkmsdev) static int vkms_shutdown_release(struct vkms_device *vkmsdev) { if (vkms_quiesce(vkmsdev)) { - DRM_ERROR("cannot release virtual scanout while capture leases remain\n"); + DRM_ERROR( + "cannot release virtual scanout while capture leases remain\n"); return -EBUSY; } @@ -1203,8 +1263,7 @@ static int vkms_shutdown_release(struct vkms_device *vkmsdev) return 0; } -static ssize_t quiesce_store(struct device *dev, - struct device_attribute *attr, +static ssize_t quiesce_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { struct vkms_device *vkmsdev = dev_get_drvdata(dev); @@ -1239,9 +1298,8 @@ static const struct attribute_group vkms_device_attr_group = { static int vkms_reboot_notifier(struct notifier_block *notifier, unsigned long action, void *data) { - struct vkms_device *vkmsdev = container_of(notifier, - struct vkms_device, - reboot_notifier); + struct vkms_device *vkmsdev = + container_of(notifier, struct vkms_device, reboot_notifier); (void)action; (void)data; @@ -1249,7 +1307,8 @@ static int vkms_reboot_notifier(struct notifier_block *notifier, /* Best effort: reboot cannot force a live capture importer to release. */ DRM_INFO("releasing virtual scanout before system shutdown\n"); if (vkms_shutdown_release(vkmsdev)) - DRM_ERROR("GPU imports may remain active during device shutdown\n"); + DRM_ERROR( + "GPU imports may remain active during device shutdown\n"); return NOTIFY_DONE; } @@ -1357,7 +1416,8 @@ static int __init vkms_init(void) return 0; config = vkms_config_default_create(enable_cursor, enable_writeback, - enable_overlay, enable_plane_pipeline); + enable_overlay, + enable_plane_pipeline); if (IS_ERR(config)) { ret = PTR_ERR(config); goto out_configfs; diff --git a/linux/vibeshine-drm/vkms_drv.h b/linux/vibeshine-drm/vkms_drv.h index 293f81a..0f80b6e 100644 --- a/linux/vibeshine-drm/vkms_drv.h +++ b/linux/vibeshine-drm/vkms_drv.h @@ -22,14 +22,14 @@ #define DEFAULT_DEVICE_NAME "vkms" -#define XRES_MIN 10 -#define YRES_MIN 10 +#define XRES_MIN 10 +#define YRES_MIN 10 -#define XRES_DEF 1024 -#define YRES_DEF 768 +#define XRES_DEF 1024 +#define YRES_DEF 768 -#define XRES_MAX 8192 -#define YRES_MAX 8192 +#define XRES_MAX 8192 +#define YRES_MAX 8192 #define NUM_OVERLAY_PLANES 8 @@ -92,7 +92,8 @@ struct line_buffer { * @out_pixel: destination address to write the pixel * @in_pixel: pixel to write */ -typedef void (*pixel_write_t)(u8 *out_pixel, const struct pixel_argb_u16 *in_pixel); +typedef void (*pixel_write_t)(u8 *out_pixel, + const struct pixel_argb_u16 *in_pixel); struct vkms_writeback_job { struct iosys_map data[DRM_FORMAT_MAX_PLANES]; @@ -128,9 +129,10 @@ struct vkms_plane_state; * (included) to @out_pixel[@count] (excluded). The caller must ensure that out_pixel have a * length of at least @count. */ -typedef void (*pixel_read_line_t)(const struct vkms_plane_state *plane, int x_start, - int y_start, enum pixel_read_direction direction, int count, - struct pixel_argb_u16 out_pixel[]); +typedef void (*pixel_read_line_t)(const struct vkms_plane_state *plane, + int x_start, int y_start, + enum pixel_read_direction direction, + int count, struct pixel_argb_u16 out_pixel[]); /** * struct conversion_matrix - Matrix to use for a specific encoding and range @@ -320,10 +322,10 @@ struct vkms_device { #define drm_device_to_vkms_device(target) \ container_of(target, struct vkms_device, drm) -#define to_vkms_crtc_state(target)\ +#define to_vkms_crtc_state(target) \ container_of(target, struct vkms_crtc_state, base) -#define to_vkms_plane_state(target)\ +#define to_vkms_plane_state(target) \ container_of(target, struct vkms_plane_state, base.base) /** @@ -358,7 +360,7 @@ struct vkms_output *vkms_crtc_init(struct drm_device *dev, struct drm_plane *cursor); void vkms_crtc_release_presented_frame(struct vkms_output *output); u64 vkms_crtc_take_present_timestamp(struct vkms_output *output, - struct drm_crtc_state *crtc_state); + struct drm_crtc_state *crtc_state); bool vkms_framebuffer_has_implicit_import(struct drm_framebuffer *fb); u64 vkms_framebuffer_modifier(struct drm_framebuffer *fb); @@ -380,8 +382,7 @@ struct vkms_plane *vkms_plane_init(struct vkms_device *vkmsdev, struct vkms_config_plane *plane_cfg); /* CRC Support */ -const char *const *vkms_get_crc_sources(struct drm_crtc *crtc, - size_t *count); +const char *const *vkms_get_crc_sources(struct drm_crtc *crtc, size_t *count); int vkms_set_crc_source(struct drm_crtc *crtc, const char *src_name); int vkms_verify_crc_source(struct drm_crtc *crtc, const char *source_name, size_t *values_cnt); @@ -389,10 +390,12 @@ int vkms_verify_crc_source(struct drm_crtc *crtc, const char *source_name, /* Composer Support */ void vkms_composer_worker(struct work_struct *work); void vkms_set_composer(struct vkms_output *out, bool enabled); -void vkms_writeback_row(struct vkms_writeback_job *wb, const struct line_buffer *src_buffer, int y); +void vkms_writeback_row(struct vkms_writeback_job *wb, + const struct line_buffer *src_buffer, int y); /* Writeback */ -int vkms_enable_writeback_connector(struct vkms_device *vkmsdev, struct vkms_output *vkms_out); +int vkms_enable_writeback_connector(struct vkms_device *vkmsdev, + struct vkms_output *vkms_out); /* Colorops */ int vkms_initialize_colorops(struct drm_plane *plane); diff --git a/linux/vibeshine-drm/vkms_formats.c b/linux/vibeshine-drm/vkms_formats.c index 8d2261d..21bbea8 100644 --- a/linux/vibeshine-drm/vkms_formats.c +++ b/linux/vibeshine-drm/vkms_formats.c @@ -31,8 +31,9 @@ * * With this function, the caller just have to extract the correct pixel from the block. */ -static void packed_pixels_offset(const struct vkms_frame_info *frame_info, int x, int y, - int plane_index, int *offset, int *rem_x, int *rem_y) +static void packed_pixels_offset(const struct vkms_frame_info *frame_info, + int x, int y, int plane_index, int *offset, + int *rem_x, int *rem_y) { struct drm_framebuffer *fb = frame_info->fb; const struct drm_format_info *format = frame_info->fb->format; @@ -45,12 +46,11 @@ static void packed_pixels_offset(const struct vkms_frame_info *frame_info, int x int block_x = x / drm_format_info_block_width(format, plane_index); int block_y = y / drm_format_info_block_height(format, plane_index); - int block_pitch = fb->pitches[plane_index] * drm_format_info_block_height(format, - plane_index); + int block_pitch = fb->pitches[plane_index] * + drm_format_info_block_height(format, plane_index); *rem_x = x % drm_format_info_block_width(format, plane_index); *rem_y = y % drm_format_info_block_height(format, plane_index); - *offset = fb->offsets[plane_index] + - block_y * block_pitch + + *offset = fb->offsets[plane_index] + block_y * block_pitch + block_x * format->char_per_block[plane_index]; } @@ -71,13 +71,14 @@ static void packed_pixels_offset(const struct vkms_frame_info *frame_info, int x * * See @packed_pixels_offset for details about rem_x/rem_y behavior. */ -static void packed_pixels_addr(const struct vkms_frame_info *frame_info, - int x, int y, int plane_index, u8 **addr, int *rem_x, +static void packed_pixels_addr(const struct vkms_frame_info *frame_info, int x, + int y, int plane_index, u8 **addr, int *rem_x, int *rem_y) { int offset; - packed_pixels_offset(frame_info, x, y, plane_index, &offset, rem_x, rem_y); + packed_pixels_offset(frame_info, x, y, plane_index, &offset, rem_x, + rem_y); *addr = (u8 *)frame_info->map[0].vaddr + offset; } @@ -94,7 +95,8 @@ static void packed_pixels_addr(const struct vkms_frame_info *frame_info, * left to right in a DRM_FORMAT_R1 plane, each block contains 8 pixels, so the step must be used * only every 8 pixels). */ -static int get_block_step_bytes(struct drm_framebuffer *fb, enum pixel_read_direction direction, +static int get_block_step_bytes(struct drm_framebuffer *fb, + enum pixel_read_direction direction, int plane_index) { switch (direction) { @@ -103,11 +105,11 @@ static int get_block_step_bytes(struct drm_framebuffer *fb, enum pixel_read_dire case READ_RIGHT_TO_LEFT: return -fb->format->char_per_block[plane_index]; case READ_TOP_TO_BOTTOM: - return (int)fb->pitches[plane_index] * drm_format_info_block_width(fb->format, - plane_index); + return (int)fb->pitches[plane_index] * + drm_format_info_block_width(fb->format, plane_index); case READ_BOTTOM_TO_TOP: - return -(int)fb->pitches[plane_index] * drm_format_info_block_width(fb->format, - plane_index); + return -(int)fb->pitches[plane_index] * + drm_format_info_block_width(fb->format, plane_index); } return 0; @@ -132,10 +134,10 @@ static void packed_pixels_addr_1x1(const struct vkms_frame_info *frame_info, WARN_ONCE(drm_format_info_block_width(frame_info->fb->format, plane_index) != 1, - "%s() only support formats with block_w == 1", __func__); + "%s() only support formats with block_w == 1", __func__); WARN_ONCE(drm_format_info_block_height(frame_info->fb->format, plane_index) != 1, - "%s() only support formats with block_h == 1", __func__); + "%s() only support formats with block_h == 1", __func__); packed_pixels_offset(frame_info, x, y, plane_index, &offset, &rem_x, &rem_y); @@ -171,7 +173,8 @@ static int get_subsampling(const struct drm_format_info *format, * @x_start: x coordinate of the starting point of the readed line * @y_start: y coordinate of the starting point of the readed line */ -static int get_subsampling_offset(enum pixel_read_direction direction, int x_start, int y_start) +static int get_subsampling_offset(enum pixel_read_direction direction, + int x_start, int y_start) { switch (direction) { case READ_BOTTOM_TO_TOP: @@ -223,10 +226,11 @@ static struct pixel_argb_u16 argb_u16_from_u16161616(u16 a, u16 r, u16 g, u16 b) return out_pixel; } -static struct pixel_argb_u16 argb_u16_from_le16161616(__le16 a, __le16 r, __le16 g, __le16 b) +static struct pixel_argb_u16 argb_u16_from_le16161616(__le16 a, __le16 r, + __le16 g, __le16 b) { - return argb_u16_from_u16161616(le16_to_cpu(a), le16_to_cpu(r), le16_to_cpu(g), - le16_to_cpu(b)); + return argb_u16_from_u16161616(le16_to_cpu(a), le16_to_cpu(r), + le16_to_cpu(g), le16_to_cpu(b)); } static struct pixel_argb_u16 argb_u16_from_xrgb2101010(const __le32 *pixel) @@ -306,8 +310,9 @@ static struct pixel_argb_u16 argb_u16_from_BGR565(const __le16 *pixel) } VISIBLE_IF_KUNIT -struct pixel_argb_u16 argb_u16_from_yuv161616(const struct conversion_matrix *matrix, - u16 y, u16 channel_1, u16 channel_2) +struct pixel_argb_u16 +argb_u16_from_yuv161616(const struct conversion_matrix *matrix, u16 y, + u16 channel_1, u16 channel_2) { u16 r, g, b; s64 fp_y, fp_channel_1, fp_channel_2; @@ -350,24 +355,28 @@ struct pixel_argb_u16 argb_u16_from_yuv161616(const struct conversion_matrix *ma * __VA_ARGS__: Argument to pass inside the callback. You can use @pixel_name to access current * pixel. */ -#define READ_LINE(function_name, pixel_name, pixel_type, callback, ...) \ -static void function_name(const struct vkms_plane_state *plane, int x_start, \ - int y_start, enum pixel_read_direction direction, int count, \ - struct pixel_argb_u16 out_pixel[]) \ -{ \ - struct pixel_argb_u16 *end = out_pixel + count; \ - int step = get_block_step_bytes(plane->frame_info->fb, direction, 0); \ - u8 *src_pixels; \ - \ - packed_pixels_addr_1x1(plane->frame_info, x_start, y_start, 0, &src_pixels); \ - \ - while (out_pixel < end) { \ - pixel_type *(pixel_name) = (pixel_type *)src_pixels; \ - *out_pixel = (callback)(__VA_ARGS__); \ - out_pixel += 1; \ - src_pixels += step; \ - } \ -} +#define READ_LINE(function_name, pixel_name, pixel_type, callback, ...) \ + static void function_name(const struct vkms_plane_state *plane, \ + int x_start, int y_start, \ + enum pixel_read_direction direction, \ + int count, \ + struct pixel_argb_u16 out_pixel[]) \ + { \ + struct pixel_argb_u16 *end = out_pixel + count; \ + int step = get_block_step_bytes(plane->frame_info->fb, \ + direction, 0); \ + u8 *src_pixels; \ + \ + packed_pixels_addr_1x1(plane->frame_info, x_start, y_start, 0, \ + &src_pixels); \ + \ + while (out_pixel < end) { \ + pixel_type *(pixel_name) = (pixel_type *)src_pixels; \ + *out_pixel = (callback)(__VA_ARGS__); \ + out_pixel += 1; \ + src_pixels += step; \ + } \ + } /** * READ_LINE_ARGB8888() - Generic generator for ARGB8888 formats. @@ -380,8 +389,9 @@ static void function_name(const struct vkms_plane_state *plane, int x_start, \ * @g: green value * @b: blue value */ -#define READ_LINE_ARGB8888(function_name, pixel_name, a, r, g, b) \ - READ_LINE(function_name, pixel_name, u8, argb_u16_from_u8888, a, r, g, b) +#define READ_LINE_ARGB8888(function_name, pixel_name, a, r, g, b) \ + READ_LINE(function_name, pixel_name, u8, argb_u16_from_u8888, a, r, g, \ + b) /** * READ_LINE_le16161616() - Generic generator for ARGB16161616 formats. * The pixel type used is u16, so pixel_name[0]..pixel_name[n] are the n components of the pixel. @@ -393,8 +403,9 @@ static void function_name(const struct vkms_plane_state *plane, int x_start, \ * @g: green value * @b: blue value */ -#define READ_LINE_le16161616(function_name, pixel_name, a, r, g, b) \ - READ_LINE(function_name, pixel_name, __le16, argb_u16_from_le16161616, a, r, g, b) +#define READ_LINE_le16161616(function_name, pixel_name, a, r, g, b) \ + READ_LINE(function_name, pixel_name, __le16, argb_u16_from_le16161616, \ + a, r, g, b) /* * The following functions are read_line function for each pixel format supported by VKMS. @@ -410,24 +421,28 @@ static void function_name(const struct vkms_plane_state *plane, int x_start, \ */ static void Rx_read_line(const struct vkms_plane_state *plane, int x_start, - int y_start, enum pixel_read_direction direction, int count, - struct pixel_argb_u16 out_pixel[]) + int y_start, enum pixel_read_direction direction, + int count, struct pixel_argb_u16 out_pixel[]) { struct pixel_argb_u16 *end = out_pixel + count; - int bits_per_pixel = drm_format_info_bpp(plane->frame_info->fb->format, 0); + int bits_per_pixel = + drm_format_info_bpp(plane->frame_info->fb->format, 0); u8 *src_pixels; int rem_x, rem_y; - WARN_ONCE(drm_format_info_block_height(plane->frame_info->fb->format, 0) != 1, + WARN_ONCE(drm_format_info_block_height(plane->frame_info->fb->format, + 0) != 1, "%s() only support formats with block_h == 1", __func__); - packed_pixels_addr(plane->frame_info, x_start, y_start, 0, &src_pixels, &rem_x, &rem_y); + packed_pixels_addr(plane->frame_info, x_start, y_start, 0, &src_pixels, + &rem_x, &rem_y); int bit_offset = (8 - bits_per_pixel) - rem_x * bits_per_pixel; int step = get_block_step_bytes(plane->frame_info->fb, direction, 0); int mask = (0x1 << bits_per_pixel) - 1; int lum_per_level = 0xFFFF / mask; - if (direction == READ_LEFT_TO_RIGHT || direction == READ_RIGHT_TO_LEFT) { + if (direction == READ_LEFT_TO_RIGHT || + direction == READ_RIGHT_TO_LEFT) { int restart_bit_offset; int step_bit_offset; @@ -442,7 +457,8 @@ static void Rx_read_line(const struct vkms_plane_state *plane, int x_start, while (out_pixel < end) { u8 val = ((*src_pixels) >> bit_offset) & mask; - *out_pixel = argb_u16_from_grayu16((int)val * lum_per_level); + *out_pixel = + argb_u16_from_grayu16((int)val * lum_per_level); bit_offset += step_bit_offset; if (bit_offset < 0 || 8 <= bit_offset) { @@ -451,10 +467,12 @@ static void Rx_read_line(const struct vkms_plane_state *plane, int x_start, } out_pixel += 1; } - } else if (direction == READ_TOP_TO_BOTTOM || direction == READ_BOTTOM_TO_TOP) { + } else if (direction == READ_TOP_TO_BOTTOM || + direction == READ_BOTTOM_TO_TOP) { while (out_pixel < end) { u8 val = (*src_pixels >> bit_offset) & mask; - *out_pixel = argb_u16_from_grayu16((int)val * lum_per_level); + *out_pixel = + argb_u16_from_grayu16((int)val * lum_per_level); src_pixels += step; out_pixel += 1; } @@ -462,27 +480,26 @@ static void Rx_read_line(const struct vkms_plane_state *plane, int x_start, } static void R1_read_line(const struct vkms_plane_state *plane, int x_start, - int y_start, enum pixel_read_direction direction, int count, - struct pixel_argb_u16 out_pixel[]) + int y_start, enum pixel_read_direction direction, + int count, struct pixel_argb_u16 out_pixel[]) { Rx_read_line(plane, x_start, y_start, direction, count, out_pixel); } static void R2_read_line(const struct vkms_plane_state *plane, int x_start, - int y_start, enum pixel_read_direction direction, int count, - struct pixel_argb_u16 out_pixel[]) + int y_start, enum pixel_read_direction direction, + int count, struct pixel_argb_u16 out_pixel[]) { Rx_read_line(plane, x_start, y_start, direction, count, out_pixel); } static void R4_read_line(const struct vkms_plane_state *plane, int x_start, - int y_start, enum pixel_read_direction direction, int count, - struct pixel_argb_u16 out_pixel[]) + int y_start, enum pixel_read_direction direction, + int count, struct pixel_argb_u16 out_pixel[]) { Rx_read_line(plane, x_start, y_start, direction, count, out_pixel); } - READ_LINE_ARGB8888(XRGB8888_read_line, px, 0xFF, px[2], px[1], px[0]) READ_LINE_ARGB8888(XBGR8888_read_line, px, 0xFF, px[0], px[1], px[2]) @@ -499,15 +516,22 @@ READ_LINE(XBGR2101010_read_line, px, __le32, argb_u16_from_xbgr2101010, px) READ_LINE(ARGB2101010_read_line, px, __le32, argb_u16_from_argb2101010, px) READ_LINE(ABGR2101010_read_line, px, __le32, argb_u16_from_abgr2101010, px) -READ_LINE_le16161616(ARGB16161616_read_line, px, px[3], px[2], px[1], px[0]) -READ_LINE_le16161616(ABGR16161616_read_line, px, px[3], px[0], px[1], px[2]) -READ_LINE_le16161616(XRGB16161616_read_line, px, cpu_to_le16(0xFFFF), px[2], px[1], px[0]) -READ_LINE_le16161616(XBGR16161616_read_line, px, cpu_to_le16(0xFFFF), px[0], px[1], px[2]) +READ_LINE_le16161616(ARGB16161616_read_line, px, px[3], px[2], px[1], + px[0]) READ_LINE_le16161616(ABGR16161616_read_line, px, + px[3], px[0], px[1], px[2]) + READ_LINE_le16161616(XRGB16161616_read_line, px, cpu_to_le16(0xFFFF), + px[2], px[1], + px[0]) READ_LINE_le16161616(XBGR16161616_read_line, + px, + cpu_to_le16(0xFFFF), + px[0], px[1], px[2]) -READ_LINE(RGB565_read_line, px, __le16, argb_u16_from_RGB565, px) -READ_LINE(BGR565_read_line, px, __le16, argb_u16_from_BGR565, px) + READ_LINE(RGB565_read_line, px, __le16, argb_u16_from_RGB565, + px) READ_LINE(BGR565_read_line, px, __le16, + argb_u16_from_BGR565, px) -READ_LINE(R8_read_line, px, u8, argb_u16_from_gray8, *px) + READ_LINE(R8_read_line, px, u8, argb_u16_from_gray8, + *px) /* * This callback can be used for YUV formats where U and V values are @@ -534,43 +558,59 @@ READ_LINE(R8_read_line, px, u8, argb_u16_from_gray8, *px) * __VA_ARGS__: Argument to pass inside the callback. You can use @pixel_1_name and @pixel_2_name * to access current pixel values */ -#define READ_LINE_YUV_SEMIPLANAR(function_name, pixel_1_name, pixel_2_name, pixel_1_type, \ - pixel_2_type, callback, ...) \ -static void function_name(const struct vkms_plane_state *plane, int x_start, \ - int y_start, enum pixel_read_direction direction, int count, \ - struct pixel_argb_u16 out_pixel[]) \ -{ \ - u8 *plane_1; \ - u8 *plane_2; \ - \ - packed_pixels_addr_1x1(plane->frame_info, x_start, y_start, 0, \ - &plane_1); \ - packed_pixels_addr_1x1(plane->frame_info, \ - x_start / plane->frame_info->fb->format->hsub, \ - y_start / plane->frame_info->fb->format->vsub, 1, \ - &plane_2); \ - int step_1 = get_block_step_bytes(plane->frame_info->fb, direction, 0); \ - int step_2 = get_block_step_bytes(plane->frame_info->fb, direction, 1); \ - int subsampling = get_subsampling(plane->frame_info->fb->format, direction); \ - int subsampling_offset = get_subsampling_offset(direction, x_start, y_start); \ - const struct conversion_matrix *conversion_matrix = &plane->conversion_matrix; \ - \ - for (int i = 0; i < count; i++) { \ - pixel_1_type *(pixel_1_name) = (pixel_1_type *)plane_1; \ - pixel_2_type *(pixel_2_name) = (pixel_2_type *)plane_2; \ - *out_pixel = (callback)(conversion_matrix, __VA_ARGS__); \ - out_pixel += 1; \ - plane_1 += step_1; \ - if ((i + subsampling_offset + 1) % subsampling == 0) \ - plane_2 += step_2; \ - } \ -} - -READ_LINE_YUV_SEMIPLANAR(YUV888_semiplanar_read_line, y, uv, u8, u8, argb_u16_from_yuv161616, - y[0] * 257, uv[0] * 257, uv[1] * 257) -READ_LINE_YUV_SEMIPLANAR(YUV161616_semiplanar_read_line, y, uv, u16, u16, argb_u16_from_yuv161616, - y[0], uv[0], uv[1]) -/* +#define READ_LINE_YUV_SEMIPLANAR(function_name, pixel_1_name, pixel_2_name, \ + pixel_1_type, pixel_2_type, callback, ...) \ + static void function_name(const struct vkms_plane_state *plane, \ + int x_start, int y_start, \ + enum pixel_read_direction direction, \ + int count, \ + struct pixel_argb_u16 out_pixel[]) \ + { \ + u8 *plane_1; \ + u8 *plane_2; \ + \ + packed_pixels_addr_1x1(plane->frame_info, x_start, y_start, 0, \ + &plane_1); \ + packed_pixels_addr_1x1( \ + plane->frame_info, \ + x_start / plane->frame_info->fb->format->hsub, \ + y_start / plane->frame_info->fb->format->vsub, 1, \ + &plane_2); \ + int step_1 = get_block_step_bytes(plane->frame_info->fb, \ + direction, 0); \ + int step_2 = get_block_step_bytes(plane->frame_info->fb, \ + direction, 1); \ + int subsampling = get_subsampling( \ + plane->frame_info->fb->format, direction); \ + int subsampling_offset = \ + get_subsampling_offset(direction, x_start, y_start); \ + const struct conversion_matrix *conversion_matrix = \ + &plane->conversion_matrix; \ + \ + for (int i = 0; i < count; i++) { \ + pixel_1_type *(pixel_1_name) = \ + (pixel_1_type *)plane_1; \ + pixel_2_type *(pixel_2_name) = \ + (pixel_2_type *)plane_2; \ + *out_pixel = \ + (callback)(conversion_matrix, __VA_ARGS__); \ + out_pixel += 1; \ + plane_1 += step_1; \ + if ((i + subsampling_offset + 1) % subsampling == 0) \ + plane_2 += step_2; \ + } \ + } + + READ_LINE_YUV_SEMIPLANAR( + YUV888_semiplanar_read_line, y, uv, u8, + u8, argb_u16_from_yuv161616, y[0] * 257, + uv[0] * 257, uv[1] * 257) + READ_LINE_YUV_SEMIPLANAR( + YUV161616_semiplanar_read_line, + y, uv, u16, u16, + argb_u16_from_yuv161616, y[0], + uv[0], uv[1]) + /* * This callback can be used for YUV format where each color component is * stored in a different plane (often called planar formats). It will * correctly handle subsampling as described in the drm_format_info of the plane. @@ -580,9 +620,11 @@ READ_LINE_YUV_SEMIPLANAR(YUV161616_semiplanar_read_line, y, uv, u16, u16, argb_u * - Convert YUV and YVU with the same function (a column swap is needed when setting up * plane->conversion_matrix) */ -static void planar_yuv_read_line(const struct vkms_plane_state *plane, int x_start, - int y_start, enum pixel_read_direction direction, int count, - struct pixel_argb_u16 out_pixel[]) + static void planar_yuv_read_line(const struct vkms_plane_state *plane, + int x_start, int y_start, + enum pixel_read_direction direction, + int count, + struct pixel_argb_u16 out_pixel[]) { u8 *y_plane; u8 *channel_1_plane; @@ -599,15 +641,21 @@ static void planar_yuv_read_line(const struct vkms_plane_state *plane, int x_sta y_start / plane->frame_info->fb->format->vsub, 2, &channel_2_plane); int step_y = get_block_step_bytes(plane->frame_info->fb, direction, 0); - int step_channel_1 = get_block_step_bytes(plane->frame_info->fb, direction, 1); - int step_channel_2 = get_block_step_bytes(plane->frame_info->fb, direction, 2); - int subsampling = get_subsampling(plane->frame_info->fb->format, direction); - int subsampling_offset = get_subsampling_offset(direction, x_start, y_start); - const struct conversion_matrix *conversion_matrix = &plane->conversion_matrix; + int step_channel_1 = + get_block_step_bytes(plane->frame_info->fb, direction, 1); + int step_channel_2 = + get_block_step_bytes(plane->frame_info->fb, direction, 2); + int subsampling = + get_subsampling(plane->frame_info->fb->format, direction); + int subsampling_offset = + get_subsampling_offset(direction, x_start, y_start); + const struct conversion_matrix *conversion_matrix = + &plane->conversion_matrix; for (int i = 0; i < count; i++) { *out_pixel = argb_u16_from_yuv161616(conversion_matrix, - *y_plane * 257, *channel_1_plane * 257, + *y_plane * 257, + *channel_1_plane * 257, *channel_2_plane * 257); out_pixel += 1; y_plane += step_y; @@ -625,7 +673,8 @@ static void planar_yuv_read_line(const struct vkms_plane_state *plane, int x_sta * They are used in vkms_writeback_row() to convert and store a pixel from the src_buffer to * the writeback buffer. */ -static void argb_u16_to_ARGB8888(u8 *out_pixel, const struct pixel_argb_u16 *in_pixel) +static void argb_u16_to_ARGB8888(u8 *out_pixel, + const struct pixel_argb_u16 *in_pixel) { /* * This sequence below is important because the format's byte order is @@ -643,7 +692,8 @@ static void argb_u16_to_ARGB8888(u8 *out_pixel, const struct pixel_argb_u16 *in_ out_pixel[0] = DIV_ROUND_CLOSEST(in_pixel->b, 257); } -static void argb_u16_to_XRGB8888(u8 *out_pixel, const struct pixel_argb_u16 *in_pixel) +static void argb_u16_to_XRGB8888(u8 *out_pixel, + const struct pixel_argb_u16 *in_pixel) { out_pixel[3] = 0xff; out_pixel[2] = DIV_ROUND_CLOSEST(in_pixel->r, 257); @@ -651,7 +701,8 @@ static void argb_u16_to_XRGB8888(u8 *out_pixel, const struct pixel_argb_u16 *in_ out_pixel[0] = DIV_ROUND_CLOSEST(in_pixel->b, 257); } -static void argb_u16_to_ABGR8888(u8 *out_pixel, const struct pixel_argb_u16 *in_pixel) +static void argb_u16_to_ABGR8888(u8 *out_pixel, + const struct pixel_argb_u16 *in_pixel) { out_pixel[3] = DIV_ROUND_CLOSEST(in_pixel->a, 257); out_pixel[2] = DIV_ROUND_CLOSEST(in_pixel->b, 257); @@ -659,7 +710,8 @@ static void argb_u16_to_ABGR8888(u8 *out_pixel, const struct pixel_argb_u16 *in_ out_pixel[0] = DIV_ROUND_CLOSEST(in_pixel->r, 257); } -static void argb_u16_to_ARGB16161616(u8 *out_pixel, const struct pixel_argb_u16 *in_pixel) +static void argb_u16_to_ARGB16161616(u8 *out_pixel, + const struct pixel_argb_u16 *in_pixel) { __le16 *pixel = (__le16 *)out_pixel; @@ -669,7 +721,8 @@ static void argb_u16_to_ARGB16161616(u8 *out_pixel, const struct pixel_argb_u16 pixel[0] = cpu_to_le16(in_pixel->b); } -static void argb_u16_to_XRGB16161616(u8 *out_pixel, const struct pixel_argb_u16 *in_pixel) +static void argb_u16_to_XRGB16161616(u8 *out_pixel, + const struct pixel_argb_u16 *in_pixel) { __le16 *pixel = (__le16 *)out_pixel; @@ -679,7 +732,8 @@ static void argb_u16_to_XRGB16161616(u8 *out_pixel, const struct pixel_argb_u16 pixel[0] = cpu_to_le16(in_pixel->b); } -static void argb_u16_to_RGB565(u8 *out_pixel, const struct pixel_argb_u16 *in_pixel) +static void argb_u16_to_RGB565(u8 *out_pixel, + const struct pixel_argb_u16 *in_pixel) { __le16 *pixel = (__le16 *)out_pixel; @@ -713,11 +767,14 @@ void vkms_writeback_row(struct vkms_writeback_job *wb, u8 *dst_pixels; int rem_x, rem_y; - packed_pixels_addr(frame_info, x_dst, y, 0, &dst_pixels, &rem_x, &rem_y); + packed_pixels_addr(frame_info, x_dst, y, 0, &dst_pixels, &rem_x, + &rem_y); struct pixel_argb_u16 *in_pixels = src_buffer->pixels; - int x_limit = min_t(size_t, drm_rect_width(&frame_info->dst), src_buffer->n_pixels); + int x_limit = min_t(size_t, drm_rect_width(&frame_info->dst), + src_buffer->n_pixels); - for (size_t x = 0; x < x_limit; x++, dst_pixels += frame_info->fb->format->cpp[0]) + for (size_t x = 0; x < x_limit; + x++, dst_pixels += frame_info->fb->format->cpp[0]) wb->pixel_write(dst_pixels, &in_pixels[x]); } diff --git a/linux/vibeshine-drm/vkms_formats.h b/linux/vibeshine-drm/vkms_formats.h index eeb208c..5fff396 100644 --- a/linux/vibeshine-drm/vkms_formats.h +++ b/linux/vibeshine-drm/vkms_formats.h @@ -9,13 +9,15 @@ pixel_read_line_t get_pixel_read_line_function(u32 format); pixel_write_t get_pixel_write_function(u32 format); -void get_conversion_matrix_to_argb_u16(u32 format, enum drm_color_encoding encoding, +void get_conversion_matrix_to_argb_u16(u32 format, + enum drm_color_encoding encoding, enum drm_color_range range, struct conversion_matrix *matrix); #if IS_ENABLED(CONFIG_KUNIT) -struct pixel_argb_u16 argb_u16_from_yuv161616(const struct conversion_matrix *matrix, - u16 y, u16 channel_1, u16 channel_2); +struct pixel_argb_u16 +argb_u16_from_yuv161616(const struct conversion_matrix *matrix, u16 y, + u16 channel_1, u16 channel_2); #endif #endif /* _VKMS_FORMATS_H_ */ diff --git a/linux/vibeshine-drm/vkms_frame_fds.h b/linux/vibeshine-drm/vkms_frame_fds.h index b149173..a115e66 100644 --- a/linux/vibeshine-drm/vkms_frame_fds.h +++ b/linux/vibeshine-drm/vkms_frame_fds.h @@ -16,7 +16,7 @@ struct vkms_frame_fds { }; static inline int vkms_frame_reserve_fd(struct vkms_frame_fds *fds, - struct file *file) + struct file *file) { int number; @@ -30,7 +30,8 @@ static inline int vkms_frame_reserve_fd(struct vkms_frame_fds *fds, return number; } -static inline void vkms_frame_finish_fds(struct vkms_frame_fds *fds, bool install) +static inline void vkms_frame_finish_fds(struct vkms_frame_fds *fds, + bool install) { unsigned int index; diff --git a/linux/vibeshine-drm/vkms_luts.c b/linux/vibeshine-drm/vkms_luts.c index 7e8d307..1a45dbd 100644 --- a/linux/vibeshine-drm/vkms_luts.c +++ b/linux/vibeshine-drm/vkms_luts.c @@ -13,796 +13,409 @@ */ static struct drm_color_lut linear_array[LUT_SIZE] = { - { 0x0, 0x0, 0x0, 0 }, - { 0x101, 0x101, 0x101, 0 }, - { 0x202, 0x202, 0x202, 0 }, - { 0x303, 0x303, 0x303, 0 }, - { 0x404, 0x404, 0x404, 0 }, - { 0x505, 0x505, 0x505, 0 }, - { 0x606, 0x606, 0x606, 0 }, - { 0x707, 0x707, 0x707, 0 }, - { 0x808, 0x808, 0x808, 0 }, - { 0x909, 0x909, 0x909, 0 }, - { 0xa0a, 0xa0a, 0xa0a, 0 }, - { 0xb0b, 0xb0b, 0xb0b, 0 }, - { 0xc0c, 0xc0c, 0xc0c, 0 }, - { 0xd0d, 0xd0d, 0xd0d, 0 }, - { 0xe0e, 0xe0e, 0xe0e, 0 }, - { 0xf0f, 0xf0f, 0xf0f, 0 }, - { 0x1010, 0x1010, 0x1010, 0 }, - { 0x1111, 0x1111, 0x1111, 0 }, - { 0x1212, 0x1212, 0x1212, 0 }, - { 0x1313, 0x1313, 0x1313, 0 }, - { 0x1414, 0x1414, 0x1414, 0 }, - { 0x1515, 0x1515, 0x1515, 0 }, - { 0x1616, 0x1616, 0x1616, 0 }, - { 0x1717, 0x1717, 0x1717, 0 }, - { 0x1818, 0x1818, 0x1818, 0 }, - { 0x1919, 0x1919, 0x1919, 0 }, - { 0x1a1a, 0x1a1a, 0x1a1a, 0 }, - { 0x1b1b, 0x1b1b, 0x1b1b, 0 }, - { 0x1c1c, 0x1c1c, 0x1c1c, 0 }, - { 0x1d1d, 0x1d1d, 0x1d1d, 0 }, - { 0x1e1e, 0x1e1e, 0x1e1e, 0 }, - { 0x1f1f, 0x1f1f, 0x1f1f, 0 }, - { 0x2020, 0x2020, 0x2020, 0 }, - { 0x2121, 0x2121, 0x2121, 0 }, - { 0x2222, 0x2222, 0x2222, 0 }, - { 0x2323, 0x2323, 0x2323, 0 }, - { 0x2424, 0x2424, 0x2424, 0 }, - { 0x2525, 0x2525, 0x2525, 0 }, - { 0x2626, 0x2626, 0x2626, 0 }, - { 0x2727, 0x2727, 0x2727, 0 }, - { 0x2828, 0x2828, 0x2828, 0 }, - { 0x2929, 0x2929, 0x2929, 0 }, - { 0x2a2a, 0x2a2a, 0x2a2a, 0 }, - { 0x2b2b, 0x2b2b, 0x2b2b, 0 }, - { 0x2c2c, 0x2c2c, 0x2c2c, 0 }, - { 0x2d2d, 0x2d2d, 0x2d2d, 0 }, - { 0x2e2e, 0x2e2e, 0x2e2e, 0 }, - { 0x2f2f, 0x2f2f, 0x2f2f, 0 }, - { 0x3030, 0x3030, 0x3030, 0 }, - { 0x3131, 0x3131, 0x3131, 0 }, - { 0x3232, 0x3232, 0x3232, 0 }, - { 0x3333, 0x3333, 0x3333, 0 }, - { 0x3434, 0x3434, 0x3434, 0 }, - { 0x3535, 0x3535, 0x3535, 0 }, - { 0x3636, 0x3636, 0x3636, 0 }, - { 0x3737, 0x3737, 0x3737, 0 }, - { 0x3838, 0x3838, 0x3838, 0 }, - { 0x3939, 0x3939, 0x3939, 0 }, - { 0x3a3a, 0x3a3a, 0x3a3a, 0 }, - { 0x3b3b, 0x3b3b, 0x3b3b, 0 }, - { 0x3c3c, 0x3c3c, 0x3c3c, 0 }, - { 0x3d3d, 0x3d3d, 0x3d3d, 0 }, - { 0x3e3e, 0x3e3e, 0x3e3e, 0 }, - { 0x3f3f, 0x3f3f, 0x3f3f, 0 }, - { 0x4040, 0x4040, 0x4040, 0 }, - { 0x4141, 0x4141, 0x4141, 0 }, - { 0x4242, 0x4242, 0x4242, 0 }, - { 0x4343, 0x4343, 0x4343, 0 }, - { 0x4444, 0x4444, 0x4444, 0 }, - { 0x4545, 0x4545, 0x4545, 0 }, - { 0x4646, 0x4646, 0x4646, 0 }, - { 0x4747, 0x4747, 0x4747, 0 }, - { 0x4848, 0x4848, 0x4848, 0 }, - { 0x4949, 0x4949, 0x4949, 0 }, - { 0x4a4a, 0x4a4a, 0x4a4a, 0 }, - { 0x4b4b, 0x4b4b, 0x4b4b, 0 }, - { 0x4c4c, 0x4c4c, 0x4c4c, 0 }, - { 0x4d4d, 0x4d4d, 0x4d4d, 0 }, - { 0x4e4e, 0x4e4e, 0x4e4e, 0 }, - { 0x4f4f, 0x4f4f, 0x4f4f, 0 }, - { 0x5050, 0x5050, 0x5050, 0 }, - { 0x5151, 0x5151, 0x5151, 0 }, - { 0x5252, 0x5252, 0x5252, 0 }, - { 0x5353, 0x5353, 0x5353, 0 }, - { 0x5454, 0x5454, 0x5454, 0 }, - { 0x5555, 0x5555, 0x5555, 0 }, - { 0x5656, 0x5656, 0x5656, 0 }, - { 0x5757, 0x5757, 0x5757, 0 }, - { 0x5858, 0x5858, 0x5858, 0 }, - { 0x5959, 0x5959, 0x5959, 0 }, - { 0x5a5a, 0x5a5a, 0x5a5a, 0 }, - { 0x5b5b, 0x5b5b, 0x5b5b, 0 }, - { 0x5c5c, 0x5c5c, 0x5c5c, 0 }, - { 0x5d5d, 0x5d5d, 0x5d5d, 0 }, - { 0x5e5e, 0x5e5e, 0x5e5e, 0 }, - { 0x5f5f, 0x5f5f, 0x5f5f, 0 }, - { 0x6060, 0x6060, 0x6060, 0 }, - { 0x6161, 0x6161, 0x6161, 0 }, - { 0x6262, 0x6262, 0x6262, 0 }, - { 0x6363, 0x6363, 0x6363, 0 }, - { 0x6464, 0x6464, 0x6464, 0 }, - { 0x6565, 0x6565, 0x6565, 0 }, - { 0x6666, 0x6666, 0x6666, 0 }, - { 0x6767, 0x6767, 0x6767, 0 }, - { 0x6868, 0x6868, 0x6868, 0 }, - { 0x6969, 0x6969, 0x6969, 0 }, - { 0x6a6a, 0x6a6a, 0x6a6a, 0 }, - { 0x6b6b, 0x6b6b, 0x6b6b, 0 }, - { 0x6c6c, 0x6c6c, 0x6c6c, 0 }, - { 0x6d6d, 0x6d6d, 0x6d6d, 0 }, - { 0x6e6e, 0x6e6e, 0x6e6e, 0 }, - { 0x6f6f, 0x6f6f, 0x6f6f, 0 }, - { 0x7070, 0x7070, 0x7070, 0 }, - { 0x7171, 0x7171, 0x7171, 0 }, - { 0x7272, 0x7272, 0x7272, 0 }, - { 0x7373, 0x7373, 0x7373, 0 }, - { 0x7474, 0x7474, 0x7474, 0 }, - { 0x7575, 0x7575, 0x7575, 0 }, - { 0x7676, 0x7676, 0x7676, 0 }, - { 0x7777, 0x7777, 0x7777, 0 }, - { 0x7878, 0x7878, 0x7878, 0 }, - { 0x7979, 0x7979, 0x7979, 0 }, - { 0x7a7a, 0x7a7a, 0x7a7a, 0 }, - { 0x7b7b, 0x7b7b, 0x7b7b, 0 }, - { 0x7c7c, 0x7c7c, 0x7c7c, 0 }, - { 0x7d7d, 0x7d7d, 0x7d7d, 0 }, - { 0x7e7e, 0x7e7e, 0x7e7e, 0 }, - { 0x7f7f, 0x7f7f, 0x7f7f, 0 }, - { 0x8080, 0x8080, 0x8080, 0 }, - { 0x8181, 0x8181, 0x8181, 0 }, - { 0x8282, 0x8282, 0x8282, 0 }, - { 0x8383, 0x8383, 0x8383, 0 }, - { 0x8484, 0x8484, 0x8484, 0 }, - { 0x8585, 0x8585, 0x8585, 0 }, - { 0x8686, 0x8686, 0x8686, 0 }, - { 0x8787, 0x8787, 0x8787, 0 }, - { 0x8888, 0x8888, 0x8888, 0 }, - { 0x8989, 0x8989, 0x8989, 0 }, - { 0x8a8a, 0x8a8a, 0x8a8a, 0 }, - { 0x8b8b, 0x8b8b, 0x8b8b, 0 }, - { 0x8c8c, 0x8c8c, 0x8c8c, 0 }, - { 0x8d8d, 0x8d8d, 0x8d8d, 0 }, - { 0x8e8e, 0x8e8e, 0x8e8e, 0 }, - { 0x8f8f, 0x8f8f, 0x8f8f, 0 }, - { 0x9090, 0x9090, 0x9090, 0 }, - { 0x9191, 0x9191, 0x9191, 0 }, - { 0x9292, 0x9292, 0x9292, 0 }, - { 0x9393, 0x9393, 0x9393, 0 }, - { 0x9494, 0x9494, 0x9494, 0 }, - { 0x9595, 0x9595, 0x9595, 0 }, - { 0x9696, 0x9696, 0x9696, 0 }, - { 0x9797, 0x9797, 0x9797, 0 }, - { 0x9898, 0x9898, 0x9898, 0 }, - { 0x9999, 0x9999, 0x9999, 0 }, - { 0x9a9a, 0x9a9a, 0x9a9a, 0 }, - { 0x9b9b, 0x9b9b, 0x9b9b, 0 }, - { 0x9c9c, 0x9c9c, 0x9c9c, 0 }, - { 0x9d9d, 0x9d9d, 0x9d9d, 0 }, - { 0x9e9e, 0x9e9e, 0x9e9e, 0 }, - { 0x9f9f, 0x9f9f, 0x9f9f, 0 }, - { 0xa0a0, 0xa0a0, 0xa0a0, 0 }, - { 0xa1a1, 0xa1a1, 0xa1a1, 0 }, - { 0xa2a2, 0xa2a2, 0xa2a2, 0 }, - { 0xa3a3, 0xa3a3, 0xa3a3, 0 }, - { 0xa4a4, 0xa4a4, 0xa4a4, 0 }, - { 0xa5a5, 0xa5a5, 0xa5a5, 0 }, - { 0xa6a6, 0xa6a6, 0xa6a6, 0 }, - { 0xa7a7, 0xa7a7, 0xa7a7, 0 }, - { 0xa8a8, 0xa8a8, 0xa8a8, 0 }, - { 0xa9a9, 0xa9a9, 0xa9a9, 0 }, - { 0xaaaa, 0xaaaa, 0xaaaa, 0 }, - { 0xabab, 0xabab, 0xabab, 0 }, - { 0xacac, 0xacac, 0xacac, 0 }, - { 0xadad, 0xadad, 0xadad, 0 }, - { 0xaeae, 0xaeae, 0xaeae, 0 }, - { 0xafaf, 0xafaf, 0xafaf, 0 }, - { 0xb0b0, 0xb0b0, 0xb0b0, 0 }, - { 0xb1b1, 0xb1b1, 0xb1b1, 0 }, - { 0xb2b2, 0xb2b2, 0xb2b2, 0 }, - { 0xb3b3, 0xb3b3, 0xb3b3, 0 }, - { 0xb4b4, 0xb4b4, 0xb4b4, 0 }, - { 0xb5b5, 0xb5b5, 0xb5b5, 0 }, - { 0xb6b6, 0xb6b6, 0xb6b6, 0 }, - { 0xb7b7, 0xb7b7, 0xb7b7, 0 }, - { 0xb8b8, 0xb8b8, 0xb8b8, 0 }, - { 0xb9b9, 0xb9b9, 0xb9b9, 0 }, - { 0xbaba, 0xbaba, 0xbaba, 0 }, - { 0xbbbb, 0xbbbb, 0xbbbb, 0 }, - { 0xbcbc, 0xbcbc, 0xbcbc, 0 }, - { 0xbdbd, 0xbdbd, 0xbdbd, 0 }, - { 0xbebe, 0xbebe, 0xbebe, 0 }, - { 0xbfbf, 0xbfbf, 0xbfbf, 0 }, - { 0xc0c0, 0xc0c0, 0xc0c0, 0 }, - { 0xc1c1, 0xc1c1, 0xc1c1, 0 }, - { 0xc2c2, 0xc2c2, 0xc2c2, 0 }, - { 0xc3c3, 0xc3c3, 0xc3c3, 0 }, - { 0xc4c4, 0xc4c4, 0xc4c4, 0 }, - { 0xc5c5, 0xc5c5, 0xc5c5, 0 }, - { 0xc6c6, 0xc6c6, 0xc6c6, 0 }, - { 0xc7c7, 0xc7c7, 0xc7c7, 0 }, - { 0xc8c8, 0xc8c8, 0xc8c8, 0 }, - { 0xc9c9, 0xc9c9, 0xc9c9, 0 }, - { 0xcaca, 0xcaca, 0xcaca, 0 }, - { 0xcbcb, 0xcbcb, 0xcbcb, 0 }, - { 0xcccc, 0xcccc, 0xcccc, 0 }, - { 0xcdcd, 0xcdcd, 0xcdcd, 0 }, - { 0xcece, 0xcece, 0xcece, 0 }, - { 0xcfcf, 0xcfcf, 0xcfcf, 0 }, - { 0xd0d0, 0xd0d0, 0xd0d0, 0 }, - { 0xd1d1, 0xd1d1, 0xd1d1, 0 }, - { 0xd2d2, 0xd2d2, 0xd2d2, 0 }, - { 0xd3d3, 0xd3d3, 0xd3d3, 0 }, - { 0xd4d4, 0xd4d4, 0xd4d4, 0 }, - { 0xd5d5, 0xd5d5, 0xd5d5, 0 }, - { 0xd6d6, 0xd6d6, 0xd6d6, 0 }, - { 0xd7d7, 0xd7d7, 0xd7d7, 0 }, - { 0xd8d8, 0xd8d8, 0xd8d8, 0 }, - { 0xd9d9, 0xd9d9, 0xd9d9, 0 }, - { 0xdada, 0xdada, 0xdada, 0 }, - { 0xdbdb, 0xdbdb, 0xdbdb, 0 }, - { 0xdcdc, 0xdcdc, 0xdcdc, 0 }, - { 0xdddd, 0xdddd, 0xdddd, 0 }, - { 0xdede, 0xdede, 0xdede, 0 }, - { 0xdfdf, 0xdfdf, 0xdfdf, 0 }, - { 0xe0e0, 0xe0e0, 0xe0e0, 0 }, - { 0xe1e1, 0xe1e1, 0xe1e1, 0 }, - { 0xe2e2, 0xe2e2, 0xe2e2, 0 }, - { 0xe3e3, 0xe3e3, 0xe3e3, 0 }, - { 0xe4e4, 0xe4e4, 0xe4e4, 0 }, - { 0xe5e5, 0xe5e5, 0xe5e5, 0 }, - { 0xe6e6, 0xe6e6, 0xe6e6, 0 }, - { 0xe7e7, 0xe7e7, 0xe7e7, 0 }, - { 0xe8e8, 0xe8e8, 0xe8e8, 0 }, - { 0xe9e9, 0xe9e9, 0xe9e9, 0 }, - { 0xeaea, 0xeaea, 0xeaea, 0 }, - { 0xebeb, 0xebeb, 0xebeb, 0 }, - { 0xecec, 0xecec, 0xecec, 0 }, - { 0xeded, 0xeded, 0xeded, 0 }, - { 0xeeee, 0xeeee, 0xeeee, 0 }, - { 0xefef, 0xefef, 0xefef, 0 }, - { 0xf0f0, 0xf0f0, 0xf0f0, 0 }, - { 0xf1f1, 0xf1f1, 0xf1f1, 0 }, - { 0xf2f2, 0xf2f2, 0xf2f2, 0 }, - { 0xf3f3, 0xf3f3, 0xf3f3, 0 }, - { 0xf4f4, 0xf4f4, 0xf4f4, 0 }, - { 0xf5f5, 0xf5f5, 0xf5f5, 0 }, - { 0xf6f6, 0xf6f6, 0xf6f6, 0 }, - { 0xf7f7, 0xf7f7, 0xf7f7, 0 }, - { 0xf8f8, 0xf8f8, 0xf8f8, 0 }, - { 0xf9f9, 0xf9f9, 0xf9f9, 0 }, - { 0xfafa, 0xfafa, 0xfafa, 0 }, - { 0xfbfb, 0xfbfb, 0xfbfb, 0 }, - { 0xfcfc, 0xfcfc, 0xfcfc, 0 }, - { 0xfdfd, 0xfdfd, 0xfdfd, 0 }, - { 0xfefe, 0xfefe, 0xfefe, 0 }, - { 0xffff, 0xffff, 0xffff, 0 }, + { 0x0, 0x0, 0x0, 0 }, { 0x101, 0x101, 0x101, 0 }, + { 0x202, 0x202, 0x202, 0 }, { 0x303, 0x303, 0x303, 0 }, + { 0x404, 0x404, 0x404, 0 }, { 0x505, 0x505, 0x505, 0 }, + { 0x606, 0x606, 0x606, 0 }, { 0x707, 0x707, 0x707, 0 }, + { 0x808, 0x808, 0x808, 0 }, { 0x909, 0x909, 0x909, 0 }, + { 0xa0a, 0xa0a, 0xa0a, 0 }, { 0xb0b, 0xb0b, 0xb0b, 0 }, + { 0xc0c, 0xc0c, 0xc0c, 0 }, { 0xd0d, 0xd0d, 0xd0d, 0 }, + { 0xe0e, 0xe0e, 0xe0e, 0 }, { 0xf0f, 0xf0f, 0xf0f, 0 }, + { 0x1010, 0x1010, 0x1010, 0 }, { 0x1111, 0x1111, 0x1111, 0 }, + { 0x1212, 0x1212, 0x1212, 0 }, { 0x1313, 0x1313, 0x1313, 0 }, + { 0x1414, 0x1414, 0x1414, 0 }, { 0x1515, 0x1515, 0x1515, 0 }, + { 0x1616, 0x1616, 0x1616, 0 }, { 0x1717, 0x1717, 0x1717, 0 }, + { 0x1818, 0x1818, 0x1818, 0 }, { 0x1919, 0x1919, 0x1919, 0 }, + { 0x1a1a, 0x1a1a, 0x1a1a, 0 }, { 0x1b1b, 0x1b1b, 0x1b1b, 0 }, + { 0x1c1c, 0x1c1c, 0x1c1c, 0 }, { 0x1d1d, 0x1d1d, 0x1d1d, 0 }, + { 0x1e1e, 0x1e1e, 0x1e1e, 0 }, { 0x1f1f, 0x1f1f, 0x1f1f, 0 }, + { 0x2020, 0x2020, 0x2020, 0 }, { 0x2121, 0x2121, 0x2121, 0 }, + { 0x2222, 0x2222, 0x2222, 0 }, { 0x2323, 0x2323, 0x2323, 0 }, + { 0x2424, 0x2424, 0x2424, 0 }, { 0x2525, 0x2525, 0x2525, 0 }, + { 0x2626, 0x2626, 0x2626, 0 }, { 0x2727, 0x2727, 0x2727, 0 }, + { 0x2828, 0x2828, 0x2828, 0 }, { 0x2929, 0x2929, 0x2929, 0 }, + { 0x2a2a, 0x2a2a, 0x2a2a, 0 }, { 0x2b2b, 0x2b2b, 0x2b2b, 0 }, + { 0x2c2c, 0x2c2c, 0x2c2c, 0 }, { 0x2d2d, 0x2d2d, 0x2d2d, 0 }, + { 0x2e2e, 0x2e2e, 0x2e2e, 0 }, { 0x2f2f, 0x2f2f, 0x2f2f, 0 }, + { 0x3030, 0x3030, 0x3030, 0 }, { 0x3131, 0x3131, 0x3131, 0 }, + { 0x3232, 0x3232, 0x3232, 0 }, { 0x3333, 0x3333, 0x3333, 0 }, + { 0x3434, 0x3434, 0x3434, 0 }, { 0x3535, 0x3535, 0x3535, 0 }, + { 0x3636, 0x3636, 0x3636, 0 }, { 0x3737, 0x3737, 0x3737, 0 }, + { 0x3838, 0x3838, 0x3838, 0 }, { 0x3939, 0x3939, 0x3939, 0 }, + { 0x3a3a, 0x3a3a, 0x3a3a, 0 }, { 0x3b3b, 0x3b3b, 0x3b3b, 0 }, + { 0x3c3c, 0x3c3c, 0x3c3c, 0 }, { 0x3d3d, 0x3d3d, 0x3d3d, 0 }, + { 0x3e3e, 0x3e3e, 0x3e3e, 0 }, { 0x3f3f, 0x3f3f, 0x3f3f, 0 }, + { 0x4040, 0x4040, 0x4040, 0 }, { 0x4141, 0x4141, 0x4141, 0 }, + { 0x4242, 0x4242, 0x4242, 0 }, { 0x4343, 0x4343, 0x4343, 0 }, + { 0x4444, 0x4444, 0x4444, 0 }, { 0x4545, 0x4545, 0x4545, 0 }, + { 0x4646, 0x4646, 0x4646, 0 }, { 0x4747, 0x4747, 0x4747, 0 }, + { 0x4848, 0x4848, 0x4848, 0 }, { 0x4949, 0x4949, 0x4949, 0 }, + { 0x4a4a, 0x4a4a, 0x4a4a, 0 }, { 0x4b4b, 0x4b4b, 0x4b4b, 0 }, + { 0x4c4c, 0x4c4c, 0x4c4c, 0 }, { 0x4d4d, 0x4d4d, 0x4d4d, 0 }, + { 0x4e4e, 0x4e4e, 0x4e4e, 0 }, { 0x4f4f, 0x4f4f, 0x4f4f, 0 }, + { 0x5050, 0x5050, 0x5050, 0 }, { 0x5151, 0x5151, 0x5151, 0 }, + { 0x5252, 0x5252, 0x5252, 0 }, { 0x5353, 0x5353, 0x5353, 0 }, + { 0x5454, 0x5454, 0x5454, 0 }, { 0x5555, 0x5555, 0x5555, 0 }, + { 0x5656, 0x5656, 0x5656, 0 }, { 0x5757, 0x5757, 0x5757, 0 }, + { 0x5858, 0x5858, 0x5858, 0 }, { 0x5959, 0x5959, 0x5959, 0 }, + { 0x5a5a, 0x5a5a, 0x5a5a, 0 }, { 0x5b5b, 0x5b5b, 0x5b5b, 0 }, + { 0x5c5c, 0x5c5c, 0x5c5c, 0 }, { 0x5d5d, 0x5d5d, 0x5d5d, 0 }, + { 0x5e5e, 0x5e5e, 0x5e5e, 0 }, { 0x5f5f, 0x5f5f, 0x5f5f, 0 }, + { 0x6060, 0x6060, 0x6060, 0 }, { 0x6161, 0x6161, 0x6161, 0 }, + { 0x6262, 0x6262, 0x6262, 0 }, { 0x6363, 0x6363, 0x6363, 0 }, + { 0x6464, 0x6464, 0x6464, 0 }, { 0x6565, 0x6565, 0x6565, 0 }, + { 0x6666, 0x6666, 0x6666, 0 }, { 0x6767, 0x6767, 0x6767, 0 }, + { 0x6868, 0x6868, 0x6868, 0 }, { 0x6969, 0x6969, 0x6969, 0 }, + { 0x6a6a, 0x6a6a, 0x6a6a, 0 }, { 0x6b6b, 0x6b6b, 0x6b6b, 0 }, + { 0x6c6c, 0x6c6c, 0x6c6c, 0 }, { 0x6d6d, 0x6d6d, 0x6d6d, 0 }, + { 0x6e6e, 0x6e6e, 0x6e6e, 0 }, { 0x6f6f, 0x6f6f, 0x6f6f, 0 }, + { 0x7070, 0x7070, 0x7070, 0 }, { 0x7171, 0x7171, 0x7171, 0 }, + { 0x7272, 0x7272, 0x7272, 0 }, { 0x7373, 0x7373, 0x7373, 0 }, + { 0x7474, 0x7474, 0x7474, 0 }, { 0x7575, 0x7575, 0x7575, 0 }, + { 0x7676, 0x7676, 0x7676, 0 }, { 0x7777, 0x7777, 0x7777, 0 }, + { 0x7878, 0x7878, 0x7878, 0 }, { 0x7979, 0x7979, 0x7979, 0 }, + { 0x7a7a, 0x7a7a, 0x7a7a, 0 }, { 0x7b7b, 0x7b7b, 0x7b7b, 0 }, + { 0x7c7c, 0x7c7c, 0x7c7c, 0 }, { 0x7d7d, 0x7d7d, 0x7d7d, 0 }, + { 0x7e7e, 0x7e7e, 0x7e7e, 0 }, { 0x7f7f, 0x7f7f, 0x7f7f, 0 }, + { 0x8080, 0x8080, 0x8080, 0 }, { 0x8181, 0x8181, 0x8181, 0 }, + { 0x8282, 0x8282, 0x8282, 0 }, { 0x8383, 0x8383, 0x8383, 0 }, + { 0x8484, 0x8484, 0x8484, 0 }, { 0x8585, 0x8585, 0x8585, 0 }, + { 0x8686, 0x8686, 0x8686, 0 }, { 0x8787, 0x8787, 0x8787, 0 }, + { 0x8888, 0x8888, 0x8888, 0 }, { 0x8989, 0x8989, 0x8989, 0 }, + { 0x8a8a, 0x8a8a, 0x8a8a, 0 }, { 0x8b8b, 0x8b8b, 0x8b8b, 0 }, + { 0x8c8c, 0x8c8c, 0x8c8c, 0 }, { 0x8d8d, 0x8d8d, 0x8d8d, 0 }, + { 0x8e8e, 0x8e8e, 0x8e8e, 0 }, { 0x8f8f, 0x8f8f, 0x8f8f, 0 }, + { 0x9090, 0x9090, 0x9090, 0 }, { 0x9191, 0x9191, 0x9191, 0 }, + { 0x9292, 0x9292, 0x9292, 0 }, { 0x9393, 0x9393, 0x9393, 0 }, + { 0x9494, 0x9494, 0x9494, 0 }, { 0x9595, 0x9595, 0x9595, 0 }, + { 0x9696, 0x9696, 0x9696, 0 }, { 0x9797, 0x9797, 0x9797, 0 }, + { 0x9898, 0x9898, 0x9898, 0 }, { 0x9999, 0x9999, 0x9999, 0 }, + { 0x9a9a, 0x9a9a, 0x9a9a, 0 }, { 0x9b9b, 0x9b9b, 0x9b9b, 0 }, + { 0x9c9c, 0x9c9c, 0x9c9c, 0 }, { 0x9d9d, 0x9d9d, 0x9d9d, 0 }, + { 0x9e9e, 0x9e9e, 0x9e9e, 0 }, { 0x9f9f, 0x9f9f, 0x9f9f, 0 }, + { 0xa0a0, 0xa0a0, 0xa0a0, 0 }, { 0xa1a1, 0xa1a1, 0xa1a1, 0 }, + { 0xa2a2, 0xa2a2, 0xa2a2, 0 }, { 0xa3a3, 0xa3a3, 0xa3a3, 0 }, + { 0xa4a4, 0xa4a4, 0xa4a4, 0 }, { 0xa5a5, 0xa5a5, 0xa5a5, 0 }, + { 0xa6a6, 0xa6a6, 0xa6a6, 0 }, { 0xa7a7, 0xa7a7, 0xa7a7, 0 }, + { 0xa8a8, 0xa8a8, 0xa8a8, 0 }, { 0xa9a9, 0xa9a9, 0xa9a9, 0 }, + { 0xaaaa, 0xaaaa, 0xaaaa, 0 }, { 0xabab, 0xabab, 0xabab, 0 }, + { 0xacac, 0xacac, 0xacac, 0 }, { 0xadad, 0xadad, 0xadad, 0 }, + { 0xaeae, 0xaeae, 0xaeae, 0 }, { 0xafaf, 0xafaf, 0xafaf, 0 }, + { 0xb0b0, 0xb0b0, 0xb0b0, 0 }, { 0xb1b1, 0xb1b1, 0xb1b1, 0 }, + { 0xb2b2, 0xb2b2, 0xb2b2, 0 }, { 0xb3b3, 0xb3b3, 0xb3b3, 0 }, + { 0xb4b4, 0xb4b4, 0xb4b4, 0 }, { 0xb5b5, 0xb5b5, 0xb5b5, 0 }, + { 0xb6b6, 0xb6b6, 0xb6b6, 0 }, { 0xb7b7, 0xb7b7, 0xb7b7, 0 }, + { 0xb8b8, 0xb8b8, 0xb8b8, 0 }, { 0xb9b9, 0xb9b9, 0xb9b9, 0 }, + { 0xbaba, 0xbaba, 0xbaba, 0 }, { 0xbbbb, 0xbbbb, 0xbbbb, 0 }, + { 0xbcbc, 0xbcbc, 0xbcbc, 0 }, { 0xbdbd, 0xbdbd, 0xbdbd, 0 }, + { 0xbebe, 0xbebe, 0xbebe, 0 }, { 0xbfbf, 0xbfbf, 0xbfbf, 0 }, + { 0xc0c0, 0xc0c0, 0xc0c0, 0 }, { 0xc1c1, 0xc1c1, 0xc1c1, 0 }, + { 0xc2c2, 0xc2c2, 0xc2c2, 0 }, { 0xc3c3, 0xc3c3, 0xc3c3, 0 }, + { 0xc4c4, 0xc4c4, 0xc4c4, 0 }, { 0xc5c5, 0xc5c5, 0xc5c5, 0 }, + { 0xc6c6, 0xc6c6, 0xc6c6, 0 }, { 0xc7c7, 0xc7c7, 0xc7c7, 0 }, + { 0xc8c8, 0xc8c8, 0xc8c8, 0 }, { 0xc9c9, 0xc9c9, 0xc9c9, 0 }, + { 0xcaca, 0xcaca, 0xcaca, 0 }, { 0xcbcb, 0xcbcb, 0xcbcb, 0 }, + { 0xcccc, 0xcccc, 0xcccc, 0 }, { 0xcdcd, 0xcdcd, 0xcdcd, 0 }, + { 0xcece, 0xcece, 0xcece, 0 }, { 0xcfcf, 0xcfcf, 0xcfcf, 0 }, + { 0xd0d0, 0xd0d0, 0xd0d0, 0 }, { 0xd1d1, 0xd1d1, 0xd1d1, 0 }, + { 0xd2d2, 0xd2d2, 0xd2d2, 0 }, { 0xd3d3, 0xd3d3, 0xd3d3, 0 }, + { 0xd4d4, 0xd4d4, 0xd4d4, 0 }, { 0xd5d5, 0xd5d5, 0xd5d5, 0 }, + { 0xd6d6, 0xd6d6, 0xd6d6, 0 }, { 0xd7d7, 0xd7d7, 0xd7d7, 0 }, + { 0xd8d8, 0xd8d8, 0xd8d8, 0 }, { 0xd9d9, 0xd9d9, 0xd9d9, 0 }, + { 0xdada, 0xdada, 0xdada, 0 }, { 0xdbdb, 0xdbdb, 0xdbdb, 0 }, + { 0xdcdc, 0xdcdc, 0xdcdc, 0 }, { 0xdddd, 0xdddd, 0xdddd, 0 }, + { 0xdede, 0xdede, 0xdede, 0 }, { 0xdfdf, 0xdfdf, 0xdfdf, 0 }, + { 0xe0e0, 0xe0e0, 0xe0e0, 0 }, { 0xe1e1, 0xe1e1, 0xe1e1, 0 }, + { 0xe2e2, 0xe2e2, 0xe2e2, 0 }, { 0xe3e3, 0xe3e3, 0xe3e3, 0 }, + { 0xe4e4, 0xe4e4, 0xe4e4, 0 }, { 0xe5e5, 0xe5e5, 0xe5e5, 0 }, + { 0xe6e6, 0xe6e6, 0xe6e6, 0 }, { 0xe7e7, 0xe7e7, 0xe7e7, 0 }, + { 0xe8e8, 0xe8e8, 0xe8e8, 0 }, { 0xe9e9, 0xe9e9, 0xe9e9, 0 }, + { 0xeaea, 0xeaea, 0xeaea, 0 }, { 0xebeb, 0xebeb, 0xebeb, 0 }, + { 0xecec, 0xecec, 0xecec, 0 }, { 0xeded, 0xeded, 0xeded, 0 }, + { 0xeeee, 0xeeee, 0xeeee, 0 }, { 0xefef, 0xefef, 0xefef, 0 }, + { 0xf0f0, 0xf0f0, 0xf0f0, 0 }, { 0xf1f1, 0xf1f1, 0xf1f1, 0 }, + { 0xf2f2, 0xf2f2, 0xf2f2, 0 }, { 0xf3f3, 0xf3f3, 0xf3f3, 0 }, + { 0xf4f4, 0xf4f4, 0xf4f4, 0 }, { 0xf5f5, 0xf5f5, 0xf5f5, 0 }, + { 0xf6f6, 0xf6f6, 0xf6f6, 0 }, { 0xf7f7, 0xf7f7, 0xf7f7, 0 }, + { 0xf8f8, 0xf8f8, 0xf8f8, 0 }, { 0xf9f9, 0xf9f9, 0xf9f9, 0 }, + { 0xfafa, 0xfafa, 0xfafa, 0 }, { 0xfbfb, 0xfbfb, 0xfbfb, 0 }, + { 0xfcfc, 0xfcfc, 0xfcfc, 0 }, { 0xfdfd, 0xfdfd, 0xfdfd, 0 }, + { 0xfefe, 0xfefe, 0xfefe, 0 }, { 0xffff, 0xffff, 0xffff, 0 }, }; -const struct vkms_color_lut linear_eotf = { - .base = linear_array, - .lut_length = LUT_SIZE, - .channel_value2index_ratio = 0xff00ffll -}; +const struct vkms_color_lut linear_eotf = { .base = linear_array, + .lut_length = LUT_SIZE, + .channel_value2index_ratio = + 0xff00ffll }; static struct drm_color_lut srgb_array[LUT_SIZE] = { - { 0x0, 0x0, 0x0, 0 }, - { 0x13, 0x13, 0x13, 0 }, - { 0x27, 0x27, 0x27, 0 }, - { 0x3b, 0x3b, 0x3b, 0 }, - { 0x4f, 0x4f, 0x4f, 0 }, - { 0x63, 0x63, 0x63, 0 }, - { 0x77, 0x77, 0x77, 0 }, - { 0x8b, 0x8b, 0x8b, 0 }, - { 0x9f, 0x9f, 0x9f, 0 }, - { 0xb3, 0xb3, 0xb3, 0 }, - { 0xc6, 0xc6, 0xc6, 0 }, - { 0xdb, 0xdb, 0xdb, 0 }, - { 0xf0, 0xf0, 0xf0, 0 }, - { 0x107, 0x107, 0x107, 0 }, - { 0x11f, 0x11f, 0x11f, 0 }, - { 0x139, 0x139, 0x139, 0 }, - { 0x153, 0x153, 0x153, 0 }, - { 0x16f, 0x16f, 0x16f, 0 }, - { 0x18c, 0x18c, 0x18c, 0 }, - { 0x1aa, 0x1aa, 0x1aa, 0 }, - { 0x1ca, 0x1ca, 0x1ca, 0 }, - { 0x1eb, 0x1eb, 0x1eb, 0 }, - { 0x20d, 0x20d, 0x20d, 0 }, - { 0x231, 0x231, 0x231, 0 }, - { 0x256, 0x256, 0x256, 0 }, - { 0x27d, 0x27d, 0x27d, 0 }, - { 0x2a4, 0x2a4, 0x2a4, 0 }, - { 0x2ce, 0x2ce, 0x2ce, 0 }, - { 0x2f9, 0x2f9, 0x2f9, 0 }, - { 0x325, 0x325, 0x325, 0 }, - { 0x352, 0x352, 0x352, 0 }, - { 0x381, 0x381, 0x381, 0 }, - { 0x3b2, 0x3b2, 0x3b2, 0 }, - { 0x3e4, 0x3e4, 0x3e4, 0 }, - { 0x418, 0x418, 0x418, 0 }, - { 0x44d, 0x44d, 0x44d, 0 }, - { 0x484, 0x484, 0x484, 0 }, - { 0x4bc, 0x4bc, 0x4bc, 0 }, - { 0x4f6, 0x4f6, 0x4f6, 0 }, - { 0x531, 0x531, 0x531, 0 }, - { 0x56e, 0x56e, 0x56e, 0 }, - { 0x5ad, 0x5ad, 0x5ad, 0 }, - { 0x5ed, 0x5ed, 0x5ed, 0 }, - { 0x62f, 0x62f, 0x62f, 0 }, - { 0x672, 0x672, 0x672, 0 }, - { 0x6b7, 0x6b7, 0x6b7, 0 }, - { 0x6fe, 0x6fe, 0x6fe, 0 }, - { 0x746, 0x746, 0x746, 0 }, - { 0x791, 0x791, 0x791, 0 }, - { 0x7dc, 0x7dc, 0x7dc, 0 }, - { 0x82a, 0x82a, 0x82a, 0 }, - { 0x879, 0x879, 0x879, 0 }, - { 0x8ca, 0x8ca, 0x8ca, 0 }, - { 0x91d, 0x91d, 0x91d, 0 }, - { 0x971, 0x971, 0x971, 0 }, - { 0x9c7, 0x9c7, 0x9c7, 0 }, - { 0xa1f, 0xa1f, 0xa1f, 0 }, - { 0xa79, 0xa79, 0xa79, 0 }, - { 0xad4, 0xad4, 0xad4, 0 }, - { 0xb32, 0xb32, 0xb32, 0 }, - { 0xb91, 0xb91, 0xb91, 0 }, - { 0xbf2, 0xbf2, 0xbf2, 0 }, - { 0xc54, 0xc54, 0xc54, 0 }, - { 0xcb9, 0xcb9, 0xcb9, 0 }, - { 0xd1f, 0xd1f, 0xd1f, 0 }, - { 0xd88, 0xd88, 0xd88, 0 }, - { 0xdf2, 0xdf2, 0xdf2, 0 }, - { 0xe5e, 0xe5e, 0xe5e, 0 }, - { 0xecc, 0xecc, 0xecc, 0 }, - { 0xf3c, 0xf3c, 0xf3c, 0 }, - { 0xfad, 0xfad, 0xfad, 0 }, - { 0x1021, 0x1021, 0x1021, 0 }, - { 0x1096, 0x1096, 0x1096, 0 }, - { 0x110e, 0x110e, 0x110e, 0 }, - { 0x1187, 0x1187, 0x1187, 0 }, - { 0x1203, 0x1203, 0x1203, 0 }, - { 0x1280, 0x1280, 0x1280, 0 }, - { 0x12ff, 0x12ff, 0x12ff, 0 }, - { 0x1380, 0x1380, 0x1380, 0 }, - { 0x1404, 0x1404, 0x1404, 0 }, - { 0x1489, 0x1489, 0x1489, 0 }, - { 0x1510, 0x1510, 0x1510, 0 }, - { 0x1599, 0x1599, 0x1599, 0 }, - { 0x1624, 0x1624, 0x1624, 0 }, - { 0x16b2, 0x16b2, 0x16b2, 0 }, - { 0x1741, 0x1741, 0x1741, 0 }, - { 0x17d2, 0x17d2, 0x17d2, 0 }, - { 0x1865, 0x1865, 0x1865, 0 }, - { 0x18fb, 0x18fb, 0x18fb, 0 }, - { 0x1992, 0x1992, 0x1992, 0 }, - { 0x1a2c, 0x1a2c, 0x1a2c, 0 }, - { 0x1ac8, 0x1ac8, 0x1ac8, 0 }, - { 0x1b65, 0x1b65, 0x1b65, 0 }, - { 0x1c05, 0x1c05, 0x1c05, 0 }, - { 0x1ca7, 0x1ca7, 0x1ca7, 0 }, - { 0x1d4b, 0x1d4b, 0x1d4b, 0 }, - { 0x1df1, 0x1df1, 0x1df1, 0 }, - { 0x1e99, 0x1e99, 0x1e99, 0 }, - { 0x1f44, 0x1f44, 0x1f44, 0 }, - { 0x1ff0, 0x1ff0, 0x1ff0, 0 }, - { 0x209f, 0x209f, 0x209f, 0 }, - { 0x2150, 0x2150, 0x2150, 0 }, - { 0x2203, 0x2203, 0x2203, 0 }, - { 0x22b8, 0x22b8, 0x22b8, 0 }, - { 0x2370, 0x2370, 0x2370, 0 }, - { 0x2429, 0x2429, 0x2429, 0 }, - { 0x24e5, 0x24e5, 0x24e5, 0 }, - { 0x25a3, 0x25a3, 0x25a3, 0 }, - { 0x2663, 0x2663, 0x2663, 0 }, - { 0x2726, 0x2726, 0x2726, 0 }, - { 0x27ea, 0x27ea, 0x27ea, 0 }, - { 0x28b1, 0x28b1, 0x28b1, 0 }, - { 0x297a, 0x297a, 0x297a, 0 }, - { 0x2a45, 0x2a45, 0x2a45, 0 }, - { 0x2b13, 0x2b13, 0x2b13, 0 }, - { 0x2be3, 0x2be3, 0x2be3, 0 }, - { 0x2cb5, 0x2cb5, 0x2cb5, 0 }, - { 0x2d89, 0x2d89, 0x2d89, 0 }, - { 0x2e60, 0x2e60, 0x2e60, 0 }, - { 0x2f39, 0x2f39, 0x2f39, 0 }, - { 0x3014, 0x3014, 0x3014, 0 }, - { 0x30f2, 0x30f2, 0x30f2, 0 }, - { 0x31d2, 0x31d2, 0x31d2, 0 }, - { 0x32b4, 0x32b4, 0x32b4, 0 }, - { 0x3398, 0x3398, 0x3398, 0 }, - { 0x347f, 0x347f, 0x347f, 0 }, - { 0x3569, 0x3569, 0x3569, 0 }, - { 0x3654, 0x3654, 0x3654, 0 }, - { 0x3742, 0x3742, 0x3742, 0 }, - { 0x3832, 0x3832, 0x3832, 0 }, - { 0x3925, 0x3925, 0x3925, 0 }, - { 0x3a1a, 0x3a1a, 0x3a1a, 0 }, - { 0x3b11, 0x3b11, 0x3b11, 0 }, - { 0x3c0b, 0x3c0b, 0x3c0b, 0 }, - { 0x3d07, 0x3d07, 0x3d07, 0 }, - { 0x3e05, 0x3e05, 0x3e05, 0 }, - { 0x3f06, 0x3f06, 0x3f06, 0 }, - { 0x400a, 0x400a, 0x400a, 0 }, - { 0x410f, 0x410f, 0x410f, 0 }, - { 0x4218, 0x4218, 0x4218, 0 }, - { 0x4322, 0x4322, 0x4322, 0 }, - { 0x442f, 0x442f, 0x442f, 0 }, - { 0x453f, 0x453f, 0x453f, 0 }, - { 0x4650, 0x4650, 0x4650, 0 }, - { 0x4765, 0x4765, 0x4765, 0 }, - { 0x487c, 0x487c, 0x487c, 0 }, - { 0x4995, 0x4995, 0x4995, 0 }, - { 0x4ab1, 0x4ab1, 0x4ab1, 0 }, - { 0x4bcf, 0x4bcf, 0x4bcf, 0 }, - { 0x4cf0, 0x4cf0, 0x4cf0, 0 }, - { 0x4e13, 0x4e13, 0x4e13, 0 }, - { 0x4f39, 0x4f39, 0x4f39, 0 }, - { 0x5061, 0x5061, 0x5061, 0 }, - { 0x518b, 0x518b, 0x518b, 0 }, - { 0x52b9, 0x52b9, 0x52b9, 0 }, - { 0x53e8, 0x53e8, 0x53e8, 0 }, - { 0x551b, 0x551b, 0x551b, 0 }, - { 0x5650, 0x5650, 0x5650, 0 }, - { 0x5787, 0x5787, 0x5787, 0 }, - { 0x58c1, 0x58c1, 0x58c1, 0 }, - { 0x59fd, 0x59fd, 0x59fd, 0 }, - { 0x5b3c, 0x5b3c, 0x5b3c, 0 }, - { 0x5c7e, 0x5c7e, 0x5c7e, 0 }, - { 0x5dc2, 0x5dc2, 0x5dc2, 0 }, - { 0x5f09, 0x5f09, 0x5f09, 0 }, - { 0x6052, 0x6052, 0x6052, 0 }, - { 0x619e, 0x619e, 0x619e, 0 }, - { 0x62ec, 0x62ec, 0x62ec, 0 }, - { 0x643d, 0x643d, 0x643d, 0 }, - { 0x6591, 0x6591, 0x6591, 0 }, - { 0x66e7, 0x66e7, 0x66e7, 0 }, - { 0x6840, 0x6840, 0x6840, 0 }, - { 0x699b, 0x699b, 0x699b, 0 }, - { 0x6afa, 0x6afa, 0x6afa, 0 }, - { 0x6c5a, 0x6c5a, 0x6c5a, 0 }, - { 0x6dbe, 0x6dbe, 0x6dbe, 0 }, - { 0x6f24, 0x6f24, 0x6f24, 0 }, - { 0x708c, 0x708c, 0x708c, 0 }, - { 0x71f8, 0x71f8, 0x71f8, 0 }, - { 0x7366, 0x7366, 0x7366, 0 }, - { 0x74d6, 0x74d6, 0x74d6, 0 }, - { 0x764a, 0x764a, 0x764a, 0 }, - { 0x77c0, 0x77c0, 0x77c0, 0 }, - { 0x7938, 0x7938, 0x7938, 0 }, - { 0x7ab4, 0x7ab4, 0x7ab4, 0 }, - { 0x7c32, 0x7c32, 0x7c32, 0 }, - { 0x7db3, 0x7db3, 0x7db3, 0 }, - { 0x7f36, 0x7f36, 0x7f36, 0 }, - { 0x80bc, 0x80bc, 0x80bc, 0 }, - { 0x8245, 0x8245, 0x8245, 0 }, - { 0x83d1, 0x83d1, 0x83d1, 0 }, - { 0x855f, 0x855f, 0x855f, 0 }, - { 0x86f0, 0x86f0, 0x86f0, 0 }, - { 0x8884, 0x8884, 0x8884, 0 }, - { 0x8a1a, 0x8a1a, 0x8a1a, 0 }, - { 0x8bb4, 0x8bb4, 0x8bb4, 0 }, - { 0x8d50, 0x8d50, 0x8d50, 0 }, - { 0x8eee, 0x8eee, 0x8eee, 0 }, - { 0x9090, 0x9090, 0x9090, 0 }, - { 0x9234, 0x9234, 0x9234, 0 }, - { 0x93db, 0x93db, 0x93db, 0 }, - { 0x9585, 0x9585, 0x9585, 0 }, - { 0x9732, 0x9732, 0x9732, 0 }, - { 0x98e1, 0x98e1, 0x98e1, 0 }, - { 0x9a93, 0x9a93, 0x9a93, 0 }, - { 0x9c48, 0x9c48, 0x9c48, 0 }, - { 0x9e00, 0x9e00, 0x9e00, 0 }, - { 0x9fbb, 0x9fbb, 0x9fbb, 0 }, - { 0xa178, 0xa178, 0xa178, 0 }, - { 0xa338, 0xa338, 0xa338, 0 }, - { 0xa4fb, 0xa4fb, 0xa4fb, 0 }, - { 0xa6c1, 0xa6c1, 0xa6c1, 0 }, - { 0xa88a, 0xa88a, 0xa88a, 0 }, - { 0xaa56, 0xaa56, 0xaa56, 0 }, - { 0xac24, 0xac24, 0xac24, 0 }, - { 0xadf5, 0xadf5, 0xadf5, 0 }, - { 0xafc9, 0xafc9, 0xafc9, 0 }, - { 0xb1a0, 0xb1a0, 0xb1a0, 0 }, - { 0xb37a, 0xb37a, 0xb37a, 0 }, - { 0xb557, 0xb557, 0xb557, 0 }, - { 0xb736, 0xb736, 0xb736, 0 }, - { 0xb919, 0xb919, 0xb919, 0 }, - { 0xbafe, 0xbafe, 0xbafe, 0 }, - { 0xbce6, 0xbce6, 0xbce6, 0 }, - { 0xbed2, 0xbed2, 0xbed2, 0 }, - { 0xc0c0, 0xc0c0, 0xc0c0, 0 }, - { 0xc2b0, 0xc2b0, 0xc2b0, 0 }, - { 0xc4a4, 0xc4a4, 0xc4a4, 0 }, - { 0xc69b, 0xc69b, 0xc69b, 0 }, - { 0xc895, 0xc895, 0xc895, 0 }, - { 0xca91, 0xca91, 0xca91, 0 }, - { 0xcc91, 0xcc91, 0xcc91, 0 }, - { 0xce93, 0xce93, 0xce93, 0 }, - { 0xd098, 0xd098, 0xd098, 0 }, - { 0xd2a1, 0xd2a1, 0xd2a1, 0 }, - { 0xd4ac, 0xd4ac, 0xd4ac, 0 }, - { 0xd6ba, 0xd6ba, 0xd6ba, 0 }, - { 0xd8cb, 0xd8cb, 0xd8cb, 0 }, - { 0xdadf, 0xdadf, 0xdadf, 0 }, - { 0xdcf7, 0xdcf7, 0xdcf7, 0 }, - { 0xdf11, 0xdf11, 0xdf11, 0 }, - { 0xe12e, 0xe12e, 0xe12e, 0 }, - { 0xe34e, 0xe34e, 0xe34e, 0 }, - { 0xe571, 0xe571, 0xe571, 0 }, - { 0xe796, 0xe796, 0xe796, 0 }, - { 0xe9bf, 0xe9bf, 0xe9bf, 0 }, - { 0xebeb, 0xebeb, 0xebeb, 0 }, - { 0xee1a, 0xee1a, 0xee1a, 0 }, - { 0xf04c, 0xf04c, 0xf04c, 0 }, - { 0xf281, 0xf281, 0xf281, 0 }, - { 0xf4b9, 0xf4b9, 0xf4b9, 0 }, - { 0xf6f4, 0xf6f4, 0xf6f4, 0 }, - { 0xf932, 0xf932, 0xf932, 0 }, - { 0xfb73, 0xfb73, 0xfb73, 0 }, - { 0xfdb7, 0xfdb7, 0xfdb7, 0 }, - { 0xffff, 0xffff, 0xffff, 0 }, + { 0x0, 0x0, 0x0, 0 }, { 0x13, 0x13, 0x13, 0 }, + { 0x27, 0x27, 0x27, 0 }, { 0x3b, 0x3b, 0x3b, 0 }, + { 0x4f, 0x4f, 0x4f, 0 }, { 0x63, 0x63, 0x63, 0 }, + { 0x77, 0x77, 0x77, 0 }, { 0x8b, 0x8b, 0x8b, 0 }, + { 0x9f, 0x9f, 0x9f, 0 }, { 0xb3, 0xb3, 0xb3, 0 }, + { 0xc6, 0xc6, 0xc6, 0 }, { 0xdb, 0xdb, 0xdb, 0 }, + { 0xf0, 0xf0, 0xf0, 0 }, { 0x107, 0x107, 0x107, 0 }, + { 0x11f, 0x11f, 0x11f, 0 }, { 0x139, 0x139, 0x139, 0 }, + { 0x153, 0x153, 0x153, 0 }, { 0x16f, 0x16f, 0x16f, 0 }, + { 0x18c, 0x18c, 0x18c, 0 }, { 0x1aa, 0x1aa, 0x1aa, 0 }, + { 0x1ca, 0x1ca, 0x1ca, 0 }, { 0x1eb, 0x1eb, 0x1eb, 0 }, + { 0x20d, 0x20d, 0x20d, 0 }, { 0x231, 0x231, 0x231, 0 }, + { 0x256, 0x256, 0x256, 0 }, { 0x27d, 0x27d, 0x27d, 0 }, + { 0x2a4, 0x2a4, 0x2a4, 0 }, { 0x2ce, 0x2ce, 0x2ce, 0 }, + { 0x2f9, 0x2f9, 0x2f9, 0 }, { 0x325, 0x325, 0x325, 0 }, + { 0x352, 0x352, 0x352, 0 }, { 0x381, 0x381, 0x381, 0 }, + { 0x3b2, 0x3b2, 0x3b2, 0 }, { 0x3e4, 0x3e4, 0x3e4, 0 }, + { 0x418, 0x418, 0x418, 0 }, { 0x44d, 0x44d, 0x44d, 0 }, + { 0x484, 0x484, 0x484, 0 }, { 0x4bc, 0x4bc, 0x4bc, 0 }, + { 0x4f6, 0x4f6, 0x4f6, 0 }, { 0x531, 0x531, 0x531, 0 }, + { 0x56e, 0x56e, 0x56e, 0 }, { 0x5ad, 0x5ad, 0x5ad, 0 }, + { 0x5ed, 0x5ed, 0x5ed, 0 }, { 0x62f, 0x62f, 0x62f, 0 }, + { 0x672, 0x672, 0x672, 0 }, { 0x6b7, 0x6b7, 0x6b7, 0 }, + { 0x6fe, 0x6fe, 0x6fe, 0 }, { 0x746, 0x746, 0x746, 0 }, + { 0x791, 0x791, 0x791, 0 }, { 0x7dc, 0x7dc, 0x7dc, 0 }, + { 0x82a, 0x82a, 0x82a, 0 }, { 0x879, 0x879, 0x879, 0 }, + { 0x8ca, 0x8ca, 0x8ca, 0 }, { 0x91d, 0x91d, 0x91d, 0 }, + { 0x971, 0x971, 0x971, 0 }, { 0x9c7, 0x9c7, 0x9c7, 0 }, + { 0xa1f, 0xa1f, 0xa1f, 0 }, { 0xa79, 0xa79, 0xa79, 0 }, + { 0xad4, 0xad4, 0xad4, 0 }, { 0xb32, 0xb32, 0xb32, 0 }, + { 0xb91, 0xb91, 0xb91, 0 }, { 0xbf2, 0xbf2, 0xbf2, 0 }, + { 0xc54, 0xc54, 0xc54, 0 }, { 0xcb9, 0xcb9, 0xcb9, 0 }, + { 0xd1f, 0xd1f, 0xd1f, 0 }, { 0xd88, 0xd88, 0xd88, 0 }, + { 0xdf2, 0xdf2, 0xdf2, 0 }, { 0xe5e, 0xe5e, 0xe5e, 0 }, + { 0xecc, 0xecc, 0xecc, 0 }, { 0xf3c, 0xf3c, 0xf3c, 0 }, + { 0xfad, 0xfad, 0xfad, 0 }, { 0x1021, 0x1021, 0x1021, 0 }, + { 0x1096, 0x1096, 0x1096, 0 }, { 0x110e, 0x110e, 0x110e, 0 }, + { 0x1187, 0x1187, 0x1187, 0 }, { 0x1203, 0x1203, 0x1203, 0 }, + { 0x1280, 0x1280, 0x1280, 0 }, { 0x12ff, 0x12ff, 0x12ff, 0 }, + { 0x1380, 0x1380, 0x1380, 0 }, { 0x1404, 0x1404, 0x1404, 0 }, + { 0x1489, 0x1489, 0x1489, 0 }, { 0x1510, 0x1510, 0x1510, 0 }, + { 0x1599, 0x1599, 0x1599, 0 }, { 0x1624, 0x1624, 0x1624, 0 }, + { 0x16b2, 0x16b2, 0x16b2, 0 }, { 0x1741, 0x1741, 0x1741, 0 }, + { 0x17d2, 0x17d2, 0x17d2, 0 }, { 0x1865, 0x1865, 0x1865, 0 }, + { 0x18fb, 0x18fb, 0x18fb, 0 }, { 0x1992, 0x1992, 0x1992, 0 }, + { 0x1a2c, 0x1a2c, 0x1a2c, 0 }, { 0x1ac8, 0x1ac8, 0x1ac8, 0 }, + { 0x1b65, 0x1b65, 0x1b65, 0 }, { 0x1c05, 0x1c05, 0x1c05, 0 }, + { 0x1ca7, 0x1ca7, 0x1ca7, 0 }, { 0x1d4b, 0x1d4b, 0x1d4b, 0 }, + { 0x1df1, 0x1df1, 0x1df1, 0 }, { 0x1e99, 0x1e99, 0x1e99, 0 }, + { 0x1f44, 0x1f44, 0x1f44, 0 }, { 0x1ff0, 0x1ff0, 0x1ff0, 0 }, + { 0x209f, 0x209f, 0x209f, 0 }, { 0x2150, 0x2150, 0x2150, 0 }, + { 0x2203, 0x2203, 0x2203, 0 }, { 0x22b8, 0x22b8, 0x22b8, 0 }, + { 0x2370, 0x2370, 0x2370, 0 }, { 0x2429, 0x2429, 0x2429, 0 }, + { 0x24e5, 0x24e5, 0x24e5, 0 }, { 0x25a3, 0x25a3, 0x25a3, 0 }, + { 0x2663, 0x2663, 0x2663, 0 }, { 0x2726, 0x2726, 0x2726, 0 }, + { 0x27ea, 0x27ea, 0x27ea, 0 }, { 0x28b1, 0x28b1, 0x28b1, 0 }, + { 0x297a, 0x297a, 0x297a, 0 }, { 0x2a45, 0x2a45, 0x2a45, 0 }, + { 0x2b13, 0x2b13, 0x2b13, 0 }, { 0x2be3, 0x2be3, 0x2be3, 0 }, + { 0x2cb5, 0x2cb5, 0x2cb5, 0 }, { 0x2d89, 0x2d89, 0x2d89, 0 }, + { 0x2e60, 0x2e60, 0x2e60, 0 }, { 0x2f39, 0x2f39, 0x2f39, 0 }, + { 0x3014, 0x3014, 0x3014, 0 }, { 0x30f2, 0x30f2, 0x30f2, 0 }, + { 0x31d2, 0x31d2, 0x31d2, 0 }, { 0x32b4, 0x32b4, 0x32b4, 0 }, + { 0x3398, 0x3398, 0x3398, 0 }, { 0x347f, 0x347f, 0x347f, 0 }, + { 0x3569, 0x3569, 0x3569, 0 }, { 0x3654, 0x3654, 0x3654, 0 }, + { 0x3742, 0x3742, 0x3742, 0 }, { 0x3832, 0x3832, 0x3832, 0 }, + { 0x3925, 0x3925, 0x3925, 0 }, { 0x3a1a, 0x3a1a, 0x3a1a, 0 }, + { 0x3b11, 0x3b11, 0x3b11, 0 }, { 0x3c0b, 0x3c0b, 0x3c0b, 0 }, + { 0x3d07, 0x3d07, 0x3d07, 0 }, { 0x3e05, 0x3e05, 0x3e05, 0 }, + { 0x3f06, 0x3f06, 0x3f06, 0 }, { 0x400a, 0x400a, 0x400a, 0 }, + { 0x410f, 0x410f, 0x410f, 0 }, { 0x4218, 0x4218, 0x4218, 0 }, + { 0x4322, 0x4322, 0x4322, 0 }, { 0x442f, 0x442f, 0x442f, 0 }, + { 0x453f, 0x453f, 0x453f, 0 }, { 0x4650, 0x4650, 0x4650, 0 }, + { 0x4765, 0x4765, 0x4765, 0 }, { 0x487c, 0x487c, 0x487c, 0 }, + { 0x4995, 0x4995, 0x4995, 0 }, { 0x4ab1, 0x4ab1, 0x4ab1, 0 }, + { 0x4bcf, 0x4bcf, 0x4bcf, 0 }, { 0x4cf0, 0x4cf0, 0x4cf0, 0 }, + { 0x4e13, 0x4e13, 0x4e13, 0 }, { 0x4f39, 0x4f39, 0x4f39, 0 }, + { 0x5061, 0x5061, 0x5061, 0 }, { 0x518b, 0x518b, 0x518b, 0 }, + { 0x52b9, 0x52b9, 0x52b9, 0 }, { 0x53e8, 0x53e8, 0x53e8, 0 }, + { 0x551b, 0x551b, 0x551b, 0 }, { 0x5650, 0x5650, 0x5650, 0 }, + { 0x5787, 0x5787, 0x5787, 0 }, { 0x58c1, 0x58c1, 0x58c1, 0 }, + { 0x59fd, 0x59fd, 0x59fd, 0 }, { 0x5b3c, 0x5b3c, 0x5b3c, 0 }, + { 0x5c7e, 0x5c7e, 0x5c7e, 0 }, { 0x5dc2, 0x5dc2, 0x5dc2, 0 }, + { 0x5f09, 0x5f09, 0x5f09, 0 }, { 0x6052, 0x6052, 0x6052, 0 }, + { 0x619e, 0x619e, 0x619e, 0 }, { 0x62ec, 0x62ec, 0x62ec, 0 }, + { 0x643d, 0x643d, 0x643d, 0 }, { 0x6591, 0x6591, 0x6591, 0 }, + { 0x66e7, 0x66e7, 0x66e7, 0 }, { 0x6840, 0x6840, 0x6840, 0 }, + { 0x699b, 0x699b, 0x699b, 0 }, { 0x6afa, 0x6afa, 0x6afa, 0 }, + { 0x6c5a, 0x6c5a, 0x6c5a, 0 }, { 0x6dbe, 0x6dbe, 0x6dbe, 0 }, + { 0x6f24, 0x6f24, 0x6f24, 0 }, { 0x708c, 0x708c, 0x708c, 0 }, + { 0x71f8, 0x71f8, 0x71f8, 0 }, { 0x7366, 0x7366, 0x7366, 0 }, + { 0x74d6, 0x74d6, 0x74d6, 0 }, { 0x764a, 0x764a, 0x764a, 0 }, + { 0x77c0, 0x77c0, 0x77c0, 0 }, { 0x7938, 0x7938, 0x7938, 0 }, + { 0x7ab4, 0x7ab4, 0x7ab4, 0 }, { 0x7c32, 0x7c32, 0x7c32, 0 }, + { 0x7db3, 0x7db3, 0x7db3, 0 }, { 0x7f36, 0x7f36, 0x7f36, 0 }, + { 0x80bc, 0x80bc, 0x80bc, 0 }, { 0x8245, 0x8245, 0x8245, 0 }, + { 0x83d1, 0x83d1, 0x83d1, 0 }, { 0x855f, 0x855f, 0x855f, 0 }, + { 0x86f0, 0x86f0, 0x86f0, 0 }, { 0x8884, 0x8884, 0x8884, 0 }, + { 0x8a1a, 0x8a1a, 0x8a1a, 0 }, { 0x8bb4, 0x8bb4, 0x8bb4, 0 }, + { 0x8d50, 0x8d50, 0x8d50, 0 }, { 0x8eee, 0x8eee, 0x8eee, 0 }, + { 0x9090, 0x9090, 0x9090, 0 }, { 0x9234, 0x9234, 0x9234, 0 }, + { 0x93db, 0x93db, 0x93db, 0 }, { 0x9585, 0x9585, 0x9585, 0 }, + { 0x9732, 0x9732, 0x9732, 0 }, { 0x98e1, 0x98e1, 0x98e1, 0 }, + { 0x9a93, 0x9a93, 0x9a93, 0 }, { 0x9c48, 0x9c48, 0x9c48, 0 }, + { 0x9e00, 0x9e00, 0x9e00, 0 }, { 0x9fbb, 0x9fbb, 0x9fbb, 0 }, + { 0xa178, 0xa178, 0xa178, 0 }, { 0xa338, 0xa338, 0xa338, 0 }, + { 0xa4fb, 0xa4fb, 0xa4fb, 0 }, { 0xa6c1, 0xa6c1, 0xa6c1, 0 }, + { 0xa88a, 0xa88a, 0xa88a, 0 }, { 0xaa56, 0xaa56, 0xaa56, 0 }, + { 0xac24, 0xac24, 0xac24, 0 }, { 0xadf5, 0xadf5, 0xadf5, 0 }, + { 0xafc9, 0xafc9, 0xafc9, 0 }, { 0xb1a0, 0xb1a0, 0xb1a0, 0 }, + { 0xb37a, 0xb37a, 0xb37a, 0 }, { 0xb557, 0xb557, 0xb557, 0 }, + { 0xb736, 0xb736, 0xb736, 0 }, { 0xb919, 0xb919, 0xb919, 0 }, + { 0xbafe, 0xbafe, 0xbafe, 0 }, { 0xbce6, 0xbce6, 0xbce6, 0 }, + { 0xbed2, 0xbed2, 0xbed2, 0 }, { 0xc0c0, 0xc0c0, 0xc0c0, 0 }, + { 0xc2b0, 0xc2b0, 0xc2b0, 0 }, { 0xc4a4, 0xc4a4, 0xc4a4, 0 }, + { 0xc69b, 0xc69b, 0xc69b, 0 }, { 0xc895, 0xc895, 0xc895, 0 }, + { 0xca91, 0xca91, 0xca91, 0 }, { 0xcc91, 0xcc91, 0xcc91, 0 }, + { 0xce93, 0xce93, 0xce93, 0 }, { 0xd098, 0xd098, 0xd098, 0 }, + { 0xd2a1, 0xd2a1, 0xd2a1, 0 }, { 0xd4ac, 0xd4ac, 0xd4ac, 0 }, + { 0xd6ba, 0xd6ba, 0xd6ba, 0 }, { 0xd8cb, 0xd8cb, 0xd8cb, 0 }, + { 0xdadf, 0xdadf, 0xdadf, 0 }, { 0xdcf7, 0xdcf7, 0xdcf7, 0 }, + { 0xdf11, 0xdf11, 0xdf11, 0 }, { 0xe12e, 0xe12e, 0xe12e, 0 }, + { 0xe34e, 0xe34e, 0xe34e, 0 }, { 0xe571, 0xe571, 0xe571, 0 }, + { 0xe796, 0xe796, 0xe796, 0 }, { 0xe9bf, 0xe9bf, 0xe9bf, 0 }, + { 0xebeb, 0xebeb, 0xebeb, 0 }, { 0xee1a, 0xee1a, 0xee1a, 0 }, + { 0xf04c, 0xf04c, 0xf04c, 0 }, { 0xf281, 0xf281, 0xf281, 0 }, + { 0xf4b9, 0xf4b9, 0xf4b9, 0 }, { 0xf6f4, 0xf6f4, 0xf6f4, 0 }, + { 0xf932, 0xf932, 0xf932, 0 }, { 0xfb73, 0xfb73, 0xfb73, 0 }, + { 0xfdb7, 0xfdb7, 0xfdb7, 0 }, { 0xffff, 0xffff, 0xffff, 0 }, }; -const struct vkms_color_lut srgb_eotf = { - .base = srgb_array, - .lut_length = LUT_SIZE, - .channel_value2index_ratio = 0xff00ffll -}; +const struct vkms_color_lut srgb_eotf = { .base = srgb_array, + .lut_length = LUT_SIZE, + .channel_value2index_ratio = + 0xff00ffll }; static struct drm_color_lut srgb_inv_array[LUT_SIZE] = { - { 0x0, 0x0, 0x0, 0 }, - { 0xcc2, 0xcc2, 0xcc2, 0 }, - { 0x15be, 0x15be, 0x15be, 0 }, - { 0x1c56, 0x1c56, 0x1c56, 0 }, - { 0x21bd, 0x21bd, 0x21bd, 0 }, - { 0x2666, 0x2666, 0x2666, 0 }, - { 0x2a8a, 0x2a8a, 0x2a8a, 0 }, - { 0x2e4c, 0x2e4c, 0x2e4c, 0 }, - { 0x31c0, 0x31c0, 0x31c0, 0 }, - { 0x34f6, 0x34f6, 0x34f6, 0 }, - { 0x37f9, 0x37f9, 0x37f9, 0 }, - { 0x3acf, 0x3acf, 0x3acf, 0 }, - { 0x3d80, 0x3d80, 0x3d80, 0 }, - { 0x4010, 0x4010, 0x4010, 0 }, - { 0x4284, 0x4284, 0x4284, 0 }, - { 0x44dd, 0x44dd, 0x44dd, 0 }, - { 0x4720, 0x4720, 0x4720, 0 }, - { 0x494e, 0x494e, 0x494e, 0 }, - { 0x4b69, 0x4b69, 0x4b69, 0 }, - { 0x4d73, 0x4d73, 0x4d73, 0 }, - { 0x4f6e, 0x4f6e, 0x4f6e, 0 }, - { 0x5159, 0x5159, 0x5159, 0 }, - { 0x5337, 0x5337, 0x5337, 0 }, - { 0x5509, 0x5509, 0x5509, 0 }, - { 0x56cf, 0x56cf, 0x56cf, 0 }, - { 0x588a, 0x588a, 0x588a, 0 }, - { 0x5a3b, 0x5a3b, 0x5a3b, 0 }, - { 0x5be2, 0x5be2, 0x5be2, 0 }, - { 0x5d80, 0x5d80, 0x5d80, 0 }, - { 0x5f16, 0x5f16, 0x5f16, 0 }, - { 0x60a4, 0x60a4, 0x60a4, 0 }, - { 0x6229, 0x6229, 0x6229, 0 }, - { 0x63a8, 0x63a8, 0x63a8, 0 }, - { 0x6520, 0x6520, 0x6520, 0 }, - { 0x6691, 0x6691, 0x6691, 0 }, - { 0x67fc, 0x67fc, 0x67fc, 0 }, - { 0x6961, 0x6961, 0x6961, 0 }, - { 0x6ac0, 0x6ac0, 0x6ac0, 0 }, - { 0x6c19, 0x6c19, 0x6c19, 0 }, - { 0x6d6e, 0x6d6e, 0x6d6e, 0 }, - { 0x6ebd, 0x6ebd, 0x6ebd, 0 }, - { 0x7008, 0x7008, 0x7008, 0 }, - { 0x714d, 0x714d, 0x714d, 0 }, - { 0x728f, 0x728f, 0x728f, 0 }, - { 0x73cc, 0x73cc, 0x73cc, 0 }, - { 0x7504, 0x7504, 0x7504, 0 }, - { 0x7639, 0x7639, 0x7639, 0 }, - { 0x776a, 0x776a, 0x776a, 0 }, - { 0x7897, 0x7897, 0x7897, 0 }, - { 0x79c1, 0x79c1, 0x79c1, 0 }, - { 0x7ae7, 0x7ae7, 0x7ae7, 0 }, - { 0x7c09, 0x7c09, 0x7c09, 0 }, - { 0x7d28, 0x7d28, 0x7d28, 0 }, - { 0x7e44, 0x7e44, 0x7e44, 0 }, - { 0x7f5d, 0x7f5d, 0x7f5d, 0 }, - { 0x8073, 0x8073, 0x8073, 0 }, - { 0x8186, 0x8186, 0x8186, 0 }, - { 0x8296, 0x8296, 0x8296, 0 }, - { 0x83a4, 0x83a4, 0x83a4, 0 }, - { 0x84ae, 0x84ae, 0x84ae, 0 }, - { 0x85b6, 0x85b6, 0x85b6, 0 }, - { 0x86bc, 0x86bc, 0x86bc, 0 }, - { 0x87bf, 0x87bf, 0x87bf, 0 }, - { 0x88bf, 0x88bf, 0x88bf, 0 }, - { 0x89be, 0x89be, 0x89be, 0 }, - { 0x8ab9, 0x8ab9, 0x8ab9, 0 }, - { 0x8bb3, 0x8bb3, 0x8bb3, 0 }, - { 0x8cab, 0x8cab, 0x8cab, 0 }, - { 0x8da0, 0x8da0, 0x8da0, 0 }, - { 0x8e93, 0x8e93, 0x8e93, 0 }, - { 0x8f84, 0x8f84, 0x8f84, 0 }, - { 0x9073, 0x9073, 0x9073, 0 }, - { 0x9161, 0x9161, 0x9161, 0 }, - { 0x924c, 0x924c, 0x924c, 0 }, - { 0x9335, 0x9335, 0x9335, 0 }, - { 0x941d, 0x941d, 0x941d, 0 }, - { 0x9503, 0x9503, 0x9503, 0 }, - { 0x95e7, 0x95e7, 0x95e7, 0 }, - { 0x96c9, 0x96c9, 0x96c9, 0 }, - { 0x97aa, 0x97aa, 0x97aa, 0 }, - { 0x9889, 0x9889, 0x9889, 0 }, - { 0x9966, 0x9966, 0x9966, 0 }, - { 0x9a42, 0x9a42, 0x9a42, 0 }, - { 0x9b1c, 0x9b1c, 0x9b1c, 0 }, - { 0x9bf5, 0x9bf5, 0x9bf5, 0 }, - { 0x9ccc, 0x9ccc, 0x9ccc, 0 }, - { 0x9da1, 0x9da1, 0x9da1, 0 }, - { 0x9e76, 0x9e76, 0x9e76, 0 }, - { 0x9f49, 0x9f49, 0x9f49, 0 }, - { 0xa01a, 0xa01a, 0xa01a, 0 }, - { 0xa0ea, 0xa0ea, 0xa0ea, 0 }, - { 0xa1b9, 0xa1b9, 0xa1b9, 0 }, - { 0xa286, 0xa286, 0xa286, 0 }, - { 0xa352, 0xa352, 0xa352, 0 }, - { 0xa41d, 0xa41d, 0xa41d, 0 }, - { 0xa4e7, 0xa4e7, 0xa4e7, 0 }, - { 0xa5af, 0xa5af, 0xa5af, 0 }, - { 0xa676, 0xa676, 0xa676, 0 }, - { 0xa73c, 0xa73c, 0xa73c, 0 }, - { 0xa801, 0xa801, 0xa801, 0 }, - { 0xa8c5, 0xa8c5, 0xa8c5, 0 }, - { 0xa987, 0xa987, 0xa987, 0 }, - { 0xaa48, 0xaa48, 0xaa48, 0 }, - { 0xab09, 0xab09, 0xab09, 0 }, - { 0xabc8, 0xabc8, 0xabc8, 0 }, - { 0xac86, 0xac86, 0xac86, 0 }, - { 0xad43, 0xad43, 0xad43, 0 }, - { 0xadff, 0xadff, 0xadff, 0 }, - { 0xaeba, 0xaeba, 0xaeba, 0 }, - { 0xaf74, 0xaf74, 0xaf74, 0 }, - { 0xb02d, 0xb02d, 0xb02d, 0 }, - { 0xb0e5, 0xb0e5, 0xb0e5, 0 }, - { 0xb19c, 0xb19c, 0xb19c, 0 }, - { 0xb252, 0xb252, 0xb252, 0 }, - { 0xb307, 0xb307, 0xb307, 0 }, - { 0xb3bb, 0xb3bb, 0xb3bb, 0 }, - { 0xb46f, 0xb46f, 0xb46f, 0 }, - { 0xb521, 0xb521, 0xb521, 0 }, - { 0xb5d3, 0xb5d3, 0xb5d3, 0 }, - { 0xb683, 0xb683, 0xb683, 0 }, - { 0xb733, 0xb733, 0xb733, 0 }, - { 0xb7e2, 0xb7e2, 0xb7e2, 0 }, - { 0xb890, 0xb890, 0xb890, 0 }, - { 0xb93d, 0xb93d, 0xb93d, 0 }, - { 0xb9ea, 0xb9ea, 0xb9ea, 0 }, - { 0xba96, 0xba96, 0xba96, 0 }, - { 0xbb40, 0xbb40, 0xbb40, 0 }, - { 0xbbea, 0xbbea, 0xbbea, 0 }, - { 0xbc94, 0xbc94, 0xbc94, 0 }, - { 0xbd3c, 0xbd3c, 0xbd3c, 0 }, - { 0xbde4, 0xbde4, 0xbde4, 0 }, - { 0xbe8b, 0xbe8b, 0xbe8b, 0 }, - { 0xbf31, 0xbf31, 0xbf31, 0 }, - { 0xbfd7, 0xbfd7, 0xbfd7, 0 }, - { 0xc07b, 0xc07b, 0xc07b, 0 }, - { 0xc120, 0xc120, 0xc120, 0 }, - { 0xc1c3, 0xc1c3, 0xc1c3, 0 }, - { 0xc266, 0xc266, 0xc266, 0 }, - { 0xc308, 0xc308, 0xc308, 0 }, - { 0xc3a9, 0xc3a9, 0xc3a9, 0 }, - { 0xc449, 0xc449, 0xc449, 0 }, - { 0xc4e9, 0xc4e9, 0xc4e9, 0 }, - { 0xc589, 0xc589, 0xc589, 0 }, - { 0xc627, 0xc627, 0xc627, 0 }, - { 0xc6c5, 0xc6c5, 0xc6c5, 0 }, - { 0xc763, 0xc763, 0xc763, 0 }, - { 0xc7ff, 0xc7ff, 0xc7ff, 0 }, - { 0xc89b, 0xc89b, 0xc89b, 0 }, - { 0xc937, 0xc937, 0xc937, 0 }, - { 0xc9d2, 0xc9d2, 0xc9d2, 0 }, - { 0xca6c, 0xca6c, 0xca6c, 0 }, - { 0xcb06, 0xcb06, 0xcb06, 0 }, - { 0xcb9f, 0xcb9f, 0xcb9f, 0 }, - { 0xcc37, 0xcc37, 0xcc37, 0 }, - { 0xcccf, 0xcccf, 0xcccf, 0 }, - { 0xcd66, 0xcd66, 0xcd66, 0 }, - { 0xcdfd, 0xcdfd, 0xcdfd, 0 }, - { 0xce93, 0xce93, 0xce93, 0 }, - { 0xcf29, 0xcf29, 0xcf29, 0 }, - { 0xcfbe, 0xcfbe, 0xcfbe, 0 }, - { 0xd053, 0xd053, 0xd053, 0 }, - { 0xd0e7, 0xd0e7, 0xd0e7, 0 }, - { 0xd17a, 0xd17a, 0xd17a, 0 }, - { 0xd20d, 0xd20d, 0xd20d, 0 }, - { 0xd2a0, 0xd2a0, 0xd2a0, 0 }, - { 0xd331, 0xd331, 0xd331, 0 }, - { 0xd3c3, 0xd3c3, 0xd3c3, 0 }, - { 0xd454, 0xd454, 0xd454, 0 }, - { 0xd4e4, 0xd4e4, 0xd4e4, 0 }, - { 0xd574, 0xd574, 0xd574, 0 }, - { 0xd603, 0xd603, 0xd603, 0 }, - { 0xd692, 0xd692, 0xd692, 0 }, - { 0xd720, 0xd720, 0xd720, 0 }, - { 0xd7ae, 0xd7ae, 0xd7ae, 0 }, - { 0xd83c, 0xd83c, 0xd83c, 0 }, - { 0xd8c9, 0xd8c9, 0xd8c9, 0 }, - { 0xd955, 0xd955, 0xd955, 0 }, - { 0xd9e1, 0xd9e1, 0xd9e1, 0 }, - { 0xda6d, 0xda6d, 0xda6d, 0 }, - { 0xdaf8, 0xdaf8, 0xdaf8, 0 }, - { 0xdb83, 0xdb83, 0xdb83, 0 }, - { 0xdc0d, 0xdc0d, 0xdc0d, 0 }, - { 0xdc97, 0xdc97, 0xdc97, 0 }, - { 0xdd20, 0xdd20, 0xdd20, 0 }, - { 0xdda9, 0xdda9, 0xdda9, 0 }, - { 0xde31, 0xde31, 0xde31, 0 }, - { 0xdeb9, 0xdeb9, 0xdeb9, 0 }, - { 0xdf41, 0xdf41, 0xdf41, 0 }, - { 0xdfc8, 0xdfc8, 0xdfc8, 0 }, - { 0xe04f, 0xe04f, 0xe04f, 0 }, - { 0xe0d5, 0xe0d5, 0xe0d5, 0 }, - { 0xe15b, 0xe15b, 0xe15b, 0 }, - { 0xe1e0, 0xe1e0, 0xe1e0, 0 }, - { 0xe266, 0xe266, 0xe266, 0 }, - { 0xe2ea, 0xe2ea, 0xe2ea, 0 }, - { 0xe36f, 0xe36f, 0xe36f, 0 }, - { 0xe3f3, 0xe3f3, 0xe3f3, 0 }, - { 0xe476, 0xe476, 0xe476, 0 }, - { 0xe4f9, 0xe4f9, 0xe4f9, 0 }, - { 0xe57c, 0xe57c, 0xe57c, 0 }, - { 0xe5fe, 0xe5fe, 0xe5fe, 0 }, - { 0xe680, 0xe680, 0xe680, 0 }, - { 0xe702, 0xe702, 0xe702, 0 }, - { 0xe783, 0xe783, 0xe783, 0 }, - { 0xe804, 0xe804, 0xe804, 0 }, - { 0xe884, 0xe884, 0xe884, 0 }, - { 0xe905, 0xe905, 0xe905, 0 }, - { 0xe984, 0xe984, 0xe984, 0 }, - { 0xea04, 0xea04, 0xea04, 0 }, - { 0xea83, 0xea83, 0xea83, 0 }, - { 0xeb02, 0xeb02, 0xeb02, 0 }, - { 0xeb80, 0xeb80, 0xeb80, 0 }, - { 0xebfe, 0xebfe, 0xebfe, 0 }, - { 0xec7b, 0xec7b, 0xec7b, 0 }, - { 0xecf9, 0xecf9, 0xecf9, 0 }, - { 0xed76, 0xed76, 0xed76, 0 }, - { 0xedf2, 0xedf2, 0xedf2, 0 }, - { 0xee6f, 0xee6f, 0xee6f, 0 }, - { 0xeeeb, 0xeeeb, 0xeeeb, 0 }, - { 0xef66, 0xef66, 0xef66, 0 }, - { 0xefe2, 0xefe2, 0xefe2, 0 }, - { 0xf05d, 0xf05d, 0xf05d, 0 }, - { 0xf0d7, 0xf0d7, 0xf0d7, 0 }, - { 0xf152, 0xf152, 0xf152, 0 }, - { 0xf1cc, 0xf1cc, 0xf1cc, 0 }, - { 0xf245, 0xf245, 0xf245, 0 }, - { 0xf2bf, 0xf2bf, 0xf2bf, 0 }, - { 0xf338, 0xf338, 0xf338, 0 }, - { 0xf3b0, 0xf3b0, 0xf3b0, 0 }, - { 0xf429, 0xf429, 0xf429, 0 }, - { 0xf4a1, 0xf4a1, 0xf4a1, 0 }, - { 0xf519, 0xf519, 0xf519, 0 }, - { 0xf590, 0xf590, 0xf590, 0 }, - { 0xf608, 0xf608, 0xf608, 0 }, - { 0xf67e, 0xf67e, 0xf67e, 0 }, - { 0xf6f5, 0xf6f5, 0xf6f5, 0 }, - { 0xf76b, 0xf76b, 0xf76b, 0 }, - { 0xf7e1, 0xf7e1, 0xf7e1, 0 }, - { 0xf857, 0xf857, 0xf857, 0 }, - { 0xf8cd, 0xf8cd, 0xf8cd, 0 }, - { 0xf942, 0xf942, 0xf942, 0 }, - { 0xf9b7, 0xf9b7, 0xf9b7, 0 }, - { 0xfa2b, 0xfa2b, 0xfa2b, 0 }, - { 0xfaa0, 0xfaa0, 0xfaa0, 0 }, - { 0xfb14, 0xfb14, 0xfb14, 0 }, - { 0xfb88, 0xfb88, 0xfb88, 0 }, - { 0xfbfb, 0xfbfb, 0xfbfb, 0 }, - { 0xfc6e, 0xfc6e, 0xfc6e, 0 }, - { 0xfce1, 0xfce1, 0xfce1, 0 }, - { 0xfd54, 0xfd54, 0xfd54, 0 }, - { 0xfdc6, 0xfdc6, 0xfdc6, 0 }, - { 0xfe39, 0xfe39, 0xfe39, 0 }, - { 0xfeaa, 0xfeaa, 0xfeaa, 0 }, - { 0xff1c, 0xff1c, 0xff1c, 0 }, - { 0xff8d, 0xff8d, 0xff8d, 0 }, - { 0xffff, 0xffff, 0xffff, 0 }, + { 0x0, 0x0, 0x0, 0 }, { 0xcc2, 0xcc2, 0xcc2, 0 }, + { 0x15be, 0x15be, 0x15be, 0 }, { 0x1c56, 0x1c56, 0x1c56, 0 }, + { 0x21bd, 0x21bd, 0x21bd, 0 }, { 0x2666, 0x2666, 0x2666, 0 }, + { 0x2a8a, 0x2a8a, 0x2a8a, 0 }, { 0x2e4c, 0x2e4c, 0x2e4c, 0 }, + { 0x31c0, 0x31c0, 0x31c0, 0 }, { 0x34f6, 0x34f6, 0x34f6, 0 }, + { 0x37f9, 0x37f9, 0x37f9, 0 }, { 0x3acf, 0x3acf, 0x3acf, 0 }, + { 0x3d80, 0x3d80, 0x3d80, 0 }, { 0x4010, 0x4010, 0x4010, 0 }, + { 0x4284, 0x4284, 0x4284, 0 }, { 0x44dd, 0x44dd, 0x44dd, 0 }, + { 0x4720, 0x4720, 0x4720, 0 }, { 0x494e, 0x494e, 0x494e, 0 }, + { 0x4b69, 0x4b69, 0x4b69, 0 }, { 0x4d73, 0x4d73, 0x4d73, 0 }, + { 0x4f6e, 0x4f6e, 0x4f6e, 0 }, { 0x5159, 0x5159, 0x5159, 0 }, + { 0x5337, 0x5337, 0x5337, 0 }, { 0x5509, 0x5509, 0x5509, 0 }, + { 0x56cf, 0x56cf, 0x56cf, 0 }, { 0x588a, 0x588a, 0x588a, 0 }, + { 0x5a3b, 0x5a3b, 0x5a3b, 0 }, { 0x5be2, 0x5be2, 0x5be2, 0 }, + { 0x5d80, 0x5d80, 0x5d80, 0 }, { 0x5f16, 0x5f16, 0x5f16, 0 }, + { 0x60a4, 0x60a4, 0x60a4, 0 }, { 0x6229, 0x6229, 0x6229, 0 }, + { 0x63a8, 0x63a8, 0x63a8, 0 }, { 0x6520, 0x6520, 0x6520, 0 }, + { 0x6691, 0x6691, 0x6691, 0 }, { 0x67fc, 0x67fc, 0x67fc, 0 }, + { 0x6961, 0x6961, 0x6961, 0 }, { 0x6ac0, 0x6ac0, 0x6ac0, 0 }, + { 0x6c19, 0x6c19, 0x6c19, 0 }, { 0x6d6e, 0x6d6e, 0x6d6e, 0 }, + { 0x6ebd, 0x6ebd, 0x6ebd, 0 }, { 0x7008, 0x7008, 0x7008, 0 }, + { 0x714d, 0x714d, 0x714d, 0 }, { 0x728f, 0x728f, 0x728f, 0 }, + { 0x73cc, 0x73cc, 0x73cc, 0 }, { 0x7504, 0x7504, 0x7504, 0 }, + { 0x7639, 0x7639, 0x7639, 0 }, { 0x776a, 0x776a, 0x776a, 0 }, + { 0x7897, 0x7897, 0x7897, 0 }, { 0x79c1, 0x79c1, 0x79c1, 0 }, + { 0x7ae7, 0x7ae7, 0x7ae7, 0 }, { 0x7c09, 0x7c09, 0x7c09, 0 }, + { 0x7d28, 0x7d28, 0x7d28, 0 }, { 0x7e44, 0x7e44, 0x7e44, 0 }, + { 0x7f5d, 0x7f5d, 0x7f5d, 0 }, { 0x8073, 0x8073, 0x8073, 0 }, + { 0x8186, 0x8186, 0x8186, 0 }, { 0x8296, 0x8296, 0x8296, 0 }, + { 0x83a4, 0x83a4, 0x83a4, 0 }, { 0x84ae, 0x84ae, 0x84ae, 0 }, + { 0x85b6, 0x85b6, 0x85b6, 0 }, { 0x86bc, 0x86bc, 0x86bc, 0 }, + { 0x87bf, 0x87bf, 0x87bf, 0 }, { 0x88bf, 0x88bf, 0x88bf, 0 }, + { 0x89be, 0x89be, 0x89be, 0 }, { 0x8ab9, 0x8ab9, 0x8ab9, 0 }, + { 0x8bb3, 0x8bb3, 0x8bb3, 0 }, { 0x8cab, 0x8cab, 0x8cab, 0 }, + { 0x8da0, 0x8da0, 0x8da0, 0 }, { 0x8e93, 0x8e93, 0x8e93, 0 }, + { 0x8f84, 0x8f84, 0x8f84, 0 }, { 0x9073, 0x9073, 0x9073, 0 }, + { 0x9161, 0x9161, 0x9161, 0 }, { 0x924c, 0x924c, 0x924c, 0 }, + { 0x9335, 0x9335, 0x9335, 0 }, { 0x941d, 0x941d, 0x941d, 0 }, + { 0x9503, 0x9503, 0x9503, 0 }, { 0x95e7, 0x95e7, 0x95e7, 0 }, + { 0x96c9, 0x96c9, 0x96c9, 0 }, { 0x97aa, 0x97aa, 0x97aa, 0 }, + { 0x9889, 0x9889, 0x9889, 0 }, { 0x9966, 0x9966, 0x9966, 0 }, + { 0x9a42, 0x9a42, 0x9a42, 0 }, { 0x9b1c, 0x9b1c, 0x9b1c, 0 }, + { 0x9bf5, 0x9bf5, 0x9bf5, 0 }, { 0x9ccc, 0x9ccc, 0x9ccc, 0 }, + { 0x9da1, 0x9da1, 0x9da1, 0 }, { 0x9e76, 0x9e76, 0x9e76, 0 }, + { 0x9f49, 0x9f49, 0x9f49, 0 }, { 0xa01a, 0xa01a, 0xa01a, 0 }, + { 0xa0ea, 0xa0ea, 0xa0ea, 0 }, { 0xa1b9, 0xa1b9, 0xa1b9, 0 }, + { 0xa286, 0xa286, 0xa286, 0 }, { 0xa352, 0xa352, 0xa352, 0 }, + { 0xa41d, 0xa41d, 0xa41d, 0 }, { 0xa4e7, 0xa4e7, 0xa4e7, 0 }, + { 0xa5af, 0xa5af, 0xa5af, 0 }, { 0xa676, 0xa676, 0xa676, 0 }, + { 0xa73c, 0xa73c, 0xa73c, 0 }, { 0xa801, 0xa801, 0xa801, 0 }, + { 0xa8c5, 0xa8c5, 0xa8c5, 0 }, { 0xa987, 0xa987, 0xa987, 0 }, + { 0xaa48, 0xaa48, 0xaa48, 0 }, { 0xab09, 0xab09, 0xab09, 0 }, + { 0xabc8, 0xabc8, 0xabc8, 0 }, { 0xac86, 0xac86, 0xac86, 0 }, + { 0xad43, 0xad43, 0xad43, 0 }, { 0xadff, 0xadff, 0xadff, 0 }, + { 0xaeba, 0xaeba, 0xaeba, 0 }, { 0xaf74, 0xaf74, 0xaf74, 0 }, + { 0xb02d, 0xb02d, 0xb02d, 0 }, { 0xb0e5, 0xb0e5, 0xb0e5, 0 }, + { 0xb19c, 0xb19c, 0xb19c, 0 }, { 0xb252, 0xb252, 0xb252, 0 }, + { 0xb307, 0xb307, 0xb307, 0 }, { 0xb3bb, 0xb3bb, 0xb3bb, 0 }, + { 0xb46f, 0xb46f, 0xb46f, 0 }, { 0xb521, 0xb521, 0xb521, 0 }, + { 0xb5d3, 0xb5d3, 0xb5d3, 0 }, { 0xb683, 0xb683, 0xb683, 0 }, + { 0xb733, 0xb733, 0xb733, 0 }, { 0xb7e2, 0xb7e2, 0xb7e2, 0 }, + { 0xb890, 0xb890, 0xb890, 0 }, { 0xb93d, 0xb93d, 0xb93d, 0 }, + { 0xb9ea, 0xb9ea, 0xb9ea, 0 }, { 0xba96, 0xba96, 0xba96, 0 }, + { 0xbb40, 0xbb40, 0xbb40, 0 }, { 0xbbea, 0xbbea, 0xbbea, 0 }, + { 0xbc94, 0xbc94, 0xbc94, 0 }, { 0xbd3c, 0xbd3c, 0xbd3c, 0 }, + { 0xbde4, 0xbde4, 0xbde4, 0 }, { 0xbe8b, 0xbe8b, 0xbe8b, 0 }, + { 0xbf31, 0xbf31, 0xbf31, 0 }, { 0xbfd7, 0xbfd7, 0xbfd7, 0 }, + { 0xc07b, 0xc07b, 0xc07b, 0 }, { 0xc120, 0xc120, 0xc120, 0 }, + { 0xc1c3, 0xc1c3, 0xc1c3, 0 }, { 0xc266, 0xc266, 0xc266, 0 }, + { 0xc308, 0xc308, 0xc308, 0 }, { 0xc3a9, 0xc3a9, 0xc3a9, 0 }, + { 0xc449, 0xc449, 0xc449, 0 }, { 0xc4e9, 0xc4e9, 0xc4e9, 0 }, + { 0xc589, 0xc589, 0xc589, 0 }, { 0xc627, 0xc627, 0xc627, 0 }, + { 0xc6c5, 0xc6c5, 0xc6c5, 0 }, { 0xc763, 0xc763, 0xc763, 0 }, + { 0xc7ff, 0xc7ff, 0xc7ff, 0 }, { 0xc89b, 0xc89b, 0xc89b, 0 }, + { 0xc937, 0xc937, 0xc937, 0 }, { 0xc9d2, 0xc9d2, 0xc9d2, 0 }, + { 0xca6c, 0xca6c, 0xca6c, 0 }, { 0xcb06, 0xcb06, 0xcb06, 0 }, + { 0xcb9f, 0xcb9f, 0xcb9f, 0 }, { 0xcc37, 0xcc37, 0xcc37, 0 }, + { 0xcccf, 0xcccf, 0xcccf, 0 }, { 0xcd66, 0xcd66, 0xcd66, 0 }, + { 0xcdfd, 0xcdfd, 0xcdfd, 0 }, { 0xce93, 0xce93, 0xce93, 0 }, + { 0xcf29, 0xcf29, 0xcf29, 0 }, { 0xcfbe, 0xcfbe, 0xcfbe, 0 }, + { 0xd053, 0xd053, 0xd053, 0 }, { 0xd0e7, 0xd0e7, 0xd0e7, 0 }, + { 0xd17a, 0xd17a, 0xd17a, 0 }, { 0xd20d, 0xd20d, 0xd20d, 0 }, + { 0xd2a0, 0xd2a0, 0xd2a0, 0 }, { 0xd331, 0xd331, 0xd331, 0 }, + { 0xd3c3, 0xd3c3, 0xd3c3, 0 }, { 0xd454, 0xd454, 0xd454, 0 }, + { 0xd4e4, 0xd4e4, 0xd4e4, 0 }, { 0xd574, 0xd574, 0xd574, 0 }, + { 0xd603, 0xd603, 0xd603, 0 }, { 0xd692, 0xd692, 0xd692, 0 }, + { 0xd720, 0xd720, 0xd720, 0 }, { 0xd7ae, 0xd7ae, 0xd7ae, 0 }, + { 0xd83c, 0xd83c, 0xd83c, 0 }, { 0xd8c9, 0xd8c9, 0xd8c9, 0 }, + { 0xd955, 0xd955, 0xd955, 0 }, { 0xd9e1, 0xd9e1, 0xd9e1, 0 }, + { 0xda6d, 0xda6d, 0xda6d, 0 }, { 0xdaf8, 0xdaf8, 0xdaf8, 0 }, + { 0xdb83, 0xdb83, 0xdb83, 0 }, { 0xdc0d, 0xdc0d, 0xdc0d, 0 }, + { 0xdc97, 0xdc97, 0xdc97, 0 }, { 0xdd20, 0xdd20, 0xdd20, 0 }, + { 0xdda9, 0xdda9, 0xdda9, 0 }, { 0xde31, 0xde31, 0xde31, 0 }, + { 0xdeb9, 0xdeb9, 0xdeb9, 0 }, { 0xdf41, 0xdf41, 0xdf41, 0 }, + { 0xdfc8, 0xdfc8, 0xdfc8, 0 }, { 0xe04f, 0xe04f, 0xe04f, 0 }, + { 0xe0d5, 0xe0d5, 0xe0d5, 0 }, { 0xe15b, 0xe15b, 0xe15b, 0 }, + { 0xe1e0, 0xe1e0, 0xe1e0, 0 }, { 0xe266, 0xe266, 0xe266, 0 }, + { 0xe2ea, 0xe2ea, 0xe2ea, 0 }, { 0xe36f, 0xe36f, 0xe36f, 0 }, + { 0xe3f3, 0xe3f3, 0xe3f3, 0 }, { 0xe476, 0xe476, 0xe476, 0 }, + { 0xe4f9, 0xe4f9, 0xe4f9, 0 }, { 0xe57c, 0xe57c, 0xe57c, 0 }, + { 0xe5fe, 0xe5fe, 0xe5fe, 0 }, { 0xe680, 0xe680, 0xe680, 0 }, + { 0xe702, 0xe702, 0xe702, 0 }, { 0xe783, 0xe783, 0xe783, 0 }, + { 0xe804, 0xe804, 0xe804, 0 }, { 0xe884, 0xe884, 0xe884, 0 }, + { 0xe905, 0xe905, 0xe905, 0 }, { 0xe984, 0xe984, 0xe984, 0 }, + { 0xea04, 0xea04, 0xea04, 0 }, { 0xea83, 0xea83, 0xea83, 0 }, + { 0xeb02, 0xeb02, 0xeb02, 0 }, { 0xeb80, 0xeb80, 0xeb80, 0 }, + { 0xebfe, 0xebfe, 0xebfe, 0 }, { 0xec7b, 0xec7b, 0xec7b, 0 }, + { 0xecf9, 0xecf9, 0xecf9, 0 }, { 0xed76, 0xed76, 0xed76, 0 }, + { 0xedf2, 0xedf2, 0xedf2, 0 }, { 0xee6f, 0xee6f, 0xee6f, 0 }, + { 0xeeeb, 0xeeeb, 0xeeeb, 0 }, { 0xef66, 0xef66, 0xef66, 0 }, + { 0xefe2, 0xefe2, 0xefe2, 0 }, { 0xf05d, 0xf05d, 0xf05d, 0 }, + { 0xf0d7, 0xf0d7, 0xf0d7, 0 }, { 0xf152, 0xf152, 0xf152, 0 }, + { 0xf1cc, 0xf1cc, 0xf1cc, 0 }, { 0xf245, 0xf245, 0xf245, 0 }, + { 0xf2bf, 0xf2bf, 0xf2bf, 0 }, { 0xf338, 0xf338, 0xf338, 0 }, + { 0xf3b0, 0xf3b0, 0xf3b0, 0 }, { 0xf429, 0xf429, 0xf429, 0 }, + { 0xf4a1, 0xf4a1, 0xf4a1, 0 }, { 0xf519, 0xf519, 0xf519, 0 }, + { 0xf590, 0xf590, 0xf590, 0 }, { 0xf608, 0xf608, 0xf608, 0 }, + { 0xf67e, 0xf67e, 0xf67e, 0 }, { 0xf6f5, 0xf6f5, 0xf6f5, 0 }, + { 0xf76b, 0xf76b, 0xf76b, 0 }, { 0xf7e1, 0xf7e1, 0xf7e1, 0 }, + { 0xf857, 0xf857, 0xf857, 0 }, { 0xf8cd, 0xf8cd, 0xf8cd, 0 }, + { 0xf942, 0xf942, 0xf942, 0 }, { 0xf9b7, 0xf9b7, 0xf9b7, 0 }, + { 0xfa2b, 0xfa2b, 0xfa2b, 0 }, { 0xfaa0, 0xfaa0, 0xfaa0, 0 }, + { 0xfb14, 0xfb14, 0xfb14, 0 }, { 0xfb88, 0xfb88, 0xfb88, 0 }, + { 0xfbfb, 0xfbfb, 0xfbfb, 0 }, { 0xfc6e, 0xfc6e, 0xfc6e, 0 }, + { 0xfce1, 0xfce1, 0xfce1, 0 }, { 0xfd54, 0xfd54, 0xfd54, 0 }, + { 0xfdc6, 0xfdc6, 0xfdc6, 0 }, { 0xfe39, 0xfe39, 0xfe39, 0 }, + { 0xfeaa, 0xfeaa, 0xfeaa, 0 }, { 0xff1c, 0xff1c, 0xff1c, 0 }, + { 0xff8d, 0xff8d, 0xff8d, 0 }, { 0xffff, 0xffff, 0xffff, 0 }, }; -const struct vkms_color_lut srgb_inv_eotf = { - .base = srgb_inv_array, - .lut_length = LUT_SIZE, - .channel_value2index_ratio = 0xff00ffll -}; +const struct vkms_color_lut srgb_inv_eotf = { .base = srgb_inv_array, + .lut_length = LUT_SIZE, + .channel_value2index_ratio = + 0xff00ffll }; diff --git a/linux/vibeshine-drm/vkms_output.c b/linux/vibeshine-drm/vkms_output.c index 64ad4db..e434ab4 100644 --- a/linux/vibeshine-drm/vkms_output.c +++ b/linux/vibeshine-drm/vkms_output.c @@ -30,11 +30,14 @@ int vkms_output_init(struct vkms_device *vkmsdev) vkms_config_for_each_crtc(vkmsdev->config, crtc_cfg) { struct vkms_config_plane *primary, *cursor; - primary = vkms_config_crtc_primary_plane(vkmsdev->config, crtc_cfg); - cursor = vkms_config_crtc_cursor_plane(vkmsdev->config, crtc_cfg); - - crtc_cfg->crtc = vkms_crtc_init(dev, &primary->plane->base, - cursor ? &cursor->plane->base : NULL); + primary = vkms_config_crtc_primary_plane(vkmsdev->config, + crtc_cfg); + cursor = vkms_config_crtc_cursor_plane(vkmsdev->config, + crtc_cfg); + + crtc_cfg->crtc = + vkms_crtc_init(dev, &primary->plane->base, + cursor ? &cursor->plane->base : NULL); if (IS_ERR(crtc_cfg->crtc)) { DRM_ERROR("Failed to allocate CRTC\n"); return PTR_ERR(crtc_cfg->crtc); @@ -42,9 +45,11 @@ int vkms_output_init(struct vkms_device *vkmsdev) /* Initialize the writeback component */ if (vkms_config_crtc_get_writeback(crtc_cfg)) { - writeback = vkms_enable_writeback_connector(vkmsdev, crtc_cfg->crtc); + writeback = vkms_enable_writeback_connector( + vkmsdev, crtc_cfg->crtc); if (writeback) - DRM_ERROR("Failed to init writeback connector\n"); + DRM_ERROR( + "Failed to init writeback connector\n"); } } @@ -52,7 +57,8 @@ int vkms_output_init(struct vkms_device *vkmsdev) struct vkms_config_crtc *possible_crtc; unsigned long idx = 0; - vkms_config_plane_for_each_possible_crtc(plane_cfg, idx, possible_crtc) { + vkms_config_plane_for_each_possible_crtc(plane_cfg, idx, + possible_crtc) { plane_cfg->plane->base.possible_crtcs |= drm_crtc_mask(&possible_crtc->crtc->crtc); } @@ -62,7 +68,8 @@ int vkms_output_init(struct vkms_device *vkmsdev) struct vkms_config_crtc *possible_crtc; unsigned long idx = 0; - encoder_cfg->encoder = drmm_kzalloc(dev, sizeof(*encoder_cfg->encoder), GFP_KERNEL); + encoder_cfg->encoder = drmm_kzalloc( + dev, sizeof(*encoder_cfg->encoder), GFP_KERNEL); if (!encoder_cfg->encoder) { DRM_ERROR("Failed to allocate encoder\n"); return -ENOMEM; @@ -77,7 +84,8 @@ int vkms_output_init(struct vkms_device *vkmsdev) encoder_cfg->encoder->possible_clones |= drm_encoder_mask(encoder_cfg->encoder); - vkms_config_encoder_for_each_possible_crtc(encoder_cfg, idx, possible_crtc) { + vkms_config_encoder_for_each_possible_crtc(encoder_cfg, idx, + possible_crtc) { encoder_cfg->encoder->possible_crtcs |= drm_crtc_mask(&possible_crtc->crtc->crtc); @@ -98,22 +106,25 @@ int vkms_output_init(struct vkms_device *vkmsdev) unsigned long idx = 0; connector_cfg->connector = vkms_connector_init( - vkmsdev, vkms_config_connector_get_status(connector_cfg)); + vkmsdev, + vkms_config_connector_get_status(connector_cfg)); if (IS_ERR(connector_cfg->connector)) { DRM_ERROR("Failed to init connector\n"); return PTR_ERR(connector_cfg->connector); } - vkms_connector_set_requested_mode(connector_cfg->connector, - &connector_cfg->requested_mode); + vkms_connector_set_requested_mode( + connector_cfg->connector, + &connector_cfg->requested_mode); - vkms_config_connector_for_each_possible_encoder(connector_cfg, - idx, - possible_encoder) { - ret = drm_connector_attach_encoder(&connector_cfg->connector->base, - possible_encoder->encoder); + vkms_config_connector_for_each_possible_encoder( + connector_cfg, idx, possible_encoder) { + ret = drm_connector_attach_encoder( + &connector_cfg->connector->base, + possible_encoder->encoder); if (ret) { - DRM_ERROR("Failed to attach connector to encoder\n"); + DRM_ERROR( + "Failed to attach connector to encoder\n"); return ret; } } diff --git a/linux/vibeshine-drm/vkms_plane.c b/linux/vibeshine-drm/vkms_plane.c index de4d808..6784afd 100644 --- a/linux/vibeshine-drm/vkms_plane.c +++ b/linux/vibeshine-drm/vkms_plane.c @@ -16,42 +16,24 @@ #include "vibeshine_drm_compat.h" static const u32 vkms_formats[] = { - DRM_FORMAT_ARGB8888, - DRM_FORMAT_ABGR8888, - DRM_FORMAT_BGRA8888, - DRM_FORMAT_RGBA8888, - DRM_FORMAT_XRGB8888, - DRM_FORMAT_XBGR8888, - DRM_FORMAT_XRGB2101010, - DRM_FORMAT_XBGR2101010, - DRM_FORMAT_ARGB2101010, - DRM_FORMAT_ABGR2101010, - DRM_FORMAT_RGB888, - DRM_FORMAT_BGR888, - DRM_FORMAT_XRGB16161616, - DRM_FORMAT_XBGR16161616, - DRM_FORMAT_ARGB16161616, - DRM_FORMAT_ABGR16161616, - DRM_FORMAT_RGB565, - DRM_FORMAT_BGR565, - DRM_FORMAT_NV12, - DRM_FORMAT_NV16, - DRM_FORMAT_NV24, - DRM_FORMAT_NV21, - DRM_FORMAT_NV61, - DRM_FORMAT_NV42, - DRM_FORMAT_YUV420, - DRM_FORMAT_YUV422, - DRM_FORMAT_YUV444, - DRM_FORMAT_YVU420, - DRM_FORMAT_YVU422, - DRM_FORMAT_YVU444, - DRM_FORMAT_P010, - DRM_FORMAT_P012, - DRM_FORMAT_P016, - DRM_FORMAT_R1, - DRM_FORMAT_R2, - DRM_FORMAT_R4, + DRM_FORMAT_ARGB8888, DRM_FORMAT_ABGR8888, + DRM_FORMAT_BGRA8888, DRM_FORMAT_RGBA8888, + DRM_FORMAT_XRGB8888, DRM_FORMAT_XBGR8888, + DRM_FORMAT_XRGB2101010, DRM_FORMAT_XBGR2101010, + DRM_FORMAT_ARGB2101010, DRM_FORMAT_ABGR2101010, + DRM_FORMAT_RGB888, DRM_FORMAT_BGR888, + DRM_FORMAT_XRGB16161616, DRM_FORMAT_XBGR16161616, + DRM_FORMAT_ARGB16161616, DRM_FORMAT_ABGR16161616, + DRM_FORMAT_RGB565, DRM_FORMAT_BGR565, + DRM_FORMAT_NV12, DRM_FORMAT_NV16, + DRM_FORMAT_NV24, DRM_FORMAT_NV21, + DRM_FORMAT_NV61, DRM_FORMAT_NV42, + DRM_FORMAT_YUV420, DRM_FORMAT_YUV422, + DRM_FORMAT_YUV444, DRM_FORMAT_YVU420, + DRM_FORMAT_YVU422, DRM_FORMAT_YVU444, + DRM_FORMAT_P010, DRM_FORMAT_P012, + DRM_FORMAT_P016, DRM_FORMAT_R1, + DRM_FORMAT_R2, DRM_FORMAT_R4, DRM_FORMAT_R8, }; @@ -186,19 +168,19 @@ static void vkms_plane_reset(struct drm_plane *plane) } static const struct drm_plane_funcs vkms_plane_funcs = { - .update_plane = drm_atomic_helper_update_plane, - .disable_plane = drm_atomic_helper_disable_plane, - .reset = vkms_plane_reset, + .update_plane = drm_atomic_helper_update_plane, + .disable_plane = drm_atomic_helper_disable_plane, + .reset = vkms_plane_reset, .atomic_duplicate_state = vkms_plane_duplicate_state, - .atomic_destroy_state = vkms_plane_destroy_state, - .format_mod_supported = vkms_format_mod_supported, + .atomic_destroy_state = vkms_plane_destroy_state, + .format_mod_supported = vkms_format_mod_supported, }; static void vkms_plane_atomic_update(struct drm_plane *plane, struct drm_atomic_commit *state) { - struct drm_plane_state *new_state = drm_atomic_get_new_plane_state(state, - plane); + struct drm_plane_state *new_state = + drm_atomic_get_new_plane_state(state, plane); struct vkms_plane_state *vkms_plane_state; struct drm_shadow_plane_state *shadow_plane_state; struct drm_framebuffer *fb = new_state->fb; @@ -216,35 +198,36 @@ static void vkms_plane_atomic_update(struct drm_plane *plane, memcpy(&frame_info->src, &new_state->src, sizeof(struct drm_rect)); memcpy(&frame_info->dst, &new_state->dst, sizeof(struct drm_rect)); frame_info->fb = fb; - memcpy(&frame_info->map, &shadow_plane_state->data, sizeof(frame_info->map)); + memcpy(&frame_info->map, &shadow_plane_state->data, + sizeof(frame_info->map)); drm_framebuffer_get(frame_info->fb); frame_info->rotation = new_state->rotation; vkms_plane_state->pixel_read_line = get_pixel_read_line_function(fmt); - get_conversion_matrix_to_argb_u16(fmt, new_state->color_encoding, new_state->color_range, + get_conversion_matrix_to_argb_u16(fmt, new_state->color_encoding, + new_state->color_range, &vkms_plane_state->conversion_matrix); } static int vkms_plane_atomic_check(struct drm_plane *plane, struct drm_atomic_commit *state) { - struct drm_plane_state *new_plane_state = drm_atomic_get_new_plane_state(state, - plane); + struct drm_plane_state *new_plane_state = + drm_atomic_get_new_plane_state(state, plane); struct drm_crtc_state *crtc_state; int ret; if (!new_plane_state->fb || WARN_ON(!new_plane_state->crtc)) return 0; - crtc_state = drm_atomic_get_crtc_state(state, - new_plane_state->crtc); + crtc_state = drm_atomic_get_crtc_state(state, new_plane_state->crtc); if (IS_ERR(crtc_state)) return PTR_ERR(crtc_state); ret = drm_atomic_helper_check_plane_state(new_plane_state, crtc_state, DRM_PLANE_NO_SCALING, - DRM_PLANE_NO_SCALING, - true, true); + DRM_PLANE_NO_SCALING, true, + true); if (ret != 0) return ret; @@ -311,10 +294,10 @@ static void vkms_cleanup_fb(struct drm_plane *plane, } static const struct drm_plane_helper_funcs vkms_plane_helper_funcs = { - .atomic_update = vkms_plane_atomic_update, - .atomic_check = vkms_plane_atomic_check, - .prepare_fb = vkms_prepare_fb, - .cleanup_fb = vkms_cleanup_fb, + .atomic_update = vkms_plane_atomic_update, + .atomic_check = vkms_plane_atomic_check, + .prepare_fb = vkms_prepare_fb, + .cleanup_fb = vkms_cleanup_fb, }; struct vkms_plane *vkms_plane_init(struct vkms_device *vkmsdev, @@ -323,28 +306,26 @@ struct vkms_plane *vkms_plane_init(struct vkms_device *vkmsdev, struct drm_device *dev = &vkmsdev->drm; struct vkms_plane *plane; - plane = drmm_universal_plane_alloc(dev, struct vkms_plane, base, 0, - &vkms_plane_funcs, - vkms_formats, ARRAY_SIZE(vkms_formats), - vkms_format_modifiers, - vkms_config_plane_get_type(plane_cfg), - NULL); + plane = drmm_universal_plane_alloc( + dev, struct vkms_plane, base, 0, &vkms_plane_funcs, + vkms_formats, ARRAY_SIZE(vkms_formats), vkms_format_modifiers, + vkms_config_plane_get_type(plane_cfg), NULL); if (IS_ERR(plane)) return plane; drm_plane_helper_add(&plane->base, &vkms_plane_helper_funcs); drm_plane_create_rotation_property(&plane->base, DRM_MODE_ROTATE_0, - DRM_MODE_ROTATE_MASK | DRM_MODE_REFLECT_MASK); - - drm_plane_create_color_properties(&plane->base, - BIT(DRM_COLOR_YCBCR_BT601) | - BIT(DRM_COLOR_YCBCR_BT709) | - BIT(DRM_COLOR_YCBCR_BT2020), - BIT(DRM_COLOR_YCBCR_LIMITED_RANGE) | - BIT(DRM_COLOR_YCBCR_FULL_RANGE), - DRM_COLOR_YCBCR_BT601, - DRM_COLOR_YCBCR_FULL_RANGE); + DRM_MODE_ROTATE_MASK | + DRM_MODE_REFLECT_MASK); + + drm_plane_create_color_properties( + &plane->base, + BIT(DRM_COLOR_YCBCR_BT601) | BIT(DRM_COLOR_YCBCR_BT709) | + BIT(DRM_COLOR_YCBCR_BT2020), + BIT(DRM_COLOR_YCBCR_LIMITED_RANGE) | + BIT(DRM_COLOR_YCBCR_FULL_RANGE), + DRM_COLOR_YCBCR_BT601, DRM_COLOR_YCBCR_FULL_RANGE); #if VIBESHINE_DRM_HAS_COLOR_PIPELINE if (vkms_config_plane_get_default_pipeline(plane_cfg)) diff --git a/linux/vibeshine-drm/vkms_writeback.c b/linux/vibeshine-drm/vkms_writeback.c index dc45a47..5346c3c 100644 --- a/linux/vibeshine-drm/vkms_writeback.c +++ b/linux/vibeshine-drm/vkms_writeback.c @@ -17,12 +17,8 @@ #include "vibeshine_drm_compat.h" static const u32 vkms_wb_formats[] = { - DRM_FORMAT_ARGB8888, - DRM_FORMAT_XRGB8888, - DRM_FORMAT_ABGR8888, - DRM_FORMAT_XRGB16161616, - DRM_FORMAT_ARGB16161616, - DRM_FORMAT_RGB565 + DRM_FORMAT_ARGB8888, DRM_FORMAT_XRGB8888, DRM_FORMAT_ABGR8888, + DRM_FORMAT_XRGB16161616, DRM_FORMAT_ARGB16161616, DRM_FORMAT_RGB565 }; static const struct drm_connector_funcs vkms_wb_connector_funcs = { @@ -53,8 +49,8 @@ static int vkms_wb_atomic_check(struct drm_connector *connector, fb = conn_state->writeback_job->fb; if (fb->width != mode->hdisplay || fb->height != mode->vdisplay) { - DRM_DEBUG_KMS("Invalid framebuffer size %ux%u\n", - fb->width, fb->height); + DRM_DEBUG_KMS("Invalid framebuffer size %ux%u\n", fb->width, + fb->height); return -EINVAL; } @@ -86,7 +82,8 @@ static int vkms_wb_prepare_job(struct drm_writeback_connector *wb_connector, if (!vkmsjob) return -ENOMEM; - ret = drm_gem_fb_vmap(job->fb, vkmsjob->wb_frame_info.map, vkmsjob->data); + ret = drm_gem_fb_vmap(job->fb, vkmsjob->wb_frame_info.map, + vkmsjob->data); if (ret) { DRM_ERROR("vmap failed: %d\n", ret); goto err_kfree; @@ -108,9 +105,8 @@ static void vkms_wb_cleanup_job(struct drm_writeback_connector *connector, struct drm_writeback_job *job) { struct vkms_writeback_job *vkmsjob = job->priv; - struct vkms_output *vkms_output = container_of(connector, - struct vkms_output, - wb_connector); + struct vkms_output *vkms_output = + container_of(connector, struct vkms_output, wb_connector); if (!job->fb) return; @@ -126,9 +122,10 @@ static void vkms_wb_cleanup_job(struct drm_writeback_connector *connector, static void vkms_wb_atomic_commit(struct drm_connector *conn, struct drm_atomic_commit *state) { - struct drm_connector_state *connector_state = drm_atomic_get_new_connector_state(state, - conn); - struct vkms_output *output = drm_crtc_to_vkms_output(connector_state->crtc); + struct drm_connector_state *connector_state = + drm_atomic_get_new_connector_state(state, conn); + struct vkms_output *output = + drm_crtc_to_vkms_output(connector_state->crtc); struct drm_writeback_connector *wb_conn = &output->wb_connector; struct drm_connector_state *conn_state = wb_conn->base.state; struct vkms_crtc_state *crtc_state = output->composer_state; @@ -171,11 +168,12 @@ int vkms_enable_writeback_connector(struct vkms_device *vkmsdev, struct drm_writeback_connector *wb = &vkms_output->wb_connector; int ret; - ret = drmm_encoder_init(&vkmsdev->drm, &vkms_output->wb_encoder, - NULL, DRM_MODE_ENCODER_VIRTUAL, NULL); + ret = drmm_encoder_init(&vkmsdev->drm, &vkms_output->wb_encoder, NULL, + DRM_MODE_ENCODER_VIRTUAL, NULL); if (ret) return ret; - vkms_output->wb_encoder.possible_crtcs |= drm_crtc_mask(&vkms_output->crtc); + vkms_output->wb_encoder.possible_crtcs |= + drm_crtc_mask(&vkms_output->crtc); vkms_output->wb_encoder.possible_clones |= drm_encoder_mask(&vkms_output->wb_encoder); diff --git a/linux/vkms_peercred.cpp b/linux/vkms_peercred.cpp index 337e659..35f07ce 100644 --- a/linux/vkms_peercred.cpp +++ b/linux/vkms_peercred.cpp @@ -2,18 +2,17 @@ #include #include #include -#include - #include #include #include +#include namespace { -int fail(const char *message) { - std::fprintf(stderr, "vibeshine-vkms-peercred: %s: %s\n", message, std::strerror(errno)); - return 1; -} + int fail(const char *message) { + std::fprintf(stderr, "vibeshine-vkms-peercred: %s: %s\n", message, std::strerror(errno)); + return 1; + } } // namespace @@ -25,8 +24,7 @@ int main(int argc, char **argv) { sockaddr_storage local_address {}; socklen_t local_address_size = sizeof(local_address); - if (getsockname(STDIN_FILENO, reinterpret_cast(&local_address), - &local_address_size) != 0) { + if (getsockname(STDIN_FILENO, reinterpret_cast(&local_address), &local_address_size) != 0) { return fail("standard input is not a socket"); } if (local_address.ss_family != AF_UNIX) { diff --git a/src/driver/broker_commands.cpp b/src/driver/broker_commands.cpp index dce7422..68cd8da 100644 --- a/src/driver/broker_commands.cpp +++ b/src/driver/broker_commands.cpp @@ -82,7 +82,7 @@ namespace virtual_display::driver { std::wstring widen_ascii(const std::string_view text) { std::wstring wide; wide.reserve(text.size()); - for (const unsigned char ch: text) { + for (const unsigned char ch : text) { wide.push_back(static_cast(ch)); } return wide; @@ -91,7 +91,7 @@ namespace virtual_display::driver { std::wstring quote_broker_argument(const std::wstring &value) { std::wstring quoted {L"\""}; std::size_t backslashes = 0; - for (wchar_t ch: value) { + for (wchar_t ch : value) { if (ch == L'"') { quoted.append(backslashes * 2 + 1, L'\\'); quoted += ch; @@ -179,7 +179,7 @@ namespace virtual_display::driver { void set_display_name(char (&target)[kDisplayNameChars], const std::string_view name) { std::fill(std::begin(target), std::end(target), '\0'); - std::memcpy(target, name.data(), (std::min)(name.size(), static_cast(kDisplayNameChars - 1))); + std::memcpy(target, name.data(), (std::min) (name.size(), static_cast(kDisplayNameChars - 1))); } } // namespace @@ -282,7 +282,7 @@ namespace virtual_display::driver { } std::size_t name_offset = 0; - for (const auto field: fields) { + for (const auto field : fields) { name_offset = static_cast((field.data() + field.size()) - payload.data()); } while (name_offset < payload.size() && payload[name_offset] == ' ') { @@ -293,12 +293,7 @@ namespace virtual_display::driver { } PermanentDisplayCountRequest request {}; - if (!parse_broker_u32(fields[0], request.display_count) || - !parse_broker_u32(fields[1], request.width) || - !parse_broker_u32(fields[2], request.height) || - !parse_broker_u32(fields[3], request.physical_width_mm) || - !parse_broker_u32(fields[4], request.physical_height_mm) || - !parse_broker_u32(fields[5], request.refresh_rate_millihz)) { + if (!parse_broker_u32(fields[0], request.display_count) || !parse_broker_u32(fields[1], request.width) || !parse_broker_u32(fields[2], request.height) || !parse_broker_u32(fields[3], request.physical_width_mm) || !parse_broker_u32(fields[4], request.physical_height_mm) || !parse_broker_u32(fields[5], request.refresh_rate_millihz)) { return std::nullopt; } set_display_name(request.display_name, payload.substr(name_offset)); @@ -318,7 +313,7 @@ namespace virtual_display::driver { } std::size_t name_offset = 0; - for (const auto field: fields) { + for (const auto field : fields) { name_offset = static_cast((field.data() + field.size()) - payload.data()); } while (name_offset < payload.size() && payload[name_offset] == ' ') { @@ -338,22 +333,13 @@ namespace virtual_display::driver { std::uint32_t layout_policy {}; std::int32_t position_x {}; std::int32_t position_y {}; - if (!parse_broker_u32(fields[0], slot) || - !parse_broker_u32(fields[1], width) || - !parse_broker_u32(fields[2], height) || - !parse_broker_u32(fields[3], physical_width_mm) || - !parse_broker_u32(fields[4], physical_height_mm) || - !parse_broker_u32(fields[5], refresh_rate_millihz) || - !parse_broker_u32(fields[6], hdr_supported) || - !parse_broker_u32(fields[7], layout_policy) || - !parse_broker_i32(fields[8], position_x) || - !parse_broker_i32(fields[9], position_y)) { + if (!parse_broker_u32(fields[0], slot) || !parse_broker_u32(fields[1], width) || !parse_broker_u32(fields[2], height) || !parse_broker_u32(fields[3], physical_width_mm) || !parse_broker_u32(fields[4], physical_height_mm) || !parse_broker_u32(fields[5], refresh_rate_millihz) || !parse_broker_u32(fields[6], hdr_supported) || !parse_broker_u32(fields[7], layout_policy) || !parse_broker_i32(fields[8], position_x) || !parse_broker_i32(fields[9], position_y)) { return std::nullopt; } DisplayManifestProfile profile {}; profile.flags = kDisplayManifestProfileFlagRetainIdentity | - kDisplayManifestProfileFlagPermanentIdentity; + kDisplayManifestProfileFlagPermanentIdentity; if (hdr_supported != 0) { profile.flags |= kDisplayManifestProfileFlagHdrSupported; } @@ -403,14 +389,14 @@ namespace virtual_display::driver { if (fields.size() != 4) { return std::nullopt; } - for (const auto field: fields) { + for (const auto field : fields) { if (!broker_u32_text_is_valid(field)) { return std::nullopt; } } std::wstring arguments = quote_broker_argument(L"--stress-capture-remove"); - for (const auto field: fields) { + for (const auto field : fields) { arguments += L" "; arguments += quote_broker_argument(widen_ascii(field)); } @@ -425,7 +411,7 @@ namespace virtual_display::driver { } std::size_t profile_offset = 0; - for (const auto field: fields) { + for (const auto field : fields) { profile_offset = static_cast((field.data() + field.size()) - payload.data()); } while (profile_offset < payload.size() && payload[profile_offset] == ' ') { diff --git a/src/driver/cli_commands.cpp b/src/driver/cli_commands.cpp index c41e0d7..b2cffce 100644 --- a/src/driver/cli_commands.cpp +++ b/src/driver/cli_commands.cpp @@ -1,12 +1,12 @@ #include "virtual_display/driver/cli_commands.h" #include +#include #include #include #include -#include -#include #include +#include #include #include #include @@ -53,9 +53,7 @@ namespace virtual_display::driver { } const double millihz = refresh <= 1000.0 ? refresh * 1000.0 : refresh; - if (!std::isfinite(millihz) || - millihz < 1.0 || - millihz > static_cast((std::numeric_limits::max)())) { + if (!std::isfinite(millihz) || millihz < 1.0 || millihz > static_cast((std::numeric_limits::max)())) { return false; } @@ -267,7 +265,7 @@ namespace virtual_display::driver { std::memcpy( request.display_name, options.name.data(), - (std::min)(options.name.size(), static_cast(kDisplayNameChars - 1)) + (std::min) (options.name.size(), static_cast(kDisplayNameChars - 1)) ); return request; } @@ -383,14 +381,7 @@ namespace virtual_display::driver { }; if (args[0] == "broker") { - if (args.size() == 2 && - (args[1] == "protocol" || - args[1] == "query-state" || - args[1] == "query-manifest" || - args[1] == "helper-diagnose" || - args[1] == "helper-apply-extended-topology" || - args[1] == "helper-apply-manifest-topology" || - args[1] == "helper-query-color-profiles")) { + if (args.size() == 2 && (args[1] == "protocol" || args[1] == "query-state" || args[1] == "query-manifest" || args[1] == "helper-diagnose" || args[1] == "helper-apply-extended-topology" || args[1] == "helper-apply-manifest-topology" || args[1] == "helper-query-color-profiles")) { return query_route(args[1]); } if (args.size() >= 5 && args[1] == "helper-associate-color-profile") { @@ -435,20 +426,19 @@ namespace virtual_display::driver { } std::string cli_usage_text() { - return - "virtualdisplay commands:\n" - " driver install [--inf PATH]\n" - " vulkan-layer install [--json PATH] | uninstall | status\n" - " broker install|start|stop|status|uninstall\n" - " broker protocol|query-state|query-manifest|helper-diagnose|helper-apply-extended-topology|helper-apply-manifest-topology|helper-query-color-profiles\n" - " broker helper-associate-color-profile [--advanced-color] [--default]\n" - " broker helper-stress-capture-remove [iterations width height refresh_hz]\n" - " status\n" - " display query\n" - " spawn [--width N] [--height N] [--physical-width-mm N] [--physical-height-mm N] [--refresh HZ] [--name TEXT]\n" - " permanent query\n" - " permanent set --count N [--width N] [--height N] [--physical-width-mm N] [--physical-height-mm N] [--refresh HZ] [--name TEXT]\n" - " permanent profile set --slot N [--width N] [--height N] [--physical-width-mm N] [--physical-height-mm N] [--refresh HZ] [--name TEXT] [--layout none|apply|persist] [--x N] [--y N] [--hdr 0|1]\n" - " permanent off\n"; + return "virtualdisplay commands:\n" + " driver install [--inf PATH]\n" + " vulkan-layer install [--json PATH] | uninstall | status\n" + " broker install|start|stop|status|uninstall\n" + " broker protocol|query-state|query-manifest|helper-diagnose|helper-apply-extended-topology|helper-apply-manifest-topology|helper-query-color-profiles\n" + " broker helper-associate-color-profile [--advanced-color] [--default]\n" + " broker helper-stress-capture-remove [iterations width height refresh_hz]\n" + " status\n" + " display query\n" + " spawn [--width N] [--height N] [--physical-width-mm N] [--physical-height-mm N] [--refresh HZ] [--name TEXT]\n" + " permanent query\n" + " permanent set --count N [--width N] [--height N] [--physical-width-mm N] [--physical-height-mm N] [--refresh HZ] [--name TEXT]\n" + " permanent profile set --slot N [--width N] [--height N] [--physical-width-mm N] [--physical-height-mm N] [--refresh HZ] [--name TEXT] [--layout none|apply|persist] [--x N] [--y N] [--hdr 0|1]\n" + " permanent off\n"; } } // namespace virtual_display::driver diff --git a/src/driver/control_client.cpp b/src/driver/control_client.cpp index 278c32c..caf1086 100644 --- a/src/driver/control_client.cpp +++ b/src/driver/control_client.cpp @@ -10,9 +10,7 @@ namespace virtual_display::driver { if (!result.ok()) { return result; } - if (!is_valid_api_namespace(result.value.api_namespace) || - result.value.major != kProtocolVersionMajor || - result.value.minor < kMinimumCompatibleProtocolVersionMinor) { + if (!is_valid_api_namespace(result.value.api_namespace) || result.value.major != kProtocolVersionMajor || result.value.minor < kMinimumCompatibleProtocolVersionMinor) { result.status = ControlStatus::ProtocolIncompatible; } return result; @@ -34,12 +32,7 @@ namespace virtual_display::driver { return {}; } auto result = ioctl_out(kIoctlQueryFrameTransportCapabilities, nullptr, 0); - if (result.ok() && - (result.value.version != kFrameTransportCapabilitiesVersion || - result.value.size != sizeof(FrameTransportCapabilities) || - result.value.reserved != 0 || - ((result.value.capabilities & kFrameTransportCapabilityKeyedMutexRing) != 0 && - result.value.max_ring_slots != kFrameRingSlotCount))) { + if (result.ok() && (result.value.version != kFrameTransportCapabilitiesVersion || result.value.size != sizeof(FrameTransportCapabilities) || result.value.reserved != 0 || ((result.value.capabilities & kFrameTransportCapabilityKeyedMutexRing) != 0 && result.value.max_ring_slots != kFrameRingSlotCount))) { result.status = ControlStatus::InvalidOutput; } return result; diff --git a/src/driver/control_protocol.cpp b/src/driver/control_protocol.cpp index 0cacce1..e9ba1e8 100644 --- a/src/driver/control_protocol.cpp +++ b/src/driver/control_protocol.cpp @@ -136,31 +136,22 @@ namespace virtual_display::driver { if ((request.flags & ~kCreateTemporaryDisplayKnownFlags) != 0) { return ValidationError::InvalidFlags; } - if (const auto mode_validation = validate_display_mode( - request.width, - request.height, - request.refresh_rate_millihz - ); - mode_validation != ValidationError::None) { + if (const auto mode_validation = validate_display_mode(request.width, request.height, request.refresh_rate_millihz); mode_validation != ValidationError::None) { return mode_validation; } const auto physical_width_mm = request.physical_width_mm == 0 ? - kDefaultPhysicalWidthMillimeters : - request.physical_width_mm; + kDefaultPhysicalWidthMillimeters : + request.physical_width_mm; const auto physical_height_mm = request.physical_height_mm == 0 ? - kDefaultPhysicalHeightMillimeters : - request.physical_height_mm; - if (physical_width_mm < kMinPhysicalSizeMillimeters || - physical_width_mm > kMaxPhysicalSizeMillimeters || - physical_height_mm < kMinPhysicalSizeMillimeters || - physical_height_mm > kMaxPhysicalSizeMillimeters) { + kDefaultPhysicalHeightMillimeters : + request.physical_height_mm; + if (physical_width_mm < kMinPhysicalSizeMillimeters || physical_width_mm > kMaxPhysicalSizeMillimeters || physical_height_mm < kMinPhysicalSizeMillimeters || physical_height_mm > kMaxPhysicalSizeMillimeters) { return ValidationError::InvalidPhysicalSize; } const auto hdr_max_luminance_nits = request.hdr_max_luminance_nits == 0 ? - kDefaultHdrMaxLuminanceNits : - request.hdr_max_luminance_nits; - if (hdr_max_luminance_nits < kMinHdrMaxLuminanceNits || - hdr_max_luminance_nits > kMaxHdrMaxLuminanceNits) { + kDefaultHdrMaxLuminanceNits : + request.hdr_max_luminance_nits; + if (hdr_max_luminance_nits < kMinHdrMaxLuminanceNits || hdr_max_luminance_nits > kMaxHdrMaxLuminanceNits) { return ValidationError::InvalidHdrLuminance; } char canonical_display_name[kDisplayNameChars] {}; @@ -189,18 +180,13 @@ namespace virtual_display::driver { const CreateTemporaryDisplayOwnedRequest &request, ValidatedCreateTemporaryDisplay *validated ) { - if (const auto validation = validate_create_temporary_display(request.display, validated); - validation != ValidationError::None) { + if (const auto validation = validate_create_temporary_display(request.display, validated); validation != ValidationError::None) { return validation; } - if (std::all_of( - request.owner_capability.bytes.begin(), - request.owner_capability.bytes.end(), - [](const std::uint8_t byte) { - return byte == 0; - } - )) { + if (std::all_of(request.owner_capability.bytes.begin(), request.owner_capability.bytes.end(), [](const std::uint8_t byte) { + return byte == 0; + })) { return ValidationError::MissingOwnerCapability; } @@ -220,13 +206,9 @@ namespace virtual_display::driver { if (request.reserved != 0) { return ValidationError::InvalidReservedField; } - if (std::all_of( - request.owner_capability.bytes.begin(), - request.owner_capability.bytes.end(), - [](const std::uint8_t byte) { - return byte == 0; - } - )) { + if (std::all_of(request.owner_capability.bytes.begin(), request.owner_capability.bytes.end(), [](const std::uint8_t byte) { + return byte == 0; + })) { return ValidationError::MissingOwnerCapability; } @@ -274,18 +256,10 @@ namespace virtual_display::driver { if (request.display_count > max_display_count) { return ValidationError::PermanentDisplayCountTooHigh; } - if (const auto mode_validation = validate_display_mode( - request.width, - request.height, - request.refresh_rate_millihz - ); - mode_validation != ValidationError::None) { + if (const auto mode_validation = validate_display_mode(request.width, request.height, request.refresh_rate_millihz); mode_validation != ValidationError::None) { return mode_validation; } - if (request.physical_width_mm < kMinPhysicalSizeMillimeters || - request.physical_width_mm > kMaxPhysicalSizeMillimeters || - request.physical_height_mm < kMinPhysicalSizeMillimeters || - request.physical_height_mm > kMaxPhysicalSizeMillimeters) { + if (request.physical_width_mm < kMinPhysicalSizeMillimeters || request.physical_width_mm > kMaxPhysicalSizeMillimeters || request.physical_height_mm < kMinPhysicalSizeMillimeters || request.physical_height_mm > kMaxPhysicalSizeMillimeters) { return ValidationError::InvalidPhysicalSize; } char canonical_display_name[kDisplayNameChars] {}; @@ -309,13 +283,10 @@ namespace virtual_display::driver { if (manifest.version != kDisplayManifestVersion) { return ValidationError::InvalidManifestVersion; } - if (manifest.profile_count > max_display_count || - manifest.profile_count > kMaxPermanentDisplayProfiles) { + if (manifest.profile_count > max_display_count || manifest.profile_count > kMaxPermanentDisplayProfiles) { return ValidationError::PermanentDisplayCountTooHigh; } - if (manifest.max_profile_count < manifest.profile_count || - manifest.max_profile_count > max_display_count || - manifest.max_profile_count > kMaxPermanentDisplayProfiles) { + if (manifest.max_profile_count < manifest.profile_count || manifest.max_profile_count > max_display_count || manifest.max_profile_count > kMaxPermanentDisplayProfiles) { return ValidationError::PermanentDisplayCountTooHigh; } @@ -332,9 +303,7 @@ namespace virtual_display::driver { if ((profile.flags & kDisplayManifestProfileFlagPermanentIdentity) == 0) { return ValidationError::InvalidFlags; } - if (profile.connector_index >= max_display_count || - profile.connector_index >= kMaxPermanentDisplayProfiles || - used_connectors[profile.connector_index]) { + if (profile.connector_index >= max_display_count || profile.connector_index >= kMaxPermanentDisplayProfiles || used_connectors[profile.connector_index]) { return ValidationError::InvalidConnectorIndex; } used_connectors[profile.connector_index] = true; @@ -355,10 +324,7 @@ namespace virtual_display::driver { return ValidationError::InvalidProductCode; } for (std::uint32_t previous = 0; previous < index; ++previous) { - if (used_display_ids[previous] == profile.display_id || - used_container_ids[previous] == profile.container_id || - used_product_codes[previous] == profile.product_code || - used_serial_numbers[previous] == profile.serial_number) { + if (used_display_ids[previous] == profile.display_id || used_container_ids[previous] == profile.container_id || used_product_codes[previous] == profile.product_code || used_serial_numbers[previous] == profile.serial_number) { return ValidationError::DuplicateManifestIdentity; } } @@ -369,15 +335,10 @@ namespace virtual_display::driver { if (!valid_manufacturer_id(profile.manufacturer_id)) { return ValidationError::InvalidManufacturerId; } - if (profile.physical_width_mm < kMinPhysicalSizeMillimeters || - profile.physical_width_mm > kMaxPhysicalSizeMillimeters || - profile.physical_height_mm < kMinPhysicalSizeMillimeters || - profile.physical_height_mm > kMaxPhysicalSizeMillimeters) { + if (profile.physical_width_mm < kMinPhysicalSizeMillimeters || profile.physical_width_mm > kMaxPhysicalSizeMillimeters || profile.physical_height_mm < kMinPhysicalSizeMillimeters || profile.physical_height_mm > kMaxPhysicalSizeMillimeters) { return ValidationError::InvalidPhysicalSize; } - if (profile.allowed_mode_count == 0 || - profile.allowed_mode_count > kMaxAllowedModesPerProfile || - profile.native_mode_index >= profile.allowed_mode_count) { + if (profile.allowed_mode_count == 0 || profile.allowed_mode_count > kMaxAllowedModesPerProfile || profile.native_mode_index >= profile.allowed_mode_count) { return ValidationError::InvalidModeCount; } if (profile.layout_policy > kDisplayManifestLayoutPolicyApplyAndPersist) { @@ -389,12 +350,7 @@ namespace virtual_display::driver { for (std::uint32_t mode_index = 0; mode_index < profile.allowed_mode_count; ++mode_index) { const auto &mode = profile.allowed_modes[mode_index]; - if (const auto mode_validation = validate_display_mode( - mode.width, - mode.height, - mode.refresh_rate_millihz - ); - mode_validation != ValidationError::None) { + if (const auto mode_validation = validate_display_mode(mode.width, mode.height, mode.refresh_rate_millihz); mode_validation != ValidationError::None) { return mode_validation; } } diff --git a/src/driver/display_identity.cpp b/src/driver/display_identity.cpp index 3a0b703..0a98d09 100644 --- a/src/driver/display_identity.cpp +++ b/src/driver/display_identity.cpp @@ -24,23 +24,21 @@ namespace virtual_display::driver { 0x9161d0d5, static_cast((display_id >> 48) & 0xffffu), static_cast((display_id >> 32) & 0xffffu), - { - 0x93, - 0x7d, - static_cast((display_id >> 24) & 0xffu), - static_cast((display_id >> 16) & 0xffu), - static_cast((display_id >> 8) & 0xffu), - static_cast(display_id & 0xffu), - 0x53, - 0x44 - } + {0x93, + 0x7d, + static_cast((display_id >> 24) & 0xffu), + static_cast((display_id >> 16) & 0xffu), + static_cast((display_id >> 8) & 0xffu), + static_cast(display_id & 0xffu), + 0x53, + 0x44} }; } EdidOptions edid_options_for_temporary_display(const TemporaryDisplayRecord &record) { const auto identity_display_id = record.identity_display_id == 0 ? - record.display_id : - record.identity_display_id; + record.display_id : + record.identity_display_id; EdidOptions options {}; options.manufacturer_id = kSunshineDriverManufacturerId; diff --git a/src/driver/driver_controller.cpp b/src/driver/driver_controller.cpp index 7c3a656..84bd00a 100644 --- a/src/driver/driver_controller.cpp +++ b/src/driver/driver_controller.cpp @@ -70,8 +70,7 @@ namespace virtual_display::driver { const std::chrono::steady_clock::time_point now, std::unique_lock *controller_lock ) { - if (const auto validation = validate_create_temporary_display_owned(request); - validation != ValidationError::None) { + if (const auto validation = validate_create_temporary_display_owned(request); validation != ValidationError::None) { return { {StoreError::ValidationFailed, validation, BackendError::None}, {} @@ -91,31 +90,24 @@ namespace virtual_display::driver { const std::chrono::steady_clock::time_point now, std::unique_lock *controller_lock ) { - if (const auto validation = validate_create_temporary_display(request); - validation != ValidationError::None) { + if (const auto validation = validate_create_temporary_display(request); validation != ValidationError::None) { return { {StoreError::ValidationFailed, validation, BackendError::None}, {} }; } - if (const auto existing = store_.find_temporary_display(request.display_id); - existing && existing->pending_departure) { + if (const auto existing = store_.find_temporary_display(request.display_id); existing && existing->pending_departure) { const auto pending_record = *existing; // Depart unfenced (generation 0): the store record is pending departure, // so any backend monitor still parked under this display_id belongs to an // abandoned lineage and must be cleared before the fresh create. - if (const auto backend_error = call_backend_without_controller_lock( - backend_call_mutex_, - controller_lock, - BackendError::Busy, - [&]() { - return backend_.depart_temporary_display(existing->display_id, 0); - }); + if (const auto backend_error = call_backend_without_controller_lock(backend_call_mutex_, controller_lock, BackendError::Busy, [&]() { + return backend_.depart_temporary_display(existing->display_id, 0); + }); backend_error != BackendError::None) { bool abandoned = false; - if (backend_error == BackendError::Failed && - temporary_display_generation_is_current(pending_record)) { + if (backend_error == BackendError::Failed && temporary_display_generation_is_current(pending_record)) { if (owner_capability) { // The backend actively refused the departure again. Without an // escape the display_id stays wedged until a driver restart: the @@ -182,13 +174,9 @@ namespace virtual_display::driver { const auto created_record = *record; bool identity_reserved = false; if (descriptor.retain_identity) { - if (const auto backend_error = call_backend_without_controller_lock( - backend_call_mutex_, - controller_lock, - BackendError::Busy, - [&]() { - return backend_.reserve_temporary_display_identity(descriptor); - }); + if (const auto backend_error = call_backend_without_controller_lock(backend_call_mutex_, controller_lock, BackendError::Busy, [&]() { + return backend_.reserve_temporary_display_identity(descriptor); + }); backend_error != BackendError::None) { // Roll back only if our just-created record is still current. A concurrent // remove+recreate of the same display_id during the unlocked backend call @@ -237,13 +225,9 @@ namespace virtual_display::driver { if (backend_result.error != BackendError::None) { auto rollback_mode = RemoveTemporaryDisplayMode::ReleaseConnectorReservation; if (identity_reserved) { - if (call_backend_without_controller_lock( - backend_call_mutex_, - controller_lock, - BackendError::Busy, - [&]() { - return backend_.unreserve_temporary_display_identity(request.display_id); - }) != BackendError::None) { + if (call_backend_without_controller_lock(backend_call_mutex_, controller_lock, BackendError::Busy, [&]() { + return backend_.unreserve_temporary_display_identity(request.display_id); + }) != BackendError::None) { rollback_mode = RemoveTemporaryDisplayMode::RetainConnectorReservation; } } @@ -265,9 +249,7 @@ namespace virtual_display::driver { } const auto arrived_record = store_.find_temporary_display(request.display_id); - if (!arrived_record || - arrived_record->lease_id != request.lease_id || - arrived_record->generation != created_record.generation) { + if (!arrived_record || arrived_record->lease_id != request.lease_id || arrived_record->generation != created_record.generation) { (void) call_backend_without_controller_lock( backend_call_mutex_, controller_lock, @@ -290,8 +272,7 @@ namespace virtual_display::driver { return backend_.depart_temporary_display(request.display_id, created_record.generation); } ); - if (cleanup_error == BackendError::None && - temporary_display_generation_is_current(*arrived_record)) { + if (cleanup_error == BackendError::None && temporary_display_generation_is_current(*arrived_record)) { LeaseDisplayRequest remove {}; remove.lease_id = arrived_record->lease_id; remove.display_id = arrived_record->display_id; @@ -313,8 +294,7 @@ namespace virtual_display::driver { const std::chrono::steady_clock::time_point now, std::unique_lock *controller_lock ) { - if (const auto validation = validate_reclaim_temporary_display(request); - validation != ValidationError::None) { + if (const auto validation = validate_reclaim_temporary_display(request); validation != ValidationError::None) { return {{StoreError::ValidationFailed, validation, BackendError::None}, {}}; } @@ -348,8 +328,7 @@ namespace virtual_display::driver { const LeaseDisplayRequest &request, std::unique_lock *controller_lock ) { - if (const auto validation = validate_lease_display_request(request); - validation != ValidationError::None) { + if (const auto validation = validate_lease_display_request(request); validation != ValidationError::None) { return {StoreError::ValidationFailed, validation, BackendError::None}; } @@ -358,13 +337,9 @@ namespace virtual_display::driver { return {StoreError::DisplayNotFound, ValidationError::None, BackendError::None}; } - if (const auto backend_error = call_backend_without_controller_lock( - backend_call_mutex_, - controller_lock, - BackendError::Busy, - [&]() { - return backend_.depart_temporary_display(request.display_id, record->generation); - }); + if (const auto backend_error = call_backend_without_controller_lock(backend_call_mutex_, controller_lock, BackendError::Busy, [&]() { + return backend_.depart_temporary_display(request.display_id, record->generation); + }); backend_error != BackendError::None) { // Only mark OUR record pending-departure, and only when the backend // actually failed the departure. The backend call released the controller @@ -373,8 +348,7 @@ namespace virtual_display::driver { // healthy, in-use virtual display (ABA). A Busy result means the backend // was never invoked - leave the record untouched so a mere lock timeout // cannot poison a live display. Matches release_lease. - if (backend_error == BackendError::Failed && - temporary_display_generation_is_current(*record)) { + if (backend_error == BackendError::Failed && temporary_display_generation_is_current(*record)) { (void) store_.mark_temporary_display_pending_departure(request); } return {StoreError::None, ValidationError::None, backend_error}; @@ -402,8 +376,7 @@ namespace virtual_display::driver { const LeaseRequest &request, std::unique_lock *controller_lock ) { - if (const auto validation = validate_lease_request(request); - validation != ValidationError::None) { + if (const auto validation = validate_lease_request(request); validation != ValidationError::None) { return {StoreError::ValidationFailed, validation, BackendError::None}; } @@ -413,7 +386,7 @@ namespace virtual_display::driver { } BackendError backend_error = BackendError::None; - for (const auto &display: displays) { + for (const auto &display : displays) { const auto depart_error = call_backend_without_controller_lock( backend_call_mutex_, controller_lock, @@ -431,8 +404,7 @@ namespace virtual_display::driver { } } else { // Busy means the backend was never invoked; do not poison the record. - if (depart_error == BackendError::Failed && - temporary_display_generation_is_current(display)) { + if (depart_error == BackendError::Failed && temporary_display_generation_is_current(display)) { LeaseDisplayRequest pending {}; pending.lease_id = display.lease_id; pending.display_id = display.display_id; @@ -464,8 +436,7 @@ namespace virtual_display::driver { ) { auto normalized = request; set_default_permanent_display_settings(normalized); - if (const auto validation = validate_permanent_display_count(normalized, store_.max_permanent_displays()); - validation != ValidationError::None) { + if (const auto validation = validate_permanent_display_count(normalized, store_.max_permanent_displays()); validation != ValidationError::None) { return {StoreError::ValidationFailed, validation, BackendError::None}; } @@ -483,8 +454,7 @@ namespace virtual_display::driver { const DisplayManifest &manifest, std::unique_lock *controller_lock ) { - if (const auto validation = validate_display_manifest(manifest, store_.max_permanent_displays()); - validation != ValidationError::None) { + if (const auto validation = validate_display_manifest(manifest, store_.max_permanent_displays()); validation != ValidationError::None) { return {StoreError::ValidationFailed, validation, BackendError::None}; } @@ -501,13 +471,9 @@ namespace virtual_display::driver { ); } - if (const auto backend_error = call_backend_without_controller_lock( - backend_call_mutex_, - controller_lock, - BackendError::Busy, - [&]() { - return backend_.apply_display_manifest(canonical); - }); + if (const auto backend_error = call_backend_without_controller_lock(backend_call_mutex_, controller_lock, BackendError::Busy, [&]() { + return backend_.apply_display_manifest(canonical); + }); backend_error != BackendError::None) { return {StoreError::None, ValidationError::None, backend_error}; } @@ -530,13 +496,9 @@ namespace virtual_display::driver { return {StoreError::ValidationFailed, ValidationError::InvalidFlags, BackendError::None}; } - if (const auto backend_error = call_backend_without_controller_lock( - backend_call_mutex_, - controller_lock, - BackendError::Busy, - [&]() { - return backend_.set_render_adapter(request); - }); + if (const auto backend_error = call_backend_without_controller_lock(backend_call_mutex_, controller_lock, BackendError::Busy, [&]() { + return backend_.set_render_adapter(request); + }); backend_error != BackendError::None) { return {StoreError::None, ValidationError::None, backend_error}; } @@ -588,7 +550,7 @@ namespace virtual_display::driver { ); } - for (const auto &display: store_.temporary_displays()) { + for (const auto &display : store_.temporary_displays()) { if (result.entry_count >= kMaxDisplayStateEntries) { break; } @@ -608,19 +570,16 @@ namespace virtual_display::driver { ) { auto expired = store_.expired_temporary_displays(now); auto reap_candidates = store_.pending_departure_temporary_displays(); - for (const auto &display: expired) { - if (std::none_of( - reap_candidates.begin(), - reap_candidates.end(), - [&](const auto &candidate) { - return candidate.display_id == display.display_id; - })) { + for (const auto &display : expired) { + if (std::none_of(reap_candidates.begin(), reap_candidates.end(), [&](const auto &candidate) { + return candidate.display_id == display.display_id; + })) { reap_candidates.push_back(display); } } std::uint32_t removed = 0; - for (const auto &display: reap_candidates) { + for (const auto &display : reap_candidates) { // Fence the backend departure on the snapshot's generation. The snapshot // was taken before the controller lock was released for the backend call, // so the same display_id may since have been removed and recreated; an @@ -639,8 +598,7 @@ namespace virtual_display::driver { LeaseDisplayRequest remove {}; remove.lease_id = display.lease_id; remove.display_id = display.display_id; - if (temporary_display_generation_is_current(display) && - store_.remove_temporary_display(remove).error == StoreError::None) { + if (temporary_display_generation_is_current(display) && store_.remove_temporary_display(remove).error == StoreError::None) { ++removed; } } else if (depart_error == BackendError::Failed) { @@ -683,8 +641,8 @@ namespace virtual_display::driver { descriptor.lease_id = record.lease_id; descriptor.display_id = record.display_id; const auto identity_display_id = record.identity_display_id == 0 ? - record.display_id : - record.identity_display_id; + record.display_id : + record.identity_display_id; descriptor.container_id = container_guid_from_display_id(identity_display_id); descriptor.connector_index = record.connector_index; descriptor.width = record.width; @@ -711,8 +669,8 @@ namespace virtual_display::driver { } entry.display_id = record.display_id; const auto identity_display_id = record.identity_display_id == 0 ? - record.display_id : - record.identity_display_id; + record.display_id : + record.identity_display_id; entry.container_id = container_guid_from_display_id(identity_display_id); entry.connector_index = record.connector_index; entry.product_code = product_code_from_display_id(identity_display_id); @@ -722,7 +680,7 @@ namespace virtual_display::driver { entry.physical_width_mm = record.physical_width_mm; entry.physical_height_mm = record.physical_height_mm; entry.refresh_rate_millihz = record.refresh_rate_millihz; - const auto copy_size = (std::min)(record.display_name.size(), static_cast(kDisplayNameChars - 1)); + const auto copy_size = (std::min) (record.display_name.size(), static_cast(kDisplayNameChars - 1)); std::memcpy(entry.display_name, record.display_name.data(), copy_size); return entry; } diff --git a/src/driver/edid.cpp b/src/driver/edid.cpp index 8434270..66c73b0 100644 --- a/src/driver/edid.cpp +++ b/src/driver/edid.cpp @@ -68,9 +68,8 @@ namespace virtual_display::driver { std::uint64_t preferred_total_pixels(const EdidOptions &options) { const auto horizontal_blanking = align8(std::clamp(options.width / 5u, 160u, 2047u)); const auto vertical_blanking = static_cast(std::clamp(options.height / 20u, 45u, 1023u)); - return - static_cast(options.width + horizontal_blanking) * - static_cast(options.height + vertical_blanking); + return static_cast(options.width + horizontal_blanking) * + static_cast(options.height + vertical_blanking); } std::uint64_t preferred_pixel_clock_hz(const EdidOptions &options) { @@ -96,8 +95,7 @@ namespace virtual_display::driver { } EdidOptions detailed_timing_options(const EdidOptions &options) { - if (preferred_pixel_clock_hz(options) <= kMaxBaseDetailedTimingPixelClockHz && - options.refresh_rate_millihz <= kMaxRangeDescriptorVerticalHz * 1000u) { + if (preferred_pixel_clock_hz(options) <= kMaxBaseDetailedTimingPixelClockHz && options.refresh_rate_millihz <= kMaxRangeDescriptorVerticalHz * 1000u) { return options; } @@ -267,8 +265,14 @@ namespace virtual_display::driver { auto extension = std::span {edid.data() + kEdidBlockSize, kEdidBlockSize}; const std::array header { - std::byte {0x00}, std::byte {0xff}, std::byte {0xff}, std::byte {0xff}, - std::byte {0xff}, std::byte {0xff}, std::byte {0xff}, std::byte {0x00} + std::byte {0x00}, + std::byte {0xff}, + std::byte {0xff}, + std::byte {0xff}, + std::byte {0xff}, + std::byte {0xff}, + std::byte {0xff}, + std::byte {0x00} }; std::copy(header.begin(), header.end(), base.begin()); @@ -304,7 +308,14 @@ namespace virtual_display::driver { // handles its own gamut mapping; guessing P3 here would still limit it. // Coordinates are Rx, Ry, Gx, Gy, Bx, By, Wx, Wy (ITU-R BT.2020). constexpr std::array chromaticities { - 0.708, 0.292, 0.170, 0.797, 0.131, 0.046, 0.3127, 0.3290 + 0.708, + 0.292, + 0.170, + 0.797, + 0.131, + 0.046, + 0.3127, + 0.3290 }; base[25] = std::byte {0}; base[26] = std::byte {0}; @@ -329,22 +340,70 @@ namespace virtual_display::driver { std::size_t data_offset = 4; if (safe_options.hdr_supported) { std::array hdr_cta_blocks { - std::byte {0x51}, std::byte {0x5d}, std::byte {0x5e}, std::byte {0x5f}, - std::byte {0x60}, std::byte {0x61}, std::byte {0x10}, std::byte {0x1f}, - std::byte {0x22}, std::byte {0x21}, std::byte {0x20}, std::byte {0x05}, - std::byte {0x14}, std::byte {0x04}, std::byte {0x13}, std::byte {0x12}, - std::byte {0x03}, std::byte {0x01}, std::byte {0x23}, std::byte {0x0f}, - std::byte {0x56}, std::byte {0x05}, std::byte {0x83}, std::byte {0x0f}, - std::byte {0x08}, std::byte {0x00}, std::byte {0x6d}, std::byte {0x03}, - std::byte {0x0c}, std::byte {0x00}, std::byte {0x10}, std::byte {0x00}, - std::byte {0x38}, std::byte {0x78}, std::byte {0x20}, std::byte {0x00}, - std::byte {0x60}, std::byte {0x01}, std::byte {0x02}, std::byte {0x03}, - std::byte {0x67}, std::byte {0xd8}, std::byte {0x5d}, std::byte {0xc4}, - std::byte {0x01}, std::byte {0x78}, std::byte {0x80}, std::byte {0x03}, - std::byte {0xe3}, std::byte {0x05}, std::byte {0xe0}, std::byte {0x01}, - std::byte {0xe4}, std::byte {0x0f}, std::byte {0x18}, std::byte {0x00}, - std::byte {0x00}, std::byte {0xe6}, std::byte {0x06}, std::byte {0x0f}, - std::byte {0x01}, std::byte {0x00}, std::byte {0x00}, std::byte {0x00} + std::byte {0x51}, + std::byte {0x5d}, + std::byte {0x5e}, + std::byte {0x5f}, + std::byte {0x60}, + std::byte {0x61}, + std::byte {0x10}, + std::byte {0x1f}, + std::byte {0x22}, + std::byte {0x21}, + std::byte {0x20}, + std::byte {0x05}, + std::byte {0x14}, + std::byte {0x04}, + std::byte {0x13}, + std::byte {0x12}, + std::byte {0x03}, + std::byte {0x01}, + std::byte {0x23}, + std::byte {0x0f}, + std::byte {0x56}, + std::byte {0x05}, + std::byte {0x83}, + std::byte {0x0f}, + std::byte {0x08}, + std::byte {0x00}, + std::byte {0x6d}, + std::byte {0x03}, + std::byte {0x0c}, + std::byte {0x00}, + std::byte {0x10}, + std::byte {0x00}, + std::byte {0x38}, + std::byte {0x78}, + std::byte {0x20}, + std::byte {0x00}, + std::byte {0x60}, + std::byte {0x01}, + std::byte {0x02}, + std::byte {0x03}, + std::byte {0x67}, + std::byte {0xd8}, + std::byte {0x5d}, + std::byte {0xc4}, + std::byte {0x01}, + std::byte {0x78}, + std::byte {0x80}, + std::byte {0x03}, + std::byte {0xe3}, + std::byte {0x05}, + std::byte {0xe0}, + std::byte {0x01}, + std::byte {0xe4}, + std::byte {0x0f}, + std::byte {0x18}, + std::byte {0x00}, + std::byte {0x00}, + std::byte {0xe6}, + std::byte {0x06}, + std::byte {0x0f}, + std::byte {0x01}, + std::byte {0x00}, + std::byte {0x00}, + std::byte {0x00} }; const auto hdr_max_luminance = hdr_max_luminance_cta_value(safe_options.hdr_max_luminance_nits); hdr_cta_blocks[61] = hdr_max_luminance; @@ -504,12 +563,8 @@ namespace virtual_display::driver { std::optional read_monitor_name(const std::span edid) { constexpr std::array kDescriptorOffsets {54, 72, 90, 108}; - for (const auto offset: kDescriptorOffsets) { - if (edid[offset] != std::byte {0x00} || - edid[offset + 1] != std::byte {0x00} || - edid[offset + 2] != std::byte {0x00} || - edid[offset + 3] != std::byte {0xfc} || - edid[offset + 4] != std::byte {0x00}) { + for (const auto offset : kDescriptorOffsets) { + if (edid[offset] != std::byte {0x00} || edid[offset + 1] != std::byte {0x00} || edid[offset + 2] != std::byte {0x00} || edid[offset + 3] != std::byte {0xfc} || edid[offset + 4] != std::byte {0x00}) { continue; } diff --git a/src/driver/frame_ring_lifetime.cpp b/src/driver/frame_ring_lifetime.cpp index 93e5ff1..0f153be 100644 --- a/src/driver/frame_ring_lifetime.cpp +++ b/src/driver/frame_ring_lifetime.cpp @@ -41,9 +41,7 @@ namespace virtual_display::driver { previous_publication->disable(); } const auto publication = std::make_shared(); - rings_.insert_or_assign(owner.display.display_id, Entry { - owner, {owner.display_generation, generation, resources, publication} - }); + rings_.insert_or_assign(owner.display.display_id, Entry {owner, {owner.display_generation, generation, resources, publication}}); ++next_ring_generation_; return {FrameRingRegistrationStatus::Success, generation}; } @@ -80,8 +78,7 @@ namespace virtual_display::driver { const std::uint64_t ring_generation ) { const auto entry = rings_.find(display_id); - if (entry == rings_.end() || entry->second.snapshot.display_generation != display_generation || - entry->second.snapshot.ring_generation != ring_generation) { + if (entry == rings_.end() || entry->second.snapshot.display_generation != display_generation || entry->second.snapshot.ring_generation != ring_generation) { return false; } entry->second.snapshot.retire_publication(); @@ -100,7 +97,7 @@ namespace virtual_display::driver { } void FrameRingLifetime::reset() { - for (const auto &[_, entry]: rings_) { + for (const auto &[_, entry] : rings_) { entry.snapshot.retire_publication(); } rings_.clear(); diff --git a/src/driver/frame_ring_server.cpp b/src/driver/frame_ring_server.cpp index 3c7b3d3..ca9b902 100644 --- a/src/driver/frame_ring_server.cpp +++ b/src/driver/frame_ring_server.cpp @@ -10,32 +10,40 @@ namespace virtual_display::driver { o.capability = r.owner_capability; return o; } - } + } // namespace + FrameRingServer::FrameRingServer(const DisplayStore &store, FrameRingLifetime &rings, FrameResourceImporter &importer): - store_(store), rings_(rings), importer_(importer) {} - FrameRingServer::~FrameRingServer() { reset(); } + store_(store), + rings_(rings), + importer_(importer) {} - FrameWireResult FrameRingServer::register_ring(const FrameRequestPeer &peer, const FrameRingRegisterRequest &r, - std::chrono::steady_clock::time_point now) { + FrameRingServer::~FrameRingServer() { + reset(); + } + + FrameWireResult FrameRingServer::register_ring(const FrameRequestPeer &peer, const FrameRingRegisterRequest &r, std::chrono::steady_clock::time_point now) { return register_ring(peer, r, now, importer_); } - FrameWireResult FrameRingServer::register_ring(const FrameRequestPeer &peer, const FrameRingRegisterRequest &r, - std::chrono::steady_clock::time_point now, - FrameResourceImporter &importer) { - if (!peer.valid() || !valid_frame_ring_request(r)) return {}; + FrameWireResult FrameRingServer::register_ring(const FrameRequestPeer &peer, const FrameRingRegisterRequest &r, std::chrono::steady_clock::time_point now, FrameResourceImporter &importer) { + if (!peer.valid() || !valid_frame_ring_request(r)) { + return {}; + } const auto owner = owner_for(r); const auto display = store_.authorize_temporary_display_owner(owner.display, owner.capability, now); - if (!display || display->generation != r.display_generation) return {FrameWireStatus::Unauthorized, {}}; + if (!display || display->generation != r.display_generation) { + return {FrameWireStatus::Unauthorized, {}}; + } reap(now); const auto old = entries_.find(r.display_id); if (old != entries_.end()) { // A new process must reclaim a fresh lease before binding. Otherwise a // delayed request from the previous process could replace its successor. - if (old->second.peer != peer) return {FrameWireStatus::Unauthorized, {}}; + if (old->second.peer != peer) { + return {FrameWireStatus::Unauthorized, {}}; + } if (r.client_cookie <= old->second.request.client_cookie) { - if (r.client_cookie == old->second.request.client_cookie && old->second.reply.ring_generation && - same_frame_ring_request(old->second.request, r)) { + if (r.client_cookie == old->second.request.client_cookie && old->second.reply.ring_generation && same_frame_ring_request(old->second.request, r)) { return {FrameWireStatus::Success, old->second.reply}; } return {FrameWireStatus::StaleGeneration, {}}; @@ -47,8 +55,10 @@ namespace virtual_display::driver { const auto previous = entry->second; entry->second = {peer, r, {}}; std::shared_ptr resources; - try { resources = importer.import(peer, r); } - catch (...) { /* native partial imports use RAII; fail closed */ } + try { + resources = importer.import(peer, r); + } catch (...) { /* native partial imports use RAII; fail closed */ + } if (!resources) { // A failed replacement retires the old ring, rather than leaving its old // identity active behind the newer tombstone. @@ -69,15 +79,20 @@ namespace virtual_display::driver { } std::optional FrameRingServer::query_target( - const FrameRequestPeer &peer, const FrameTransportTargetRequest &request, + const FrameRequestPeer &peer, + const FrameTransportTargetRequest &request, const std::chrono::steady_clock::time_point now ) const { - if (!peer.valid() || !valid_frame_transport_target_request(request)) return {}; + if (!peer.valid() || !valid_frame_transport_target_request(request)) { + return {}; + } LeaseDisplayRequest owner {}; owner.lease_id = request.lease_id; owner.display_id = request.display_id; const auto display = store_.authorize_temporary_display_owner(owner, request.owner_capability, now); - if (!display || display->pending_departure || !display->generation) return {}; + if (!display || display->pending_departure || !display->generation) { + return {}; + } FrameTransportTarget target {}; target.lease_id = display->lease_id; target.display_id = display->display_id; @@ -87,37 +102,42 @@ namespace virtual_display::driver { return target; } - FrameWireStatus FrameRingServer::clear_ring(const FrameRequestPeer &peer, const FrameRingClearRequest &r, - std::chrono::steady_clock::time_point now) { - if (!peer.valid() || r.reserved || r.flags > 1 || - !is_valid_api_namespace(r.identity.api_namespace) || r.identity.version != kFrameRingWireVersion || - r.identity.size != sizeof(FrameRingReply) || !r.identity.client_cookie || !r.identity.display_generation || - (r.flags == 1 ? r.identity.ring_generation != 0 : r.identity.ring_generation == 0)) { + FrameWireStatus FrameRingServer::clear_ring(const FrameRequestPeer &peer, const FrameRingClearRequest &r, std::chrono::steady_clock::time_point now) { + if (!peer.valid() || r.reserved || r.flags > 1 || !is_valid_api_namespace(r.identity.api_namespace) || r.identity.version != kFrameRingWireVersion || r.identity.size != sizeof(FrameRingReply) || !r.identity.client_cookie || !r.identity.display_generation || (r.flags == 1 ? r.identity.ring_generation != 0 : r.identity.ring_generation == 0)) { return FrameWireStatus::InvalidInput; } FrameRingRegisterRequest cancel {}; - cancel.lease_id = r.lease_id; cancel.display_id = r.display_id; + cancel.lease_id = r.lease_id; + cancel.display_id = r.display_id; cancel.display_generation = r.identity.display_generation; - cancel.client_cookie = r.identity.client_cookie; cancel.owner_capability = r.owner_capability; + cancel.client_cookie = r.identity.client_cookie; + cancel.owner_capability = r.owner_capability; const auto owner = owner_for(cancel); const auto display = store_.authorize_temporary_display_owner(owner.display, owner.capability, now); - if (!display || display->generation != cancel.display_generation) return FrameWireStatus::Unauthorized; + if (!display || display->generation != cancel.display_generation) { + return FrameWireStatus::Unauthorized; + } reap(now); auto i = entries_.find(r.display_id); if (i == entries_.end()) { - if (r.flags != 1) return FrameWireStatus::StaleGeneration; + if (r.flags != 1) { + return FrameWireStatus::StaleGeneration; + } // Cancellation may win the race against registration. The tombstone // consumes the cookie even when no handles were ever imported. entries_.emplace(r.display_id, Entry {peer, cancel, {}}); return FrameWireStatus::Success; } auto &entry = i->second; - if (entry.peer != peer || entry.request.owner_capability != r.owner_capability || - entry.request.lease_id != r.lease_id) return FrameWireStatus::Unauthorized; - if (r.identity.client_cookie < entry.request.client_cookie || - r.identity.display_generation != entry.request.display_generation) return FrameWireStatus::StaleGeneration; - if (r.flags == 0 && (r.identity.client_cookie != entry.request.client_cookie || - r.identity.ring_generation != entry.reply.ring_generation)) return FrameWireStatus::StaleGeneration; + if (entry.peer != peer || entry.request.owner_capability != r.owner_capability || entry.request.lease_id != r.lease_id) { + return FrameWireStatus::Unauthorized; + } + if (r.identity.client_cookie < entry.request.client_cookie || r.identity.display_generation != entry.request.display_generation) { + return FrameWireStatus::StaleGeneration; + } + if (r.flags == 0 && (r.identity.client_cookie != entry.request.client_cookie || r.identity.ring_generation != entry.reply.ring_generation)) { + return FrameWireStatus::StaleGeneration; + } if (entry.reply.ring_generation) { rings_.retire_ring(r.display_id, entry.request.display_generation, entry.reply.ring_generation); } @@ -134,7 +154,8 @@ namespace virtual_display::driver { const auto display = store_.authorize_temporary_display_owner(owner.display, owner.capability, now); if (!display || display->generation != i->second.request.display_generation) { rings_.retire_ring(i->first, i->second.request.display_generation, i->second.reply.ring_generation); - i = entries_.erase(i); ++count; + i = entries_.erase(i); + ++count; } else { if (i->second.reply.ring_generation) { const auto snapshot = rings_.snapshot(i->first, i->second.request.display_generation, now); @@ -147,12 +168,15 @@ namespace virtual_display::driver { } return count; } + void FrameRingServer::reset() { - for (const auto &[id, entry]: entries_) { + for (const auto &[id, entry] : entries_) { rings_.retire_ring(id, entry.request.display_generation, entry.reply.ring_generation); } // Retain high-water tombstones while the same display/lease remains live. // Delayed requests after a reset cannot resurrect a retired generation. - for (auto &[id, entry]: entries_) entry.reply = {}; + for (auto &[id, entry] : entries_) { + entry.reply = {}; + } } -} +} // namespace virtual_display::driver diff --git a/src/driver/frame_transport_protocol.cpp b/src/driver/frame_transport_protocol.cpp index 14e27bb..277cd56 100644 --- a/src/driver/frame_transport_protocol.cpp +++ b/src/driver/frame_transport_protocol.cpp @@ -4,11 +4,12 @@ namespace virtual_display::driver { bool valid_frame_transport_target_request(const FrameTransportTargetRequest &r) { return is_valid_api_namespace(r.api_namespace) && r.version == kFrameRingWireVersion && r.size == sizeof(r) && r.lease_id && r.display_id && - std::any_of(r.owner_capability.bytes.begin(), r.owner_capability.bytes.end(), [](auto byte) { return byte != 0; }); + std::any_of(r.owner_capability.bytes.begin(), r.owner_capability.bytes.end(), [](auto byte) { + return byte != 0; + }); } - bool valid_frame_transport_target(const FrameTransportTarget &target, - const FrameTransportTargetRequest &request) { + bool valid_frame_transport_target(const FrameTransportTarget &target, const FrameTransportTargetRequest &request) { return is_valid_api_namespace(target.api_namespace) && target.version == kFrameRingWireVersion && target.size == sizeof(target) && target.lease_id == request.lease_id && target.display_id == request.display_id && target.display_generation != 0 && @@ -19,13 +20,7 @@ namespace virtual_display::driver { } bool valid_frame_ring_request(const FrameRingRegisterRequest &r) { - if (!is_valid_api_namespace(r.api_namespace) || r.version != kFrameRingWireVersion || - r.size != sizeof(r) || !r.lease_id || !r.display_id || !r.display_generation || - !r.client_cookie || r.width < kMinWidth || r.width > kMaxWidth || - r.height < kMinHeight || r.height > kMaxHeight || - r.slot_count != kFrameRingSlotCount || r.metadata_bytes != kFrameRingMetadataBytes || - !r.metadata_handle || !r.event_handle || r.reserved || - !((r.format == 87 && r.color_space == 0) || (r.format == 10 && r.color_space == 1))) { + if (!is_valid_api_namespace(r.api_namespace) || r.version != kFrameRingWireVersion || r.size != sizeof(r) || !r.lease_id || !r.display_id || !r.display_generation || !r.client_cookie || r.width < kMinWidth || r.width > kMaxWidth || r.height < kMinHeight || r.height > kMaxHeight || r.slot_count != kFrameRingSlotCount || r.metadata_bytes != kFrameRingMetadataBytes || !r.metadata_handle || !r.event_handle || r.reserved || !((r.format == 87 && r.color_space == 0) || (r.format == 10 && r.color_space == 1))) { return false; } std::array handles {}; @@ -54,4 +49,4 @@ namespace virtual_display::driver { reply.size == sizeof(reply) && reply.client_cookie == request.client_cookie && reply.display_generation == request.display_generation && reply.ring_generation != 0; } -} +} // namespace virtual_display::driver diff --git a/src/driver/include/virtual_display/driver/control_protocol.h b/src/driver/include/virtual_display/driver/control_protocol.h index 7d3a176..58267ad 100644 --- a/src/driver/include/virtual_display/driver/control_protocol.h +++ b/src/driver/include/virtual_display/driver/control_protocol.h @@ -404,11 +404,13 @@ namespace virtual_display::driver { std::string_view display_name {}; ValidatedCreateTemporaryDisplay() = default; + ValidatedCreateTemporaryDisplay(const ValidatedCreateTemporaryDisplay &other): request {other.request}, effective_timeout_ms {other.effective_timeout_ms} { rebind_display_name(other.display_name.size()); } + ValidatedCreateTemporaryDisplay &operator=(const ValidatedCreateTemporaryDisplay &other) { if (this != &other) { request = other.request; @@ -417,11 +419,13 @@ namespace virtual_display::driver { } return *this; } + ValidatedCreateTemporaryDisplay(ValidatedCreateTemporaryDisplay &&other) noexcept: request {other.request}, effective_timeout_ms {other.effective_timeout_ms} { rebind_display_name(other.display_name.size()); } + ValidatedCreateTemporaryDisplay &operator=(ValidatedCreateTemporaryDisplay &&other) noexcept { if (this != &other) { request = other.request; diff --git a/src/driver/include/virtual_display/driver/frame_ring_lifetime.h b/src/driver/include/virtual_display/driver/frame_ring_lifetime.h index 7fb22bb..9475673 100644 --- a/src/driver/include/virtual_display/driver/frame_ring_lifetime.h +++ b/src/driver/include/virtual_display/driver/frame_ring_lifetime.h @@ -2,11 +2,11 @@ #include "virtual_display/driver/lease_store.h" +#include +#include #include #include -#include #include -#include #include namespace virtual_display::driver { @@ -38,9 +38,7 @@ namespace virtual_display::driver { auto current = sequence.load(std::memory_order_relaxed); constexpr auto last_valid = (std::numeric_limits::max)() - 1; while (current < last_valid) { - if (sequence.compare_exchange_weak(current, current + 1, - std::memory_order_relaxed, - std::memory_order_relaxed)) { + if (sequence.compare_exchange_weak(current, current + 1, std::memory_order_relaxed, std::memory_order_relaxed)) { out = current + 1; return true; } @@ -87,7 +85,9 @@ namespace virtual_display::driver { } void retire_publication() const { - if (publication) publication->disable(); + if (publication) { + publication->disable(); + } } }; @@ -96,9 +96,10 @@ namespace virtual_display::driver { // key, while a retired ring returns the slot to producer key 0 and cannot // expose it to a consumer after clear/replacement has returned. template - bool release_unpublished_slot(const FrameRingSnapshot &snapshot, const std::uint64_t acquired_key, - Release &&release) { - if (!snapshot.publication) return false; + bool release_unpublished_slot(const FrameRingSnapshot &snapshot, const std::uint64_t acquired_key, Release &&release) { + if (!snapshot.publication) { + return false; + } std::lock_guard lock {snapshot.publication->mutex}; const auto release_key = snapshot.can_publish() ? acquired_key : 0; return std::forward(release)(release_key); @@ -145,6 +146,7 @@ namespace virtual_display::driver { FrameRingOwner owner {}; FrameRingSnapshot snapshot {}; }; + const DisplayStore &store_; std::map rings_ {}; // Deliberately not reset by reset(): a late clear/error cannot match a later diff --git a/src/driver/include/virtual_display/driver/frame_ring_server.h b/src/driver/include/virtual_display/driver/frame_ring_server.h index 35229af..2f8cb60 100644 --- a/src/driver/include/virtual_display/driver/frame_ring_server.h +++ b/src/driver/include/virtual_display/driver/frame_ring_server.h @@ -10,7 +10,10 @@ namespace virtual_display::driver { std::uint64_t process_id {}; std::uint64_t process_start {}; friend bool operator==(const FrameRequestPeer &, const FrameRequestPeer &) = default; - bool valid() const { return process_id != 0 && process_start != 0; } + + bool valid() const { + return process_id != 0 && process_start != 0; + } }; class FrameResourceImporter { @@ -20,10 +23,19 @@ namespace virtual_display::driver { // objects and their device/geometry/header, and return only owned resources. // Partial failure destroys local duplicates; source handles stay caller-owned. virtual std::shared_ptr import( - const FrameRequestPeer &peer, const FrameRingRegisterRequest &request) = 0; + const FrameRequestPeer &peer, + const FrameRingRegisterRequest &request + ) = 0; + }; + + enum class FrameWireStatus { + Success, + InvalidInput, + Unauthorized, + ImportFailed, + StaleGeneration }; - enum class FrameWireStatus { Success, InvalidInput, Unauthorized, ImportFailed, StaleGeneration }; struct FrameWireResult { FrameWireStatus status {FrameWireStatus::InvalidInput}; FrameRingReply reply {}; @@ -37,22 +49,29 @@ namespace virtual_display::driver { public: FrameRingServer(const DisplayStore &store, FrameRingLifetime &rings, FrameResourceImporter &importer); ~FrameRingServer(); - FrameWireResult register_ring(const FrameRequestPeer &peer, const FrameRingRegisterRequest &request, - std::chrono::steady_clock::time_point now); - FrameWireResult register_ring(const FrameRequestPeer &peer, const FrameRingRegisterRequest &request, - std::chrono::steady_clock::time_point now, FrameResourceImporter &importer); + FrameWireResult register_ring(const FrameRequestPeer &peer, const FrameRingRegisterRequest &request, std::chrono::steady_clock::time_point now); + FrameWireResult register_ring(const FrameRequestPeer &peer, const FrameRingRegisterRequest &request, std::chrono::steady_clock::time_point now, FrameResourceImporter &importer); std::optional query_target( - const FrameRequestPeer &peer, const FrameTransportTargetRequest &request, + const FrameRequestPeer &peer, + const FrameTransportTargetRequest &request, std::chrono::steady_clock::time_point now ) const; - FrameWireStatus clear_ring(const FrameRequestPeer &peer, const FrameRingClearRequest &request, - std::chrono::steady_clock::time_point now); + FrameWireStatus clear_ring(const FrameRequestPeer &peer, const FrameRingClearRequest &request, std::chrono::steady_clock::time_point now); std::size_t reap(std::chrono::steady_clock::time_point now); // Retires resources and preserves live-lease cancellation tombstones. void reset(); - std::size_t size() const { return entries_.size(); } + + std::size_t size() const { + return entries_.size(); + } + private: - struct Entry { FrameRequestPeer peer; FrameRingRegisterRequest request; FrameRingReply reply; }; + struct Entry { + FrameRequestPeer peer; + FrameRingRegisterRequest request; + FrameRingReply reply; + }; + // Entry survives clear as a high-water tombstone until lease/display expiry. // client_cookie must increase within one authenticated process and lease. const DisplayStore &store_; @@ -60,4 +79,4 @@ namespace virtual_display::driver { FrameResourceImporter &importer_; std::map entries_; }; -} +} // namespace virtual_display::driver diff --git a/src/driver/include/virtual_display/driver/frame_transport_protocol.h b/src/driver/include/virtual_display/driver/frame_transport_protocol.h index 1ea5648..0236e47 100644 --- a/src/driver/include/virtual_display/driver/frame_transport_protocol.h +++ b/src/driver/include/virtual_display/driver/frame_transport_protocol.h @@ -49,8 +49,8 @@ namespace virtual_display::driver { AdapterLuid adapter_luid {}; std::uint32_t width {}; std::uint32_t height {}; - std::uint32_t format {}; // DXGI_FORMAT_B8G8R8A8_UNORM or R16G16B16A16_FLOAT - std::uint32_t color_space {}; // P709 gamma 2.2 or linear scRGB, respectively + std::uint32_t format {}; // DXGI_FORMAT_B8G8R8A8_UNORM or R16G16B16A16_FLOAT + std::uint32_t color_space {}; // P709 gamma 2.2 or linear scRGB, respectively std::uint32_t slot_count {kFrameRingSlotCount}; std::uint32_t metadata_bytes {kFrameRingMetadataBytes}; // Values belong to the authenticated requestor's handle table. Never close @@ -75,7 +75,7 @@ namespace virtual_display::driver { std::uint64_t lease_id {}; std::uint64_t display_id {}; OwnerCapability owner_capability {}; - std::uint32_t flags {}; // 1: cancel an unacknowledged client_cookie, ring_generation must be 0 + std::uint32_t flags {}; // 1: cancel an unacknowledged client_cookie, ring_generation must be 0 std::uint32_t reserved {}; }; @@ -87,10 +87,11 @@ namespace virtual_display::driver { std::uint64_t client_cookie {}; std::uint64_t display_generation {}; std::uint64_t ring_generation {}; - std::uint64_t sequence {}; // starts at 1; retire before uint64 overflow - std::uint64_t acquired_qpc {}; // acquisition timestamp, never scan-out QPC + std::uint64_t sequence {}; // starts at 1; retire before uint64 overflow + std::uint64_t acquired_qpc {}; // acquisition timestamp, never scan-out QPC std::uint64_t reserved {}; }; + struct alignas(8) FrameRingMetadata { Guid api_namespace {kApiNamespaceGuid}; std::uint32_t version {kFrameRingWireVersion}; @@ -113,8 +114,7 @@ namespace virtual_display::driver { bool valid_frame_ring_request(const FrameRingRegisterRequest &request); bool valid_frame_transport_target_request(const FrameTransportTargetRequest &request); - bool valid_frame_transport_target(const FrameTransportTarget &target, - const FrameTransportTargetRequest &request); + bool valid_frame_transport_target(const FrameTransportTarget &target, const FrameTransportTargetRequest &request); bool same_frame_ring_request(const FrameRingRegisterRequest &a, const FrameRingRegisterRequest &b); bool valid_frame_ring_reply(const FrameRingReply &reply, const FrameRingRegisterRequest &request); -} // namespace virtual_display::driver +} // namespace virtual_display::driver diff --git a/src/driver/include/virtual_display/driver/linux_control_client.h b/src/driver/include/virtual_display/driver/linux_control_client.h index 4b0f458..0425173 100644 --- a/src/driver/include/virtual_display/driver/linux_control_client.h +++ b/src/driver/include/virtual_display/driver/linux_control_client.h @@ -2,10 +2,10 @@ #if defined(__linux__) -#include -#include -#include -#include + #include + #include + #include + #include namespace virtual_display::driver { inline constexpr std::string_view kDefaultLinuxControlSocketPath = "/run/vibeshine/vkms-control.sock"; diff --git a/src/driver/include/virtual_display/driver/windows_control_client.h b/src/driver/include/virtual_display/driver/windows_control_client.h index 2db4a3f..c673847 100644 --- a/src/driver/include/virtual_display/driver/windows_control_client.h +++ b/src/driver/include/virtual_display/driver/windows_control_client.h @@ -5,11 +5,10 @@ #ifdef _WIN32 -#include - -#include -#include -#include + #include + #include + #include + #include namespace virtual_display::driver { class WindowsControlTransport final: public ControlTransport { diff --git a/src/driver/include/virtual_display/driver/windows_control_protocol.h b/src/driver/include/virtual_display/driver/windows_control_protocol.h index 0599d00..ba43520 100644 --- a/src/driver/include/virtual_display/driver/windows_control_protocol.h +++ b/src/driver/include/virtual_display/driver/windows_control_protocol.h @@ -4,8 +4,8 @@ #ifdef _WIN32 -#include -#include + #include + #include // Windows-facing adapter for the clean-room protocol. The underlying request // structs intentionally stay platform-neutral so they can be exhaustively tested @@ -16,16 +16,14 @@ namespace virtual_display::driver { guid.data1, guid.data2, guid.data3, - { - guid.data4[0], - guid.data4[1], - guid.data4[2], - guid.data4[3], - guid.data4[4], - guid.data4[5], - guid.data4[6], - guid.data4[7] - } + {guid.data4[0], + guid.data4[1], + guid.data4[2], + guid.data4[3], + guid.data4[4], + guid.data4[5], + guid.data4[6], + guid.data4[7]} }; } @@ -34,16 +32,14 @@ namespace virtual_display::driver { guid.Data1, guid.Data2, guid.Data3, - { - guid.Data4[0], - guid.Data4[1], - guid.Data4[2], - guid.Data4[3], - guid.Data4[4], - guid.Data4[5], - guid.Data4[6], - guid.Data4[7] - } + {guid.Data4[0], + guid.Data4[1], + guid.Data4[2], + guid.Data4[3], + guid.Data4[4], + guid.Data4[5], + guid.Data4[6], + guid.Data4[7]} }; } diff --git a/src/driver/include/virtual_display/driver/windows_frame_importer.h b/src/driver/include/virtual_display/driver/windows_frame_importer.h index 7902017..7c93d18 100644 --- a/src/driver/include/virtual_display/driver/windows_frame_importer.h +++ b/src/driver/include/virtual_display/driver/windows_frame_importer.h @@ -1,10 +1,10 @@ #pragma once #include "virtual_display/driver/frame_ring_server.h" #ifdef _WIN32 -#include -#include -#include -#include + #include + #include + #include + #include namespace virtual_display::driver { // Native request adapter must supply WdfRequestGetRequestorProcessId(request), @@ -16,16 +16,28 @@ namespace virtual_display::driver { class WindowsImportedFrameRing final: public FrameRingResources { public: ~WindowsImportedFrameRing() override; + [[nodiscard]] HANDLE texture_handle(std::size_t slot) const { return slot < kFrameRingSlotCount ? handles_[slot] : nullptr; } - [[nodiscard]] const FrameRingRegisterRequest &request() const { return request_; } - [[nodiscard]] FrameRingMetadata *metadata_view() const { return metadata; } - [[nodiscard]] HANDLE event_handle() const { return event; } + + [[nodiscard]] const FrameRingRegisterRequest &request() const { + return request_; + } + + [[nodiscard]] FrameRingMetadata *metadata_view() const { + return metadata; + } + + [[nodiscard]] HANDLE event_handle() const { + return event; + } + std::array, kFrameRingSlotCount> textures; std::array, kFrameRingSlotCount> mutexes; FrameRingMetadata *metadata {}; HANDLE event {}; + private: friend class WindowsFrameImporter; FrameRingRegisterRequest request_ {}; @@ -37,10 +49,10 @@ namespace virtual_display::driver { public: WindowsFrameImporter() = default; explicit WindowsFrameImporter(ID3D11Device1 *device); - std::shared_ptr import(const FrameRequestPeer &peer, - const FrameRingRegisterRequest &request) override; + std::shared_ptr import(const FrameRequestPeer &peer, const FrameRingRegisterRequest &request) override; + private: Microsoft::WRL::ComPtr device_; }; -} +} // namespace virtual_display::driver #endif diff --git a/src/driver/ioctl_dispatcher.cpp b/src/driver/ioctl_dispatcher.cpp index aae460c..5a8d5a1 100644 --- a/src/driver/ioctl_dispatcher.cpp +++ b/src/driver/ioctl_dispatcher.cpp @@ -79,208 +79,222 @@ namespace virtual_display::driver { std::size_t bytes_returned = 0; switch (ioctl_code) { - case kIoctlQueryFrameTransportCapabilities: { - if (input_size != 0) { - return {IoctlStatus::InvalidInputBuffer, 0, {}}; - } - FrameTransportCapabilities capabilities {}; + case kIoctlQueryFrameTransportCapabilities: + { + if (input_size != 0) { + return {IoctlStatus::InvalidInputBuffer, 0, {}}; + } + FrameTransportCapabilities capabilities {}; #if defined(VDD_ENABLE_FRAME_TRANSPORT) && defined(_WIN32) - capabilities.capabilities = kFrameTransportCapabilityKeyedMutexRing; - capabilities.max_ring_slots = kFrameRingSlotCount; + capabilities.capabilities = kFrameTransportCapabilityKeyedMutexRing; + capabilities.max_ring_slots = kFrameRingSlotCount; #endif - if (!write_output(output, output_size, capabilities, bytes_returned)) { - return {IoctlStatus::InvalidOutputBuffer, 0, {}}; + if (!write_output(output, output_size, capabilities, bytes_returned)) { + return {IoctlStatus::InvalidOutputBuffer, 0, {}}; + } + return {IoctlStatus::Success, bytes_returned, {}}; } - return {IoctlStatus::Success, bytes_returned, {}}; - } - case kIoctlGetProtocolVersion: { - ProtocolVersion version {}; - if (!write_output(output, output_size, version, bytes_returned)) { - return {IoctlStatus::InvalidOutputBuffer, 0, {}}; + case kIoctlGetProtocolVersion: + { + ProtocolVersion version {}; + if (!write_output(output, output_size, version, bytes_returned)) { + return {IoctlStatus::InvalidOutputBuffer, 0, {}}; + } + + return {IoctlStatus::Success, bytes_returned, {}}; } - return {IoctlStatus::Success, bytes_returned, {}}; - } + case kIoctlCreateTemporaryDisplay: + { + CreateTemporaryDisplayRequest request {}; + if (!read_input(input, input_size, request)) { + return {IoctlStatus::InvalidInputBuffer, 0, {}}; + } - case kIoctlCreateTemporaryDisplay: { - CreateTemporaryDisplayRequest request {}; - if (!read_input(input, input_size, request)) { - return {IoctlStatus::InvalidInputBuffer, 0, {}}; - } + if (!output || output_size < sizeof(CreateTemporaryDisplayResult)) { + return {IoctlStatus::InvalidOutputBuffer, 0, {}}; + } - if (!output || output_size < sizeof(CreateTemporaryDisplayResult)) { - return {IoctlStatus::InvalidOutputBuffer, 0, {}}; - } + auto created = controller_.create_temporary_display(request, now, controller_lock); + if (!created.status.ok()) { + return result_from_controller(created.status); + } - auto created = controller_.create_temporary_display(request, now, controller_lock); - if (!created.status.ok()) { - return result_from_controller(created.status); - } - - (void) write_output(output, output_size, created.result, bytes_returned); - - return {IoctlStatus::Success, bytes_returned, {}}; - } + (void) write_output(output, output_size, created.result, bytes_returned); - case kIoctlRemoveTemporaryDisplay: { - LeaseDisplayRequest request {}; - if (!read_input(input, input_size, request)) { - return {IoctlStatus::InvalidInputBuffer, 0, {}}; + return {IoctlStatus::Success, bytes_returned, {}}; } - return result_from_controller(controller_.remove_temporary_display(request, controller_lock)); - } + case kIoctlRemoveTemporaryDisplay: + { + LeaseDisplayRequest request {}; + if (!read_input(input, input_size, request)) { + return {IoctlStatus::InvalidInputBuffer, 0, {}}; + } - case kIoctlFeedLease: { - LeaseRequest request {}; - if (!read_input(input, input_size, request)) { - return {IoctlStatus::InvalidInputBuffer, 0, {}}; + return result_from_controller(controller_.remove_temporary_display(request, controller_lock)); } - return result_from_controller(controller_.feed_lease(request, now)); - } + case kIoctlFeedLease: + { + LeaseRequest request {}; + if (!read_input(input, input_size, request)) { + return {IoctlStatus::InvalidInputBuffer, 0, {}}; + } - case kIoctlReleaseLease: { - LeaseRequest request {}; - if (!read_input(input, input_size, request)) { - return {IoctlStatus::InvalidInputBuffer, 0, {}}; + return result_from_controller(controller_.feed_lease(request, now)); } - return result_from_controller(controller_.release_lease(request, controller_lock)); - } + case kIoctlReleaseLease: + { + LeaseRequest request {}; + if (!read_input(input, input_size, request)) { + return {IoctlStatus::InvalidInputBuffer, 0, {}}; + } - case kIoctlQueryLease: { - LeaseRequest request {}; - if (!read_input(input, input_size, request)) { - return {IoctlStatus::InvalidInputBuffer, 0, {}}; + return result_from_controller(controller_.release_lease(request, controller_lock)); } - if (const auto validation = validate_lease_request(request); - validation != ValidationError::None) { - return {IoctlStatus::InvalidRequest, 0, {StoreError::ValidationFailed, validation, BackendError::None}}; - } + case kIoctlQueryLease: + { + LeaseRequest request {}; + if (!read_input(input, input_size, request)) { + return {IoctlStatus::InvalidInputBuffer, 0, {}}; + } - const auto query = controller_.query_lease(request.lease_id, now); - if (!write_output(output, output_size, query, bytes_returned)) { - return {IoctlStatus::InvalidOutputBuffer, 0, {}}; - } + if (const auto validation = validate_lease_request(request); validation != ValidationError::None) { + return {IoctlStatus::InvalidRequest, 0, {StoreError::ValidationFailed, validation, BackendError::None}}; + } - return {IoctlStatus::Success, bytes_returned, {}}; - } + const auto query = controller_.query_lease(request.lease_id, now); + if (!write_output(output, output_size, query, bytes_returned)) { + return {IoctlStatus::InvalidOutputBuffer, 0, {}}; + } - case kIoctlSetPermanentDisplayCount: { - PermanentDisplayCountRequest request {}; - if (!read_input(input, input_size, request)) { - return {IoctlStatus::InvalidInputBuffer, 0, {}}; + return {IoctlStatus::Success, bytes_returned, {}}; } - if (!output || output_size < sizeof(PermanentDisplayCountResult)) { - return {IoctlStatus::InvalidOutputBuffer, 0, {}}; - } + case kIoctlSetPermanentDisplayCount: + { + PermanentDisplayCountRequest request {}; + if (!read_input(input, input_size, request)) { + return {IoctlStatus::InvalidInputBuffer, 0, {}}; + } - const auto status = controller_.set_permanent_display_count(request, controller_lock); - if (!status.ok()) { - return result_from_controller(status); - } + if (!output || output_size < sizeof(PermanentDisplayCountResult)) { + return {IoctlStatus::InvalidOutputBuffer, 0, {}}; + } - const auto result = controller_.query_permanent_display_count(); - (void) write_output(output, output_size, result, bytes_returned); + const auto status = controller_.set_permanent_display_count(request, controller_lock); + if (!status.ok()) { + return result_from_controller(status); + } - return {IoctlStatus::Success, bytes_returned, {}}; - } + const auto result = controller_.query_permanent_display_count(); + (void) write_output(output, output_size, result, bytes_returned); - case kIoctlQueryPermanentDisplayCount: { - const auto result = controller_.query_permanent_display_count(); - if (!write_output(output, output_size, result, bytes_returned)) { - return {IoctlStatus::InvalidOutputBuffer, 0, {}}; + return {IoctlStatus::Success, bytes_returned, {}}; } - return {IoctlStatus::Success, bytes_returned, {}}; - } + case kIoctlQueryPermanentDisplayCount: + { + const auto result = controller_.query_permanent_display_count(); + if (!write_output(output, output_size, result, bytes_returned)) { + return {IoctlStatus::InvalidOutputBuffer, 0, {}}; + } - case kIoctlQueryDisplayState: { - const auto result = controller_.query_display_state(); - if (!write_output(output, output_size, result, bytes_returned)) { - return {IoctlStatus::InvalidOutputBuffer, 0, {}}; + return {IoctlStatus::Success, bytes_returned, {}}; } - return {IoctlStatus::Success, bytes_returned, {}}; - } + case kIoctlQueryDisplayState: + { + const auto result = controller_.query_display_state(); + if (!write_output(output, output_size, result, bytes_returned)) { + return {IoctlStatus::InvalidOutputBuffer, 0, {}}; + } - case kIoctlSetDisplayManifest: { - DisplayManifest manifest {}; - if (!read_input(input, input_size, manifest)) { - return {IoctlStatus::InvalidInputBuffer, 0, {}}; + return {IoctlStatus::Success, bytes_returned, {}}; } - if (!output || output_size < sizeof(DisplayManifest)) { - return {IoctlStatus::InvalidOutputBuffer, 0, {}}; - } + case kIoctlSetDisplayManifest: + { + DisplayManifest manifest {}; + if (!read_input(input, input_size, manifest)) { + return {IoctlStatus::InvalidInputBuffer, 0, {}}; + } - const auto status = controller_.apply_display_manifest(manifest, controller_lock); - if (!status.ok()) { - return result_from_controller(status); - } + if (!output || output_size < sizeof(DisplayManifest)) { + return {IoctlStatus::InvalidOutputBuffer, 0, {}}; + } - (void) write_output(output, output_size, controller_.query_display_manifest(), bytes_returned); + const auto status = controller_.apply_display_manifest(manifest, controller_lock); + if (!status.ok()) { + return result_from_controller(status); + } - return {IoctlStatus::Success, bytes_returned, {}}; - } + (void) write_output(output, output_size, controller_.query_display_manifest(), bytes_returned); - case kIoctlQueryDisplayManifest: { - if (!write_output(output, output_size, controller_.query_display_manifest(), bytes_returned)) { - return {IoctlStatus::InvalidOutputBuffer, 0, {}}; + return {IoctlStatus::Success, bytes_returned, {}}; } - return {IoctlStatus::Success, bytes_returned, {}}; - } + case kIoctlQueryDisplayManifest: + { + if (!write_output(output, output_size, controller_.query_display_manifest(), bytes_returned)) { + return {IoctlStatus::InvalidOutputBuffer, 0, {}}; + } - case kIoctlCreateTemporaryDisplayOwned: { - CreateTemporaryDisplayOwnedRequest request {}; - if (!read_input(input, input_size, request)) { - return {IoctlStatus::InvalidInputBuffer, 0, {}}; + return {IoctlStatus::Success, bytes_returned, {}}; } - if (!output || output_size < sizeof(CreateTemporaryDisplayResult)) { - return {IoctlStatus::InvalidOutputBuffer, 0, {}}; - } + case kIoctlCreateTemporaryDisplayOwned: + { + CreateTemporaryDisplayOwnedRequest request {}; + if (!read_input(input, input_size, request)) { + return {IoctlStatus::InvalidInputBuffer, 0, {}}; + } - auto created = controller_.create_temporary_display_owned(request, now, controller_lock); - if (!created.status.ok()) { - return result_from_controller(created.status); - } + if (!output || output_size < sizeof(CreateTemporaryDisplayResult)) { + return {IoctlStatus::InvalidOutputBuffer, 0, {}}; + } - (void) write_output(output, output_size, created.result, bytes_returned); - return {IoctlStatus::Success, bytes_returned, {}}; - } + auto created = controller_.create_temporary_display_owned(request, now, controller_lock); + if (!created.status.ok()) { + return result_from_controller(created.status); + } - case kIoctlReclaimTemporaryDisplay: { - ReclaimTemporaryDisplayRequest request {}; - if (!read_input(input, input_size, request)) { - return {IoctlStatus::InvalidInputBuffer, 0, {}}; + (void) write_output(output, output_size, created.result, bytes_returned); + return {IoctlStatus::Success, bytes_returned, {}}; } - if (!output || output_size < sizeof(ReclaimTemporaryDisplayResult)) { - return {IoctlStatus::InvalidOutputBuffer, 0, {}}; - } + case kIoctlReclaimTemporaryDisplay: + { + ReclaimTemporaryDisplayRequest request {}; + if (!read_input(input, input_size, request)) { + return {IoctlStatus::InvalidInputBuffer, 0, {}}; + } - auto reclaimed = controller_.reclaim_temporary_display(request, now, controller_lock); - if (!reclaimed.status.ok()) { - return result_from_controller(reclaimed.status); - } + if (!output || output_size < sizeof(ReclaimTemporaryDisplayResult)) { + return {IoctlStatus::InvalidOutputBuffer, 0, {}}; + } - (void) write_output(output, output_size, reclaimed.result, bytes_returned); - return {IoctlStatus::Success, bytes_returned, {}}; - } + auto reclaimed = controller_.reclaim_temporary_display(request, now, controller_lock); + if (!reclaimed.status.ok()) { + return result_from_controller(reclaimed.status); + } - case kIoctlSetRenderAdapter: { - SetRenderAdapterRequest request {}; - if (!read_input(input, input_size, request)) { - return {IoctlStatus::InvalidInputBuffer, 0, {}}; + (void) write_output(output, output_size, reclaimed.result, bytes_returned); + return {IoctlStatus::Success, bytes_returned, {}}; } - return result_from_controller(controller_.set_render_adapter(request, controller_lock)); - } + case kIoctlSetRenderAdapter: + { + SetRenderAdapterRequest request {}; + if (!read_input(input, input_size, request)) { + return {IoctlStatus::InvalidInputBuffer, 0, {}}; + } + + return result_from_controller(controller_.set_render_adapter(request, controller_lock)); + } default: return {IoctlStatus::InvalidIoctl, 0, {}}; diff --git a/src/driver/lease_store.cpp b/src/driver/lease_store.cpp index 06d78dc..e123ffe 100644 --- a/src/driver/lease_store.cpp +++ b/src/driver/lease_store.cpp @@ -39,8 +39,8 @@ namespace virtual_display::driver { ++index) { auto &profile = manifest.profiles[index]; profile.flags = kDisplayManifestProfileFlagHdrSupported | - kDisplayManifestProfileFlagRetainIdentity | - kDisplayManifestProfileFlagPermanentIdentity; + kDisplayManifestProfileFlagRetainIdentity | + kDisplayManifestProfileFlagPermanentIdentity; profile.connector_index = index; profile.display_id = permanent_display_id(index); profile.container_id = container_guid_from_display_id(profile.display_id); @@ -110,8 +110,7 @@ namespace virtual_display::driver { permanent_display_settings_, max_permanent_displays_ ); - if (initial_manifest && - validate_display_manifest(*initial_manifest, max_permanent_displays_) == ValidationError::None) { + if (initial_manifest && validate_display_manifest(*initial_manifest, max_permanent_displays_) == ValidationError::None) { (void) apply_display_manifest(*initial_manifest); } } @@ -151,8 +150,7 @@ namespace virtual_display::driver { const CreateTemporaryDisplayOwnedRequest &request, const std::chrono::steady_clock::time_point now ) { - if (const auto validation = validate_create_temporary_display_owned(request); - validation != ValidationError::None) { + if (const auto validation = validate_create_temporary_display_owned(request); validation != ValidationError::None) { return CreateStoreResult {validation_failure(validation), {}}; } return create_temporary_display_impl(request.display, &request.owner_capability, now); @@ -164,8 +162,7 @@ namespace virtual_display::driver { const std::chrono::steady_clock::time_point now ) { ValidatedCreateTemporaryDisplay validated {}; - if (const auto validation = validate_create_temporary_display(request, &validated); - validation != ValidationError::None) { + if (const auto validation = validate_create_temporary_display(request, &validated); validation != ValidationError::None) { return CreateStoreResult {validation_failure(validation), {}}; } @@ -178,13 +175,10 @@ namespace virtual_display::driver { } const auto lease = leases_by_id_.find(request.lease_id); - if (lease != leases_by_id_.end() && - (lease->second.expires_at <= now || lease_has_pending_departure(request.lease_id))) { + if (lease != leases_by_id_.end() && (lease->second.expires_at <= now || lease_has_pending_departure(request.lease_id))) { return CreateStoreResult {{StoreError::LeaseNotFound, ValidationError::None}, {}}; } - if (lease != leases_by_id_.end() && owner_capability && - lease->second.owner_capability && - !owner_capabilities_equal(*lease->second.owner_capability, *owner_capability)) { + if (lease != leases_by_id_.end() && owner_capability && lease->second.owner_capability && !owner_capabilities_equal(*lease->second.owner_capability, *owner_capability)) { return CreateStoreResult {{StoreError::LeaseNotFound, ValidationError::None}, {}}; } @@ -266,8 +260,7 @@ namespace virtual_display::driver { const ReclaimTemporaryDisplayRequest &request, const std::chrono::steady_clock::time_point now ) { - if (const auto validation = validate_reclaim_temporary_display(request); - validation != ValidationError::None) { + if (const auto validation = validate_reclaim_temporary_display(request); validation != ValidationError::None) { return ReclaimStoreResult {validation_failure(validation), {}}; } @@ -278,11 +271,7 @@ namespace virtual_display::driver { const auto old_lease_id = display->second.lease_id; auto lease = leases_by_id_.find(old_lease_id); - if (lease == leases_by_id_.end() || - lease->second.expires_at <= now || - lease_has_pending_departure(old_lease_id) || - !lease->second.owner_capability || - !owner_capabilities_equal(*lease->second.owner_capability, request.owner_capability)) { + if (lease == leases_by_id_.end() || lease->second.expires_at <= now || lease_has_pending_departure(old_lease_id) || !lease->second.owner_capability || !owner_capabilities_equal(*lease->second.owner_capability, request.owner_capability)) { return ReclaimStoreResult {{StoreError::LeaseNotFound, ValidationError::None}, {}}; } @@ -297,7 +286,7 @@ namespace virtual_display::driver { const auto capability = *lease->second.owner_capability; std::uint32_t display_count = 0; - for (auto &[_, record]: displays_by_id_) { + for (auto &[_, record] : displays_by_id_) { if (record.lease_id != old_lease_id) { continue; } @@ -330,8 +319,7 @@ namespace virtual_display::driver { const LeaseDisplayRequest &request, const RemoveTemporaryDisplayMode mode ) { - if (const auto validation = validate_lease_display_request(request); - validation != ValidationError::None) { + if (const auto validation = validate_lease_display_request(request); validation != ValidationError::None) { return validation_failure(validation); } @@ -359,11 +347,7 @@ namespace virtual_display::driver { } const auto display = displays_by_id_.find(request.display_id); const auto lease = leases_by_id_.find(request.lease_id); - if (display == displays_by_id_.end() || lease == leases_by_id_.end() || - display->second.lease_id != request.lease_id || display->second.pending_departure || - lease->second.expires_at <= now || display->second.expires_at <= now || - !lease->second.owner_capability || - !owner_capabilities_equal(*lease->second.owner_capability, owner_capability)) { + if (display == displays_by_id_.end() || lease == leases_by_id_.end() || display->second.lease_id != request.lease_id || display->second.pending_departure || lease->second.expires_at <= now || display->second.expires_at <= now || !lease->second.owner_capability || !owner_capabilities_equal(*lease->second.owner_capability, owner_capability)) { return std::nullopt; } return display->second; @@ -374,16 +358,12 @@ namespace virtual_display::driver { const std::uint64_t expected_generation, const OwnerCapability &owner_capability ) { - if (const auto validation = validate_lease_display_request(request); - validation != ValidationError::None) { + if (const auto validation = validate_lease_display_request(request); validation != ValidationError::None) { return validation_failure(validation); } const auto display = displays_by_id_.find(request.display_id); - if (display == displays_by_id_.end() || - display->second.lease_id != request.lease_id || - display->second.generation != expected_generation || - !display->second.pending_departure) { + if (display == displays_by_id_.end() || display->second.lease_id != request.lease_id || display->second.generation != expected_generation || !display->second.pending_departure) { return {StoreError::DisplayNotFound, ValidationError::None}; } @@ -391,9 +371,7 @@ namespace virtual_display::driver { // lease without a stored capability (plain create) cannot be // owner-verified and stays fail-closed. const auto lease = leases_by_id_.find(request.lease_id); - if (lease == leases_by_id_.end() || - !lease->second.owner_capability || - !owner_capabilities_equal(*lease->second.owner_capability, owner_capability)) { + if (lease == leases_by_id_.end() || !lease->second.owner_capability || !owner_capabilities_equal(*lease->second.owner_capability, owner_capability)) { return {StoreError::LeaseNotFound, ValidationError::None}; } @@ -405,8 +383,7 @@ namespace virtual_display::driver { } StoreResult DisplayStore::mark_temporary_display_pending_departure(const LeaseDisplayRequest &request) { - if (const auto validation = validate_lease_display_request(request); - validation != ValidationError::None) { + if (const auto validation = validate_lease_display_request(request); validation != ValidationError::None) { return validation_failure(validation); } @@ -423,8 +400,7 @@ namespace virtual_display::driver { const LeaseRequest &request, const std::chrono::steady_clock::time_point now ) { - if (const auto validation = validate_lease_request(request); - validation != ValidationError::None) { + if (const auto validation = validate_lease_request(request); validation != ValidationError::None) { return validation_failure(validation); } @@ -442,7 +418,7 @@ namespace virtual_display::driver { lease->second.timeout_ms = timeout_ms; lease->second.expires_at = expires_at; - for (auto &[_, display]: displays_by_id_) { + for (auto &[_, display] : displays_by_id_) { if (display.lease_id == request.lease_id && !display.pending_departure) { display.timeout_ms = timeout_ms; display.expires_at = expires_at; @@ -453,8 +429,7 @@ namespace virtual_display::driver { } StoreResult DisplayStore::release_lease(const LeaseRequest &request) { - if (const auto validation = validate_lease_request(request); - validation != ValidationError::None) { + if (const auto validation = validate_lease_request(request); validation != ValidationError::None) { return validation_failure(validation); } @@ -512,8 +487,7 @@ namespace virtual_display::driver { StoreResult DisplayStore::set_permanent_display_count(const PermanentDisplayCountRequest &request) { auto normalized = request; set_default_permanent_display_settings(normalized); - if (const auto validation = validate_permanent_display_count(normalized, max_permanent_displays_); - validation != ValidationError::None) { + if (const auto validation = validate_permanent_display_count(normalized, max_permanent_displays_); validation != ValidationError::None) { return validation_failure(validation); } @@ -521,8 +495,7 @@ namespace virtual_display::driver { } StoreResult DisplayStore::apply_display_manifest(const DisplayManifest &manifest) { - if (const auto validation = validate_display_manifest(manifest, max_permanent_displays_); - validation != ValidationError::None) { + if (const auto validation = validate_display_manifest(manifest, max_permanent_displays_); validation != ValidationError::None) { return validation_failure(validation); } @@ -592,7 +565,7 @@ namespace virtual_display::driver { std::vector DisplayStore::temporary_displays() const { std::vector displays; displays.reserve(displays_by_id_.size()); - for (const auto &[_, display]: displays_by_id_) { + for (const auto &[_, display] : displays_by_id_) { displays.push_back(display); } @@ -601,7 +574,7 @@ namespace virtual_display::driver { std::vector DisplayStore::temporary_displays_for_lease(const std::uint64_t lease_id) const { std::vector displays; - for (const auto &[_, display]: displays_by_id_) { + for (const auto &[_, display] : displays_by_id_) { if (display.lease_id == lease_id) { displays.push_back(display); } @@ -612,7 +585,7 @@ namespace virtual_display::driver { std::vector DisplayStore::pending_departure_temporary_displays() const { std::vector displays; - for (const auto &[_, display]: displays_by_id_) { + for (const auto &[_, display] : displays_by_id_) { if (display.pending_departure) { displays.push_back(display); } @@ -625,7 +598,7 @@ namespace virtual_display::driver { const std::chrono::steady_clock::time_point now ) const { std::vector displays; - for (const auto &[_, display]: displays_by_id_) { + for (const auto &[_, display] : displays_by_id_) { if (display.expires_at <= now) { displays.push_back(display); } @@ -684,8 +657,8 @@ namespace virtual_display::driver { displays_by_id_.end(), [&](const auto &entry) { const auto active_identity_display_id = entry.second.identity_display_id == 0 ? - entry.second.display_id : - entry.second.identity_display_id; + entry.second.display_id : + entry.second.identity_display_id; return product_code_from_display_id(active_identity_display_id) == candidate_product_code && serial_number_from_display_id(active_identity_display_id) == candidate_serial_number; } @@ -711,10 +684,7 @@ namespace virtual_display::driver { const bool retain_identity ) { if (retain_identity) { - if (const auto reservation = connector_reservations_by_display_id_.find(display_id); - reservation != connector_reservations_by_display_id_.end() && - is_temporary_connector_index(reservation->second) && - !connector_index_is_active(reservation->second)) { + if (const auto reservation = connector_reservations_by_display_id_.find(display_id); reservation != connector_reservations_by_display_id_.end() && is_temporary_connector_index(reservation->second) && !connector_index_is_active(reservation->second)) { return reservation->second; } } @@ -723,11 +693,7 @@ namespace virtual_display::driver { for (std::uint32_t connector_index = max_permanent_displays_; connector_index < connector_limit; ++connector_index) { - if (!connector_index_is_active(connector_index) && - !quarantined_connectors_.contains(connector_index) && - (retain_identity ? - !connector_index_is_reserved_for_other_display(connector_index, display_id) : - !connector_index_is_reserved(connector_index))) { + if (!connector_index_is_active(connector_index) && !quarantined_connectors_.contains(connector_index) && (retain_identity ? !connector_index_is_reserved_for_other_display(connector_index, display_id) : !connector_index_is_reserved(connector_index))) { return connector_index; } } @@ -735,8 +701,7 @@ namespace virtual_display::driver { for (std::uint32_t connector_index = max_permanent_displays_; connector_index < connector_limit; ++connector_index) { - if (!connector_index_is_active(connector_index) && - !quarantined_connectors_.contains(connector_index)) { + if (!connector_index_is_active(connector_index) && !quarantined_connectors_.contains(connector_index)) { remove_connector_reservation(connector_index, display_id); return connector_index; } diff --git a/src/driver/linux_control_client.cpp b/src/driver/linux_control_client.cpp index b5a3e9c..095f8ee 100644 --- a/src/driver/linux_control_client.cpp +++ b/src/driver/linux_control_client.cpp @@ -2,16 +2,16 @@ #if defined(__linux__) -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include namespace virtual_display::driver { namespace { @@ -21,8 +21,7 @@ namespace virtual_display::driver { return false; } const auto suffix = output_name.substr(prefix.size()); - if (suffix.size() > 10 || suffix.front() < '1' || suffix.front() > '9' || - !std::all_of(suffix.begin(), suffix.end(), [](const char digit) { + if (suffix.size() > 10 || suffix.front() < '1' || suffix.front() > '9' || !std::all_of(suffix.begin(), suffix.end(), [](const char digit) { return digit >= '0' && digit <= '9'; })) { return false; @@ -63,8 +62,7 @@ namespace virtual_display::driver { // A socket-activated one-shot broker can close immediately after // writing its reply. Consume queued data when POLLIN and POLLHUP // arrive together. - if ((descriptor.revents & events) != 0 || - (events == POLLIN && (descriptor.revents & POLLHUP) != 0)) { + if ((descriptor.revents & events) != 0 || (events == POLLIN && (descriptor.revents & POLLHUP) != 0)) { return WaitResult::Ready; } native_error = EIO; @@ -100,8 +98,7 @@ namespace virtual_display::driver { const std::string_view verb, const std::string_view output_name ) const { - if ((verb != "connect" && verb != "disconnect" && verb != "status") || - !valid_output_name(output_name) || socket_path_.empty()) { + if ((verb != "connect" && verb != "disconnect" && verb != "status") || !valid_output_name(output_name) || socket_path_.empty()) { return {LinuxControlStatus::InvalidRequest, std::nullopt, EINVAL, "invalid broker request"}; } @@ -109,8 +106,10 @@ namespace virtual_display::driver { if (fd < 0) { return {LinuxControlStatus::TransportFailed, std::nullopt, errno, std::strerror(errno)}; } + struct CloseFd { int value; + ~CloseFd() { close(value); } @@ -176,8 +175,7 @@ namespace virtual_display::driver { } else if (count < 0 && (errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK)) { continue; } else { - return {LinuxControlStatus::TransportFailed, std::nullopt, count < 0 ? errno : ECONNRESET, - count < 0 ? std::strerror(errno) : "broker closed without a complete response"}; + return {LinuxControlStatus::TransportFailed, std::nullopt, count < 0 ? errno : ECONNRESET, count < 0 ? std::strerror(errno) : "broker closed without a complete response"}; } const auto newline = response.find('\n'); @@ -217,10 +215,7 @@ namespace virtual_display::driver { // shortcut cannot prove that this UID owns an already-connected output. const auto result = request(connected ? "connect" : "disconnect", output_name); if (!result.ok() || result.connected != connected) { - return result.ok() - ? LinuxControlResult {LinuxControlStatus::ProtocolError, result.connected, EPROTO, - "broker acknowledged the wrong connector state"} - : result; + return result.ok() ? LinuxControlResult {LinuxControlStatus::ProtocolError, result.connected, EPROTO, "broker acknowledged the wrong connector state"} : result; } return result; } diff --git a/src/driver/probe_commands.cpp b/src/driver/probe_commands.cpp index c96b69e..a044f80 100644 --- a/src/driver/probe_commands.cpp +++ b/src/driver/probe_commands.cpp @@ -14,10 +14,8 @@ namespace virtual_display::driver { } std::uint32_t saturating_u32(const std::uint64_t value) { - return static_cast((std::min)( - value, - (std::numeric_limits::max)() - )); + return static_cast((std::min) (value, + (std::numeric_limits::max)())); } std::uint32_t refresh_millihz_from_hz(const std::uint32_t refresh_hz) { @@ -59,12 +57,7 @@ namespace virtual_display::driver { }; }; - if (command == "--diagnose" || - command == "--apply-extended-topology" || - command == "--query-color-profiles" || - command == "--check" || - command == "--query-permanent" || - command == "--apply-manifest-topology") { + if (command == "--diagnose" || command == "--apply-extended-topology" || command == "--query-color-profiles" || command == "--check" || command == "--query-permanent" || command == "--apply-manifest-topology") { return plan(2, 2); } if (command == "--set-permanent") { @@ -73,22 +66,16 @@ namespace virtual_display::driver { if (command == "--associate-color-profile") { return plan(5, (std::numeric_limits::max)()); } - if (command == "--self-test-permanent" || - command == "--self-test-4k240") { + if (command == "--self-test-permanent" || command == "--self-test-4k240") { return plan(2, 3); } if (command == "--qa-multi-temp-lease") { return plan(2, 4); } - if (command == "--self-test-temp" || - command == "--self-test-hdr") { + if (command == "--self-test-temp" || command == "--self-test-hdr") { return plan(2, 5); } - if (command == "--self-test-lease-expiry" || - command == "--qa-temp-identity-retention" || - command == "--debug-temp-config" || - command == "--stress-capture-remove" || - command == "--qa-temp-lease") { + if (command == "--self-test-lease-expiry" || command == "--qa-temp-identity-retention" || command == "--debug-temp-config" || command == "--stress-capture-remove" || command == "--qa-temp-lease") { return plan(2, 6); } return std::nullopt; @@ -121,9 +108,7 @@ namespace virtual_display::driver { if (command == "--diagnose") { return ProbeCommandExecutionStage::NoControlDevice; } - if (command == "--apply-extended-topology" || - command == "--query-color-profiles" || - command == "--associate-color-profile") { + if (command == "--apply-extended-topology" || command == "--query-color-profiles" || command == "--associate-color-profile") { return ProbeCommandExecutionStage::ActiveSessionBeforeControlDevice; } if (probe_command_uses_display_config(command)) { diff --git a/src/driver/vulkan_layer/vk_layer_sunshine_hdr.cpp b/src/driver/vulkan_layer/vk_layer_sunshine_hdr.cpp index 6d1a987..1fd711d 100644 --- a/src/driver/vulkan_layer/vk_layer_sunshine_hdr.cpp +++ b/src/driver/vulkan_layer/vk_layer_sunshine_hdr.cpp @@ -19,419 +19,420 @@ // Environment variables: // DISABLE_SUNSHINE_VIRTUAL_HDR=1 disable the layer (loader-level). // SUNSHINE_VHDR_FORCE=1 inject regardless of monitor HDR support. -#include - #include #include #include #include #include #include +#include namespace { -// ---- Vulkan ABI (subset; kept local so the layer builds without an SDK) ---- -using VkResult = std::int32_t; -using VkInstance = struct VkInstance_T *; -using VkPhysicalDevice = struct VkPhysicalDevice_T *; -using VkSurfaceKHR = std::uint64_t; - -constexpr std::int32_t kVkSuccess = 0; -constexpr std::int32_t kVkIncomplete = 5; -constexpr std::int32_t kVkErrorInitializationFailed = -3; - -constexpr std::int32_t kFormatA2B10G10R10UnormPack32 = 64; -constexpr std::int32_t kFormatR16G16B16A16Sfloat = 97; -constexpr std::int32_t kColorSpaceHdr10St2084 = 1000104008; -constexpr std::int32_t kColorSpaceExtendedSrgbLinear = 1000104002; -constexpr std::uint32_t kStructureTypeSurfaceFormat2 = 1000119002; - -struct VkSurfaceFormatKHR { - std::int32_t format; - std::int32_t colorSpace; -}; - -struct VkSurfaceFormat2KHR { - std::uint32_t sType; - void *pNext; - VkSurfaceFormatKHR surfaceFormat; -}; - -struct VkPhysicalDeviceSurfaceInfo2KHR { - std::uint32_t sType; - const void *pNext; - VkSurfaceKHR surface; -}; - -struct VkWin32SurfaceCreateInfoKHR { - std::uint32_t sType; - const void *pNext; - std::uint32_t flags; - HINSTANCE hinstance; - HWND hwnd; -}; - -struct VkInstanceCreateInfo { - std::uint32_t sType; - const void *pNext; - std::uint32_t flags; - const void *pApplicationInfo; - std::uint32_t enabledLayerCount; - const char *const *ppEnabledLayerNames; - std::uint32_t enabledExtensionCount; - const char *const *ppEnabledExtensionNames; -}; - -struct VkAllocationCallbacks; - -using PFN_vkVoidFunction = void (*)(); -using PFN_vkGetInstanceProcAddr = PFN_vkVoidFunction(__stdcall *)(VkInstance, const char *); -using PFN_vkCreateInstance = VkResult(__stdcall *)(const VkInstanceCreateInfo *, const VkAllocationCallbacks *, VkInstance *); -using PFN_vkDestroyInstance = void(__stdcall *)(VkInstance, const VkAllocationCallbacks *); -using PFN_vkCreateWin32SurfaceKHR = VkResult(__stdcall *)(VkInstance, const VkWin32SurfaceCreateInfoKHR *, const VkAllocationCallbacks *, VkSurfaceKHR *); -using PFN_vkDestroySurfaceKHR = void(__stdcall *)(VkInstance, VkSurfaceKHR, const VkAllocationCallbacks *); -using PFN_vkGetPhysicalDeviceSurfaceFormatsKHR = VkResult(__stdcall *)(VkPhysicalDevice, VkSurfaceKHR, std::uint32_t *, VkSurfaceFormatKHR *); -using PFN_vkGetPhysicalDeviceSurfaceFormats2KHR = VkResult(__stdcall *)(VkPhysicalDevice, const VkPhysicalDeviceSurfaceInfo2KHR *, std::uint32_t *, VkSurfaceFormat2KHR *); - -// ---- loader/layer negotiation ---- -constexpr std::uint32_t kStructureTypeLoaderInstanceCreateInfo = 47; -constexpr std::int32_t kLayerLinkInfo = 0; - -struct VkLayerInstanceLink { - VkLayerInstanceLink *pNext; - PFN_vkGetInstanceProcAddr pfnNextGetInstanceProcAddr; - PFN_vkVoidFunction pfnNextGetPhysicalDeviceProcAddr; -}; - -struct VkLayerInstanceCreateInfo { - std::uint32_t sType; - const void *pNext; - std::int32_t function; - union { - VkLayerInstanceLink *pLayerInfo; - void *other; - } u; -}; - -// ---- layer state ---- -struct InstanceData { - PFN_vkGetInstanceProcAddr next_gipa = nullptr; - PFN_vkDestroyInstance next_destroy_instance = nullptr; - PFN_vkCreateWin32SurfaceKHR next_create_win32_surface = nullptr; - PFN_vkDestroySurfaceKHR next_destroy_surface = nullptr; - PFN_vkGetPhysicalDeviceSurfaceFormatsKHR next_get_formats = nullptr; - PFN_vkGetPhysicalDeviceSurfaceFormats2KHR next_get_formats2 = nullptr; -}; - -std::mutex g_lock; -std::unordered_map g_instances; -std::unordered_map g_surface_hwnd; - -void *dispatch_key(const void *handle) { - return *reinterpret_cast(handle); -} - -bool instance_data(const void *handle, InstanceData &data) { - if (!handle) { - return false; - } - std::lock_guard hold {g_lock}; - const auto it = g_instances.find(dispatch_key(handle)); - if (it == g_instances.end()) { - return false; - } - data = it->second; - return true; -} - -bool sunshine_streaming_hdr_active() { - HANDLE event = OpenEventW(SYNCHRONIZE, FALSE, L"Global\\SunshineVirtualHdrActive"); - if (!event) { - event = OpenEventW(SYNCHRONIZE, FALSE, L"Local\\SunshineVirtualHdrActive"); - } - if (!event) { - return false; + // ---- Vulkan ABI (subset; kept local so the layer builds without an SDK) ---- + using VkResult = std::int32_t; + using VkInstance = struct VkInstance_T *; + using VkPhysicalDevice = struct VkPhysicalDevice_T *; + using VkSurfaceKHR = std::uint64_t; + + constexpr std::int32_t kVkSuccess = 0; + constexpr std::int32_t kVkIncomplete = 5; + constexpr std::int32_t kVkErrorInitializationFailed = -3; + + constexpr std::int32_t kFormatA2B10G10R10UnormPack32 = 64; + constexpr std::int32_t kFormatR16G16B16A16Sfloat = 97; + constexpr std::int32_t kColorSpaceHdr10St2084 = 1000104008; + constexpr std::int32_t kColorSpaceExtendedSrgbLinear = 1000104002; + constexpr std::uint32_t kStructureTypeSurfaceFormat2 = 1000119002; + + struct VkSurfaceFormatKHR { + std::int32_t format; + std::int32_t colorSpace; + }; + + struct VkSurfaceFormat2KHR { + std::uint32_t sType; + void *pNext; + VkSurfaceFormatKHR surfaceFormat; + }; + + struct VkPhysicalDeviceSurfaceInfo2KHR { + std::uint32_t sType; + const void *pNext; + VkSurfaceKHR surface; + }; + + struct VkWin32SurfaceCreateInfoKHR { + std::uint32_t sType; + const void *pNext; + std::uint32_t flags; + HINSTANCE hinstance; + HWND hwnd; + }; + + struct VkInstanceCreateInfo { + std::uint32_t sType; + const void *pNext; + std::uint32_t flags; + const void *pApplicationInfo; + std::uint32_t enabledLayerCount; + const char *const *ppEnabledLayerNames; + std::uint32_t enabledExtensionCount; + const char *const *ppEnabledExtensionNames; + }; + + struct VkAllocationCallbacks; + + using PFN_vkVoidFunction = void (*)(); + using PFN_vkGetInstanceProcAddr = PFN_vkVoidFunction(__stdcall *)(VkInstance, const char *); + using PFN_vkCreateInstance = VkResult(__stdcall *)(const VkInstanceCreateInfo *, const VkAllocationCallbacks *, VkInstance *); + using PFN_vkDestroyInstance = void(__stdcall *)(VkInstance, const VkAllocationCallbacks *); + using PFN_vkCreateWin32SurfaceKHR = VkResult(__stdcall *)(VkInstance, const VkWin32SurfaceCreateInfoKHR *, const VkAllocationCallbacks *, VkSurfaceKHR *); + using PFN_vkDestroySurfaceKHR = void(__stdcall *)(VkInstance, VkSurfaceKHR, const VkAllocationCallbacks *); + using PFN_vkGetPhysicalDeviceSurfaceFormatsKHR = VkResult(__stdcall *)(VkPhysicalDevice, VkSurfaceKHR, std::uint32_t *, VkSurfaceFormatKHR *); + using PFN_vkGetPhysicalDeviceSurfaceFormats2KHR = VkResult(__stdcall *)(VkPhysicalDevice, const VkPhysicalDeviceSurfaceInfo2KHR *, std::uint32_t *, VkSurfaceFormat2KHR *); + + // ---- loader/layer negotiation ---- + constexpr std::uint32_t kStructureTypeLoaderInstanceCreateInfo = 47; + constexpr std::int32_t kLayerLinkInfo = 0; + + struct VkLayerInstanceLink { + VkLayerInstanceLink *pNext; + PFN_vkGetInstanceProcAddr pfnNextGetInstanceProcAddr; + PFN_vkVoidFunction pfnNextGetPhysicalDeviceProcAddr; + }; + + struct VkLayerInstanceCreateInfo { + std::uint32_t sType; + const void *pNext; + std::int32_t function; + + union { + VkLayerInstanceLink *pLayerInfo; + void *other; + } u; + }; + + // ---- layer state ---- + struct InstanceData { + PFN_vkGetInstanceProcAddr next_gipa = nullptr; + PFN_vkDestroyInstance next_destroy_instance = nullptr; + PFN_vkCreateWin32SurfaceKHR next_create_win32_surface = nullptr; + PFN_vkDestroySurfaceKHR next_destroy_surface = nullptr; + PFN_vkGetPhysicalDeviceSurfaceFormatsKHR next_get_formats = nullptr; + PFN_vkGetPhysicalDeviceSurfaceFormats2KHR next_get_formats2 = nullptr; + }; + + std::mutex g_lock; + std::unordered_map g_instances; + std::unordered_map g_surface_hwnd; + + void *dispatch_key(const void *handle) { + return *reinterpret_cast(handle); + } + + bool instance_data(const void *handle, InstanceData &data) { + if (!handle) { + return false; + } + std::lock_guard hold {g_lock}; + const auto it = g_instances.find(dispatch_key(handle)); + if (it == g_instances.end()) { + return false; + } + data = it->second; + return true; } - const bool active = WaitForSingleObject(event, 0) == WAIT_OBJECT_0; - CloseHandle(event); - return active; -} + bool sunshine_streaming_hdr_active() { + HANDLE event = OpenEventW(SYNCHRONIZE, FALSE, L"Global\\SunshineVirtualHdrActive"); + if (!event) { + event = OpenEventW(SYNCHRONIZE, FALSE, L"Local\\SunshineVirtualHdrActive"); + } + if (!event) { + return false; + } -// ---- Windows advanced color query ---- -bool monitor_reports_hdr(HWND hwnd) { - if (!hwnd) { - return false; - } - char force[8] {}; - if (GetEnvironmentVariableA("SUNSHINE_VHDR_FORCE", force, sizeof(force)) > 0 && force[0] == '1') { - return true; - } - HMONITOR monitor = MonitorFromWindow(hwnd, MONITOR_DEFAULTTONEAREST); - MONITORINFOEXW info {}; - info.cbSize = sizeof(info); - if (!monitor || !GetMonitorInfoW(monitor, &info)) { - return false; + const bool active = WaitForSingleObject(event, 0) == WAIT_OBJECT_0; + CloseHandle(event); + return active; } - UINT32 path_count = 0; - UINT32 mode_count = 0; - if (GetDisplayConfigBufferSizes(QDC_ONLY_ACTIVE_PATHS, &path_count, &mode_count) != ERROR_SUCCESS) { - return false; - } - std::vector paths(path_count); - std::vector modes(mode_count); - if (QueryDisplayConfig(QDC_ONLY_ACTIVE_PATHS, &path_count, paths.data(), &mode_count, modes.data(), nullptr) != ERROR_SUCCESS) { - return false; - } - for (UINT32 i = 0; i < path_count; ++i) { - DISPLAYCONFIG_SOURCE_DEVICE_NAME source {}; - source.header.type = DISPLAYCONFIG_DEVICE_INFO_GET_SOURCE_NAME; - source.header.size = sizeof(source); - source.header.adapterId = paths[i].sourceInfo.adapterId; - source.header.id = paths[i].sourceInfo.id; - if (DisplayConfigGetDeviceInfo(&source.header) != ERROR_SUCCESS) { - continue; - } - if (wcscmp(source.viewGdiDeviceName, info.szDevice) != 0) { - continue; - } - - // DISPLAYCONFIG_DEVICE_INFO_GET_ADVANCED_COLOR_INFO_2 (Windows 11 24H2+) - // reports HDR support directly; defined locally so older SDKs build. - struct GetAdvancedColorInfo2 { - DISPLAYCONFIG_DEVICE_INFO_HEADER header; - union { - struct { - UINT32 advancedColorSupported : 1; - UINT32 advancedColorActive : 1; - UINT32 reserved1 : 1; - UINT32 advancedColorLimitedByPolicy : 1; - UINT32 highDynamicRangeSupported : 1; - UINT32 highDynamicRangeUserEnabled : 1; - UINT32 wideColorSupported : 1; - UINT32 wideColorUserEnabled : 1; - UINT32 reserved : 24; - }; - UINT32 value; - }; - DISPLAYCONFIG_COLOR_ENCODING colorEncoding; - UINT32 bitsPerColorChannel; - UINT32 activeColorMode; - } aci2 {}; - aci2.header.type = static_cast(15); - aci2.header.size = sizeof(aci2); - aci2.header.adapterId = paths[i].targetInfo.adapterId; - aci2.header.id = paths[i].targetInfo.id; - if (DisplayConfigGetDeviceInfo(&aci2.header) == ERROR_SUCCESS) { - return aci2.highDynamicRangeSupported != 0; - } - - DISPLAYCONFIG_GET_ADVANCED_COLOR_INFO aci1 {}; - aci1.header.type = DISPLAYCONFIG_DEVICE_INFO_GET_ADVANCED_COLOR_INFO; - aci1.header.size = sizeof(aci1); - aci1.header.adapterId = paths[i].targetInfo.adapterId; - aci1.header.id = paths[i].targetInfo.id; - if (DisplayConfigGetDeviceInfo(&aci1.header) == ERROR_SUCCESS) { - return aci1.advancedColorSupported != 0; + // ---- Windows advanced color query ---- + bool monitor_reports_hdr(HWND hwnd) { + if (!hwnd) { + return false; } - } - return false; -} + char force[8] {}; + if (GetEnvironmentVariableA("SUNSHINE_VHDR_FORCE", force, sizeof(force)) > 0 && force[0] == '1') { + return true; + } + HMONITOR monitor = MonitorFromWindow(hwnd, MONITOR_DEFAULTTONEAREST); + MONITORINFOEXW info {}; + info.cbSize = sizeof(info); + if (!monitor || !GetMonitorInfoW(monitor, &info)) { + return false; + } + + UINT32 path_count = 0; + UINT32 mode_count = 0; + if (GetDisplayConfigBufferSizes(QDC_ONLY_ACTIVE_PATHS, &path_count, &mode_count) != ERROR_SUCCESS) { + return false; + } + std::vector paths(path_count); + std::vector modes(mode_count); + if (QueryDisplayConfig(QDC_ONLY_ACTIVE_PATHS, &path_count, paths.data(), &mode_count, modes.data(), nullptr) != ERROR_SUCCESS) { + return false; + } + for (UINT32 i = 0; i < path_count; ++i) { + DISPLAYCONFIG_SOURCE_DEVICE_NAME source {}; + source.header.type = DISPLAYCONFIG_DEVICE_INFO_GET_SOURCE_NAME; + source.header.size = sizeof(source); + source.header.adapterId = paths[i].sourceInfo.adapterId; + source.header.id = paths[i].sourceInfo.id; + if (DisplayConfigGetDeviceInfo(&source.header) != ERROR_SUCCESS) { + continue; + } + if (wcscmp(source.viewGdiDeviceName, info.szDevice) != 0) { + continue; + } + + // DISPLAYCONFIG_DEVICE_INFO_GET_ADVANCED_COLOR_INFO_2 (Windows 11 24H2+) + // reports HDR support directly; defined locally so older SDKs build. + struct GetAdvancedColorInfo2 { + DISPLAYCONFIG_DEVICE_INFO_HEADER header; + + union { + struct { + UINT32 advancedColorSupported : 1; + UINT32 advancedColorActive : 1; + UINT32 reserved1 : 1; + UINT32 advancedColorLimitedByPolicy : 1; + UINT32 highDynamicRangeSupported : 1; + UINT32 highDynamicRangeUserEnabled : 1; + UINT32 wideColorSupported : 1; + UINT32 wideColorUserEnabled : 1; + UINT32 reserved : 24; + }; + + UINT32 value; + }; -bool should_inject(VkSurfaceKHR surface) { - if (!sunshine_streaming_hdr_active()) { + DISPLAYCONFIG_COLOR_ENCODING colorEncoding; + UINT32 bitsPerColorChannel; + UINT32 activeColorMode; + } aci2 {}; + + aci2.header.type = static_cast(15); + aci2.header.size = sizeof(aci2); + aci2.header.adapterId = paths[i].targetInfo.adapterId; + aci2.header.id = paths[i].targetInfo.id; + if (DisplayConfigGetDeviceInfo(&aci2.header) == ERROR_SUCCESS) { + return aci2.highDynamicRangeSupported != 0; + } + + DISPLAYCONFIG_GET_ADVANCED_COLOR_INFO aci1 {}; + aci1.header.type = DISPLAYCONFIG_DEVICE_INFO_GET_ADVANCED_COLOR_INFO; + aci1.header.size = sizeof(aci1); + aci1.header.adapterId = paths[i].targetInfo.adapterId; + aci1.header.id = paths[i].targetInfo.id; + if (DisplayConfigGetDeviceInfo(&aci1.header) == ERROR_SUCCESS) { + return aci1.advancedColorSupported != 0; + } + } return false; } - HWND hwnd = nullptr; - { - std::lock_guard hold {g_lock}; - const auto it = g_surface_hwnd.find(surface); - if (it == g_surface_hwnd.end()) { + bool should_inject(VkSurfaceKHR surface) { + if (!sunshine_streaming_hdr_active()) { return false; } - hwnd = it->second; - } - return monitor_reports_hdr(hwnd); -} -void append_missing(std::vector &formats) { - bool has_hdr10 = false; - bool has_scrgb = false; - for (const auto &format : formats) { - if (format.colorSpace == kColorSpaceHdr10St2084) { - has_hdr10 = true; + HWND hwnd = nullptr; + { + std::lock_guard hold {g_lock}; + const auto it = g_surface_hwnd.find(surface); + if (it == g_surface_hwnd.end()) { + return false; + } + hwnd = it->second; } - if (format.colorSpace == kColorSpaceExtendedSrgbLinear) { - has_scrgb = true; + return monitor_reports_hdr(hwnd); + } + + void append_missing(std::vector &formats) { + bool has_hdr10 = false; + bool has_scrgb = false; + for (const auto &format : formats) { + if (format.colorSpace == kColorSpaceHdr10St2084) { + has_hdr10 = true; + } + if (format.colorSpace == kColorSpaceExtendedSrgbLinear) { + has_scrgb = true; + } + } + if (!has_scrgb) { + formats.push_back({kFormatR16G16B16A16Sfloat, kColorSpaceExtendedSrgbLinear}); + } + if (!has_hdr10) { + formats.push_back({kFormatA2B10G10R10UnormPack32, kColorSpaceHdr10St2084}); } } - if (!has_scrgb) { - formats.push_back({kFormatR16G16B16A16Sfloat, kColorSpaceExtendedSrgbLinear}); - } - if (!has_hdr10) { - formats.push_back({kFormatA2B10G10R10UnormPack32, kColorSpaceHdr10St2084}); - } -} -// ---- intercepted entry points ---- -VkResult __stdcall layer_CreateWin32SurfaceKHR(VkInstance instance, const VkWin32SurfaceCreateInfoKHR *create_info, - const VkAllocationCallbacks *allocator, VkSurfaceKHR *surface) { - InstanceData data; - if (!instance_data(instance, data) || !data.next_create_win32_surface) { - return kVkErrorInitializationFailed; - } - const VkResult result = data.next_create_win32_surface(instance, create_info, allocator, surface); - if (result == kVkSuccess && create_info) { - std::lock_guard hold {g_lock}; - g_surface_hwnd[*surface] = create_info->hwnd; - } - return result; -} - -void __stdcall layer_DestroySurfaceKHR(VkInstance instance, VkSurfaceKHR surface, const VkAllocationCallbacks *allocator) { - InstanceData data; - const bool have_data = instance_data(instance, data); - { - std::lock_guard hold {g_lock}; - g_surface_hwnd.erase(surface); - } - if (have_data && data.next_destroy_surface) { - data.next_destroy_surface(instance, surface, allocator); + // ---- intercepted entry points ---- + VkResult __stdcall layer_CreateWin32SurfaceKHR(VkInstance instance, const VkWin32SurfaceCreateInfoKHR *create_info, const VkAllocationCallbacks *allocator, VkSurfaceKHR *surface) { + InstanceData data; + if (!instance_data(instance, data) || !data.next_create_win32_surface) { + return kVkErrorInitializationFailed; + } + const VkResult result = data.next_create_win32_surface(instance, create_info, allocator, surface); + if (result == kVkSuccess && create_info) { + std::lock_guard hold {g_lock}; + g_surface_hwnd[*surface] = create_info->hwnd; + } + return result; } -} -VkResult __stdcall layer_GetPhysicalDeviceSurfaceFormatsKHR(VkPhysicalDevice physical_device, VkSurfaceKHR surface, - std::uint32_t *count, VkSurfaceFormatKHR *out) { - InstanceData data; - if (!instance_data(physical_device, data) || !data.next_get_formats) { - return kVkErrorInitializationFailed; - } - if (!should_inject(surface)) { - return data.next_get_formats(physical_device, surface, count, out); + void __stdcall layer_DestroySurfaceKHR(VkInstance instance, VkSurfaceKHR surface, const VkAllocationCallbacks *allocator) { + InstanceData data; + const bool have_data = instance_data(instance, data); + { + std::lock_guard hold {g_lock}; + g_surface_hwnd.erase(surface); + } + if (have_data && data.next_destroy_surface) { + data.next_destroy_surface(instance, surface, allocator); + } } - std::uint32_t base_count = 0; - VkResult result = data.next_get_formats(physical_device, surface, &base_count, nullptr); - if (result != kVkSuccess) { - return data.next_get_formats(physical_device, surface, count, out); - } - std::vector formats(base_count); - result = data.next_get_formats(physical_device, surface, &base_count, formats.data()); - if (result != kVkSuccess && result != kVkIncomplete) { - return data.next_get_formats(physical_device, surface, count, out); - } - formats.resize(base_count); - append_missing(formats); + VkResult __stdcall layer_GetPhysicalDeviceSurfaceFormatsKHR(VkPhysicalDevice physical_device, VkSurfaceKHR surface, std::uint32_t *count, VkSurfaceFormatKHR *out) { + InstanceData data; + if (!instance_data(physical_device, data) || !data.next_get_formats) { + return kVkErrorInitializationFailed; + } + if (!should_inject(surface)) { + return data.next_get_formats(physical_device, surface, count, out); + } - if (!out) { - *count = static_cast(formats.size()); - return kVkSuccess; - } - const auto total = static_cast(formats.size()); - const std::uint32_t to_copy = *count < total ? *count : total; - std::memcpy(out, formats.data(), to_copy * sizeof(VkSurfaceFormatKHR)); - *count = to_copy; - return to_copy < total ? kVkIncomplete : kVkSuccess; -} + std::uint32_t base_count = 0; + VkResult result = data.next_get_formats(physical_device, surface, &base_count, nullptr); + if (result != kVkSuccess) { + return data.next_get_formats(physical_device, surface, count, out); + } + std::vector formats(base_count); + result = data.next_get_formats(physical_device, surface, &base_count, formats.data()); + if (result != kVkSuccess && result != kVkIncomplete) { + return data.next_get_formats(physical_device, surface, count, out); + } + formats.resize(base_count); + append_missing(formats); -VkResult __stdcall layer_GetPhysicalDeviceSurfaceFormats2KHR(VkPhysicalDevice physical_device, - const VkPhysicalDeviceSurfaceInfo2KHR *surface_info, - std::uint32_t *count, VkSurfaceFormat2KHR *out) { - InstanceData data; - if (!instance_data(physical_device, data) || !data.next_get_formats2) { - return kVkErrorInitializationFailed; - } - if (!surface_info || !should_inject(surface_info->surface)) { - return data.next_get_formats2(physical_device, surface_info, count, out); + if (!out) { + *count = static_cast(formats.size()); + return kVkSuccess; + } + const auto total = static_cast(formats.size()); + const std::uint32_t to_copy = *count < total ? *count : total; + std::memcpy(out, formats.data(), to_copy * sizeof(VkSurfaceFormatKHR)); + *count = to_copy; + return to_copy < total ? kVkIncomplete : kVkSuccess; } - std::uint32_t base_count = 0; - VkResult result = data.next_get_formats2(physical_device, surface_info, &base_count, nullptr); - if (result != kVkSuccess) { - return data.next_get_formats2(physical_device, surface_info, count, out); - } - std::vector base(base_count); - for (auto &entry : base) { - entry.sType = kStructureTypeSurfaceFormat2; - entry.pNext = nullptr; - } - result = data.next_get_formats2(physical_device, surface_info, &base_count, base.data()); - if (result != kVkSuccess && result != kVkIncomplete) { - return data.next_get_formats2(physical_device, surface_info, count, out); - } - std::vector formats; - formats.reserve(base_count + 2); - for (std::uint32_t i = 0; i < base_count; ++i) { - formats.push_back(base[i].surfaceFormat); - } - append_missing(formats); + VkResult __stdcall layer_GetPhysicalDeviceSurfaceFormats2KHR(VkPhysicalDevice physical_device, const VkPhysicalDeviceSurfaceInfo2KHR *surface_info, std::uint32_t *count, VkSurfaceFormat2KHR *out) { + InstanceData data; + if (!instance_data(physical_device, data) || !data.next_get_formats2) { + return kVkErrorInitializationFailed; + } + if (!surface_info || !should_inject(surface_info->surface)) { + return data.next_get_formats2(physical_device, surface_info, count, out); + } - if (!out) { - *count = static_cast(formats.size()); - return kVkSuccess; - } - const auto total = static_cast(formats.size()); - const std::uint32_t to_copy = *count < total ? *count : total; - for (std::uint32_t i = 0; i < to_copy; ++i) { - out[i].surfaceFormat = formats[i]; - } - *count = to_copy; - return to_copy < total ? kVkIncomplete : kVkSuccess; -} + std::uint32_t base_count = 0; + VkResult result = data.next_get_formats2(physical_device, surface_info, &base_count, nullptr); + if (result != kVkSuccess) { + return data.next_get_formats2(physical_device, surface_info, count, out); + } + std::vector base(base_count); + for (auto &entry : base) { + entry.sType = kStructureTypeSurfaceFormat2; + entry.pNext = nullptr; + } + result = data.next_get_formats2(physical_device, surface_info, &base_count, base.data()); + if (result != kVkSuccess && result != kVkIncomplete) { + return data.next_get_formats2(physical_device, surface_info, count, out); + } + std::vector formats; + formats.reserve(base_count + 2); + for (std::uint32_t i = 0; i < base_count; ++i) { + formats.push_back(base[i].surfaceFormat); + } + append_missing(formats); -void __stdcall layer_DestroyInstance(VkInstance instance, const VkAllocationCallbacks *allocator) { - PFN_vkDestroyInstance next = nullptr; - { - std::lock_guard hold {g_lock}; - const auto it = g_instances.find(dispatch_key(instance)); - if (it != g_instances.end()) { - next = it->second.next_destroy_instance; - g_instances.erase(it); + if (!out) { + *count = static_cast(formats.size()); + return kVkSuccess; + } + const auto total = static_cast(formats.size()); + const std::uint32_t to_copy = *count < total ? *count : total; + for (std::uint32_t i = 0; i < to_copy; ++i) { + out[i].surfaceFormat = formats[i]; + } + *count = to_copy; + return to_copy < total ? kVkIncomplete : kVkSuccess; + } + + void __stdcall layer_DestroyInstance(VkInstance instance, const VkAllocationCallbacks *allocator) { + PFN_vkDestroyInstance next = nullptr; + { + std::lock_guard hold {g_lock}; + const auto it = g_instances.find(dispatch_key(instance)); + if (it != g_instances.end()) { + next = it->second.next_destroy_instance; + g_instances.erase(it); + } + } + if (next) { + next(instance, allocator); } } - if (next) { - next(instance, allocator); - } -} -VkResult __stdcall layer_CreateInstance(const VkInstanceCreateInfo *create_info, - const VkAllocationCallbacks *allocator, VkInstance *instance) { - auto *chain = const_cast( - reinterpret_cast(create_info->pNext)); - while (chain && !(chain->sType == kStructureTypeLoaderInstanceCreateInfo && chain->function == kLayerLinkInfo)) { - chain = const_cast( - reinterpret_cast(chain->pNext)); - } - if (!chain || !chain->u.pLayerInfo) { - return kVkErrorInitializationFailed; - } - PFN_vkGetInstanceProcAddr next_gipa = chain->u.pLayerInfo->pfnNextGetInstanceProcAddr; - chain->u.pLayerInfo = chain->u.pLayerInfo->pNext; + VkResult __stdcall layer_CreateInstance(const VkInstanceCreateInfo *create_info, const VkAllocationCallbacks *allocator, VkInstance *instance) { + auto *chain = const_cast( + reinterpret_cast(create_info->pNext) + ); + while (chain && !(chain->sType == kStructureTypeLoaderInstanceCreateInfo && chain->function == kLayerLinkInfo)) { + chain = const_cast( + reinterpret_cast(chain->pNext) + ); + } + if (!chain || !chain->u.pLayerInfo) { + return kVkErrorInitializationFailed; + } + PFN_vkGetInstanceProcAddr next_gipa = chain->u.pLayerInfo->pfnNextGetInstanceProcAddr; + chain->u.pLayerInfo = chain->u.pLayerInfo->pNext; - const auto next_create = reinterpret_cast(next_gipa(nullptr, "vkCreateInstance")); - if (!next_create) { - return kVkErrorInitializationFailed; - } - const VkResult result = next_create(create_info, allocator, instance); - if (result != kVkSuccess) { - return result; - } + const auto next_create = reinterpret_cast(next_gipa(nullptr, "vkCreateInstance")); + if (!next_create) { + return kVkErrorInitializationFailed; + } + const VkResult result = next_create(create_info, allocator, instance); + if (result != kVkSuccess) { + return result; + } - InstanceData data; - data.next_gipa = next_gipa; - data.next_destroy_instance = reinterpret_cast(next_gipa(*instance, "vkDestroyInstance")); - data.next_create_win32_surface = reinterpret_cast(next_gipa(*instance, "vkCreateWin32SurfaceKHR")); - data.next_destroy_surface = reinterpret_cast(next_gipa(*instance, "vkDestroySurfaceKHR")); - data.next_get_formats = reinterpret_cast(next_gipa(*instance, "vkGetPhysicalDeviceSurfaceFormatsKHR")); - data.next_get_formats2 = reinterpret_cast(next_gipa(*instance, "vkGetPhysicalDeviceSurfaceFormats2KHR")); - { - std::lock_guard hold {g_lock}; - g_instances[dispatch_key(*instance)] = data; + InstanceData data; + data.next_gipa = next_gipa; + data.next_destroy_instance = reinterpret_cast(next_gipa(*instance, "vkDestroyInstance")); + data.next_create_win32_surface = reinterpret_cast(next_gipa(*instance, "vkCreateWin32SurfaceKHR")); + data.next_destroy_surface = reinterpret_cast(next_gipa(*instance, "vkDestroySurfaceKHR")); + data.next_get_formats = reinterpret_cast(next_gipa(*instance, "vkGetPhysicalDeviceSurfaceFormatsKHR")); + data.next_get_formats2 = reinterpret_cast(next_gipa(*instance, "vkGetPhysicalDeviceSurfaceFormats2KHR")); + { + std::lock_guard hold {g_lock}; + g_instances[dispatch_key(*instance)] = data; + } + return kVkSuccess; } - return kVkSuccess; -} } // namespace diff --git a/src/driver/windows_control_client.cpp b/src/driver/windows_control_client.cpp index 258392a..3039c2e 100644 --- a/src/driver/windows_control_client.cpp +++ b/src/driver/windows_control_client.cpp @@ -2,12 +2,11 @@ #ifdef _WIN32 -#include - -#include -#include -#include -#include + #include + #include + #include + #include + #include namespace virtual_display::driver { namespace { @@ -161,9 +160,7 @@ namespace virtual_display::driver { ) { bytes_returned = 0; native_error = 0; - if (!valid() || - input_size > (std::numeric_limits::max)() || - output_size > (std::numeric_limits::max)()) { + if (!valid() || input_size > (std::numeric_limits::max)() || output_size > (std::numeric_limits::max)()) { native_error = ERROR_INVALID_PARAMETER; return false; } diff --git a/src/driver/windows_driver/driver_main.cpp b/src/driver/windows_driver/driver_main.cpp index b1a1f03..dd630c7 100644 --- a/src/driver/windows_driver/driver_main.cpp +++ b/src/driver/windows_driver/driver_main.cpp @@ -1,16 +1,18 @@ #ifndef NOMINMAX -# define NOMINMAX + #define NOMINMAX #endif -#include "virtual_display/driver/ioctl_dispatcher.h" +#include "virtual_display/driver/frame_ring_server.h" #include "virtual_display/driver/hdr_capabilities.h" +#include "virtual_display/driver/ioctl_dispatcher.h" #include "virtual_display/driver/lease_store.h" -#include "virtual_display/driver/frame_ring_server.h" -#include "virtual_display/driver/windows_frame_importer.h" #include "virtual_display/driver/windows_control_protocol.h" #include "virtual_display/driver/windows_driver_modes.h" #include "virtual_display/driver/windows_driver_state.h" +#include "virtual_display/driver/windows_frame_importer.h" +// Win32 types precede the SDK headers, and IddCx uses declarations from WDF. +// clang-format off #include #include #include @@ -21,6 +23,7 @@ #include #include #include +// clang-format on #include #include @@ -58,9 +61,10 @@ TRACELOGGING_DEFINE_PROVIDER( SunshineVirtualDisplayDriverWpp, \ (b0dcb744, 045b, 463b, 9c2f, 6a3c897d3458), \ WPP_DEFINE_BIT(TRACE_DRIVER) \ - WPP_DEFINE_BIT(TRACE_DEVICE) \ - WPP_DEFINE_BIT(TRACE_SWAPCHAIN) \ - WPP_DEFINE_BIT(TRACE_CURSOR)) + WPP_DEFINE_BIT(TRACE_DEVICE) \ + WPP_DEFINE_BIT(TRACE_SWAPCHAIN) \ + WPP_DEFINE_BIT(TRACE_CURSOR) \ + ) #define WPP_LEVEL_FLAGS_LOGGER(level, flags) WPP_LEVEL_LOGGER(flags) #define WPP_LEVEL_FLAGS_ENABLED(level, flags) \ @@ -109,7 +113,8 @@ namespace { class CursorProcessor; class SwapChainProcessor; using FrameRingSnapshotProvider = std::function; struct AdapterContext { @@ -171,20 +176,25 @@ namespace { class RegistryKey { public: RegistryKey() = default; + explicit RegistryKey(WDFKEY key): key_ {key} { } + RegistryKey(const RegistryKey &) = delete; RegistryKey &operator=(const RegistryKey &) = delete; + RegistryKey(RegistryKey &&other) noexcept: key_ {std::exchange(other.key_, nullptr)} { } + RegistryKey &operator=(RegistryKey &&other) noexcept { if (this != &other) { reset(std::exchange(other.key_, nullptr)); } return *this; } + ~RegistryKey() { reset(); } @@ -212,20 +222,25 @@ namespace { class NativeRegistryKey { public: NativeRegistryKey() = default; + explicit NativeRegistryKey(HKEY key): key_ {key} { } + NativeRegistryKey(const NativeRegistryKey &) = delete; NativeRegistryKey &operator=(const NativeRegistryKey &) = delete; + NativeRegistryKey(NativeRegistryKey &&other) noexcept: key_ {std::exchange(other.key_, nullptr)} { } + NativeRegistryKey &operator=(NativeRegistryKey &&other) noexcept { if (this != &other) { reset(std::exchange(other.key_, nullptr)); } return *this; } + ~NativeRegistryKey() { reset(); } @@ -294,8 +309,7 @@ namespace { &value_length, &value_type ); - if (!NT_SUCCESS(status) || value_type != REG_BINARY || value_length < vdd::kTemporaryDisplayProfilesHeaderBytes || - value_length > blob.size()) { + if (!NT_SUCCESS(status) || value_type != REG_BINARY || value_length < vdd::kTemporaryDisplayProfilesHeaderBytes || value_length > blob.size()) { return profiles; } @@ -309,7 +323,7 @@ namespace { return vdd::temporary_connector_reservations(profiles); } - template + template void write_registry_value_if_success( WDFKEY key, const wchar_t *value_name, @@ -579,13 +593,7 @@ namespace { NativeRegistryKey per_monitor_settings_key; const auto per_monitor_settings_path = *sid + L"\\Control Panel\\Desktop\\PerMonitorSettings"; - if (RegOpenKeyExW( - HKEY_USERS, - per_monitor_settings_path.c_str(), - 0, - KEY_ENUMERATE_SUB_KEYS, - per_monitor_settings_key.put() - ) != ERROR_SUCCESS) { + if (RegOpenKeyExW(HKEY_USERS, per_monitor_settings_path.c_str(), 0, KEY_ENUMERATE_SUB_KEYS, per_monitor_settings_key.put()) != ERROR_SUCCESS) { return std::nullopt; } @@ -608,13 +616,7 @@ namespace { NativeRegistryKey per_monitor_settings_key; const auto per_monitor_settings_path = *sid + L"\\Control Panel\\Desktop\\PerMonitorSettings"; - if (RegOpenKeyExW( - HKEY_USERS, - per_monitor_settings_path.c_str(), - 0, - KEY_ENUMERATE_SUB_KEYS, - per_monitor_settings_key.put() - ) != ERROR_SUCCESS) { + if (RegOpenKeyExW(HKEY_USERS, per_monitor_settings_path.c_str(), 0, KEY_ENUMERATE_SUB_KEYS, per_monitor_settings_key.put()) != ERROR_SUCCESS) { return false; } @@ -652,19 +654,11 @@ namespace { // change. Slots that are absent, default (DpiValue == 0), or already // equal are safe to (re)seed with the retained value. DWORD existing_value {}; - if (read_registry_dword(settings_key.get(), L"DpiValue", existing_value) && - existing_value != 0 && existing_value != dpi_value) { + if (read_registry_dword(settings_key.get(), L"DpiValue", existing_value) && existing_value != 0 && existing_value != dpi_value) { continue; } - if (RegSetValueExW( - settings_key.get(), - L"DpiValue", - 0, - REG_DWORD, - reinterpret_cast(&dpi_value), - sizeof(dpi_value) - ) == ERROR_SUCCESS) { + if (RegSetValueExW(settings_key.get(), L"DpiValue", 0, REG_DWORD, reinterpret_cast(&dpi_value), sizeof(dpi_value)) == ERROR_SUCCESS) { ++applied_count; } } @@ -759,8 +753,7 @@ namespace { } std::wstring container_id; - if (!read_registry_string(instance_key.get(), L"ContainerID", container_id) || - !equals_ci(container_id, expected_container_id)) { + if (!read_registry_string(instance_key.get(), L"ContainerID", container_id) || !equals_ci(container_id, expected_container_id)) { continue; } @@ -809,10 +802,7 @@ namespace { std::wstring candidate_driver; std::wstring candidate_container; - if (read_registry_string(instance_key.get(), L"Driver", candidate_driver) && - read_registry_string(instance_key.get(), L"ContainerID", candidate_container) && - equals_ci(candidate_driver, driver_value) && - equals_ci(candidate_container, container_id)) { + if (read_registry_string(instance_key.get(), L"Driver", candidate_driver) && read_registry_string(instance_key.get(), L"ContainerID", candidate_container) && equals_ci(candidate_driver, driver_value) && equals_ci(candidate_container, container_id)) { return true; } } @@ -845,17 +835,7 @@ namespace { NativeRegistryKey current_profile_key; const auto current_user_path = *sid + L"\\" + *current_profile_path; - if (RegCreateKeyExW( - HKEY_USERS, - current_user_path.c_str(), - 0, - nullptr, - REG_OPTION_NON_VOLATILE, - KEY_QUERY_VALUE | KEY_SET_VALUE, - nullptr, - current_profile_key.put(), - nullptr - ) != ERROR_SUCCESS) { + if (RegCreateKeyExW(HKEY_USERS, current_user_path.c_str(), 0, nullptr, REG_OPTION_NON_VOLATILE, KEY_QUERY_VALUE | KEY_SET_VALUE, nullptr, current_profile_key.put(), nullptr) != ERROR_SUCCESS) { return; } @@ -893,8 +873,7 @@ namespace { } const auto candidate_driver = current_driver->substr(0, current_slash + 1) + profile_key_name; - if (equals_ci(candidate_driver, *current_driver) || - !monitor_driver_value_matches_identity(candidate_driver, hardware_id, container_id)) { + if (equals_ci(candidate_driver, *current_driver) || !monitor_driver_value_matches_identity(candidate_driver, hardware_id, container_id)) { continue; } @@ -920,14 +899,7 @@ namespace { sizeof(use_per_user) ); - if (RegSetValueExW( - current_profile_key.get(), - L"ICMProfileAC", - 0, - source_profile_type, - reinterpret_cast(source_profile.data()), - static_cast(source_profile.size()) - ) == ERROR_SUCCESS) { + if (RegSetValueExW(current_profile_key.get(), L"ICMProfileAC", 0, source_profile_type, reinterpret_cast(source_profile.data()), static_cast(source_profile.size())) == ERROR_SUCCESS) { TraceLoggingWrite( g_trace_provider, "HdrProfileAssociationRetained", @@ -945,8 +917,8 @@ namespace { const auto *context = GetHdrProfileRetentionWorkItemContext(work_item); if (context) { const auto retained_dpi_value = context->has_retained_dpi_value ? - std::optional {context->retained_dpi_value} : - std::nullopt; + std::optional {context->retained_dpi_value} : + std::nullopt; for (std::uint32_t attempt = 0; attempt < 20; ++attempt) { (void) retain_temporary_display_dpi_settings(context->descriptor, retained_dpi_value); migrate_hdr_profile_association_for_monitor(context->descriptor, context->target_id); @@ -1038,8 +1010,8 @@ namespace { profile.manufacturer_id[2] }; options.product_code = profile.product_code > 0xffffu ? - 0xffffu : - static_cast(profile.product_code); + 0xffffu : + static_cast(profile.product_code); options.serial_number = profile.serial_number; options.width = mode.width; options.height = mode.height; @@ -1065,9 +1037,7 @@ namespace { } std::optional mode_shape_from_description(const IDDCX_MONITOR_DESCRIPTION &description) { - if (description.Type != IDDCX_MONITOR_DESCRIPTION_TYPE_EDID || - !description.pData || - description.DataSize < vdd::kEdidSize) { + if (description.Type != IDDCX_MONITOR_DESCRIPTION_TYPE_EDID || !description.pData || description.DataSize < vdd::kEdidSize) { return std::nullopt; } @@ -1088,8 +1058,8 @@ namespace { }; const auto total_pixels = - static_cast((std::max)(shape.total_width, 1u)) * - static_cast((std::max)(shape.total_height, 1u)); + static_cast((std::max) (shape.total_width, 1u)) * + static_cast((std::max) (shape.total_height, 1u)); const auto derived_refresh_millihz = total_pixels == 0 ? 0 : (shape.pixel_rate * 1000ull) / total_pixels; shape.refresh_rate_millihz = vdd::clamp_windows_driver_u32(derived_refresh_millihz); @@ -1111,9 +1081,7 @@ namespace { std::optional> monitor_description_key( const IDDCX_MONITOR_DESCRIPTION &description ) { - if (description.Type != IDDCX_MONITOR_DESCRIPTION_TYPE_EDID || - !description.pData || - description.DataSize < vdd::kEdidSize) { + if (description.Type != IDDCX_MONITOR_DESCRIPTION_TYPE_EDID || !description.pData || description.DataSize < vdd::kEdidSize) { return std::nullopt; } @@ -1131,7 +1099,9 @@ namespace { std::lock_guard lock {g_monitor_description_modes_mutex}; return g_monitor_description_modes.register_mode( - descriptor.edid, mode, descriptor.requested_resolution_only + descriptor.edid, + mode, + descriptor.requested_resolution_only ); } @@ -1211,8 +1181,8 @@ namespace { signal.pixelRate = shape.pixel_rate; signal.activeSize.cx = shape.width; signal.activeSize.cy = shape.height; - signal.totalSize.cx = (std::max)(shape.total_width, shape.width); - signal.totalSize.cy = (std::max)(shape.total_height, shape.height); + signal.totalSize.cx = (std::max) (shape.total_width, shape.width); + signal.totalSize.cy = (std::max) (shape.total_height, shape.height); const auto frequencies = vdd::windows_driver_signal_frequencies(shape); signal.vSyncFreq = {frequencies.vertical.numerator, frequencies.vertical.denominator}; signal.hSyncFreq = {frequencies.horizontal.numerator, frequencies.horizontal.denominator}; @@ -1329,7 +1299,8 @@ namespace { const auto [modes, preferred_index] = vdd::build_windows_driver_mode_shapes( requested_shape && requested_shape->requested_resolution_only ? - std::optional {requested_shape->preferred} : std::nullopt, + std::optional {requested_shape->preferred} : + std::nullopt, requested_shape && requested_shape->requested_resolution_only ); output->DefaultMonitorModeBufferOutputCount = static_cast(modes.size()); @@ -1503,20 +1474,25 @@ namespace { class UniqueHandle { public: UniqueHandle() = default; + explicit UniqueHandle(HANDLE handle): handle_ {handle} { } + UniqueHandle(const UniqueHandle &) = delete; UniqueHandle &operator=(const UniqueHandle &) = delete; + UniqueHandle(UniqueHandle &&other) noexcept: handle_ {std::exchange(other.handle_, nullptr)} { } + UniqueHandle &operator=(UniqueHandle &&other) noexcept { if (this != &other) { reset(std::exchange(other.handle_, nullptr)); } return *this; } + ~UniqueHandle() { reset(); } @@ -1543,22 +1519,27 @@ namespace { class WdfObjectReferenceGuard { public: WdfObjectReferenceGuard() = default; + explicit WdfObjectReferenceGuard(WDFOBJECT object): object_ {object} { if (object_) { WdfObjectReference(object_); } } + static WdfObjectReferenceGuard adopt(WDFOBJECT object) { WdfObjectReferenceGuard guard; guard.object_ = object; return guard; } + WdfObjectReferenceGuard(const WdfObjectReferenceGuard &) = delete; WdfObjectReferenceGuard &operator=(const WdfObjectReferenceGuard &) = delete; + WdfObjectReferenceGuard(WdfObjectReferenceGuard &&other) noexcept: object_ {std::exchange(other.object_, nullptr)} { } + WdfObjectReferenceGuard &operator=(WdfObjectReferenceGuard &&other) noexcept { if (this != &other) { reset(); @@ -1566,6 +1547,7 @@ namespace { } return *this; } + ~WdfObjectReferenceGuard() { reset(); } @@ -1665,10 +1647,8 @@ namespace { return true; } - const auto wait_ms = static_cast((std::min)( - (std::max)(timeout.count(), 0), - MAXDWORD - )); + const auto wait_ms = static_cast((std::min) ((std::max) (timeout.count(), 0), + MAXDWORD)); const DWORD wait_result = WaitForSingleObject(worker_.native_handle(), wait_ms); if (wait_result == WAIT_OBJECT_0) { worker_.join(); @@ -1861,30 +1841,36 @@ namespace { const std::uint64_t display_id, const std::uint64_t display_generation ) { - if (!snapshot.can_publish() || !snapshot.resources || !device || - snapshot.display_generation != display_generation || !snapshot.ring_generation) return {}; + if (!snapshot.can_publish() || !snapshot.resources || !device || snapshot.display_generation != display_generation || !snapshot.ring_generation) { + return {}; + } const auto imported = std::dynamic_pointer_cast(snapshot.resources); - if (!imported) return {}; + if (!imported) { + return {}; + } const auto &request = imported->request(); - if (request.display_id != display_id || request.display_generation != display_generation || - request.adapter_luid != vdd::from_windows_luid(render_adapter_luid)) return {}; + if (request.display_id != display_id || request.display_generation != display_generation || request.adapter_luid != vdd::from_windows_luid(render_adapter_luid)) { + return {}; + } Microsoft::WRL::ComPtr dxgi; Microsoft::WRL::ComPtr adapter; DXGI_ADAPTER_DESC adapter_desc {}; - if (FAILED(device->QueryInterface(IID_PPV_ARGS(&dxgi))) || FAILED(dxgi->GetAdapter(&adapter)) || - FAILED(adapter->GetDesc(&adapter_desc)) || adapter_desc.AdapterLuid.LowPart != render_adapter_luid.LowPart || - adapter_desc.AdapterLuid.HighPart != render_adapter_luid.HighPart) return {}; + if (FAILED(device->QueryInterface(IID_PPV_ARGS(&dxgi))) || FAILED(dxgi->GetAdapter(&adapter)) || FAILED(adapter->GetDesc(&adapter_desc)) || adapter_desc.AdapterLuid.LowPart != render_adapter_luid.LowPart || adapter_desc.AdapterLuid.HighPart != render_adapter_luid.HighPart) { + return {}; + } auto result = std::make_shared(); result->snapshot = snapshot; result->imported = imported; for (std::size_t slot = 0; slot < vdd::kFrameRingSlotCount; ++slot) { - if (FAILED(device->OpenSharedResource1(imported->texture_handle(slot), IID_PPV_ARGS(&result->textures[slot]))) || - FAILED(result->textures[slot].As(&result->mutexes[slot]))) return {}; + if (FAILED(device->OpenSharedResource1(imported->texture_handle(slot), IID_PPV_ARGS(&result->textures[slot]))) || FAILED(result->textures[slot].As(&result->mutexes[slot]))) { + return {}; + } D3D11_TEXTURE2D_DESC desc {}; result->textures[slot]->GetDesc(&desc); - if (desc.Width != request.width || desc.Height != request.height || desc.Format != request.format || - desc.MipLevels != 1 || desc.ArraySize != 1 || desc.SampleDesc.Count != 1 || desc.SampleDesc.Quality != 0) return {}; + if (desc.Width != request.width || desc.Height != request.height || desc.Format != request.format || desc.MipLevels != 1 || desc.ArraySize != 1 || desc.SampleDesc.Count != 1 || desc.SampleDesc.Quality != 0) { + return {}; + } } return result; } @@ -1900,30 +1886,37 @@ namespace { } const auto &request = ring.imported->request(); Microsoft::WRL::ComPtr source; - if (FAILED(surface->QueryInterface(IID_PPV_ARGS(&source)))) return FramePublishResult::Failed; + if (FAILED(surface->QueryInterface(IID_PPV_ARGS(&source)))) { + return FramePublishResult::Failed; + } D3D11_TEXTURE2D_DESC source_desc {}; source->GetDesc(&source_desc); - if (source_desc.Width != request.width || source_desc.Height != request.height || - source_desc.Format != request.format || source_desc.MipLevels != 1 || source_desc.ArraySize != 1 || - source_desc.SampleDesc.Count != 1 || source_desc.SampleDesc.Quality != 0) { + if (source_desc.Width != request.width || source_desc.Height != request.height || source_desc.Format != request.format || source_desc.MipLevels != 1 || source_desc.ArraySize != 1 || source_desc.SampleDesc.Count != 1 || source_desc.SampleDesc.Quality != 0) { return FramePublishResult::ModeMismatch; } Microsoft::WRL::ComPtr source_device; source->GetDevice(&source_device); Microsoft::WRL::ComPtr source_identity, target_identity; - if (!source_device || FAILED(source_device.As(&source_identity)) || FAILED(device->QueryInterface(IID_PPV_ARGS(&target_identity))) || - source_identity.Get() != target_identity.Get()) return FramePublishResult::Failed; + if (!source_device || FAILED(source_device.As(&source_identity)) || FAILED(device->QueryInterface(IID_PPV_ARGS(&target_identity))) || source_identity.Get() != target_identity.Get()) { + return FramePublishResult::Failed; + } for (std::size_t slot = 0; slot < vdd::kFrameRingSlotCount; ++slot) { - if (!ring.snapshot.can_publish()) return FramePublishResult::PublishedOrDropped; + if (!ring.snapshot.can_publish()) { + return FramePublishResult::PublishedOrDropped; + } auto acquired_key = std::uint64_t {0}; HRESULT acquire = ring.mutexes[slot]->AcquireSync(0, 0); if (acquire == WAIT_TIMEOUT) { acquire = ring.mutexes[slot]->AcquireSync(1, 0); acquired_key = 1; } - if (acquire == WAIT_TIMEOUT) continue; - if (acquire != S_OK) return FramePublishResult::Failed; + if (acquire == WAIT_TIMEOUT) { + continue; + } + if (acquire != S_OK) { + return FramePublishResult::Failed; + } const auto release_unpublished = [&]() { return vdd::release_unpublished_slot(ring.snapshot, acquired_key, [&](const std::uint64_t key) { return ring.mutexes[slot]->ReleaseSync(key) == S_OK; @@ -1970,7 +1963,9 @@ namespace { metadata.acquired_qpc = static_cast(captured_qpc.QuadPart); metadata.reserved = 0; MemoryBarrier(); - if (ring.mutexes[slot]->ReleaseSync(1) != S_OK) return FramePublishResult::Failed; + if (ring.mutexes[slot]->ReleaseSync(1) != S_OK) { + return FramePublishResult::Failed; + } (void) SetEvent(ring.imported->event_handle()); return FramePublishResult::PublishedOrDropped; } @@ -1982,9 +1977,7 @@ namespace { class SwapChainProcessor { public: - SwapChainProcessor(IDDCX_SWAPCHAIN swapchain, HANDLE next_surface_available, - const std::uint64_t display_id, const std::uint64_t display_generation, - FrameRingSnapshotProvider frame_ring_snapshot_provider): + SwapChainProcessor(IDDCX_SWAPCHAIN swapchain, HANDLE next_surface_available, const std::uint64_t display_id, const std::uint64_t display_generation, FrameRingSnapshotProvider frame_ring_snapshot_provider): swapchain_ {swapchain}, next_surface_available_ {next_surface_available}, display_id_ {display_id}, @@ -2055,10 +2048,8 @@ namespace { return true; } - const auto wait_ms = static_cast((std::min)( - (std::max)(timeout.count(), 0), - MAXDWORD - )); + const auto wait_ms = static_cast((std::min) ((std::max) (timeout.count(), 0), + MAXDWORD)); const DWORD wait_result = WaitForSingleObject(worker_.native_handle(), wait_ms); if (wait_result == WAIT_OBJECT_0) { worker_.join(); @@ -2093,10 +2084,13 @@ namespace { Microsoft::WRL::ComPtr frame_import_device(const LUID &requested_luid) { #if defined(VDD_ENABLE_FRAME_TRANSPORT) std::lock_guard lock {device_mutex_}; - if (!device_ready_ || requested_luid.LowPart != render_adapter_luid_.LowPart || - requested_luid.HighPart != render_adapter_luid_.HighPart) return {}; + if (!device_ready_ || requested_luid.LowPart != render_adapter_luid_.LowPart || requested_luid.HighPart != render_adapter_luid_.HighPart) { + return {}; + } Microsoft::WRL::ComPtr result; - if (FAILED(device_.As(&result))) return {}; + if (FAILED(device_.As(&result))) { + return {}; + } return result; #else (void) requested_luid; @@ -2172,8 +2166,8 @@ namespace { assignment_pending = false; std::unique_lock lock {assignment_mutex_}; if (!assignment_changed_.wait_for(lock, kSwapchainProcessorTeardownTimeout, [this]() { - return assign_completed_; - })) { + return assign_completed_; + })) { assignment_pending = true; TraceLoggingWrite(g_trace_provider, "SwapChainDeleteDeferredForAssignCompletion"); TraceEvents(TRACE_LEVEL_WARNING, TRACE_SWAPCHAIN, "SwapChainDeleteDeferredForAssignCompletion"); @@ -2292,9 +2286,9 @@ namespace { Microsoft::WRL::ComPtr adapter; DXGI_ADAPTER_DESC desc {}; const bool is_assigned_hardware_device = device_ && SUCCEEDED(device_.As(&dxgi)) && - SUCCEEDED(dxgi->GetAdapter(&adapter)) && SUCCEEDED(adapter->GetDesc(&desc)) && - desc.AdapterLuid.LowPart == render_adapter_luid.LowPart && - desc.AdapterLuid.HighPart == render_adapter_luid.HighPart && device_context_; + SUCCEEDED(dxgi->GetAdapter(&adapter)) && SUCCEEDED(adapter->GetDesc(&desc)) && + desc.AdapterLuid.LowPart == render_adapter_luid.LowPart && + desc.AdapterLuid.HighPart == render_adapter_luid.HighPart && device_context_; std::lock_guard lock {device_mutex_}; render_adapter_luid_ = is_assigned_hardware_device ? render_adapter_luid : LUID {}; device_ready_ = is_assigned_hardware_device; @@ -2432,18 +2426,25 @@ namespace { delete_swapchain(); return; } - if (!frame_ring_producer_ || frame_ring_producer_->snapshot.ring_generation != snapshot.ring_generation || - frame_ring_producer_->snapshot.display_generation != snapshot.display_generation) { + if (!frame_ring_producer_ || frame_ring_producer_->snapshot.ring_generation != snapshot.ring_generation || frame_ring_producer_->snapshot.display_generation != snapshot.display_generation) { frame_ring_producer_ = open_frame_ring_for_producer( - snapshot, producer_device.Get(), render_adapter_luid, display_id_, display_generation_ + snapshot, + producer_device.Get(), + render_adapter_luid, + display_id_, + display_generation_ ); } else { frame_ring_producer_->snapshot = snapshot; frame_ring_producer_->imported = std::dynamic_pointer_cast(snapshot.resources); } const auto publish_result = frame_ring_producer_ ? publish_frame_to_ring( - *frame_ring_producer_, surface.Get(), device_.Get(), device_context_.Get() - ) : FramePublishResult::PublishedOrDropped; + *frame_ring_producer_, + surface.Get(), + device_.Get(), + device_context_.Get() + ) : + FramePublishResult::PublishedOrDropped; if (publish_result == FramePublishResult::ModeMismatch) { // Keep servicing the IddCx swapchain, but retire this ring. The // host's bounded first-frame/stall probe will reopen it against @@ -2505,7 +2506,6 @@ namespace { } } } - } #if defined(VDD_ENABLE_FRAME_TRANSPORT) @@ -2518,13 +2518,13 @@ namespace { frame_surface_mode_.reset(); } Microsoft::WRL::ComPtr texture; - if (!surface || FAILED(surface->QueryInterface(IID_PPV_ARGS(&texture)))) return; + if (!surface || FAILED(surface->QueryInterface(IID_PPV_ARGS(&texture)))) { + return; + } D3D11_TEXTURE2D_DESC desc {}; texture->GetDesc(&desc); FrameTransportSurfaceMode mode {}; - if (desc.Width < vdd::kMinWidth || desc.Width > vdd::kMaxWidth || - desc.Height < vdd::kMinHeight || desc.Height > vdd::kMaxHeight || - desc.MipLevels != 1 || desc.ArraySize != 1 || desc.SampleDesc.Count != 1 || desc.SampleDesc.Quality != 0) { + if (desc.Width < vdd::kMinWidth || desc.Width > vdd::kMaxWidth || desc.Height < vdd::kMinHeight || desc.Height > vdd::kMaxHeight || desc.MipLevels != 1 || desc.ArraySize != 1 || desc.SampleDesc.Count != 1 || desc.SampleDesc.Quality != 0) { return; } if (desc.Format == DXGI_FORMAT_B8G8R8A8_UNORM) { @@ -2652,7 +2652,7 @@ namespace { std::vector> &processors, const DeferredSwapChainCleanup deferred_cleanup = DeferredSwapChainCleanup::CloseOwned ) { - for (auto &processor: processors) { + for (auto &processor : processors) { stop_swapchain_processor(processor, deferred_cleanup); } processors.clear(); @@ -2672,14 +2672,14 @@ namespace { } void abandon_swapchain_processors_for_shutdown(std::vector> &processors) { - for (auto &processor: processors) { + for (auto &processor : processors) { abandon_swapchain_processor_for_shutdown(processor); } processors.clear(); } void request_stop_swapchain_processors(std::vector> &processors) { - for (auto &processor: processors) { + for (auto &processor : processors) { request_stop_swapchain_processor(processor); } } @@ -2719,7 +2719,7 @@ namespace { const std::chrono::steady_clock::time_point deadline ) { bool all_stopped = true; - for (auto &processor: processors) { + for (auto &processor : processors) { if (!try_stop_swapchain_processor_for_monitor_departure(processor, deadline)) { all_stopped = false; } @@ -2761,7 +2761,7 @@ namespace { const std::chrono::steady_clock::time_point deadline ) { bool all_stopped = true; - for (auto &processor: processors) { + for (auto &processor : processors) { if (!try_stop_swapchain_processor_for_unassign(processor, deadline)) { all_stopped = false; } @@ -2784,7 +2784,7 @@ namespace { std::vector> &finished_processors ) { std::uint32_t cleaned = 0; - for (auto &processor: processors) { + for (auto &processor : processors) { if (processor && processor->has_stopped()) { finished_processors.push_back(std::move(processor)); ++cleaned; @@ -2824,8 +2824,9 @@ namespace { #if defined(VDD_ENABLE_FRAME_TRANSPORT) std::lock_guard lock {mutex_}; const auto record = monitors_.find(display_id); - if (record == monitors_.end() || record->second.departing || record->second.permanent || - record->second.descriptor.generation != display_generation || !record->second.swapchain_processor) return {}; + if (record == monitors_.end() || record->second.departing || record->second.permanent || record->second.descriptor.generation != display_generation || !record->second.swapchain_processor) { + return {}; + } return record->second.swapchain_processor->frame_import_device(adapter_luid); #else (void) display_id; @@ -2836,15 +2837,19 @@ namespace { } std::optional frame_transport_target( - const std::uint64_t display_id, const std::uint64_t display_generation + const std::uint64_t display_id, + const std::uint64_t display_generation ) { #if defined(VDD_ENABLE_FRAME_TRANSPORT) std::lock_guard lock {mutex_}; const auto record = monitors_.find(display_id); - if (record == monitors_.end() || record->second.departing || record->second.permanent || - record->second.descriptor.generation != display_generation || !record->second.swapchain_processor) return {}; + if (record == monitors_.end() || record->second.departing || record->second.permanent || record->second.descriptor.generation != display_generation || !record->second.swapchain_processor) { + return {}; + } const auto mode = record->second.swapchain_processor->frame_transport_surface_mode(); - if (!mode) return {}; + if (!mode) { + return {}; + } vdd::FrameTransportTarget target {}; target.lease_id = record->second.descriptor.lease_id; target.display_id = display_id; @@ -2882,8 +2887,8 @@ namespace { IDDCX_ADAPTER_CAPS caps {}; caps.Size = sizeof(caps); caps.Flags = has_hdr_iddcx_ddi() && hdr_capabilities.fp16_swapchain ? - IDDCX_ADAPTER_FLAGS_CAN_PROCESS_FP16 : - IDDCX_ADAPTER_FLAGS_NONE; + IDDCX_ADAPTER_FLAGS_CAN_PROCESS_FP16 : + IDDCX_ADAPTER_FLAGS_NONE; caps.MaxMonitorsSupported = kMaxPermanentDisplays + kMaxTemporaryDisplays; caps.EndPointDiagnostics.Size = sizeof(caps.EndPointDiagnostics); // The virtual sink does not render an endpoint image or apply the OS @@ -2891,8 +2896,8 @@ namespace { // SetGammaRamp callback registered for FP16/HDR diagnostics, but do not // advertise software gamma support until the frame path applies it. caps.EndPointDiagnostics.GammaSupport = hdr_capabilities.endpoint_gamma_transform ? - IDDCX_FEATURE_IMPLEMENTATION_SOFTWARE : - IDDCX_FEATURE_IMPLEMENTATION_NONE; + IDDCX_FEATURE_IMPLEMENTATION_SOFTWARE : + IDDCX_FEATURE_IMPLEMENTATION_NONE; caps.EndPointDiagnostics.TransmissionType = IDDCX_TRANSMISSION_TYPE_WIRED_OTHER; caps.EndPointDiagnostics.pEndPointFriendlyName = const_cast(L"Sunshine Virtual Display Adapter"); caps.EndPointDiagnostics.pEndPointManufacturerName = const_cast(L"Sunshine"); @@ -3003,16 +3008,16 @@ namespace { { std::lock_guard lock {mutex_}; active_permanent_descriptors.reserve(monitors_.size()); - for (const auto &[display_id, record]: monitors_) { + for (const auto &[display_id, record] : monitors_) { if (record.permanent) { active_permanent_descriptors.push_back(record.descriptor); } } } - for (const auto &descriptor: active_permanent_descriptors) { + for (const auto &descriptor : active_permanent_descriptors) { if (depart_display(descriptor.display_id) != vdd::BackendError::None) { - for (const auto &restore_descriptor: active_permanent_descriptors) { + for (const auto &restore_descriptor : active_permanent_descriptors) { (void) arrive_display(restore_descriptor, true); } return vdd::BackendError::Failed; @@ -3024,10 +3029,10 @@ namespace { const auto descriptor = make_permanent_descriptor(manifest.profiles[index]); const auto result = arrive_display(descriptor, true); if (result.error != vdd::BackendError::None) { - for (const auto display_id: added) { + for (const auto display_id : added) { (void) depart_display(display_id); } - for (const auto &restore_descriptor: active_permanent_descriptors) { + for (const auto &restore_descriptor : active_permanent_descriptors) { (void) arrive_display(restore_descriptor, true); } return vdd::BackendError::Failed; @@ -3059,6 +3064,7 @@ namespace { struct RenderAdapterState { vdd::BackendError result {vdd::BackendError::Failed}; }; + auto state = std::make_shared(); { std::lock_guard lock {mutex_}; @@ -3159,9 +3165,11 @@ namespace { if (adapter && (preferred_render_adapter.HighPart != 0 || preferred_render_adapter.LowPart != 0)) { auto *adapter_object = reinterpret_cast(adapter); WdfObjectReference(adapter_object); + struct RenderAdapterState { vdd::BackendError result {vdd::BackendError::Failed}; }; + auto state = std::make_shared(); { std::lock_guard lock {mutex_}; @@ -3188,8 +3196,7 @@ namespace { render_adapter_thread.native_handle(), static_cast(kRenderAdapterTimeout.count()) ); - if (wait_result == WAIT_OBJECT_0 || - WaitForSingleObject(render_adapter_thread.native_handle(), 0) == WAIT_OBJECT_0) { + if (wait_result == WAIT_OBJECT_0 || WaitForSingleObject(render_adapter_thread.native_handle(), 0) == WAIT_OBJECT_0) { render_adapter_thread.join(); } else { TraceLoggingWrite( @@ -3257,9 +3264,7 @@ namespace { { std::unique_lock lock {mutex_}; shutting_down_ = true; - if (monitor_arrivals_in_flight_ > 0 || - monitor_departures_in_flight_ > 0 || - render_adapter_calls_in_flight_ > 0) { + if (monitor_arrivals_in_flight_ > 0 || monitor_departures_in_flight_ > 0 || render_adapter_calls_in_flight_ > 0) { departure_cv_.wait_for(lock, kMonitorDepartureTimeout, [&]() { return monitor_arrivals_in_flight_ == 0 && monitor_departures_in_flight_ == 0 && @@ -3267,9 +3272,7 @@ namespace { }); } - if (monitor_arrivals_in_flight_ > 0 || - monitor_departures_in_flight_ > 0 || - render_adapter_calls_in_flight_ > 0) { + if (monitor_arrivals_in_flight_ > 0 || monitor_departures_in_flight_ > 0 || render_adapter_calls_in_flight_ > 0) { TraceLoggingWrite( g_trace_provider, "BackendShutdownDeferredForInFlightLifecycle", @@ -3286,7 +3289,7 @@ namespace { { std::lock_guard lock {mutex_}; display_ids.reserve(monitors_.size()); - for (const auto &[display_id, record]: monitors_) { + for (const auto &[display_id, record] : monitors_) { if (!record.departing) { display_ids.push_back(display_id); } @@ -3294,7 +3297,7 @@ namespace { } std::vector failed_departures; - for (const auto display_id: display_ids) { + for (const auto display_id : display_ids) { if (depart_display(display_id) != vdd::BackendError::None) { failed_departures.push_back(display_id); } @@ -3302,7 +3305,7 @@ namespace { if (!failed_departures.empty()) { std::lock_guard lock {mutex_}; - for (const auto display_id: failed_departures) { + for (const auto display_id : failed_departures) { const auto monitor = monitors_.find(display_id); if (monitor == monitors_.end()) { continue; @@ -3346,7 +3349,7 @@ namespace { std::vector> orphaned_late_arrivals; { std::lock_guard lock {mutex_}; - for (auto &[display_id, record]: monitors_) { + for (auto &[display_id, record] : monitors_) { if (record.orphaned_late_arrival && !record.departing) { orphaned_late_arrivals.emplace_back(display_id, record.descriptor.generation); } @@ -3371,7 +3374,7 @@ namespace { } } finished_processors.clear(); - for (const auto &[display_id, generation]: orphaned_late_arrivals) { + for (const auto &[display_id, generation] : orphaned_late_arrivals) { // Fenced on the orphan's own generation: this retry runs with neither // the controller nor the backend-call lock held, so an unfenced depart // here could retract a monitor a concurrent create just arrived. @@ -3514,9 +3517,7 @@ namespace { }; void clear_lifecycle_unhealthy_if_settled_locked() { - if (monitor_arrivals_in_flight_ == 0 && - monitor_departures_in_flight_ == 0 && - render_adapter_calls_in_flight_ == 0) { + if (monitor_arrivals_in_flight_ == 0 && monitor_departures_in_flight_ == 0 && render_adapter_calls_in_flight_ == 0) { lifecycle_unhealthy_ = false; } } @@ -3592,9 +3593,7 @@ namespace { // descriptor's generation keeps a subsequent create's fresh // monitor (same display_id, new generation) out of reach of this // stale cleanup. - if (auto monitor = monitors_.find(requested_descriptor.display_id); - monitor != monitors_.end() && - monitor->second.descriptor.generation == requested_descriptor.generation) { + if (auto monitor = monitors_.find(requested_descriptor.display_id); monitor != monitors_.end() && monitor->second.descriptor.generation == requested_descriptor.generation) { monitor->second.orphaned_late_arrival = true; } } @@ -3670,11 +3669,7 @@ namespace { { std::lock_guard lock {mutex_}; const auto monitor = monitors_.find(descriptor.display_id); - if (monitor != monitors_.end() && - !monitor->second.permanent && - !monitor->second.arriving && - !monitor->second.departing && - monitor->second.descriptor.generation != descriptor.generation) { + if (monitor != monitors_.end() && !monitor->second.permanent && !monitor->second.arriving && !monitor->second.departing && monitor->second.descriptor.generation != descriptor.generation) { stale_generation = monitor->second.descriptor.generation; } } @@ -3863,8 +3858,7 @@ namespace { std::optional retained_dpi_value; { std::lock_guard lock {mutex_}; - if (const auto dpi = retained_dpi_values_by_display_id_.find(descriptor.display_id); - dpi != retained_dpi_values_by_display_id_.end()) { + if (const auto dpi = retained_dpi_values_by_display_id_.find(descriptor.display_id); dpi != retained_dpi_values_by_display_id_.end()) { retained_dpi_value = dpi->second; } } @@ -3990,9 +3984,7 @@ namespace { if (monitor == monitors_.end()) { return vdd::BackendError::None; } - if (expected_generation != 0 && - monitor->second.descriptor.generation != 0 && - monitor->second.descriptor.generation != expected_generation) { + if (expected_generation != 0 && monitor->second.descriptor.generation != 0 && monitor->second.descriptor.generation != expected_generation) { // The request was issued for a superseded record lineage (the store // record was removed and recreated while the requester held no lock). // The monitor that is up belongs to the current lineage; retracting @@ -4023,8 +4015,7 @@ namespace { monitor->second.departing = true; monitor_handle = monitor->second.monitor; - if (monitor->second.assign_callbacks_in_flight > 0 || - monitor->second.unassign_callbacks_in_flight > 0) { + if (monitor->second.assign_callbacks_in_flight > 0 || monitor->second.unassign_callbacks_in_flight > 0) { // DisplayConfig can remove a just-activated path while IddCx is still // unwinding swapchain callbacks. Mark departure first, then wait only // for known in-flight callbacks to restore or settle processor @@ -4042,8 +4033,7 @@ namespace { if (monitor == monitors_.end() || monitor->second.monitor != monitor_handle) { return vdd::BackendError::None; } - if (monitor->second.assign_callbacks_in_flight > 0 || - monitor->second.unassign_callbacks_in_flight > 0) { + if (monitor->second.assign_callbacks_in_flight > 0 || monitor->second.unassign_callbacks_in_flight > 0) { monitor->second.departing = false; TraceLoggingWrite( g_trace_provider, @@ -4063,15 +4053,13 @@ namespace { const bool cursor_processor_stopped = try_stop_cursor_processor_for_monitor_departure(cursor_processor_to_stop); if (!cursor_processor_stopped) { std::lock_guard lock {mutex_}; - if (auto monitor = monitors_.find(display_id); - monitor != monitors_.end() && - monitor->second.monitor == monitor_handle) { + if (auto monitor = monitors_.find(display_id); monitor != monitors_.end() && monitor->second.monitor == monitor_handle) { monitor->second.departing = false; monitor->second.cursor_processor = std::move(cursor_processor_to_stop); if (processor_to_stop) { monitor->second.swapchain_processor = std::move(processor_to_stop); } - for (auto &processor: retired_processors_to_stop) { + for (auto &processor : retired_processors_to_stop) { if (processor) { monitor->second.retired_swapchain_processors.push_back(std::move(processor)); } @@ -4109,14 +4097,12 @@ namespace { ); if (!active_processor_stopped || !retired_processors_stopped) { std::lock_guard lock {mutex_}; - if (auto monitor = monitors_.find(display_id); - monitor != monitors_.end() && - monitor->second.monitor == monitor_handle) { + if (auto monitor = monitors_.find(display_id); monitor != monitors_.end() && monitor->second.monitor == monitor_handle) { monitor->second.departing = false; if (processor_to_stop) { monitor->second.swapchain_processor = std::move(processor_to_stop); } - for (auto &processor: retired_processors_to_stop) { + for (auto &processor : retired_processors_to_stop) { if (processor) { monitor->second.retired_swapchain_processors.push_back(std::move(processor)); } @@ -4175,8 +4161,11 @@ namespace { std::unique_ptr processor; try { processor = std::make_unique( - args->hSwapChain, args->hNextSurfaceAvailable, context->display_id, - context->display_generation, frame_ring_snapshot_provider_ + args->hSwapChain, + args->hNextSurfaceAvailable, + context->display_id, + context->display_generation, + frame_ring_snapshot_provider_ ); } catch (...) { return STATUS_GRAPHICS_INDIRECT_DISPLAY_ABANDON_SWAPCHAIN; @@ -4325,7 +4314,7 @@ namespace { if (processor_to_stop) { record->second.retired_swapchain_processors.push_back(std::move(processor_to_stop)); } - for (auto &processor: retired_processors_to_stop) { + for (auto &processor : retired_processors_to_stop) { if (processor) { record->second.retired_swapchain_processors.push_back(std::move(processor)); } @@ -4508,13 +4497,13 @@ namespace { }, dispatcher {controller} #if defined(VDD_ENABLE_FRAME_TRANSPORT) - , frame_ring_lifetime {controller.store()} - , frame_ring_server {controller.store(), frame_ring_lifetime, frame_importer} + , + frame_ring_lifetime {controller.store()}, + frame_ring_server {controller.store(), frame_ring_lifetime, frame_importer} #endif { #if defined(VDD_ENABLE_FRAME_TRANSPORT) - backend.set_frame_ring_snapshot_provider([this](const std::uint64_t display_id, - const std::uint64_t generation) { + backend.set_frame_ring_snapshot_provider([this](const std::uint64_t display_id, const std::uint64_t generation) { return frame_ring_snapshot(display_id, generation); }); #endif @@ -4568,9 +4557,7 @@ namespace { return {vdd::IoctlStatus::BackendFailed, 0, {}}; } #if defined(VDD_ENABLE_FRAME_TRANSPORT) - if (backend.lifecycle_unhealthy() && - (io_control_code == vdd::kIoctlQueryFrameTransportTarget || - io_control_code == vdd::kIoctlRegisterFrameRing)) { + if (backend.lifecycle_unhealthy() && (io_control_code == vdd::kIoctlQueryFrameTransportTarget || io_control_code == vdd::kIoctlRegisterFrameRing)) { return {vdd::IoctlStatus::BackendFailed, 0, {}}; } #endif @@ -4586,13 +4573,12 @@ namespace { return {vdd::IoctlStatus::BackendFailed, 0, {}}; } #if defined(VDD_ENABLE_FRAME_TRANSPORT) - if (io_control_code == vdd::kIoctlQueryFrameTransportTarget || - io_control_code == vdd::kIoctlRegisterFrameRing || - io_control_code == vdd::kIoctlClearFrameRing) { + if (io_control_code == vdd::kIoctlQueryFrameTransportTarget || io_control_code == vdd::kIoctlRegisterFrameRing || io_control_code == vdd::kIoctlClearFrameRing) { const auto peer = vdd::capture_frame_request_peer(requestor_pid); - if (!peer) return {vdd::IoctlStatus::InvalidRequest, 0, {}}; - return dispatch_frame_transport(io_control_code, input, input_buffer_length, output, - output_buffer_length, *peer, now); + if (!peer) { + return {vdd::IoctlStatus::InvalidRequest, 0, {}}; + } + return dispatch_frame_transport(io_control_code, input, input_buffer_length, output, output_buffer_length, *peer, now); } #else (void) requestor_pid; @@ -4624,16 +4610,23 @@ namespace { #if defined(VDD_ENABLE_FRAME_TRANSPORT) vdd::FrameRingSnapshot frame_ring_snapshot( - const std::uint64_t display_id, const std::uint64_t generation + const std::uint64_t display_id, + const std::uint64_t generation ) { std::unique_lock lock {controller_mutex, std::try_to_lock}; - if (!lock.owns_lock()) return {}; + if (!lock.owns_lock()) { + return {}; + } return frame_ring_lifetime.snapshot(display_id, generation, lease_clock_now()); } vdd::IoctlDispatchResult dispatch_frame_transport( - const ULONG code, const void *input, const std::size_t input_size, void *output, - const std::size_t output_size, const vdd::FrameRequestPeer &peer, + const ULONG code, + const void *input, + const std::size_t input_size, + void *output, + const std::size_t output_size, + const vdd::FrameRequestPeer &peer, const std::chrono::steady_clock::time_point now ) { if (code == vdd::kIoctlQueryFrameTransportTarget) { @@ -4646,9 +4639,13 @@ namespace { vdd::FrameTransportTargetRequest request {}; std::memcpy(&request, input, sizeof(request)); auto target = frame_ring_server.query_target(peer, request, now); - if (!target) return {vdd::IoctlStatus::InvalidRequest, 0, {}}; + if (!target) { + return {vdd::IoctlStatus::InvalidRequest, 0, {}}; + } const auto active_mode = backend.frame_transport_target(target->display_id, target->display_generation); - if (!active_mode) return {vdd::IoctlStatus::BackendFailed, 0, {}}; + if (!active_mode) { + return {vdd::IoctlStatus::BackendFailed, 0, {}}; + } target->width = active_mode->width; target->height = active_mode->height; target->adapter_luid = active_mode->adapter_luid; @@ -4674,27 +4671,32 @@ namespace { target_request.display_id = request.display_id; target_request.owner_capability = request.owner_capability; const auto authorized_target = frame_ring_server.query_target(peer, target_request, now); - if (!authorized_target) return {vdd::IoctlStatus::InvalidRequest, 0, {}}; + if (!authorized_target) { + return {vdd::IoctlStatus::InvalidRequest, 0, {}}; + } const auto active_mode = backend.frame_transport_target( - authorized_target->display_id, authorized_target->display_generation + authorized_target->display_id, + authorized_target->display_generation ); - if (!active_mode || request.display_generation != active_mode->display_generation || - request.width != active_mode->width || request.height != active_mode->height || - request.adapter_luid != active_mode->adapter_luid || request.format != active_mode->format || - request.color_space != active_mode->color_space) { + if (!active_mode || request.display_generation != active_mode->display_generation || request.width != active_mode->width || request.height != active_mode->height || request.adapter_luid != active_mode->adapter_luid || request.format != active_mode->format || request.color_space != active_mode->color_space) { return {vdd::IoctlStatus::NotFound, 0, {}}; } const auto import_device = backend.frame_import_device_for( - request.display_id, request.display_generation, vdd::to_windows_luid(request.adapter_luid) + request.display_id, + request.display_generation, + vdd::to_windows_luid(request.adapter_luid) ); - if (!import_device) return {vdd::IoctlStatus::BackendFailed, 0, {}}; + if (!import_device) { + return {vdd::IoctlStatus::BackendFailed, 0, {}}; + } vdd::WindowsFrameImporter importer {import_device.Get()}; const auto result = frame_ring_server.register_ring(peer, request, now, importer); if (result.status != vdd::FrameWireStatus::Success) { - return {result.status == vdd::FrameWireStatus::InvalidInput ? vdd::IoctlStatus::InvalidRequest : - result.status == vdd::FrameWireStatus::StaleGeneration ? vdd::IoctlStatus::NotFound : - result.status == vdd::FrameWireStatus::ImportFailed ? vdd::IoctlStatus::BackendFailed : - vdd::IoctlStatus::InvalidRequest, 0, {}}; + return {result.status == vdd::FrameWireStatus::InvalidInput ? vdd::IoctlStatus::InvalidRequest : result.status == vdd::FrameWireStatus::StaleGeneration ? vdd::IoctlStatus::NotFound : + result.status == vdd::FrameWireStatus::ImportFailed ? vdd::IoctlStatus::BackendFailed : + vdd::IoctlStatus::InvalidRequest, + 0, + {}}; } std::memcpy(output, &result.reply, sizeof(result.reply)); return {vdd::IoctlStatus::Success, sizeof(result.reply), {}}; @@ -4703,14 +4705,17 @@ namespace { if (!input || input_size != sizeof(vdd::FrameRingClearRequest)) { return {vdd::IoctlStatus::InvalidInputBuffer, 0, {}}; } - if (output_size != 0) return {vdd::IoctlStatus::InvalidOutputBuffer, 0, {}}; + if (output_size != 0) { + return {vdd::IoctlStatus::InvalidOutputBuffer, 0, {}}; + } vdd::FrameRingClearRequest request {}; std::memcpy(&request, input, sizeof(request)); const auto result = frame_ring_server.clear_ring(peer, request, now); if (result != vdd::FrameWireStatus::Success) { - return {result == vdd::FrameWireStatus::StaleGeneration ? vdd::IoctlStatus::NotFound : - result == vdd::FrameWireStatus::ImportFailed ? vdd::IoctlStatus::BackendFailed : - vdd::IoctlStatus::InvalidRequest, 0, {}}; + return {result == vdd::FrameWireStatus::StaleGeneration ? vdd::IoctlStatus::NotFound : result == vdd::FrameWireStatus::ImportFailed ? vdd::IoctlStatus::BackendFailed : + vdd::IoctlStatus::InvalidRequest, + 0, + {}}; } return {vdd::IoctlStatus::Success, 0, {}}; } @@ -4865,8 +4870,8 @@ namespace { } return output ? - WdfRequestRetrieveOutputBuffer(request, length, buffer, nullptr) : - WdfRequestRetrieveInputBuffer(request, length, buffer, nullptr); + WdfRequestRetrieveOutputBuffer(request, length, buffer, nullptr) : + WdfRequestRetrieveInputBuffer(request, length, buffer, nullptr); } } // namespace diff --git a/src/driver/windows_driver_modes.cpp b/src/driver/windows_driver_modes.cpp index 4b66c77..a1747e0 100644 --- a/src/driver/windows_driver_modes.cpp +++ b/src/driver/windows_driver_modes.cpp @@ -15,64 +15,9 @@ namespace virtual_display::driver { std::uint32_t refresh_rate_millihz; }; - constexpr std::array kDefaultWindowsDriverModes {{ - {800, 600, 30'000}, - {800, 600, 60'000}, - {800, 600, 72'000}, - {800, 600, 90'000}, - {800, 600, 120'000}, - {800, 600, 144'000}, - {800, 600, 240'000}, - {1280, 720, 30'000}, - {1280, 720, 60'000}, - {1280, 720, 72'000}, - {1280, 720, 90'000}, - {1280, 720, 120'000}, - {1280, 720, 144'000}, - {1366, 768, 30'000}, - {1366, 768, 60'000}, - {1366, 768, 72'000}, - {1366, 768, 90'000}, - {1366, 768, 120'000}, - {1366, 768, 144'000}, - {1366, 768, 240'000}, - {1920, 1080, 30'000}, - {1920, 1080, 60'000}, - {1920, 1080, 72'000}, - {1920, 1080, 90'000}, - {1920, 1080, 120'000}, - {1920, 1080, 144'000}, - {1920, 1080, 240'000}, - {2560, 1440, 30'000}, - {2560, 1440, 60'000}, - {2560, 1440, 72'000}, - {2560, 1440, 90'000}, - {2560, 1440, 120'000}, - {2560, 1440, 144'000}, - {2560, 1440, 240'000}, - {3840, 2160, 30'000}, - {3840, 2160, 60'000}, - {3840, 2160, 72'000}, - {3840, 2160, 90'000}, - {3840, 2160, 120'000}, - {3840, 2160, 144'000}, - {3840, 2160, 240'000}, - {5120, 1440, 30'000}, - {5120, 1440, 60'000}, - {5120, 1440, 120'000}, - {5120, 1440, 144'000}, - {5120, 1440, 175'000}, - {5120, 1440, 240'000}, - {5120, 1440, 480'000} - }}; - - constexpr std::array kPreferredModeScalePercent {{ - 100, - 50, - 75, - 125, - 150 - }}; + constexpr std::array kDefaultWindowsDriverModes {{{800, 600, 30'000}, {800, 600, 60'000}, {800, 600, 72'000}, {800, 600, 90'000}, {800, 600, 120'000}, {800, 600, 144'000}, {800, 600, 240'000}, {1280, 720, 30'000}, {1280, 720, 60'000}, {1280, 720, 72'000}, {1280, 720, 90'000}, {1280, 720, 120'000}, {1280, 720, 144'000}, {1366, 768, 30'000}, {1366, 768, 60'000}, {1366, 768, 72'000}, {1366, 768, 90'000}, {1366, 768, 120'000}, {1366, 768, 144'000}, {1366, 768, 240'000}, {1920, 1080, 30'000}, {1920, 1080, 60'000}, {1920, 1080, 72'000}, {1920, 1080, 90'000}, {1920, 1080, 120'000}, {1920, 1080, 144'000}, {1920, 1080, 240'000}, {2560, 1440, 30'000}, {2560, 1440, 60'000}, {2560, 1440, 72'000}, {2560, 1440, 90'000}, {2560, 1440, 120'000}, {2560, 1440, 144'000}, {2560, 1440, 240'000}, {3840, 2160, 30'000}, {3840, 2160, 60'000}, {3840, 2160, 72'000}, {3840, 2160, 90'000}, {3840, 2160, 120'000}, {3840, 2160, 144'000}, {3840, 2160, 240'000}, {5120, 1440, 30'000}, {5120, 1440, 60'000}, {5120, 1440, 120'000}, {5120, 1440, 144'000}, {5120, 1440, 175'000}, {5120, 1440, 240'000}, {5120, 1440, 480'000}}}; + + constexpr std::array kPreferredModeScalePercent {{100, 50, 75, 125, 150}}; WindowsDriverModeShape mode_shape_from_spec(const ModeSpec &spec) { return active_windows_driver_mode_shape(spec.width, spec.height, spec.refresh_rate_millihz); @@ -90,9 +35,7 @@ namespace virtual_display::driver { static_cast(base.height) * scale_percent / 100ull ); - if (width < kMinWidth || width > kMaxWidth || - height < kMinHeight || height > kMaxHeight || - refresh_rate_millihz < kMinRefreshRateMilliHz) { + if (width < kMinWidth || width > kMaxWidth || height < kMinHeight || height > kMaxHeight || refresh_rate_millihz < kMinRefreshRateMilliHz) { return std::nullopt; } @@ -112,7 +55,7 @@ namespace virtual_display::driver { // near-identical fractional one is what stops a "60 Hz" request from // landing on 59.94. Callers that genuinely want the fractional timing // select it by preferred index or by its exact vSyncFreq rational. - for (const auto scale_percent: kPreferredModeScalePercent) { + for (const auto scale_percent : kPreferredModeScalePercent) { if (const auto scaled = scaled_mode_shape(preferred, scale_percent, preferred.refresh_rate_millihz)) { const auto index = append_unique_windows_driver_mode(modes, *scaled); if (scale_percent == 100) { @@ -121,7 +64,7 @@ namespace virtual_display::driver { } } - for (const auto multiplier: {2ull, 4ull}) { + for (const auto multiplier : {2ull, 4ull}) { const auto multiplied_refresh_rate_millihz = clamp_windows_driver_u32( static_cast(preferred.refresh_rate_millihz) * multiplier ); @@ -150,9 +93,7 @@ namespace virtual_display::driver { std::array key {}; std::copy(edid.begin(), edid.end(), key.begin()); auto &entry = entries_[key]; - if (entry.references != 0 && - (entry.mode.preferred != mode || - entry.mode.requested_resolution_only != requested_resolution_only)) { + if (entry.references != 0 && (entry.mode.preferred != mode || entry.mode.requested_resolution_only != requested_resolution_only)) { return false; } entry.mode = {mode, requested_resolution_only}; @@ -202,7 +143,7 @@ namespace virtual_display::driver { std::uint32_t clamp_windows_driver_u32(const std::uint64_t value) { return static_cast( - (std::min)(value, (std::numeric_limits::max)()) + (std::min) (value, (std::numeric_limits::max)()) ); } @@ -218,7 +159,7 @@ namespace virtual_display::driver { height, static_cast(width) * static_cast(height) * - static_cast((std::max)(refresh_rate_millihz, 1u)) / + static_cast((std::max) (refresh_rate_millihz, 1u)) / 1000ull, refresh_rate_millihz }; @@ -230,9 +171,7 @@ namespace virtual_display::driver { ) { for (std::size_t index = 0; index < modes.size(); ++index) { const auto &mode = modes[index]; - if (mode.width == candidate.width && - mode.height == candidate.height && - mode.refresh_rate_millihz == candidate.refresh_rate_millihz) { + if (mode.width == candidate.width && mode.height == candidate.height && mode.refresh_rate_millihz == candidate.refresh_rate_millihz) { return static_cast(index); } } @@ -257,17 +196,14 @@ namespace virtual_display::driver { const std::optional &preferred, const bool requested_resolution_only ) { - if (requested_resolution_only && - (!preferred || preferred->width < kMinWidth || preferred->width > kMaxWidth || - preferred->height < kMinHeight || preferred->height > kMaxHeight || - preferred->refresh_rate_millihz < kMinRefreshRateMilliHz)) { + if (requested_resolution_only && (!preferred || preferred->width < kMinWidth || preferred->width > kMaxWidth || preferred->height < kMinHeight || preferred->height > kMaxHeight || preferred->refresh_rate_millihz < kMinRefreshRateMilliHz)) { return build_windows_driver_mode_shapes(std::nullopt); } std::vector modes; modes.reserve(kDefaultWindowsDriverModes.size() + (preferred ? kPreferredModeScalePercent.size() * 3u : 0u)); - for (const auto &spec: kDefaultWindowsDriverModes) { + for (const auto &spec : kDefaultWindowsDriverModes) { modes.push_back(mode_shape_from_spec(spec)); } @@ -304,7 +240,7 @@ namespace virtual_display::driver { std::uint64_t numerator, std::uint32_t denominator ) { - denominator = (std::max)(denominator, 1u); + denominator = (std::max) (denominator, 1u); if (numerator == 0) { return {0, 1}; } @@ -317,12 +253,12 @@ namespace virtual_display::driver { } WindowsDriverSignalFrequencies windows_driver_signal_frequencies(const WindowsDriverModeShape &shape) { - const auto total_height = (std::max)(shape.total_height, shape.height); + const auto total_height = (std::max) (shape.total_height, shape.height); return { - make_windows_driver_frequency_rational((std::max)(shape.refresh_rate_millihz, 1u), 1000), + make_windows_driver_frequency_rational((std::max) (shape.refresh_rate_millihz, 1u), 1000), make_windows_driver_frequency_rational( - static_cast((std::max)(shape.refresh_rate_millihz, 1u)) * - static_cast((std::max)(total_height, 1u)), + static_cast((std::max) (shape.refresh_rate_millihz, 1u)) * + static_cast((std::max) (total_height, 1u)), 1000 ) }; diff --git a/src/driver/windows_driver_state.cpp b/src/driver/windows_driver_state.cpp index a713ba3..14f38a2 100644 --- a/src/driver/windows_driver_state.cpp +++ b/src/driver/windows_driver_state.cpp @@ -92,11 +92,7 @@ namespace virtual_display::driver { std::size_t offset {}; std::uint32_t schema_version {}; std::uint32_t profile_count {}; - if (!read_u32(blob, offset, schema_version) || - !read_u32(blob, offset, profile_count) || - schema_version != kWindowsDriverPersistentStateSchemaVersion || - profile_count > kWindowsDriverMaxTemporaryDisplays || - blob.size() != kTemporaryDisplayProfilesHeaderBytes + profile_count * kTemporaryDisplayProfileBytes) { + if (!read_u32(blob, offset, schema_version) || !read_u32(blob, offset, profile_count) || schema_version != kWindowsDriverPersistentStateSchemaVersion || profile_count > kWindowsDriverMaxTemporaryDisplays || blob.size() != kTemporaryDisplayProfilesHeaderBytes + profile_count * kTemporaryDisplayProfileBytes) { return std::nullopt; } @@ -104,12 +100,7 @@ namespace virtual_display::driver { profiles.reserve(profile_count); for (std::uint32_t index = 0; index < profile_count; ++index) { TemporaryDisplayProfile profile {}; - if (!read_u64(blob, offset, profile.display_id) || - !read_u32(blob, offset, profile.connector_index) || - !read_guid(blob, offset, profile.container_id) || - !read_u32(blob, offset, profile.edid_product_code) || - !read_u32(blob, offset, profile.edid_serial_number) || - !valid_temporary_display_profile(profile.display_id, profile.connector_index)) { + if (!read_u64(blob, offset, profile.display_id) || !read_u32(blob, offset, profile.connector_index) || !read_guid(blob, offset, profile.container_id) || !read_u32(blob, offset, profile.edid_product_code) || !read_u32(blob, offset, profile.edid_serial_number) || !valid_temporary_display_profile(profile.display_id, profile.connector_index)) { return std::nullopt; } @@ -126,7 +117,7 @@ namespace virtual_display::driver { blob.reserve(kTemporaryDisplayProfilesHeaderBytes + profiles.size() * kTemporaryDisplayProfileBytes); append_u32(blob, kWindowsDriverPersistentStateSchemaVersion); append_u32(blob, static_cast(profiles.size())); - for (const auto &entry: profiles) { + for (const auto &entry : profiles) { append_u64(blob, entry.display_id); append_u32(blob, entry.connector_index); append_guid(blob, entry.container_id); @@ -196,7 +187,7 @@ namespace virtual_display::driver { const std::span profiles ) { std::map reservations; - for (const auto &profile: profiles) { + for (const auto &profile : profiles) { reservations.emplace(profile.display_id, profile.connector_index); } return reservations; diff --git a/src/driver/windows_frame_importer.cpp b/src/driver/windows_frame_importer.cpp index 70b33e3..7844806 100644 --- a/src/driver/windows_frame_importer.cpp +++ b/src/driver/windows_frame_importer.cpp @@ -1,17 +1,20 @@ #include "virtual_display/driver/windows_frame_importer.h" + #include "virtual_display/driver/windows_control_protocol.h" #ifdef _WIN32 -#include + #include namespace virtual_display::driver { namespace { std::uint64_t file_time(const FILETIME &t) { return (static_cast(t.dwHighDateTime) << 32) | t.dwLowDateTime; } + std::uint64_t process_start(HANDLE process) { FILETIME created {}, exited {}, kernel {}, user {}; return GetProcessTimes(process, &created, &exited, &kernel, &user) ? file_time(created) : 0; } + bool device_matches(ID3D11Device1 *device, const AdapterLuid &luid) { Microsoft::WRL::ComPtr dxgi; Microsoft::WRL::ComPtr adapter; @@ -25,89 +28,121 @@ namespace virtual_display::driver { Microsoft::WRL::ComPtr result; Microsoft::WRL::ComPtr factory; Microsoft::WRL::ComPtr adapter; - if (FAILED(CreateDXGIFactory1(IID_PPV_ARGS(&factory))) || - FAILED(factory->EnumAdapterByLuid(to_windows_luid(luid), IID_PPV_ARGS(&adapter)))) return {}; + if (FAILED(CreateDXGIFactory1(IID_PPV_ARGS(&factory))) || FAILED(factory->EnumAdapterByLuid(to_windows_luid(luid), IID_PPV_ARGS(&adapter)))) { + return {}; + } static constexpr D3D_FEATURE_LEVEL levels[] { - D3D_FEATURE_LEVEL_11_1, D3D_FEATURE_LEVEL_11_0, D3D_FEATURE_LEVEL_10_1, D3D_FEATURE_LEVEL_10_0 + D3D_FEATURE_LEVEL_11_1, + D3D_FEATURE_LEVEL_11_0, + D3D_FEATURE_LEVEL_10_1, + D3D_FEATURE_LEVEL_10_0 }; Microsoft::WRL::ComPtr device; Microsoft::WRL::ComPtr context; D3D_FEATURE_LEVEL selected {}; - if (FAILED(D3D11CreateDevice(adapter.Get(), D3D_DRIVER_TYPE_UNKNOWN, nullptr, D3D11_CREATE_DEVICE_BGRA_SUPPORT, - levels, static_cast(std::size(levels)), D3D11_SDK_VERSION, - &device, &selected, &context)) || FAILED(device.As(&result)) || - !device_matches(result.Get(), luid)) return {}; + if (FAILED(D3D11CreateDevice(adapter.Get(), D3D_DRIVER_TYPE_UNKNOWN, nullptr, D3D11_CREATE_DEVICE_BGRA_SUPPORT, levels, static_cast(std::size(levels)), D3D11_SDK_VERSION, &device, &selected, &context)) || FAILED(device.As(&result)) || !device_matches(result.Get(), luid)) { + return {}; + } return result; } - } + } // namespace std::optional capture_frame_request_peer(const std::uint32_t pid) { - if (!pid) return {}; + if (!pid) { + return {}; + } const auto process = OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION | PROCESS_DUP_HANDLE | SYNCHRONIZE, FALSE, pid); - if (!process) return {}; + if (!process) { + return {}; + } const auto start = process_start(process); const bool alive = WaitForSingleObject(process, 0) == WAIT_TIMEOUT; CloseHandle(process); - if (!start || !alive) return {}; + if (!start || !alive) { + return {}; + } return FrameRequestPeer {pid, start}; } WindowsImportedFrameRing::~WindowsImportedFrameRing() { - if (metadata) UnmapViewOfFile(metadata); - for (const auto handle: handles_) if (handle) CloseHandle(handle); - if (source_process_) CloseHandle(source_process_); + if (metadata) { + UnmapViewOfFile(metadata); + } + for (const auto handle : handles_) { + if (handle) { + CloseHandle(handle); + } + } + if (source_process_) { + CloseHandle(source_process_); + } // COM resources remain owned until the last native GPU-work snapshot drops. // No keyed mutex wait, GPU flush or consumer wait occurs in destruction. } - WindowsFrameImporter::WindowsFrameImporter(ID3D11Device1 *device): device_(device) {} + WindowsFrameImporter::WindowsFrameImporter(ID3D11Device1 *device): + device_(device) {} + std::shared_ptr WindowsFrameImporter::import( - const FrameRequestPeer &peer, const FrameRingRegisterRequest &r) { - if (!peer.valid() || peer.process_id > MAXDWORD || !valid_frame_ring_request(r)) return {}; + const FrameRequestPeer &peer, + const FrameRingRegisterRequest &r + ) { + if (!peer.valid() || peer.process_id > MAXDWORD || !valid_frame_ring_request(r)) { + return {}; + } auto device = device_ ? device_ : create_hardware_device_for_luid(r.adapter_luid); - if (!device || !device_matches(device.Get(), r.adapter_luid)) return {}; + if (!device || !device_matches(device.Get(), r.adapter_luid)) { + return {}; + } auto ring = std::make_shared(); ring->request_ = r; - ring->source_process_ = OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION | PROCESS_DUP_HANDLE | SYNCHRONIZE, - FALSE, static_cast(peer.process_id)); - if (!ring->source_process_ || process_start(ring->source_process_) != peer.process_start || - WaitForSingleObject(ring->source_process_, 0) != WAIT_TIMEOUT) return {}; + ring->source_process_ = OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION | PROCESS_DUP_HANDLE | SYNCHRONIZE, FALSE, static_cast(peer.process_id)); + if (!ring->source_process_ || process_start(ring->source_process_) != peer.process_start || WaitForSingleObject(ring->source_process_, 0) != WAIT_TIMEOUT) { + return {}; + } std::array values {}; std::copy(r.texture_handles.begin(), r.texture_handles.end(), values.begin()); - values[4] = r.metadata_handle; values[5] = r.event_handle; + values[4] = r.metadata_handle; + values[5] = r.event_handle; for (std::size_t i = 0; i < values.size(); ++i) { - if (values[i] > (std::numeric_limits::max)() || - !DuplicateHandle(ring->source_process_, reinterpret_cast(static_cast(values[i])), - GetCurrentProcess(), &ring->handles_[i], 0, FALSE, DUPLICATE_SAME_ACCESS)) return {}; + if (values[i] > (std::numeric_limits::max)() || !DuplicateHandle(ring->source_process_, reinterpret_cast(static_cast(values[i])), GetCurrentProcess(), &ring->handles_[i], 0, FALSE, DUPLICATE_SAME_ACCESS)) { + return {}; + } } for (std::size_t i = 0; i < ring->handles_.size(); ++i) { for (std::size_t j = 0; j < i; ++j) { - if (CompareObjectHandles(ring->handles_[i], ring->handles_[j])) return {}; + if (CompareObjectHandles(ring->handles_[i], ring->handles_[j])) { + return {}; + } } } for (std::size_t i = 0; i < kFrameRingSlotCount; ++i) { - if (FAILED(device->OpenSharedResource1(ring->handles_[i], IID_PPV_ARGS(&ring->textures[i]))) || - FAILED(ring->textures[i].As(&ring->mutexes[i]))) return {}; + if (FAILED(device->OpenSharedResource1(ring->handles_[i], IID_PPV_ARGS(&ring->textures[i]))) || FAILED(ring->textures[i].As(&ring->mutexes[i]))) { + return {}; + } D3D11_TEXTURE2D_DESC desc {}; ring->textures[i]->GetDesc(&desc); - if (desc.Width != r.width || desc.Height != r.height || desc.Format != r.format || - desc.MipLevels != 1 || desc.ArraySize != 1 || desc.SampleDesc.Count != 1 || - desc.SampleDesc.Quality != 0 || desc.Usage != D3D11_USAGE_DEFAULT || desc.CPUAccessFlags != 0 || - desc.BindFlags != (D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE) || - desc.MiscFlags != (D3D11_RESOURCE_MISC_SHARED_NTHANDLE | D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX)) return {}; - } - ring->metadata = static_cast(MapViewOfFile(ring->handles_[4], FILE_MAP_READ | FILE_MAP_WRITE, - 0, 0, kFrameRingMetadataBytes)); - if (!ring->metadata) return {}; + if (desc.Width != r.width || desc.Height != r.height || desc.Format != r.format || desc.MipLevels != 1 || desc.ArraySize != 1 || desc.SampleDesc.Count != 1 || desc.SampleDesc.Quality != 0 || desc.Usage != D3D11_USAGE_DEFAULT || desc.CPUAccessFlags != 0 || desc.BindFlags != (D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE) || desc.MiscFlags != (D3D11_RESOURCE_MISC_SHARED_NTHANDLE | D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX)) { + return {}; + } + } + ring->metadata = static_cast(MapViewOfFile(ring->handles_[4], FILE_MAP_READ | FILE_MAP_WRITE, 0, 0, kFrameRingMetadataBytes)); + if (!ring->metadata) { + return {}; + } const auto &header = *ring->metadata; - if (!is_valid_api_namespace(header.api_namespace) || header.version != kFrameRingWireVersion || - header.size != sizeof(header) || header.client_cookie != r.client_cookie || - std::any_of(header.reserved.begin(), header.reserved.end(), [](auto b) { return b != 0; })) return {}; + if (!is_valid_api_namespace(header.api_namespace) || header.version != kFrameRingWireVersion || header.size != sizeof(header) || header.client_cookie != r.client_cookie || std::any_of(header.reserved.begin(), header.reserved.end(), [](auto b) { + return b != 0; + })) { + return {}; + } // SetEvent verifies the duplicated object is an event. Its extra wake is a // harmless hint: consumers always scan/validate mutex-protected slot data. - if (!SetEvent(ring->handles_[5])) return {}; + if (!SetEvent(ring->handles_[5])) { + return {}; + } ring->event = ring->handles_[5]; return ring; } -} +} // namespace virtual_display::driver #endif diff --git a/tests/linux/kernel-shim/drm/drm_gem_shmem_helper.h b/tests/linux/kernel-shim/drm/drm_gem_shmem_helper.h index 27dd794..b339836 100644 --- a/tests/linux/kernel-shim/drm/drm_gem_shmem_helper.h +++ b/tests/linux/kernel-shim/drm/drm_gem_shmem_helper.h @@ -1,20 +1,25 @@ #pragma once -#include #include +#include typedef uint32_t u32; -struct drm_file { int unused; }; -struct drm_device { int unused; }; + +struct drm_file { + int unused; +}; + +struct drm_device { + int unused; +}; /* Kernel API boundaries only; allocation policy comes from production .c. */ -int drm_gem_shmem_dumb_create(struct drm_file *, struct drm_device *, - struct drm_mode_create_dumb *); +int drm_gem_shmem_dumb_create(struct drm_file *, struct drm_device *, struct drm_mode_create_dumb *); void *drm_gem_shmem_prime_import_no_map(struct drm_device *, void *); void *drm_gem_shmem_prime_import_sg_table(struct drm_device *, void *, void *); struct drm_driver { - int (*dumb_create)(struct drm_file *, struct drm_device *, struct drm_mode_create_dumb *); - void *(*gem_prime_import)(struct drm_device *, void *); - void *(*gem_prime_import_sg_table)(struct drm_device *, void *, void *); + int (*dumb_create)(struct drm_file *, struct drm_device *, struct drm_mode_create_dumb *); + void *(*gem_prime_import)(struct drm_device *, void *); + void *(*gem_prime_import_sg_table)(struct drm_device *, void *, void *); }; diff --git a/tests/linux/kernel-shim/linux/mm.h b/tests/linux/kernel-shim/linux/mm.h index 8924e1b..15f8009 100644 --- a/tests/linux/kernel-shim/linux/mm.h +++ b/tests/linux/kernel-shim/linux/mm.h @@ -1,4 +1,4 @@ #pragma once #ifndef PAGE_SIZE -#define PAGE_SIZE 4096U + #define PAGE_SIZE 4096U #endif diff --git a/tests/linux/native-dumb-baseline-probe.c b/tests/linux/native-dumb-baseline-probe.c index 645cbe7..364098f 100644 --- a/tests/linux/native-dumb-baseline-probe.c +++ b/tests/linux/native-dumb-baseline-probe.c @@ -4,11 +4,8 @@ */ #include "vkms_drv.c" -int vibeshine_baseline_dumb_create(struct drm_file *, struct drm_device *, - struct drm_mode_create_dumb *); +int vibeshine_baseline_dumb_create(struct drm_file *, struct drm_device *, struct drm_mode_create_dumb *); -int vibeshine_baseline_dumb_create(struct drm_file *file, struct drm_device *dev, - struct drm_mode_create_dumb *args) -{ - return vkms_driver.dumb_create(file, dev, args); +int vibeshine_baseline_dumb_create(struct drm_file *file, struct drm_device *dev, struct drm_mode_create_dumb *args) { + return vkms_driver.dumb_create(file, dev, args); } diff --git a/tests/linux/test-kwin-gpu-routing.cpp b/tests/linux/test-kwin-gpu-routing.cpp index dbbdcca..87abebc 100644 --- a/tests/linux/test-kwin-gpu-routing.cpp +++ b/tests/linux/test-kwin-gpu-routing.cpp @@ -1,15 +1,13 @@ // Exercise the production GBM hooks with DRM/GBM providers, without changing // host displays or requiring a particular GPU. This verifies allocator routing // and fd ownership; real console, KScreen and client cadence remain runtime tests. -#include - #include +#include #include #include #include +#include #include - -#include #include struct gbm_device { @@ -54,14 +52,16 @@ namespace { nodes[DRM_NODE_RENDER] = path.data(); } } + ~device_fixture() { close(fd); unlink(path.data()); } + bool matches_fd(int candidate) const { struct stat actual {}, expected {}; return fstat(candidate, &actual) == 0 && fstat(fd, &expected) == 0 && - actual.st_dev == expected.st_dev && actual.st_ino == expected.st_ino; + actual.st_dev == expected.st_dev && actual.st_ino == expected.st_ino; } }; @@ -80,10 +80,13 @@ namespace { bool native_allocator_symbol; #ifdef VIBESHINE_KWIN_NATIVE_ALLOCATOR std::function render_device_body; + void *native_render_device(const void *manager, drmDevicePtr device) { return render_device_body(manager, device); } + std::function allocate_body; + KWin::GraphicsBuffer *native_allocate(void *allocator, const KWin::GraphicsBufferOptions &options) { return allocate_body(allocator, options); } @@ -119,7 +122,8 @@ namespace { if (candidate->matches_fd(fd)) { // Simulate renderD* being reused by a different GPU after enumeration. *device = renumbered_device && fd != candidate->fd ? - &renumbered_device->record : &candidate->record; + &renumbered_device->record : + &candidate->record; return 0; } } @@ -149,7 +153,9 @@ namespace { native_hooks_enabled = true; real_gbm_create_device = create_device; real_gbm_device_destroy = destroy_device; - real_gbm_device_get_fd = +[](gbm_device *device) { return device->fd; }; + real_gbm_device_get_fd = +[](gbm_device *device) { + return device->fd; + }; #ifdef VIBESHINE_KWIN_NATIVE_ALLOCATOR real_native_render_device = native_render_device; real_native_allocate = native_allocate; @@ -170,31 +176,22 @@ namespace { } void require_original_devices() { - require(virtual_device->record.bustype == DRM_BUS_FAUX && - virtual_device->record.businfo.faux == &virtual_device->faux, - "virtual DRM identity changed"); - require(console_device->record.bustype == DRM_BUS_PCI && - console_device->record.businfo.pci == &console_device->bus && - console_device->record.deviceinfo.pci->vendor_id == 0x1af4, - "Virtio console identity changed"); + require(virtual_device->record.bustype == DRM_BUS_FAUX && virtual_device->record.businfo.faux == &virtual_device->faux, "virtual DRM identity changed"); + require(console_device->record.bustype == DRM_BUS_PCI && console_device->record.businfo.pci == &console_device->bus && console_device->record.deviceinfo.pci->vendor_id == 0x1af4, "Virtio console identity changed"); for (auto *candidate : native_devices) { require(candidate->record.nodes == candidate->nodes.data(), "DRM node list changed"); } } void require_routed(gbm_device *device, device_fixture &renderer) { - require(device && device->fd != virtual_device->fd && renderer.matches_fd(device->fd), - "virtual allocator did not use the selected NVIDIA render node"); + require(device && device->fd != virtual_device->fd && renderer.matches_fd(device->fd), "virtual allocator did not use the selected NVIDIA render node"); require((fcntl(device->fd, F_GETFD) & FD_CLOEXEC) != 0, "render fd can leak into children"); const int render_fd = device->fd; const int kms_fd = owned_render_fds.at(device).kms; - require(virtual_device->matches_fd(kms_fd) && (fcntl(kms_fd, F_GETFD) & FD_CLOEXEC), - "software allocator lost its owned KMS descriptor"); + require(virtual_device->matches_fd(kms_fd) && (fcntl(kms_fd, F_GETFD) & FD_CLOEXEC), "software allocator lost its owned KMS descriptor"); gbm_device_destroy(device); - require(fcntl(render_fd, F_GETFD) == -1 && errno == EBADF, - "render fd survived GBM destruction"); - require(fcntl(kms_fd, F_GETFD) == -1 && errno == EBADF, - "owned KMS fd survived GBM destruction"); + require(fcntl(render_fd, F_GETFD) == -1 && errno == EBADF, "render fd survived GBM destruction"); + require(fcntl(kms_fd, F_GETFD) == -1 && errno == EBADF, "owned KMS fd survived GBM destruction"); require(fcntl(virtual_device->fd, F_GETFD) >= 0, "caller-owned virtual KMS fd was closed"); require_original_devices(); } @@ -204,24 +201,25 @@ namespace { require(device && device->fd == virtual_device->fd, "virtual fallback used a different fd"); require(owned_render_fds.empty(), "fallback retained a renderer fd"); if (last_node_fd >= 0) { - require(fcntl(last_node_fd, F_GETFD) == -1 && errno == EBADF, - "failed renderer association leaked an fd"); + require(fcntl(last_node_fd, F_GETFD) == -1 && errno == EBADF, "failed renderer association leaked an fd"); } gbm_device_destroy(device); require(fcntl(virtual_device->fd, F_GETFD) >= 0, "fallback closed caller-owned fd"); require_original_devices(); } -} +} // namespace // Providers own these fixtures; native libdrm owns allocations in production. extern "C" void drmFreeDevice(drmDevicePtr *device) { *device = nullptr; } + extern "C" void drmFreeDevices(drmDevicePtr devices[], int count) { for (int i = 0; i < count; ++i) { devices[i] = nullptr; } } + extern "C" int drmGetNodeTypeFromFd(int fd) { last_node_fd = fd; return reject_render_type ? DRM_NODE_PRIMARY : DRM_NODE_RENDER; @@ -246,8 +244,7 @@ int main() { run("outside KWin all GBM calls pass through without DRM enumeration", [&] { hooks_enabled = false; auto *device = gbm_create_device(virtual_kms.fd); - require(device->fd == virtual_kms.fd && lookups == 0 && enumerations == 0, - "non-compositor GBM call was inspected or routed"); + require(device->fd == virtual_kms.fd && lookups == 0 && enumerations == 0, "non-compositor GBM call was inspected or routed"); gbm_device_destroy(device); require_original_devices(); }); @@ -264,8 +261,7 @@ int main() { setenv("VIBESHINE_KWIN_RENDER_PCI", "0000:01:00.0", 1); errno = EBUSY; auto *device = gbm_create_device(virtio.fd); - require(device->fd == virtio.fd && enumerations == 0 && errno == EBUSY, - "physical seat allocator was routed or changed errno"); + require(device->fd == virtio.fd && enumerations == 0 && errno == EBUSY, "physical seat allocator was routed or changed errno"); gbm_device_destroy(device); require(fcntl(virtio.fd, F_GETFD) >= 0, "caller-owned console fd was closed"); require_original_devices(); @@ -282,8 +278,7 @@ int main() { setenv("LD_PRELOAD", "libvibeshine-kwin-gpu.so", 1); configure_allocator_routing(lookup_allocator, false); require(!hooks_enabled, "native scanout allocator was routed to a render node"); - require(!std::getenv("LD_PRELOAD") && !std::getenv("VIBESHINE_KWIN_GPU_PRELOAD_ACTIVE"), - "native allocator path leaked preload into compositor children"); + require(!std::getenv("LD_PRELOAD") && !std::getenv("VIBESHINE_KWIN_GPU_PRELOAD_ACTIVE"), "native allocator path leaked preload into compositor children"); require_fallback(); require(lookups == 0 && enumerations == 0, "native KMS allocation inspected other GPUs"); auto *physical = gbm_create_device(nvidia_one.fd); @@ -390,19 +385,16 @@ int main() { require(device == &nvidia_one.record, "virtual output did not query the real NVIDIA renderer"); return &selected; }; - require(vibeshine_kwin_render_device(&manager, &virtual_kms.record) == &selected, - "virtual output lost its NVIDIA render association"); + require(vibeshine_kwin_render_device(&manager, &virtual_kms.record) == &selected, "virtual output lost its NVIDIA render association"); require_original_devices(); - require(owned_render_fds.empty() && fcntl(last_node_fd, F_GETFD) == -1, - "compatibility query leaked its temporary render fd"); + require(owned_render_fds.empty() && fcntl(last_node_fd, F_GETFD) == -1, "compatibility query leaked its temporary render fd"); for (auto *physical : {&virtio, &nvidia_one, &unrelated_faux}) { render_device_body = [&](const void *, drmDevicePtr device) -> void * { require(device == &physical->record, "physical or unrelated output was rerouted"); return &selected; }; const int before = enumerations; - require(vibeshine_kwin_render_device(&manager, &physical->record) == &selected && - enumerations == before, "unrelated compatibility query inspected other GPUs"); + require(vibeshine_kwin_render_device(&manager, &physical->record) == &selected && enumerations == before, "unrelated compatibility query inspected other GPUs"); } }); run("native compatibility honors PCI choice and falls back when renderer is absent", [&] { @@ -412,17 +404,16 @@ int main() { unsigned calls = 0; render_device_body = [&](const void *, drmDevicePtr device) -> void * { ++calls; - if (device == &nvidia_two.record) + if (device == &nvidia_two.record) { return nullptr; + } require(device == &virtual_kms.record, "missing render device selected another GPU"); return &original; }; - require(vibeshine_kwin_render_device(nullptr, &virtual_kms.record) == &original && calls == 2, - "missing render device did not preserve native virtual compatibility"); + require(vibeshine_kwin_render_device(nullptr, &virtual_kms.record) == &original && calls == 2, "missing render device did not preserve native virtual compatibility"); setenv("VIBESHINE_KWIN_RENDER_PCI", "bad", 1); calls = 0; - require(vibeshine_kwin_render_device(nullptr, &virtual_kms.record) == &original && calls == 1, - "invalid PCI choice did not preserve native compatibility"); + require(vibeshine_kwin_render_device(nullptr, &virtual_kms.record) == &original && calls == 1, "invalid PCI choice did not preserve native compatibility"); require_original_devices(); }); run("unmatched native ABI leaves render compatibility unchanged", [&] { @@ -432,8 +423,7 @@ int main() { require(device == &virtual_kms.record, "ABI fallback changed renderer lookup"); return &original; }; - require(vibeshine_kwin_render_device(nullptr, &virtual_kms.record) == &original && - enumerations == 0, "ABI fallback routed render compatibility"); + require(vibeshine_kwin_render_device(nullptr, &virtual_kms.record) == &original && enumerations == 0, "ABI fallback routed render compatibility"); }); run("matching native allocator uses NVIDIA hardware and original KMS software allocation", [&] { native_allocator_symbol = true; @@ -442,15 +432,13 @@ int main() { auto *device = gbm_create_device(virtual_kms.fd); allocate_body = [&](void *, const KWin::GraphicsBufferOptions &options) -> KWin::GraphicsBuffer * { const int fd = gbm_device_get_fd(device); - require(options.software ? virtual_kms.matches_fd(fd) : nvidia_one.matches_fd(fd), - "hardware and software allocation fds were conflated"); + require(options.software ? virtual_kms.matches_fd(fd) : nvidia_one.matches_fd(fd), "hardware and software allocation fds were conflated"); return nullptr; }; KWin::GraphicsBufferOptions options; options.software = true; vibeshine_kwin_allocate(nullptr, options); - require(!software_allocation && nvidia_one.matches_fd(gbm_device_get_fd(device)), - "software scope escaped into EGL rendering"); + require(!software_allocation && nvidia_one.matches_fd(gbm_device_get_fd(device)), "software scope escaped into EGL rendering"); options.software = false; vibeshine_kwin_allocate(nullptr, options); require_routed(device, nvidia_one); @@ -461,7 +449,9 @@ int main() { allocate_body = [&](void *, const KWin::GraphicsBufferOptions &) -> KWin::GraphicsBuffer * { require(gbm_device_get_fd(physical) == virtio.fd, "software scope changed physical seat fd"); bool other_thread_rendered = false; - std::thread other([&] { other_thread_rendered = nvidia_one.matches_fd(gbm_device_get_fd(device)); }); + std::thread other([&] { + other_thread_rendered = nvidia_one.matches_fd(gbm_device_get_fd(device)); + }); other.join(); require(other_thread_rendered, "software scope leaked into another rendering thread"); return nullptr; diff --git a/tests/linux/test-kwin-native-abi.cpp b/tests/linux/test-kwin-native-abi.cpp index 1b40626..89ef43b 100644 --- a/tests/linux/test-kwin-native-abi.cpp +++ b/tests/linux/test-kwin-native-abi.cpp @@ -3,19 +3,20 @@ #include "../../linux/kwin_native_abi.h" #include -#include - #include #include #include +#include namespace { using vibeshine::kwin::native_abi_result; int allocator; void *mapped_allocator; + void *lookup_mapped(void *, const char *) { return mapped_allocator; } + bool symbol_available = true; bool address_available = true; const char *library_path; @@ -25,19 +26,23 @@ namespace { throw std::runtime_error(message); } } + void *lookup(void *scope, const char *name) { require(scope == RTLD_NEXT, "must resolve the next allocator, not the bridge"); require(std::strcmp(name, "allocator") == 0, "wrong allocator symbol"); return symbol_available ? &allocator : nullptr; } + int address(const void *symbol, Dl_info *info) { require(symbol == &allocator, "must identify the resolved allocator"); info->dli_fname = library_path; return address_available; } + struct fixture { char directory[64] = "/tmp/kwin-native-abi-XXXXXX"; std::string old_library, new_library, link; + fixture() { require(mkdtemp(directory) != nullptr, "mkdtemp failed"); old_library = std::string(directory) + "/libkwin.so.6.8.0"; @@ -50,6 +55,7 @@ namespace { } require(symlink(old_library.c_str(), link.c_str()) == 0, "symlink failed"); } + ~fixture() { unlink(link.c_str()); unlink(old_library.c_str()); @@ -57,9 +63,11 @@ namespace { rmdir(directory); } }; + auto probe() { return vibeshine::kwin::probe_native_abi("allocator", "libkwin.so.6.8.0", lookup, address); } + std::string diagnostic(const vibeshine::kwin::native_abi_probe &result) { FILE *file = tmpfile(); require(file != nullptr, "diagnostic capture failed"); @@ -73,7 +81,7 @@ namespace { fclose(file); return output; } -} +} // namespace int main(int argc, char **argv) { try { @@ -89,8 +97,7 @@ int main(int argc, char **argv) { result = probe(); require(result.result == native_abi_result::different_library, "patch update must remain rejected"); const auto message = diagnostic(result); - for (const char *needle : {"built for libkwin.so.6.8.0", "resolved current pathname libkwin.so.6.8.1", - "CPU upload", "rebuilt", "log out", "Restarting the streaming service alone"}) { + for (const char *needle : {"built for libkwin.so.6.8.0", "resolved current pathname libkwin.so.6.8.1", "CPU upload", "rebuilt", "log out", "Restarting the streaming service alone"}) { require(message.find(needle) != std::string::npos, "missing actionable runtime diagnostic"); } // A direct old filename still compares equal; unlike the mapped test below, @@ -98,7 +105,7 @@ int main(int argc, char **argv) { library_path = files.old_library.c_str(); require(probe().result == native_abi_result::compatible, "direct old filename comparison must remain compatible"); - library_path = files.directory; // basename must not be treated as a compatible prefix + library_path = files.directory; // basename must not be treated as a compatible prefix require(probe().result == native_abi_result::different_library, "unrelated name must fail closed"); library_path = nullptr; require(probe().result == native_abi_result::unavailable_library, "missing owner path must fail closed"); @@ -128,12 +135,9 @@ int main(int argc, char **argv) { result = vibeshine::kwin::probe_native_abi("kwin_abi_fixture", "libkwin.so.6.8.0", lookup_mapped); require(result.result == native_abi_result::different_library, "retarget must retain guard rejection"); const auto mapped_message = diagnostic(result); - require(mapped_message.find("resolved current pathname libkwin.so.6.8.1") != std::string::npos, - "diagnostic must describe the current pathname target"); - require(mapped_message.find("mapped library identity unverified") != std::string::npos, - "diagnostic must disclose that mapped identity is unverified"); - require(mapped_message.find("loaded libkwin.so.6.8.1") == std::string::npos, - "diagnostic must not misidentify the old mapped code as the new library"); + require(mapped_message.find("resolved current pathname libkwin.so.6.8.1") != std::string::npos, "diagnostic must describe the current pathname target"); + require(mapped_message.find("mapped library identity unverified") != std::string::npos, "diagnostic must disclose that mapped identity is unverified"); + require(mapped_message.find("loaded libkwin.so.6.8.1") == std::string::npos, "diagnostic must not misidentify the old mapped code as the new library"); dlclose(handle); std::cout << "KWin native ABI guard and diagnostics: PASS\n"; } catch (const std::exception &error) { diff --git a/tests/linux/test-kwin-native-allocation.cpp b/tests/linux/test-kwin-native-allocation.cpp index 220a611..2b74ff9 100644 --- a/tests/linux/test-kwin-native-allocation.cpp +++ b/tests/linux/test-kwin-native-allocation.cpp @@ -1,23 +1,26 @@ // Real allocator/GL interoperability. Allocates private buffers without // modesetting. #include "../../linux/kwin_gpu_interposer.cpp" -#include -#include + #include #include #include -#include #include +#include #include -#include -#include +#include #include +#include +#include #include +#include static void require(bool ok, const char *message) { - if (!ok) + if (!ok) { throw std::runtime_error(message); + } } + int main(int argc, char **argv) { QCoreApplication app(argc, argv); try { @@ -26,20 +29,22 @@ int main(int argc, char **argv) { return 77; } configure_allocator_routing(dlsym); - require(hooks_enabled && native_hooks_enabled, - "native allocator routing did not enable"); + require(hooks_enabled && native_hooks_enabled, "native allocator routing did not enable"); const int count = drmGetDevices2(0, nullptr, 0); - if (count <= 0) + if (count <= 0) { return 77; + } std::vector devices(count, nullptr); const int actual = drmGetDevices2(0, devices.data(), count); QString path; - for (int i = 0; i < actual; ++i) - if (is_vibeshine_display(devices[i]) && - (devices[i]->available_nodes & (1 << DRM_NODE_PRIMARY))) + for (int i = 0; i < actual; ++i) { + if (is_vibeshine_display(devices[i]) && (devices[i]->available_nodes & (1 << DRM_NODE_PRIMARY))) { path = QString::fromLocal8Bit(devices[i]->nodes[DRM_NODE_PRIMARY]); - if (actual > 0) + } + } + if (actual > 0) { drmFreeDevices(devices.data(), actual); + } if (path.isEmpty()) { std::cout << "SKIP: managed virtual DRM device unavailable\n"; return 77; @@ -53,24 +58,19 @@ int main(int argc, char **argv) { // This is the boundary that a direct allocator-only probe misses: KWin // must associate the virtual output with its existing hardware renderer. // The optional switch reproduces the old bridge's software association. - if (app.arguments().contains(QStringLiteral("--without-render-selection"))) + if (app.arguments().contains(QStringLiteral("--without-render-selection"))) { native_hooks_enabled = false; + } auto manager = std::make_unique(); auto *renderer = manager->compatibleRenderDevice(device.get()); - require(renderer && !renderer->isSoftwareDevice() && renderer->isNvidia(), - "virtual output still selects a software renderer"); + require(renderer && !renderer->isSoftwareDevice() && renderer->isNvidia(), "virtual output still selects a software renderer"); const auto renderer_device = renderer->drmDevice(); - require(renderer_device && - is_nvidia_render_device(renderer_device->libdrmDevice()), - "selected render device is not the real NVIDIA GPU"); - require(device->busType() == DRM_BUS_FAUX, - "render association changed virtual KMS identity"); + require(renderer_device && is_nvidia_render_device(renderer_device->libdrmDevice()), "selected render device is not the real NVIDIA GPU"); + require(device->busType() == DRM_BUS_FAUX, "render association changed virtual KMS identity"); std::cout << "KWin virtual-output hardware render selection: PASS\n"; const auto &fds = owned_render_fds.at(device->gbmDevice()); drmVersionPtr version = drmGetVersion(fds.kms); - require(version && std::string_view(version->name, version->name_len) == - "vibeshine_drm", - "software fd does not refer to virtual KMS"); + require(version && std::string_view(version->name, version->name_len) == "vibeshine_drm", "software fd does not refer to virtual KMS"); drmFreeVersion(version); KWin::GraphicsBufferOptions opts; opts.size = QSize(64, 64); @@ -80,90 +80,74 @@ int main(int argc, char **argv) { opts.render = false; auto software = device->allocator()->allocate(opts); require(software, "real KWin software scanout allocation failed"); - require(software->dmabufAttributes() && - software->dmabufAttributes()->modifier == DRM_FORMAT_MOD_LINEAR, - "software allocation lost linear scanout"); + require(software->dmabufAttributes() && software->dmabufAttributes()->modifier == DRM_FORMAT_MOD_LINEAR, "software allocation lost linear scanout"); software->drop(); - require(!software_allocation, - "software scope leaked after real KWin allocation"); + require(!software_allocation, "software scope leaked after real KWin allocation"); opts.software = false; opts.render = true; - opts.modifiers = {DRM_FORMAT_MOD_NVIDIA_BLOCK_LINEAR_2D(0, 1, 2, 6, 5), - DRM_FORMAT_MOD_NVIDIA_BLOCK_LINEAR_2D(0, 1, 2, 6, 4), - DRM_FORMAT_MOD_NVIDIA_BLOCK_LINEAR_2D(0, 1, 2, 6, 3), - DRM_FORMAT_MOD_NVIDIA_BLOCK_LINEAR_2D(0, 1, 2, 6, 2), - DRM_FORMAT_MOD_NVIDIA_BLOCK_LINEAR_2D(0, 1, 2, 6, 1), - DRM_FORMAT_MOD_NVIDIA_BLOCK_LINEAR_2D(0, 1, 2, 6, 0)}; + opts.modifiers = {DRM_FORMAT_MOD_NVIDIA_BLOCK_LINEAR_2D(0, 1, 2, 6, 5), DRM_FORMAT_MOD_NVIDIA_BLOCK_LINEAR_2D(0, 1, 2, 6, 4), DRM_FORMAT_MOD_NVIDIA_BLOCK_LINEAR_2D(0, 1, 2, 6, 3), DRM_FORMAT_MOD_NVIDIA_BLOCK_LINEAR_2D(0, 1, 2, 6, 2), DRM_FORMAT_MOD_NVIDIA_BLOCK_LINEAR_2D(0, 1, 2, 6, 1), DRM_FORMAT_MOD_NVIDIA_BLOCK_LINEAR_2D(0, 1, 2, 6, 0)}; auto swapchain = KWin::EglSwapchain::create( - device->allocator(), renderer->eglContext(), opts); - require(bool(swapchain) && bool(swapchain->acquire()), - "KWin failed to create a GPU scanout swapchain"); + device->allocator(), + renderer->eglContext(), + opts + ); + require(bool(swapchain) && bool(swapchain->acquire()), "KWin failed to create a GPU scanout swapchain"); std::cout << "KWin GPU scanout swapchain: PASS\n"; EGLDisplay egl = eglGetCurrentDisplay(); require(egl != EGL_NO_DISPLAY, "KWin render EGL display unavailable"); const EGLContext kwin_context = eglGetCurrentContext(); const EGLenum kwin_api = eglQueryAPI(); require(eglBindAPI(EGL_OPENGL_API), "OpenGL API unavailable"); - EGLint config_attrs[] = {EGL_RENDERABLE_TYPE, EGL_OPENGL_BIT, - EGL_SURFACE_TYPE, EGL_PBUFFER_BIT, EGL_NONE}; + EGLint config_attrs[] = {EGL_RENDERABLE_TYPE, EGL_OPENGL_BIT, EGL_SURFACE_TYPE, EGL_PBUFFER_BIT, EGL_NONE}; EGLConfig config; EGLint config_count; - require(eglChooseConfig(egl, config_attrs, &config, 1, &config_count) && config_count, - "GL config unavailable"); - EGLint context_attrs[] = {EGL_CONTEXT_MAJOR_VERSION, 3, - EGL_CONTEXT_MINOR_VERSION, 3, EGL_NONE}; + require(eglChooseConfig(egl, config_attrs, &config, 1, &config_count) && config_count, "GL config unavailable"); + EGLint context_attrs[] = {EGL_CONTEXT_MAJOR_VERSION, 3, EGL_CONTEXT_MINOR_VERSION, 3, EGL_NONE}; EGLContext context = - eglCreateContext(egl, config, EGL_NO_CONTEXT, context_attrs); - require(context != EGL_NO_CONTEXT && - eglMakeCurrent(egl, EGL_NO_SURFACE, EGL_NO_SURFACE, context), - "GL context unavailable"); - auto target = (PFNGLEGLIMAGETARGETTEXTURE2DOESPROC)eglGetProcAddress( - "glEGLImageTargetTexture2DOES"); + eglCreateContext(egl, config, EGL_NO_CONTEXT, context_attrs); + require(context != EGL_NO_CONTEXT && eglMakeCurrent(egl, EGL_NO_SURFACE, EGL_NO_SURFACE, context), "GL context unavailable"); + auto target = (PFNGLEGLIMAGETARGETTEXTURE2DOESPROC) eglGetProcAddress( + "glEGLImageTargetTexture2DOES" + ); require(target, "legacy capture import entry point unavailable"); for (auto format : {DRM_FORMAT_XRGB8888, DRM_FORMAT_ARGB8888}) { opts.format = format; auto hardware = device->allocator()->allocate(opts); require(hardware, "real KWin GPU scanout allocation failed"); const auto attrs = hardware->dmabufAttributes(); - require(attrs && attrs->modifier != DRM_FORMAT_MOD_LINEAR && - attrs->modifier != DRM_FORMAT_MOD_INVALID, - "hardware allocation is not explicit tiled GPU storage"); + require(attrs && attrs->modifier != DRM_FORMAT_MOD_LINEAR && attrs->modifier != DRM_FORMAT_MOD_INVALID, "hardware allocation is not explicit tiled GPU storage"); // Register a private framebuffer on the actual virtual KMS device. // It is never attached to an output, so this does not modeset. - uint32_t handles[4]{}, pitches[4]{}, offsets[4]{}; - uint64_t modifiers[4]{}; - require(drmPrimeFDToHandle(fds.kms, attrs->fd[0].get(), &handles[0]) == 0, - "virtual KMS PRIME import of GPU scanout failed"); + uint32_t handles[4] {}, pitches[4] {}, offsets[4] {}; + uint64_t modifiers[4] {}; + require(drmPrimeFDToHandle(fds.kms, attrs->fd[0].get(), &handles[0]) == 0, "virtual KMS PRIME import of GPU scanout failed"); pitches[0] = attrs->pitch[0]; offsets[0] = attrs->offset[0]; modifiers[0] = attrs->modifier; uint32_t framebuffer = 0; const int added = drmModeAddFB2WithModifiers( - fds.kms, 64, 64, format, handles, pitches, offsets, modifiers, - &framebuffer, DRM_MODE_FB_MODIFIERS); + fds.kms, + 64, + 64, + format, + handles, + pitches, + offsets, + modifiers, + &framebuffer, + DRM_MODE_FB_MODIFIERS + ); drmCloseBufferHandle(fds.kms, handles[0]); require(added == 0, "virtual KMS rejected explicit tiled framebuffer"); - require(drmModeRmFB(fds.kms, framebuffer) == 0, - "private scanout framebuffer cleanup failed"); - const EGLAttrib image_attrs[] = {EGL_WIDTH, - 64, - EGL_HEIGHT, - 64, - EGL_LINUX_DRM_FOURCC_EXT, - format, - EGL_DMA_BUF_PLANE0_FD_EXT, - attrs->fd[0].get(), - EGL_DMA_BUF_PLANE0_OFFSET_EXT, - attrs->offset[0], - EGL_DMA_BUF_PLANE0_PITCH_EXT, - attrs->pitch[0], - EGL_DMA_BUF_PLANE0_MODIFIER_LO_EXT, - EGLAttrib(attrs->modifier & 0xffffffff), - EGL_DMA_BUF_PLANE0_MODIFIER_HI_EXT, - EGLAttrib(attrs->modifier >> 32), - EGL_NONE}; + require(drmModeRmFB(fds.kms, framebuffer) == 0, "private scanout framebuffer cleanup failed"); + const EGLAttrib image_attrs[] = {EGL_WIDTH, 64, EGL_HEIGHT, 64, EGL_LINUX_DRM_FOURCC_EXT, format, EGL_DMA_BUF_PLANE0_FD_EXT, attrs->fd[0].get(), EGL_DMA_BUF_PLANE0_OFFSET_EXT, attrs->offset[0], EGL_DMA_BUF_PLANE0_PITCH_EXT, attrs->pitch[0], EGL_DMA_BUF_PLANE0_MODIFIER_LO_EXT, EGLAttrib(attrs->modifier & 0xffffffff), EGL_DMA_BUF_PLANE0_MODIFIER_HI_EXT, EGLAttrib(attrs->modifier >> 32), EGL_NONE}; EGLImage image = eglCreateImage( - egl, EGL_NO_CONTEXT, EGL_LINUX_DMA_BUF_EXT, nullptr, image_attrs); + egl, + EGL_NO_CONTEXT, + EGL_LINUX_DMA_BUF_EXT, + nullptr, + image_attrs + ); require(image != EGL_NO_IMAGE, "tiled EGL import failed"); GLuint texture, fbo; glGenTextures(1, &texture); @@ -171,23 +155,19 @@ int main(int argc, char **argv) { while (glGetError()) { } target(GL_TEXTURE_2D, image); - require(glGetError() == GL_NO_ERROR, - "HEVC-compatible direct GL import failed"); + require(glGetError() == GL_NO_ERROR, "HEVC-compatible direct GL import failed"); glGenFramebuffers(1, &fbo); glBindFramebuffer(GL_FRAMEBUFFER, fbo); - glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, - GL_TEXTURE_2D, texture, 0); - require(glCheckFramebufferStatus(GL_FRAMEBUFFER) == - GL_FRAMEBUFFER_COMPLETE, - "GPU scanout framebuffer incomplete"); + glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0); + require(glCheckFramebufferStatus(GL_FRAMEBUFFER) == GL_FRAMEBUFFER_COMPLETE, "GPU scanout framebuffer incomplete"); const float reference[] = {0.25f, 0.5f, 0.75f, 1}; glClearBufferfv(GL_COLOR, 0, reference); - float actual[4]{}; + float actual[4] {}; glReadPixels(0, 0, 1, 1, GL_RGBA, GL_FLOAT, actual); require(glGetError() == GL_NO_ERROR, "GPU pixel check failed"); - for (int i = 0; i < 4; ++i) - require(std::abs(actual[i] - reference[i]) < 0.003, - "GPU import changed pixel values"); + for (int i = 0; i < 4; ++i) { + require(std::abs(actual[i] - reference[i]) < 0.003, "GPU import changed pixel values"); + } std::cout << "format=0x" << std::hex << format << " tiled modifier=0x" << attrs->modifier << std::dec << " direct HEVC GL import and GPU pixels: PASS\n"; @@ -198,15 +178,13 @@ int main(int argc, char **argv) { } eglMakeCurrent(egl, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); eglDestroyContext(egl, context); - require(eglBindAPI(kwin_api) && - eglMakeCurrent(egl, EGL_NO_SURFACE, EGL_NO_SURFACE, kwin_context), - "restoring KWin context for resource cleanup failed"); + require(eglBindAPI(kwin_api) && eglMakeCurrent(egl, EGL_NO_SURFACE, EGL_NO_SURFACE, kwin_context), "restoring KWin context for resource cleanup failed"); swapchain.reset(); manager.reset(); device.reset(); require(owned_render_fds.empty(), "routed descriptors leaked"); std::cout - << "native allocator lifecycle: PASS; no outputs or services changed\n"; + << "native allocator lifecycle: PASS; no outputs or services changed\n"; } catch (const std::exception &e) { std::cerr << e.what() << "\n"; return 1; diff --git a/tests/linux/test-native-dumb-allocation.c b/tests/linux/test-native-dumb-allocation.c index cf40a80..2b91bef 100644 --- a/tests/linux/test-native-dumb-allocation.c +++ b/tests/linux/test-native-dumb-allocation.c @@ -1,12 +1,12 @@ // SPDX-License-Identifier: GPL-2.0+ /* Link the production allocator .c unchanged; mock only kernel DRM APIs. */ -#include -#include -#include #include "vibeshine_drm_dumb.h" #include +#include #include +#include +#include #include #include #include @@ -24,160 +24,154 @@ static const struct drm_driver ops = {VIBESHINE_DRM_SHMEM_DRIVER_OPS}; #ifdef VIBESHINE_TEST_BASELINE /* This bridge is compiled with the unmodified pre-fix vkms_drv.c. */ -extern int vibeshine_baseline_dumb_create(struct drm_file *, struct drm_device *, - struct drm_mode_create_dumb *); -#define allocate vibeshine_baseline_dumb_create +extern int vibeshine_baseline_dumb_create(struct drm_file *, struct drm_device *, struct drm_mode_create_dumb *); + #define allocate vibeshine_baseline_dumb_create #else -#define allocate ops.dumb_create + #define allocate ops.dumb_create #endif -int drm_gem_shmem_dumb_create(struct drm_file *f, struct drm_device *d, - struct drm_mode_create_dumb *args) -{ - assert(f == &file && d == &device); - allocated = *args; - ++calls; - if (allocation_error) - return allocation_error; - /* Linux 6.16 shmem allocation semantics, without a real GEM object. */ - args->pitch = (args->width * args->bpp + 7U) / 8U; - args->size = (args->pitch * args->height + PAGE_SIZE - 1U) & ~(PAGE_SIZE - 1U); - args->handle = 42; - if (map_allocation) { - assert(!mapping); - mapped_size = args->size; - mapping = malloc(mapped_size + 64U); - assert(mapping); - memset(mapping, 0xa5, mapped_size + 64U); - } - return 0; +int drm_gem_shmem_dumb_create(struct drm_file *f, struct drm_device *d, struct drm_mode_create_dumb *args) { + assert(f == &file && d == &device); + allocated = *args; + ++calls; + if (allocation_error) { + return allocation_error; + } + /* Linux 6.16 shmem allocation semantics, without a real GEM object. */ + args->pitch = (args->width * args->bpp + 7U) / 8U; + args->size = (args->pitch * args->height + PAGE_SIZE - 1U) & ~(PAGE_SIZE - 1U); + args->handle = 42; + if (map_allocation) { + assert(!mapping); + mapped_size = args->size; + mapping = malloc(mapped_size + 64U); + assert(mapping); + memset(mapping, 0xa5, mapped_size + 64U); + } + return 0; } -void *drm_gem_shmem_prime_import_no_map(struct drm_device *d, void *buffer) -{ - assert(d == &device && buffer == &imported); - ++prime_calls; - return buffer; +void *drm_gem_shmem_prime_import_no_map(struct drm_device *d, void *buffer) { + assert(d == &device && buffer == &imported); + ++prime_calls; + return buffer; } -void *drm_gem_shmem_prime_import_sg_table(struct drm_device *d, void *attachment, void *table) -{ - assert(d == &device && attachment == &imported && table == &allocated); - ++prime_calls; - return attachment; +void *drm_gem_shmem_prime_import_sg_table(struct drm_device *d, void *attachment, void *table) { + assert(d == &device && attachment == &imported && table == &allocated); + ++prime_calls; + return attachment; } -static int check_layout(uint32_t width, uint32_t height) -{ - struct drm_mode_create_dumb args = {.width = width, .height = height, .bpp = 32}; - uint64_t expected_pitch = ((uint64_t)width * 4U + 255U) / 256U * 256U; - uint64_t expected_size = (expected_pitch * height + PAGE_SIZE - 1U) & - ~((uint64_t)PAGE_SIZE - 1U); - unsigned int before_calls = calls; - assert(allocate(&file, &device, &args) == 0); - printf("%ux%u: kernel allocation width=%u pitch=%u size=%llu; logical=%ux%u\n", - width, height, allocated.width, args.pitch, (unsigned long long)args.size, - args.width, args.height); - if (args.pitch != expected_pitch || args.size != expected_size) { - fprintf(stderr, "FAIL: %ux%u returned pitch=%u size=%llu; expected pitch=%llu size=%llu\n", - width, height, args.pitch, (unsigned long long)args.size, - (unsigned long long)expected_pitch, (unsigned long long)expected_size); - return 1; - } - assert(calls == before_calls + 1); - assert(args.width == width && args.height == height && args.bpp == 32); - assert(args.handle == 42 && args.size >= (uint64_t)args.pitch * height); - assert(allocated.width == expected_pitch / 4U && allocated.height == height); - assert(allocated.pitch == 0 && allocated.size == 0 && allocated.handle == 0); - return 0; +static int check_layout(uint32_t width, uint32_t height) { + struct drm_mode_create_dumb args = {.width = width, .height = height, .bpp = 32}; + uint64_t expected_pitch = ((uint64_t) width * 4U + 255U) / 256U * 256U; + uint64_t expected_size = (expected_pitch * height + PAGE_SIZE - 1U) & + ~((uint64_t) PAGE_SIZE - 1U); + unsigned int before_calls = calls; + assert(allocate(&file, &device, &args) == 0); + printf("%ux%u: kernel allocation width=%u pitch=%u size=%llu; logical=%ux%u\n", width, height, allocated.width, args.pitch, (unsigned long long) args.size, args.width, args.height); + if (args.pitch != expected_pitch || args.size != expected_size) { + fprintf(stderr, "FAIL: %ux%u returned pitch=%u size=%llu; expected pitch=%llu size=%llu\n", width, height, args.pitch, (unsigned long long) args.size, (unsigned long long) expected_pitch, (unsigned long long) expected_size); + return 1; + } + assert(calls == before_calls + 1); + assert(args.width == width && args.height == height && args.bpp == 32); + assert(args.handle == 42 && args.size >= (uint64_t) args.pitch * height); + assert(allocated.width == expected_pitch / 4U && allocated.height == height); + assert(allocated.pitch == 0 && allocated.size == 0 && allocated.handle == 0); + return 0; } -static void check_rejected(uint32_t width, uint32_t height) -{ - struct drm_mode_create_dumb args = {.width = width, .height = height, .bpp = 32}; - struct drm_mode_create_dumb before = args; - unsigned int previous_calls = calls; - assert(allocate(&file, &device, &args) == -EINVAL); - assert(calls == previous_calls); - assert(memcmp(&args, &before, sizeof(args)) == 0); +static void check_rejected(uint32_t width, uint32_t height) { + struct drm_mode_create_dumb args = {.width = width, .height = height, .bpp = 32}; + struct drm_mode_create_dumb before = args; + unsigned int previous_calls = calls; + assert(allocate(&file, &device, &args) == -EINVAL); + assert(calls == previous_calls); + assert(memcmp(&args, &before, sizeof(args)) == 0); } -static void check_row_writes(uint32_t width, uint32_t height) -{ - struct drm_mode_create_dumb args = {.width = width, .height = height, .bpp = 32}; - map_allocation = 1; - assert(allocate(&file, &device, &args) == 0); - assert(args.size == mapped_size && args.width == width && args.height == height); - for (uint32_t y = 0; y < height; ++y) - memset(mapping + (size_t)y * args.pitch, 0x3c, (size_t)width * 4U); - for (uint32_t y = 0; y < height; ++y) { - assert(mapping[(size_t)y * args.pitch] == 0x3c); - assert(mapping[(size_t)y * args.pitch + width * 4U - 1U] == 0x3c); - for (uint32_t x = width * 4U; x < args.pitch; ++x) - assert(mapping[(size_t)y * args.pitch + x] == 0xa5); +static void check_row_writes(uint32_t width, uint32_t height) { + struct drm_mode_create_dumb args = {.width = width, .height = height, .bpp = 32}; + map_allocation = 1; + assert(allocate(&file, &device, &args) == 0); + assert(args.size == mapped_size && args.width == width && args.height == height); + for (uint32_t y = 0; y < height; ++y) { + memset(mapping + (size_t) y * args.pitch, 0x3c, (size_t) width * 4U); + } + for (uint32_t y = 0; y < height; ++y) { + assert(mapping[(size_t) y * args.pitch] == 0x3c); + assert(mapping[(size_t) y * args.pitch + width * 4U - 1U] == 0x3c); + for (uint32_t x = width * 4U; x < args.pitch; ++x) { + assert(mapping[(size_t) y * args.pitch + x] == 0xa5); } - for (size_t x = (size_t)args.pitch * height; x < mapped_size + 64U; ++x) - assert(mapping[x] == 0xa5); - free(mapping); - mapping = NULL; - map_allocation = 0; + } + for (size_t x = (size_t) args.pitch * height; x < mapped_size + 64U; ++x) { + assert(mapping[x] == 0xa5); + } + free(mapping); + mapping = NULL; + map_allocation = 0; } -int main(void) -{ - /* Keep the logged failing case first so baseline failure is behavioral. */ - if (check_layout(3440, 1440)) +int main(void) { + /* Keep the logged failing case first so baseline failure is behavioral. */ + if (check_layout(3440, 1440)) { + return 1; + } + const uint32_t widths[] = {1, 63, 64, 65, 1280, 1920, 2176, 2190, 2448, 2560, 3120, 3456, 3840, 8191, 8192}; + const uint32_t heights[] = {1, 1179, 1440, 1848, 8192}; + for (size_t w = 0; w < sizeof(widths) / sizeof(widths[0]); ++w) { + for (size_t h = 0; h < sizeof(heights) / sizeof(heights[0]); ++h) { + if (check_layout(widths[w], heights[h])) { return 1; - const uint32_t widths[] = {1, 63, 64, 65, 1280, 1920, 2176, 2190, 2448, - 2560, 3120, 3456, 3840, 8191, 8192}; - const uint32_t heights[] = {1, 1179, 1440, 1848, 8192}; - for (size_t w = 0; w < sizeof(widths) / sizeof(widths[0]); ++w) - for (size_t h = 0; h < sizeof(heights) / sizeof(heights[0]); ++h) - if (check_layout(widths[w], heights[h])) - return 1; - check_row_writes(3440, 1440); - check_row_writes(2190, 1179); + } + } + } + check_row_writes(3440, 1440); + check_row_writes(2190, 1179); - check_rejected(0, 1440); - check_rejected(3440, 0); - check_rejected(U32_MAX, 1); - check_rejected(U32_MAX - 63U, 1); - check_rejected(U32_MAX / 32U, 1); - assert(!check_layout((U32_MAX / 32U) & ~63U, 1)); - check_rejected(64, U32_MAX / 256U + 1U); - check_rejected(64, (U32_MAX & ~(PAGE_SIZE - 1U)) / 256U + 1U); - assert(!check_layout(64, (U32_MAX & ~(PAGE_SIZE - 1U)) / 256U)); + check_rejected(0, 1440); + check_rejected(3440, 0); + check_rejected(U32_MAX, 1); + check_rejected(U32_MAX - 63U, 1); + check_rejected(U32_MAX / 32U, 1); + assert(!check_layout((U32_MAX / 32U) & ~63U, 1)); + check_rejected(64, U32_MAX / 256U + 1U); + check_rejected(64, (U32_MAX & ~(PAGE_SIZE - 1U)) / 256U + 1U); + assert(!check_layout(64, (U32_MAX & ~(PAGE_SIZE - 1U)) / 256U)); - struct drm_mode_create_dumb args = {.width = 3440, .height = 1440, .bpp = 32}; - struct drm_mode_create_dumb before = args; - const int errors[] = {-ENOMEM, -EIO}; - for (size_t i = 0; i < sizeof(errors) / sizeof(errors[0]); ++i) { - unsigned int previous_calls = calls; - allocation_error = errors[i]; - assert(allocate(&file, &device, &args) == errors[i]); - assert(calls == previous_calls + 1 && memcmp(&args, &before, sizeof(args)) == 0); - } - allocation_error = 0; + struct drm_mode_create_dumb args = {.width = 3440, .height = 1440, .bpp = 32}; + struct drm_mode_create_dumb before = args; + const int errors[] = {-ENOMEM, -EIO}; + for (size_t i = 0; i < sizeof(errors) / sizeof(errors[0]); ++i) { + unsigned int previous_calls = calls; + allocation_error = errors[i]; + assert(allocate(&file, &device, &args) == errors[i]); + assert(calls == previous_calls + 1 && memcmp(&args, &before, sizeof(args)) == 0); + } + allocation_error = 0; - const uint32_t depths[] = {8, 16, 24, 30, 48, 64}; - for (size_t i = 0; i < sizeof(depths) / sizeof(depths[0]); ++i) { - args = (struct drm_mode_create_dumb){.width = 65, .height = 17, .bpp = depths[i]}; - before = args; - unsigned int previous_calls = calls; - assert(allocate(&file, &device, &args) == 0); - assert(calls == previous_calls + 1 && memcmp(&allocated, &before, sizeof(args)) == 0); - assert(args.pitch == (65U * depths[i] + 7U) / 8U); - } + const uint32_t depths[] = {8, 16, 24, 30, 48, 64}; + for (size_t i = 0; i < sizeof(depths) / sizeof(depths[0]); ++i) { + args = (struct drm_mode_create_dumb) {.width = 65, .height = 17, .bpp = depths[i]}; + before = args; + unsigned int previous_calls = calls; + assert(allocate(&file, &device, &args) == 0); + assert(calls == previous_calls + 1 && memcmp(&allocated, &before, sizeof(args)) == 0); + assert(args.pitch == (65U * depths[i] + 7U) / 8U); + } - unsigned int before_calls = calls; + unsigned int before_calls = calls; #if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 17, 0) - assert(!ops.gem_prime_import_sg_table); - assert(ops.gem_prime_import(&device, &imported) == &imported); + assert(!ops.gem_prime_import_sg_table); + assert(ops.gem_prime_import(&device, &imported) == &imported); #else - assert(!ops.gem_prime_import); - assert(ops.gem_prime_import_sg_table(&device, &imported, &allocated) == &imported); + assert(!ops.gem_prime_import); + assert(ops.gem_prime_import_sg_table(&device, &imported, &allocated) == &imported); #endif - assert(prime_calls == 1 && calls == before_calls); - puts("PASS: production allocator component and PRIME callback behavior"); - return 0; + assert(prime_calls == 1 && calls == before_calls); + puts("PASS: production allocator component and PRIME callback behavior"); + return 0; } diff --git a/tests/linux/test-vibeshine-drm-contract.py b/tests/linux/test-vibeshine-drm-contract.py index b5b8e8d..50b6d2d 100755 --- a/tests/linux/test-vibeshine-drm-contract.py +++ b/tests/linux/test-vibeshine-drm-contract.py @@ -21,7 +21,10 @@ def require(condition: bool, message: str) -> None: def require_source(source: str, needle: str, filename: str) -> None: - require(needle in source, f"{filename} is missing {needle!r}") + # Match source tokens across line wraps and alignment changes. + tokens = re.findall(r'"(?:\\.|[^"\\])*"|\w+|[^\w\s]', needle) + pattern = r"\s*".join(re.escape(token) for token in tokens) + require(re.search(pattern, source) is not None, f"{filename} is missing {needle!r}") def decode_manufacturer(edid: bytes) -> str: diff --git a/tests/unit/driver/test_broker_contract.cpp b/tests/unit/driver/test_broker_contract.cpp index db85a25..a0ebd7f 100644 --- a/tests/unit/driver/test_broker_contract.cpp +++ b/tests/unit/driver/test_broker_contract.cpp @@ -1,10 +1,9 @@ -#include - #include "virtual_display/driver/broker_commands.h" #include "virtual_display/driver/display_identity.h" #include #include +#include #include namespace vdd = virtual_display::driver; @@ -12,7 +11,7 @@ namespace vdd = virtual_display::driver; namespace { void set_display_name(char (&target)[vdd::kDisplayNameChars], const char *name) { std::fill(std::begin(target), std::end(target), '\0'); - std::memcpy(target, name, (std::min)(std::strlen(name), static_cast(vdd::kDisplayNameChars - 1))); + std::memcpy(target, name, (std::min) (std::strlen(name), static_cast(vdd::kDisplayNameChars - 1))); } } // namespace @@ -74,9 +73,7 @@ TEST(VirtualDisplayBrokerContract, ParsesManifestProfileSetCommand) { EXPECT_STREQ(profile->display_name, "Profile Display"); EXPECT_FALSE(vdd::parse_manifest_profile_set_command("manifest-profile-set 3 3840").has_value()); - EXPECT_FALSE(vdd::parse_manifest_profile_set_command( - "manifest-profile-set 3 3840 2160 600 340 120000 0 2 west 40 Profile Display" - ).has_value()); + EXPECT_FALSE(vdd::parse_manifest_profile_set_command("manifest-profile-set 3 3840 2160 600 340 120000 0 2 west 40 Profile Display").has_value()); } TEST(VirtualDisplayBrokerContract, BuildsHelperArgumentsForClientSessionProbe) { @@ -97,9 +94,7 @@ TEST(VirtualDisplayBrokerContract, BuildsHelperArgumentsForClientSessionProbe) { ); EXPECT_FALSE(vdd::helper_arguments_for_broker_command("helper-stress-capture-remove 5 wide 1080 60").has_value()); - EXPECT_FALSE(vdd::helper_arguments_for_broker_command( - "helper-associate-color-profile luid 44 advanced default profile.icc" - ).has_value()); + EXPECT_FALSE(vdd::helper_arguments_for_broker_command("helper-associate-color-profile luid 44 advanced default profile.icc").has_value()); } TEST(VirtualDisplayBrokerContract, FormatsPermanentStateForBrokerPayload) { diff --git a/tests/unit/driver/test_cli_contract.cpp b/tests/unit/driver/test_cli_contract.cpp index 38940cb..abe3439 100644 --- a/tests/unit/driver/test_cli_contract.cpp +++ b/tests/unit/driver/test_cli_contract.cpp @@ -1,10 +1,9 @@ -#include - #include "virtual_display/driver/broker_commands.h" #include "virtual_display/driver/cli_commands.h" #include "virtual_display/driver/windows_cli_utils.h" #include +#include #include #include @@ -172,58 +171,17 @@ TEST(VirtualDisplayCliContract, RoutesPublicDisplayCommandsThroughBrokerIpc) { EXPECT_EQ(permanent_off.command, "permanent-set 0 1920 1080 600 340 60000 Sunshine Display"); EXPECT_TRUE(permanent_off.print_payload); - const auto spawn = vdd::cli_broker_route_for_args({ - "spawn", - "--width", - "2560", - "--height", - "1440", - "--name", - "Desk Display" - }); + const auto spawn = vdd::cli_broker_route_for_args({"spawn", "--width", "2560", "--height", "1440", "--name", "Desk Display"}); EXPECT_EQ(spawn.action, vdd::CliBrokerRouteAction::RequireBrokerCommand); EXPECT_EQ(spawn.command, "permanent-set 1 2560 1440 600 340 60000 Desk Display"); EXPECT_TRUE(spawn.print_payload); - const auto permanent_set = vdd::cli_broker_route_for_args({ - "permanent", - "set", - "--count", - "2", - "--width", - "2560", - "--height", - "1440", - "--name", - "Desk Display" - }); + const auto permanent_set = vdd::cli_broker_route_for_args({"permanent", "set", "--count", "2", "--width", "2560", "--height", "1440", "--name", "Desk Display"}); EXPECT_EQ(permanent_set.action, vdd::CliBrokerRouteAction::RequireBrokerCommand); EXPECT_EQ(permanent_set.command, "permanent-set 2 2560 1440 600 340 60000 Desk Display"); EXPECT_TRUE(permanent_set.print_payload); - const auto profile_set = vdd::cli_broker_route_for_args({ - "permanent", - "profile", - "set", - "--slot", - "3", - "--width", - "3840", - "--height", - "2160", - "--refresh", - "120", - "--layout", - "persist", - "--x", - "-1920", - "--y", - "40", - "--hdr", - "0", - "--name", - "Profile Display" - }); + const auto profile_set = vdd::cli_broker_route_for_args({"permanent", "profile", "set", "--slot", "3", "--width", "3840", "--height", "2160", "--refresh", "120", "--layout", "persist", "--x", "-1920", "--y", "40", "--hdr", "0", "--name", "Profile Display"}); EXPECT_EQ(profile_set.action, vdd::CliBrokerRouteAction::RequireBrokerCommand); EXPECT_EQ( profile_set.command, @@ -408,36 +366,14 @@ TEST(VirtualDisplayCliContract, RoutesBrokerHelperCommandsThroughBrokerIpc) { EXPECT_EQ(color_profiles.action, vdd::CliBrokerRouteAction::QueryBrokerCommand); EXPECT_EQ(color_profiles.command, "helper-query-color-profiles"); - const auto helper = vdd::cli_broker_route_for_args({ - "broker", - "helper-associate-color-profile", - "12:34", - "56", - "C:\\Profiles\\display profile.icc", - "--advanced-color", - "--default" - }); + const auto helper = vdd::cli_broker_route_for_args({"broker", "helper-associate-color-profile", "12:34", "56", "C:\\Profiles\\display profile.icc", "--advanced-color", "--default"}); EXPECT_EQ(helper.action, vdd::CliBrokerRouteAction::QueryBrokerCommand); EXPECT_EQ(helper.command, "helper-associate-color-profile 12:34 56 advanced default C:\\Profiles\\display profile.icc"); - const auto stress_helper = vdd::cli_broker_route_for_args({ - "broker", - "helper-stress-capture-remove", - "5", - "1920", - "1080", - "60" - }); + const auto stress_helper = vdd::cli_broker_route_for_args({"broker", "helper-stress-capture-remove", "5", "1920", "1080", "60"}); EXPECT_EQ(stress_helper.action, vdd::CliBrokerRouteAction::QueryBrokerCommand); EXPECT_EQ(stress_helper.command, "helper-stress-capture-remove 5 1920 1080 60"); - const auto invalid_helper = vdd::cli_broker_route_for_args({ - "broker", - "helper-stress-capture-remove", - "0", - "1920", - "1080", - "60" - }); + const auto invalid_helper = vdd::cli_broker_route_for_args({"broker", "helper-stress-capture-remove", "0", "1920", "1080", "60"}); EXPECT_EQ(invalid_helper.action, vdd::CliBrokerRouteAction::InvalidArguments); } diff --git a/tests/unit/driver/test_control_client.cpp b/tests/unit/driver/test_control_client.cpp index f8dae83..b770175 100644 --- a/tests/unit/driver/test_control_client.cpp +++ b/tests/unit/driver/test_control_client.cpp @@ -1,8 +1,8 @@ -#include #include "virtual_display/driver/control_client.h" #include "virtual_display/driver/display_identity.h" #include +#include #include namespace vdd = virtual_display::driver; diff --git a/tests/unit/driver/test_control_protocol.cpp b/tests/unit/driver/test_control_protocol.cpp index 4ae791d..b282f01 100644 --- a/tests/unit/driver/test_control_protocol.cpp +++ b/tests/unit/driver/test_control_protocol.cpp @@ -1,10 +1,10 @@ -#include #include "virtual_display/driver/control_protocol.h" #include "virtual_display/driver/device_identity.h" #include "virtual_display/driver/display_identity.h" #include "virtual_display/driver/windows_control_protocol.h" #include +#include #include #include #include @@ -55,8 +55,8 @@ namespace { manifest.max_profile_count = 2; auto &profile = manifest.profiles[0]; profile.flags = vdd::kDisplayManifestProfileFlagHdrSupported | - vdd::kDisplayManifestProfileFlagRetainIdentity | - vdd::kDisplayManifestProfileFlagPermanentIdentity; + vdd::kDisplayManifestProfileFlagRetainIdentity | + vdd::kDisplayManifestProfileFlagPermanentIdentity; set_manifest_profile_identity(profile, 0); std::memcpy(profile.manufacturer_id, "SDD", 4); profile.physical_width_mm = 700; diff --git a/tests/unit/driver/test_display_identity.cpp b/tests/unit/driver/test_display_identity.cpp index fb9af76..21cdb60 100644 --- a/tests/unit/driver/test_display_identity.cpp +++ b/tests/unit/driver/test_display_identity.cpp @@ -1,6 +1,7 @@ -#include #include "virtual_display/driver/display_identity.h" +#include + namespace vdd = virtual_display::driver; namespace { diff --git a/tests/unit/driver/test_driver_controller.cpp b/tests/unit/driver/test_driver_controller.cpp index 8e39240..36844bd 100644 --- a/tests/unit/driver/test_driver_controller.cpp +++ b/tests/unit/driver/test_driver_controller.cpp @@ -1,4 +1,3 @@ -#include #include "virtual_display/driver/driver_controller.h" #include "virtual_display/driver/windows_driver_modes.h" @@ -6,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -23,7 +23,7 @@ namespace { void set_display_name(char (&destination)[N], const std::string_view value) { static_assert(N > 0); std::fill_n(destination, N, '\0'); - std::copy_n(value.data(), (std::min)(value.size(), N - 1), destination); + std::copy_n(value.data(), (std::min) (value.size(), N - 1), destination); } class FakeBackend: public vdd::DisplayDriverBackend { @@ -502,7 +502,7 @@ TEST(VirtualDisplayDriverController, ReleaseLeaseKeepsStoreWhenBackendDepartFail EXPECT_FALSE(status.ok()); EXPECT_EQ(status.backend_error, vdd::BackendError::Failed); EXPECT_EQ(controller.store().temporary_display_count(), 2u); - for (const auto &display: controller.store().temporary_displays()) { + for (const auto &display : controller.store().temporary_displays()) { EXPECT_TRUE(display.pending_departure); } const auto query = controller.query_lease(lease_id(100), now); @@ -516,7 +516,7 @@ TEST(VirtualDisplayDriverController, ReleaseLeaseKeepsStoreWhenBackendDepartFail feed.lease_id = lease_id(100); feed.requested_timeout_ms = 60'000; EXPECT_EQ(controller.feed_lease(feed, now + std::chrono::seconds(1)).store_error, vdd::StoreError::None); - for (const auto &display: controller.store().temporary_displays()) { + for (const auto &display : controller.store().temporary_displays()) { EXPECT_TRUE(display.pending_departure); EXPECT_EQ(display.timeout_ms, 30'000u); } @@ -669,7 +669,7 @@ TEST(VirtualDisplayDriverController, ApplyDisplayManifestReportsPerSlotIdentity) manifest.max_profile_count = 4; auto &profile = manifest.profiles[0]; profile.flags = vdd::kDisplayManifestProfileFlagRetainIdentity | - vdd::kDisplayManifestProfileFlagPermanentIdentity; + vdd::kDisplayManifestProfileFlagPermanentIdentity; profile.connector_index = 2; profile.display_id = 0x7000000000000100ull; profile.container_id = vdd::container_guid_from_display_id(profile.display_id); @@ -970,7 +970,7 @@ TEST(VirtualDisplayDriverController, CatalogPolicySurvivesOwnedReclaimAndDoesNot descriptor.requested_resolution_only ); ASSERT_LT(preferred, catalog.size()); - for (const auto &mode: catalog) { + for (const auto &mode : catalog) { EXPECT_EQ(mode.width, 2420u); EXPECT_EQ(mode.height, 1668u); } @@ -981,8 +981,7 @@ TEST(VirtualDisplayDriverController, CatalogPolicySurvivesOwnedReclaimAndDoesNot auto state = controller.query_display_state(); ASSERT_EQ(state.entry_count, 2u); for (std::uint32_t i = 0; i < state.entry_count; ++i) { - EXPECT_EQ((state.entries[i].flags & vdd::kDisplayStateFlagRequestedResolutionOnly) != 0, - state.entries[i].display_id == owned.display.display_id); + EXPECT_EQ((state.entries[i].flags & vdd::kDisplayStateFlagRequestedResolutionOnly) != 0, state.entries[i].display_id == owned.display.display_id); } vdd::ReclaimTemporaryDisplayRequest reclaim {}; @@ -1018,7 +1017,7 @@ TEST(VirtualDisplayDriverController, CatalogPolicyRejectsMalformedCreateBeforeAn ASSERT_TRUE(controller.create_temporary_display(peer, now).status.ok()); const auto peer_before = controller.store().find_temporary_display(peer.display_id); ASSERT_TRUE(peer_before); - for (const auto dimensions: {std::pair {0u, 1668u}, {2420u, 0u}, {7681u, 1668u}, {2420u, 4321u}}) { + for (const auto dimensions : {std::pair {0u, 1668u}, {2420u, 0u}, {7681u, 1668u}, {2420u, 4321u}}) { auto invalid = make_create_request(lease_id(100), 0x325); invalid.width = dimensions.first; invalid.height = dimensions.second; @@ -1138,7 +1137,9 @@ TEST(VirtualDisplayDriverController, CatalogPolicyPendingRecoveryUsesNewOwnedLif EXPECT_FALSE(controller.store().find_temporary_display(peer.display_id)->requested_resolution_only); ASSERT_EQ(backend.arrived.size(), 3u); EXPECT_FALSE(backend.arrived.back().requested_resolution_only); - for (const auto departed: backend.departed) EXPECT_EQ(departed, owned.display.display_id); + for (const auto departed : backend.departed) { + EXPECT_EQ(departed, owned.display.display_id); + } } TEST(VirtualDisplayDriverController, CatalogPolicySharedLeaseReclaimDoesNotCopyPolicyToFullSibling) { @@ -1168,8 +1169,7 @@ TEST(VirtualDisplayDriverController, CatalogPolicySharedLeaseReclaimDoesNotCopyP for (std::uint32_t index = 0; index < state.entry_count; ++index) { const auto &entry = state.entries[index]; EXPECT_EQ(entry.lease_id, 0u); - EXPECT_EQ((entry.flags & vdd::kDisplayStateFlagRequestedResolutionOnly) != 0, - entry.display_id == first.display.display_id); + EXPECT_EQ((entry.flags & vdd::kDisplayStateFlagRequestedResolutionOnly) != 0, entry.display_id == first.display.display_id); const auto record = controller.store().find_temporary_display(entry.display_id); ASSERT_TRUE(record); EXPECT_EQ(record->lease_id, reclaim.new_lease_id); diff --git a/tests/unit/driver/test_edid.cpp b/tests/unit/driver/test_edid.cpp index abeb456..814c2ff 100644 --- a/tests/unit/driver/test_edid.cpp +++ b/tests/unit/driver/test_edid.cpp @@ -1,7 +1,7 @@ -#include #include "virtual_display/driver/edid.h" #include +#include namespace vdd = virtual_display::driver; @@ -97,7 +97,14 @@ TEST(VirtualDisplayDriverEdid, HdrAdvertisesBt2020PrimariesWithD65White) { // EDID 1.4 stores each xy coordinate as a ten-bit fraction: eight high // bits in bytes 27-34, and two low bits packed into bytes 25-26. const std::array expected { - 0.708, 0.292, 0.170, 0.797, 0.131, 0.046, 0.3127, 0.3290 + 0.708, + 0.292, + 0.170, + 0.797, + 0.131, + 0.046, + 0.3127, + 0.3290 }; const auto low_bits = (byte_value(edid[25]) << 8u) | byte_value(edid[26]); for (std::size_t coordinate = 0; coordinate < expected.size(); ++coordinate) { @@ -119,7 +126,16 @@ TEST(VirtualDisplayDriverEdid, SdrPreservesOriginalRec709ChromaticityBytes) { options.hdr_supported = false; const auto edid = vdd::create_edid(options); const std::array original { - 0xee, 0x91, 0xa3, 0x54, 0x4c, 0x99, 0x26, 0x0f, 0x50, 0x54 + 0xee, + 0x91, + 0xa3, + 0x54, + 0x4c, + 0x99, + 0x26, + 0x0f, + 0x50, + 0x54 }; for (std::size_t index = 0; index < original.size(); ++index) { EXPECT_EQ(byte_value(edid[25 + index]), original[index]); diff --git a/tests/unit/driver/test_frame_ring_lifetime.cpp b/tests/unit/driver/test_frame_ring_lifetime.cpp index 2dbd4aa..1bfe02e 100644 --- a/tests/unit/driver/test_frame_ring_lifetime.cpp +++ b/tests/unit/driver/test_frame_ring_lifetime.cpp @@ -1,9 +1,8 @@ -#include - #include "virtual_display/driver/frame_ring_lifetime.h" #include #include +#include #include namespace vdd = virtual_display::driver; @@ -11,8 +10,13 @@ namespace vdd = virtual_display::driver; namespace { class Resources final: public vdd::FrameRingResources { public: - explicit Resources(std::shared_ptr destroyed): destroyed_ {std::move(destroyed)} {} - ~Resources() override { ++*destroyed_; } + explicit Resources(std::shared_ptr destroyed): + destroyed_ {std::move(destroyed)} {} + + ~Resources() override { + ++*destroyed_; + } + private: std::shared_ptr destroyed_; }; @@ -52,7 +56,7 @@ namespace { return owner; } }; -} +} // namespace TEST_F(FrameRingLifetimeTest, RetainsResourcesOnlyForTheCurrentLiveOwner) { auto destroyed = std::make_shared(0); @@ -69,7 +73,7 @@ TEST_F(FrameRingLifetimeTest, RetainsResourcesOnlyForTheCurrentLiveOwner) { EXPECT_FALSE(snapshot.can_publish()); EXPECT_FALSE(rings.snapshot(owner.display.display_id, owner.display_generation, now).resources); resources.reset(); - EXPECT_EQ(*destroyed, 0); // in-flight GPU work still owns its snapshot + EXPECT_EQ(*destroyed, 0); // in-flight GPU work still owns its snapshot snapshot = {}; EXPECT_EQ(*destroyed, 1); } @@ -81,12 +85,24 @@ TEST_F(FrameRingLifetimeTest, RejectsGuessedIdentityCapabilityAndGenerationWitho for (int mutation = 0; mutation < 6; ++mutation) { auto wrong = owner; switch (mutation) { - case 0: ++wrong.display.lease_id; break; - case 1: ++wrong.display.display_id; break; - case 2: wrong.capability.bytes[31] ^= 1; break; - case 3: wrong.display_generation = 0; break; - case 4: ++wrong.display_generation; break; - case 5: wrong.display.api_namespace = {}; break; + case 0: + ++wrong.display.lease_id; + break; + case 1: + ++wrong.display.display_id; + break; + case 2: + wrong.capability.bytes[31] ^= 1; + break; + case 3: + wrong.display_generation = 0; + break; + case 4: + ++wrong.display_generation; + break; + case 5: + wrong.display.api_namespace = {}; + break; } EXPECT_EQ(rings.register_ring(wrong, resources, now).status, vdd::FrameRingRegistrationStatus::OwnerUnavailable); EXPECT_EQ(resources.use_count(), 1); @@ -114,9 +130,8 @@ TEST_F(FrameRingLifetimeTest, PendingDepartureAndExpiryStopNewPublication) { auto inflight = rings.snapshot(200, owner.display_generation, now); ASSERT_TRUE(inflight.resources); EXPECT_FALSE(rings.snapshot(200, owner.display_generation, now + std::chrono::seconds {30}).resources); - EXPECT_EQ(rings.register_ring(owner, resources, now + std::chrono::seconds {30}).status, - vdd::FrameRingRegistrationStatus::OwnerUnavailable); - EXPECT_EQ(resources.use_count(), 2); // caller + existing in-flight work + EXPECT_EQ(rings.register_ring(owner, resources, now + std::chrono::seconds {30}).status, vdd::FrameRingRegistrationStatus::OwnerUnavailable); + EXPECT_EQ(resources.use_count(), 2); // caller + existing in-flight work ASSERT_EQ(store.mark_temporary_display_pending_departure(owner.display).error, vdd::StoreError::None); EXPECT_EQ(rings.register_ring(owner, resources, now).status, vdd::FrameRingRegistrationStatus::OwnerUnavailable); } @@ -188,14 +203,14 @@ TEST_F(FrameRingLifetimeTest, AbortedSlotCleanupCannotRestoreConsumerKeyAfterRet released_key = key; return true; })); - EXPECT_EQ(released_key, 1u); // live ring keeps the acquired key + EXPECT_EQ(released_key, 1u); // live ring keeps the acquired key ASSERT_TRUE(rings.retire_ring(200, owner.display_generation, registered.ring_generation)); EXPECT_TRUE(vdd::release_unpublished_slot(snapshot, 1, [&](const std::uint64_t key) { released_key = key; return true; })); - EXPECT_EQ(released_key, 0u); // retired ring returns the slot to producer ownership + EXPECT_EQ(released_key, 0u); // retired ring returns the slot to producer ownership EXPECT_FALSE(snapshot.can_publish()); } diff --git a/tests/unit/driver/test_frame_ring_server.cpp b/tests/unit/driver/test_frame_ring_server.cpp index bd12f47..8f6e183 100644 --- a/tests/unit/driver/test_frame_ring_server.cpp +++ b/tests/unit/driver/test_frame_ring_server.cpp @@ -1,8 +1,7 @@ -#include - #include "virtual_display/driver/frame_ring_server.h" #include +#include namespace vdd = virtual_display::driver; @@ -10,7 +9,8 @@ namespace { class UnusedImporter final: public vdd::FrameResourceImporter { public: std::shared_ptr import( - const vdd::FrameRequestPeer &, const vdd::FrameRingRegisterRequest & + const vdd::FrameRequestPeer &, + const vdd::FrameRingRegisterRequest & ) override { return {}; } @@ -50,7 +50,7 @@ namespace { return request; } }; -} +} // namespace TEST_F(FrameRingServerTest, OwnerQueryReturnsTheCurrentLifetimeTokenAndModeBounds) { const auto created = create_request(); diff --git a/tests/unit/driver/test_frame_transport_capabilities.cpp b/tests/unit/driver/test_frame_transport_capabilities.cpp index 137ea63..6c77e6c 100644 --- a/tests/unit/driver/test_frame_transport_capabilities.cpp +++ b/tests/unit/driver/test_frame_transport_capabilities.cpp @@ -1,9 +1,8 @@ -#include - #include "virtual_display/driver/control_client.h" #include "virtual_display/driver/ioctl_dispatcher.h" #include +#include #include #include @@ -12,17 +11,26 @@ namespace vdd = virtual_display::driver; namespace { class Backend final: public vdd::DisplayDriverBackend { public: - vdd::BackendDisplayResult arrive_temporary_display(const vdd::DisplayDescriptor &) override { return {}; } - vdd::BackendError depart_temporary_display(std::uint64_t, std::uint64_t) override { return vdd::BackendError::None; } - vdd::BackendError set_permanent_display_count(const vdd::PermanentDisplayCountRequest &) override { return vdd::BackendError::None; } - vdd::BackendError set_render_adapter(const vdd::SetRenderAdapterRequest &) override { return vdd::BackendError::None; } + vdd::BackendDisplayResult arrive_temporary_display(const vdd::DisplayDescriptor &) override { + return {}; + } + + vdd::BackendError depart_temporary_display(std::uint64_t, std::uint64_t) override { + return vdd::BackendError::None; + } + + vdd::BackendError set_permanent_display_count(const vdd::PermanentDisplayCountRequest &) override { + return vdd::BackendError::None; + } + + vdd::BackendError set_render_adapter(const vdd::SetRenderAdapterRequest &) override { + return vdd::BackendError::None; + } }; class Transport final: public vdd::ControlTransport { public: - bool ioctl(std::uint32_t code, const void *input, std::size_t input_size, - void *output, std::size_t output_size, - std::size_t &bytes_returned, std::uint32_t &native_error) override { + bool ioctl(std::uint32_t code, const void *input, std::size_t input_size, void *output, std::size_t output_size, std::size_t &bytes_returned, std::uint32_t &native_error) override { calls.push_back(code); native_error = 0; if (code == vdd::kIoctlGetProtocolVersion && version) { @@ -40,8 +48,7 @@ namespace { bytes_returned = sizeof(*target); return true; } - const auto result = dispatcher.dispatch(code, input, input_size, output, output_size, - std::chrono::steady_clock::now()); + const auto result = dispatcher.dispatch(code, input, input_size, output, output_size, std::chrono::steady_clock::now()); bytes_returned = result.bytes_returned; return result.status == vdd::IoctlStatus::Success; } @@ -54,7 +61,7 @@ namespace { std::optional target {}; std::vector calls {}; }; -} +} // namespace TEST(FrameTransportCapabilities, DispatcherCapabilityTracksTheExplicitBuildOption) { Transport transport; @@ -68,9 +75,7 @@ TEST(FrameTransportCapabilities, DispatcherCapabilityTracksTheExplicitBuildOptio EXPECT_EQ(capabilities.value.capabilities, 0u); EXPECT_EQ(capabilities.value.max_ring_slots, 0u); #endif - EXPECT_EQ(transport.calls, (std::vector { - vdd::kIoctlGetProtocolVersion, vdd::kIoctlQueryFrameTransportCapabilities - })); + EXPECT_EQ(transport.calls, (std::vector {vdd::kIoctlGetProtocolVersion, vdd::kIoctlQueryFrameTransportCapabilities})); // Existing display control remains available after capability discovery. EXPECT_TRUE(client.query_display_state().ok()); } @@ -102,15 +107,24 @@ TEST(FrameTransportCapabilities, RejectsMalformedAndUnusableCapabilityReplies) { Transport transport; transport.capabilities = vdd::FrameTransportCapabilities {}; switch (mutation) { - case 0: ++transport.capabilities->version; break; - case 1: --transport.capabilities->size; break; - case 2: transport.capabilities->reserved = 1; break; - case 3: transport.capabilities->capabilities = vdd::kFrameTransportCapabilityKeyedMutexRing; break; - case 4: transport.capabilities->api_namespace = {}; break; + case 0: + ++transport.capabilities->version; + break; + case 1: + --transport.capabilities->size; + break; + case 2: + transport.capabilities->reserved = 1; + break; + case 3: + transport.capabilities->capabilities = vdd::kFrameTransportCapabilityKeyedMutexRing; + break; + case 4: + transport.capabilities->api_namespace = {}; + break; } vdd::ControlClient client {transport}; - EXPECT_EQ(client.query_frame_transport_capabilities().status, - mutation == 4 ? vdd::ControlStatus::ProtocolIncompatible : vdd::ControlStatus::InvalidOutput); + EXPECT_EQ(client.query_frame_transport_capabilities().status, mutation == 4 ? vdd::ControlStatus::ProtocolIncompatible : vdd::ControlStatus::InvalidOutput); } } @@ -128,12 +142,10 @@ TEST(FrameTransportCapabilities, DispatcherRejectsInputOrTruncatedOutput) { Transport transport; vdd::FrameTransportCapabilities output {}; const auto now = std::chrono::steady_clock::now(); - auto result = transport.dispatcher.dispatch(vdd::kIoctlQueryFrameTransportCapabilities, - nullptr, 0, &output, sizeof(output) - 1, now); + auto result = transport.dispatcher.dispatch(vdd::kIoctlQueryFrameTransportCapabilities, nullptr, 0, &output, sizeof(output) - 1, now); EXPECT_EQ(result.status, vdd::IoctlStatus::InvalidOutputBuffer); EXPECT_EQ(result.bytes_returned, 0u); - result = transport.dispatcher.dispatch(vdd::kIoctlQueryFrameTransportCapabilities, - &output, sizeof(output), &output, sizeof(output), now); + result = transport.dispatcher.dispatch(vdd::kIoctlQueryFrameTransportCapabilities, &output, sizeof(output), &output, sizeof(output), now); EXPECT_EQ(result.status, vdd::IoctlStatus::InvalidInputBuffer); EXPECT_EQ(result.bytes_returned, 0u); } @@ -160,9 +172,7 @@ TEST(FrameTransportTarget, ClientReturnsOnlyAnOwnerBoundLiveModeToken) { EXPECT_EQ(target.value.display_generation, 30u); EXPECT_EQ(target.value.adapter_luid, (vdd::AdapterLuid {1, 2})); EXPECT_EQ(target.value.width, 2560u); - EXPECT_EQ(transport.calls, (std::vector { - vdd::kIoctlGetProtocolVersion, vdd::kIoctlQueryFrameTransportTarget - })); + EXPECT_EQ(transport.calls, (std::vector {vdd::kIoctlGetProtocolVersion, vdd::kIoctlQueryFrameTransportTarget})); } TEST(FrameTransportTarget, ClientRejectsInvalidRequestAndMismatchedModeReply) { @@ -185,7 +195,7 @@ TEST(FrameTransportTarget, ClientRejectsInvalidRequestAndMismatchedModeReply) { EXPECT_EQ(client.query_frame_transport_target(request).status, vdd::ControlStatus::InvalidOutput); request.owner_capability.bytes.fill(0); EXPECT_EQ(client.query_frame_transport_target(request).status, vdd::ControlStatus::InvalidOutput); - EXPECT_EQ(transport.calls.size(), 3u); // version + target reply; then version only for malformed request + EXPECT_EQ(transport.calls.size(), 3u); // version + target reply; then version only for malformed request } TEST(FrameTransportTarget, LegacyProtocolDoesNotReceiveTheNewQuery) { diff --git a/tests/unit/driver/test_hdr_capabilities.cpp b/tests/unit/driver/test_hdr_capabilities.cpp index 67f300c..c067bad 100644 --- a/tests/unit/driver/test_hdr_capabilities.cpp +++ b/tests/unit/driver/test_hdr_capabilities.cpp @@ -1,6 +1,7 @@ -#include #include "virtual_display/driver/hdr_capabilities.h" +#include + namespace vdd = virtual_display::driver; TEST(VirtualDisplayDriverHdrCapabilities, AdvertisesWindowsHdrPrerequisites) { diff --git a/tests/unit/driver/test_ioctl_dispatcher.cpp b/tests/unit/driver/test_ioctl_dispatcher.cpp index 1a38c97..bc844ea 100644 --- a/tests/unit/driver/test_ioctl_dispatcher.cpp +++ b/tests/unit/driver/test_ioctl_dispatcher.cpp @@ -1,7 +1,7 @@ -#include #include "virtual_display/driver/ioctl_dispatcher.h" #include +#include #include #include @@ -16,7 +16,7 @@ namespace { void set_display_name(char (&destination)[N], const std::string_view value) { static_assert(N > 0); std::fill_n(destination, N, '\0'); - std::copy_n(value.data(), (std::min)(value.size(), N - 1), destination); + std::copy_n(value.data(), (std::min) (value.size(), N - 1), destination); } class FakeBackend: public vdd::DisplayDriverBackend { @@ -180,13 +180,14 @@ TEST(VirtualDisplayDriverIoctlDispatcher, OwnedCreateAndReclaimRoundTripWithoutB vdd::CreateTemporaryDisplayResult created {}; ASSERT_EQ( harness.dispatcher.dispatch( - vdd::kIoctlCreateTemporaryDisplayOwned, - &owned, - sizeof(owned), - &created, - sizeof(created), - now - ).status, + vdd::kIoctlCreateTemporaryDisplayOwned, + &owned, + sizeof(owned), + &created, + sizeof(created), + now + ) + .status, vdd::IoctlStatus::Success ); ASSERT_EQ(harness.backend.arrived.size(), 1u); @@ -217,13 +218,14 @@ TEST(VirtualDisplayDriverIoctlDispatcher, OwnedCreateAndReclaimRoundTripWithoutB reclaim.owner_capability = owner_capability(9); EXPECT_EQ( harness.dispatcher.dispatch( - vdd::kIoctlReclaimTemporaryDisplay, - &reclaim, - sizeof(reclaim), - &reclaimed, - sizeof(reclaimed), - now + std::chrono::seconds(2) - ).status, + vdd::kIoctlReclaimTemporaryDisplay, + &reclaim, + sizeof(reclaim), + &reclaimed, + sizeof(reclaimed), + now + std::chrono::seconds(2) + ) + .status, vdd::IoctlStatus::NotFound ); } @@ -560,13 +562,14 @@ TEST(VirtualDisplayDriverIoctlDispatcher, QueryDisplayStateReturnsActiveIdentiti vdd::PermanentDisplayCountResult permanent_output {}; ASSERT_EQ( harness.dispatcher.dispatch( - vdd::kIoctlSetPermanentDisplayCount, - &permanent, - sizeof(permanent), - &permanent_output, - sizeof(permanent_output), - std::chrono::steady_clock::now() - ).status, + vdd::kIoctlSetPermanentDisplayCount, + &permanent, + sizeof(permanent), + &permanent_output, + sizeof(permanent_output), + std::chrono::steady_clock::now() + ) + .status, vdd::IoctlStatus::Success ); @@ -575,13 +578,14 @@ TEST(VirtualDisplayDriverIoctlDispatcher, QueryDisplayStateReturnsActiveIdentiti vdd::CreateTemporaryDisplayResult created {}; ASSERT_EQ( harness.dispatcher.dispatch( - vdd::kIoctlCreateTemporaryDisplay, - &temporary, - sizeof(temporary), - &created, - sizeof(created), - std::chrono::steady_clock::now() - ).status, + vdd::kIoctlCreateTemporaryDisplay, + &temporary, + sizeof(temporary), + &created, + sizeof(created), + std::chrono::steady_clock::now() + ) + .status, vdd::IoctlStatus::Success ); @@ -613,7 +617,7 @@ TEST(VirtualDisplayDriverIoctlDispatcher, SetAndQueryDisplayManifestUseManifestA manifest.max_profile_count = 4; auto &profile = manifest.profiles[0]; profile.flags = vdd::kDisplayManifestProfileFlagRetainIdentity | - vdd::kDisplayManifestProfileFlagPermanentIdentity; + vdd::kDisplayManifestProfileFlagPermanentIdentity; profile.connector_index = 2; profile.display_id = 0x7000000000000100ull; profile.container_id = vdd::container_guid_from_display_id(profile.display_id); diff --git a/tests/unit/driver/test_lease_store.cpp b/tests/unit/driver/test_lease_store.cpp index d0a5dfe..e2dbdca 100644 --- a/tests/unit/driver/test_lease_store.cpp +++ b/tests/unit/driver/test_lease_store.cpp @@ -1,9 +1,9 @@ -#include #include "virtual_display/driver/display_identity.h" #include "virtual_display/driver/lease_store.h" #include #include +#include #include #include #include @@ -15,11 +15,11 @@ namespace { return vdd::kMinOpaqueLeaseId | suffix; } - template + template void set_display_name(char (&destination)[N], const std::string_view name) { static_assert(N > 0); std::fill(std::begin(destination), std::end(destination), '\0'); - const auto bytes_to_copy = (std::min)(name.size(), N - 1u); + const auto bytes_to_copy = (std::min) (name.size(), N - 1u); std::memcpy(destination, name.data(), bytes_to_copy); } @@ -672,7 +672,7 @@ TEST(VirtualDisplayDriverLeaseStore, AppliesDisplayManifestAsPermanentState) { manifest.profile_count = 1; auto &profile = manifest.profiles[0]; profile.flags = vdd::kDisplayManifestProfileFlagRetainIdentity | - vdd::kDisplayManifestProfileFlagPermanentIdentity; + vdd::kDisplayManifestProfileFlagPermanentIdentity; profile.connector_index = 2; profile.display_id = 0x7000000000000100ull; profile.container_id = vdd::container_guid_from_display_id(profile.display_id); diff --git a/tests/unit/driver/test_probe_contract.cpp b/tests/unit/driver/test_probe_contract.cpp index 7de9a88..a3c1852 100644 --- a/tests/unit/driver/test_probe_contract.cpp +++ b/tests/unit/driver/test_probe_contract.cpp @@ -1,10 +1,9 @@ -#include - #include "virtual_display/driver/probe_commands.h" -#include #include +#include #include +#include #include #include @@ -77,7 +76,7 @@ TEST(VirtualDisplayProbeContract, PlansProbeCommandArgcBoundsAndExecutionStage) ExpectedPlan {"--qa-temp-lease", 2, 6, vdd::ProbeCommandExecutionStage::ControlDeviceBeforeActiveSession} }; - for (const auto &expected: kPlans) { + for (const auto &expected : kPlans) { const auto plan = vdd::probe_command_plan(expected.command); ASSERT_TRUE(plan.has_value()) << expected.command; EXPECT_EQ(plan->minimum_argc, expected.minimum_argc) << expected.command; diff --git a/tests/unit/driver/test_windows_driver_modes.cpp b/tests/unit/driver/test_windows_driver_modes.cpp index 422fe44..3ac296d 100644 --- a/tests/unit/driver/test_windows_driver_modes.cpp +++ b/tests/unit/driver/test_windows_driver_modes.cpp @@ -1,9 +1,8 @@ #include "virtual_display/driver/windows_driver_modes.h" -#include - #include #include +#include #include #include #include @@ -17,7 +16,7 @@ namespace { const std::uint32_t height, const std::uint32_t refresh_rate_millihz ) { - for (const auto &mode: modes) { + for (const auto &mode : modes) { if (mode.width == width && mode.height == height && mode.refresh_rate_millihz == refresh_rate_millihz) { return true; } @@ -124,7 +123,7 @@ TEST(VirtualDisplayWindowsDriverModes, DoesNotDuplicateExistingRequestedMode) { const auto [modes, preferred_index] = vdd::build_windows_driver_mode_shapes(requested); std::uint32_t matches = 0; - for (const auto &mode: modes) { + for (const auto &mode : modes) { if (mode.width == 1920 && mode.height == 1080 && mode.refresh_rate_millihz == 60'000) { ++matches; } @@ -268,7 +267,7 @@ TEST(VirtualDisplayWindowsDriverModes, SignalFrequenciesUseReducedVerticalAndHor } TEST(VirtualDisplayWindowsDriverModes, OptInCatalogKeepsOnlyRequestedDimensionsAndAllMatchingRates) { - for (const auto requested: { + for (const auto requested : { vdd::active_windows_driver_mode_shape(2420, 1668, 60'000), vdd::active_windows_driver_mode_shape(1920, 1080, 59'940), vdd::active_windows_driver_mode_shape(2560, 1440, 144'500), @@ -284,14 +283,14 @@ TEST(VirtualDisplayWindowsDriverModes, OptInCatalogKeepsOnlyRequestedDimensionsA EXPECT_TRUE(has_mode(restricted, requested.width, requested.height, requested.refresh_rate_millihz * 4)); ASSERT_LT(restricted.size(), full.size()); std::size_t expected_count = 0; - for (const auto &mode: full) { + for (const auto &mode : full) { if (mode.width == requested.width && mode.height == requested.height) { ++expected_count; EXPECT_TRUE(has_mode(restricted, mode.width, mode.height, mode.refresh_rate_millihz)); } } EXPECT_EQ(restricted.size(), expected_count); - for (const auto &mode: restricted) { + for (const auto &mode : restricted) { EXPECT_EQ(mode.width, requested.width); EXPECT_EQ(mode.height, requested.height); } @@ -316,7 +315,7 @@ TEST(VirtualDisplayWindowsDriverModes, RestrictedTargetCatalogRetainsOwnedDescri TEST(VirtualDisplayWindowsDriverModes, RestrictedCatalogFallsBackSafelyWithoutValidPreferredTiming) { const auto [normal, normal_preferred] = vdd::build_windows_driver_mode_shapes(std::nullopt); - for (const auto preferred: { + for (const auto preferred : { std::optional {}, std::optional {vdd::active_windows_driver_mode_shape(0, 1668, 60'000)}, std::optional {vdd::active_windows_driver_mode_shape(2420, 0, 60'000)}, @@ -359,8 +358,8 @@ TEST(VirtualDisplayWindowsDriverModes, RegisteredCatalogsStayPerMonitorAndReject } TEST(VirtualDisplayWindowsDriverModes, RestrictedCatalogIsExactStableProjectionOfFullCatalogAcrossBoundaries) { - for (const auto dimensions: {std::pair {320u, 200u}, {321u, 201u}, {1920u, 1080u}, {2420u, 1668u}, {5120u, 1440u}, {7680u, 4320u}}) { - for (const auto refresh: {1u, 23'976u, 59'940u, 60'000u, 144'500u, 480'000u}) { + for (const auto dimensions : {std::pair {320u, 200u}, {321u, 201u}, {1920u, 1080u}, {2420u, 1668u}, {5120u, 1440u}, {7680u, 4320u}}) { + for (const auto refresh : {1u, 23'976u, 59'940u, 60'000u, 144'500u, 480'000u}) { const auto requested = vdd::active_windows_driver_mode_shape(dimensions.first, dimensions.second, refresh); const auto [full, full_preferred] = vdd::build_windows_driver_mode_shapes(requested); const auto [restricted, preferred] = vdd::build_windows_driver_mode_shapes(requested, true); @@ -368,8 +367,10 @@ TEST(VirtualDisplayWindowsDriverModes, RestrictedCatalogIsExactStableProjectionO ASSERT_LT(preferred, restricted.size()); EXPECT_EQ(restricted[preferred], requested); std::vector expected; - for (const auto &mode: full) { - if (mode.width == requested.width && mode.height == requested.height) expected.push_back(mode); + for (const auto &mode : full) { + if (mode.width == requested.width && mode.height == requested.height) { + expected.push_back(mode); + } } EXPECT_EQ(restricted, expected); EXPECT_TRUE(has_mode(restricted, requested.width, requested.height, refresh)); diff --git a/tests/unit/driver/test_windows_driver_state.cpp b/tests/unit/driver/test_windows_driver_state.cpp index 99e38c6..b0fcf79 100644 --- a/tests/unit/driver/test_windows_driver_state.cpp +++ b/tests/unit/driver/test_windows_driver_state.cpp @@ -1,8 +1,7 @@ #include "virtual_display/driver/windows_driver_state.h" -#include - #include +#include #include namespace vdd = virtual_display::driver; @@ -56,22 +55,16 @@ TEST(VirtualDisplayWindowsDriverState, RejectsInvalidTemporaryProfileBlobShapeAn auto invalid_connector = profiles; invalid_connector[0].connector_index = vdd::kWindowsDriverMaxPermanentDisplays - 1u; - EXPECT_FALSE(vdd::parse_temporary_display_profiles_blob( - vdd::serialize_temporary_display_profiles(invalid_connector) - ).has_value()); + EXPECT_FALSE(vdd::parse_temporary_display_profiles_blob(vdd::serialize_temporary_display_profiles(invalid_connector)).has_value()); auto too_high_connector = profiles; too_high_connector[0].connector_index = vdd::kWindowsDriverMaxPermanentDisplays + vdd::kWindowsDriverMaxTemporaryDisplays; - EXPECT_FALSE(vdd::parse_temporary_display_profiles_blob( - vdd::serialize_temporary_display_profiles(too_high_connector) - ).has_value()); + EXPECT_FALSE(vdd::parse_temporary_display_profiles_blob(vdd::serialize_temporary_display_profiles(too_high_connector)).has_value()); auto invalid_display_id = profiles; invalid_display_id[0].display_id = 0; - EXPECT_FALSE(vdd::parse_temporary_display_profiles_blob( - vdd::serialize_temporary_display_profiles(invalid_display_id) - ).has_value()); + EXPECT_FALSE(vdd::parse_temporary_display_profiles_blob(vdd::serialize_temporary_display_profiles(invalid_display_id)).has_value()); } TEST(VirtualDisplayWindowsDriverState, UsesVersionedFixedRecordFormatForPersistentProfiles) { @@ -81,17 +74,50 @@ TEST(VirtualDisplayWindowsDriverState, UsesVersionedFixedRecordFormatForPersiste const auto blob = vdd::serialize_temporary_display_profiles(profiles); const std::vector expected { - 0x01, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x60, - 0x04, 0x00, 0x00, 0x00, - 0x44, 0x33, 0x22, 0x11, - 0x66, 0x55, - 0x88, 0x77, - 0x90, 0xab, 0xcd, 0xef, 0x01, 0x23, 0x45, 0x01, - 0x01, 0x50, 0x00, 0x00, - 0x01, 0x70, 0x00, 0x00 + 0x01, + 0x00, + 0x00, + 0x00, + 0x01, + 0x00, + 0x00, + 0x00, + 0x01, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x00, + 0x60, + 0x04, + 0x00, + 0x00, + 0x00, + 0x44, + 0x33, + 0x22, + 0x11, + 0x66, + 0x55, + 0x88, + 0x77, + 0x90, + 0xab, + 0xcd, + 0xef, + 0x01, + 0x23, + 0x45, + 0x01, + 0x01, + 0x50, + 0x00, + 0x00, + 0x01, + 0x70, + 0x00, + 0x00 }; EXPECT_EQ(blob, expected); @@ -117,10 +143,7 @@ TEST(VirtualDisplayWindowsDriverState, UpsertReplacesExistingDisplayAndConflicti } TEST(VirtualDisplayWindowsDriverState, UpsertRejectsInvalidOrFullProfileSet) { - EXPECT_FALSE(vdd::upsert_temporary_display_profile( - {}, - make_profile(0x6000000000000001ull, vdd::kWindowsDriverMaxPermanentDisplays - 1u) - ).has_value()); + EXPECT_FALSE(vdd::upsert_temporary_display_profile({}, make_profile(0x6000000000000001ull, vdd::kWindowsDriverMaxPermanentDisplays - 1u)).has_value()); std::vector profiles; for (std::uint32_t index = 0; index < vdd::kWindowsDriverMaxTemporaryDisplays; ++index) { @@ -130,15 +153,9 @@ TEST(VirtualDisplayWindowsDriverState, UpsertRejectsInvalidOrFullProfileSet) { )); } - EXPECT_FALSE(vdd::upsert_temporary_display_profile( - profiles, - make_profile(0x6000000000000200ull, vdd::kWindowsDriverMaxPermanentDisplays + vdd::kWindowsDriverMaxTemporaryDisplays - 1u) - ).has_value()); + EXPECT_FALSE(vdd::upsert_temporary_display_profile(profiles, make_profile(0x6000000000000200ull, vdd::kWindowsDriverMaxPermanentDisplays + vdd::kWindowsDriverMaxTemporaryDisplays - 1u)).has_value()); - EXPECT_TRUE(vdd::upsert_temporary_display_profile( - profiles, - make_profile(0x6000000000000100ull, vdd::kWindowsDriverMaxPermanentDisplays) - ).has_value()); + EXPECT_TRUE(vdd::upsert_temporary_display_profile(profiles, make_profile(0x6000000000000100ull, vdd::kWindowsDriverMaxPermanentDisplays)).has_value()); } TEST(VirtualDisplayWindowsDriverState, RemoveAndMapTemporaryConnectorReservations) { diff --git a/tests/unit/linux_control_client.cpp b/tests/unit/linux_control_client.cpp index 553f396..f62394a 100644 --- a/tests/unit/linux_control_client.cpp +++ b/tests/unit/linux_control_client.cpp @@ -1,22 +1,25 @@ #if defined(__linux__) -#include + #include "virtual_display/driver/linux_control_client.h" -#include "virtual_display/driver/linux_control_client.h" - -#include -#include -#include -#include -#include -#include -#include + #include + #include + #include + #include + #include + #include + #include + #include namespace virtual_display::driver { TEST(LinuxControlClient, RejectsUnknownConnectorBeforeTransport) { LinuxControlClient client {"/tmp/libvirtualdisplay-unused.sock", std::chrono::milliseconds {10}}; for (const auto &name : { - "Virtual-0", "Virtual-01", "Virtual-2147483648", "Virtual-8 extra", "Virtual-../8" + "Virtual-0", + "Virtual-01", + "Virtual-2147483648", + "Virtual-8 extra", + "Virtual-../8" }) { const auto result = client.query_connector(name); EXPECT_EQ(result.status, LinuxControlStatus::InvalidRequest) << name; diff --git a/tests/unit/linux_drm_capture_test.cpp b/tests/unit/linux_drm_capture_test.cpp index 2958f7f..86892c3 100644 --- a/tests/unit/linux_drm_capture_test.cpp +++ b/tests/unit/linux_drm_capture_test.cpp @@ -1,9 +1,9 @@ // SPDX-License-Identifier: GPL-2.0+ #ifdef __linux__ -#include -#include -#include -#include + #include + #include + #include + #include TEST(LinuxCaptureLease, RetirementRejectsActiveReadersAndBlocksNewReaders) { vibeshine_capture_state state {}; @@ -19,15 +19,23 @@ TEST(LinuxCaptureLease, RetirementRejectsActiveReadersAndBlocksNewReaders) { EXPECT_TRUE(vibeshine_capture_publish(&state)); EXPECT_TRUE(vibeshine_capture_acquire(&state, false)); } + TEST(LinuxCaptureLease, AcquisitionAndRetirementShareOneLinearizationPoint) { for (int iteration = 0; iteration < 1000; ++iteration) { vibeshine_capture_state state {}; std::mutex lock; bool acquired = false; bool retired = false; - std::thread reader([&] { std::lock_guard guard(lock); acquired = vibeshine_capture_acquire(&state, false); }); - std::thread committer([&] { std::lock_guard guard(lock); retired = vibeshine_capture_retire(&state, false); }); - reader.join(); committer.join(); + std::thread reader([&] { + std::lock_guard guard(lock); + acquired = vibeshine_capture_acquire(&state, false); + }); + std::thread committer([&] { + std::lock_guard guard(lock); + retired = vibeshine_capture_retire(&state, false); + }); + reader.join(); + committer.join(); EXPECT_NE(acquired, retired); EXPECT_EQ(state.retiring, retired ? 1u : 0u); EXPECT_EQ(state.readers, acquired ? 1u : 0u); @@ -39,6 +47,7 @@ TEST(LinuxCaptureLease, AcquisitionAndRetirementShareOneLinearizationPoint) { EXPECT_TRUE(vibeshine_capture_publish(&state)); } } + TEST(LinuxCaptureLease, FailedAdmissionRollsBackAndAllowsRetry) { vibeshine_capture_state first {}; vibeshine_capture_state second {}; @@ -54,6 +63,7 @@ TEST(LinuxCaptureLease, FailedAdmissionRollsBackAndAllowsRetry) { EXPECT_TRUE(vibeshine_capture_publish(&first)); EXPECT_TRUE(vibeshine_capture_publish(&second)); } + TEST(LinuxCaptureLease, AsyncRetirementAllowsExistingReadersButBlocksNewOnes) { vibeshine_capture_state state {}; ASSERT_TRUE(vibeshine_capture_acquire(&state, false)); @@ -64,14 +74,17 @@ TEST(LinuxCaptureLease, AsyncRetirementAllowsExistingReadersButBlocksNewOnes) { EXPECT_TRUE(vibeshine_capture_publish(&state)); EXPECT_TRUE(vibeshine_capture_acquire(&state, false)); } + TEST(LinuxCaptureLease, ReadersAreBoundedAndStoppingRejectsNewWork) { vibeshine_capture_state state {}; EXPECT_FALSE(vibeshine_capture_acquire(&state, true)); - for (unsigned i = 0; i < VIBESHINE_CAPTURE_MAX_READERS; ++i) + for (unsigned i = 0; i < VIBESHINE_CAPTURE_MAX_READERS; ++i) { EXPECT_TRUE(vibeshine_capture_acquire(&state, false)); + } EXPECT_FALSE(vibeshine_capture_acquire(&state, false)); - for (unsigned i = 0; i < VIBESHINE_CAPTURE_MAX_READERS; ++i) + for (unsigned i = 0; i < VIBESHINE_CAPTURE_MAX_READERS; ++i) { EXPECT_TRUE(vibeshine_capture_release(&state)); + } EXPECT_FALSE(vibeshine_capture_release(&state)); EXPECT_FALSE(vibeshine_capture_publish(&state)); } diff --git a/tests/unit/linux_drm_change_test.cpp b/tests/unit/linux_drm_change_test.cpp index 4249665..0877c39 100644 --- a/tests/unit/linux_drm_change_test.cpp +++ b/tests/unit/linux_drm_change_test.cpp @@ -2,11 +2,10 @@ #ifdef __linux__ -#include - -#include -#include -#include + #include + #include + #include + #include TEST(LinuxDrmPresentPolicy, ReturnsACompletedSequenceWithoutWaitingForQueueDrain) { vibeshine_drm_wait_present request {}; diff --git a/tools/alttab_stress.cpp b/tools/alttab_stress.cpp index 8c85be7..d354b14 100644 --- a/tools/alttab_stress.cpp +++ b/tools/alttab_stress.cpp @@ -32,29 +32,26 @@ // No driver test-signing or reboot needed (Microsoft-whitelisted IddCx driver). #ifndef NOMINMAX -#define NOMINMAX + #define NOMINMAX #endif -#include - -#include -#include -#include - -#include -#include -#include - #include #include #include #include #include #include +#include +#include #include #include #include #include #include +#include +#include +#include +#include +#include using Microsoft::WRL::ComPtr; namespace vd = virtual_display::driver; @@ -141,10 +138,13 @@ namespace { if (label && now > deadline) { const long long stuck_ms = (now - g_op_started.load(std::memory_order_acquire)) / 1000000LL; if (!flagged || flagged_label != label) { - logmsg("*** HANG DETECTED *** operation '%s' in flight for %lld ms (exceeded its bound). " - "User-mode signature of the teardown wedge - capture a full dump of this process AND the " - "WUDFHost now.", - label, stuck_ms); + logmsg( + "*** HANG DETECTED *** operation '%s' in flight for %lld ms (exceeded its bound). " + "User-mode signature of the teardown wedge - capture a full dump of this process AND the " + "WUDFHost now.", + label, + stuck_ms + ); flagged = true; flagged_label = label; } else if (stuck_ms % 10000 < 600) { @@ -158,13 +158,19 @@ namespace { if (sclock::now() - last_heartbeat >= std::chrono::seconds(5)) { last_heartbeat = sclock::now(); - logmsg("heartbeat: sessions=%llu alt_tabs=%llu capture_reinits=%llu render_reinits=%llu frames=%llu " - "access_lost=%llu create_fail=%llu transport_fail=%llu%s", - (unsigned long long) g_sessions.load(), (unsigned long long) g_alttabs.load(), - (unsigned long long) g_capture_reinits.load(), (unsigned long long) g_render_reinits.load(), - (unsigned long long) g_capture_frames.load(), (unsigned long long) g_access_lost.load(), - (unsigned long long) g_create_fail.load(), (unsigned long long) g_transport_fail.load(), - label ? " (op in flight)" : ""); + logmsg( + "heartbeat: sessions=%llu alt_tabs=%llu capture_reinits=%llu render_reinits=%llu frames=%llu " + "access_lost=%llu create_fail=%llu transport_fail=%llu%s", + (unsigned long long) g_sessions.load(), + (unsigned long long) g_alttabs.load(), + (unsigned long long) g_capture_reinits.load(), + (unsigned long long) g_render_reinits.load(), + (unsigned long long) g_capture_frames.load(), + (unsigned long long) g_access_lost.load(), + (unsigned long long) g_create_fail.load(), + (unsigned long long) g_transport_fail.load(), + label ? " (op in flight)" : "" + ); } } } @@ -258,7 +264,9 @@ namespace { ref_ = std::move(ref); stop_.store(false, std::memory_order_release); reinit_.store(true, std::memory_order_release); - thread_ = std::thread([this]() { run(); }); + thread_ = std::thread([this]() { + run(); + }); } void request_reinit() { @@ -292,16 +300,14 @@ namespace { D3D_FEATURE_LEVEL_10_0, }; D3D_FEATURE_LEVEL got {}; - HRESULT hr = D3D11CreateDevice(ref_.adapter.Get(), D3D_DRIVER_TYPE_UNKNOWN, nullptr, 0, levels, - ARRAYSIZE(levels), D3D11_SDK_VERSION, &dev_, &got, &ctx_); + HRESULT hr = D3D11CreateDevice(ref_.adapter.Get(), D3D_DRIVER_TYPE_UNKNOWN, nullptr, 0, levels, ARRAYSIZE(levels), D3D11_SDK_VERSION, &dev_, &got, &ctx_); if (FAILED(hr)) { return false; } ComPtr output5; if (SUCCEEDED(ref_.output.As(&output5))) { - const DXGI_FORMAT formats[] {DXGI_FORMAT_B8G8R8A8_UNORM, DXGI_FORMAT_R10G10B10A2_UNORM, - DXGI_FORMAT_R16G16B16A16_FLOAT}; + const DXGI_FORMAT formats[] {DXGI_FORMAT_B8G8R8A8_UNORM, DXGI_FORMAT_R10G10B10A2_UNORM, DXGI_FORMAT_R16G16B16A16_FLOAT}; for (int attempt = 0; attempt < 2; ++attempt) { hr = output5->DuplicateOutput1(dev_.Get(), 0, ARRAYSIZE(formats), formats, &dup_); if (SUCCEEDED(hr)) { @@ -394,7 +400,9 @@ namespace { hold_ms_ = hold_ms; mode_ = mode; stop_.store(false, std::memory_order_release); - thread_ = std::thread([this]() { run(); }); + thread_ = std::thread([this]() { + run(); + }); } void stop_and_join() { @@ -444,16 +452,14 @@ namespace { const D3D_FEATURE_LEVEL levels[] {D3D_FEATURE_LEVEL_11_1, D3D_FEATURE_LEVEL_11_0, D3D_FEATURE_LEVEL_10_1}; D3D_FEATURE_LEVEL got {}; - if (FAILED(D3D11CreateDevice(ref_.adapter.Get(), D3D_DRIVER_TYPE_UNKNOWN, nullptr, 0, levels, - ARRAYSIZE(levels), D3D11_SDK_VERSION, &dev_, &got, &ctx_))) { + if (FAILED(D3D11CreateDevice(ref_.adapter.Get(), D3D_DRIVER_TYPE_UNKNOWN, nullptr, 0, levels, ARRAYSIZE(levels), D3D11_SDK_VERSION, &dev_, &got, &ctx_))) { return false; } ComPtr dxgi_dev; ComPtr adap; ComPtr factory; - if (FAILED(dev_.As(&dxgi_dev)) || FAILED(dxgi_dev->GetAdapter(&adap)) || - FAILED(adap->GetParent(IID_PPV_ARGS(&factory)))) { + if (FAILED(dev_.As(&dxgi_dev)) || FAILED(dxgi_dev->GetAdapter(&adap)) || FAILED(adap->GetParent(IID_PPV_ARGS(&factory)))) { return false; } @@ -522,8 +528,7 @@ namespace { if (active_) { ScopedOp op {"game_alttab_in", 15}; ShowWindow(hwnd_, SW_RESTORE); - SetWindowPos(hwnd_, HWND_TOPMOST, ref_.left, ref_.top, static_cast(ref_.width), - static_cast(ref_.height), SWP_SHOWWINDOW); + SetWindowPos(hwnd_, HWND_TOPMOST, ref_.left, ref_.top, static_cast(ref_.width), static_cast(ref_.height), SWP_SHOWWINDOW); SetForegroundWindow(hwnd_); } else { ScopedOp op {"game_alttab_out", 15}; @@ -553,9 +558,7 @@ namespace { // Allow our (SYSTEM) process to take/relinquish foreground so independent flip // promotes/demotes on the alt-tab toggle. SystemParametersInfoW(SPI_SETFOREGROUNDLOCKTIMEOUT, 0, reinterpret_cast(0), SPIF_SENDCHANGE); - hwnd_ = CreateWindowExW(0, L"AltTabStressGame", L"AltTabStress Game", WS_POPUP | WS_VISIBLE, ref_.left, - ref_.top, static_cast(ref_.width), static_cast(ref_.height), nullptr, - nullptr, GetModuleHandleW(nullptr), nullptr); + hwnd_ = CreateWindowExW(0, L"AltTabStressGame", L"AltTabStress Game", WS_POPUP | WS_VISIBLE, ref_.left, ref_.top, static_cast(ref_.width), static_cast(ref_.height), nullptr, nullptr, GetModuleHandleW(nullptr), nullptr); if (!hwnd_) { logmsg("game: CreateWindow failed err=%lu", GetLastError()); return; @@ -635,11 +638,11 @@ namespace { // --------------------------------------------------------------- session -- struct Args { - int minutes = 0; // 0 == run until Ctrl+C - int session_seconds = 6; // how long a "stream" stays connected + int minutes = 0; // 0 == run until Ctrl+C + int session_seconds = 6; // how long a "stream" stays connected int fullscreen_hold_ms = 150; // dwell time per game/desktop state (the alt-tab cadence) int session_gap_ms = 150; - int mode = 0; // 0 = borderless windowed (confirmed repro), 1 = exclusive fullscreen + int mode = 0; // 0 = borderless windowed (confirmed repro), 1 = exclusive fullscreen UINT width = 1920; UINT height = 1080; UINT refresh_millihz = 60000; @@ -671,9 +674,7 @@ namespace { if (created.status == vd::ControlStatus::TransportFailed) { g_transport_fail.fetch_add(1, std::memory_order_relaxed); } - logmsg("create_temporary_display failed: status=%s native_error=%lu (display_id=%llu)", - vd::to_string(created.status), (unsigned long) created.native_error, - (unsigned long long) display_id); + logmsg("create_temporary_display failed: status=%s native_error=%lu (display_id=%llu)", vd::to_string(created.status), (unsigned long) created.native_error, (unsigned long long) display_id); return; } create_value = created.value; @@ -759,8 +760,7 @@ namespace { rel.requested_timeout_ms = 30000; auto released = client.release_lease(rel); if (!released.ok()) { - logmsg("release_lease failed: status=%s native_error=%lu", vd::to_string(released.status), - (unsigned long) released.native_error); + logmsg("release_lease failed: status=%s native_error=%lu", vd::to_string(released.status), (unsigned long) released.native_error); if (released.status == vd::ControlStatus::TransportFailed) { g_transport_fail.fetch_add(1, std::memory_order_relaxed); } @@ -818,16 +818,16 @@ int main(int argc, char **argv) { SetConsoleCtrlHandler(ctrl_handler, TRUE); std::thread wd(watchdog_thread); - logmsg("alttab_stress starting. game=%s run=%s session=%ds hold=%dms gap=%dms vd=%ux%u@%umHz", - args.mode == 1 ? "exclusive-fullscreen" : "borderless-windowed", - args.minutes > 0 ? "timed" : "until-ctrl-c", args.session_seconds, args.fullscreen_hold_ms, - args.session_gap_ms, args.width, args.height, args.refresh_millihz); + logmsg("alttab_stress starting. game=%s run=%s session=%ds hold=%dms gap=%dms vd=%ux%u@%umHz", args.mode == 1 ? "exclusive-fullscreen" : "borderless-windowed", args.minutes > 0 ? "timed" : "until-ctrl-c", args.session_seconds, args.fullscreen_hold_ms, args.session_gap_ms, args.width, args.height, args.refresh_millihz); auto opened = vd::open_first_control_device(); if (!opened.ok()) { - logmsg("FATAL: could not open the virtual-display control device (status=%s native_error=%lu). " - "Run as LocalSystem (PsExec -s -i); the device SDDL grants only SY + the broker.", - vd::to_string(opened.status), (unsigned long) opened.native_error); + logmsg( + "FATAL: could not open the virtual-display control device (status=%s native_error=%lu). " + "Run as LocalSystem (PsExec -s -i); the device SDDL grants only SY + the broker.", + vd::to_string(opened.status), + (unsigned long) opened.native_error + ); g_stop.store(true, std::memory_order_release); if (wd.joinable()) { wd.join(); @@ -852,15 +852,13 @@ int main(int argc, char **argv) { vd::SetRenderAdapterRequest sra {}; sra.adapter_luid = luid; auto r = client.set_render_adapter(sra); - logmsg("set_render_adapter(luid=%ld:%lu) -> %s", (long) luid.high_part, (unsigned long) luid.low_part, - r.ok() ? "ok" : vd::to_string(r.status)); + logmsg("set_render_adapter(luid=%ld:%lu) -> %s", (long) luid.high_part, (unsigned long) luid.low_part, r.ok() ? "ok" : vd::to_string(r.status)); } } std::mt19937_64 rng {static_cast(GetCurrentProcessId()) ^ static_cast(now_ns())}; - const auto run_deadline = args.minutes > 0 ? sclock::now() + std::chrono::minutes(args.minutes) - : sclock::time_point::max(); + const auto run_deadline = args.minutes > 0 ? sclock::now() + std::chrono::minutes(args.minutes) : sclock::time_point::max(); while (!g_stop.load(std::memory_order_acquire) && sclock::now() < run_deadline) { run_session(client, rng, args); @@ -869,12 +867,18 @@ int main(int argc, char **argv) { } } - logmsg("stopping. final: sessions=%llu alt_tabs=%llu capture_reinits=%llu render_reinits=%llu frames=%llu " - "access_lost=%llu create_fail=%llu transport_fail=%llu", - (unsigned long long) g_sessions.load(), (unsigned long long) g_alttabs.load(), - (unsigned long long) g_capture_reinits.load(), (unsigned long long) g_render_reinits.load(), - (unsigned long long) g_capture_frames.load(), (unsigned long long) g_access_lost.load(), - (unsigned long long) g_create_fail.load(), (unsigned long long) g_transport_fail.load()); + logmsg( + "stopping. final: sessions=%llu alt_tabs=%llu capture_reinits=%llu render_reinits=%llu frames=%llu " + "access_lost=%llu create_fail=%llu transport_fail=%llu", + (unsigned long long) g_sessions.load(), + (unsigned long long) g_alttabs.load(), + (unsigned long long) g_capture_reinits.load(), + (unsigned long long) g_render_reinits.load(), + (unsigned long long) g_capture_frames.load(), + (unsigned long long) g_access_lost.load(), + (unsigned long long) g_create_fail.load(), + (unsigned long long) g_transport_fail.load() + ); g_stop.store(true, std::memory_order_release); if (wd.joinable()) { diff --git a/tools/virtualdisplay.cpp b/tools/virtualdisplay.cpp index c585edd..f165d62 100644 --- a/tools/virtualdisplay.cpp +++ b/tools/virtualdisplay.cpp @@ -1,8 +1,8 @@ -#include "virtual_display/driver/control_client.h" #include "virtual_display/driver/cli_commands.h" +#include "virtual_display/driver/control_client.h" #include "virtual_display/driver/device_identity.h" -#include "virtual_display/driver/windows_control_client.h" #include "virtual_display/driver/windows_cli_utils.h" +#include "virtual_display/driver/windows_control_client.h" #include #include @@ -19,11 +19,11 @@ #include #ifdef _WIN32 -#include -#include -#include -#include -#include + #include + #include + #include + #include + #include #endif namespace vdd = virtual_display::driver; @@ -199,9 +199,7 @@ namespace { std::vector everyone_sid; std::vector authenticated_users_sid; std::vector builtin_users_sid; - if (!create_known_sid(WinWorldSid, everyone_sid) || - !create_known_sid(WinAuthenticatedUserSid, authenticated_users_sid) || - !create_known_sid(WinBuiltinUsersSid, builtin_users_sid)) { + if (!create_known_sid(WinWorldSid, everyone_sid) || !create_known_sid(WinAuthenticatedUserSid, authenticated_users_sid) || !create_known_sid(WinBuiltinUsersSid, builtin_users_sid)) { return false; } @@ -584,7 +582,7 @@ namespace { if (now >= deadline) { break; } - Sleep(static_cast((std::min)(kBrokerServiceStatePollMs, deadline - now))); + Sleep(static_cast((std::min) (kBrokerServiceStatePollMs, deadline - now))); } while (true); std::cerr @@ -941,7 +939,7 @@ namespace { break; } - std::cerr << "failed to resolve default driver INF path\n"; + std::cerr << "failed to resolve default driver INF path\n"; return std::nullopt; } @@ -1167,15 +1165,13 @@ namespace { } HKEY key {}; - LSTATUS status = RegCreateKeyExW(HKEY_LOCAL_MACHINE, kVulkanImplicitLayersKey, 0, nullptr, 0, - KEY_SET_VALUE, nullptr, &key, nullptr); + LSTATUS status = RegCreateKeyExW(HKEY_LOCAL_MACHINE, kVulkanImplicitLayersKey, 0, nullptr, 0, KEY_SET_VALUE, nullptr, &key, nullptr); if (status != ERROR_SUCCESS) { std::cerr << "open implicit layer registry key failed native_error=" << status << '\n'; return 1; } const DWORD zero = 0; - status = RegSetValueExW(key, absolute.wstring().c_str(), 0, REG_DWORD, - reinterpret_cast(&zero), sizeof(zero)); + status = RegSetValueExW(key, absolute.wstring().c_str(), 0, REG_DWORD, reinterpret_cast(&zero), sizeof(zero)); RegCloseKey(key); if (status != ERROR_SUCCESS) { std::cerr << "register implicit layer failed native_error=" << status << '\n'; @@ -1268,8 +1264,7 @@ namespace { DWORD bytes_written = 0; const auto requested = static_cast(command.size()); DWORD native_error = ERROR_SUCCESS; - if (!write_broker_pipe(pipe.get(), command.data(), requested, bytes_written, native_error) || - bytes_written != requested) { + if (!write_broker_pipe(pipe.get(), command.data(), requested, bytes_written, native_error) || bytes_written != requested) { return {true, false, "error write_failed\n", native_error == ERROR_SUCCESS ? ERROR_WRITE_FAULT : native_error}; } @@ -1420,7 +1415,7 @@ namespace { } void print_display_state(const vdd::QueryDisplayStateResult &state) { - const auto entry_count = (std::min)(state.entry_count, vdd::kMaxDisplayStateEntries); + const auto entry_count = (std::min) (state.entry_count, vdd::kMaxDisplayStateEntries); std::cout << "permanent_displays=" << state.permanent_display_count << '\n' << "temporary_displays=" << state.temporary_display_count << '\n' diff --git a/tools/virtualdisplay_broker.cpp b/tools/virtualdisplay_broker.cpp index badf5e8..521b303 100644 --- a/tools/virtualdisplay_broker.cpp +++ b/tools/virtualdisplay_broker.cpp @@ -1,5 +1,5 @@ -#include "virtual_display/driver/control_client.h" #include "virtual_display/driver/broker_commands.h" +#include "virtual_display/driver/control_client.h" #include "virtual_display/driver/device_identity.h" #include "virtual_display/driver/display_identity.h" #include "virtual_display/driver/lease_store.h" @@ -25,9 +25,9 @@ #ifndef WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN #endif - #include #include #include + #include #include #endif @@ -208,8 +208,8 @@ namespace { ScopedHandle token; const bool opened_token = OpenThreadToken(GetCurrentThread(), TOKEN_QUERY, TRUE, token.put()); const bool authorized = opened_token && - (token_is_member_of_well_known_sid(token.get(), WinLocalSystemSid) || - token_is_member_of_well_known_sid(token.get(), WinBuiltinAdministratorsSid)); + (token_is_member_of_well_known_sid(token.get(), WinLocalSystemSid) || + token_is_member_of_well_known_sid(token.get(), WinBuiltinAdministratorsSid)); if (!RevertToSelf()) { report_event_log(EVENTLOG_ERROR_TYPE, kEventServiceFailed, L"RevertToSelf failed after pipe client impersonation"); std::terminate(); @@ -349,10 +349,7 @@ namespace { reinterpret_cast(&manifest), &size ); - if (status != ERROR_SUCCESS || - type != REG_BINARY || - size != sizeof(manifest) || - vdd::validate_display_manifest(manifest, max_display_count) != vdd::ValidationError::None) { + if (status != ERROR_SUCCESS || type != REG_BINARY || size != sizeof(manifest) || vdd::validate_display_manifest(manifest, max_display_count) != vdd::ValidationError::None) { return std::nullopt; } @@ -619,8 +616,8 @@ namespace { auto stop_event = duplicate_stop_event(); HANDLE wait_handles[] {process.hProcess, stop_event.get()}; const DWORD wait_result = stop_event.valid() ? - WaitForMultipleObjects(2, wait_handles, FALSE, kHelperProcessTimeoutMs) : - WaitForSingleObject(process.hProcess, kHelperProcessTimeoutMs); + WaitForMultipleObjects(2, wait_handles, FALSE, kHelperProcessTimeoutMs) : + WaitForSingleObject(process.hProcess, kHelperProcessTimeoutMs); if (wait_result == WAIT_TIMEOUT || wait_result == WAIT_OBJECT_0 + 1) { TerminateProcess(process.hProcess, wait_result == WAIT_TIMEOUT ? ERROR_TIMEOUT : ERROR_CANCELLED); WaitForSingleObject(process.hProcess, 5000); @@ -704,7 +701,7 @@ namespace { const auto original_manifest = manifest.value; manifest.value.max_profile_count = current.value.max_display_count; const auto bounded_profile_count = - (std::min)(manifest.value.profile_count, vdd::kMaxPermanentDisplayProfiles); + (std::min) (manifest.value.profile_count, vdd::kMaxPermanentDisplayProfiles); std::optional profile_index; for (std::uint32_t index = 0; index < bounded_profile_count; ++index) { if (manifest.value.profiles[index].connector_index == profile->connector_index) { @@ -713,8 +710,7 @@ namespace { } } if (!profile_index) { - if (bounded_profile_count >= manifest.value.max_profile_count || - bounded_profile_count >= vdd::kMaxPermanentDisplayProfiles) { + if (bounded_profile_count >= manifest.value.max_profile_count || bounded_profile_count >= vdd::kMaxPermanentDisplayProfiles) { return "error manifest_full\n"; } profile_index = bounded_profile_count; @@ -771,8 +767,7 @@ namespace { report_event_log(EVENTLOG_INFORMATION_TYPE, kEventHelperStarting, L"Starting client-session helper"); auto helper_result = launch_session_helper(*session_id, *helper_arguments); if (helper_result.exit_code == ERROR_NO_TOKEN) { - if (const auto console_session_id = active_console_session_id(); - console_session_id && *console_session_id != *session_id) { + if (const auto console_session_id = active_console_session_id(); console_session_id && *console_session_id != *session_id) { report_event_log(EVENTLOG_INFORMATION_TYPE, kEventHelperStarting, L"Retrying helper in active console session"); helper_result = launch_session_helper(*console_session_id, *helper_arguments); } @@ -831,7 +826,7 @@ namespace { if (!read_ok || bytes_read == 0) { response = "error read_failed\n"; } else { - input[(std::min)(bytes_read, sizeof(input) - 1)] = '\0'; + input[(std::min) (bytes_read, sizeof(input) - 1)] = '\0'; response = handle_command(client, pipe, vdd::trim_broker_command(input)); } @@ -839,7 +834,7 @@ namespace { (void) WriteFile( pipe, response.data(), - static_cast((std::min)(response.size(), (std::numeric_limits::max)())), + static_cast((std::min) (response.size(), (std::numeric_limits::max)())), &bytes_written, nullptr ); diff --git a/tools/virtualdisplay_probe.cpp b/tools/virtualdisplay_probe.cpp index c2b88ac..25293b7 100644 --- a/tools/virtualdisplay_probe.cpp +++ b/tools/virtualdisplay_probe.cpp @@ -1,10 +1,10 @@ #include "virtual_display/driver/control_client.h" -#include "virtual_display/driver/probe_commands.h" #include "virtual_display/driver/device_identity.h" +#include "virtual_display/driver/probe_commands.h" #include "virtual_display/driver/windows_control_client.h" -#include #include +#include #include #include #include @@ -29,8 +29,8 @@ #include #include #include - #include #include + #include #endif namespace vdd = virtual_display::driver; @@ -63,7 +63,7 @@ namespace { std::wstring widen_ascii(const std::string_view text) { std::wstring wide; wide.reserve(text.size()); - for (const unsigned char ch: text) { + for (const unsigned char ch : text) { wide.push_back(static_cast(ch)); } return wide; @@ -222,6 +222,7 @@ namespace { struct DisplayConfigGetAdvancedColorInfo2 { DISPLAYCONFIG_DEVICE_INFO_HEADER header {}; + union { struct { std::uint32_t advanced_color_supported : 1; @@ -234,8 +235,10 @@ namespace { std::uint32_t wide_color_user_enabled : 1; std::uint32_t reserved : 24; }; + std::uint32_t value; }; + DISPLAYCONFIG_COLOR_ENCODING color_encoding = DISPLAYCONFIG_COLOR_ENCODING_RGB; std::uint32_t bits_per_color_channel = 0; std::uint32_t active_color_mode = 0; @@ -243,11 +246,13 @@ namespace { struct DisplayConfigSetHdrState { DISPLAYCONFIG_DEVICE_INFO_HEADER header {}; + union { struct { std::uint32_t enable_hdr : 1; std::uint32_t reserved : 31; }; + std::uint32_t value; }; }; @@ -415,8 +420,8 @@ namespace { return {std::nullopt, result}; } - const auto next_path_count = (std::max)(query_path_count, static_cast(paths.size() + 1)); - const auto next_mode_count = (std::max)(query_mode_count, static_cast(modes.size() + 1)); + const auto next_path_count = (std::max) (query_path_count, static_cast(paths.size() + 1)); + const auto next_mode_count = (std::max) (query_mode_count, static_cast(modes.size() + 1)); if (!vdd::display_config_counts_are_reasonable(next_path_count, next_mode_count)) { return {std::nullopt, ERROR_INVALID_DATA}; } @@ -483,7 +488,7 @@ namespace { } const auto bounded_profile_count = - (std::min)(manifest.profile_count, vdd::kMaxPermanentDisplayProfiles); + (std::min) (manifest.profile_count, vdd::kMaxPermanentDisplayProfiles); for (std::uint32_t index = 0; index < bounded_profile_count; ++index) { const auto &profile = manifest.profiles[index]; if (profile.connector_index == path.targetInfo.id && profile.layout_policy != vdd::kDisplayManifestLayoutPolicyNone) { @@ -535,7 +540,7 @@ namespace { bool save_to_database = false; std::uint32_t applied_profiles = 0; - for (auto &path: paths) { + for (auto &path : paths) { if ((path.flags & DISPLAYCONFIG_PATH_ACTIVE) == 0) { continue; } @@ -648,7 +653,7 @@ namespace { std::vector topology_paths; UINT32 clone_group_id = 0; - for (auto path: display_config.paths) { + for (auto path : display_config.paths) { if ((path.flags & DISPLAYCONFIG_PATH_ACTIVE) == 0) { continue; } @@ -664,10 +669,8 @@ namespace { } std::optional target_path; - for (auto path: display_config.paths) { - if (!same_luid(path.targetInfo.adapterId, luid) || - path.targetInfo.id != target_id || - !path.targetInfo.targetAvailable) { + for (auto path : display_config.paths) { + if (!same_luid(path.targetInfo.adapterId, luid) || path.targetInfo.id != target_id || !path.targetInfo.targetAvailable) { continue; } @@ -710,11 +713,11 @@ namespace { requested_modes.push_back(target_mode); if (virtual_mode_aware) { -#if defined(__MINGW32__) + #if defined(__MINGW32__) requested_target.sourceInfo.sourceModeInfoIdx = source_mode_index; requested_target.targetInfo.targetModeInfoIdx = target_mode_index; requested_target.targetInfo.desktopModeInfoIdx = DISPLAYCONFIG_PATH_DESKTOP_IMAGE_IDX_INVALID; -#else + #else const auto desktop_mode_index = static_cast(requested_modes.size()); DISPLAYCONFIG_MODE_INFO desktop_mode {}; desktop_mode.infoType = DISPLAYCONFIG_MODE_INFO_TYPE_DESKTOP_IMAGE; @@ -736,7 +739,7 @@ namespace { requested_target.sourceInfo.sourceModeInfoIdx = source_mode_index; requested_target.targetInfo.targetModeInfoIdx = target_mode_index; requested_target.targetInfo.desktopModeInfoIdx = desktop_mode_index; -#endif + #endif } else { requested_target.sourceInfo.modeInfoIdx = source_mode_index; requested_target.targetInfo.modeInfoIdx = target_mode_index; @@ -769,7 +772,7 @@ namespace { auto full_paths = std::move(fallback_query.data->paths); clone_group_id = 0; bool found_target = false; - for (auto &path: full_paths) { + for (auto &path : full_paths) { const bool already_active = (path.flags & DISPLAYCONFIG_PATH_ACTIVE) != 0; const bool is_target = same_luid(path.targetInfo.adapterId, luid) && @@ -869,7 +872,7 @@ namespace { QDC_ONLY_ACTIVE_PATHS }; - for (const auto flags: kQueryFlags) { + for (const auto flags : kQueryFlags) { auto display_config = query_display_config(flags); if (!display_config) { std::cout << "active_paths_query_error flags=" << flags << '\n'; @@ -995,7 +998,7 @@ namespace { signal.hSyncFreq.Denominator = total_width == 0 ? 1 : total_width; signal.vSyncFreq.Numerator = vdd::saturating_u32(signal.pixelRate); signal.vSyncFreq.Denominator = vdd::saturating_u32( - (std::max)(1, vdd::saturating_mul_u64(total_width, total_height)) + (std::max) (1, vdd::saturating_mul_u64(total_width, total_height)) ); signal.activeSize.cx = width; signal.activeSize.cy = height; @@ -1041,15 +1044,14 @@ namespace { QDC_ONLY_ACTIVE_PATHS }; - for (const auto flags: kQueryFlags) { + for (const auto flags : kQueryFlags) { auto display_config = query_display_config(flags); if (!display_config) { continue; } - for (const auto &path: display_config->paths) { - if (!same_luid(path.targetInfo.adapterId, luid) || - path.targetInfo.id != target_id) { + for (const auto &path : display_config->paths) { + if (!same_luid(path.targetInfo.adapterId, luid) || path.targetInfo.id != target_id) { continue; } @@ -1063,17 +1065,14 @@ namespace { if (mode.infoType == DISPLAYCONFIG_MODE_INFO_TYPE_TARGET) { info.width = mode.targetMode.targetVideoSignalInfo.activeSize.cx; info.height = mode.targetMode.targetVideoSignalInfo.activeSize.cy; - if (info.refresh_millihz == 0 && - mode.targetMode.targetVideoSignalInfo.vSyncFreq.Denominator != 0) { + if (info.refresh_millihz == 0 && mode.targetMode.targetVideoSignalInfo.vSyncFreq.Denominator != 0) { info.refresh_millihz = rational_to_millihz(mode.targetMode.targetVideoSignalInfo.vSyncFreq); } } } const auto source_idx = source_mode_index(path, flags); - if ((info.width == 0 || info.height == 0) && - source_idx && - *source_idx < display_config->modes.size()) { + if ((info.width == 0 || info.height == 0) && source_idx && *source_idx < display_config->modes.size()) { const auto &mode = display_config->modes[*source_idx]; if (mode.infoType == DISPLAYCONFIG_MODE_INFO_TYPE_SOURCE) { info.width = mode.sourceMode.width; @@ -1118,8 +1117,8 @@ namespace { ) { const auto requested_refresh = vdd::refresh_millihz_from_hz(refresh_hz); const auto refresh_delta = path.refresh_millihz > requested_refresh ? - path.refresh_millihz - requested_refresh : - requested_refresh - path.refresh_millihz; + path.refresh_millihz - requested_refresh : + requested_refresh - path.refresh_millihz; return path.active && path.width == width && path.height == height && @@ -1136,7 +1135,7 @@ namespace { return std::nullopt; } - for (const auto &path: display_config->paths) { + for (const auto &path : display_config->paths) { if (same_luid(path.targetInfo.adapterId, luid) && path.targetInfo.id == target_id) { return path.sourceInfo.id; } @@ -1391,7 +1390,7 @@ namespace { LPWSTR *value_ {}; }; - using ColorProfileGetDisplayDefaultFn = HRESULT (WINAPI *)( + using ColorProfileGetDisplayDefaultFn = HRESULT(WINAPI *)( WCS_PROFILE_MANAGEMENT_SCOPE, LUID, UINT32, @@ -1399,19 +1398,19 @@ namespace { COLORPROFILESUBTYPE, LPWSTR * ); - using ColorProfileGetDisplayListFn = HRESULT (WINAPI *)( + using ColorProfileGetDisplayListFn = HRESULT(WINAPI *)( WCS_PROFILE_MANAGEMENT_SCOPE, LUID, UINT32, LPWSTR **, PDWORD ); - using ColorProfileGetDisplayUserScopeFn = HRESULT (WINAPI *)( + using ColorProfileGetDisplayUserScopeFn = HRESULT(WINAPI *)( LUID, UINT32, WCS_PROFILE_MANAGEMENT_SCOPE * ); - using ColorProfileAddDisplayAssociationFn = HRESULT (WINAPI *)( + using ColorProfileAddDisplayAssociationFn = HRESULT(WINAPI *)( WCS_PROFILE_MANAGEMENT_SCOPE, PCWSTR, LUID, @@ -1531,7 +1530,7 @@ namespace { std::size_t active_paths = 0; std::size_t queried = 0; - for (const auto &path: display_config->paths) { + for (const auto &path : display_config->paths) { if ((path.flags & DISPLAYCONFIG_PATH_ACTIVE) == 0) { continue; } @@ -1674,10 +1673,7 @@ namespace { mode_enumeration_limit_reached = false; break; } - if (enumerated.dmPelsWidth == width && - enumerated.dmPelsHeight == height && - enumerated.dmDisplayFrequency == refresh_hz && - matching_modes != (std::numeric_limits::max)()) { + if (enumerated.dmPelsWidth == width && enumerated.dmPelsHeight == height && enumerated.dmDisplayFrequency == refresh_hz && matching_modes != (std::numeric_limits::max)()) { ++matching_modes; } } @@ -2077,9 +2073,11 @@ int main(const int argc, char **argv) { restore.display_count = before.value.current_display_count; return client.set_permanent_display_count(restore); }; + struct RestorePermanentCountOnExit { bool &restore_needed; const std::function()> restore; + ~RestorePermanentCountOnExit() { if (restore_needed) { (void) restore(); @@ -2119,9 +2117,7 @@ int main(const int argc, char **argv) { std::uint32_t width {}; std::uint32_t height {}; std::uint32_t refresh_hz {}; - if (!read_u32_arg(argc, argv, 2, 1920u, "width", width) || - !read_u32_arg(argc, argv, 3, 1080u, "height", height) || - !read_u32_arg(argc, argv, 4, 60u, "refresh_hz", refresh_hz)) { + if (!read_u32_arg(argc, argv, 2, 1920u, "width", width) || !read_u32_arg(argc, argv, 3, 1080u, "height", height) || !read_u32_arg(argc, argv, 4, 60u, "refresh_hz", refresh_hz)) { return 2; } const auto request = make_temporary_request(width, height, refresh_hz); @@ -2176,9 +2172,7 @@ int main(const int argc, char **argv) { std::uint32_t width {}; std::uint32_t height {}; std::uint32_t refresh_hz {}; - if (!read_u32_arg(argc, argv, 2, 1920u, "width", width) || - !read_u32_arg(argc, argv, 3, 1080u, "height", height) || - !read_u32_arg(argc, argv, 4, 60u, "refresh_hz", refresh_hz)) { + if (!read_u32_arg(argc, argv, 2, 1920u, "width", width) || !read_u32_arg(argc, argv, 3, 1080u, "height", height) || !read_u32_arg(argc, argv, 4, 60u, "refresh_hz", refresh_hz)) { return 2; } const auto request = make_temporary_request(width, height, refresh_hz); @@ -2264,10 +2258,7 @@ int main(const int argc, char **argv) { std::uint32_t height {}; std::uint32_t refresh_hz {}; std::uint32_t timeout_ms {}; - if (!read_u32_arg(argc, argv, 2, 1920u, "width", width) || - !read_u32_arg(argc, argv, 3, 1080u, "height", height) || - !read_u32_arg(argc, argv, 4, 60u, "refresh_hz", refresh_hz) || - !read_u32_arg(argc, argv, 5, 3'000u, "timeout_ms", timeout_ms)) { + if (!read_u32_arg(argc, argv, 2, 1920u, "width", width) || !read_u32_arg(argc, argv, 3, 1080u, "height", height) || !read_u32_arg(argc, argv, 4, 60u, "refresh_hz", refresh_hz) || !read_u32_arg(argc, argv, 5, 3'000u, "timeout_ms", timeout_ms)) { return 2; } auto request = make_temporary_request(width, height, refresh_hz); @@ -2299,10 +2290,7 @@ int main(const int argc, char **argv) { return fail("query expired lease failed", expired); } - if (active.value.lease_exists == 0 || - active.value.temporary_display_count != 1 || - expired.value.lease_exists != 0 || - expired.value.temporary_display_count != 0) { + if (active.value.lease_exists == 0 || active.value.temporary_display_count != 1 || expired.value.lease_exists != 0 || expired.value.temporary_display_count != 0) { (void) client.remove_temporary_display({vdd::kApiNamespaceGuid, request.lease_id, request.display_id}); std::cerr << "lease expiry state mismatch" << " active_exists=" << active.value.lease_exists @@ -2327,8 +2315,7 @@ int main(const int argc, char **argv) { } std::uint32_t count {}; std::uint32_t timeout_ms {}; - if (!read_u32_arg(argc, argv, 2, 3u, "count", count) || - !read_u32_arg(argc, argv, 3, 3'000u, "timeout_ms", timeout_ms)) { + if (!read_u32_arg(argc, argv, 2, 3u, "count", count) || !read_u32_arg(argc, argv, 3, 3'000u, "timeout_ms", timeout_ms)) { return 2; } if (count == 0 || count > 8) { @@ -2347,12 +2334,7 @@ int main(const int argc, char **argv) { created_displays.reserve(count); connector_indexes.reserve(count); for (std::uint32_t index = 0; index < count; ++index) { - constexpr std::array, 4> kSizes {{ - {1280u, 720u}, - {1920u, 1080u}, - {2560u, 1440u}, - {3840u, 2160u} - }}; + constexpr std::array, 4> kSizes {{{1280u, 720u}, {1920u, 1080u}, {2560u, 1440u}, {3840u, 2160u}}}; const auto [width, height] = kSizes[index % kSizes.size()]; auto request = make_temporary_request(width, height, index % 2 == 0 ? 60u : 120u); request.lease_id = lease_id; @@ -2420,7 +2402,7 @@ int main(const int argc, char **argv) { << " count=" << count << " effective_timeout_ms=" << active.value.effective_timeout_ms << " expired=1"; - for (const auto connector_index: connector_indexes) { + for (const auto connector_index : connector_indexes) { std::cout << " connector_index=" << connector_index; } std::cout << '\n'; @@ -2435,10 +2417,7 @@ int main(const int argc, char **argv) { std::uint32_t height {}; std::uint32_t refresh_hz {}; std::uint32_t timeout_ms {}; - if (!read_u32_arg(argc, argv, 2, 1920u, "width", width) || - !read_u32_arg(argc, argv, 3, 1080u, "height", height) || - !read_u32_arg(argc, argv, 4, 60u, "refresh_hz", refresh_hz) || - !read_u32_arg(argc, argv, 5, 30'000u, "timeout_ms", timeout_ms)) { + if (!read_u32_arg(argc, argv, 2, 1920u, "width", width) || !read_u32_arg(argc, argv, 3, 1080u, "height", height) || !read_u32_arg(argc, argv, 4, 60u, "refresh_hz", refresh_hz) || !read_u32_arg(argc, argv, 5, 30'000u, "timeout_ms", timeout_ms)) { return 2; } @@ -2521,10 +2500,7 @@ int main(const int argc, char **argv) { std::cerr << "Windows rejected both retained identity HDR and Advanced Color enable requests\n"; return 1; } - if (first_after_color->limited_by_policy || - !first_after_color->supported || - !first_after_color->hdr_enabled || - first_after_color->bits_per_color_channel < 10) { + if (first_after_color->limited_by_policy || !first_after_color->supported || !first_after_color->hdr_enabled || first_after_color->bits_per_color_channel < 10) { (void) remove_first(); std::cerr << "retained identity display did not enter HDR 10-bit mode after request\n"; return 1; @@ -2594,8 +2570,7 @@ int main(const int argc, char **argv) { (void) client.feed_lease(filler_lease); }; - if (second.value.connector_index != first.value.connector_index || - second.value.target_id != first.value.target_id) { + if (second.value.connector_index != first.value.connector_index || second.value.target_id != first.value.target_id) { (void) cleanup_second(); (void) client.release_lease(filler_lease); std::cerr << "retained identity changed connector/target" @@ -2630,11 +2605,7 @@ int main(const int argc, char **argv) { return 1; } print_advanced_color(*restored_color); - if (restored_color->limited_by_policy || - !restored_color->supported || - !restored_color->hdr_supported || - !restored_color->hdr_enabled || - restored_color->bits_per_color_channel < 10) { + if (restored_color->limited_by_policy || !restored_color->supported || !restored_color->hdr_supported || !restored_color->hdr_enabled || restored_color->bits_per_color_channel < 10) { (void) cleanup_second(); (void) client.release_lease(filler_lease); std::cerr << "HDR profile was not retained for recreated temporary display\n"; @@ -2676,10 +2647,7 @@ int main(const int argc, char **argv) { std::uint32_t height {}; std::uint32_t refresh_hz {}; std::uint32_t timeout_ms {}; - if (!read_u32_arg(argc, argv, 2, 1920u, "width", width) || - !read_u32_arg(argc, argv, 3, 1080u, "height", height) || - !read_u32_arg(argc, argv, 4, 60u, "refresh_hz", refresh_hz) || - !read_u32_arg(argc, argv, 5, 10'000u, "timeout_ms", timeout_ms)) { + if (!read_u32_arg(argc, argv, 2, 1920u, "width", width) || !read_u32_arg(argc, argv, 3, 1080u, "height", height) || !read_u32_arg(argc, argv, 4, 60u, "refresh_hz", refresh_hz) || !read_u32_arg(argc, argv, 5, 10'000u, "timeout_ms", timeout_ms)) { return 2; } auto request = make_temporary_request(width, height, refresh_hz); @@ -2764,10 +2732,7 @@ int main(const int argc, char **argv) { std::uint32_t width {}; std::uint32_t height {}; std::uint32_t refresh_hz {}; - if (!read_u32_arg(argc, argv, 2, 10u, "iterations", iterations) || - !read_u32_arg(argc, argv, 3, 1280u, "width", width) || - !read_u32_arg(argc, argv, 4, 720u, "height", height) || - !read_u32_arg(argc, argv, 5, 60u, "refresh_hz", refresh_hz)) { + if (!read_u32_arg(argc, argv, 2, 10u, "iterations", iterations) || !read_u32_arg(argc, argv, 3, 1280u, "width", width) || !read_u32_arg(argc, argv, 4, 720u, "height", height) || !read_u32_arg(argc, argv, 5, 60u, "refresh_hz", refresh_hz)) { return 2; } if (iterations == 0) { @@ -2900,10 +2865,7 @@ int main(const int argc, char **argv) { std::uint32_t height {}; std::uint32_t refresh_hz {}; std::uint32_t timeout_ms {}; - if (!read_u32_arg(argc, argv, 2, 1920u, "width", width) || - !read_u32_arg(argc, argv, 3, 1080u, "height", height) || - !read_u32_arg(argc, argv, 4, 60u, "refresh_hz", refresh_hz) || - !read_u32_arg(argc, argv, 5, 3'000u, "timeout_ms", timeout_ms)) { + if (!read_u32_arg(argc, argv, 2, 1920u, "width", width) || !read_u32_arg(argc, argv, 3, 1080u, "height", height) || !read_u32_arg(argc, argv, 4, 60u, "refresh_hz", refresh_hz) || !read_u32_arg(argc, argv, 5, 3'000u, "timeout_ms", timeout_ms)) { return 2; } auto request = make_temporary_request(width, height, refresh_hz); @@ -3010,10 +2972,7 @@ int main(const int argc, char **argv) { std::cerr << "Windows rejected both QA HDR and Advanced Color enable requests\n"; return 1; } - if (after_color->limited_by_policy || - !after_color->supported || - !after_color->hdr_enabled || - after_color->bits_per_color_channel < 10) { + if (after_color->limited_by_policy || !after_color->supported || !after_color->hdr_enabled || after_color->bits_per_color_channel < 10) { (void) cleanup_created(); std::cerr << "QA display did not enter HDR 10-bit mode after request\n"; return 1;