EGL and GLES

libEGL.so serves the guest's native code and Java's EGL10 alike (snx.android.opengl.Egl10, the JSR 239 EGL that GLSurfaceView uses): both reach the same objects in hle_egl.c, so a context and a surface that Java makes current are current for the native GLES calls of the same thread, as on Android.

Both GLES libraries export most of their names twice (glDrawArrays, glClear): hle.c makes one export of each such name, which calls the current context's.

gles_vk.c is the Vulkan app that both share. It makes the instance, surface, device, queue and swapchain, and presents, through the pass-through's commands (hle_vulkan_host.h), so its presents get the renderer's layer and --shot's copies as a guest's own Vulkan presents do. The device is Vulkan 1.3 where the host has it, with dynamic rendering, and VK_EXT_depth_clip_control and VK_EXT_index_type_uint8 where the device has them. A frame is one command buffer of a slot, recorded as the calls come, and two slots are in flight. Each submission has a serial: an object that a frame may still use goes when its serial completed. A call that must see the GPU's results (glReadPixels, glFinish, glClientWaitSync) submits what the frame recorded so far and waits for it, and the frame goes on in the same command buffer. Between passes an acquired image is in PRESENT_SRC_KHR, so GLES 1.1's render passes and GLES 2's dynamic rendering can share a frame.

GLES 1.1 (hle_gles.c) is the fixed function. A draw goes into a render pass on the swapchain image, or on a pbuffer's image, which rests in COLOR_ATTACHMENT_OPTIMAL between passes as GLES 2 keeps it. A texture upload ends the pass, copies from a staging buffer and starts the pass again (loading what it drew), so each draw reads the texture as it was at its call. The client arrays of a draw are converted into one vertex format (position, texture coordinate and color as floats) in a buffer of the frame, as triangle, line or point lists. GL's window origin is the bottom left: the viewport has a negative height, so GL's viewport, scissor and glDrawTexOES coordinates are used as they are. A texture of 3-byte texels on a device that cannot sample that format is an RGBA8 image, which a compute shader (gles_rgb.comp) writes from the packed rows. It does 2D textures (the base level) in GLES 1.1's formats, the texture environment of unit 0, the matrix stacks, glDrawArrays, glDrawElements, glDrawTexOES, blending, the scissor, glClear and glReadPixels of RGBA bytes (the frame's image copied into its staging buffer, the frame submitted and waited for). It does not do yet: depth and stencil tests, lighting, fog, the alpha test, mipmaps and the second texture unit.

GLES 2, 3.0 and 3.1 (gles2.c, gles2_object.c, gles2_program.c, gles2_draw.c) are done as Mesa's zink does them:

What GLES 2 and 3 do not do yet: transform feedback, GLES 3.1's atomic counters and its buffer variables in the interface queries, glFramebufferParameteri, GLES 3.2's geometry and tessellation, its indexed blending and color masks, texture buffers, sample shading and border colors, a divisor past 1, glClear of an integer color buffer with a partial color mask (it clears every channel), client depth and stencil texels for a 24-bit depth texture, ETC2 and ASTC on a device that has neither (the decode on the GPU), glReadPixels of a format other than RGBA or BGRA bytes, program binaries, and a pbuffer bound as a texture. glClear with a partial color mask, or a stencil write mask of part of the bits, draws what Vulkan's clears cannot (they write every channel and bit): a triangle over the target with the clear color and the masks in its pipeline (gles2_clear.vert, gles2_clear.frag), no test and no blend, in the scissor's rectangle.

libz.so is the build's own zlib (hle_zlib.c): z_stream has the guest's layout on an LP64 host, and a stream's allocator, when the guest gives one, is called through the bridge. Windows' uLong is 32 bits, so Windows has no zlib for the guest yet.

libicuuc.so and libicui18n.so are the host's own ICU (hle_icu.c), loaded when the guest opens them. They are not NDK libraries: an app reaches them by dlopen and dlsym, as .NET's System.Globalization.Native does, which looks for u_strlen with each version's suffix (u_strlen_76) and then takes every function by that suffix. The guest gets the host's version, and where the host's ICU was built without the suffixes (FreeBSD's) each name is looked up without it. ICU's C API takes and returns integers, pointers and UDate doubles, which pass in registers as they are; a UBool argument is extended and a UBool result cut to its byte. Windows passes arguments by position, which would need each function's signature, so there the guest finds no ICU (and .NET stops).


Made from docs/platforms/android-apps/native.md at 69237645142c. GPL-3.0-or-later.