NativeMultiDisplay.cs 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. /****************************************************************************
  2. * Copyright 2019 Nreal Techonology Limited. All rights reserved.
  3. *
  4. * This file is part of NRSDK.
  5. *
  6. * https://www.nreal.ai/
  7. *
  8. *****************************************************************************/
  9. namespace NRKernal
  10. {
  11. using System;
  12. using UnityEngine;
  13. using System.Runtime.InteropServices;
  14. /// <summary> Callback, called when the nr display resolution. </summary>
  15. /// <param name="width"> The width.</param>
  16. /// <param name="height"> The height.</param>
  17. public delegate void NRDisplayResolutionCallback(int width, int height);
  18. /// <summary> HMD Eye offset Native API . </summary>
  19. internal partial class NativeMultiDisplay
  20. {
  21. /// <summary> Handle of the multi display. </summary>
  22. private UInt64 m_MultiDisplayHandle;
  23. /// <summary> Creates a new bool. </summary>
  24. /// <returns> True if it succeeds, false if it fails. </returns>
  25. public bool Create()
  26. {
  27. NativeResult result = NativeApi.NRDisplayCreate(ref m_MultiDisplayHandle);
  28. NativeErrorListener.Check(result, this, "Create", true);
  29. return result == NativeResult.Success;
  30. }
  31. /// <summary> Initializes the color space. </summary>
  32. public void InitColorSpace()
  33. {
  34. NativeColorSpace colorspace = QualitySettings.activeColorSpace == ColorSpace.Gamma ?
  35. NativeColorSpace.COLOR_SPACE_GAMMA : NativeColorSpace.COLOR_SPACE_LINEAR;
  36. NativeResult result = NativeApi.NRDisplayInitSetTextureColorSpace(m_MultiDisplayHandle, colorspace);
  37. NativeErrorListener.Check(result, this, "InitColorSpace");
  38. }
  39. /// <summary> Starts this object. </summary>
  40. public void Start()
  41. {
  42. NativeResult result = NativeApi.NRDisplayStart(m_MultiDisplayHandle);
  43. NativeErrorListener.Check(result, this, "Start", true);
  44. }
  45. /// <summary> Listen main screen resolution changed. </summary>
  46. /// <param name="callback"> The callback.</param>
  47. public void ListenMainScrResolutionChanged(NRDisplayResolutionCallback callback)
  48. {
  49. NativeResult result = NativeApi.NRDisplaySetMainDisplayResolutionCallback(m_MultiDisplayHandle, callback);
  50. NativeErrorListener.Check(result, this, "ListenMainScrResolutionChanged");
  51. }
  52. /// <summary> Stops this object. </summary>
  53. public void Stop()
  54. {
  55. NativeResult result = NativeApi.NRDisplayStop(m_MultiDisplayHandle);
  56. NativeErrorListener.Check(result, this, "Stop");
  57. }
  58. /// <summary> Updates the home screen texture described by rendertexture. </summary>
  59. /// <param name="rendertexture"> The rendertexture.</param>
  60. /// <returns> True if it succeeds, false if it fails. </returns>
  61. public bool UpdateHomeScreenTexture(IntPtr rendertexture)
  62. {
  63. NativeResult result = NativeApi.NRDisplaySetMainDisplayTexture(m_MultiDisplayHandle, rendertexture);
  64. NativeErrorListener.Check(result, this, "UpdateHomeScreenTexture");
  65. return result == NativeResult.Success;
  66. }
  67. /// <summary> Pauses this object. </summary>
  68. /// <returns> True if it succeeds, false if it fails. </returns>
  69. public bool Pause()
  70. {
  71. NativeResult result = NativeApi.NRDisplayPause(m_MultiDisplayHandle);
  72. NativeErrorListener.Check(result, this, "Pause");
  73. return result == NativeResult.Success;
  74. }
  75. /// <summary> Resumes this object. </summary>
  76. /// <returns> True if it succeeds, false if it fails. </returns>
  77. public bool Resume()
  78. {
  79. NativeResult result = NativeApi.NRDisplayResume(m_MultiDisplayHandle);
  80. NativeErrorListener.Check(result, this, "Resume");
  81. return result == NativeResult.Success;
  82. }
  83. /// <summary> Destroys this object. </summary>
  84. /// <returns> True if it succeeds, false if it fails. </returns>
  85. public bool Destroy()
  86. {
  87. NativeResult result = NativeApi.NRDisplayDestroy(m_MultiDisplayHandle);
  88. NativeErrorListener.Check(result, this, "Destroy");
  89. return result == NativeResult.Success;
  90. }
  91. /// <summary> A native api. </summary>
  92. private struct NativeApi
  93. {
  94. /// <summary> Nr display create. </summary>
  95. /// <param name="out_display_handle"> [in,out] Handle of the out display.</param>
  96. /// <returns> A NativeResult. </returns>
  97. [DllImport(NativeConstants.NRNativeLibrary)]
  98. public static extern NativeResult NRDisplayCreate(ref UInt64 out_display_handle);
  99. /// <summary> Callback, called when the nr display set main display resolution. </summary>
  100. /// <param name="display_handle"> The display handle.</param>
  101. /// <param name="resolution_callback"> The resolution callback.</param>
  102. /// <returns> A NativeResult. </returns>
  103. [DllImport(NativeConstants.NRNativeLibrary)]
  104. public static extern NativeResult NRDisplaySetMainDisplayResolutionCallback(UInt64 display_handle,
  105. NRDisplayResolutionCallback resolution_callback);
  106. /// <summary> Nr display initialize set texture color space. </summary>
  107. /// <param name="display_handle"> The display handle.</param>
  108. /// <param name="color_space"> The color space.</param>
  109. /// <returns> A NativeResult. </returns>
  110. [DllImport(NativeConstants.NRNativeLibrary)]
  111. public static extern NativeResult NRDisplayInitSetTextureColorSpace(UInt64 display_handle,
  112. NativeColorSpace color_space);
  113. /// <summary> Nr display start. </summary>
  114. /// <param name="display_handle"> The display handle.</param>
  115. /// <returns> A NativeResult. </returns>
  116. [DllImport(NativeConstants.NRNativeLibrary)]
  117. public static extern NativeResult NRDisplayStart(UInt64 display_handle);
  118. /// <summary> Nr display stop. </summary>
  119. /// <param name="display_handle"> The display handle.</param>
  120. /// <returns> A NativeResult. </returns>
  121. [DllImport(NativeConstants.NRNativeLibrary)]
  122. public static extern NativeResult NRDisplayStop(UInt64 display_handle);
  123. /// <summary> Nr display pause. </summary>
  124. /// <param name="display_handle"> The display handle.</param>
  125. /// <returns> A NativeResult. </returns>
  126. [DllImport(NativeConstants.NRNativeLibrary)]
  127. public static extern NativeResult NRDisplayPause(UInt64 display_handle);
  128. /// <summary> Nr display resume. </summary>
  129. /// <param name="display_handle"> The display handle.</param>
  130. /// <returns> A NativeResult. </returns>
  131. [DllImport(NativeConstants.NRNativeLibrary)]
  132. public static extern NativeResult NRDisplayResume(UInt64 display_handle);
  133. /// <summary> Nr display set main display texture. </summary>
  134. /// <param name="display_handle"> The display handle.</param>
  135. /// <param name="controller_texture"> The controller texture.</param>
  136. /// <returns> A NativeResult. </returns>
  137. [DllImport(NativeConstants.NRNativeLibrary)]
  138. public static extern NativeResult NRDisplaySetMainDisplayTexture(UInt64 display_handle,
  139. IntPtr controller_texture);
  140. /// <summary> Nr display destroy. </summary>
  141. /// <param name="display_handle"> The display handle.</param>
  142. /// <returns> A NativeResult. </returns>
  143. [DllImport(NativeConstants.NRNativeLibrary)]
  144. public static extern NativeResult NRDisplayDestroy(UInt64 display_handle);
  145. };
  146. }
  147. }