1#![doc(html_favicon_url = "https://zng-ui.github.io/res/zng-logo-icon.png")]
2#![doc(html_logo_url = "https://zng-ui.github.io/res/zng-logo.png")]
3#![doc = include_str!(concat!("../", std::env!("CARGO_PKG_README")))]
56
57use zng_app::{
58 third_party::{LICENSES, License, LicenseUsed, User},
59 view_process::{VIEW_PROCESS, VIEW_PROCESS_INITED_EVENT},
60};
61use zng_ext_window::{WINDOW_Ext as _, WINDOWS_EXTENSIONS};
62use zng_view_api::api_extension::*;
63use zng_wgt::prelude::*;
64
65fn init(win_id: WindowId) {
66 const EXT_NAME: &str = "zng-view.prefer_angle";
67 let ext_id = VIEW_PROCESS
68 .extension_id(EXT_NAME)
69 .ok()
70 .flatten()
71 .unwrap_or(ApiExtensionId::INVALID);
72 if ext_id == ApiExtensionId::INVALID {
73 return tracing::error!("view-process does not support {EXT_NAME:?}");
74 }
75
76 WINDOWS_EXTENSIONS
77 .view_extensions_init(win_id, ext_id, ApiExtensionPayload::serialize(&true).unwrap())
78 .unwrap();
79}
80
81#[property(CONTEXT)]
89pub fn prefer_angle_egl(child: impl IntoUiNode, enable: impl IntoValue<bool>) -> UiNode {
90 if enable.into() && cfg!(windows) {
91 match_node(child, move |_c, op| {
92 if let UiNodeOp::Init = op {
93 let win_id = WINDOW.id();
94
95 let mut loading_handle = None;
96 if VIEW_PROCESS.is_connected() {
97 init(win_id);
98 } else {
99 loading_handle = WINDOW.loading_handle(5.secs(), "prefer_angle_egl");
100 }
101 let handle = VIEW_PROCESS_INITED_EVENT.hook(move |_| {
102 let _ = loading_handle.take();
103 init(win_id);
104 true
106 });
107 WIDGET.push_var_handle(handle);
108 }
109 })
110 } else {
111 child.into_node()
112 }
113}
114
115pub fn register_root_extender() {
121 WINDOWS_EXTENSIONS.register_root_extender(|a| prefer_angle_egl(a.root, true));
122}
123
124pub fn register_license() {
128 fn l() -> Vec<LicenseUsed> {
129 vec![LicenseUsed {
130 license: License::new("BSD3-Clause", r#"BSD 3-Clause "Revised" License"#, LICENSE),
131 used_by: vec![User::new(
132 "ANGLE",
133 "fca8ca8",
134 "https://github.com/zng-ui/build-angle/releases/tag/2026-05-17",
135 )],
136 }]
137 }
138 LICENSES.register(l);
139}
140
141const LICENSE: &str = r#"
142// Copyright 2018 The ANGLE Project Authors.
143// All rights reserved.
144//
145// Redistribution and use in source and binary forms, with or without
146// modification, are permitted provided that the following conditions
147// are met:
148//
149// Redistributions of source code must retain the above copyright
150// notice, this list of conditions and the following disclaimer.
151//
152// Redistributions in binary form must reproduce the above
153// copyright notice, this list of conditions and the following
154// disclaimer in the documentation and/or other materials provided
155// with the distribution.
156//
157// Neither the name of TransGaming Inc., Google Inc., 3DLabs Inc.
158// Ltd., nor the names of their contributors may be used to endorse
159// or promote products derived from this software without specific
160// prior written permission.
161//
162// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
163// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
164// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
165// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
166// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
167// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
168// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
169// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
170// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
171// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
172// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
173// POSSIBILITY OF SUCH DAMAGE.
174"#;