shift disassembly view to being usable as a view rule too; arbitrary disassembly view parameterization

This commit is contained in:
Ryan Fleury
2024-08-27 13:00:21 -07:00
parent 08652e8b0a
commit e59e014b2b
7 changed files with 130 additions and 319 deletions
-239
View File
@@ -852,245 +852,6 @@ DF_CORE_VIEW_RULE_VIZ_BLOCK_PROD_FUNCTION_DEF(bitmap)
df_eval_viz_block_end(out, vb);
}
#if 0
internal Vec2F32
df_bitmap_view_state__screen_from_canvas_pos(DF_BitmapViewState *bvs, Rng2F32 rect, Vec2F32 cvs)
{
Vec2F32 scr =
{
(rect.x0+rect.x1)/2 + (cvs.x - bvs->view_center_pos.x) * bvs->zoom,
(rect.y0+rect.y1)/2 + (cvs.y - bvs->view_center_pos.y) * bvs->zoom,
};
return scr;
}
internal Rng2F32
df_bitmap_view_state__screen_from_canvas_rect(DF_BitmapViewState *bvs, Rng2F32 rect, Rng2F32 cvs)
{
Rng2F32 scr = r2f32(df_bitmap_view_state__screen_from_canvas_pos(bvs, rect, cvs.p0), df_bitmap_view_state__screen_from_canvas_pos(bvs, rect, cvs.p1));
return scr;
}
internal Vec2F32
df_bitmap_view_state__canvas_from_screen_pos(DF_BitmapViewState *bvs, Rng2F32 rect, Vec2F32 scr)
{
Vec2F32 cvs =
{
(scr.x - (rect.x0+rect.x1)/2) / bvs->zoom + bvs->view_center_pos.x,
(scr.y - (rect.y0+rect.y1)/2) / bvs->zoom + bvs->view_center_pos.y,
};
return cvs;
}
internal Rng2F32
df_bitmap_view_state__canvas_from_screen_rect(DF_BitmapViewState *bvs, Rng2F32 rect, Rng2F32 scr)
{
Rng2F32 cvs = r2f32(df_bitmap_view_state__canvas_from_screen_pos(bvs, rect, scr.p0), df_bitmap_view_state__canvas_from_screen_pos(bvs, rect, scr.p1));
return cvs;
}
internal DF_BitmapTopologyInfo
df_vr_bitmap_topology_info_from_cfg(DF_CfgNode *cfg)
{
Temp scratch = scratch_begin(0, 0);
DF_BitmapTopologyInfo info = {0};
{
info.fmt = R_Tex2DFormat_RGBA8;
}
{
DF_CfgNode *width_cfg = df_cfg_node_child_from_string(cfg, str8_lit("w"), 0);
DF_CfgNode *height_cfg = df_cfg_node_child_from_string(cfg, str8_lit("h"), 0);
DF_CfgNode *fmt_cfg = df_cfg_node_child_from_string(cfg, str8_lit("fmt"), 0);
String8List width_expr_strs = {0};
String8List height_expr_strs = {0};
for(DF_CfgNode *child = width_cfg->first; child != &df_g_nil_cfg_node; child = child->next)
{
str8_list_push(scratch.arena, &width_expr_strs, child->string);
}
for(DF_CfgNode *child = height_cfg->first; child != &df_g_nil_cfg_node; child = child->next)
{
str8_list_push(scratch.arena, &height_expr_strs, child->string);
}
String8 width_expr = str8_list_join(scratch.arena, &width_expr_strs, 0);
String8 height_expr = str8_list_join(scratch.arena, &height_expr_strs, 0);
String8 fmt_string = fmt_cfg->first->string;
E_Eval width_eval = e_eval_from_string(scratch.arena, width_expr);
E_Eval width_eval_value = e_value_eval_from_eval(width_eval);
info.width = width_eval_value.value.u64;
E_Eval height_eval = e_eval_from_string(scratch.arena, height_expr);
E_Eval height_eval_value = e_value_eval_from_eval(height_eval);
info.height = height_eval_value.value.u64;
if(fmt_string.size != 0)
{
for(R_Tex2DFormat fmt = (R_Tex2DFormat)0; fmt < R_Tex2DFormat_COUNT; fmt = (R_Tex2DFormat)(fmt+1))
{
if(str8_match(r_tex2d_format_display_string_table[fmt], fmt_string, StringMatchFlag_CaseInsensitive))
{
info.fmt = fmt;
break;
}
}
}
}
scratch_end(scratch);
return info;
}
internal UI_BOX_CUSTOM_DRAW(df_vr_bitmap_box_draw)
{
DF_VR_BitmapBoxDrawData *draw_data = (DF_VR_BitmapBoxDrawData *)user_data;
Vec4F32 bg_color = box->palette->background;
d_img(box->rect, draw_data->src, draw_data->texture, v4f32(1, 1, 1, 1), 0, 0, 0);
if(draw_data->loaded_t < 0.98f)
{
Rng2F32 clip = box->rect;
for(UI_Box *b = box->parent; !ui_box_is_nil(b); b = b->parent)
{
if(b->flags & UI_BoxFlag_Clip)
{
clip = intersect_2f32(b->rect, clip);
}
}
d_blur(intersect_2f32(clip, box->rect), 10.f-9.f*draw_data->loaded_t, 0);
}
if(r_handle_match(draw_data->texture, r_handle_zero()))
{
d_rect(box->rect, v4f32(0, 0, 0, 1), 0, 0, 0);
}
d_rect(box->rect, v4f32(bg_color.x*bg_color.w, bg_color.y*bg_color.w, bg_color.z*bg_color.w, 1.f-draw_data->loaded_t), 0, 0, 0);
if(draw_data->hovered)
{
Vec4F32 indicator_color = v4f32(1, 1, 1, 1);
d_rect(pad_2f32(r2f32p(box->rect.x0 + draw_data->mouse_px.x*draw_data->ui_per_bmp_px,
box->rect.y0 + draw_data->mouse_px.y*draw_data->ui_per_bmp_px,
box->rect.x0 + draw_data->mouse_px.x*draw_data->ui_per_bmp_px + draw_data->ui_per_bmp_px,
box->rect.y0 + draw_data->mouse_px.y*draw_data->ui_per_bmp_px + draw_data->ui_per_bmp_px),
3.f),
indicator_color, 3.f, 4.f, 1.f);
}
}
#endif
#if 0
DF_GFX_VIEW_RULE_BLOCK_UI_FUNCTION_DEF(bitmap)
{
Temp scratch = scratch_begin(0, 0);
HS_Scope *hs_scope = hs_scope_open();
TEX_Scope *tex_scope = tex_scope_open();
DF_VR_BitmapState *state = df_view_rule_block_user_state(key, DF_VR_BitmapState);
if(state->last_open_frame_idx+1 < df_frame_index())
{
state->loaded_t = 0;
}
state->last_open_frame_idx = df_frame_index();
//////////////////////////////
//- rjf: unpack context
//
DF_Entity *thread = df_entity_from_handle(df_interact_regs()->thread);
DF_Entity *process = df_entity_ancestor_from_kind(thread, DF_EntityKind_Process);
//////////////////////////////
//- rjf: evaluate expression
//
E_Eval value_eval = e_value_eval_from_eval(eval);
U64 base_vaddr = value_eval.value.u64;
DF_BitmapTopologyInfo topology_info = df_vr_bitmap_topology_info_from_cfg(cfg);
U64 expected_size = topology_info.width*topology_info.height*r_tex2d_format_bytes_per_pixel_table[topology_info.fmt];
Rng1U64 vaddr_range = r1u64(base_vaddr, base_vaddr+expected_size);
//////////////////////////////
//- rjf: map expression artifacts -> texture
//
U128 texture_key = ctrl_hash_store_key_from_process_vaddr_range(process->ctrl_machine_id, process->ctrl_handle, vaddr_range, 0);
TEX_Topology topology = tex_topology_make(v2s32((S32)topology_info.width, (S32)topology_info.height), topology_info.fmt);
R_Handle texture = tex_texture_from_key_topology(tex_scope, texture_key, topology, 0);
//////////////////////////////
//- rjf: animate
//
if(expected_size != 0)
{
if(r_handle_match(r_handle_zero(), texture))
{
df_gfx_request_frame();
state->loaded_t = 0;
}
else
{
F32 rate = 1 - pow_f32(2, (-15.f * df_dt()));
state->loaded_t += (1.f - state->loaded_t) * rate;
if(state->loaded_t < 0.99f)
{
df_gfx_request_frame();
}
}
}
//////////////////////////////
//- rjf: build preview
//
if(expected_size != 0)
{
F32 img_dim = dim.y - ui_top_font_size()*2.f;
UI_Padding(ui_pct(1.f, 0.f))
UI_PrefWidth(ui_px(img_dim*((F32)topology_info.width/(F32)topology_info.height), 1.f))
UI_Column UI_Padding(ui_pct(1.f, 0.f))
UI_PrefHeight(ui_px(img_dim, 1.f))
{
ui_image(texture, R_Tex2DSampleKind_Nearest, r2f32(v2f32(0, 0), v2f32((F32)topology_info.width, (F32)topology_info.height)), v4f32(1, 1, 1, state->loaded_t), 10.f*(1-state->loaded_t), str8_lit("image_box"));
}
}
tex_scope_close(tex_scope);
hs_scope_close(hs_scope);
scratch_end(scratch);
}
#endif
#if 0
DF_VIEW_SETUP_FUNCTION_DEF(bitmap)
{
DF_BitmapViewState *bvs = df_view_user_state(view, DF_BitmapViewState);
DF_CfgNode *view_center_cfg = df_cfg_node_child_from_string(cfg_root, str8_lit("view_center"), StringMatchFlag_CaseInsensitive);
DF_CfgNode *zoom_cfg = df_cfg_node_child_from_string(cfg_root, str8_lit("zoom"), StringMatchFlag_CaseInsensitive);
DF_CfgNode *bitmap_cfg = df_cfg_node_child_from_string(cfg_root, str8_lit("bitmap"), StringMatchFlag_CaseInsensitive);
DF_Entity *thread = df_entity_from_handle(df_interact_regs()->thread);
DF_Entity *process = df_entity_ancestor_from_kind(thread, DF_EntityKind_Process);
U64 thread_unwind_rip_vaddr = df_query_cached_rip_from_thread_unwind(thread, df_interact_regs()->unwind_count);
bvs->view_center_pos.x = (F32)f64_from_str8(bitmap_cfg->first->string);
bvs->view_center_pos.y = (F32)f64_from_str8(bitmap_cfg->first->next->string);
bvs->zoom = (F32)f64_from_str8(zoom_cfg->first->string);
bvs->top = df_vr_bitmap_topology_info_from_cfg(bitmap_cfg);
if(bvs->zoom == 0)
{
bvs->zoom = 1.f;
}
}
DF_VIEW_STRING_FROM_STATE_FUNCTION_DEF(bitmap)
{
DF_BitmapViewState *bvs = df_view_user_state(view, DF_BitmapViewState);
String8 result = push_str8f(arena, "view_center:(%.2f %.2f) zoom:(%.2f) bitmap:(w:%I64u, h:%I64u, fmt:%S)",
bvs->view_center_pos.x,
bvs->view_center_pos.y,
bvs->zoom,
bvs->top.width,
bvs->top.height,
r_tex2d_format_display_string_table[bvs->top.fmt]);
return result;
}
DF_VIEW_CMD_FUNCTION_DEF(bitmap)
{
}
DF_VIEW_UI_FUNCTION_DEF(bitmap)
{
}
#endif
////////////////////////////////
//~ rjf: "geo"