diff options
-rw-r--r-- | pointless/viewer/screen.js | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/pointless/viewer/screen.js b/pointless/viewer/screen.js index 9ba4574..de88469 100644 --- a/pointless/viewer/screen.js +++ b/pointless/viewer/screen.js | |||
@@ -13,6 +13,7 @@ class Screen { | |||
13 | this.secondary = secondary; | 13 | this.secondary = secondary; |
14 | 14 | ||
15 | this.canvasId = "screen"; | 15 | this.canvasId = "screen"; |
16 | this.workCanvas = document.createElement("canvas"); | ||
16 | this.page = null; | 17 | this.page = null; |
17 | 18 | ||
18 | this.timer = withTimer ? new Timer(window) : null; | 19 | this.timer = withTimer ? new Timer(window) : null; |
@@ -50,8 +51,8 @@ class Screen { | |||
50 | return (viewport.width / 2) / viewport.height; | 51 | return (viewport.width / 2) / viewport.height; |
51 | } | 52 | } |
52 | 53 | ||
53 | _newCanvas(width, height, xOffset, yOffset) { | 54 | _getCanvas(width, height, xOffset, yOffset) { |
54 | const canvas = document.createElement("canvas"); | 55 | const canvas = this.workCanvas; |
55 | canvas.width = width; | 56 | canvas.width = width; |
56 | canvas.height = height; | 57 | canvas.height = height; |
57 | 58 | ||
@@ -61,11 +62,12 @@ class Screen { | |||
61 | return { canvas: canvas, context: context }; | 62 | return { canvas: canvas, context: context }; |
62 | } | 63 | } |
63 | 64 | ||
64 | _showCanvas(canvas) { | 65 | _swapCanvas(canvas) { |
65 | const oldCanvas = this.window.document.getElementById(this.canvasId); | 66 | const oldCanvas = this.window.document.getElementById(this.canvasId); |
66 | canvas.id = oldCanvas.id; | 67 | canvas.id = oldCanvas.id; |
67 | canvas.classList = oldCanvas.classList; | 68 | canvas.classList = oldCanvas.classList; |
68 | oldCanvas.replaceWith(canvas); | 69 | oldCanvas.replaceWith(canvas); |
70 | this.workCanvas = oldCanvas; | ||
69 | } | 71 | } |
70 | 72 | ||
71 | _render(canvas, context, scaleFactor) { | 73 | _render(canvas, context, scaleFactor) { |
@@ -76,7 +78,7 @@ class Screen { | |||
76 | 78 | ||
77 | const self = this; | 79 | const self = this; |
78 | this.page.render(renderContext).then(function() { | 80 | this.page.render(renderContext).then(function() { |
79 | self._showCanvas(canvas); | 81 | self._swapCanvas(canvas); |
80 | }); | 82 | }); |
81 | } | 83 | } |
82 | 84 | ||
@@ -87,7 +89,7 @@ class Screen { | |||
87 | const { width, height } = this._getScreenSize(screenRatio); | 89 | const { width, height } = this._getScreenSize(screenRatio); |
88 | const scaleFactor = height / this.page.getViewport(1).height; | 90 | const scaleFactor = height / this.page.getViewport(1).height; |
89 | const xOffset = this.secondary ? -width : 0; | 91 | const xOffset = this.secondary ? -width : 0; |
90 | const { canvas, context } = this._newCanvas(width, height, xOffset, 0); | 92 | const { canvas, context } = this._getCanvas(width, height, xOffset, 0); |
91 | this._render(canvas, context, scaleFactor); | 93 | this._render(canvas, context, scaleFactor); |
92 | } | 94 | } |
93 | } | 95 | } |