mirror of
https://github.com/kkapsner/CanvasBlocker
synced 2025-01-03 10:31:54 +01:00
Removed bug with faking webgl and added readPixels for webgl2.
Fixes #96 and #97.
This commit is contained in:
parent
6748771402
commit
6d7a9fc22a
@ -26,11 +26,12 @@
|
||||
if (siteStatus.mode !== "allow"){
|
||||
apiNames.forEach(function(name){
|
||||
var changedFunction = changedFunctions[name];
|
||||
var original = window.wrappedJSObject[changedFunction.object].prototype[name];
|
||||
|
||||
if (changedFunction.getStatus(undefined, siteStatus).active){
|
||||
(Array.isArray(changedFunction.object)? changedFunction.object: [changedFunction.object]).forEach(function(object){
|
||||
var original = window.wrappedJSObject[object].prototype[name];
|
||||
|
||||
Object.defineProperty(
|
||||
window.wrappedJSObject[changedFunction.object].prototype,
|
||||
window.wrappedJSObject[object].prototype,
|
||||
name,
|
||||
{
|
||||
enumerable: true,
|
||||
@ -76,6 +77,7 @@
|
||||
}
|
||||
}
|
||||
);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -17,30 +17,37 @@
|
||||
window.HTMLCanvasElement.prototype.getContext.call(canvas, "experimental-webgl2");
|
||||
}
|
||||
function getImageData(window, context){
|
||||
var imageData;
|
||||
var source;
|
||||
if (context instanceof window.CanvasRenderingContext2D){
|
||||
return window.CanvasRenderingContext2D.prototype.getImageData.call(context, 0, 0, context.canvas.width, context.canvas.height);
|
||||
imageData = window.CanvasRenderingContext2D.prototype.getImageData.call(context, 0, 0, context.canvas.width, context.canvas.height);
|
||||
source = imageData.data;
|
||||
}
|
||||
else {
|
||||
var imageData = new window.wrappedJSObject.ImageData(context.canvas.width, context.canvas.height);
|
||||
var source = new Uint8Array(imageData.data.length);
|
||||
window.WebGLRenderingContext.prototype.readPixels.call(
|
||||
context,
|
||||
0, 0, context.canvas.width, context.canvas.height,
|
||||
context.RGBA, context.UNSIGNED_BYTE,
|
||||
imageData.data
|
||||
source
|
||||
);
|
||||
return imageData;
|
||||
}
|
||||
return {
|
||||
imageData,
|
||||
source
|
||||
};
|
||||
}
|
||||
|
||||
function getFakeCanvas(window, original){
|
||||
var context = getContext(window, original);
|
||||
var imageData = getImageData(window, context);
|
||||
var data = imageData.data;
|
||||
var l = data.length;
|
||||
var {imageData, source} = getImageData(window, context);
|
||||
var desc = imageData.data;
|
||||
var l = desc.length;
|
||||
var rng = randomSupply.getRng(l, window);
|
||||
|
||||
for (var i = 0; i < l; i += 1){
|
||||
data[i] = rng(data[i], i);
|
||||
for (var i = 0; i < l; i += 10){
|
||||
desc[i] = rng(source[i], i);
|
||||
}
|
||||
var canvas = original.cloneNode(true);
|
||||
context = window.HTMLCanvasElement.prototype.getContext.call(canvas, "2d");
|
||||
@ -249,7 +256,7 @@
|
||||
status.active = hasType(status, "readout") || hasType(status, "input");
|
||||
return status;
|
||||
},
|
||||
object: "WebGLRenderingContext",
|
||||
object: ["WebGLRenderingContext", "WebGL2RenderingContext"],
|
||||
fakeGenerator: function(prefs, notify){
|
||||
return function readPixels(x, y, width, height, format, type, pixels){
|
||||
// not able to use the getFakeCanvas function because the context type is wrong...
|
||||
|
Loading…
x
Reference in New Issue
Block a user