Skip to content

Commit e5d6324

Browse files
authored
deprecate legacy reshape() and improve backward compatibility (#2881)
1 parent f531fdd commit e5d6324

9 files changed

Lines changed: 145 additions & 3 deletions

File tree

jme3-android/src/main/java/com/jme3/system/android/OGLESContext.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,7 @@ public void onSurfaceChanged(GL10 gl, int width, int height) {
465465
if (renderable.get()) {
466466
logger.log(Level.FINE, "App already initialized, calling reshape");
467467
listener.reshape(logicalWidth, logicalHeight, getRenderFramebufferWidth(), getRenderFramebufferHeight());
468+
listener.reshape(logicalWidth, logicalHeight);
468469
}
469470
}
470471

@@ -511,6 +512,7 @@ private void applyDisplayScaleModeIfNeeded() {
511512
updateDisplayScaleMetrics();
512513
if (renderable.get()) {
513514
listener.reshape(logicalWidth, logicalHeight, getRenderFramebufferWidth(), getRenderFramebufferHeight());
515+
listener.reshape(logicalWidth, logicalHeight);
514516
}
515517
}
516518

@@ -529,6 +531,7 @@ public void onDrawFrame(GL10 gl) {
529531
listener.initialize();
530532
if (framebufferWidth > 0 && framebufferHeight > 0) {
531533
listener.reshape(logicalWidth, logicalHeight, getRenderFramebufferWidth(), getRenderFramebufferHeight());
534+
listener.reshape(logicalWidth, logicalHeight);
532535
}
533536
renderable.set(true);
534537
}

jme3-core/src/main/java/com/jme3/app/LegacyApplication.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -590,10 +590,14 @@ public void startCanvas(boolean waitFor) {
590590

591591
/**
592592
* Internal use only.
593+
*
594+
* @deprecated Display size changes are reported through
595+
* {@link #reshape(int, int, int, int)}. Use this new method instead.
596+
* This one is kept only for backward compatibility.
593597
*/
594598
@Override
599+
@Deprecated
595600
public void reshape(int w, int h) {
596-
reshape(w, h, w, h);
597601
}
598602

599603
@Override

jme3-core/src/main/java/com/jme3/system/SystemListener.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,13 @@ public interface SystemListener {
4848
* Called to notify the application that the resolution has changed.
4949
* @param width the new logical width of the display (≥0)
5050
* @param height the new logical height of the display (≥0)
51+
*
52+
* @deprecated Implement {@link #reshape(int, int, int, int)} instead.
53+
* This one is kept only for backward compatibility.
5154
*/
52-
public void reshape(int width, int height);
55+
@Deprecated
56+
public default void reshape(int width, int height) {
57+
}
5358

5459
/**
5560
* Called to notify the application that logical application size and
@@ -61,7 +66,6 @@ public interface SystemListener {
6166
* @param framebufferHeight the physical framebuffer height in pixels
6267
*/
6368
public default void reshape(int logicalWidth, int logicalHeight, int framebufferWidth, int framebufferHeight) {
64-
reshape(logicalWidth, logicalHeight);
6569
}
6670

6771
/**
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
/*
2+
* Copyright (c) 2009-2022 jMonkeyEngine
3+
* All rights reserved.
4+
*
5+
* Redistribution and use in source and binary forms, with or without
6+
* modification, are permitted provided that the following conditions are
7+
* met:
8+
*
9+
* * Redistributions of source code must retain the above copyright
10+
* notice, this list of conditions and the following disclaimer.
11+
*
12+
* * Redistributions in binary form must reproduce the above copyright
13+
* notice, this list of conditions and the following disclaimer in the
14+
* documentation and/or other materials provided with the distribution.
15+
*
16+
* * Neither the name of 'jMonkeyEngine' nor the names of its contributors
17+
* may be used to endorse or promote products derived from this software
18+
* without specific prior written permission.
19+
*
20+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21+
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22+
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23+
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24+
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25+
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26+
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; OR BUSINESS INTERRUPTION)
27+
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28+
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29+
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
30+
* DAMAGE.
31+
*/
32+
package com.jme3.app;
33+
34+
import org.junit.jupiter.api.Test;
35+
36+
import static org.junit.jupiter.api.Assertions.assertEquals;
37+
38+
class LegacyApplicationReshapeTest {
39+
40+
@Test
41+
void fourArgumentReshapeDoesNotCallLegacyOverride() {
42+
LegacyReshapeApplication application = new LegacyReshapeApplication();
43+
44+
application.reshape(320, 240, 640, 480);
45+
46+
assertEquals(0, application.legacyReshapeCalls);
47+
}
48+
49+
@Test
50+
void directLegacyReshapeCallInvokesLegacyOverrideOnly() {
51+
LegacyReshapeApplication application = new LegacyReshapeApplication();
52+
53+
application.reshape(320, 240);
54+
55+
assertEquals(1, application.legacyReshapeCalls);
56+
assertEquals(320, application.width);
57+
assertEquals(240, application.height);
58+
}
59+
60+
@Test
61+
void fourArgumentReshapeWithModernOverrideDoesNotCallLegacyOverride() {
62+
ModernReshapeApplication application = new ModernReshapeApplication();
63+
64+
application.reshape(320, 240, 640, 480);
65+
66+
assertEquals(1, application.modernReshapeCalls);
67+
assertEquals(0, application.legacyReshapeCalls);
68+
}
69+
70+
@Test
71+
void directLegacyReshapeCallDoesNotReachModernOverride() {
72+
ModernOnlyReshapeApplication application = new ModernOnlyReshapeApplication();
73+
74+
application.reshape(320, 240);
75+
76+
assertEquals(0, application.modernReshapeCalls);
77+
}
78+
79+
private static class LegacyReshapeApplication extends LegacyApplication {
80+
81+
protected int legacyReshapeCalls;
82+
private int width;
83+
private int height;
84+
85+
@Override
86+
public void reshape(int width, int height) {
87+
legacyReshapeCalls++;
88+
this.width = width;
89+
this.height = height;
90+
super.reshape(width, height);
91+
}
92+
}
93+
94+
private static final class ModernReshapeApplication extends LegacyReshapeApplication {
95+
96+
private int modernReshapeCalls;
97+
98+
@Override
99+
public void reshape(int logicalWidth, int logicalHeight, int framebufferWidth, int framebufferHeight) {
100+
modernReshapeCalls++;
101+
super.reshape(logicalWidth, logicalHeight, framebufferWidth, framebufferHeight);
102+
}
103+
}
104+
105+
private static final class ModernOnlyReshapeApplication extends LegacyApplication {
106+
107+
private int modernReshapeCalls;
108+
private int logicalWidth;
109+
private int logicalHeight;
110+
private int framebufferWidth;
111+
private int framebufferHeight;
112+
113+
@Override
114+
public void reshape(int logicalWidth, int logicalHeight, int framebufferWidth, int framebufferHeight) {
115+
modernReshapeCalls++;
116+
this.logicalWidth = logicalWidth;
117+
this.logicalHeight = logicalHeight;
118+
this.framebufferWidth = framebufferWidth;
119+
this.framebufferHeight = framebufferHeight;
120+
super.reshape(logicalWidth, logicalHeight, framebufferWidth, framebufferHeight);
121+
}
122+
}
123+
}

jme3-ios/src/main/java/com/jme3/system/ios/IGLESContext.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,7 @@ public void create(boolean waitFor) {
260260
renderable.set(true);
261261
if (framebufferWidth > 0 && framebufferHeight > 0) {
262262
listener.reshape(logicalWidth, logicalHeight, getRenderFramebufferWidth(), getRenderFramebufferHeight());
263+
listener.reshape(logicalWidth, logicalHeight);
263264
}
264265

265266
if (waitFor) {
@@ -319,6 +320,7 @@ public void resizeFramebuffer(int width, int height) {
319320
logger.log(Level.FINE, "iOS framebuffer resized, width: {0} height: {1}",
320321
new Object[]{framebufferWidth, framebufferHeight});
321322
listener.reshape(logicalWidth, logicalHeight, getRenderFramebufferWidth(), getRenderFramebufferHeight());
323+
listener.reshape(logicalWidth, logicalHeight);
322324
}
323325
}
324326
}
@@ -364,6 +366,7 @@ private void applyDisplayScaleModeIfNeeded() {
364366
linearFrameBufferDirty = true;
365367
if (renderable.get() && listener != null) {
366368
listener.reshape(logicalWidth, logicalHeight, getRenderFramebufferWidth(), getRenderFramebufferHeight());
369+
listener.reshape(logicalWidth, logicalHeight);
367370
}
368371
}
369372

jme3-lwjgl/src/main/java/com/jme3/system/lwjgl/LwjglCanvas.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ protected void runLoop() {
210210
width = newWidth;
211211
height = newHeight;
212212
if (listener != null) {
213+
listener.reshape(width, height, width, height);
213214
listener.reshape(width, height);
214215
}
215216
}

jme3-lwjgl/src/main/java/com/jme3/system/lwjgl/LwjglDisplay.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ public void runLoop() {
226226
} catch (LWJGLException ex) {
227227
logger.log(Level.SEVERE, "Failed to set display settings!", ex);
228228
}
229+
listener.reshape(settings.getWidth(), settings.getHeight(), settings.getWidth(), settings.getHeight());
229230
listener.reshape(settings.getWidth(), settings.getHeight());
230231
if (renderable.get()) {
231232
reinitContext();
@@ -237,6 +238,7 @@ public void runLoop() {
237238
int newWidth = Display.getWidth();
238239
int newHeight = Display.getHeight();
239240
settings.setResolution(newWidth, newHeight);
241+
listener.reshape(newWidth, newHeight, newWidth, newHeight);
240242
listener.reshape(newWidth, newHeight);
241243
}
242244

jme3-lwjgl3/src/main/java/com/jme3/system/lwjgl/LwjglCanvas.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,7 @@ public void run() {
525525
if (needResize.getAndSet(false)) {
526526
settings.setResolution(framebufferWidth, framebufferHeight);
527527
listener.reshape(framebufferWidth, framebufferHeight, framebufferWidth, framebufferHeight);
528+
listener.reshape(framebufferWidth, framebufferHeight);
528529
}
529530

530531
synchronized (lock) {

jme3-lwjgl3/src/main/java/com/jme3/system/lwjgl/LwjglWindow.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -579,6 +579,7 @@ private void updateSizes(boolean notifyListener) {
579579
|| framebufferWidth != oldFramebufferWidth || framebufferHeight != oldFramebufferHeight) {
580580
settings.setResolution(logicalWidth, logicalHeight);
581581
listener.reshape(logicalWidth, logicalHeight, getRenderFramebufferWidth(), getRenderFramebufferHeight());
582+
listener.reshape(logicalWidth, logicalHeight);
582583
oldLogicalWidth = logicalWidth;
583584
oldLogicalHeight = logicalHeight;
584585
oldFramebufferWidth = framebufferWidth;

0 commit comments

Comments
 (0)