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

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