aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2023-03-08 05:39:56 +0100
committerSven Gothel <[email protected]>2023-03-08 05:39:56 +0100
commitd76fc6f518606def8ddc52e0cd4d8a29bd2536fc (patch)
treef8332e129ab8c3238b7cdf05eeab4d681fbb4671 /src
parentadfe4abec47313d2c533096f6c3e9a94d2fc4571 (diff)
Graph: Font: Add equals() + hash() API doc; GraphUI's Label*.setText(): Only modify values if text and/or font differs, skipping markShapeDirty() saves performance.
Diffstat (limited to 'src')
-rw-r--r--src/jogl/classes/com/jogamp/graph/font/Font.java18
-rw-r--r--src/jogl/classes/jogamp/graph/font/typecast/TypecastFont.java3
-rw-r--r--src/test/com/jogamp/opengl/test/junit/graph/demos/GPUUISceneGLListener0A.java15
-rw-r--r--src/test/com/jogamp/opengl/test/junit/graph/demos/ui/Label.java30
-rw-r--r--src/test/com/jogamp/opengl/test/junit/graph/demos/ui/LabelButton.java8
5 files changed, 57 insertions, 17 deletions
diff --git a/src/jogl/classes/com/jogamp/graph/font/Font.java b/src/jogl/classes/com/jogamp/graph/font/Font.java
index f296c77b3..1b5452a45 100644
--- a/src/jogl/classes/com/jogamp/graph/font/Font.java
+++ b/src/jogl/classes/com/jogamp/graph/font/Font.java
@@ -256,6 +256,24 @@ public interface Font {
StringBuilder getAllNames(final StringBuilder string, final String separator);
/**
+ * Returns the hash code based on {@link #NAME_UNIQUNAME}.
+ * <p>
+ * {@inheritDoc}
+ * </p>
+ */
+ @Override
+ int hashCode();
+
+ /**
+ * Returns true if other instance is of same type and {@link #NAME_UNIQUNAME} is equal.
+ * <p>
+ * {@inheritDoc}
+ * </p>
+ */
+ @Override
+ boolean equals(final Object o);
+
+ /**
* Return advance-width of given glyphID in font-units, sourced from `hmtx` table.
* @param glyphID
*/
diff --git a/src/jogl/classes/jogamp/graph/font/typecast/TypecastFont.java b/src/jogl/classes/jogamp/graph/font/typecast/TypecastFont.java
index 003795942..12128f5ad 100644
--- a/src/jogl/classes/jogamp/graph/font/typecast/TypecastFont.java
+++ b/src/jogl/classes/jogamp/graph/font/typecast/TypecastFont.java
@@ -456,8 +456,7 @@ class TypecastFont implements Font {
public final boolean equals(final Object o) {
if( this == o ) { return true; }
if( o instanceof TypecastFont ) {
- final TypecastFont of = (TypecastFont)o;
- return of.font.getName(Font.NAME_UNIQUNAME).equals(font.getName(Font.NAME_UNIQUNAME));
+ return ((TypecastFont)o).font.getName(Font.NAME_UNIQUNAME).equals(font.getName(Font.NAME_UNIQUNAME));
}
return false;
}
diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUUISceneGLListener0A.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUUISceneGLListener0A.java
index f9a333fc4..c1ef5f7fd 100644
--- a/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUUISceneGLListener0A.java
+++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUUISceneGLListener0A.java
@@ -179,6 +179,7 @@ public class GPUUISceneGLListener0A implements GLEventListener {
throw new RuntimeException(ioe);
}
sceneUIController = new SceneUIController(sceneDist, zNear, zFar);
+ // sceneUIController.setSampleCount(3); // easy on embedded devices w/ just 3 samples (default is 4)?
screenshot = new GLReadBufferUtil(false, false);
}
@@ -929,7 +930,7 @@ public class GPUUISceneGLListener0A implements GLEventListener {
if( null != animator ) {
lfps = animator.getLastFPS();
tfps = animator.getTotalFPS();
- td = animator.getTotalFPSDuration()/1000f;
+ td = (float)animator.getLastFPSPeriod() / (float)animator.getUpdateFPSFrames();
} else {
lfps = 0f;
tfps = 0f;
@@ -938,16 +939,18 @@ public class GPUUISceneGLListener0A implements GLEventListener {
final String modeS = Region.getRenderModeString(renderModes);
final String text;
if( null == actionText ) {
- text = String.format("%03.1f/%03.1f fps, v-sync %d, dpi %.1f, %s-samples %d, q %d, td %.0f, blend %b, alpha %d, msaa %d",
- lfps, tfps, gl.getSwapInterval(), dpiH, modeS, sceneUIController.getSampleCount(), fpsLabel.getQuality(), td,
+ text = String.format("%03.1f/%03.1f fps, %.1f ms/f, v-sync %d, dpi %.1f, %s-samples %d, q %d, msaa %d, blend %b, alpha %d",
+ lfps, tfps, td, gl.getSwapInterval(), dpiH, modeS, sceneUIController.getSampleCount(), fpsLabel.getQuality(),
+ drawable.getChosenGLCapabilities().getNumSamples(),
renderer.getRenderState().isHintMaskSet(RenderState.BITHINT_BLENDING_ENABLED),
- drawable.getChosenGLCapabilities().getAlphaBits(),
- drawable.getChosenGLCapabilities().getNumSamples());
+ drawable.getChosenGLCapabilities().getAlphaBits());
} else {
text = String.format("%03.1f/%03.1f fps, v-sync %d, %s",
lfps, tfps, gl.getSwapInterval(), actionText);
}
- fpsLabel.setText(text);
+ if( fpsLabel.setText(text) ) { // marks dirty only if text differs.
+ System.err.println(text);
+ }
}
sceneUIController.display(drawable);
}
diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/Label.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/Label.java
index c4c450763..d64b9a731 100644
--- a/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/Label.java
+++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/Label.java
@@ -52,18 +52,36 @@ public class Label extends UIShape {
return text;
}
- public void setText(final String text) {
- this.text = text;
- markShapeDirty();
+ /**
+ * Returns true if text has been updated, false if unchanged.
+ * @param text the text to be set.
+ */
+ public boolean setText(final String text) {
+ if( !this.text.equals(text) ) {
+ this.text = text;
+ markShapeDirty();
+ return true;
+ } else {
+ return false;
+ }
}
public Font getFont() {
return font;
}
- public void setFont(final Font font) {
- this.font = font;
- markShapeDirty();
+ /**
+ * Returns true if font has been updated, false if unchanged.
+ * @param font the font to be set.
+ */
+ public boolean setFont(final Font font) {
+ if( !this.font.equals(font) ) {
+ this.font = font;
+ markShapeDirty();
+ return true;
+ } else {
+ return false;
+ }
}
public float getPixelSize() {
diff --git a/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/LabelButton.java b/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/LabelButton.java
index 6a3637e4a..8a357c8a6 100644
--- a/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/LabelButton.java
+++ b/src/test/com/jogamp/opengl/test/junit/graph/demos/ui/LabelButton.java
@@ -165,9 +165,11 @@ public class LabelButton extends RoundButton {
}
public final void setLabelText(final Font labelFont, final String labelText) {
- label.setFont(labelFont);
- label.setText(labelText);
- markShapeDirty();
+ if( !label.getText().equals(labelText) || !label.getFont().equals(labelFont) ) {
+ label.setFont(labelFont);
+ label.setText(labelText);
+ markShapeDirty();
+ }
}
@Override