Skip to content

Commit

Permalink
Handle resizing more efficiently - if video changed less than 20% kee…
Browse files Browse the repository at this point in the history
…p using old size
  • Loading branch information
JustAMan committed Mar 25, 2020
1 parent bc33fd6 commit 825c999
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/subtitles-octopus.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ var SubtitlesOctopus = function (options) {
eventOver: false,
iteration: 0,
renderRequested: false,
requestNextTimestamp: -1
requestNextTimestamp: -1,
prevWidth: null,
prevHeight: null
}

self.hasAlphaBug = false;
Expand Down Expand Up @@ -394,11 +396,27 @@ var SubtitlesOctopus = function (options) {

function resetRenderAheadCache() {
if (self.renderAhead > 0) {
if (self.oneshotState.prevHeight && self.oneshotState.prevWidth) {
if (self.canvas.height >= self.oneshotState.prevHeight * 0.8 &&
self.canvas.height <= self.oneshotState.prevHeight * 1.2 &&
self.canvas.width >= self.oneshotState.prevWidth * 0.8 &&
self.canvas.width <= self.oneshotState.prevWidth * 1.2) {
console.debug('not resetting prerender cache - keep using current');
// keep rendering canvas size the same,
// otherwise subtitles got placed incorrectly
self.canvas.width = self.oneshotState.prevWidth;
self.canvas.height = self.oneshotState.prevHeight;
return;
}
}

console.info('resetting prerender cache');
self.renderedItems = [];
self.oneshotState.eventStart = null;
self.oneshotState.iteration++;
self.oneshotState.renderRequested = false;
self.oneshotState.prevHeight = self.canvas.height;
self.oneshotState.prevWidth = self.canvas.width;

window.requestAnimationFrame(oneshotRender);
tryRequestOneshot(undefined, true);
Expand Down

0 comments on commit 825c999

Please sign in to comment.