ImageNativeBuffer.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /*
  2. * Copyright (c) 2016-2022, 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. #ifndef _EGLSTREAM_NV_IMAGE_NATIVE_BUFFER_H
  29. #define _EGLSTREAM_NV_IMAGE_NATIVE_BUFFER_H
  30. #include "nvbufsurface.h"
  31. namespace EGLStream
  32. {
  33. /**
  34. * The NV::ImageNativeBuffer extension adds an interface to create and/or
  35. * copy EGLStream Images to NvBuffers.
  36. */
  37. DEFINE_UUID(Argus::ExtensionName, NV_IMAGE_NATIVE_BUFFER, ce9e8c60,1792,11e6,bdf4,08,00,20,0c,9a,66);
  38. namespace NV
  39. {
  40. /*
  41. * Counterclockwise rotation value, in degree
  42. */
  43. enum Rotation
  44. {
  45. ROTATION_0,
  46. ROTATION_90,
  47. ROTATION_180,
  48. ROTATION_270,
  49. ROTATION_COUNT
  50. };
  51. /**
  52. * @class IImageNativeBuffer
  53. *
  54. * Interface that supports creating new NvBuffers and/or copying Image contents
  55. * to existing NvBuffers.
  56. */
  57. DEFINE_UUID(Argus::InterfaceID, IID_IMAGE_NATIVE_BUFFER, 2f410340,1793,11e6,bdf4,08,00,20,0c,9a,66);
  58. class IImageNativeBuffer : public Argus::Interface
  59. {
  60. public:
  61. static const Argus::InterfaceID& id() { return IID_IMAGE_NATIVE_BUFFER; }
  62. /**
  63. * Creates a new NvBuffer, copies the image contents to the new buffer, then
  64. * returns the dmabuf-fd. Ownership of this dmabuf-fd is given to the caller
  65. * and must be destroyed using NvBufSurfaceDestroy (see nvbufsurface.h).
  66. *
  67. * Note that the size, format, and layout of the new buffer can be different from
  68. * what is being used for the EGLStream, and if this is the case then scaling
  69. * and format conversion will be performed when the image is copied to the
  70. * new buffer. Details of this scaling and conversion are left up to the
  71. * implementation, but the application should consider and account for any
  72. * measured performance penalties associated with such operations.
  73. *
  74. * @param[in] size the size of the NvBuffer to create.
  75. * @param[in] format the color format to use for the new NvBuffer.
  76. * @param[in] layout the buffer layout to use for the new NvBuffer.
  77. * @param[in] rotation flag that could be 0/90/180/270 degree.
  78. * @param[out] status optional status return code.
  79. * @returns -1 on failure, or a valid dmabuf-fd on success.
  80. */
  81. virtual int createNvBuffer(Argus::Size2D<uint32_t> size,
  82. NvBufSurfaceColorFormat format,
  83. NvBufSurfaceLayout layout,
  84. Rotation rotation = ROTATION_0,
  85. Argus::Status* status = NULL) const = 0;
  86. /**
  87. * Copies the image contents to the given NvBuffer. This performs an uncropped
  88. * (full-surface) copy of the image to the provided buffer, which is permitted
  89. * to have different size, format, and layout attributes than those of the buffer
  90. * backing this EGLStream image. If this is the case, scaling and format conversion
  91. * will be performed when the image is copied to the buffer. Details of this scaling
  92. * and conversion are left up to the implementation, but the application should
  93. * consider and account for any measured performance penalties associated with such
  94. * operations.
  95. *
  96. * @param[in] fd the dmabuf-fd of the NvBuffer to copy to.
  97. * @param[in] rotation flag that could be 0/90/180/270 degree.
  98. */
  99. virtual Argus::Status copyToNvBuffer(int fd, Rotation rotation = ROTATION_0) const = 0;
  100. protected:
  101. ~IImageNativeBuffer() {}
  102. };
  103. } // namespace NV
  104. } // namespace EGLStream
  105. #endif // _EGLSTREAM_NV_IMAGE_NATIVE_BUFFER_H