اعتبارًا من 27 آذار (مارس) 2025، ننصحك باستخدام android-latest-release بدلاً من aosp-main لإنشاء AOSP والمساهمة فيه. لمزيد من المعلومات، يُرجى الاطّلاع على التغييرات في AOSP.
تنظيم صفحاتك في مجموعات
يمكنك حفظ المحتوى وتصنيفه حسب إعداداتك المفضّلة.
يستخدم Android واجهة برمجة التطبيقات OpenGL ES (GLES)
لعرض الرسومات. لإنشاء سياقات GLES
وتوفير نظام لعرض النوافذ لعمليات عرض GLES، يستخدم Android
مكتبة EGL. تؤدي طلبات GLES إلى عرض مضلّعات مسطّحة، في حين تؤدي طلبات EGL إلى عرض الرسومات على
الشاشات.
قبل الرسم باستخدام GLES، عليك إنشاء سياق GL. في EGL،
يعني ذلك إنشاء EGLContext وEGLSurface. تنطبق عمليات GLES على
السياق الحالي الذي يتم الوصول إليه من خلال مساحة التخزين المحلية الخاصة بالسلسلة بدلاً من
تمريرها كوسيطة. يجب تنفيذ رمز العرض في سلسلة مهام GLES الحالية،
وليس في سلسلة مهام واجهة المستخدم.
EGLSurfaces
يمكن أن يكون EGLSurface مخزنًا مؤقتًا خارج الشاشة تخصصه EGL، ويُعرف باسم
pbuffer، أو نافذة تخصصها نظام التشغيل. يؤدي استدعاء الدالة
eglCreateWindowSurface() إلى إنشاء مساحات نوافذ EGL.
يأخذ eglCreateWindowSurface()عنصر نافذة كأحد
المَعلمات، وهو سطح على Android. السطح هو جانب المنتج
في BufferQueue. المستخدمون، وهم SurfaceView أو
SurfaceTexture أو TextureView أو ImageReader، ينشئون مساحات العرض.
عند استدعاء eglCreateWindowSurface()، تنشئ EGL عنصرًا جديدًا من نوع
EGLSurface وتربطه بواجهة المنتج في BufferQueue لعنصر
النافذة. ومن تلك النقطة فصاعدًا، يؤدي التقديم إلى EGLSurface
إلى إزالة مخزن مؤقت من قائمة الانتظار وتقديمه إلى قائمة الانتظار لاستخدامه من قِبل العميل.
لا توفّر EGL مكالمات قفل/فتح القفل. أدخِل أوامر الرسم ثمّ اتصل بالرقم eglSwapBuffers() لإرسال الإطار الحالي. ينبع اسم المحاولة
من عملية التبديل التقليدية بين المخزّنين الأمامي والخلفي، ولكن قد يختلف التنفيذ
الحقيقي.
يمكن ربط EGLSurface واحد فقط بسطح في كل مرة (يمكنك استخدام
منتج واحد فقط متصل بـ BufferQueue)، ولكن في حال إتلاف
EGLSurface، سيتم فصله عن BufferQueue والسماح بربط عنصر آخر.
يمكن أن يتبدّل مؤشر تسلسل معيّن بين EGLSurfaces متعددة من خلال تغيير ما هو
حالي. يجب أن يكون EGLSurface حاليًا في سلسلة محادثات واحدة فقط في المرة الواحدة.
EGL ليس جانبًا آخر من سطح العرض (مثل SurfaceHolder). EGLSurface هو مفهوم
مرتبط ولكن مستقل. يمكنك الرسم على EGLSurface غير المستندة
إلى سطح، ويمكنك استخدام سطح بدون EGL. لا يقدّم EGLSurface سوى
مساحة للرسم في GLES.
لإنشاء سطح نافذة EGL من رمز أصلي، عليك تمرير مثيل
EGLNativeWindowType إلى eglCreateWindowSurface(). EGLNativeWindowType هو
مرادف لـ ANativeWindow، لذا يمكنك تحويل أحدهما إلى الآخر.
يخضع كل من المحتوى وعيّنات التعليمات البرمجية في هذه الصفحة للتراخيص الموضحّة في ترخيص استخدام المحتوى. إنّ Java وOpenJDK هما علامتان تجاريتان مسجَّلتان لشركة Oracle و/أو الشركات التابعة لها.
تاريخ التعديل الأخير: 2025-07-27 (حسب التوقيت العالمي المتفَّق عليه)
[[["يسهُل فهم المحتوى.","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 (حسب التوقيت العالمي المتفَّق عليه)"],[],[],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."]]