EGLSync.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. /*
  2. * Copyright (c) 2017, NVIDIA CORPORATION. All rights reserved.
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions
  6. * are met:
  7. * * Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * * Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. * * Neither the name of NVIDIA CORPORATION nor the names of its
  13. * contributors may be used to endorse or promote products derived
  14. * from this software without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
  17. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  18. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  19. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  20. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  21. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  22. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  23. * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  24. * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  25. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  26. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  27. */
  28. /**
  29. * @file
  30. * <b>Libargus API: EGLSync API</b>
  31. *
  32. * @b Description: Defines a SyncType that uses EGLSync objects.
  33. */
  34. #ifndef _ARGUS_EGL_SYNC_H
  35. #define _ARGUS_EGL_SYNC_H
  36. namespace Argus
  37. {
  38. /**
  39. * @defgroup ArgusBufferEGLSync EGLSync
  40. * @ingroup ArgusBufferSync
  41. * Sync type that uses EGLSync objects (SYNC_TYPE_EGL_SYNC).
  42. */
  43. /**
  44. * Sync type that uses EGLSync objects (SYNC_TYPE_EGL_SYNC).
  45. * @ingroup ArgusBufferSync
  46. */
  47. DEFINE_UUID(SyncType, SYNC_TYPE_EGL_SYNC, 5df77c90,5d1b,11e7,9598,08,00,20,0c,9a,66);
  48. /**
  49. * @class IEGLSync
  50. *
  51. * Interface that provides EGLSync input and output methods for a Buffer.
  52. *
  53. * @ingroup ArgusBufferEGLSync
  54. */
  55. DEFINE_UUID(InterfaceID, IID_EGL_SYNC, 5df77c91,5d1b,11e7,9598,08,00,20,0c,9a,66);
  56. class IEGLSync : public Interface
  57. {
  58. public:
  59. static const InterfaceID& id() { return IID_EGL_SYNC; }
  60. /**
  61. * Creates and returns a new EGLSync object that is signalled when all operations on the
  62. * Buffer from the previous libargus capture request have completed.
  63. *
  64. * When sync support is enabled for a Stream, libargus may output Buffers to that stream
  65. * even if hardware operations are still pending on the Buffer's image data. In this case,
  66. * libargus will attach sync information to the Buffer when it is acquired by the client
  67. * that must be used to block any client operations on the image data until all preceeding
  68. * libargus operations have completed. Failure to block on this sync information may lead
  69. * to undefined buffer contents.
  70. *
  71. * This method will create and output a new EGLSync object that will be signalled once all
  72. * libargus operations on the Buffer have completed. Ownership of this EGLSync object is
  73. * given to the caller, who must then wait on the sync object as needed before destroying
  74. * it using eglDestroySyncKHR. Calling this method more than once is allowed, and each call
  75. * will create and return a new EGLSync object.
  76. *
  77. * This method should only ever be called while the Buffer is in an acquired state; ie. the
  78. * time between when the Buffer was acquired by IBufferOutputStream::acquireBuffer and when
  79. * it was released by IBufferOutputStream::releaseBuffer. If called outside of the acquired
  80. * state, STATUS_UNAVAILABLE will be returned.
  81. *
  82. * When successful, STATUS_OK will be returned and 'eglSync' will be written with the new
  83. * EGLSync object. Note that EGL_NO_SYNC_KHR is still a valid output for the 'eglSync' even
  84. * when STATUS_OK is returned; this implies that libargus does not have any pending
  85. * operations to the Buffer and so the client need not take any sync precautions before
  86. * accessing the image data. Thus, the returned Status code should be used for detecting
  87. * failures rather than checking for an EGL_NO_SYNC_KHR output.
  88. *
  89. * @param[in] eglDisplay The EGLDisplay that shall own the returned EGLSync object.
  90. * @param[out] eglSync Output for the newly created EGLSync object. Ownership of this object
  91. * is given to the client.
  92. *
  93. * @returns success/status of this call.
  94. */
  95. virtual Status getAcquireSync(EGLDisplay eglDisplay, EGLSyncKHR* eglSync) = 0;
  96. /**
  97. * Sets the client-provided EGLSync for a Buffer prior to its release.
  98. *
  99. * When sync support is enabled for a Stream, the client may release Buffers back to
  100. * libargus for future capture use even if the client has hardware operations pending on
  101. * the Buffer's image data. In this case, the client must provide an EGLSync object to
  102. * libargus that will be signalled by the completion of the client's pending operations.
  103. * This sync object will then be waited on by libargus to prevent any buffer operations
  104. * from occuring before the client sync has been signalled.
  105. *
  106. * This method should only ever be called while the Buffer is in an acquired state; ie. the
  107. * time between when the Buffer was acquired by IBufferOutputStream::acquireBuffer and when
  108. * it was released by IBufferOutputStream::releaseBuffer. If called outside of this period,
  109. * STATUS_UNAVAILBLE will be returned and no object updates will be made. Otherwise, when
  110. * called in the acquired state, this method will set the EGLSync that will be provided to
  111. * libargus at the time that the Buffer is released by IBufferOutputStream::releaseBuffer
  112. * and STATUS_OK will be returned. On success, ownership of the EGLSync object will be passed
  113. * to libargus; further use of the EGLSync by the client after this point may lead to
  114. * undefined results or abnormal termination. If called more than once when in the acquired
  115. * state, any previously set EGLSync will be replaced; only the last set EGLSync before
  116. * calling releaseBuffer will be waited on by libargus.
  117. *
  118. * If the client does not have any pending operations on the Buffer at the time that
  119. * releaseBuffer is called, it is allowed for the client to either skip calling this method
  120. * or to call it using EGL_NO_DISPLAY and EGL_NO_SYNC_KHR such that libargus will not have
  121. * to consider any sync requirements and may use the Buffer immediately.
  122. *
  123. * @param[in] eglDisplay The EGLDisplay that created the EGLSync object being provided.
  124. * @param[in] eglSync The EGLSync that libargus must wait on before accessing the buffer.
  125. *
  126. * @returns success/status of this call.
  127. */
  128. virtual Status setReleaseSync(EGLDisplay eglDisplay, EGLSyncKHR eglSync) = 0;
  129. protected:
  130. ~IEGLSync() {}
  131. };
  132. } // namespace Argus
  133. #endif // _ARGUS_EGL_SYNC_H