# -*- coding: utf-8 -*-
# This file has been autogenerated by the pywayland scanner

# Copyright © 2014, 2015 Collabora, Ltd.
#
# Permission to use, copy, modify, distribute, and sell this
# software and its documentation for any purpose is hereby granted
# without fee, provided that the above copyright notice appear in
# all copies and that both that copyright notice and this permission
# notice appear in supporting documentation, and that the name of
# the copyright holders not be used in advertising or publicity
# pertaining to distribution of the software without specific,
# written prior permission.  The copyright holders make no
# representations about the suitability of this software for any
# purpose.  It is provided "as is" without express or implied
# warranty.
#
# THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
# SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
# FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
# SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
# AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
# ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
# THIS SOFTWARE.

from pywayland.interface import Interface
from .linuxbufferparamsv1 import LinuxBufferParamsV1


class LinuxDmabufV1(Interface):
    """Factory for creating dmabuf-based :class:`~pywayland.protocol.wayland.buffers.Buffers`

    Following the interfaces from: https://www.khronos.org/registry/egl/extensi
    ons/EXT/EGL_EXT_image_dma_buf_import.txt and the Linux DRM sub-system's
    AddFb2 ioctl.

    This interface offers a way to create generic dmabuf-based
    :class:`~pywayland.protocol.wayland.buffers.Buffers`. Immediately after a
    client binds to this interface, the set of supported formats is sent with
    'format' events.

    The following are required from clients:

    - Clients must ensure that either all data in the dma-buf is coherent for
      all subsequent read access or that coherency is correctly handled by the
      underlying kernel-side dma-buf implementation.

    - Don't make any more attachments after sending the buffer to the
      compositor. Making more attachments later increases the risk of the
      compositor not being able to use (re-import) an existing dmabuf-based
      :class:`~pywayland.protocol.wayland.buffer.Buffer`.

    The underlying graphics stack must ensure the following:

    - The dmabuf file descriptors relayed to the server will stay valid for the
      whole lifetime of the :class:`~pywayland.protocol.wayland.buffer.Buffer`.
      This means the server may at any time use those fds to import the dmabuf
      into any kernel sub-system that might accept it.

    To create a :class:`~pywayland.protocol.wayland.buffer.Buffer` from one or
    more dmabufs, a client creates a zwp_linux_dmabuf_params_v1 object with
    zwp_linux_dmabuf_v1.create_params request. All planes required by the
    intended format are added with the 'add' request. Finally, 'create' request
    is issued. The server will reply with either 'created' event which provides
    the final :class:`~pywayland.protocol.wayland.buffer.Buffer` or 'failed'
    event saying that it cannot use the dmabufs provided.

    Warning! The protocol described in this file is experimental and backward
    incompatible changes may be made. Backward compatible changes may be added
    together with the corresponding interface version bump. Backward
    incompatible changes are done by bumping the version number in the protocol
    and interface names and resetting the interface version. Once the protocol
    is to be declared stable, the 'z' prefix and the version number in the
    protocol and interface names are removed and the interface version number
    is reset.
    """
    name = "zwp_linux_dmabuf_v1"
    version = 1


@LinuxDmabufV1.request("", [])
def destroy(self):
    """Unbind the factory

    Objects created through this interface, especially
    :class:`~pywayland.protocol.wayland.buffers.Buffers`, will remain valid.
    """
    self._marshal(0)
    self._destroy()


@LinuxDmabufV1.request("n", [LinuxBufferParamsV1])
def create_params(self):
    """Create a temporary object for buffer parameters

    This temporary object is used to collect multiple dmabuf handles into a
    single batch to create a
    :class:`~pywayland.protocol.wayland.buffer.Buffer`. It can only be used
    once and should be destroyed after an 'created' or 'failed' event has been
    received.

    :returns: :class:`~pywayland.protocol.linux_dmabuf_unstable_v1.linuxbufferparamsv1.LinuxBufferParamsV1` -- the new temporary
    """
    params_id = self._marshal_constructor(1, LinuxBufferParamsV1)
    return params_id


@LinuxDmabufV1.event("u", [None])
def format(self, format):
    """Supported buffer format

    This event advertises one buffer format that the server supports. All the
    supported formats are advertised once when the client binds to this
    interface. A roundtrip after binding guarantees, that the client has
    received all supported formats.

    For the definition of the format codes, see create request.

    XXX: Can a compositor ever enumerate them?

    :param format: DRM_FORMAT code
    :type format: `uint`
    """
    self._post_event(0, format)


LinuxDmabufV1._gen_c()
