:right-sidebar: True DrawContext =================================================================== .. currentmodule:: gi.repository.Gdk .. class:: DrawContext(**properties: ~typing.Any) :no-contents-entry: Superclasses: :class:`~gi.repository.GObject.Object` Subclasses: :class:`~gi.repository.Gdk.CairoContext`, :class:`~gi.repository.Gdk.GLContext`, :class:`~gi.repository.Gdk.VulkanContext` Base class for objects implementing different rendering methods. ``GdkDrawContext`` is the base object used by contexts implementing different rendering methods, such as :obj:`~gi.repository.Gdk.CairoContext` or :obj:`~gi.repository.Gdk.GLContext`\. It provides shared functionality between those contexts. You will always interact with one of those subclasses. A ``GdkDrawContext`` is always associated with a single toplevel surface. Methods ------- .. rst-class:: interim-class .. class:: DrawContext :no-index: .. method:: begin_frame(region: ~gi.repository.cairo.Region) -> None Indicates that you are beginning the process of redrawing ``region`` on the ``context``\'s surface. Calling this function begins a drawing operation using ``context`` on the surface that ``context`` was created from. The actual requirements and guarantees for the drawing operation vary for different implementations of drawing, so a :obj:`~gi.repository.Gdk.CairoContext` and a :obj:`~gi.repository.Gdk.GLContext` need to be treated differently. A call to this function is a requirement for drawing and must be followed by a call to :obj:`~gi.repository.Gdk.DrawContext.end_frame`\, which will complete the drawing operation and ensure the contents become visible on screen. Note that the ``region`` passed to this function is the minimum region that needs to be drawn and depending on implementation, windowing system and hardware in use, it might be necessary to draw a larger region. Drawing implementation must use :obj:`~gi.repository.Gdk.DrawContext.get_frame_region` to query the region that must be drawn. When using GTK, the widget system automatically places calls to :func:`~gi.repository.Gdk.DrawContext.begin_frame` and :func:`~gi.repository.Gdk.DrawContext.end_frame` via the use of `GskRenderer <../gsk4/class.Renderer.html>`__\s, so application code does not need to call these functions explicitly. .. deprecated:: 4.16 Drawing directly to the surface is no longer recommended. Use ``GskRenderNode`` and ``GskRenderer``\. :param region: minimum region that should be drawn .. method:: end_frame() -> None Ends a drawing operation started with :func:`~gi.repository.Gdk.DrawContext.begin_frame`. This makes the drawing available on screen. See :obj:`~gi.repository.Gdk.DrawContext.begin_frame` for more details about drawing. When using a :obj:`~gi.repository.Gdk.GLContext`\, this function may call ``glFlush()`` implicitly before returning; it is not recommended to call ``glFlush()`` explicitly before calling this function. .. deprecated:: 4.16 Drawing directly to the surface is no longer recommended. Use ``GskRenderNode`` and ``GskRenderer``\. .. method:: get_display() -> ~gi.repository.Gdk.Display | None Retrieves the ``GdkDisplay`` the ``context`` is created for .. method:: get_frame_region() -> ~gi.repository.cairo.Region | None Retrieves the region that is currently being repainted. After a call to :obj:`~gi.repository.Gdk.DrawContext.begin_frame` this function will return a union of the region passed to that function and the area of the surface that the ``context`` determined needs to be repainted. If ``context`` is not in between calls to :obj:`~gi.repository.Gdk.DrawContext.begin_frame` and :obj:`~gi.repository.Gdk.DrawContext.end_frame`\, :const:`None` will be returned. .. deprecated:: 4.16 Drawing directly to the surface is no longer recommended. Use ``GskRenderNode`` and ``GskRenderer``\. .. method:: get_surface() -> ~gi.repository.Gdk.Surface | None Retrieves the surface that ``context`` is bound to. .. method:: is_in_frame() -> bool Returns :const:`True` if ``context`` is in the process of drawing to its surface. This is the case between calls to :obj:`~gi.repository.Gdk.DrawContext.begin_frame` and :obj:`~gi.repository.Gdk.DrawContext.end_frame`\. In this situation, drawing commands may be effecting the contents of the ``context``\'s surface. .. deprecated:: 4.16 Drawing directly to the surface is no longer recommended. Use ``GskRenderNode`` and ``GskRenderer``\. Properties ---------- .. rst-class:: interim-class .. class:: DrawContext :no-index: .. attribute:: props.display :type: ~gi.repository.Gdk.Display The type of the None singleton. .. attribute:: props.surface :type: ~gi.repository.Gdk.Surface The type of the None singleton.