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

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