Skip to content

Commit b4a99ae

Browse files
committed
contrib/android: fix missing text outside of boxes
PCI speeds and factorization info did not appear at all because they are displayed outside of their box but drawn inside that box "view". Move them out of the box view to the main layout. Signed-off-by: Brice Goglin <[email protected]>
1 parent 8ef74b6 commit b4a99ae

File tree

4 files changed

+42
-22
lines changed

4 files changed

+42
-22
lines changed

contrib/android/AndroidApp/lstopo/src/main/cpp/lib.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ void JNIbox(int r, int g, int b, int x, int y, int width, int height, unsigned s
163163
(*tools.jni)->DeleteLocalRef(tools.jni, class);
164164
}
165165

166-
void JNItext(char *text, int gp_index, int x, int y, int fontsize, int bold) {
166+
void JNItext(char *text, int gp_index, int x, int y, int fontsize, int bold, int outside) {
167167
size_t length = strlen(text);
168168
jbyteArray array = (*tools.jni)->NewByteArray(tools.jni, length);
169169
(*tools.jni)->SetByteArrayRegion(tools.jni, array, 0, length, (const jbyte *) text);
@@ -172,7 +172,7 @@ void JNItext(char *text, int gp_index, int x, int y, int fontsize, int bold) {
172172
jmethodID ctor = (*tools.jni)->GetMethodID(tools.jni, class, "<init>", "([BLjava/lang/String;)V");
173173
jstring str = (jstring) (*tools.jni)->NewObject(tools.jni, class, ctor, array, strEncode);
174174

175-
(*tools.jni)->CallVoidMethod(tools.jni, tools.lstopo, tools.methods.text, str, x, y, fontsize, bold, gp_index);
175+
(*tools.jni)->CallVoidMethod(tools.jni, tools.lstopo, tools.methods.text, str, x, y, fontsize, bold, outside, gp_index);
176176
(*tools.jni)->DeleteLocalRef(tools.jni, str);
177177
(*tools.jni)->DeleteLocalRef(tools.jni, array);
178178
(*tools.jni)->DeleteLocalRef(tools.jni, strEncode);
@@ -207,7 +207,7 @@ void JNIDebug(char *text) {
207207
void setJNIEnv() {
208208
tools.methods.lstopo_android = (*tools.jni)->GetObjectClass(tools.jni, tools.lstopo);
209209
tools.methods.box = (*tools.jni)->GetMethodID(tools.jni, tools.methods.lstopo_android, "box", "(IIIIIIIIILjava/lang/String;)V");
210-
tools.methods.text = (*tools.jni)->GetMethodID(tools.jni, tools.methods.lstopo_android, "text", "(Ljava/lang/String;IIIII)V");
210+
tools.methods.text = (*tools.jni)->GetMethodID(tools.jni, tools.methods.lstopo_android, "text", "(Ljava/lang/String;IIIIII)V");
211211
tools.methods.line = (*tools.jni)->GetMethodID(tools.jni, tools.methods.lstopo_android, "line", "(IIII)V");
212212
tools.methods.debug = (*tools.jni)->GetMethodID(tools.jni, tools.methods.lstopo_android, "writeDebugFile", "(Ljava/lang/String;)V");
213213
tools.methods.clearDebug = (*tools.jni)->GetMethodID(tools.jni, tools.methods.lstopo_android, "clearDebugFile", "()V");

contrib/android/AndroidApp/lstopo/src/main/java/com/hwloc/lstopo/Lstopo.java

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ private void setBoxAttributes(View view, int r, int g, int b, int x, int y, int
133133
/**
134134
* Draw topology text
135135
*/
136-
public void text(String text, int x, int y, int fontsize, int bold, int id){
136+
public void text(String text, int x, int y, int fontsize, int bold, int outside, int id){
137137
currentContent = text;
138138

139139
TextView tv = new TextView(activity);
@@ -155,16 +155,23 @@ public void text(String text, int x, int y, int fontsize, int bold, int id){
155155
} else {
156156
tv.setClickable(false);
157157
LinearLayout viewGroup = layout.findViewById(id);
158-
159-
viewGroup.addView(tv);
160-
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
161-
LinearLayout.LayoutParams.WRAP_CONTENT,
162-
LinearLayout.LayoutParams.WRAP_CONTENT
163-
);
164-
params.setMargins((int) (10 * xscale), (int) (2 * yscale), 0, 0);
165-
tv.setLayoutParams(params);
166-
167-
158+
if (outside != 0) {
159+
/* Text outside the box (PCI speed or factorization) cannot be in the box view,
160+
* or it wouldn't appear. So put it in the entire layout.
161+
* We won't be able to hide it on click, but there's nothing to show there on click anyway.
162+
*/
163+
layout.addView(tv);
164+
tv.setX(x * xscale);
165+
tv.setY(y * yscale);
166+
} else {
167+
viewGroup.addView(tv);
168+
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
169+
LinearLayout.LayoutParams.WRAP_CONTENT,
170+
LinearLayout.LayoutParams.WRAP_CONTENT
171+
);
172+
params.setMargins((int) (10 * xscale), (int) (2 * yscale), 0, 0);
173+
tv.setLayoutParams(params);
174+
}
168175
}
169176
if(bold != 0){
170177
tv.setTypeface(tv.getTypeface(), Typeface.BOLD);

contrib/android/AndroidApp/lstopo/src/main/java/com/hwloc/lstopo/MainActivity.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ public boolean onNavigationItemSelected(MenuItem item) {
254254
startWithInput(lstopo, 2, txtFile.getAbsolutePath(), topology, options);
255255
setMode("txt");
256256
String lstopoText = readFile(txtFile);
257-
lstopo.text(lstopoText, 0, 0, 0, 0, -1);
257+
lstopo.text(lstopoText, 0, 0, 0, 0, 0, -1);
258258
break;
259259
} catch (IOException e) {
260260
e.printStackTrace();
@@ -275,7 +275,7 @@ public boolean onNavigationItemSelected(MenuItem item) {
275275
startWithInput(lstopo, 3, xmlFile.getAbsolutePath(), topology, options);
276276
setMode("xml");
277277
String lstopoText = readFile(xmlFile);
278-
lstopo.text(lstopoText, 0, 0, 0, 0, -1);
278+
lstopo.text(lstopoText, 0, 0, 0, 0, 0, -1);
279279
break;
280280
} catch (IOException e) {
281281
e.printStackTrace();

utils/lstopo/lstopo-android.c

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright © 2019-2022 Inria. All rights reserved.
2+
* Copyright © 2019-2023 Inria. All rights reserved.
33
* See COPYING in top-level directory.
44
*/
55

@@ -14,7 +14,7 @@
1414
#include "lstopo.h"
1515

1616
extern void JNIbox(int r, int g, int b, int x, int y, int width, int height, unsigned style, int gp_index, char *info);
17-
extern void JNItext(char *text, int gp_index, int x, int y, int fontsize, int bold);
17+
extern void JNItext(char *text, int gp_index, int x, int y, int fontsize, int bold, int outside);
1818
extern void JNIline(unsigned x1, unsigned y1, unsigned x2, unsigned y2);
1919
extern void JNIprepare(int width, int height, int fontsize);
2020

@@ -31,6 +31,9 @@ static void native_android_box(struct lstopo_output *loutput, const struct lstop
3131
unsigned style = 0;
3232

3333
if(obj){
34+
/* we could remove this info for factorized objects and bridges,
35+
* but it pretty much doesn't appear at all anyway because it's in the very small bow.
36+
*/
3437
gp_index = obj->gp_index;
3538
hwloc_obj_attr_snprintf(info, 1096, obj, sep, HWLOC_OBJ_SNPRINTF_FLAG_LONG_NAMES|HWLOC_OBJ_SNPRINTF_FLAG_MORE_ATTRS);
3639
}
@@ -64,14 +67,24 @@ native_android_text(struct lstopo_output *loutput, const struct lstopo_color *lc
6467
unsigned cpukind_style = lstopo_obj_cpukind_style(loutput, obj);
6568
int gp_index = -1;
6669
int bold = 0;
67-
68-
if(obj)
69-
gp_index = obj->gp_index;
70+
int outside = 0;
71+
72+
if(obj) {
73+
struct lstopo_obj_userdata *lud = obj->userdata;
74+
gp_index = obj->gp_index;
75+
/* no info box in small boxes */
76+
if (loutput->factorize_enabled
77+
&& lud->factorized == 1
78+
&& obj->parent->arity > loutput->factorize_min[obj->type])
79+
outside = 1;
80+
else if (obj->type == HWLOC_OBJ_BRIDGE)
81+
outside = 1;
82+
}
7083

7184
if (cpukind_style % 2)
7285
bold = 1;
7386

74-
JNItext((char *)text, gp_index, x, y, loutput->fontsize, bold);
87+
JNItext((char *)text, gp_index, x, y, loutput->fontsize, bold, outside);
7588
}
7689

7790
static struct draw_methods native_android_draw_methods = {

0 commit comments

Comments
 (0)