• Emmanuele Bassi's avatar
    cairo-texture: Use signal-based drawing · 2f445682
    Emmanuele Bassi authored
    The current "create context/draw/destroy context" pattern presents
    various problems. The first issue is that it defers memory management to
    the caller of the create() or create_region() methods, which makes
    bookkeeping of the cairo_t* harder for language bindings and third party
    libraries. The second issue is that, while it's easier for
    draw-and-forget texturs, this API is needlessly complicated for contents
    that have to change programmatically - and it introduces constraints
    like calling the drawing code explicitly after a surface resize (e.g.
    inside an allocate() implementation).
    By using a signal-based approach we can make the CairoTexture actor
    behave like other actors, and like other libraries using Cairo as their
    2D drawing API.
    The semantics of the newly-introduced ::draw signal are the same as the
    one used by GTK+:
      - the signal is emitted on invalidation;
      - the cairo_t* context is owned by the actor;
      - it is safe to have multiple callbacks attached to the same
        signal, to allow composition;
      - the cairo_t* is already clipped to the invalidated area, so
        that Cairo can discard geometry immediately before we upload
        the texture data.
    There are possible future improvements, like coalescing multiple
    invalidations inside regions, and performing clipped draws during
    the paint cycle; we could even perform clipped redraws if we know the
    extent of the invalidated area.
clutter-cairo-texture.h 5.74 KB