Skip to content

Commit 422e4ae

Browse files
committed
⚡ New BoxConnector constructor
Optimize BoxConnector performance by using 'willReadFrequently' when adquiring the CanvasRenderingContext2D
1 parent 8d29932 commit 422e4ae

File tree

10 files changed

+959
-6682
lines changed

10 files changed

+959
-6682
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
### v2.1.12 (not yet released)
1+
### v2.1.12 (2022-11-26)
22
#### Improvements
33
- Upgraded dependencies
44
- Remove unnecessary dependencies: `scriptjs`
5+
- Improve graphics performance setting [willReadFrequently](https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/getContext#willreadfrequently) when adquiring [CanvasRenderingContext2D](https://html.spec.whatwg.org/multipage/canvas.html#canvasrenderingcontext2d) in activities using [BoxConnector](https://github.com/projectestac/jclic.js/blob/master/src/boxes/BoxConnector.js).
56

67
### v2.1.11 (2022-08-04)
78
#### Improvements

package-lock.json

Lines changed: 938 additions & 6662 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,23 +53,23 @@
5353
"webfontloader": "^1.6.28"
5454
},
5555
"devDependencies": {
56-
"@babel/core": "^7.19.6",
56+
"@babel/core": "^7.20.2",
5757
"@babel/eslint-parser": "^7.19.1",
58-
"@babel/preset-env": "^7.19.4",
59-
"@xmldom/xmldom": "^0.8.4",
60-
"babel-loader": "^9.0.0",
58+
"@babel/preset-env": "^7.20.2",
59+
"@xmldom/xmldom": "^0.8.6",
60+
"babel-loader": "^9.1.0",
6161
"clipboard-polyfill": "^3.0.3",
62-
"eslint": "^8.26.0",
62+
"eslint": "^8.28.0",
6363
"eslint-webpack-plugin": "^3.2.0",
6464
"fs-extra": "^10.1.0",
6565
"ink-docstrap-template": "^1.3.2",
66-
"jsdoc": "^3.6.11",
67-
"jsdom": "^20.0.2",
66+
"jsdoc": "^4.0.0",
67+
"jsdom": "^20.0.3",
6868
"patch-package": "^6.5.0",
6969
"po2json": "^1.0.0-alpha",
7070
"terser-webpack-plugin": "^5.3.6",
71-
"webpack": "^5.74.0",
72-
"webpack-cli": "^4.10.0",
71+
"webpack": "^5.75.0",
72+
"webpack-cli": "^5.0.0",
7373
"webpack-dev-server": "^4.11.1",
7474
"webpack-node-externals": "^3.0.0"
7575
},

src/activities/associations/SimpleAssociation.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ export class SimpleAssociationPanel extends ActivityPanel {
305305
this.$div.append(this.$canvas);
306306

307307
// Create a [BoxConnector](BoxConnector.html) and attach it to the canvas context
308-
this.bc = new BoxConnector(this, this.$canvas.get(-1).getContext('2d'));
308+
this.bc = new BoxConnector(this, this.$canvas);
309309

310310
// Repaint all
311311
this.invalidate().update();

src/activities/memory/MemoryGame.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ export class MemoryGamePanel extends ActivityPanel {
234234
this.$div.append(this.$canvas);
235235

236236
// Create a [BoxConnector](BoxConnector.html) and attach it to the canvas context
237-
this.bc = new BoxConnector(this, this.$canvas.get(-1).getContext('2d'));
237+
this.bc = new BoxConnector(this, this.$canvas);
238238

239239
// Repaint all
240240
this.invalidate().update();

src/activities/puzzles/DoublePuzzle.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ export class DoublePuzzlePanel extends ActivityPanel {
233233
this.$div.append(this.$canvas);
234234

235235
// Create a [BoxConnector](BoxConnector.html) and attach it to the canvas context
236-
this.bc = new BoxConnector(this, this.$canvas.get(-1).getContext('2d'));
236+
this.bc = new BoxConnector(this, this.$canvas);
237237

238238
// Repaint all
239239
this.invalidate().update();

src/activities/puzzles/ExchangePuzzle.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ class ExchangePuzzlePanel extends ActivityPanel {
212212
this.$div.append(this.$canvas);
213213

214214
// Create a [BoxConnector](BoxConnector.html) and attach it to the canvas context
215-
this.bc = new BoxConnector(this, this.$canvas.get(-1).getContext('2d'));
215+
this.bc = new BoxConnector(this, this.$canvas);
216216

217217
// Repaint all
218218
this.invalidate().update();

src/activities/text/OrderText.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ export class OrderTextPanel extends TextActivityBasePanel {
136136
this.$div.append(this.$canvas);
137137

138138
// Create a [BoxConnector](BoxConnector.html) and attach it to the canvas context
139-
this.bc = new BoxConnector(this, this.$canvas.get(-1).getContext('2d'));
139+
this.bc = new BoxConnector(this, this.$canvas);
140140
this.bc.compositeOp = this.bc.DEFAULT_COMPOSITE_OP;
141141

142142
// Repaint all

src/activities/textGrid/WordSearch.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ export class WordSearchPanel extends ActivityPanel {
283283
this.$div.append(this.$canvas);
284284

285285
// Create a [BoxConnector](BoxConnector.html) and attach it to the canvas context
286-
this.bc = new BoxConnector(this, this.$canvas.get(-1).getContext('2d'));
286+
this.bc = new BoxConnector(this, this.$canvas);
287287

288288
// Repaint all
289289
this.invalidate().update();

src/boxes/BoxConnector.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,12 @@ export class BoxConnector {
4747
/**
4848
* BoxConnector constructor
4949
* @param {module:AWT.Container} parent - The Container to which this BoxConnector belongs
50-
* @param {external:CanvasRenderingContext2D} ctx - The canvas rendering context where to draw
50+
* @param {external:jQuery} $canvas - The HTML `canvas` element where this BoxConnector will draw.
5151
*/
52-
constructor(parent, ctx) {
52+
constructor(parent, $canvas) {
5353
this.parent = parent;
54-
this.ctx = ctx;
55-
this.dim = new Dimension(ctx.canvas.width, ctx.canvas.height);
54+
this.ctx = $canvas.get(-1).getContext('2d', { willReadFrequently: true });
55+
this.dim = new Dimension(this.ctx.canvas.width, this.ctx.canvas.height);
5656
this.origin = new Point();
5757
this.dest = new Point();
5858
this.relativePos = new Point();

0 commit comments

Comments
 (0)