اعتبارًا من 27 آذار (مارس) 2025، ننصحك باستخدام android-latest-release
بدلاً من aosp-main
لإنشاء AOSP والمساهمة فيه. لمزيد من المعلومات، يُرجى الاطّلاع على التغييرات في AOSP.
بنية الرسومات
تنظيم صفحاتك في مجموعات
يمكنك حفظ المحتوى وتصنيفه حسب إعداداتك المفضّلة.
المعلومات التي يجب أن يعرفها كل مطوِّر عن مساحات العرض وSurfaceHolder
وEGLSurface وSurfaceView وGLSurfaceView وSurfaceTexture وTextureView
وSurfaceFlinger وVulkan
توضِّح هذه الصفحة العناصر الأساسية لبنية الرسومات
على مستوى نظام Android وكيفية استخدامها من قِبل إطار عمل التطبيق ونظام
الوسائط المتعددة. ينصبّ التركيز على كيفية نقل ذاكرات التخزين المؤقت للبيانات الرسومية عبر النظام.
إذا كنت قد تساءلت يومًا عن سبب سلوك SurfaceView وTextureView بالطريقة التي يتصرفان بها،
أو عن كيفية تفاعل surfaces وEGLSurface، فأنت في المكان الصحيح.
من المفترض أن تكون لديك بعض المعرفة بأجهزة Android وتطوير التطبيقات.
لا تحتاج إلى معرفة تفصيلية عن إطار عمل التطبيق، ولا تتم الإشارة إلا إلى عدد قليل جدًا من طلبات بيانات واجهة برمجة التطبيقات، ولكن لا تتداخل المادة مع الوثائق العامة الأخرى. والهدف من ذلك هو تقديم تفاصيل عن الأحداث المهمة
المرتبطة بعرض إطار للإخراج لمساعدتك في اتخاذ خيارات مدروسة
عند تصميم تطبيق. ولتحقيق ذلك، نعمل من الأسفل إلى الأعلى،
ونوضّح طريقة عمل فئات واجهة المستخدم بدلاً من كيفية استخدامها.
يتضمّن هذا القسم عدة صفحات تتناول كل شيء بدءًا من مواد
الخلفية وتفاصيل HAL ووصولاً إلى حالات الاستخدام. يبدأ الدليل بشرح ملفّات التخزين المؤقت لرسومات Android، ويصف آلية التركيب والعرض، ثم ينتقل إلى الآليات ذات المستوى الأعلى التي توفّر البيانات لبرنامج التركيب. ننصح
بقراءة الصفحات بالترتيب المذكور أدناه بدلاً من الانتقال إلى موضوع
يبدو مثيرًا للاهتمام.
المكونات ذات المستوى المنخفض
- BufferQueue و
gralloc تربط فئة BufferQueue بين عنصر ينشئ وحدات تخزين مؤقتة لبيانات الرسومات (المُنشئ) وعنصر يقبل البيانات لعرضها أو معالجتها بشكلٍ إضافي (المستهلك). يتم تنفيذ عمليات تخصيص المخزن المؤقت
من خلال أداة تخصيص الذاكرة gralloc التي يتم تنفيذها من خلال
واجهة HAL الخاصة بالمورّد.
- SurfaceFlinger،
وHardware Composer، والشاشات الافتراضية يقبل SurfaceFlinger مخازن ข้อมูล
من مصادر متعددة ويجمعها ويرسلها إلى الشاشة. تحدِّد واجهة برمجة التطبيقات (HAL) لبرنامج "مُنشئ الأجهزة" (HWC) الطريقة الأكثر فعالية لدمج ملفّات التخزين المؤقت مع الأجهزة المتاحة، وتوفِّر الشاشات الافتراضية ناتجًا مدمجًا
داخل النظام (تسجيل الشاشة أو إرسال الشاشة عبر
الشبكة).
- Surface ولوحة الرسم و
SurfaceHolder تُنشئ المساحة سطحًا ينتج قائمة انتظار للمخازن المؤقتة التي غالبًا ما يستخدمها
SurfaceFlinger. عند العرض على سطح، تنتهي النتيجة في ذاكرة تخزين مؤقت
تُرسَل إلى المستهلك. توفّر واجهات برمجة تطبيقات Canvas تنفيذًا للبرامج
(مع دعم التسارع بالأجهزة) للرسم مباشرةً على سطح
(بديل منخفض المستوى لـ OpenGL ES). أيّ شيء يتعلّق بالعرض يتضمن
SurfaceHolder، وتتيح واجهات برمجة التطبيقات الخاصة به الحصول على مَعلمات السطح وضبطها، مثل
الحجم والتنسيق.
- EGLSurface و
OpenGL ES OpenGL ES (GLES): تحدِّد هذه الواجهة واجهة برمجة تطبيقات لعرض الرسومات مصمّمة للدمج مع EGL، وهي مكتبة يمكنها إنشاء النوافذ والوصول إليها من خلال نظام التشغيل (لرسم المضلّعات المزخرفة، استخدِم طلبات GLES، ولعرض الرسومات على الشاشة، استخدِم طلبات EGL). تتناول هذه الصفحة أيضًا ANativeWindow، وهو مكافئ C/C++ لفئة Java Surface المستخدَمة لإنشاء سطح EGL
window من الرمز البرمجي الأصلي.
- Vulkan Vulkan هي
واجهة برمجة تطبيقات متعددة المنصات ذات تكلفة منخفضة للرسومات الثلاثية الأبعاد العالية الأداء. مثل OpenGL
ES، يوفّر Vulkan أدوات لإنشاء رسومات عالية الجودة في الوقت الفعلي في التطبيقات. تشمل مزايا Vulkan تقليل النفقات العامة لوحدة المعالجة المركزية ودعم
لغة SPIR-V Binary Intermediate.
المكوّنات عالية المستوى
- SurfaceView و
GLSurfaceView تجمع SurfaceView بين مساحة عرض وعرض. يُجمِّع SurfaceFlinger (وليس التطبيق) مكوّنات عرض SurfaceView، ما يتيح عرضها من سلسلة مهام أو عملية منفصلة وعزلها عن عرض واجهة المستخدم للتطبيق.
توفّر GLSurfaceView فئات مساعدة لإدارة سياقات EGL والتواصل بين مؤشرات الترابط والتفاعل مع دورة نشاط التطبيق (ولكن ليس مطلوبًا استخدام GLES).
- SurfaceTexture:
يجمع SurfaceTexture بين مساحة العرض وسطح GLES لإنشاء BufferQueue
يكون تطبيقك هو المستخدِم له. عندما يضيف مُنشئ محتوى عنصر تخزين مؤقت جديد إلى "قائمة الانتظار"، يُرسِل إشعارًا
إلى تطبيقك الذي بدوره يُطلق عنصر التخزين المؤقت الذي كان يحتفظ به سابقًا، ويحصل على عنصر التخزين المؤقت الجديد
من "قائمة الانتظار"، ويُجري طلبات إلى EGL لإتاحة عنصر التخزين المؤقت لـ GLES
كنسيج خارجي. أضاف نظام التشغيل Android 7.0 ميزة تشغيل فيديوهات رسومات كثيفة
وآمنة تتيح لوحدة معالجة الرسومات إجراء معالجة لاحقة لمحتوى الفيديو المحمي.
- TextureView:
يجمع TextureView بين عرض وSurfaceTexture. يُغلِّف TextureView عنصر
SurfaceTexture ويتحمّل مسؤولية الاستجابة لطلبات إعادة الاتصال و
الحصول على وحدات تخزين مؤقتة جديدة. عند الرسم، يستخدم TextureView محتويات آخر
مخزن مؤقت تم استلامه كمصدر بياناته، ويتم عرضها في أي مكان وبأي شكل تشير إليه
حالة العرض. يتم تنفيذ تركيب العرض دائمًا باستخدام GLES،
ما يعني أنّ التعديلات على المحتوى قد تؤدي إلى إعادة رسم عناصر العرض الأخرى أيضًا.
يخضع كل من المحتوى وعيّنات التعليمات البرمجية في هذه الصفحة للتراخيص الموضحّة في ترخيص استخدام المحتوى. إنّ 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,["# Graphics architecture\n\n*What every developer should know about surfaces, SurfaceHolder,\nEGLSurface, SurfaceView, GLSurfaceView, SurfaceTexture, TextureView,\nSurfaceFlinger, and Vulkan.*\n\nThis page describes essential elements of the Android system-level graphics\narchitecture and how they are used by the app framework and multimedia\nsystem. The focus is on how buffers of graphical data move through the system.\nIf you've ever wondered why SurfaceView and TextureView behave the way they do,\nor how surfaces and EGLSurface interact, you're in the correct place.\n\nSome familiarity with Android devices and app development is assumed.\nYou don't need detailed knowledge of the app framework and very few API calls\nare mentioned, but the material doesn't overlap with other public\ndocumentation. The goal is to provide details on the significant events\ninvolved in rendering a frame for output to help you make informed choices\nwhen designing an app. To achieve this, we work from the bottom up,\ndescribing how the UI classes work rather than how they can be used.\n\nThis section includes several pages covering everything from background\nmaterial to HAL details to use cases. It starts with an explanation of Android\ngraphics buffers, describes the composition and display mechanism, then proceeds\nto the higher-level mechanisms that supply the compositor with data. We\nrecommend reading pages in the order listed below rather than skipping to a\ntopic that sounds interesting.\n\nLow-level components\n--------------------\n\n- [BufferQueue and\n gralloc](/docs/core/graphics/arch-bq-gralloc). BufferQueue connects something that generates buffers of graphical data (the *producer* ) to something that accepts the data for display or further processing (the *consumer* ). Buffer allocations are performed through the *gralloc* memory allocator implemented through a vendor-specific HAL interface.\n- [SurfaceFlinger,\n Hardware Composer, and virtual displays](/docs/core/graphics/arch-sf-hwc). SurfaceFlinger accepts buffers of data from multiple sources, composites them, and sends them to the display. The Hardware Composer HAL (HWC) determines the most efficient way to composite buffers with the available hardware, and virtual displays make composited output available within the system (recording the screen or sending the screen over a network).\n- [Surface, canvas, and\n SurfaceHolder](/docs/core/graphics/arch-sh). A surface produces a buffer queue that is often consumed by SurfaceFlinger. When rendering onto a surface, the result ends up in a buffer that gets shipped to the consumer. Canvas APIs provide a software implementation (with hardware-acceleration support) for drawing directly on a surface (low-level alternative to OpenGL ES). Anything having to do with a view involves a SurfaceHolder, whose APIs enable getting and setting surface parameters such as size and format.\n- [EGLSurface and\n OpenGL ES](/docs/core/graphics/arch-egl-opengl). [OpenGL ES (GLES)](https://www.khronos.org/opengles/) defines a graphics-rendering API designed to be combined with [EGL](https://www.khronos.org/egl), a library that can create and access windows through the operating system (to draw textured polygons, use GLES calls; to put rendering on the screen, use EGL calls). This page also covers ANativeWindow, the C/C++ equivalent of the Java Surface class used to create an EGL window surface from native code.\n- [Vulkan](/docs/core/graphics/arch-vulkan). Vulkan is a low-overhead, cross-platform API for high-performance 3D graphics. Like OpenGL ES, Vulkan provides tools for creating high-quality, real-time graphics in apps. Vulkan advantages include reductions in CPU overhead and support for the [SPIR-V Binary Intermediate](https://www.khronos.org/spir) language.\n\nHigh-level components\n---------------------\n\n- [SurfaceView and\n GLSurfaceView](/docs/core/graphics/arch-sv-glsv). SurfaceView combines a surface and a view. SurfaceView's view components are composited by SurfaceFlinger (and not the app), enabling rendering from a separate thread/process and isolation from app UI rendering. GLSurfaceView provides helper classes to manage EGL contexts, interthread communication, and interaction with the activity lifecycle (but isn't required to use GLES).\n- [SurfaceTexture](/docs/core/graphics/arch-st). SurfaceTexture combines a surface and GLES texture to create a BufferQueue for which your app is the consumer. When a producer queues a new buffer, it notifies your app, which in turn releases the previously-held buffer, acquires the new buffer from the queue, and makes EGL calls to make the buffer available to GLES as an external texture. Android 7.0 added support for secure texture video playback enabling GPU post-processing of protected video content.\n- [TextureView](/docs/core/graphics/arch-tv). TextureView combines a view with a SurfaceTexture. TextureView wraps a SurfaceTexture and takes responsibility for responding to callbacks and acquiring new buffers. When drawing, TextureView uses the contents of the most recently received buffer as its data source, rendering wherever and however the view state indicates it should. View composition is always performed with GLES, meaning updates to contents may cause other view elements to redraw as well."]]