flame_barrage 0.0.7
flame_barrage: ^0.0.7 copied to clipboard
A high-performance barrage rendering engine powered by Flame.
đēđ¸ English | đ¨đŗ įŽäŊ䏿
đĨ FlameBarrage Engine
A High-Performance, Hardware-Accelerated Barrage Rendering Engine for Flutter
đŽ Live Demo #
Experience FlameBarrage directly in your browser:
đ Demo: https://liuchuancong.github.io/flame_barrage/
The online demo showcases:
- High-performance barrage rendering
- Dynamic configuration updates
- Native Emoji support
- Sprite atlas animation rendering
- Interactive barrage events
- Real-time performance testing
Powered by Flutter Web + Flame Engine.
đ Overview #
FlameBarrage Engine is a high-performance, hardware-accelerated barrage (danmaku) rendering engine built on top of the Flame graphics framework.
Designed for demanding real-time scenarios such as live streaming platforms, video comment overlays, esports broadcasts, and large-scale interactive applications, FlameBarrage bypasses the traditional widget-heavy rendering approach and leverages Flame's rendering pipeline to achieve exceptional performance under heavy concurrency.
With optimized memory management, object reuse, and a lightweight rendering architecture, the engine maintains stable frame rates and predictable memory behavior even when handling hundreds of simultaneous barrage items on modern high-refresh-rate devices (120Hz+).
đĨ Core Features #
⥠Batch Rendering Pipeline #
Instead of creating a widget for every barrage item, FlameBarrage decomposes text, emoji, and graphic assets into lightweight rendering fragments and submits them directly to the low-level canvas rendering layer.
Benefits
- Reduced Widget Tree overhead
- Minimal layout cost
- Lower rebuild frequency
- Better scalability under high message throughput
đŧī¸ Rasterized Barrage Bitmaps #
Each message is recorded once as a vector display list, then baked into a GPU-resident bitmap at device resolution (BarrageConfig.rasterizeItems, on by default). A display frame then draws one textured quad per visible message instead of replaying its text, outline, shadow and emoji operations â and a stroked glyph run is re-tessellated on the raster thread on every one of those replays, which is what makes a full screen of danmaku miss its deadline on TV-class hardware.
Measured on a 1080p scene with ~74 messages on screen (Windows / Impeller, per-frame raster time): p50 1.99 ms â 0.82 ms, p90 2.19 ms â 1.04 ms, VRAM cost 8.3 MB. A synthetic CPU-raster scene of 100 distinct CJK messages drops from 4.63 ms to 2.41 ms per frame.
- Bitmaps are reference counted, so a cache eviction never disposes something still on screen
- Bounded by
pictureCacheMaxSizeentries andrasterCacheMaxBytesof GPU memory - Repeated content ("666", welcome templates) shares a single bitmap across every instance
- Messages longer than 4096 device pixels, and platforms without picture rasterization, transparently keep the vector path
đ¨ Dual-Pass Typography Rendering #
Text outlines and fill colors are rendered independently to ensure visual consistency and eliminate common font cache issues.
Advantages
- No first-frame dark rendering artifacts
- No outline bleeding
- Reduced text flickering
- Improved rendering stability
âģī¸ Zero-Allocation Object Pool #
The built-in BarragePool reuses rendering components instead of continuously allocating and disposing objects.
Benefits
- Extremely low GC pressure
- Stable memory footprint
- Long-session reliability
- Predictable runtime performance
đ Dynamic Responsive Viewports #
Runtime configuration changes can be applied without clearing active barrages or rebuilding the rendering surface.
Supported dynamic properties:
fontSizetrackHeightareatopAreaDistancesafeAreaopacity
Changes take effect immediately and seamlessly.
đ¯ Stable Motion Scheduling #
A dedicated scheduler ensures smooth and predictable movement for all barrage items.
Features
- Constant scrolling speed
- Collision avoidance
- Safe spacing control
- Smooth visual flow
đ Enterprise-Grade Capabilities #
đ Precise Barrage Interaction #
Built on Flame's native input event system, every barrage item can participate in interaction handling.
Supported events:
onTapDownonTapUponLongTapDown- Custom gesture callbacks
Accurate interaction detection remains reliable even under hundreds of simultaneously moving barrage items.
đ Sprite Atlas Animation Support #
Supports both regular and irregular sprite atlases for efficient animated rendering.
Ideal for:
- Live-stream gifts
- Animated reactions
- Full-screen visual effects
- Event decorations
- Interactive rewards
đ Native Emoji Rendering #
Supports seamless inline rendering of system emojis together with normal text while preserving alignment and layout consistency.
đĻ Installation #
Add the following dependencies to your pubspec.yaml:
dependencies:
flame: ^1.37.0
flame_barrage: ^0.0.6
đ Quick Start #
Create a Controller #
final controller = BarrageController();
Mount the Barrage View #
FlameBarrageWidget(
controller: controller,
config: config,
emojiAtlas: EmojiAtlas.instance,
)
Send a Barrage #
controller.send(
BarrageItem(
content: 'Hello FlameBarrage!',
type: BarrageType.scroll,
),
);
Dynamic Configuration Updates #
controller.updateConfig(
config.copyWith(
fontSize: 24,
),
);
Configuration changes are applied instantly without interrupting active barrage rendering.
đģ Example #
import 'package:flutter/material.dart';
import 'package:flame_barrage/flame_barrage.dart';
class VideoPlayerView extends StatefulWidget {
const VideoPlayerView({super.key});
@override
State<VideoPlayerView> createState() => _VideoPlayerViewState();
}
class _VideoPlayerViewState extends State<VideoPlayerView> {
final BarrageController _controller = BarrageController();
final BarrageConfig _config = const BarrageConfig(
fontSize: 20,
baseSpeed: 150,
trackHeight: 44,
showStroke: true,
safeArea: true,
opacity: 0.8,
);
@override
void dispose() {
_controller.clear();
_controller.detach();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Stack(
children: [
Positioned.fill(
child: FlameBarrageWidget(
controller: _controller,
config: _config,
emojiAtlas: EmojiAtlas.instance,
),
),
],
);
}
}
đ§Š Extensible Fragment Architecture #
FlameBarrage exposes a fully extensible Fragment abstraction layer.
Developers can introduce custom rendering strategies without modifying the engine source code.
Examples include:
- SVG assets
- Network images
- Animated stickers
- Custom emoji packs
- Lottie animations
- Virtual gifts
- Business-specific visual components
Custom Fragment Example #
class CustomFragment extends Fragment {
@override
ui.Size computeSize(BarrageConfig config) {
return const ui.Size(40, 40);
}
@override
void paint(
ui.Canvas canvas,
ui.Offset offset,
ui.Size size,
BarrageConfig config,
) {
// custom rendering logic
}
}
đ Ideal Use Cases #
- Live Streaming Platforms
- Video Comment Overlays
- Esports Broadcasting
- Social Media Applications
- Virtual Gift Systems
- Real-Time Message Feeds
- Interactive Event Platforms
- In-Game Announcement Systems
đē TV & Low-End Device Tuning #
Android TV boxes and other weak SoCs usually have a modest GPU, a slow CPU, and a 60 Hz panel. A configuration that is comfortable on a phone can still stutter there, so tune these first:
| Setting | Recommendation | Why |
|---|---|---|
fps |
Set it to the panel's refresh rate (60 or 120) | The engine can never step more often than the display refreshes. Setting fps: 144 on a 60 Hz TV changes nothing â if frames still drop, the cost per frame is the problem, not the target rate. |
rasterizeItems |
true (default) |
Removes per-frame text, stroke and shadow rasterization. |
maxVisibleCount |
40â80 on a weak GPU | This is the number of bitmap blits per frame. |
showStroke |
Keep true if the text sits on bright video; disable if the bake cost itself shows up as a startup spike |
The outline is rasterized once per message rather than per frame, so it is no longer a per-frame cost. |
trackHeight / area |
A full screen of lanes only helps if the GPU can fill it | Fewer lanes means fewer messages on screen at once. |
pictureCacheMaxSize / rasterCacheMaxBytes |
Fit the bitmap budget to the device | Caps the GPU memory the cache may hold (rasterCacheBytes reports live usage). |
emitInterval |
0.1 for a calm stream, 0.02â0.05 for a busy one |
Paces how many new messages are shaped and baked per second. |
Calling controller.clear() (or disposing FlameBarrageWidget) stops the frame pulses entirely, so a paused room costs nothing.
đŦ Performance Philosophy #
FlameBarrage is engineered around four core principles:
- Minimize allocations
- Reduce framework overhead
- Maximize GPU utilization
- Rasterize each message once, not every frame
The result is a barrage engine capable of sustaining extremely high message throughput while maintaining smooth animations, stable frame pacing, and low memory pressure.
đ License #
Released under the MIT License.