Clone of mesa.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

egl.html 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  1. <html>
  2. <title>Mesa EGL</title>
  3. <head><link rel="stylesheet" type="text/css" href="mesa.css"></head>
  4. <body>
  5. <h1>Mesa EGL</h1>
  6. <p>The current version of EGL in Mesa implements EGL 1.4. More information
  7. about EGL can be found at
  8. <a href="http://www.khronos.org/egl/" target="_parent">
  9. http://www.khronos.org/egl/</a>.</p>
  10. <p>The Mesa's implementation of EGL uses a driver architecture. The main
  11. library (<code>libEGL</code>) is window system neutral. It provides the EGL
  12. API entry points and helper functions for use by the drivers. Drivers are
  13. dynamically loaded by the main library and most of the EGL API calls are
  14. directly dispatched to the drivers.</p>
  15. <p>The driver in use decides the window system to support.</p>
  16. <h2>Build EGL</h2>
  17. <ol>
  18. <li>
  19. <p>Run <code>configure</code> with the desired client APIs and enable
  20. the driver for your hardware. For example</p>
  21. <pre>
  22. $ ./configure --enable-gles1 --enable-gles2 \
  23. --with-dri-drivers=... \
  24. --with-gallium-drivers=...
  25. </pre>
  26. <p>The main library and OpenGL is enabled by default. The first two options
  27. above enables <a href="opengles.html">OpenGL ES 1.x and 2.x</a>. The last two
  28. options enables the listed classic and and Gallium drivers respectively.</p>
  29. </li>
  30. <li>Build and install Mesa as usual.</li>
  31. </ol>
  32. <p>In the given example, it will build and install <code>libEGL</code>,
  33. <code>libGL</code>, <code>libGLESv1_CM</code>, <code>libGLESv2</code>, and one
  34. or more EGL drivers.</p>
  35. <h3>Configure Options</h3>
  36. <p>There are several options that control the build of EGL at configuration
  37. time</p>
  38. <ul>
  39. <li><code>--enable-egl</code>
  40. <p>By default, EGL is enabled. When disabled, the main library and the drivers
  41. will not be built.</p>
  42. </li>
  43. <li><code>--with-egl-driver-dir</code>
  44. <p>The directory EGL drivers should be installed to. If not specified, EGL
  45. drivers will be installed to <code>${libdir}/egl</code>.</p>
  46. </li>
  47. <li><code>--enable-gallium-egl</code>
  48. <p>Enable the optional <code>egl_gallium</code> driver.</p>
  49. </li>
  50. <li><code>--with-egl-platforms</code>
  51. <p>List the platforms (window systems) to support. Its argument is a comma
  52. seprated string such as <code>--with-egl-platforms=x11,drm</code>. It decides
  53. the platforms a driver may support. The first listed platform is also used by
  54. the main library to decide the native platform: the platform the EGL native
  55. types such as <code>EGLNativeDisplayType</code> or
  56. <code>EGLNativeWindowType</code> defined for.</p>
  57. <p>The available platforms are <code>x11</code>, <code>drm</code>,
  58. <code>fbdev</code>, and <code>gdi</code>. The <code>gdi</code> platform can
  59. only be built with SCons. Unless for special needs, the build system should
  60. select the right platforms automatically.</p>
  61. </li>
  62. <li><code>--enable-gles1</code> and <code>--enable-gles2</code>
  63. <p>These options enable OpenGL ES support in OpenGL. The result is one big
  64. internal library that supports multiple APIs.</p>
  65. </li>
  66. <li><code>--enable-shared-glapi</code>
  67. <p>By default, <code>libGL</code> has its own copy of <code>libglapi</code>.
  68. This options makes <code>libGL</code> use the shared <code>libglapi</code>. This
  69. is required if applications mix OpenGL and OpenGL ES.</p>
  70. </li>
  71. <li><code>--enable-openvg</code>
  72. <p>OpenVG must be explicitly enabled by this option.</p>
  73. </li>
  74. </ul>
  75. <h2>Use EGL</h2>
  76. <h3>Demos</h3>
  77. <p>There are demos for the client APIs supported by EGL. They can be found in
  78. mesa/demos repository.</p>
  79. <h3>Environment Variables</h3>
  80. <p>There are several environment variables that control the behavior of EGL at
  81. runtime</p>
  82. <ul>
  83. <li><code>EGL_DRIVERS_PATH</code>
  84. <p>By default, the main library will look for drivers in the directory where
  85. the drivers are installed to. This variable specifies a list of
  86. colon-separated directories where the main library will look for drivers, in
  87. addition to the default directory. This variable is ignored for setuid/setgid
  88. binaries.</p>
  89. <p>This variable is usually set to test an uninstalled build. For example, one
  90. may set</p>
  91. <pre>
  92. $ export LD_LIBRARY_PATH=$mesa/lib
  93. $ export EGL_DRIVERS_PATH=$mesa/lib/egl
  94. </pre>
  95. <p>to test a build without installation</p>
  96. </li>
  97. <li><code>EGL_DRIVER</code>
  98. <p>This variable specifies a full path to or the name of an EGL driver. It
  99. forces the specified EGL driver to be loaded. It comes in handy when one wants
  100. to test a specific driver. This variable is ignored for setuid/setgid
  101. binaries.</p>
  102. </li>
  103. <li><code>EGL_PLATFORM</code>
  104. <p>This variable specifies the native platform. The valid values are the same
  105. as those for <code>--with-egl-platforms</code>. When the variable is not set,
  106. the main library uses the first platform listed in
  107. <code>--with-egl-platforms</code> as the native platform.</p>
  108. <p>Extensions like <code>EGL_MESA_drm_display</code> define new functions to
  109. create displays for non-native platforms. These extensions are usually used by
  110. applications that support non-native platforms. Setting this variable is
  111. probably required only for some of the demos found in mesa/demo repository.</p>
  112. </li>
  113. <li><code>EGL_LOG_LEVEL</code>
  114. <p>This changes the log level of the main library and the drivers. The valid
  115. values are: <code>debug</code>, <code>info</code>, <code>warning</code>, and
  116. <code>fatal</code>.</p>
  117. </li>
  118. <li><code>EGL_SOFTWARE</code>
  119. <p>For drivers that support both hardware and software rendering, setting this
  120. variable to true forces the use of software rendering.</p>
  121. </li>
  122. </ul>
  123. <h2>EGL Drivers</h2>
  124. <ul>
  125. <li><code>egl_dri2</code>
  126. <p>This driver supports both <code>x11</code> and <code>drm</code> platforms.
  127. It functions as a DRI driver loader. For <code>x11</code> support, it talks to
  128. the X server directly using (XCB-)DRI2 protocol.</p>
  129. <p>This driver can share DRI drivers with <code>libGL</code>.</p>
  130. </li>
  131. <li><code>egl_gallium</code>
  132. <p>This driver is based on Gallium3D. It supports all rendering APIs and
  133. hardwares supported by Gallium3D. It is the only driver that supports OpenVG.
  134. The supported platforms are X11, DRM, FBDEV, and GDI.</p>
  135. <p>This driver comes with its own hardware drivers
  136. (<code>pipe_&lt;hw&gt;</code>) and client API modules
  137. (<code>st_&lt;api&gt;</code>).</p>
  138. </li>
  139. <li><code>egl_glx</code>
  140. <p>This driver provides a wrapper to GLX. It uses exclusively GLX to implement
  141. the EGL API. It supports both direct and indirect rendering when the GLX does.
  142. It is accelerated when the GLX is. As such, it cannot provide functions that
  143. is not available in GLX or GLX extensions.</p>
  144. </li>
  145. </ul>
  146. <h2>Packaging</h2>
  147. <p>The ABI between the main library and its drivers are not stable. Nor is
  148. there a plan to stabilize it at the moment. Of the EGL drivers,
  149. <code>egl_gallium</code> has its own hardware drivers and client API modules.
  150. They are considered internal to <code>egl_gallium</code> and there is also no
  151. stable ABI between them. These should be kept in mind when packaging for
  152. distribution.</p>
  153. <p>Generally, <code>egl_dri2</code> is preferred over <code>egl_gallium</code>
  154. when the system already has DRI drivers. As <code>egl_gallium</code> is loaded
  155. before <code>egl_dri2</code> when both are available, <code>egl_gallium</code>
  156. is disabled by default.</p>
  157. <h2>Developers</h2>
  158. <p>The sources of the main library and the classic drivers can be found at
  159. <code>src/egl/</code>. The sources of the <code>egl</code> state tracker can
  160. be found at <code>src/gallium/state_trackers/egl/</code>.</p>
  161. <p>The suggested way to learn to write a EGL driver is to see how other drivers
  162. are written. <code>egl_glx</code> should be a good reference. It works in any
  163. environment that has GLX support, and it is simpler than most drivers.</p>
  164. <h3>Lifetime of Display Resources</h3>
  165. <p>Contexts and surfaces are examples of display resources. They might live
  166. longer than the display that creates them.</p>
  167. <p>In EGL, when a display is terminated through <code>eglTerminate</code>, all
  168. display resources should be destroyed. Similarly, when a thread is released
  169. throught <code>eglReleaseThread</code>, all current display resources should be
  170. released. Another way to destory or release resources is through functions
  171. such as <code>eglDestroySurface</code> or <code>eglMakeCurrent</code>.</p>
  172. <p>When a resource that is current to some thread is destroyed, the resource
  173. should not be destroyed immediately. EGL requires the resource to live until
  174. it is no longer current. A driver usually calls
  175. <code>eglIs&lt;Resource&gt;Bound</code> to check if a resource is bound
  176. (current) to any thread in the destroy callbacks. If it is still bound, the
  177. resource is not destroyed.</p>
  178. <p>The main library will mark destroyed current resources as unlinked. In a
  179. driver's <code>MakeCurrent</code> callback,
  180. <code>eglIs&lt;Resource&gt;Linked</code> can then be called to check if a newly
  181. released resource is linked to a display. If it is not, the last reference to
  182. the resource is removed and the driver should destroy the resource. But it
  183. should be careful here because <code>MakeCurrent</code> might be called with an
  184. uninitialized display.</p>
  185. <p>This is the only mechanism provided by the main library to help manage the
  186. resources. The drivers are responsible to the correct behavior as defined by
  187. EGL.</p>
  188. <h3><code>EGL_RENDER_BUFFER</code></h3>
  189. <p>In EGL, the color buffer a context should try to render to is decided by the
  190. binding surface. It should try to render to the front buffer if the binding
  191. surface has <code>EGL_RENDER_BUFFER</code> set to
  192. <code>EGL_SINGLE_BUFFER</code>; If the same context is later bound to a
  193. surface with <code>EGL_RENDER_BUFFER</code> set to
  194. <code>EGL_BACK_BUFFER</code>, the context should try to render to the back
  195. buffer. However, the context is allowed to make the final decision as to which
  196. color buffer it wants to or is able to render to.</p>
  197. <p>For pbuffer surfaces, the render buffer is always
  198. <code>EGL_BACK_BUFFER</code>. And for pixmap surfaces, the render buffer is
  199. always <code>EGL_SINGLE_BUFFER</code>. Unlike window surfaces, EGL spec
  200. requires their <code>EGL_RENDER_BUFFER</code> values to be honored. As a
  201. result, a driver should never set <code>EGL_PIXMAP_BIT</code> or
  202. <code>EGL_PBUFFER_BIT</code> bits of a config if the contexts created with the
  203. config won't be able to honor the <code>EGL_RENDER_BUFFER</code> of pixmap or
  204. pbuffer surfaces.</p>
  205. <p>It should also be noted that pixmap and pbuffer surfaces are assumed to be
  206. single-buffered, in that <code>eglSwapBuffers</code> has no effect on them. It
  207. is desirable that a driver allocates a private color buffer for each pbuffer
  208. surface created. If the window system the driver supports has native pbuffers,
  209. or if the native pixmaps have more than one color buffers, the driver should
  210. carefully attach the native color buffers to the EGL surfaces, re-route them if
  211. required.</p>
  212. <p>There is no defined behavior as to, for example, how
  213. <code>glDrawBuffer</code> interacts with <code>EGL_RENDER_BUFFER</code>. Right
  214. now, it is desired that the draw buffer in a client API be fixed for pixmap and
  215. pbuffer surfaces. Therefore, the driver is responsible to guarantee that the
  216. client API renders to the specified render buffer for pixmap and pbuffer
  217. surfaces.</p>
  218. <h3><code>EGLDisplay</code> Mutex</h3>
  219. The <code>EGLDisplay</code> will be locked before calling any of the dispatch
  220. functions (well, except for GetProcAddress which does not take an
  221. <code>EGLDisplay</code>). This guarantees that the same dispatch function will
  222. not be called with the sample display at the same time. If a driver has access
  223. to an <code>EGLDisplay</code> without going through the EGL APIs, the driver
  224. should as well lock the display before using it.
  225. </body>
  226. </html>