# This file has been autogenerated by the pywayland scanner

# Copyright 2016 The Chromium Authors.
# Copyright 2017 Intel Corporation
# Copyright 2018 Collabora, Ltd
# Copyright 2021 Simon Ser
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice (including the next
# paragraph) shall be included in all copies or substantial portions of the
# Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.

from __future__ import annotations

import enum

from pywayland.protocol_core import Argument, ArgumentType, Global, Interface, Proxy, Resource

from .wayland import WlSurface
from .wayland import WlSurfaceProxy


class WpLinuxDrmSyncobjManagerV1(Interface):
    """Global for providing explicit synchronization

    This global is a factory interface, allowing clients to request explicit
    synchronization for buffers on a per-surface basis.

    See
    :class:`~pywayland.protocol.linux_drm_syncobj_v1.WpLinuxDrmSyncobjSurfaceV1`
    for more information.
    """

    name = "wp_linux_drm_syncobj_manager_v1"
    version = 1

    class error(enum.IntEnum):
        surface_exists = 0
        invalid_timeline = 1


class WpLinuxDrmSyncobjSurfaceV1(Interface):
    """Per-surface explicit synchronization

    This object is an add-on interface for
    :class:`~pywayland.protocol.wayland.WlSurface` to enable explicit
    synchronization.

    Each surface can be associated with only one object of this interface at
    any time.

    Explicit synchronization is guaranteed to be supported for buffers created
    with any version of the linux-dmabuf protocol. Compositors are free to
    support explicit synchronization for additional buffer types. If at surface
    commit time the attached buffer does not support explicit synchronization,
    an unsupported_buffer error is raised.

    As long as the :class:`WpLinuxDrmSyncobjSurfaceV1` object is alive, the
    compositor may ignore implicit synchronization for buffers attached and
    committed to the :class:`~pywayland.protocol.wayland.WlSurface`. The
    delivery of :func:`WlBuffer.release()
    <pywayland.protocol.wayland.WlBuffer.release>` events for buffers attached
    to the surface becomes undefined.

    Clients must set both acquire and release points if and only if a non-null
    buffer is attached in the same surface commit. See the no_buffer,
    no_acquire_point and no_release_point protocol errors.

    If at surface commit time the acquire and release DRM syncobj timelines are
    identical, the acquire point value must be strictly less than the release
    point value, or else the conflicting_points protocol error is raised.
    """

    name = "wp_linux_drm_syncobj_surface_v1"
    version = 1

    class error(enum.IntEnum):
        no_surface = 1
        unsupported_buffer = 2
        no_buffer = 3
        no_acquire_point = 4
        no_release_point = 5
        conflicting_points = 6


class WpLinuxDrmSyncobjTimelineV1(Interface):
    """Synchronization object timeline

    This object represents an explicit synchronization object timeline imported
    by the client to the compositor.
    """

    name = "wp_linux_drm_syncobj_timeline_v1"
    version = 1


class WpLinuxDrmSyncobjManagerV1Resource(Resource[WpLinuxDrmSyncobjManagerV1]):
    interface = WpLinuxDrmSyncobjManagerV1


class WpLinuxDrmSyncobjSurfaceV1Resource(Resource[WpLinuxDrmSyncobjSurfaceV1]):
    interface = WpLinuxDrmSyncobjSurfaceV1


class WpLinuxDrmSyncobjTimelineV1Resource(Resource[WpLinuxDrmSyncobjTimelineV1]):
    interface = WpLinuxDrmSyncobjTimelineV1


class WpLinuxDrmSyncobjManagerV1Proxy(Proxy[WpLinuxDrmSyncobjManagerV1]):
    interface = WpLinuxDrmSyncobjManagerV1

    @WpLinuxDrmSyncobjManagerV1.request()
    def destroy(self) -> None:
        """Destroy explicit synchronization factory object

        Destroy this explicit synchronization factory object. Other objects
        shall not be affected by this request.
        """
        self._marshal(0)
        self._destroy()

    @WpLinuxDrmSyncobjManagerV1.request(
        Argument(ArgumentType.NewId, interface=WpLinuxDrmSyncobjSurfaceV1),
        Argument(ArgumentType.Object, interface=WlSurface),
    )
    def get_surface(self, surface: WlSurfaceProxy) -> WpLinuxDrmSyncobjSurfaceV1Proxy:
        """Extend surface interface for explicit synchronization

        Instantiate an interface extension for the given
        :class:`~pywayland.protocol.wayland.WlSurface` to provide explicit
        synchronization.

        If the given :class:`~pywayland.protocol.wayland.WlSurface` already has
        an explicit synchronization object associated, the surface_exists
        protocol error is raised.

        Graphics APIs, like EGL or Vulkan, that manage the buffer queue and
        commits of a :class:`~pywayland.protocol.wayland.WlSurface` themselves,
        are likely to be using this extension internally. If a client is using
        such an API for a :class:`~pywayland.protocol.wayland.WlSurface`, it
        should not directly use this extension on that surface, to avoid
        raising a surface_exists protocol error.

        :param surface:
            the surface
        :type surface:
            :class:`~pywayland.protocol.wayland.WlSurface`
        :returns:
            :class:`~pywayland.protocol.linux_drm_syncobj_v1.WpLinuxDrmSyncobjSurfaceV1`
            -- the new synchronization surface object id
        """
        id = self._marshal_constructor(1, WpLinuxDrmSyncobjSurfaceV1, surface)
        return id

    @WpLinuxDrmSyncobjManagerV1.request(
        Argument(ArgumentType.NewId, interface=WpLinuxDrmSyncobjTimelineV1),
        Argument(ArgumentType.FileDescriptor),
    )
    def import_timeline(self, fd: int) -> WpLinuxDrmSyncobjTimelineV1Proxy:
        """Import a drm syncobj timeline

        Import a DRM synchronization object timeline.

        If the FD cannot be imported, the invalid_timeline error is raised.

        :param fd:
            drm_syncobj file descriptor
        :type fd:
            `ArgumentType.FileDescriptor`
        :returns:
            :class:`~pywayland.protocol.linux_drm_syncobj_v1.WpLinuxDrmSyncobjTimelineV1`
        """
        id = self._marshal_constructor(2, WpLinuxDrmSyncobjTimelineV1, fd)
        return id


class WpLinuxDrmSyncobjSurfaceV1Proxy(Proxy[WpLinuxDrmSyncobjSurfaceV1]):
    interface = WpLinuxDrmSyncobjSurfaceV1

    @WpLinuxDrmSyncobjSurfaceV1.request()
    def destroy(self) -> None:
        """Destroy the surface synchronization object

        Destroy this surface synchronization object.

        Any timeline point set by this object with set_acquire_point or
        set_release_point since the last commit may be discarded by the
        compositor. Any timeline point set by this object before the last
        commit will not be affected.
        """
        self._marshal(0)
        self._destroy()

    @WpLinuxDrmSyncobjSurfaceV1.request(
        Argument(ArgumentType.Object, interface=WpLinuxDrmSyncobjTimelineV1),
        Argument(ArgumentType.Uint),
        Argument(ArgumentType.Uint),
    )
    def set_acquire_point(self, timeline: WpLinuxDrmSyncobjTimelineV1Proxy, point_hi: int, point_lo: int) -> None:
        """Set the acquire timeline point

        Set the timeline point that must be signalled before the compositor may
        sample from the buffer attached with :func:`WlSurface.attach()
        <pywayland.protocol.wayland.WlSurface.attach>`.

        The 64-bit unsigned value combined from point_hi and point_lo is the
        point value.

        The acquire point is double-buffered state, and will be applied on the
        next :func:`WlSurface.commit()
        <pywayland.protocol.wayland.WlSurface.commit>` request for the
        associated surface. Thus, it applies only to the buffer that is
        attached to the surface at commit time.

        If an acquire point has already been attached during the same commit
        cycle, the new point replaces the old one.

        If the associated :class:`~pywayland.protocol.wayland.WlSurface` was
        destroyed, a no_surface error is raised.

        If at surface commit time there is a pending acquire timeline point set
        but no pending buffer attached, a no_buffer error is raised. If at
        surface commit time there is a pending buffer attached but no pending
        acquire timeline point set, the no_acquire_point protocol error is
        raised.

        :param timeline:
        :type timeline:
            :class:`~pywayland.protocol.linux_drm_syncobj_v1.WpLinuxDrmSyncobjTimelineV1`
        :param point_hi:
            high 32 bits of the point value
        :type point_hi:
            `ArgumentType.Uint`
        :param point_lo:
            low 32 bits of the point value
        :type point_lo:
            `ArgumentType.Uint`
        """
        self._marshal(1, timeline, point_hi, point_lo)

    @WpLinuxDrmSyncobjSurfaceV1.request(
        Argument(ArgumentType.Object, interface=WpLinuxDrmSyncobjTimelineV1),
        Argument(ArgumentType.Uint),
        Argument(ArgumentType.Uint),
    )
    def set_release_point(self, timeline: WpLinuxDrmSyncobjTimelineV1Proxy, point_hi: int, point_lo: int) -> None:
        """Set the release timeline point

        Set the timeline point that must be signalled by the compositor when it
        has finished its usage of the buffer attached with
        :func:`WlSurface.attach()
        <pywayland.protocol.wayland.WlSurface.attach>` for the relevant commit.

        Once the timeline point is signaled, and assuming the associated buffer
        is not pending release from other :func:`WlSurface.commit()
        <pywayland.protocol.wayland.WlSurface.commit>` requests, no additional
        explicit or implicit synchronization with the compositor is required to
        safely re-use the buffer.

        Note that clients cannot rely on the release point being always
        signaled after the acquire point: compositors may release buffers
        without ever reading from them. In addition, the compositor may use
        different presentation paths for different commits, which may have
        different release behavior. As a result, the compositor may signal the
        release points in a different order than the client committed them.

        Because signaling a timeline point also signals every previous point,
        it is generally not safe to use the same timeline object for the
        release points of multiple buffers. The out-of-order signaling
        described above may lead to a release point being signaled before the
        compositor has finished reading. To avoid this, it is strongly
        recommended that each buffer should use a separate timeline for its
        release points.

        The 64-bit unsigned value combined from point_hi and point_lo is the
        point value.

        The release point is double-buffered state, and will be applied on the
        next :func:`WlSurface.commit()
        <pywayland.protocol.wayland.WlSurface.commit>` request for the
        associated surface. Thus, it applies only to the buffer that is
        attached to the surface at commit time.

        If a release point has already been attached during the same commit
        cycle, the new point replaces the old one.

        If the associated :class:`~pywayland.protocol.wayland.WlSurface` was
        destroyed, a no_surface error is raised.

        If at surface commit time there is a pending release timeline point set
        but no pending buffer attached, a no_buffer error is raised. If at
        surface commit time there is a pending buffer attached but no pending
        release timeline point set, the no_release_point protocol error is
        raised.

        :param timeline:
        :type timeline:
            :class:`~pywayland.protocol.linux_drm_syncobj_v1.WpLinuxDrmSyncobjTimelineV1`
        :param point_hi:
            high 32 bits of the point value
        :type point_hi:
            `ArgumentType.Uint`
        :param point_lo:
            low 32 bits of the point value
        :type point_lo:
            `ArgumentType.Uint`
        """
        self._marshal(2, timeline, point_hi, point_lo)


class WpLinuxDrmSyncobjTimelineV1Proxy(Proxy[WpLinuxDrmSyncobjTimelineV1]):
    interface = WpLinuxDrmSyncobjTimelineV1

    @WpLinuxDrmSyncobjTimelineV1.request()
    def destroy(self) -> None:
        """Destroy the timeline

        Destroy the synchronization object timeline. Other objects are not
        affected by this request, in particular timeline points set by
        set_acquire_point and set_release_point are not unset.
        """
        self._marshal(0)
        self._destroy()


class WpLinuxDrmSyncobjManagerV1Global(Global[WpLinuxDrmSyncobjManagerV1]):
    interface = WpLinuxDrmSyncobjManagerV1


class WpLinuxDrmSyncobjSurfaceV1Global(Global[WpLinuxDrmSyncobjSurfaceV1]):
    interface = WpLinuxDrmSyncobjSurfaceV1


class WpLinuxDrmSyncobjTimelineV1Global(Global[WpLinuxDrmSyncobjTimelineV1]):
    interface = WpLinuxDrmSyncobjTimelineV1


WpLinuxDrmSyncobjManagerV1._gen_c()
WpLinuxDrmSyncobjManagerV1.proxy_class = WpLinuxDrmSyncobjManagerV1Proxy
WpLinuxDrmSyncobjManagerV1.resource_class = WpLinuxDrmSyncobjManagerV1Resource
WpLinuxDrmSyncobjManagerV1.global_class = WpLinuxDrmSyncobjManagerV1Global


WpLinuxDrmSyncobjSurfaceV1._gen_c()
WpLinuxDrmSyncobjSurfaceV1.proxy_class = WpLinuxDrmSyncobjSurfaceV1Proxy
WpLinuxDrmSyncobjSurfaceV1.resource_class = WpLinuxDrmSyncobjSurfaceV1Resource
WpLinuxDrmSyncobjSurfaceV1.global_class = WpLinuxDrmSyncobjSurfaceV1Global


WpLinuxDrmSyncobjTimelineV1._gen_c()
WpLinuxDrmSyncobjTimelineV1.proxy_class = WpLinuxDrmSyncobjTimelineV1Proxy
WpLinuxDrmSyncobjTimelineV1.resource_class = WpLinuxDrmSyncobjTimelineV1Resource
WpLinuxDrmSyncobjTimelineV1.global_class = WpLinuxDrmSyncobjTimelineV1Global
