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 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  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. For drivers that
  16. support hardware rendering, there are usually multiple drivers supporting the
  17. same window system. Each one of of them supports a certain range of graphics
  18. cards.</p>
  19. <h2>Build EGL</h2>
  20. <ol>
  21. <li>
  22. <p>Run <code>configure</code> with the desired state trackers and enable
  23. the Gallium driver for your hardware. For example</p>
  24. <pre>
  25. $ ./configure --enable-gles-overlay --with-state-trackers=egl,vega --enable-gallium-{swrast,intel}
  26. </pre>
  27. <p>The main library and OpenGL is enabled by default. The first option enables
  28. <a href="opengles.html">OpenGL ES 1.x and 2.x</a>. The <code>egl</code> state
  29. tracker is needed by a number of EGL drivers. EGL drivers will be covered
  30. later. The <a href="openvg.html">vega state tracker</a> provides OpenVG
  31. 1.x.</p>
  32. </li>
  33. <li>Build and install Mesa as usual.</li>
  34. </ol>
  35. <p>In the given example, it will build and install <code>libEGL</code>,
  36. <code>libGL</code>, <code>libGLESv1_CM</code>, <code>libGLESv2</code>,
  37. <code>libOpenVG</code>, and one or more EGL drivers.</p>
  38. <h3>Configure Options</h3>
  39. <p>There are several options that control the build of EGL at configuration
  40. time</p>
  41. <ul>
  42. <li><code>--enable-egl</code>
  43. <p>By default, EGL is enabled. When disabled, the main library and the drivers
  44. will not be built.</p>
  45. </li>
  46. <li><code>--with-egl-driver-dir</code>
  47. <p>The directory EGL drivers should be installed to. If not specified, EGL
  48. drivers will be installed to <code>${libdir}/egl</code>.</p>
  49. </li>
  50. <li><code>--with-egl-displays</code>
  51. <p>List the window system(s) to support. It is by default <code>x11</code>,
  52. which supports the X Window System. Its argument is a comma separated string
  53. like, for example, <code>--with-egl-displays=x11,kms</code>. Because an EGL
  54. driver decides which window system to support, this example will enable two
  55. (sets of) EGL drivers. One supports the X window system and the other supports
  56. bare KMS (kernel modesetting).</p>
  57. </li>
  58. <li><code>--with-state-trackers</code>
  59. <p>The argument is a comma separated string. It is usually used to specify the
  60. rendering APIs, such as OpenVG, to build. But it should be noted that a number
  61. of EGL drivers depend on the <code>egl</code> state tracker. They will
  62. <em>not</em> be built without the <code>egl</code> state tracker.</p>
  63. </li>
  64. <li><code>--enable-gles-overlay</code>
  65. <p>OpenGL and OpenGL ES are not controlled by
  66. <code>--with-state-trackers</code>. OpenGL is always built. To build OpenGL
  67. ES, this option must be explicitly given.</p>
  68. </li>
  69. <li><code>--enable-gles1</code> and <code>--enable-gles2</code>
  70. <p>Unlike <code>--enable-gles-overlay</code>, which builds one library for each
  71. rendering API, these options enable OpenGL ES support in OpenGL. The result is
  72. one big library that supports multiple APIs. This is used by DRI drivers and
  73. <code>egl_dri2</code> EGL driver.
  74. </li>
  75. <li><code>--enable-gallium-swrast</code>
  76. <p>This option is not specific to EGL. But if there is no driver for your
  77. hardware, or you are experiencing problems with the hardware driver, you can
  78. enable the swrast DRM driver. It is a dummy driver and EGL will fallback to
  79. software rendering automatically.</p>
  80. </li>
  81. </ul>
  82. <h2>Use EGL</h2>
  83. <p>There are demos for the client APIs supported by EGL. They can be found in
  84. <code>progs/egl/</code>, You can use them to test your build. For example,</p>
  85. <pre>
  86. $ cd progs/egl/eglut
  87. $ make
  88. $ cd ../opengles1
  89. $ make
  90. $ ./torus_x11
  91. </pre>
  92. <h3>Environment Variables</h3>
  93. <p>There are several environment variables that control the behavior of EGL at
  94. runtime</p>
  95. <ul>
  96. <li><code>EGL_DRIVERS_PATH</code>
  97. <p>By default, the main library will look for drivers in the directory where
  98. the drivers are installed to. This variable specifies a list of
  99. colon-separated directories where the main library will look for drivers, in
  100. addition to the default directory. This variable is ignored for setuid/setgid
  101. binaries.</p>
  102. </li>
  103. <li><code>EGL_DRIVER</code>
  104. <p>This variable specifies a full path to an EGL driver and it forces the
  105. specified EGL driver to be loaded. It comes in handy when one wants to test a
  106. specific driver. This variable is ignored for setuid/setgid binaries.</p>
  107. </li>
  108. <li><code>EGL_DISPLAY</code>
  109. <p>When <code>EGL_DRIVER</code> is not set, the main library loads <em>all</em>
  110. EGL drivers that support a certain window system. <code>EGL_DISPLAY</code> can
  111. be used to specify the window system and the valid values are, for example,
  112. <code>x11</code> or <code>kms</code>. When the variable is not set, the main
  113. library defaults the value to the first window system listed in
  114. <code>--with-egl-displays</code> at configuration time.
  115. </li>
  116. <li><code>EGL_LOG_LEVEL</code>
  117. <p>This changes the log level of the main library and the drivers. The valid
  118. values are: <code>debug</code>, <code>info</code>, <code>warning</code>, and
  119. <code>fatal</code>.</p>
  120. </li>
  121. <li><code>EGL_SOFTWARE</code>
  122. <p>For drivers that support both hardware and software rendering, setting this
  123. variable to true forces the use of software rendering.</p>
  124. </li>
  125. </ul>
  126. <h2>EGL Drivers</h2>
  127. <p>There are two categories of EGL drivers: Gallium and classic.</p>
  128. <p>Gallium EGL drivers supports all rendering APIs specified in EGL 1.4. The
  129. support for optional EGL functions and EGL extensions is usually more complete
  130. than the classic ones. These drivers depend on the <code>egl</code> state
  131. tracker to build. The available drivers are</p>
  132. <ul>
  133. <li><code>egl_&lt;dpy&gt;_i915</code></li>
  134. <li><code>egl_&lt;dpy&gt;_i965</code></li>
  135. <li><code>egl_&lt;dpy&gt;_radeon</code></li>
  136. <li><code>egl_&lt;dpy&gt;_nouveau</code></li>
  137. <li><code>egl_&lt;dpy&gt;_swrast</code></li>
  138. <li><code>egl_&lt;dpy&gt;_vmwgfx</code></li>
  139. </ul>
  140. <p><code>&lt;dpy&gt;</code> is given by <code>--with-egl-displays</code> at
  141. configuration time. There will be one EGL driver for each combination of the
  142. displays listed and the hardware drivers enabled.</p>
  143. <p>Classic EGL drivers, on the other hand, supports only OpenGL as its
  144. rendering API. They can be found under <code>src/egl/drivers/</code>. There
  145. are 3 of them</p>
  146. <ul>
  147. <li><code>egl_glx</code>
  148. <p>This driver provides a wrapper to GLX. It uses exclusively GLX to implement
  149. the EGL API. It supports both direct and indirect rendering when the GLX does.
  150. It is accelerated when the GLX is. As such, it cannot provide functions that
  151. is not available in GLX or GLX extensions.</p>
  152. </li>
  153. <li><code>egl_dri2</code>
  154. <p>This driver supports the X Window System as its window system. It functions
  155. as a DRI2 driver loader. Unlike <code>egl_glx</code>, it has no dependency on
  156. <code>libGL</code>. It talks to the X server directly using DRI2 protocol.</p>
  157. </li>
  158. <li><code>egl_dri</code>
  159. <p>This driver lacks maintenance and does <em>not</em> build. It is similiar
  160. to <code>egl_dri2</code> in that it functions as a DRI(1) driver loader. But
  161. unlike <code>egl_dri2</code>, it supports Linux framebuffer devices as its
  162. window system and supports EGL_MESA_screen_surface extension. As DRI1 drivers
  163. are phasing out, it might eventually be replaced by <code>egl_dri2</code>.</p>
  164. </li>
  165. </ul>
  166. <p>To use the classic drivers, one must manually set <code>EGL_DRIVER</code> at
  167. runtime.</p>
  168. <h2>Developers</h2>
  169. <p>The sources of the main library and the classic drivers can be found at
  170. <code>src/egl/</code>. The sources of the <code>egl</code> state tracker can
  171. be found at <code>src/gallium/state_trackers/egl/</code>.</p>
  172. <p>The suggested way to learn to write a EGL driver is to see how other drivers
  173. are written. <code>egl_glx</code> should be a good reference. It works in any
  174. environment that has GLX support, and it is simpler than most drivers.</p>
  175. <h3>Lifetime of Display Resources</h3>
  176. <p>Contexts and surfaces are examples of display resources. They might live
  177. longer than the display that creates them.</p>
  178. <p>In EGL, when a display is terminated through <code>eglTerminate</code>, all
  179. display resources should be destroyed. Similarly, when a thread is released
  180. throught <code>eglReleaseThread</code>, all current display resources should be
  181. released. Another way to destory or release resources is through functions
  182. such as <code>eglDestroySurface</code> or <code>eglMakeCurrent</code>.</p>
  183. <p>When a resource that is current to some thread is destroyed, the resource
  184. should not be destroyed immediately. EGL requires the resource to live until
  185. it is no longer current. A driver usually calls
  186. <code>eglIs&lt;Resource&gt;Bound</code> to check if a resource is bound
  187. (current) to any thread in the destroy callbacks. If it is still bound, the
  188. resource is not destroyed.</p>
  189. <p>The main library will mark destroyed current resources as unlinked. In a
  190. driver's <code>MakeCurrent</code> callback,
  191. <code>eglIs&lt;Resource&gt;Linked</code> can then be called to check if a newly
  192. released resource is linked to a display. If it is not, the last reference to
  193. the resource is removed and the driver should destroy the resource. But it
  194. should be careful here because <code>MakeCurrent</code> might be called with an
  195. uninitialized display.</p>
  196. <p>This is the only mechanism provided by the main library to help manage the
  197. resources. The drivers are responsible to the correct behavior as defined by
  198. EGL.</p>
  199. <h3><code>EGL_RENDER_BUFFER</code></h3>
  200. <p>In EGL, the color buffer a context should try to render to is decided by the
  201. binding surface. It should try to render to the front buffer if the binding
  202. surface has <code>EGL_RENDER_BUFFER</code> set to
  203. <code>EGL_SINGLE_BUFFER</code>; If the same context is later bound to a
  204. surface with <code>EGL_RENDER_BUFFER</code> set to
  205. <code>EGL_BACK_BUFFER</code>, the context should try to render to the back
  206. buffer. However, the context is allowed to make the final decision as to which
  207. color buffer it wants to or is able to render to.</p>
  208. <p>For pbuffer surfaces, the render buffer is always
  209. <code>EGL_BACK_BUFFER</code>. And for pixmap surfaces, the render buffer is
  210. always <code>EGL_SINGLE_BUFFER</code>. Unlike window surfaces, EGL spec
  211. requires their <code>EGL_RENDER_BUFFER</code> values to be honored. As a
  212. result, a driver should never set <code>EGL_PIXMAP_BIT</code> or
  213. <code>EGL_PBUFFER_BIT</code> bits of a config if the contexts created with the
  214. config won't be able to honor the <code>EGL_RENDER_BUFFER</code> of pixmap or
  215. pbuffer surfaces.</p>
  216. <p>It should also be noted that pixmap and pbuffer surfaces are assumed to be
  217. single-buffered, in that <code>eglSwapBuffers</code> has no effect on them. It
  218. is desirable that a driver allocates a private color buffer for each pbuffer
  219. surface created. If the window system the driver supports has native pbuffers,
  220. or if the native pixmaps have more than one color buffers, the driver should
  221. carefully attach the native color buffers to the EGL surfaces, re-route them if
  222. required.</p>
  223. <p>There is no defined behavior as to, for example, how
  224. <code>glDrawBuffer</code> interacts with <code>EGL_RENDER_BUFFER</code>. Right
  225. now, it is desired that the draw buffer in a client API be fixed for pixmap and
  226. pbuffer surfaces. Therefore, the driver is responsible to guarantee that the
  227. client API renders to the specified render buffer for pixmap and pbuffer
  228. surfaces.</p>
  229. <h3><code>EGLDisplay</code> Mutex</h3>
  230. The <code>EGLDisplay</code> will be locked before calling any of the dispatch
  231. functions (well, except for GetProcAddress which does not take an
  232. <code>EGLDisplay</code>). This guarantees that the same dispatch function will
  233. not be called with the sample display at the same time. If a driver has access
  234. to an <code>EGLDisplay</code> without going through the EGL APIs, the driver
  235. should as well lock the display before using it.
  236. <h3>TODOs</h3>
  237. <ul>
  238. <li>Pass the conformance tests</li>
  239. <li>Better automatic driver selection: <code>EGL_DISPLAY</code> loads all
  240. drivers and might eat too much memory.</li>
  241. </ul>
  242. </body>
  243. </html>