@@ -63,6 +63,10 @@ var SubtitlesOctopus = function (options) {
6363
6464 self . hasAlphaBug = false ;
6565
66+ // private
67+ var targetWidth ; // Width of render target
68+ var targetHeight ; // Height of render target
69+
6670 ( function ( ) {
6771 if ( typeof ImageData . prototype . constructor === 'function' ) {
6872 try {
@@ -119,6 +123,10 @@ var SubtitlesOctopus = function (options) {
119123 self . createCanvas ( ) ;
120124 self . setVideo ( options . video ) ;
121125 self . setSubUrl ( options . subUrl ) ;
126+
127+ targetWidth = self . canvas . width ;
128+ targetHeight = self . canvas . height ;
129+
122130 self . worker . postMessage ( {
123131 target : 'worker-init' ,
124132 width : self . canvas . width ,
@@ -418,13 +426,13 @@ var SubtitlesOctopus = function (options) {
418426 if ( self . renderAhead > 0 ) {
419427 var newCache = [ ] ;
420428 if ( isResizing && self . oneshotState . prevHeight && self . oneshotState . prevWidth ) {
421- if ( self . oneshotState . prevHeight == self . canvas . height &&
422- self . oneshotState . prevWidth == self . canvas . width ) return ;
429+ if ( self . oneshotState . prevHeight === targetHeight &&
430+ self . oneshotState . prevWidth === targetWidth ) return ;
423431 var timeLimit = 10 , sizeLimit = self . renderAhead * 0.3 ;
424- if ( self . canvas . height >= self . oneshotState . prevHeight * ( 1.0 - self . resizeVariation ) &&
425- self . canvas . height <= self . oneshotState . prevHeight * ( 1.0 + self . resizeVariation ) &&
426- self . canvas . width >= self . oneshotState . prevWidth * ( 1.0 - self . resizeVariation ) &&
427- self . canvas . width <= self . oneshotState . prevWidth * ( 1.0 + self . resizeVariation ) ) {
432+ if ( targetHeight >= self . oneshotState . prevHeight * ( 1.0 - self . resizeVariation ) &&
433+ targetHeight <= self . oneshotState . prevHeight * ( 1.0 + self . resizeVariation ) &&
434+ targetWidth >= self . oneshotState . prevWidth * ( 1.0 - self . resizeVariation ) &&
435+ targetWidth <= self . oneshotState . prevWidth * ( 1.0 + self . resizeVariation ) ) {
428436 console . debug ( 'viewport changes are small, leaving more of prerendered buffer' ) ;
429437 timeLimit = 30 ;
430438 sizeLimit = self . renderAhead * 0.5 ;
@@ -445,8 +453,8 @@ var SubtitlesOctopus = function (options) {
445453 self . oneshotState . eventStart = null ;
446454 self . oneshotState . iteration ++ ;
447455 self . oneshotState . renderRequested = false ;
448- self . oneshotState . prevHeight = self . canvas . height ;
449- self . oneshotState . prevWidth = self . canvas . width ;
456+ self . oneshotState . prevHeight = targetHeight ;
457+ self . oneshotState . prevWidth = targetWidth ;
450458
451459 if ( ! self . rafId ) self . rafId = window . requestAnimationFrame ( oneshotRender ) ;
452460 tryRequestOneshot ( undefined , true ) ;
@@ -742,26 +750,22 @@ var SubtitlesOctopus = function (options) {
742750 return ;
743751 }
744752
753+ if ( videoSize != null ) {
754+ self . canvasParent . style . position = 'relative' ;
755+ self . canvas . style . display = 'block' ;
756+ self . canvas . style . position = 'absolute' ;
757+ self . canvas . style . width = videoSize . width + 'px' ;
758+ self . canvas . style . height = videoSize . height + 'px' ;
759+ self . canvas . style . top = top + 'px' ;
760+ self . canvas . style . left = left + 'px' ;
761+ self . canvas . style . pointerEvents = 'none' ;
762+ }
745763
746- if (
747- self . canvas . width != width ||
748- self . canvas . height != height ||
749- self . canvas . style . top != top ||
750- self . canvas . style . left != left
751- ) {
764+ if ( targetWidth !== width || targetHeight !== height ) {
752765 self . canvas . width = width ;
753766 self . canvas . height = height ;
754-
755- if ( videoSize != null ) {
756- self . canvasParent . style . position = 'relative' ;
757- self . canvas . style . display = 'block' ;
758- self . canvas . style . position = 'absolute' ;
759- self . canvas . style . width = videoSize . width + 'px' ;
760- self . canvas . style . height = videoSize . height + 'px' ;
761- self . canvas . style . top = top + 'px' ;
762- self . canvas . style . left = left + 'px' ;
763- self . canvas . style . pointerEvents = 'none' ;
764- }
767+ targetWidth = width ;
768+ targetHeight = height ;
765769
766770 self . worker . postMessage ( {
767771 target : 'canvas' ,
@@ -924,7 +928,7 @@ var SubtitlesOctopus = function (options) {
924928 style : style
925929 } ) ;
926930 } ;
927-
931+
928932 self . getStyles = function ( onSuccess , onError ) {
929933 self . fetchFromWorker ( {
930934 target : 'get-styles'
0 commit comments