1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529
|
<!DOCTYPE html>
<html lang="en">
<!--
Copyright 2022 The Chromium Authors
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file.
-->
<head>
<style>
#scrubberframe::-webkit-slider-thumb {
appearance: none;
width: 20px;
height: 20px;
background-color: grey;
}
#scrubberframe::slider-thumb {
appearance: none;
width: 20px;
height: 20px;
background-color: grey;
}
#scrubberframe {
margin-top: 10px;
flex-grow: 1;
appearance: none;
background-color: #f0f0f0;
width: 100%;
}
#scrubberdraw::-webkit-slider-thumb {
appearance: none;
width: 15px;
height: 20px;
background-color: grey;
}
#scrubberdraw::slider-thumb {
appearance: none;
width: 20px;
height: 20px;
background-color: grey;
}
#scrubberdraw {
margin-top: 10px;
flex-grow: 1;
appearance: none;
background-color: #f0f0f0;
width: 100%;
}
#url {
font-family: monospace;
font-size: smaller;
}
#controls {}
#controls>#buttons {
display: flex;
}
#log {
min-height: 100px;
max-height: 100%;
font-family: monospace;
overflow: auto;
}
#connectionPanel,
#saveload {
display: inline-block;
}
#connectionPanel,
#saveload,
#topPanel {
padding-bottom: 10px;
}
#topPanel {
display: flex;
}
#settings {
display: flex;
flex-direction: column;
font-size: small;
}
.panelSection {
margin-right: 20px;
}
.panelSection:last-child {
margin-right: 0px;
flex-grow: 1;
}
#connection-status {
color: limegreen;
font-size: large;
padding-right: 5px;
}
#connection-status.disconnected {
color: orange;
}
</style>
<link href="https://unpkg.com/material-components-web@latest/dist/material-components-web.min.css" rel="stylesheet">
<script src="https://unpkg.com/material-components-web@latest/dist/material-components-web.min.js"></script>
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons+Outlined">
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined" />
<link rel='stylesheet' href='style.css'>
<script src='filter.js'></script>
<script src='filter-ui.js'></script>
<script src='frame.js'></script>
<script src='connection.js'></script>
<script src='thread.js'></script>
<script src='thread-ui.js'></script>
</head>
<div id='connectionPanel'>
<div class='sectionTitle'>
<font class='disconnected' id='connection-status'>●</font>Connection
</div>
<div class='section'>
<div title="Expert usage only. Autoconnect should provide the dev tools websocket through /json/version discovery.">
<input id='url' name='url' size=60 type="text"
placeholder='WebSocket URL or leave empty for autoconnect...'></input>
</div>
<button class="mdc-button mdc-button--outline" id='connect'>
<div class="mdc-button__ripple"></div>
<span class="mdc-button__label">Connect</span>
</button>
<button class="mdc-button mdc-button--outline" id='disconnect' disabled=true>
<div class="mdc-button__ripple"></div>
<span class="mdc-button__label">Disconnect</span>
</button>
<input type="checkbox" id="autoconnect" name="autoconnect" checked="true">
<label for="autoconnect" style="font-size:small; font:Roboto" > Autoconnect</label><br>
</div>
</div>
<div id='saveload'>
<div class='sectionTitle'>Save/Load ...</div>
<div class='section'>
<button id='demo' class="mdc-button mdc-button--outline">
<div class="mdc-button__ripple"></div>
<span class="mdc-button__label">Load demo data</span>
</button>
<button id='savedata' class="mdc-button mdc-button--outline"
title="Serializes current session stream to json file.">
<div class="mdc-button__ripple"></div>
<span class="mdc-button__label">Save to disk</span>
</button>
<button id='loaddata' class="mdc-button mdc-button--outline"
title="Deserializes json file of previous session and imports these frames into the App.">
<div class="mdc-button__ripple"></div>
<span class="mdc-button__label">Load from disk</span>
</button>
</div>
</div>
<div id='logsPanel'>
<div class='panelSection'>
<div class='sectionTitle'>
Logs
<!--input size=40 placeholder='Comma separated filter ...'>(TODO)</input-->
</div>
<div class='section'>
<div id='log'></div>
</div>
</div>
</div>
<div class='panelSection'>
<div class='sectionTitle'
title="Filter debug data stream. Filter operations occur in a left to right order with first match being applied.">
<i class="material-icons-outlined">filter_list</i> Filters
</div>
<div class='section'>
<div id='filters' class="mdc-chip-set mdc-chip-set--filter" role="grid"
title="Filter debug data stream. Filter operations occur in a left to right order with first match being applied.">
</div>
<button class="mdc-button mdc-button--outline" id='createfilter'>
<div class="mdc-button__ripple"></div>
<span class="mdc-button__label"><i class="material-icons-outlined">add_box</i> Add new filter</span>
</button>
</div>
</div>
<div class='panelSection'>
<div class='sectionTitle'>
<i class="material-symbols-outlined">
airwave
</i>
Threads
</div>
<div id='threads' class='section'></div>
</div>
<div class='panelSection'>
<div class='sectionTitle'>Viewer Controls</div>
<div class='section' id='controls'>
<div id='buttons'>
<button class="mdc-button mdc-button--outline" id='prev'>
<span class="mdc-button__label"><i class="material-icons-outlined">skip_previous</i> Previous frame</span>
</button>
<button class="mdc-button mdc-button--outline" id='play'>
<div class="mdc-button__ripple"></div>
<span class="mdc-button__label"><i class="material-icons-outlined">play_circle_outline</i> Play</span>
</button>
<button class="mdc-button mdc-button--outline" id='pause'>
<div class="mdc-button__ripple"></div>
<span class="mdc-button__label"><i class="material-icons-outlined">pause_circle_outline</i> Pause</span>
</button>
<button class="mdc-button mdc-button--outline" id='next'>
<span class="mdc-button__label">Next frame <i class="material-icons-outlined">skip_next</i></span>
</button>
<button class="mdc-button mdc-button--raised" id='live'>
<div class="mdc-button__ripple"></div>
<span class="mdc-button__label">Live <i class="material-icons-outlined">fast_forward</i></span>
</button>
</div>
<div class='panelSection'>
<div class='sectionTitle'>Frame Selection</div>
<input type='range' min='0' max='0' value='0' id='scrubberframe'></input>
</div>
<div class='panelSection'>
<div class='sectionTitle'>Draw Selection</div>
<input type='range' min='0' max='0' value='0' id='scrubberdraw'></input>
</div>
</div>
</div>
<div>
<div class='sectionTitle'>
Viewer
</div>
<div style='float: right' class='sectionTitle'>
Scale
<select id="viewerscale">
<option>100%</option>
<option>50%</option>
<option>200%</option>
<option disabled>Free Camera</option>
</select>
</div>
<div style='float: right' class='sectionTitle'>
Orientation
<select id="viewerorientation">
<option class="default-orientation">0 deg clockwise</option>
<option class="default-orientation">90 deg clockwise</option>
<option class="default-orientation">180 deg clockwise</option>
<option class="default-orientation">270 deg clockwise</option>
<option class="default-orientation">Horizontal Flip</option>
<option class="default-orientation">Vertical Flip</option>
</select>
</div>
<div class='section'>
<!--We need to fix viewer size to avoid scroll position change when
multiple displays are present. crbug.com/1358526-->
<div style="height:4000px; border: 1px dotted gray; background-color: #f0f0f0">
<canvas id='canvas' style="top :0px"></canvas>
</div>
</div>
<div class='modalContainer'></div>
</div>
<div id='importtracing'>
<div class='sectionTitle'>Tracing (Prototype)...</div>
<div class='section'>
<button id='importtracebutton' class="mdc-button mdc-button--outline"
title="Import tracing data (json) into visual debugger app.">
<div class="mdc-button__ripple"></div>
<span class="mdc-button__label">Import Trace</span>
</button>
</div>
</div>
<script>
function processIncomingFrame(json) {
if (!json) return;
new DrawFrame(json);
Player.instance.onNewFrame();
}
async function testAnimate() {
const f = await fetch('demo.json');
const text = await f.text();
const json = JSON.parse(text);
for (const frame of json) {
processIncomingFrame(frame);
}
}
async function saveDemoDataToDisk() {
const text = JSON.stringify(DrawFrame.frameBuffer.instances.map(d => d.toJSON()));
const blob = new Blob([text], { type: 'text/plain' });
const link = document.createElement('a');
link.download = 'cvd-stream.json';
link.href = window.URL.createObjectURL(blob);
link.click();
}
window.onload = function () {
Connection.initialize();
const addFilterButton = document.querySelector('#createfilter');
addFilterButton.addEventListener('click', () => {
showCreateFilterPopup(addFilterButton);
});
const container = document.querySelector('.modalContainer');
container.addEventListener('click', (event) => {
if (event.target == container)
hideModal();
});
const demo = document.querySelector('#demo');
demo.addEventListener('click', testAnimate);
const savedata = document.querySelector('#savedata');
savedata.addEventListener('click', saveDemoDataToDisk);
const loaddata = document.querySelector('#loaddata');
loaddata.addEventListener('click', () => {
const f = document.createElement('input');
f.type = 'file';
f.addEventListener('change', () => {
const file = new FileReader(f.files[0]);
file.addEventListener('load', () => {
const json = JSON.parse(file.result);
for (const frame of json) {
processIncomingFrame(frame);
}
});
file.readAsText(f.files[0]);
});
f.click();
});
const importtracedata = document.querySelector('#importtracebutton');
importtracedata.addEventListener('click', () => {
const f = document.createElement('input');
f.type = 'file';
f.addEventListener('change', () => {
const file = new FileReader(f.files[0]);
file.addEventListener('load', () => {
const json = JSON.parse(file.result);
const traceEvents = json.traceEvents;
curr_frame = "0";
curr_draws = [];
sources_this_frame = []
global_sources_mapping = []
for (const event of traceEvents) {
if(!event.cat.includes("viz.visual_debugger"))
continue;
if (event.name == "visual_debugger_sync") {
single_frame = { "drawcalls": [], "frame": "none", "logs": [], "new_sources": [], "time": "0", "version": 1, "windowx": 2400, "windowy": 1600, "threads": [ {"thread_id": "1" , "thread_name": "allthreads"}]};
single_frame.drawcalls = curr_draws;
curr_frame = event.args.last_presented_trace_id;
single_frame.frame = curr_frame;
single_frame.new_sources = sources_this_frame;
single_frame.windowx = parseInt(event.args.display_size.split("x")[0]);
single_frame.windowy = parseInt(event.args.display_size.split("x")[1]);
processIncomingFrame(single_frame);
curr_draws = [];
sources_this_frame = [];
}
else {
const single_call = { "drawindex": curr_draws.length, "option": { "alpha": 5, "color": "#ff0000" }, "pos": [-1, -1], "size": [-1, -1], "source_index": -1,"thread_id":1, "buff_id":-1};
single_call.pos[0] = parseFloat(event.args.args.pos_x);
single_call.pos[1] = parseFloat(event.args.args.pos_y);
single_call.size[0] = parseFloat(event.args.args.size_x);
single_call.size[1] = parseFloat(event.args.args.size_y);
single_call.text = event.args.args.text;
found_source_index = global_sources_mapping.indexOf(event.name);
if(found_source_index == -1)
{
new_source = { "anno": "frame.root.display_rect", "file": "none", "func": "none", "index": -1, "line": -1 };
new_source.anno = event.name;
global_sources_mapping.push(event.name);
found_source_index = global_sources_mapping.indexOf(event.name);
new_source.index = found_source_index;
sources_this_frame.push(new_source);
}
single_call.source_index = found_source_index;
curr_draws.push(single_call);
}
}
});
file.readAsText(f.files[0]);
});
f.click();
});
setUpPlayer();
restoreFilters();
}
function setUpPlayer() {
// First, set up the viewer.
const canvas = document.querySelector('#canvas');
const logContainer = document.querySelector('#log');
const viewer = new Viewer(canvas, logContainer);
// Now create the player for the viewer.
const player = new Player(viewer, (frame) => {
// TODO: This feels like a hack. Find a cleaner way to update the scrubbers?
const scrubberFrame = document.querySelector('#scrubberframe');
scrubberFrame.value = player.currentFrameIndex;
const scrubberDraw = document.querySelector('#scrubberdraw');
scrubberDraw.max = frame.submissionCount() - 1;
scrubberDraw.value = frame.submissionFreezeIndex();
});
document.querySelector('#pause').addEventListener('click', () => {
player.pause();
pause.setAttribute('style', 'background:#000000;color:white');
});
document.querySelector('#play').addEventListener('click', () => {
player.play();
pause.removeAttribute('style');
});
document.querySelector('#prev').addEventListener('click', () => {
player.rewind();
});
document.querySelector('#next').addEventListener('click', () => {
player.forward();
});
document.querySelector('#live').addEventListener('click', () => {
player.freezeFrame(DrawFrame.frameBuffer.numFrames - 1);
player.live();
has_disconnected = false;
pause.removeAttribute('style');
});
const scrubberFrame = document.querySelector('#scrubberframe');
scrubberFrame.addEventListener('input', () => {
player.freezeFrame(scrubberFrame.value);
pause.setAttribute('style', 'background:#000000;color:white');
});
const scrubberDraw = document.querySelector('#scrubberdraw');
scrubberDraw.addEventListener('input', () => {
player.freezeFrame(scrubberFrame.value, scrubberDraw.value);
});
let currentMouseX = 0;
let currentMouseY = 0;
let zoom = 100;
const viewerScale = document.querySelector("#viewerscale");
viewerScale.addEventListener('input', () => {
if (viewerScale.value != "Free Camera") {
player.setViewerScale(viewerScale.value);
zoom = parseInt(viewerScale.value);
}
else {
player.setViewerScale(zoom);
canvas.addEventListener('mouseenter', () => {
canvas.addEventListener('mousemove', function (event) {
currentMouseX = Math.round(event.offsetX);
currentMouseY = Math.round(event.offsetY);
});
});
canvas.addEventListener('wheel', function(e) {
e.preventDefault();
var delta = e.deltaY;
viewer.zoomToMouse(currentMouseX, currentMouseY, delta);
}, {passive:false});
}
});
const viewerOrientation = document.querySelector("#viewerorientation");
viewerOrientation.addEventListener('input', () => {
player.setViewerOrientation(viewerOrientation.value);
});
viewerOrientation.addEventListener('change', () => {
// change dropdown style when rotation occurs
if (viewerOrientation.value !== "0 deg clockwise") {
document.getElementById("viewerorientation").className = "selected-orientation";
}
else {
document.getElementById("viewerorientation").className = "default-orientation";
}
});
}
function showModal(element, focusSelector) {
const container = document.querySelector('.modalContainer');
container.appendChild(element);
container.style.display = 'block';
element.querySelector(focusSelector).focus();
}
function hideModal() {
const container = document.querySelector('.modalContainer');
container.style.display = 'none';
container.textContent = '';
}
</script>
</html>
|