Expand description
Widget that hosts content rendered by an external GL producer.
Reserves layout space and, at draw time, samples a caller-provided GL
texture into the LTK canvas via Canvas::draw_external_texture. The
producer (a web engine, a video decoder, …) keeps ownership of the
texture and updates it on its own cadence; LTK only composites.
§Source closure contract
ExternalSource::Texture carries an
Arc<dyn Fn(&glow::Context, Rect) -> Option<glow::Texture>> that LTK
invokes once per frame, with its GLES context current. The producer:
- Reads
Rect(in physical pixels of the host surface) — useful for sizing the inner viewport (e.g. resizing aWPEToplevelto match) and for translating input coordinates byrect.origin. - May allocate / update GL textures against the supplied
glow::Context. - May bind extension-imported EGLImages onto a persistent texture.
- Returns the
glow::Textureto sample, orNoneto paint transparent (e.g. while the first frame is still being produced).
Returning None for one frame and Some for the next is fine; LTK
re-invokes on every redraw.
§Use cases
ltk-webkithosting aWPEView-rendered page.- Video / media playback widgets that decode into a GL texture.
- Any embedding that already has a GLES producer and wants its output in-line with the rest of the LTK widget tree.
§Example
let cached_texture: Arc<Mutex<Option<glow::Texture>>> = Arc::new( Mutex::new( None ) );
let cached = Arc::clone( &cached_texture );
External::new(
800.0, 600.0,
ExternalSource::Texture( Arc::new( move | _gl, _rect | -> Option<glow::Texture>
{
*cached.lock().ok()?
} ) ),
).into()Structs§
- A widget that defers its pixels to an external GL texture producer.
Enums§
- Backends an
Externalwidget can pull pixels from.