pub struct Screen {Show 19 fields
pub vram: *mut u32,
pub back_buffer: *mut u32,
pub use_back_buffer: Cell<bool>,
pub width: u32,
pub height: u32,
pub pitch: u32,
pub clip: Cell<Option<(u32, u32, u32, u32)>>,
clip_stack: Cell<[Option<(u32, u32, u32, u32)>; 4]>,
clip_depth: Cell<usize>,
render_target: Cell<*mut u32>,
target_width: Cell<u32>,
target_height: Cell<u32>,
vsync: Cell<bool>,
page: Cell<u32>,
fb_virtual_height: Cell<u32>,
fb_size: Cell<u32>,
prev_content_region: Cell<Option<(u32, u32, u32, u32)>>,
page_cursor: Cell<[(u32, u32); 2]>,
vsync_init_count: Cell<u8>,
}Fields§
§vram: *mut u32§back_buffer: *mut u32§use_back_buffer: Cell<bool>§width: u32§height: u32§pitch: u32§clip: Cell<Option<(u32, u32, u32, u32)>>§clip_stack: Cell<[Option<(u32, u32, u32, u32)>; 4]>§clip_depth: Cell<usize>§render_target: Cell<*mut u32>§target_width: Cell<u32>§target_height: Cell<u32>§vsync: Cell<bool>§page: Cell<u32>§fb_virtual_height: Cell<u32>§fb_size: Cell<u32>§prev_content_region: Cell<Option<(u32, u32, u32, u32)>>§page_cursor: Cell<[(u32, u32); 2]>§vsync_init_count: Cell<u8>Implementations§
Source§impl Screen
impl Screen
pub fn new(vram: *mut u32, width: u32, height: u32, pitch: u32) -> Self
pub fn vsync_enabled(&self) -> bool
pub fn has_pending_vsync_sync(&self) -> bool
Sourcepub fn debug_geometry(&self)
pub fn debug_geometry(&self)
フレームバッファの実ジオメトリをシリアルへ出力する(実機デバッグ用)。 ブート最序盤のログがスクロールアウトしても確認できるよう、任意の地点で呼べる。
Sourcepub fn set_fb_geometry(&self, virtual_height: u32, size: u32)
pub fn set_fb_geometry(&self, virtual_height: u32, size: u32)
GPU が実際に確保したフレームバッファのジオメトリ(仮想高さ・総サイズ)を記録する。 enable_vsync() がこれを見て 2 ページ確保済みか判定する。
Sourcepub fn enable_vsync(&self) -> bool
pub fn enable_vsync(&self) -> bool
VSync ページフリップを有効化する。ただし 2 ページ(virtual_height >= 2*height かつ バッファサイズ十分)が実際に確保できている場合のみ。確保できていなければ単一バッファの ままにする(page1 がフレームバッファ外を指して横線ノイズになるのを防ぐ)。 有効化できたら true を返す。
pub fn set_render_target(&self, buf: *mut u32, w: u32, h: u32)
pub fn reset_render_target(&self)
pub fn resolve_target(&self) -> (*mut u32, u32, u32)
Sourcepub fn resolve_stride(&self) -> u32
pub fn resolve_stride(&self) -> u32
ターゲットバッファの1行あたりの実際のピクセル数(Stride)を返します。
pub fn enable_double_buffering(&mut self)
pub fn flush(&self)
pub fn flush_rect(&self, x0: u32, y0: u32, x1: u32, y1: u32)
Sourcepub fn draw_mouse_direct(&self, mouse: &Mouse)
pub fn draw_mouse_direct(&self, mouse: &Mouse)
一時的に裏画面を無効化し、直接VRAM(表画面)にマウスを描画します
Sourcepub fn flush_with_cursor(&self, mouse: &Mouse)
pub fn flush_with_cursor(&self, mouse: &Mouse)
バックバッファにカーソルを一時合成してからflushする。 flush中にカーソルが消えてちらつく現象を防ぐ。
Sourcepub fn flush_dirty_pageflip(
&self,
content: Option<(u32, u32, u32, u32)>,
mouse: &Mouse,
)
pub fn flush_dirty_pageflip( &self, content: Option<(u32, u32, u32, u32)>, mouse: &Mouse, )
VSync ページフリップ時に、ダーティ領域だけを裏ページへ転送してフリップする部分フラッシュ。
content は今回のコンテンツのダーティ矩形 (x0,y0,x1,y1)。カーソルは内部で合成する。
裏ページは 2 フレーム前の内容なので「今回 ∪ 前回」のダーティ領域を転送して整合を保つ。
全画面コピーを避けるため、小さな更新ではコストが大幅に下がる。
pub fn set_clip(&self, x0: u32, y0: u32, x1: u32, y1: u32)
pub fn clear_clip(&self)
Sourcepub fn push_clip(&self, x0: u32, y0: u32, x1: u32, y1: u32)
pub fn push_clip(&self, x0: u32, y0: u32, x1: u32, y1: u32)
現在のクリップをスタックに積んで、新しいクリップを現在と交差させて設定する。 pop_clip() で元のクリップに戻る(最大 4 段ネスト可)。
pub fn clear(&self, color: Color)
Sourcepub fn draw_pixel(&self, x: u32, y: u32, color: Color)
pub fn draw_pixel(&self, x: u32, y: u32, color: Color)
計算量: O(1) — クリップ判定 1 回と 32bit 書き込み 1 回。
描画の最下層プリミティブ。上層はこれの呼び出し回数で見積もれる
(規約は spec/complexity_annotation.md)。
pub fn read_pixel(&self, x: u32, y: u32) -> Color
Sourcepub fn draw_pixel_alpha(&self, x: u32, y: u32, color: Color, alpha: u8)
pub fn draw_pixel_alpha(&self, x: u32, y: u32, color: Color, alpha: u8)
計算量: O(1)。ただし定数倍は draw_pixel より重い。
alpha == 0: 何もしない(最速)alpha == 255:draw_pixelへ委譲(O(1)、軽い)- それ以外: 既存ピクセルの読み出し+3 チャンネルの合成が要る。 読み出しがフレームバッファへのアクセスになるため、 不透明の場合の数倍のコストになる
Sourcepub fn draw_string_vector(
&self,
x: u32,
y: u32,
s: &str,
color: Color,
size_px: u32,
)
pub fn draw_string_vector( &self, x: u32, y: u32, s: &str, color: Color, size_px: u32, )
ベクトルフォントを用いて、指定したサイズと色で文字列を描画します (アンチエイリアス対応)
Sourcepub fn draw_string_vector_bg(
&self,
x: u32,
y: u32,
s: &str,
color: Color,
size_px: u32,
bg: Color,
)
pub fn draw_string_vector_bg( &self, x: u32, y: u32, s: &str, color: Color, size_px: u32, bg: Color, )
ベクトルフォントを用いて、指定した背景色で文字列を描画します(カラーキャッシュによる高速化版)
Sourcepub fn draw_vscrollbar(
&self,
track_x: u32,
track_y: i32,
track_h: i32,
content_h: i32,
viewport_h: i32,
scroll_pos: i32,
)
pub fn draw_vscrollbar( &self, track_x: u32, track_y: i32, track_h: i32, content_h: i32, viewport_h: i32, scroll_pos: i32, )
縦スクロールバーの共通描画ヘルパー(幅 6px のサム)。
track_x: バー帯の左端 Xtrack_y/track_h: トラック(可動域)の上端 Y と高さcontent_h: コンテンツ全体の高さviewport_h: 表示領域の高さscroll_pos: 現在のスクロール量 (0..=content_h-viewport_h)
コンテンツが表示領域に収まっている場合は何も描かない。
Web ページ・textarea・将来的にターミナル等、スクロールする UI は
すべてこのヘルパーを使い、見た目と計算を統一する。
計算量: O(6×Th) — Th はサムの高さ(ピクセル)。boxfill 1 回ぶん。
幅は 6px 固定なので実質 O(Th)。
Sourcepub fn boxfill(&self, x0: u32, y0: u32, x1: u32, y1: u32, color: Color)
pub fn boxfill(&self, x0: u32, y0: u32, x1: u32, y1: u32, color: Color)
計算量: O(W×H) — W = x1-x0, H = y1-y0(ピクセル)。
定数倍がアルファで大きく変わる:
- 不透明(
alpha == 0xFF)/ 完全透明: 行単位の一括書き込み。軽い - 半透明(1〜254): 1 ピクセルずつ
draw_pixel_alphaへ委譲するため 数倍重い(spec/alpha_compositing.md)
呼び出し頻度: 要素ごとに毎フレーム。画面を覆う大きな要素が支配的になる。
pub fn draw_char(&self, x: u32, y: u32, c: char, color: Color)
pub fn draw_string(&self, x: u32, y: u32, s: &str, color: Color)
pub fn measure_string_monospace(&self, s: &str) -> u32
pub fn draw_string_monospace(&self, x: u32, y: u32, s: &str, color: Color)
Sourcepub fn draw_string_monospace_bg(
&self,
x: u32,
y: u32,
s: &str,
color: Color,
bg: Color,
)
pub fn draw_string_monospace_bg( &self, x: u32, y: u32, s: &str, color: Color, bg: Color, )
等幅ベクターフォントを用いて、指定した背景色で文字列を描画します(カラーキャッシュによる高速化版)
pub fn measure_string_ja(&self, s: &str, size: u32) -> u32
Sourcepub fn draw_string_ja(&self, x: u32, y: u32, s: &str, color: Color)
pub fn draw_string_ja(&self, x: u32, y: u32, s: &str, color: Color)
日本語(UTF-8)の半角・全角が混在した文字列を描画します
pub fn draw_string_ja_size( &self, x: u32, y: u32, s: &str, size: u32, color: Color, )
pub fn draw_string_ja_size_ext( &self, x: u32, y: u32, s: &str, size: u32, color: Color, italic: bool, )
pub fn draw_string_ja_size_bg( &self, x: u32, y: u32, s: &str, size: u32, color: Color, bg: Color, )
pub fn draw_string_ja_size_ext_bg( &self, x: u32, y: u32, s: &str, size: u32, color: Color, italic: bool, bg: Color, )
Sourcepub fn draw_string_ja_size_ext_bg_ls(
&self,
x: u32,
y: u32,
s: &str,
size: u32,
color: Color,
italic: bool,
bg: Color,
ls: i32,
)
pub fn draw_string_ja_size_ext_bg_ls( &self, x: u32, y: u32, s: &str, size: u32, color: Color, italic: bool, bg: Color, ls: i32, )
letter-spacing 対応版。ls(px, 負も可) を各文字 advance に加える。
Sourcepub fn draw_string_family(
&self,
x: u32,
y: u32,
s: &str,
size: u32,
color: Color,
italic: bool,
bg: Color,
ls: i32,
ws: i32,
family_list: &str,
bold: bool,
)
pub fn draw_string_family( &self, x: u32, y: u32, s: &str, size: u32, color: Color, italic: bool, bg: Color, ls: i32, ws: i32, family_list: &str, bold: bool, )
letter-spacing + word-spacing 対応版。半角スペース1文字ごとに ws(px, 負も可) も加算する。 計算量: O(N × G) — N は文字数、G は 1 グリフの面積(ピクセル)。
グリフのラスタライズ結果は vector_font::get_glyph が
(文字, サイズ) をキャッシュしているため、輪郭からの再ラスタライズは
初回のみ(キャッシュは 8000 件で全クリア)。
2 回目以降はキャッシュ済みビットマップの転送だけになる。
実測: sugi-lab.net の 1 フレームで 0〜2 tick。描画コストの支配項ではない。
font-family を指定して描く。
【2026-08-03】@font-face で登録した Web フォントは
CUSTOM_FONTS に入るが、描画側が font-family を受け取らず
GLOBAL_VECTOR_FONT しか見ていなかったため、
取得・展開・登録まで成功しても字形に一切反映されなかった。
family はカンマ区切りのリストをそのまま渡してよい。
先頭から順に見て、登録済みの family が見つかればそれで描く。
見つからなければ従来どおり既定フォントで描く(フォールバック)。
計算量: O(F + N×G) — F は family リストの要素数、 N は文字数、G は 1 グリフの面積。
pub fn draw_string_ja_size_ext_bg_ls_ws( &self, x: u32, y: u32, s: &str, size: u32, color: Color, italic: bool, bg: Color, ls: i32, ws: i32, )
Sourcefn draw_glyphs_with_font(
&self,
font: &mut VectorFont,
x: u32,
y: u32,
s: &str,
size: u32,
color: Color,
italic: bool,
bg: Color,
ls: i32,
ws: i32,
)
fn draw_glyphs_with_font( &self, font: &mut VectorFont, x: u32, y: u32, s: &str, size: u32, color: Color, italic: bool, bg: Color, ls: i32, ws: i32, )
実際にグリフを並べて描く本体。フォントは呼び出し側が選んで渡す。
Sourcepub fn draw_text_emphasis(
&self,
x: u32,
y: u32,
s: &str,
size: u32,
mark: &str,
color: Color,
ls: i32,
ws: i32,
)
pub fn draw_text_emphasis( &self, x: u32, y: u32, s: &str, size: u32, mark: &str, color: Color, ls: i32, ws: i32, )
text-emphasis-style(傍点・圏点): draw_string_ja_size_ext_bg_ls_ws と同じ
文字送り幅の計算を再利用し、各文字(空白を除く)の中央上部に小さな印を描く。
横書き前提(text-emphasis-position は非対応で常に上に描く)。
mark は “dot”(●)/“circle”(○)/“double-circle”(◎近似)/“triangle”(▲)/
“sesame”(,に近い小さな2点)、またはそれ以外はカスタム1文字をそのまま
小さめのフォントで描く。
Sourcefn draw_circle_fill(&self, cx: u32, cy: u32, r: u32, color: Color)
fn draw_circle_fill(&self, cx: u32, cy: u32, r: u32, color: Color)
塗りつぶし円(emphasis mark 用の小さな円)。
Sourcefn draw_char_ja_16x16(&self, x: u32, y: u32, bitmap: &[u8; 8], color: Color)
fn draw_char_ja_16x16(&self, x: u32, y: u32, bitmap: &[u8; 8], color: Color)
8x8の日本語ビットマップデータを縦横2倍にして 16x16 で描画します (最近傍補間)
Sourcefn draw_char_ja_tofu(&self, x: u32, y: u32, color: Color)
fn draw_char_ja_tofu(&self, x: u32, y: u32, color: Color)
フォントデータが不足している場合の 16x16 豆腐 (枠線) 描画
Sourcepub fn draw_svg_icon(
&self,
x: u32,
y: u32,
svg_data: &[u8],
size: u32,
tint: Color,
)
pub fn draw_svg_icon( &self, x: u32, y: u32, svg_data: &[u8], size: u32, tint: Color, )
SVGアイコンをラスタライズしてアルファブレンドで描画します。 tint: 描画色(SVGの塗り色を上書きする)。alphaは元のアルファマスクを使用。
Sourcepub fn draw_bmp(
&self,
x: u32,
y: u32,
target_width: u32,
target_height: u32,
bmp_data: &[u8],
) -> Result<(), &'static str>
pub fn draw_bmp( &self, x: u32, y: u32, target_width: u32, target_height: u32, bmp_data: &[u8], ) -> Result<(), &'static str>
簡易 BMP デコーダ。24ビットまたは32ビット無圧縮の BMP データを指定座標に、指定サイズへ Nearest Neighbor 拡大縮小して描画します。
Sourcepub fn draw_image(
&self,
x: u32,
y: u32,
target_width: u32,
target_height: u32,
data: &[u8],
) -> Result<(), &'static str>
pub fn draw_image( &self, x: u32, y: u32, target_width: u32, target_height: u32, data: &[u8], ) -> Result<(), &'static str>
PNG, JPG, BMP をデコードし、指定サイズへ Nearest Neighbor 拡大縮小して描画します
Sourcepub fn draw_gradient_rect(
&self,
x0: u32,
y0: u32,
x1: u32,
y1: u32,
c1: Color,
c2: Color,
vertical: bool,
)
pub fn draw_gradient_rect( &self, x0: u32, y0: u32, x1: u32, y1: u32, c1: Color, c2: Color, vertical: bool, )
Draw a linear gradient rectangle. Interpolates between c1 and c2. If vertical=true, gradient goes top→bottom; otherwise left→right.
Sourcepub fn draw_radial_gradient_rect(
&self,
x0: u32,
y0: u32,
x1: u32,
y1: u32,
c1: Color,
c2: Color,
)
pub fn draw_radial_gradient_rect( &self, x0: u32, y0: u32, x1: u32, y1: u32, c1: Color, c2: Color, )
radial-gradient(circle, c1, c2) — 矩形の中心を起点に、中心から最も遠い角までの
距離を半径として c1(中心)→c2(外周) へ線形補間する。楕円/位置指定などは非対応の簡略実装。
Sourcepub fn draw_conic_gradient_rect(
&self,
x0: u32,
y0: u32,
x1: u32,
y1: u32,
c1: Color,
c2: Color,
)
pub fn draw_conic_gradient_rect( &self, x0: u32, y0: u32, x1: u32, y1: u32, c1: Color, c2: Color, )
conic-gradient(c1, c2) — 矩形の中心を起点に、12時方向(真上)を角度0として
時計回りに掃引し c1(0°)→c2(360°直前)へ線形補間する(実ブラウザの2色既定と同様、
0°/360° の境界に色が不連続に戻る「継ぎ目」ができるのが正しい挙動)。
from/位置指定・複数カラーストップは非対応の簡略実装。
Sourcefn sample_repeating_colors(colors: &[Color], t: f32) -> u32
fn sample_repeating_colors(colors: &[Color], t: f32) -> u32
周期内の位置 t(0.0-1.0)における colors のN色均等割り補間色を得る。
colors が空/1色の場合は先頭色(無ければ黒)を返す。
Sourcepub fn draw_repeating_linear_gradient_rect(
&self,
x0: u32,
y0: u32,
x1: u32,
y1: u32,
colors: &[Color],
cycle_px: i32,
vertical: bool,
)
pub fn draw_repeating_linear_gradient_rect( &self, x0: u32, y0: u32, x1: u32, y1: u32, colors: &[Color], cycle_px: i32, vertical: bool, )
repeating-linear-gradient(c1, c2, ..., cycle_px) — cycle_px を周期として全色を
均等割りで補間しながら軸方向に繰り返す(draw_gradient_rect の周期版)。
以前は先頭2色 c1/c2 固定で3色目以降が失われていた。角度指定は引き続き非対応。
Sourcepub fn draw_repeating_radial_gradient_rect(
&self,
x0: u32,
y0: u32,
x1: u32,
y1: u32,
colors: &[Color],
cycle_px: i32,
)
pub fn draw_repeating_radial_gradient_rect( &self, x0: u32, y0: u32, x1: u32, y1: u32, colors: &[Color], cycle_px: i32, )
repeating-radial-gradient(c1, c2, ..., cycle_px) — 矩形中心からの距離を cycle_px
で割った余りを使い、同心円状に全色を均等割りで繰り返す。以前は先頭2色固定で
3色目以降が失われていた。形状/位置指定は引き続き非対応。
Sourcepub fn draw_shadow_rect(
&self,
x0: i32,
y0: i32,
x1: i32,
y1: i32,
ox: i32,
oy: i32,
color: Color,
)
pub fn draw_shadow_rect( &self, x0: i32, y0: i32, x1: i32, y1: i32, ox: i32, oy: i32, color: Color, )
Draw a semi-transparent shadow rectangle at offset (ox, oy).
Sourcepub fn draw_shadow_rect_rounded(
&self,
x0: i32,
y0: i32,
x1: i32,
y1: i32,
ox: i32,
oy: i32,
radius: (i32, i32, i32, i32),
color: Color,
)
pub fn draw_shadow_rect_rounded( &self, x0: i32, y0: i32, x1: i32, y1: i32, ox: i32, oy: i32, radius: (i32, i32, i32, i32), color: Color, )
Draw a semi-transparent shadow rectangle with optional rounded corners. 計算量: O(W×H) — W,H は影の矩形サイズ。半透明合成のため 1 ピクセルずつ処理する(定数倍が重い)。
Sourcepub fn draw_inset_shadow_rect(
&self,
x0: i32,
y0: i32,
x1: i32,
y1: i32,
ox: i32,
oy: i32,
blur: i32,
radius: (i32, i32, i32, i32),
color: Color,
)
pub fn draw_inset_shadow_rect( &self, x0: i32, y0: i32, x1: i32, y1: i32, ox: i32, oy: i32, blur: i32, radius: (i32, i32, i32, i32), color: Color, )
Draw a semi-transparent inset shadow rectangle inside (x0, y0, x1, y1).