Skip to content

Commit b5cbe11

Browse files
authored
Revert "Handle use case when canvas size is already controlled by css (#20956)" (#20975)
This reverts commit 3f299c3.
1 parent f7028bb commit b5cbe11

File tree

2 files changed

+7
-59
lines changed

2 files changed

+7
-59
lines changed

src/library_glfw.js

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1076,13 +1076,6 @@ var LibraryGLFW = {
10761076
// not valid
10771077
if (width <= 0 || height <= 0) return 0;
10781078

1079-
// check whether css is modifying the size
1080-
const canvas = Module['canvas'];
1081-
const originalCanvasWidth = canvas.width;
1082-
const orginalCanvasHeight = canvas.height;
1083-
canvas.width = 1; canvas.height = 1;
1084-
GLFW.hasExternalSizing = canvas.clientWidth != 1 || canvas.clientHeight != 1;
1085-
10861079
if (monitor) {
10871080
Browser.requestFullscreen();
10881081
} else {
@@ -1116,11 +1109,9 @@ var LibraryGLFW = {
11161109
if (!Module.ctx && useWebGL) return 0;
11171110

11181111
// Get non alive id
1112+
const canvas = Module['canvas'];
11191113
var win = new GLFW_Window(id, canvas.clientWidth, canvas.clientHeight, canvas.width, canvas.height, title, monitor, share);
11201114

1121-
win.originalCanvasWidth = originalCanvasWidth;
1122-
win.orginalCanvasHeight = orginalCanvasHeight;
1123-
11241115
// Set window to array
11251116
if (id - 1 == GLFW.windows.length) {
11261117
GLFW.windows.push(win);
@@ -1151,14 +1142,7 @@ var LibraryGLFW = {
11511142
for (var i = 0; i < GLFW.windows.length; i++)
11521143
if (GLFW.windows[i] !== null) return;
11531144

1154-
const canvas = Module['canvas'];
1155-
if (!GLFW.hasExternalSizing && typeof canvas.style != 'undefined') {
1156-
canvas.style.removeProperty('width');
1157-
canvas.style.removeProperty('height');
1158-
}
1159-
Module.ctx = Browser.destroyContext(canvas, true, true);
1160-
canvas.width = win.originalCanvasWidth;
1161-
canvas.height = win.orginalCanvasHeight;
1145+
Module.ctx = Browser.destroyContext(Module['canvas'], true, true);
11621146
},
11631147

11641148
swapBuffers: (winid) => {
@@ -1261,13 +1245,13 @@ var LibraryGLFW = {
12611245
const hNativeScaled = Math.floor(hNative * scale);
12621246
if (canvas.width != wNativeScaled) canvas.width = wNativeScaled;
12631247
if (canvas.height != hNativeScaled) canvas.height = hNativeScaled;
1264-
if (!GLFW.hasExternalSizing && typeof canvas.style != 'undefined') {
1248+
if (typeof canvas.style != 'undefined') {
12651249
if (wNativeScaled != wNative || hNativeScaled != hNative) {
1266-
canvas.style.setProperty( 'width', wNative + 'px', 'important');
1267-
canvas.style.setProperty('height', hNative + 'px', 'important');
1250+
canvas.style.setProperty( "width", wNative + "px", "important");
1251+
canvas.style.setProperty("height", hNative + "px", "important");
12681252
} else {
1269-
canvas.style.removeProperty('width');
1270-
canvas.style.removeProperty('height');
1253+
canvas.style.removeProperty( "width");
1254+
canvas.style.removeProperty("height");
12711255
}
12721256
}
12731257
},

test/browser/test_glfw3_hi_dpi_aware.c

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -51,20 +51,6 @@ static void checkWindowSize(GLFWwindow *window, int expectedWidth, int expectedH
5151
assert(fbw == (int) (expectedWidth * ratio) && fbh == (int) (expectedHeight * ratio));
5252
}
5353

54-
static void checkCanvasSize(int expectedWidth, int expectedHeight) {
55-
int w, h;
56-
emscripten_get_canvas_element_size("#canvas", &w, &h);
57-
printf("canvas size => %d == %d && %d == %d\n", w, expectedWidth, h, expectedHeight);
58-
assert(w == expectedWidth && h == expectedHeight);
59-
}
60-
61-
static void checkCanvasFramebufferSize(int expectedWidth, int expectedHeight) {
62-
double fbw, fbh;
63-
emscripten_get_element_css_size("#canvas", &fbw, &fbh);
64-
printf("canvas framebufferSize => %d == %d && %d == %d\n", (int) fbw, (int) expectedWidth, (int) fbh, expectedHeight);
65-
assert((int) fbw == expectedWidth && (int) fbh == expectedHeight);
66-
}
67-
6854
static bool getGLFWIsHiDPIAware() {
6955
return EM_ASM_INT(return GLFW.isHiDPIAware() ? 1 : 0) != 0;
7056
}
@@ -89,17 +75,13 @@ int main() {
8975
// Expected outcome is window size and frame buffer size are the same
9076
{
9177
printf("Use case #1\n");
92-
checkCanvasSize(300, 150); // 300x150 is the default canvas size
93-
checkCanvasFramebufferSize(300, 150);
9478
window = glfwCreateWindow(640, 480, "test_glfw3_hi_dpi_aware.c | #1", NULL, NULL);
9579
assert(window != NULL);
9680
checkHiDPIAware(window, false);
9781
checkWindowSize(window, 640, 480, 1.0);
9882
glfwSetWindowSize(window, 600, 400);
9983
checkWindowSize(window, 600, 400, 1.0);
10084
glfwDestroyWindow(window);
101-
checkCanvasSize(300, 150); // we make sure that the glfw code resets the canvas how it was
102-
checkCanvasFramebufferSize(300, 150);
10385
}
10486

10587
// Use case 2: GLFW is NOT Hi DPI Aware | devicePixelRatio is 2.0
@@ -192,24 +174,6 @@ int main() {
192174
glfwDestroyWindow(window);
193175
}
194176

195-
// Use case 8: GLFW is Hi DPI Aware | devicePixelRatio is 2.0 | canvas has css override
196-
// Expected outcome is that the framebuffer size is adjusted according to the canvas size
197-
{
198-
printf("Use case #8\n");
199-
setDevicePixelRatio(2.0);
200-
glfwWindowHint(GLFW_SCALE_TO_MONITOR, GLFW_TRUE);
201-
emscripten_set_element_css_size("#canvas", 700, 525);
202-
checkCanvasSize(300, 150); // default canvas size
203-
checkCanvasFramebufferSize(700, 525); // css override
204-
window = glfwCreateWindow(640, 480, "test_glfw3_hi_dpi_aware.c | #8", NULL, NULL);
205-
assert(window != NULL);
206-
checkHiDPIAware(window, true);
207-
checkWindowSize(window, 700, 525, 2.0); // canvas size overrides window size
208-
glfwDestroyWindow(window);
209-
checkCanvasSize(300, 150);
210-
checkCanvasFramebufferSize(700, 525);
211-
}
212-
213177
glfwTerminate();
214178

215179
return 0;

0 commit comments

Comments
 (0)