CDC Badge OS
Firmware for the CDC Badge v1.0 hardware security key
Loading...
Searching...
No Matches
host_api_surface.cpp File Reference

Offscreen surface host API: canvas-style drawing onto MonoSurface targets of arbitrary size, exported as packed 1-bpp or JPEG. More...

#include "plugin_manager/host_api.h"
#include "plugin_manager/PluginUiState.h"
#include "cdc_image/JpegEncoder.h"
#include "cdc_views/CanvasView.h"
#include "cdc_views/Fonts.h"
#include "cdc_views/MonoSurface.h"
#include "cdc_views/RenderHelpers.h"
#include "host_str_conv.h"
#include <cstring>
#include <memory>
#include <string>

Go to the source code of this file.

Functions

void * plg_get_active_plugin (void)
int host_surface_create (uint16_t w, uint16_t h)
 Create a w x h surface, cleared to white.
int host_surface_destroy (uint32_t surface)
 Destroy a surface and free its memory.
int host_surface_clear (uint32_t surface)
 Clear a surface to white.
int host_surface_set_font (uint32_t surface, uint8_t font_id)
 Select the font for subsequent text calls (HOST_FONT_* id).
int host_surface_set_text_size (uint32_t surface, uint8_t size)
 Set the integer text scale (1..4) for subsequent text calls.
int host_surface_set_text_color (uint32_t surface, uint8_t inverted)
 Draw text white-on-black (inverted != 0) or black-on-white.
int host_surface_set_shade (uint32_t surface, uint8_t shade)
 Set the fill shade for filled shapes: 0 white .. 255 solid black.
int host_surface_draw_text (uint32_t surface, int16_t x, int16_t y, const char *text)
 Draw UTF-8 text with the current font/size at (x, y) baseline-top.
int host_surface_draw_text_aligned (uint32_t surface, int16_t x, int16_t y, int16_t w, const char *text, uint8_t align)
 Draw UTF-8 text aligned within a w-wide box starting at x.
int host_surface_measure_text (uint32_t surface, const char *text, uint16_t *out_w, uint16_t *out_h)
 Measure UTF-8 text with the surface's current font/size.
int host_surface_draw_pixel (uint32_t surface, int16_t x, int16_t y)
 Draw a pixel (current shade decides ink: shade > 0 draws black).
int host_surface_draw_line (uint32_t surface, int16_t x0, int16_t y0, int16_t x1, int16_t y1)
 Draw a line.
int host_surface_draw_rect (uint32_t surface, int16_t x, int16_t y, int16_t w, int16_t h, uint8_t filled)
 Draw a rectangle; filled ones use the current shade.
int host_surface_draw_circle (uint32_t surface, int16_t x, int16_t y, int16_t r, uint8_t filled)
 Draw a circle centered at (x, y); filled ones use the current shade.
int host_surface_draw_triangle (uint32_t surface, int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint8_t filled)
 Draw a triangle; filled ones use the current shade.
int host_surface_draw_round_rect (uint32_t surface, int16_t x, int16_t y, int16_t w, int16_t h, int16_t r, uint8_t filled)
 Draw a rounded rectangle with corner radius r.
int host_surface_hline (uint32_t surface, int16_t x, int16_t y, int16_t w)
 Draw a horizontal line of width w.
int host_surface_vline (uint32_t surface, int16_t x, int16_t y, int16_t h)
 Draw a vertical line of height h.
int host_surface_draw_bitmap (uint32_t surface, int16_t x, int16_t y, int16_t w, int16_t h, const uint8_t *data, uint32_t len)
 Blit a packed 1-bpp bitmap (MSB-first, set bit = black) at (x, y).
int host_surface_export (uint32_t surface, uint8_t *out, size_t out_size, uint16_t *out_stride_bytes)
 Copy the surface's packed pixel rows into out.
int host_surface_export_jpg (uint32_t surface, uint8_t quality, uint8_t *out, size_t out_size, uint32_t *out_len)
 Encode the surface as a grayscale JPEG.
int host_surface_draw_sprite (uint32_t surface, int16_t x, int16_t y, uint32_t sprite)
 Stamp a sprite's current frame onto a surface at (x, y).
int host_sprite_create_from_surface (uint32_t surface, uint16_t frame_w, uint16_t frame_h, uint16_t frame_count)
 Create a sprite by slicing a surface into a row-major grid of frame_w x frame_h cells.
void plg_surface_on_unload (void *plugin)

Detailed Description

Offscreen surface host API: canvas-style drawing onto MonoSurface targets of arbitrary size, exported as packed 1-bpp or JPEG.

Surfaces are per-plugin (max HOST_SURFACE_MAX_PER_PLUGIN, each capped at HOST_SURFACE_MAX_BYTES of pixel data) and are freed on plugin unload. All calls run inside the owner's WASM frame, so the table needs no locking. On the surface, ink is color 1 (a set bit is black) and background is 0.

Definition in file host_api_surface.cpp.

Function Documentation

◆ plg_get_active_plugin()

void * plg_get_active_plugin ( void )

Definition at line 24 of file plugin_log_bridge.cpp.

Referenced by host_surface_create().

◆ plg_surface_on_unload()

void plg_surface_on_unload ( void * plugin)

Definition at line 391 of file host_api_surface.cpp.