deprecate_emscripten_set_get_canvas_size#5481
Conversation
|
Looking at the implementation of emscripten_set_canvas_size: function(width, height) {
Browser.setCanvasSize(width, height);
},
setCanvasSize: function(width, height, noUpdates) {
var canvas = Module['canvas'];
Browser.updateCanvasDimensions(canvas, width, height);
if (!noUpdates) Browser.updateResizeListeners();
},
updateCanvasDimensions : function(canvas, wNative, hNative) {
if (wNative && hNative) {
canvas.widthNative = wNative;
canvas.heightNative = hNative;
} else {
wNative = canvas.widthNative;
hNative = canvas.heightNative;
}
var w = wNative;
var h = hNative;
if (Module['forcedAspectRatio'] && Module['forcedAspectRatio'] > 0) {
if (w/h < Module['forcedAspectRatio']) {
w = Math.round(h * Module['forcedAspectRatio']);
} else {
h = Math.round(w / Module['forcedAspectRatio']);
}
}
if (((document['fullscreenElement'] || document['mozFullScreenElement'] ||
document['msFullscreenElement'] || document['webkitFullscreenElement'] ||
document['webkitCurrentFullScreenElement']) === canvas.parentNode) && (typeof screen != 'undefined')) {
var factor = Math.min(screen.width / w, screen.height / h);
w = Math.round(w * factor);
h = Math.round(h * factor);
}
if (Browser.resizeCanvas) {
if (canvas.width != w) canvas.width = w;
if (canvas.height != h) canvas.height = h;
if (typeof canvas.style != 'undefined') {
canvas.style.removeProperty( "width");
canvas.style.removeProperty("height");
}
} else {
if (canvas.width != wNative) canvas.width = wNative;
if (canvas.height != hNative) canvas.height = hNative;
if (typeof canvas.style != 'undefined') {
if (w != wNative || h != hNative) {
canvas.style.setProperty( "width", w + "px", "important");
canvas.style.setProperty("height", h + "px", "important");
} else {
canvas.style.removeProperty( "width");
canvas.style.removeProperty("height");
}
}
}
},
updateResizeListeners: function() {
var canvas = Module['canvas'];
Browser.resizeListeners.forEach(function(listener) {
listener(canvas.width, canvas.height);
});
},In this flow,
It feels like most of this logic is misplaced, and we need primitive functionality that does only what is requested, without building more complex logic to the bottommost level. The part The part Item Finally, item The intent of this PR is to deprecate the usage of Another way forward might be not to deprecate Finally, there are tests for the new functions, but I have written them to be multithreading aware (1), so would prefer this to be merged without tests firsts, and testing to be introduced once the other multithreading capable bits land. |
91b6cd7 to
7495bad
Compare
|
lgtm |
|
Needs tests though. |
…/get_canvas_element_size() which are slimmer to the point and allow specifying the target canvas element to resize, instead of relying on a singleton Module['canvas'].
7495bad to
c61f726
Compare
|
Added simple singlethreaded tests. There's a much larger multithreaded test for this in my another branch (incoming...juj:pthread_proxy_main), which I'm working on pulling in bit by bit in manageable review units. |
Deprecate
emscripten_set/get_canvas_size()in favor ofemscripten_set/get_canvas_element_size()which are slimmer to the point and allow specifying the target canvas element to resize, instead of relying on a singletonModule['canvas'].