From e2e89c6053e1ccfe9cb4ef3763254bf24c8d7082 Mon Sep 17 00:00:00 2001 From: cpsdqs Date: Sun, 1 Oct 2017 00:40:39 +0200 Subject: [PATCH] Show update frames in debug mode --- js/term/debug_screen.js | 28 +++++++++++++++++++++++++++- js/term/screen_parser.js | 4 ++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/js/term/debug_screen.js b/js/term/debug_screen.js index b4c58a1..a80ed8a 100644 --- a/js/term/debug_screen.js +++ b/js/term/debug_screen.js @@ -46,6 +46,7 @@ module.exports = function attachDebugScreen (screen) { let startTime, endTime, lastReason let cells = new Map() let clippedRects = [] + let updateFrames = [] let startDrawing @@ -65,6 +66,11 @@ module.exports = function attachDebugScreen (screen) { }, clipRect (...args) { clippedRects.push(args) + }, + pushFrame (frame) { + frame.push(Date.now()) + updateFrames.push(frame) + startDrawing() } } @@ -155,6 +161,26 @@ module.exports = function attachDebugScreen (screen) { ctx.fill() } + let didDrawUpdateFrames = false + if (updateFrames.length) { + let framesToDelete = [] + for (let frame of updateFrames) { + let time = frame[4] + let elapsed = Date.now() - time + if (elapsed > 1000) framesToDelete.push(frame) + else { + didDrawUpdateFrames = true + ctx.globalAlpha = 1 - elapsed / 1000 + ctx.strokeStyle = '#ff0' + ctx.lineWidth = 2 + ctx.strokeRect(frame[0] * cellWidth, frame[1] * cellHeight, frame[2] * cellWidth, frame[3] * cellHeight) + } + } + for (let frame of framesToDelete) { + updateFrames.splice(updateFrames.indexOf(frame), 1) + } + } + if (mouseHoverCell) { ctx.save() ctx.globalAlpha = 1 @@ -170,7 +196,7 @@ module.exports = function attachDebugScreen (screen) { ctx.restore() } - if (activeCells === 0 && !mouseHoverCell) { + if (activeCells === 0 && !mouseHoverCell && !didDrawUpdateFrames) { isDrawing = false removeCanvas() } diff --git a/js/term/screen_parser.js b/js/term/screen_parser.js index 2d0ebff..1e9f197 100644 --- a/js/term/screen_parser.js +++ b/js/term/screen_parser.js @@ -243,6 +243,10 @@ module.exports = class ScreenParser { const frameHeight = du(strArray[ci++]) const frameWidth = du(strArray[ci++]) + if (this.screen._debug && this.screen.window.debug) { + this.screen._debug.pushFrame([frameX, frameY, frameWidth, frameHeight]) + } + // content let fg = 7 let bg = 0