| 1 |
/* |
| 2 |
* SPDX-License-Identifier: BSD-3-Clause |
| 3 |
* Copyright © 2019-2026 Inria. All rights reserved. |
| 4 |
* See COPYING in top-level directory. |
| 5 |
*/ |
| 6 |
|
| 7 |
#include <private/autogen/config.h> |
| 8 |
#include <hwloc.h> |
| 9 |
|
| 10 |
#include <stdlib.h> |
| 11 |
#include <stdio.h> |
| 12 |
#include <string.h> |
| 13 |
#include <errno.h> |
| 14 |
|
| 15 |
#include "lstopo.h" |
| 16 |
|
| 17 |
extern void JNIbox(int r, int g, int b, int x, int y, int width, int height, unsigned style, int gp_index, char *info); |
| 18 |
extern void JNItext(char *text, int gp_index, int x, int y, int fontsize, int bold, int outside); |
| 19 |
extern void JNIline(unsigned x1, unsigned y1, unsigned x2, unsigned y2); |
| 20 |
extern void JNIprepare(int width, int height, int fontsize); |
| 21 |
|
| 22 |
#define ANDROID_TEXT_WIDTH(length, fontsize) (((length) * (fontsize))/2) |
| 23 |
#define ANDROID_FONTSIZE_SCALE(size) (((size) * 11) / 9) |
| 24 |
|
| 25 |
#define GP_INDEX_MULTIPLIER 100 /* there can be multiple boxes per object, so multiple gp_index by 100 and add the box_id to get a unique box ID */ |
| 26 |
|
| 27 |
static void native_android_box(struct lstopo_output *loutput, const struct lstopo_color *lcolor, unsigned depth __hwloc_attribute_unused, unsigned x, unsigned width, unsigned y, unsigned height, hwloc_obj_t obj, unsigned box_id) |
| 28 |
{ |
| 29 |
unsigned cpukind_style = lstopo_obj_cpukind_style(loutput, obj); |
| 30 |
int viewid = -1; |
| 31 |
int r = lcolor->r, g = lcolor->g, b = lcolor->b; |
| 32 |
char info[1096] = ""; |
| 33 |
const char * sep = " "; |
| 34 |
unsigned style = 0; |
| 35 |
|
| 36 |
if(obj){ |
| 37 |
/* we could remove this info for factorized objects and bridges, |
| 38 |
* but it pretty much doesn't appear at all anyway because it's in the very small bow. |
| 39 |
*/ |
| 40 |
viewid = obj->gp_index * GP_INDEX_MULTIPLIER + box_id; |
| 41 |
hwloc_obj_attr_snprintf(info, 1096, obj, sep, 1); |
| 42 |
} |
| 43 |
|
| 44 |
if (cpukind_style) |
| 45 |
style = cpukind_style; |
| 46 |
|
| 47 |
JNIbox(r, g, b, x, y, width, height, style, viewid, info); |
| 48 |
//Creating a usable java string from char * may trigger an UTF-8 error |
| 49 |
//This code creates a byte array from the char * variable before creating the java string |
| 50 |
} |
| 51 |
|
| 52 |
|
| 53 |
static void |
| 54 |
native_android_line(struct lstopo_output *loutput __hwloc_attribute_unused, unsigned depth __hwloc_attribute_unused, unsigned x1, unsigned y1, unsigned x2, unsigned y2, hwloc_obj_t obj __hwloc_attribute_unused, unsigned line_id __hwloc_attribute_unused) |
| 55 |
{ |
| 56 |
JNIline(x1, y1, x2, y2); |
| 57 |
} |
| 58 |
|
| 59 |
static void |
| 60 |
native_android_textsize(struct lstopo_output *loutput __hwloc_attribute_unused, const char *text __hwloc_attribute_unused, unsigned textlength, unsigned fontsize, unsigned *width) |
| 61 |
{ |
| 62 |
fontsize = ANDROID_FONTSIZE_SCALE(fontsize); |
| 63 |
*width = ANDROID_TEXT_WIDTH(textlength, fontsize); |
| 64 |
} |
| 65 |
|
| 66 |
|
| 67 |
static void |
| 68 |
native_android_text(struct lstopo_output *loutput, const struct lstopo_color *lcolor __hwloc_attribute_unused, int size __hwloc_attribute_unused, unsigned depth __hwloc_attribute_unused, unsigned x, unsigned y, const char *text, hwloc_obj_t obj, unsigned text_id __hwloc_attribute_unused) |
| 69 |
{ |
| 70 |
unsigned cpukind_style = lstopo_obj_cpukind_style(loutput, obj); |
| 71 |
int viewid = -1; |
| 72 |
int bold = 0; |
| 73 |
int outside = 0; |
| 74 |
|
| 75 |
if(obj) { |
| 76 |
struct lstopo_obj_userdata *lud = obj->userdata; |
| 77 |
viewid = obj->gp_index * GP_INDEX_MULTIPLIER; |
| 78 |
/* no info box in small boxes */ |
| 79 |
if (loutput->factorize_enabled |
| 80 |
&& lud->factorized == 1 |
| 81 |
&& obj->parent->arity > loutput->factorize_min[obj->type]) |
| 82 |
outside = 1; |
| 83 |
else if (obj->type == HWLOC_OBJ_BRIDGE) |
| 84 |
outside = 1; |
| 85 |
} |
| 86 |
|
| 87 |
if (cpukind_style % 2) |
| 88 |
bold = 1; |
| 89 |
|
| 90 |
JNItext((char *)text, viewid, x, y, loutput->fontsize, bold, outside); |
| 91 |
} |
| 92 |
|
| 93 |
static struct draw_methods native_android_draw_methods = { |
| 94 |
NULL, |
| 95 |
NULL, |
| 96 |
native_android_box, |
| 97 |
native_android_line, |
| 98 |
native_android_text, |
| 99 |
native_android_textsize, |
| 100 |
}; |
| 101 |
|
| 102 |
int output_android(struct lstopo_output * loutput, const char *filename __hwloc_attribute_unused) |
| 103 |
{ |
| 104 |
loutput->methods = &native_android_draw_methods; |
| 105 |
loutput->backend_flags |= LSTOPO_BACKEND_FLAG_APPROXIMATIVE_TEXTWIDTH; |
| 106 |
|
| 107 |
/* recurse once for preparing sizes and positions */ |
| 108 |
loutput->drawing = LSTOPO_DRAWING_PREPARE; |
| 109 |
output_draw(loutput); |
| 110 |
loutput->drawing = LSTOPO_DRAWING_DRAW; |
| 111 |
|
| 112 |
/* ready */ |
| 113 |
declare_colors(loutput); |
| 114 |
lstopo_prepare_custom_styles(loutput); |
| 115 |
JNIprepare(loutput->height, loutput->width, loutput->fontsize); |
| 116 |
|
| 117 |
output_draw(loutput); |
| 118 |
|
| 119 |
return 0; |
| 120 |
} |