From c6ad2fc167ede92a024efba2ea0fc7aaf055dde1 Mon Sep 17 00:00:00 2001 From: Bert Peers Date: Thu, 14 May 2020 22:46:25 +0000 Subject: [PATCH] Bug 1637120 - Tileview improvements r=gw 1/ add tile_cache to input path if frame00000 can't be found 2/ add visual IDs to each tile 3/ hiding a slice also hides its Invalidation info 4/ code cleanup (+= instead of push_str) Differential Revision: https://phabricator.services.mozilla.com/D75432 --- gfx/wr/tileview/src/main.rs | 55 ++++++++++++++++++++++++-------- gfx/wr/tileview/src/tilecache.js | 33 ++++++++++++------- 2 files changed, 63 insertions(+), 25 deletions(-) diff --git a/gfx/wr/tileview/src/main.rs b/gfx/wr/tileview/src/main.rs index 2ee513e4ed39..1706197b0bc4 100644 --- a/gfx/wr/tileview/src/main.rs +++ b/gfx/wr/tileview/src/main.rs @@ -271,16 +271,14 @@ fn tile_to_svg(key: TileOffset, invalidation_report.push_str("\n"); } - svg = format!(r#"{}"#, - svg, + svg += &format!(r#""#, tile.rect.origin.x * svg_settings.scale + svg_settings.x, tile.rect.origin.y * svg_settings.scale + svg_settings.y, tile.rect.size.width * svg_settings.scale, tile.rect.size.height * svg_settings.scale, tile_style); - svg = format!("{}\n\n\n{}\n", - svg, + svg += &format!("\n\n\n{}\n", tile_node_to_svg(&tile.root, &slice.transform, svg_settings)); let right = (tile.rect.origin.x + tile.rect.size.width) as i32; @@ -291,9 +289,19 @@ fn tile_to_svg(key: TileOffset, svg += "\n\n"; - svg = format!("{}\n\t", - svg, - prim_class); + svg += &format!("\n\t", prim_class); + + + let rect_visual_id = Rect { + origin: tile.rect.origin, + size: PictureSize::new(1.0, 1.0) + }; + let rect_visual_id_world = slice.transform.transform_rect(&rect_visual_id).unwrap(); + svg += &format!("\n{},{} ({})", + rect_visual_id_world.origin.x * svg_settings.scale + svg_settings.x, + (rect_visual_id_world.origin.y + 110.0) * svg_settings.scale + svg_settings.y, + key.x, key.y, slice.tile_cache.slice); + for prim in &tile.current_descriptor.prims { let rect = prim.prim_clip_box; @@ -360,13 +368,15 @@ fn slices_to_svg(slices: &[Slice], prev_slices: Option>, let tile_cache = &slice.tile_cache; *max_slice_index = if tile_cache.slice > *max_slice_index { tile_cache.slice } else { *max_slice_index }; + invalidation_report.push_str(&format!("
\n", tile_cache.slice)); + let prim_class = format!("tile_slice{}", tile_cache.slice); - svg.push_str(&format!("\n", tile_cache.slice)); + svg += &format!("\n", tile_cache.slice); //println!("slice {}", tile_cache.slice); - svg.push_str(&format!("\n\n", - tile_cache.slice)); + svg += &format!("\n\n", + tile_cache.slice); //let tile_stroke = "stroke:grey;stroke-width:1;".to_string(); let tile_stroke = "stroke:none;".to_string(); @@ -387,14 +397,16 @@ fn slices_to_svg(slices: &[Slice], prev_slices: Option>, prev_tile = prev.tile_cache.tiles.get(key); } - svg.push_str(&tile_to_svg(*key, &tile, &slice, prev_tile, + svg += &tile_to_svg(*key, &tile, &slice, prev_tile, itemuid_to_string, &tile_stroke, &prim_class, &mut invalidation_report, - svg_width, svg_height, svg_settings)); + svg_width, svg_height, svg_settings); } - svg.push_str("\n"); + svg += "\n"; + + invalidation_report.push_str("
\n"); } ( @@ -526,6 +538,12 @@ fn write_css(output_dir: &Path, max_slice_index: usize, svg_settings: &SvgSettin rgb); } + css += &format!(".svg_tile_visual_id {{\n\ + font: {}px sans-serif;\n\ + fill: rgb(50,50,50);\n\ + }}\n\n", + 150.0 * svg_settings.scale); + let output_file = output_dir.join("tilecache.css"); let mut css_output = File::create(output_file).unwrap(); css_output.write_all(css.as_bytes()).unwrap(); @@ -638,9 +656,18 @@ fn main() { let mut max_slice_index = 0; let mut entries: Vec<_> = std::fs::read_dir(input_dir).unwrap() - //.map(|r| r.unwrap()) .filter_map(|r| r.ok()) .collect(); + // auto-fix a missing 'tile_cache' postfix on the input path -- easy to do when copy-pasting a + // path to a wr-capture; there should at least be a frame00000.ron... + let frame00000 = entries.iter().find(|&entry| entry.path().ends_with("frame00000.ron")); + // ... and if not, try again with 'tile_cache' appended to the input folder + if frame00000.is_none() { + let new_path = input_dir.join("tile_cache"); + entries = std::fs::read_dir(new_path).unwrap() + .filter_map(|r| r.ok()) + .collect(); + } entries.sort_by_key(|dir| dir.path()); let mut svg_files: Vec:: = Vec::new(); diff --git a/gfx/wr/tileview/src/tilecache.js b/gfx/wr/tileview/src/tilecache.js index 5b4f9627d0e2..0ea3d98af5a8 100644 --- a/gfx/wr/tileview/src/tilecache.js +++ b/gfx/wr/tileview/src/tilecache.js @@ -49,8 +49,7 @@ function update_slice_visibility(max_slice) { function update_slice_visibility_for_content(content, max_slice) { - if( !content ) // might happen due to cross-scripting -- use SimpleHTTPServer - return; + intern = document.getElementById('intern').contentDocument; for (let slice = 0; slice != max_slice; ++slice) { var cbox_name = "slice_toggle" + slice; @@ -58,14 +57,26 @@ function update_slice_visibility_for_content(content, max_slice) { if( !cbox ) continue; let checked = cbox.checked; - var id = "tile_slice" + slice + "_everything"; - var group = content.getElementById(id); - if( !group ) - continue; - if( checked ) - group.style.display = "block"; - else - group.style.display = "none"; + if (content) { // might fail due to cross scripting -- use SimpleHTTPServer + var id = "tile_slice" + slice + "_everything"; + var group = content.getElementById(id); + if (group) { + if (checked) + group.style.display = "block"; + else + group.style.display = "none"; + } + } + if (intern) { + var id = "invalidation_slice" + slice; + var div = intern.getElementById(id); + if (div) { + if (checked) + div.style.display = "block"; + else + div.style.display = "none"; + } + } } } @@ -104,8 +115,8 @@ function go_to_svg(index) { backbuffer = t; is_loading = false; } - backbuffer.setAttribute('data', svg_files[svg_index]); document.getElementById('intern').src = intern_files[svg_index]; + backbuffer.setAttribute('data', svg_files[svg_index]); // also see https://stackoverflow.com/a/29915275 }