1
0
mirror of https://github.com/kkapsner/CanvasBlocker synced 2024-12-22 12:50:36 +01:00

Improved input faking performance further

fixes #517
This commit is contained in:
kkapsner 2021-01-13 20:06:03 +01:00
parent 1f1d7052a1
commit 945c2716c9
2 changed files with 13 additions and 8 deletions

View File

@ -227,24 +227,25 @@
notify("fakedInput");
let oldImageData;
let x, y, width, height;
const getImageData = window.CanvasRenderingContext2D.prototype.getImageData;
const border = 4;
try {
// "this" is not trustable - it may be not a context
const measurement = window.CanvasRenderingContext2D.prototype.measureText.call(this, args[0]);
width = Math.ceil(measurement.actualBoundingBoxRight + measurement.actualBoundingBoxLeft) + border;
height = Math.ceil(measurement.actualBoundingBoxDescent + measurement.actualBoundingBoxAscent) + border;
x = Math.max(0, args[1] - width);
y = Math.max(0, args[2] - height);
width = Math.min(3 * width, this.canvas.width - x);
height = Math.min(3 * height, this.canvas.height - y);
oldImageData = window.CanvasRenderingContext2D.prototype.getImageData.call(this, x, y, width, height);
const left = Math.max(0, measurement.actualBoundingBoxLeft);
const top = Math.max(0, measurement.actualBoundingBoxAscent);
width = Math.ceil(measurement.actualBoundingBoxRight + left) + 2 * border;
height = Math.ceil(measurement.actualBoundingBoxDescent + top) + 2 * border;
x = args[1] - border - left;
y = args[2] - border - top;
oldImageData = getImageData.call(this, x, y, width, height);
}
catch (error){
// nothing to do here
}
// if "this" is not a correct context the next line will throw an error
const ret = original.call(this, ...args);
const newImageData = window.CanvasRenderingContext2D.prototype.getImageData.call(this, x, y, width, height);
const newImageData = getImageData.call(this, x, y, width, height);
this.putImageData(randomMixImageData(window, oldImageData, newImageData), x, y);
return ret;
}

View File

@ -161,6 +161,10 @@
{
"version": "1.5Alpha20210104",
"update_link": "https://canvasblocker.kkapsner.de/versions/canvasblocker_beta-1.5Alpha20210104-an+fx.xpi"
},
{
"version": "1.5Alpha20210112",
"update_link": "https://canvasblocker.kkapsner.de/versions/canvasblocker_beta-1.5Alpha20210112-an+fx.xpi"
}
]
}