mirror of
https://github.com/mileswolfallen2/browser.git
synced 2026-12-05 16:40:41 +00:00
working to make it more stabel
This commit is contained in:
1 parent
014a8cf8b7
commit
f2a1898039
4 files changed
+69
-6
No files matched your search
Generated
+15
-4
@@ -77,16 +77,16 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "aes-gcm"
|
name = "aes-gcm"
|
||||||
version = "0.11.0"
|
version = "0.11.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "fdf011db2e21ce0d575593d749db5554b47fed37aff429e4dc50bc91ac93a028"
|
checksum = "7f2b8006a0c83f52b62ba44a97b58bf76fe2f70a329e588f67f89691d93d498f"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"aead",
|
"aead",
|
||||||
"aes",
|
"aes",
|
||||||
"cipher",
|
"cipher",
|
||||||
"ctr",
|
"ctr",
|
||||||
|
"ctutils",
|
||||||
"ghash",
|
"ghash",
|
||||||
"subtle",
|
|
||||||
"zeroize",
|
"zeroize",
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -2380,6 +2380,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
checksum = "2eecf2d5dc9b66b732b97707a0210906b1d30523eb773193ab777c0c84b3e8d5"
|
checksum = "2eecf2d5dc9b66b732b97707a0210906b1d30523eb773193ab777c0c84b3e8d5"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"polyval",
|
"polyval",
|
||||||
|
"zeroize",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -5167,6 +5168,7 @@ dependencies = [
|
|||||||
"cpubits",
|
"cpubits",
|
||||||
"cpufeatures 0.3.0",
|
"cpufeatures 0.3.0",
|
||||||
"universal-hash",
|
"universal-hash",
|
||||||
|
"zeroize",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -5800,7 +5802,7 @@ dependencies = [
|
|||||||
"errno",
|
"errno",
|
||||||
"libc",
|
"libc",
|
||||||
"linux-raw-sys 0.4.15",
|
"linux-raw-sys 0.4.15",
|
||||||
"windows-sys 0.52.0",
|
"windows-sys 0.59.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -9845,6 +9847,15 @@ dependencies = [
|
|||||||
"windows-targets 0.52.6",
|
"windows-targets 0.52.6",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows-sys"
|
||||||
|
version = "0.59.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b"
|
||||||
|
dependencies = [
|
||||||
|
"windows-targets 0.52.6",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "windows-sys"
|
name = "windows-sys"
|
||||||
version = "0.60.2"
|
version = "0.60.2"
|
||||||
|
|||||||
@@ -20,3 +20,12 @@ servo = "0.5.0"
|
|||||||
url = "2"
|
url = "2"
|
||||||
wgpu = "30.0.0"
|
wgpu = "30.0.0"
|
||||||
winit = "0.30.13"
|
winit = "0.30.13"
|
||||||
|
|
||||||
|
[profile.dev.package."*"]
|
||||||
|
# Optimize dependencies (Servo, WebRender, wgpu…) even in dev builds —
|
||||||
|
# unoptimized engines are unusably slow, while keeping our crate debuggable.
|
||||||
|
opt-level = 2
|
||||||
|
|
||||||
|
[profile.release]
|
||||||
|
lto = "thin"
|
||||||
|
codegen-units = 1
|
||||||
+39
-2
@@ -30,12 +30,17 @@ const CHROME_BG_DARKER: egui::Color32 = egui::Color32::from_rgb(223, 223, 230);
|
|||||||
const TAB_ACTIVE_BG: egui::Color32 = egui::Color32::WHITE;
|
const TAB_ACTIVE_BG: egui::Color32 = egui::Color32::WHITE;
|
||||||
const ACCENT: egui::Color32 = egui::Color32::from_rgb(0, 97, 224);
|
const ACCENT: egui::Color32 = egui::Color32::from_rgb(0, 97, 224);
|
||||||
|
|
||||||
|
/// Minimum time between expensive GPU->CPU page readbacks (~one vsync).
|
||||||
|
const MIN_PAINT_INTERVAL: Duration = Duration::from_millis(15);
|
||||||
|
|
||||||
pub struct BrowserApp {
|
pub struct BrowserApp {
|
||||||
proxy: EventLoopProxy<UserEvent>,
|
proxy: EventLoopProxy<UserEvent>,
|
||||||
window: Option<Arc<Window>>,
|
window: Option<Arc<Window>>,
|
||||||
gpu: Option<Gpu>,
|
gpu: Option<Gpu>,
|
||||||
engine: Option<Rc<Engine>>,
|
// NOTE: `tabs` must be dropped BEFORE `engine` — closing a WebView sends a
|
||||||
|
// message to Servo, which must still be alive when that happens.
|
||||||
tabs: Vec<Tab>,
|
tabs: Vec<Tab>,
|
||||||
|
engine: Option<Rc<Engine>>,
|
||||||
active: usize,
|
active: usize,
|
||||||
url_edit: String,
|
url_edit: String,
|
||||||
url_bar_focused: bool,
|
url_bar_focused: bool,
|
||||||
@@ -63,8 +68,8 @@ impl BrowserApp {
|
|||||||
proxy,
|
proxy,
|
||||||
window: None,
|
window: None,
|
||||||
gpu: None,
|
gpu: None,
|
||||||
engine: None,
|
|
||||||
tabs: Vec::new(),
|
tabs: Vec::new(),
|
||||||
|
engine: None,
|
||||||
active: 0,
|
active: 0,
|
||||||
url_edit: START_PAGE.to_owned(),
|
url_edit: START_PAGE.to_owned(),
|
||||||
url_bar_focused: false,
|
url_bar_focused: false,
|
||||||
@@ -380,6 +385,12 @@ impl BrowserApp {
|
|||||||
if !tab.dirty {
|
if !tab.dirty {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
// Throttle GPU->CPU readbacks: a full-surface read is expensive, so skip
|
||||||
|
// frames arriving sooner than one vsync after the previous read. Keep the
|
||||||
|
// dirty flag so the next redraw picks the newer frame up instead.
|
||||||
|
if tab.last_paint.elapsed() < MIN_PAINT_INTERVAL {
|
||||||
|
return;
|
||||||
|
}
|
||||||
tab.webview.paint();
|
tab.webview.paint();
|
||||||
|
|
||||||
let size = tab.webview.size();
|
let size = tab.webview.size();
|
||||||
@@ -391,8 +402,24 @@ impl BrowserApp {
|
|||||||
let rect = euclid::Box2D::from_origin_and_size(euclid::point2(0, 0), euclid::size2(w, h));
|
let rect = euclid::Box2D::from_origin_and_size(euclid::point2(0, 0), euclid::size2(w, h));
|
||||||
let rc = tab.webview.rendering_context();
|
let rc = tab.webview.rendering_context();
|
||||||
if let Some(img) = rc.read_to_image(rect) {
|
if let Some(img) = rc.read_to_image(rect) {
|
||||||
|
tab.last_paint = Instant::now();
|
||||||
let dims = [img.width() as usize, img.height() as usize];
|
let dims = [img.width() as usize, img.height() as usize];
|
||||||
let pixels = img.into_raw();
|
let pixels = img.into_raw();
|
||||||
|
// Skip the (expensive) texture re-upload when nothing changed.
|
||||||
|
let hash = {
|
||||||
|
use std::hash::{Hash, Hasher};
|
||||||
|
let mut hasher = std::collections::hash_map::DefaultHasher::new();
|
||||||
|
pixels.len().hash(&mut hasher);
|
||||||
|
for chunk in pixels.chunks(4096) {
|
||||||
|
chunk.hash(&mut hasher);
|
||||||
|
}
|
||||||
|
hasher.finish()
|
||||||
|
};
|
||||||
|
if hash == tab.last_frame_hash && tab.texture.is_some() {
|
||||||
|
tab.dirty = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
tab.last_frame_hash = hash;
|
||||||
let image = egui::ColorImage::from_rgba_unmultiplied(dims, &pixels);
|
let image = egui::ColorImage::from_rgba_unmultiplied(dims, &pixels);
|
||||||
match (&tab.texture, &egui_ctx) {
|
match (&tab.texture, &egui_ctx) {
|
||||||
(Some(texture), _) => {
|
(Some(texture), _) => {
|
||||||
@@ -835,6 +862,16 @@ impl ApplicationHandler<UserEvent> for BrowserApp {
|
|||||||
event_loop.set_control_flow(ControlFlow::Wait);
|
event_loop.set_control_flow(ControlFlow::Wait);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn exiting(&mut self, _event_loop: &ActiveEventLoop) {
|
||||||
|
// Close all WebViews while the Servo instance is still alive, so their
|
||||||
|
// shutdown messages reach a running constellation instead of a dying one.
|
||||||
|
if let Some(engine) = self.engine.take() {
|
||||||
|
engine.spin();
|
||||||
|
self.drain_engine_messages();
|
||||||
|
}
|
||||||
|
self.tabs.clear();
|
||||||
|
}
|
||||||
|
|
||||||
fn window_event(
|
fn window_event(
|
||||||
&mut self,
|
&mut self,
|
||||||
event_loop: &ActiveEventLoop,
|
event_loop: &ActiveEventLoop,
|
||||||
|
|||||||
@@ -151,6 +151,10 @@ pub struct Tab {
|
|||||||
pub animating: bool,
|
pub animating: bool,
|
||||||
pub dirty: bool,
|
pub dirty: bool,
|
||||||
pub texture: Option<TextureHandle>,
|
pub texture: Option<TextureHandle>,
|
||||||
|
/// Hash of the last uploaded frame — skips redundant GPU texture uploads.
|
||||||
|
pub last_frame_hash: u64,
|
||||||
|
/// Time of the last GPU->CPU readback — throttles readback frequency.
|
||||||
|
pub last_paint: std::time::Instant,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Tab {
|
impl Tab {
|
||||||
@@ -165,6 +169,8 @@ impl Tab {
|
|||||||
animating: false,
|
animating: false,
|
||||||
dirty: true,
|
dirty: true,
|
||||||
texture: None,
|
texture: None,
|
||||||
|
last_frame_hash: 0,
|
||||||
|
last_paint: std::time::Instant::now() - std::time::Duration::from_secs(1),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user