[[["わかりやすい","easyToUnderstand","thumb-up"],["問題の解決に役立った","solvedMyProblem","thumb-up"],["その他","otherUp","thumb-up"]],[["必要な情報がない","missingTheInformationINeed","thumb-down"],["複雑すぎる / 手順が多すぎる","tooComplicatedTooManySteps","thumb-down"],["最新ではない","outOfDate","thumb-down"],["翻訳に関する問題","translationIssue","thumb-down"],["サンプル / コードに問題がある","samplesCodeIssue","thumb-down"],["その他","otherDown","thumb-down"]],["最終更新日 2025-07-27 UTC。"],[],[],null,["# EGLSurfaces and OpenGL ES\n\nAndroid uses the [OpenGL ES (GLES)](https://www.khronos.org/opengles/)\nAPI to render graphics. To create GLES contexts\nand provide a windowing system for GLES renderings, Android uses the\n[EGL\nlibrary](https://www.khronos.org/egl). GLES calls render textured polygons, while EGL calls put renderings on\nscreens.\n\nBefore you draw with GLES, you need to create a GL context. In EGL,\nthis means creating an EGLContext and an EGLSurface. GLES operations apply to\nthe current context, which is accessed through thread-local storage rather than\npassed as an argument. Rendering code should execute on a current GLES thread,\nnot the UI thread.\n\nEGLSurfaces\n-----------\n\nThe EGLSurface can be an off-screen buffer allocated by EGL, called a\n*pbuffer* , or a window allocated by the operating system. Calling the\n`eglCreateWindowSurface()` function creates EGL window surfaces.\n`eglCreateWindowSurface()` takes a *window object* as an\nargument, which on Android is a surface. A surface is the *producer*\nside of a BufferQueue. *Consumers* , which are SurfaceView,\nSurfaceTexture, TextureView, or ImageReader, create surfaces.\nWhen you call `eglCreateWindowSurface()`, EGL creates a new\nEGLSurface object and connects it to the producer interface of the window\nobject's BufferQueue. From that point onward, rendering to that EGLSurface\nresults in a buffer being dequeued, rendered into, and queued for use by the\nconsumer.\n\n| Though windows are typically displayed, in this case, the output of an EGLSurface window may not appear on the display.\n\nEGL doesn't provide lock/unlock calls. Issue drawing commands and\nthen call `eglSwapBuffers()` to submit the current frame. The\nmethod name comes from the traditional swap of front and back buffers, but the actual\nimplementation may be different.\n\nOnly one EGLSurface can be associated with a surface at a time (you can have\nonly one producer connected to a BufferQueue), but if you destroy the\nEGLSurface it disconnects from the BufferQueue and lets something else\nconnect.\n\nA given thread can switch between multiple EGLSurfaces by changing what's\n*current*. An EGLSurface must be current on only one thread at a time.\n\nEGL isn't another aspect of a surface (like SurfaceHolder). EGLSurface is a\nrelated but independent concept. You can draw on an EGLSurface that isn't\nbacked by a surface, and you can use a surface without EGL. EGLSurface just\nprovides GLES with a place to draw.\n\nRefer to the Android [Compatibility\nDefinition Document](/docs/compatibility/overview) for OpenGL ES and EGL requirements.\n\nANativeWindow\n-------------\n\nThe public surface class is implemented in the Java programming language. The\nequivalent in C/C++ is the ANativeWindow class, semi-exposed by the [Android NDK](https://developer.android.com/ndk/index.html). You\ncan get the ANativeWindow from a surface with the `ANativeWindow_fromSurface()`\ncall. Just like its Java-language cousin, you can lock it, render in software,\nand unlock-and-post. The basic *native window* type is the producer side of a\nBufferQueue.\n\nTo create an EGL window surface from native code, pass an instance of\nEGLNativeWindowType to `eglCreateWindowSurface()`. EGLNativeWindowType is\na synonym for ANativeWindow, so you can cast one to the other."]]