Skip to main content

euv_core/render/pipeline/
impl.rs

1use super::*;
2
3/// Fluent builder helpers for `FrameRenderParams`.
4impl FrameRenderParams {
5    /// Creates frame render parameters for `viewport` with `1.0` scale, white clear color, and full damage.
6    ///
7    /// # Arguments
8    ///
9    /// - `Size` - Logical viewport size.
10    ///
11    /// # Returns
12    ///
13    /// - `Self` - Ready render parameters.
14    #[must_use]
15    pub fn new(viewport: Size) -> Self {
16        Self {
17            viewport,
18            scale_factor: 1.0,
19            clear_color: COLOR_WHITE,
20            layout_stats: LayoutStats::default(),
21            damage: DamageRegion::full(),
22        }
23    }
24
25    /// Sets the active DPI scale factor.
26    ///
27    /// # Arguments
28    ///
29    /// - `Self` - Base parameters.
30    /// - `f32` - Scale factor.
31    ///
32    /// # Returns
33    ///
34    /// - `Self` - Updated parameters.
35    #[must_use]
36    pub fn with_scale(mut self, scale_factor: f32) -> Self {
37        self.set_scale_factor(scale_factor.max(0.5));
38        self
39    }
40
41    /// Sets the surface clear color.
42    ///
43    /// # Arguments
44    ///
45    /// - `Self` - Base parameters.
46    /// - `Color` - Clear color.
47    ///
48    /// # Returns
49    ///
50    /// - `Self` - Updated parameters.
51    #[must_use]
52    pub fn with_clear(mut self, clear_color: Color) -> Self {
53        self.set_clear_color(clear_color);
54        self
55    }
56
57    /// Attaches layout telemetry from the current frame.
58    ///
59    /// # Arguments
60    ///
61    /// - `Self` - Base parameters.
62    /// - `LayoutStats` - Layout pass statistics.
63    ///
64    /// # Returns
65    ///
66    /// - `Self` - Updated parameters.
67    #[must_use]
68    pub fn with_layout_stats(mut self, layout_stats: LayoutStats) -> Self {
69        self.set_layout_stats(layout_stats);
70        self
71    }
72
73    /// Sets the active dirty damage region.
74    ///
75    /// # Arguments
76    ///
77    /// - `Self` - Base parameters.
78    /// - `DamageRegion` - Damage region.
79    ///
80    /// # Returns
81    ///
82    /// - `Self` - Updated parameters.
83    #[must_use]
84    pub fn with_damage(mut self, damage: DamageRegion) -> Self {
85        self.set_damage(damage);
86        self
87    }
88}
89
90/// Multi-mode pipeline construction, live mode switching, and frame rendering for `Renderer`.
91impl Renderer {
92    /// Creates a `Renderer` resolving the optimal backend for `platform` and `config`.
93    ///
94    /// # Arguments
95    ///
96    /// - `PlatformKind` - Active execution platform.
97    /// - `PlatformCapabilities` - Hardware capabilities reported by the platform backend.
98    /// - `u32` - Initial physical width.
99    /// - `u32` - Initial physical height.
100    /// - `RenderConfig` - Requested rendering configuration.
101    ///
102    /// # Returns
103    ///
104    /// - `Self` - Initialized multi-mode renderer facade.
105    #[must_use]
106    pub fn new(
107        platform: PlatformKind,
108        capabilities: PlatformCapabilities,
109        width: u32,
110        height: u32,
111        config: RenderConfig,
112    ) -> Self {
113        let (active_mode, active_backend): (RenderMode, GraphicsBackend) =
114            Self::resolve_mode_and_backend(platform, capabilities, config);
115        let readback_mirror: bool = !config.get_direct_gpu_present();
116        let compute_pixel_hash: bool =
117            platform == PlatformKind::Headless || active_backend == GraphicsBackend::Headless;
118        let font_provider: NativeSystemFont = if platform == PlatformKind::Headless {
119            NativeSystemFont::deterministic()
120        } else {
121            NativeSystemFont::system()
122        };
123        let mut display_list: DisplayList = DisplayList::default();
124        display_list.get_mut_commands().reserve(128);
125        let (sw_w, sw_h): (u32, u32) = if active_mode == RenderMode::Software {
126            (width, height)
127        } else {
128            (1, 1)
129        };
130        let (hw_w, hw_h, hw_backend): (u32, u32, GraphicsBackend) =
131            if matches!(active_mode, RenderMode::Hardware | RenderMode::Auto) {
132                (width, height, active_backend)
133            } else {
134                (1, 1, GraphicsBackend::Headless)
135            };
136        let (hy_w, hy_h): (u32, u32) = if active_mode == RenderMode::Hybrid {
137            (width, height)
138        } else {
139            (1, 1)
140        };
141        let semantics: RenderSemanticsContract =
142            RenderSemanticsContract::from_render_config(config, 1.0);
143        Self {
144            config,
145            active_mode,
146            active_backend,
147            software: SoftwareRenderer::with_font_provider(
148                sw_w,
149                sw_h,
150                config,
151                font_provider.clone(),
152            ),
153            hardware: HardwareRenderer::with_backend_and_font(
154                hw_backend,
155                hw_w,
156                hw_h,
157                config,
158                readback_mirror,
159                font_provider.clone(),
160            ),
161            hybrid: HybridRenderer::with_backend_and_font(
162                active_backend,
163                hy_w,
164                hy_h,
165                config,
166                font_provider,
167            ),
168            paint_pass: PaintPass,
169            paint_fragment_cache: PaintFragmentCache::default(),
170            display_list,
171            frame_index: 0,
172            compute_pixel_hash,
173            last_hashed_mode: None,
174            last_hashed_dims: (0, 0),
175            last_stats: FrameStats::default(),
176            fallback_policy: FallbackPolicyEngine::with_display_hz(60.0, semantics),
177            composite_fast_path_frames: 0,
178            cpu_fallback_frames: 0,
179        }
180    }
181
182    /// Enables or disables direct GPU rendering without steady-state CPU RGBA readback mirroring.
183    ///
184    /// # Arguments
185    ///
186    /// - `&Self` - Mutable renderer.
187    /// - `bool` - `true` for GPU direct-draw (zero CPU RGBA mirror); `false` to enable software readback mirror.
188    pub fn set_direct_gpu_present(&mut self, enabled: bool) {
189        let mut cfg: RenderConfig = self.get_config();
190        cfg.set_direct_gpu_present(enabled);
191        self.set_config(cfg);
192        let Self {
193            hardware,
194            last_hashed_mode,
195            ..
196        } = self;
197        hardware.set_enable_readback(!enabled);
198        *last_hashed_mode = None;
199    }
200
201    /// Captures the active visual semantics contract verifying zero quality degradation across fallback transitions.
202    ///
203    /// # Arguments
204    ///
205    /// - `&Self` - Renderer reference.
206    /// - `f32` - Active display scale factor.
207    ///
208    /// # Returns
209    ///
210    /// - `RenderSemanticsContract` - Immutable visual fidelity snapshot.
211    #[must_use]
212    pub fn semantics_contract(&self, scale_factor: f32) -> RenderSemanticsContract {
213        RenderSemanticsContract::from_render_config(self.get_config(), scale_factor)
214    }
215
216    /// Captures an on-demand CPU reference framebuffer for pixel-parity verification even while direct GPU draw is enabled.
217    ///
218    /// # Arguments
219    ///
220    /// - `&Self` - Mutable renderer.
221    /// - `DamageRegion` - Damage region to rasterize into the reference framebuffer.
222    ///
223    /// # Returns
224    ///
225    /// - `&Framebuffer` - Rendered full-fidelity CPU reference RGBA8 framebuffer.
226    pub fn capture_reference_framebuffer(&mut self, damage: DamageRegion) -> &Framebuffer {
227        let Self {
228            active_mode,
229            software,
230            hardware,
231            hybrid,
232            display_list,
233            ..
234        } = self;
235        match *active_mode {
236            RenderMode::Software => {
237                let (_, _): (usize, usize) = software.render(display_list, damage);
238                software.get_framebuffer()
239            }
240            RenderMode::Hybrid => hybrid.get_software().get_framebuffer(),
241            RenderMode::Hardware | RenderMode::Auto => {
242                hardware.capture_reference_readback(display_list, damage)
243            }
244        }
245    }
246
247    /// Evaluates `trigger` through `FallbackPolicyEngine` and applies strictly non-degrading cache trimming or CPU reference switching.
248    ///
249    /// # Arguments
250    ///
251    /// - `&Self` - Mutable renderer.
252    /// - `FallbackTrigger` - Runtime pressure, frame overrun, or GPU fault trigger.
253    /// - `u64` - Monotonic clock timestamp in milliseconds.
254    ///
255    /// # Returns
256    ///
257    /// - `FallbackAction` - Strictly non-degrading action applied.
258    pub fn apply_fallback_trigger(
259        &mut self,
260        trigger: FallbackTrigger,
261        now_ms: u64,
262    ) -> FallbackAction {
263        let action: FallbackAction = self
264            .get_mut_fallback_policy()
265            .evaluate_trigger(trigger, now_ms);
266        match action {
267            FallbackAction::TrimPrefetchAndColdCache { retain_ratio } => {
268                let Self {
269                    software,
270                    hardware,
271                    paint_fragment_cache,
272                    ..
273                } = self;
274                let _: usize = hardware.trim_gpu_caches(retain_ratio);
275                let budget: usize =
276                    ((GLYPH_ATLAS_DEFAULT_BUDGET_BYTES as f32) * retain_ratio.clamp(0.1, 1.0))
277                        .round()
278                        .max(GLYPH_ATLAS_MIN_BUDGET_BYTES as f32) as usize;
279                software.get_mut_glyph_atlas().set_memory_budget(budget);
280                hardware
281                    .get_mut_readback()
282                    .get_mut_glyph_atlas()
283                    .set_memory_budget(budget);
284                if retain_ratio <= FALLBACK_CRITICAL_RETAIN_RATIO + 0.01 {
285                    paint_fragment_cache.clear();
286                }
287            }
288            FallbackAction::SwitchToCpuReference { .. } => {
289                let mut next_cfg: RenderConfig = self.get_config();
290                next_cfg.set_mode(RenderMode::Software);
291                self.set_config(next_cfg);
292                self.set_active_mode(RenderMode::Software);
293                self.set_active_backend(GraphicsBackend::SoftwareCpu);
294                let Self {
295                    last_hashed_mode, ..
296                } = self;
297                *last_hashed_mode = None;
298            }
299            FallbackAction::None
300            | FallbackAction::AdjustPresentCadence { .. }
301            | FallbackAction::RouteLayerToCpuReference => {}
302        }
303        action
304    }
305
306    /// Resolves `(RenderMode, GraphicsBackend)` deterministically from platform capabilities and user preference.
307    ///
308    /// # Arguments
309    ///
310    /// - `PlatformKind` - Target platform.
311    /// - `PlatformCapabilities` - Hardware support flags.
312    /// - `RenderConfig` - User configuration.
313    ///
314    /// # Returns
315    ///
316    /// - `(RenderMode, GraphicsBackend)` - Concrete resolved mode and backend.
317    #[must_use]
318    pub fn resolve_mode_and_backend(
319        platform: PlatformKind,
320        capabilities: PlatformCapabilities,
321        config: RenderConfig,
322    ) -> (RenderMode, GraphicsBackend) {
323        let default_gpu: GraphicsBackend = platform.default_graphics_backend();
324        let mode: RenderMode = match config.get_mode() {
325            RenderMode::Auto => {
326                if capabilities.get_hardware_gpu() {
327                    RenderMode::Hardware
328                } else {
329                    RenderMode::Software
330                }
331            }
332            explicit => explicit,
333        };
334        let backend: GraphicsBackend = match mode {
335            RenderMode::Software => match platform {
336                PlatformKind::Web | PlatformKind::MiniApp | PlatformKind::QuickApp => {
337                    GraphicsBackend::Canvas2d
338                }
339                _ => GraphicsBackend::SoftwareCpu,
340            },
341            RenderMode::Hardware | RenderMode::Hybrid => {
342                config.preferred_backend_value().unwrap_or(default_gpu)
343            }
344            RenderMode::Auto => default_gpu,
345        };
346        (mode, backend)
347    }
348
349    /// Dynamically switches the active rendering mode at runtime without rebuilding the scene tree.
350    ///
351    /// # Arguments
352    ///
353    /// - `&Self` - Mutable renderer.
354    /// - `PlatformKind` - Active platform kind.
355    /// - `PlatformCapabilities` - Platform hardware capabilities.
356    /// - `RenderMode` - Target render mode.
357    pub fn switch_mode(
358        &mut self,
359        platform: PlatformKind,
360        capabilities: PlatformCapabilities,
361        mode: RenderMode,
362    ) {
363        let mut next_cfg: RenderConfig = self.get_config();
364        next_cfg.set_mode(mode);
365        let (resolved_mode, resolved_backend): (RenderMode, GraphicsBackend) =
366            Self::resolve_mode_and_backend(platform, capabilities, next_cfg);
367        self.set_config(next_cfg);
368        self.set_active_mode(resolved_mode);
369        self.set_active_backend(resolved_backend);
370        let Self {
371            hardware,
372            hybrid,
373            last_hashed_mode,
374            ..
375        } = self;
376        *last_hashed_mode = None;
377        hardware.get_mut_driver().switch_backend(resolved_backend);
378        hybrid
379            .get_mut_compositor()
380            .set_backend_kind(resolved_backend);
381    }
382
383    /// Compiles `tree` into a `DisplayList`, executes the active render backend, and returns `FrameStats`.
384    ///
385    /// # Arguments
386    ///
387    /// - `&Self` - Mutable renderer.
388    /// - `&SceneTree` - Laid-out scene tree.
389    /// - `Size` - Logical viewport dimensions.
390    /// - `f32` - Active DPI scale factor.
391    /// - `Color` - Surface clear color.
392    /// - `LayoutStats` - Telemetry from the layout pass.
393    /// - `DamageRegion` - Damaged screen region.
394    ///
395    /// # Returns
396    ///
397    /// - `Result<FrameStats, PlatformError>` - Frame performance and pixel-hash telemetry.
398    pub fn render_frame(
399        &mut self,
400        tree: &SceneTree,
401        viewport: Size,
402        scale_factor: f32,
403        clear_color: Color,
404        layout_stats: LayoutStats,
405        damage: DamageRegion,
406    ) -> Result<FrameStats, PlatformError> {
407        let params: FrameRenderParams = FrameRenderParams::new(viewport)
408            .with_scale(scale_factor)
409            .with_clear(clear_color)
410            .with_layout_stats(layout_stats)
411            .with_damage(damage);
412        self.render_frame_composite_aware(tree, &params, false)
413    }
414
415    /// Compiles `tree` into a `DisplayList`, honoring composite-only fast paths and non-degrading CPU reference fallback on unsupported GPU effects.
416    ///
417    /// # Arguments
418    ///
419    /// - `&Self` - Mutable renderer.
420    /// - `&SceneTree` - Laid-out scene tree.
421    /// - `&FrameRenderParams` - Viewport, DPI, clear color, layout stats, and damage bundle.
422    /// - `bool` - Whether only composite/scroll properties changed with zero layout or paint mutations.
423    ///
424    /// # Returns
425    ///
426    /// - `Result<FrameStats, PlatformError>` - Frame performance, direct-draw, fallback, and pixel-hash telemetry.
427    pub fn render_frame_composite_aware(
428        &mut self,
429        tree: &SceneTree,
430        params: &FrameRenderParams,
431        composite_only: bool,
432    ) -> Result<FrameStats, PlatformError> {
433        let viewport: Size = params.get_viewport();
434        let scale: f32 = params.get_scale_factor().max(0.5);
435        let clear_color: Color = params.get_clear_color();
436        let layout_stats: LayoutStats = params.get_layout_stats();
437        let damage: DamageRegion = params.get_damage();
438        let phys_w: u32 = ((viewport.get_width() * scale).round() as u32).max(1);
439        let phys_h: u32 = ((viewport.get_height() * scale).round() as u32).max(1);
440        let phys_dims: (u32, u32) = (phys_w, phys_h);
441        let Self {
442            active_mode,
443            active_backend,
444            software,
445            hardware,
446            hybrid,
447            paint_pass,
448            paint_fragment_cache,
449            display_list,
450            frame_index,
451            compute_pixel_hash,
452            last_hashed_mode,
453            last_hashed_dims,
454            last_stats,
455            fallback_policy,
456            composite_fast_path_frames,
457            cpu_fallback_frames,
458            ..
459        } = self;
460        let mode: RenderMode = *active_mode;
461        let backend: GraphicsBackend = *active_backend;
462        let do_pixel_hash: bool = *compute_pixel_hash;
463        let hash_reusable: bool = *last_hashed_mode == Some(mode) && *last_hashed_dims == phys_dims;
464        if !damage.get_full_damage() && damage.bounds_rect().is_none() && hash_reusable {
465            *frame_index = frame_index.wrapping_add(1);
466            let stats: FrameStats = FrameStats {
467                frame_index: *frame_index,
468                active_mode: mode,
469                active_backend: backend,
470                layout_nodes: layout_stats.get_nodes_computed(),
471                layout_skipped: layout_stats.get_subtrees_skipped(),
472                draw_commands: 0,
473                draw_batches: 0,
474                pixels_shaded: 0,
475                frame_hash: last_stats.get_frame_hash(),
476                composite_only: false,
477                gpu_direct_draw: false,
478                cpu_rgba_upload_bytes: 0,
479                submit_outcome: FrameSubmitOutcome::SkippedNoDamage,
480            };
481            *last_stats = stats;
482            return Ok(stats);
483        }
484        let _: &PaintPass = paint_pass;
485        let layout_changed: bool = layout_stats.get_nodes_computed() > 0;
486        let took_composite_fast_path: bool = composite_only && !layout_changed;
487        if took_composite_fast_path {
488            *composite_fast_path_frames = composite_fast_path_frames.saturating_add(1);
489        }
490        PaintPass::build_retained(
491            tree,
492            viewport,
493            scale,
494            clear_color,
495            layout_changed,
496            display_list,
497            paint_fragment_cache,
498        );
499        let cmd_count: usize = display_list.len();
500        let mut gpu_direct_draw: bool = false;
501        let cpu_rgba_upload_bytes: usize;
502        let mut effective_mode: RenderMode = mode;
503        let mut effective_backend: GraphicsBackend = backend;
504        let (batches, pixels, hash): (usize, usize, u64) = match mode {
505            RenderMode::Software => {
506                let (b, p): (usize, usize) = software.render(display_list, damage);
507                cpu_rgba_upload_bytes = (phys_w as usize)
508                    .saturating_mul(phys_h as usize)
509                    .saturating_mul(4);
510                let h: u64 = if p == 0 && hash_reusable {
511                    last_stats.get_frame_hash()
512                } else if do_pixel_hash {
513                    software.get_framebuffer().fnv1a_hash()
514                } else {
515                    display_list.fast_hash()
516                };
517                (b, p, h)
518            }
519            RenderMode::Hybrid => {
520                let (b, p): (usize, usize) = hybrid.render(display_list, damage)?;
521                cpu_rgba_upload_bytes = (phys_w as usize)
522                    .saturating_mul(phys_h as usize)
523                    .saturating_mul(4);
524                let h: u64 = if p == 0 && hash_reusable {
525                    last_stats.get_frame_hash()
526                } else if do_pixel_hash {
527                    hybrid.get_software().get_framebuffer().fnv1a_hash()
528                } else {
529                    display_list.fast_hash()
530                };
531                (b, p, h)
532            }
533            RenderMode::Hardware | RenderMode::Auto => {
534                match hardware.render(display_list, damage) {
535                    Ok((b, p)) => {
536                        if hardware.get_has_unsupported_effect() {
537                            let _: FallbackAction = fallback_policy.evaluate_trigger(
538                                FallbackTrigger::MissingGpuEffectPath { isolatable: false },
539                                0,
540                            );
541                            *cpu_fallback_frames = cpu_fallback_frames.saturating_add(1);
542                            let (sb, sp): (usize, usize) = software.render(display_list, damage);
543                            effective_mode = RenderMode::Software;
544                            effective_backend = GraphicsBackend::SoftwareCpu;
545                            cpu_rgba_upload_bytes = (phys_w as usize)
546                                .saturating_mul(phys_h as usize)
547                                .saturating_mul(4);
548                            let h: u64 = if do_pixel_hash {
549                                software.get_framebuffer().fnv1a_hash()
550                            } else {
551                                display_list.fast_hash()
552                            };
553                            (sb, sp, h)
554                        } else {
555                            gpu_direct_draw = !hardware.get_enable_readback();
556                            cpu_rgba_upload_bytes = hardware.get_last_cpu_rgba_upload_bytes();
557                            let h: u64 = if p == 0 && hash_reusable {
558                                last_stats.get_frame_hash()
559                            } else if hardware.get_enable_readback() {
560                                if do_pixel_hash {
561                                    hardware.get_readback().get_framebuffer().fnv1a_hash()
562                                } else {
563                                    display_list.fast_hash()
564                                }
565                            } else {
566                                hardware.batch_hash()
567                            };
568                            (b, p, h)
569                        }
570                    }
571                    Err(_) => {
572                        let _: FallbackAction =
573                            fallback_policy.evaluate_trigger(FallbackTrigger::DeviceLost, 0);
574                        *cpu_fallback_frames = cpu_fallback_frames.saturating_add(1);
575                        let (sb, sp): (usize, usize) = software.render(display_list, damage);
576                        effective_mode = RenderMode::Software;
577                        effective_backend = GraphicsBackend::SoftwareCpu;
578                        cpu_rgba_upload_bytes = (phys_w as usize)
579                            .saturating_mul(phys_h as usize)
580                            .saturating_mul(4);
581                        let h: u64 = if do_pixel_hash {
582                            software.get_framebuffer().fnv1a_hash()
583                        } else {
584                            display_list.fast_hash()
585                        };
586                        (sb, sp, h)
587                    }
588                }
589            }
590        };
591        *last_hashed_mode = Some(effective_mode);
592        *last_hashed_dims = phys_dims;
593        *frame_index = frame_index.wrapping_add(1);
594        let stats: FrameStats = FrameStats {
595            frame_index: *frame_index,
596            active_mode: effective_mode,
597            active_backend: effective_backend,
598            layout_nodes: layout_stats.get_nodes_computed(),
599            layout_skipped: layout_stats.get_subtrees_skipped(),
600            draw_commands: cmd_count,
601            draw_batches: batches,
602            pixels_shaded: pixels,
603            frame_hash: hash,
604            composite_only: took_composite_fast_path,
605            gpu_direct_draw,
606            cpu_rgba_upload_bytes,
607            submit_outcome: FrameSubmitOutcome::Submitted,
608        };
609        *last_stats = stats;
610        Ok(stats)
611    }
612
613    /// Renders `tree` using a compact `FrameRenderParams` descriptor and returns `FrameStats`.
614    ///
615    /// # Arguments
616    ///
617    /// - `&Self` - Mutable renderer.
618    /// - `&SceneTree` - Laid-out scene tree.
619    /// - `&FrameRenderParams` - Viewport, DPI, clear color, layout stats, and damage bundle.
620    ///
621    /// # Returns
622    ///
623    /// - `Result<FrameStats, PlatformError>` - Frame performance and pixel-hash telemetry.
624    #[inline(always)]
625    pub fn render_with(
626        &mut self,
627        tree: &SceneTree,
628        params: &FrameRenderParams,
629    ) -> Result<FrameStats, PlatformError> {
630        self.render_frame(
631            tree,
632            params.get_viewport(),
633            params.get_scale_factor(),
634            params.get_clear_color(),
635            params.get_layout_stats(),
636            params.get_damage(),
637        )
638    }
639
640    /// Advances the frame counter for an undamaged idle frame without rasterizing or hashing pixels.
641    ///
642    /// # Arguments
643    ///
644    /// - `&Self` - Mutable renderer.
645    ///
646    /// # Returns
647    ///
648    /// - `FrameStats` - Lightweight telemetry preserving the last rendered `frame_hash` with zero shaded pixels.
649    pub fn record_skipped_frame(&mut self) -> FrameStats {
650        let next_idx: u64 = self.get_frame_index().wrapping_add(1);
651        self.set_frame_index(next_idx);
652        let mut stats: FrameStats = self.get_last_stats();
653        stats.set_frame_index(next_idx);
654        stats.set_layout_nodes(0);
655        stats.set_draw_batches(0);
656        stats.set_pixels_shaded(0);
657        stats.set_composite_only(false);
658        stats.set_gpu_direct_draw(false);
659        stats.set_cpu_rgba_upload_bytes(0);
660        stats.set_submit_outcome(FrameSubmitOutcome::SkippedNoDamage);
661        self.set_last_stats(stats);
662        stats
663    }
664
665    /// Returns cumulative cross-frame `PaintFragmentCache` telemetry `(whole_list_hits, fragment_hits, fragment_misses, fragment_evictions)`.
666    ///
667    /// # Arguments
668    ///
669    /// - `&Self` - Renderer reference.
670    ///
671    /// # Returns
672    ///
673    /// - `(u64, u64, u64, u64)` - Tuple of whole-list hits, fragment hits, misses, and evictions.
674    #[must_use]
675    pub fn paint_fragment_cache_stats(&self) -> (u64, u64, u64, u64) {
676        self.get_paint_fragment_cache().stats()
677    }
678
679    /// Returns a reference to the latest CPU-accessible `Framebuffer` for software/hybrid/readback presentation.
680    ///
681    /// # Arguments
682    ///
683    /// - `&Self` - Renderer reference.
684    ///
685    /// # Returns
686    ///
687    /// - `Option<&Framebuffer>` - Active RGBA8 framebuffer if available in host memory.
688    #[must_use]
689    pub fn framebuffer(&self) -> Option<&Framebuffer> {
690        match self.get_active_mode() {
691            RenderMode::Software => Some(self.get_software().get_framebuffer()),
692            RenderMode::Hybrid => Some(self.get_hybrid().get_software().get_framebuffer()),
693            RenderMode::Hardware | RenderMode::Auto => {
694                if self.get_hardware().get_enable_readback() {
695                    Some(self.get_hardware().get_readback().get_framebuffer())
696                } else {
697                    None
698                }
699            }
700        }
701    }
702}