2025년 3월 27일부터 AOSP를 빌드하고 기여하려면 aosp-main
대신 android-latest-release
를 사용하는 것이 좋습니다. 자세한 내용은 AOSP 변경사항을 참고하세요.
SurfaceFlinger 및 WindowManager
컬렉션을 사용해 정리하기
내 환경설정을 기준으로 콘텐츠를 저장하고 분류하세요.
SurfaceFlinger는 버퍼를 받아들이고 버퍼를 구성하며 버퍼를 디스플레이로 보냅니다. WindowManager
는 SurfaceFlinger가 노출 영역을 디스플레이에 합성하는 데 사용하는 버퍼 및 창 메타데이터를 SurfaceFlinger에 제공합니다.
SurfaceFlinger
SurfaceFlinger는 BufferQueue 및 SurfaceControl
를 통해 또는 ASurfaceControl
를 통해 버퍼를 수락할 수 있습니다.
SurfaceFlinger가 버퍼를 수락하는 한 가지 방법은 BufferQueue 및 SurfaceControl
를 통해서입니다. 앱이 포그라운드로 오면 WindowManager
에 버퍼를 요청합니다. 그런 다음 WindowManager
는 SurfaceFlinger에 레이어를 요청합니다. 레이어는 BufferQueue가 포함된 노출 영역과 디스플레이 프레임과 같은 레이어 메타데이터가 포함된 SurfaceControl
인스턴스의 조합입니다.
SurfaceFlinger는 레이어를 생성하여 WindowManager
로 보냅니다. 그런 다음 WindowManager
가 노출 영역을 앱으로 전송하지만 SurfaceControl
인스턴스를 유지하여 화면에서 앱의 모양을 조작합니다.
Android 10에는 SurfaceFlinger가 버퍼를 수락할 수 있는 또 다른 방법인 ASurfaceControl
가 추가됩니다. ASurfaceControl
는 노출 영역과 SurfaceControl
인스턴스를 SurfaceFlinger로 전송되는 하나의 트랜잭션 패키지로 결합합니다. ASurfaceControl
는 앱이 ASurfaceTransaction
인스턴스를 통해 업데이트하는 레이어와 연결됩니다. 그런 다음 앱은 래치 시간, 획득 시간 등의 정보가 포함된 ASurfaceTransactionStats
를 전달하는 콜백을 통해 ASurfaceTransaction
인스턴스에 관한 정보를 가져옵니다.
다음 표에는 ASurfaceControl
및 관련 구성요소에 관한 자세한 내용이 나와 있습니다.
구성요소 |
설명 |
ASurfaceControl |
SurfaceControl 를 래핑하고 앱이 디스플레이의 레이어에 부합하는 SurfaceControl 인스턴스를 만들 수 있게 합니다.
ANativeWindow 의 하위 요소 또는 다른 ASurfaceControl 인스턴스의 하위 요소로 생성될 수 있습니다. |
ASurfaceTransaction |
Transaction 를 래핑하여 클라이언트가 도형과 같은 레이어의 설명적 속성을 수정할 수 있도록 하고 업데이트된 버퍼를 SurfaceFlinger로 전송합니다. |
ASurfaceTransactionStats
| 래치 시간, 획득 시간 및 이전 릴리스 펜스와 같이 표시된 트랜잭션에 관한 정보를 사전 등록된 콜백을 통해 앱에 전송합니다. |
앱은 버퍼를 언제든지 제출할 수 있지만 SurfaceFlinger는 디스플레이 새로고침 사이에만(기기마다 다를 수 있음) 절전 모드에서 해제되어 버퍼를 받아들입니다. 이를 통해 메모리 사용량을 최소화하고 새로고침 중간에 디스플레이를 업데이트할 때 발생할 수 있는 화면 테어링 현상을 방지할 수 있습니다.
디스플레이가 새로고침 사이에 있을 때 VSync 신호를 SurfaceFlinger로 전송합니다. VSync 신호는 디스플레이가 테어링 현상 없이 새로고침될 수 있음을 나타냅니다. SurfaceFlinger가 VSync 신호를 수신하면 SurfaceFlinger는 레이어 목록을 탐색하여 새 버퍼를 찾습니다. SurfaceFlinger가 새로운 버퍼를 찾으면 SurfaceFlinger는 버퍼를 획득합니다. 새 버퍼를 찾지 못하면 SurfaceFlinger는 이전에 획득한 버퍼를 계속 사용합니다. SurfaceFlinger는 항상 무언가를 표시해야 하므로 하나의 버퍼를 계속 유지합니다. 제출된 버퍼가 없는 레이어는 무시됩니다.
SurfaceFlinger는 보이는 레이어의 모든 버퍼를 수집한 후 하드웨어 컴포저(HWC)에 합성을 어떻게 실행할지 묻습니다. HWC가 레이어 합성 유형을 클라이언트 합성으로 표시하면 SurfaceFlinger가 이러한 레이어를 합성합니다. 그런 다음 SurfaceFlinger는 출력 버퍼를 HWC에 전달합니다.
WindowManager
WindowManager
는 View
객체의 컨테이너인 Window
객체를 제어합니다. Window
객체는 항상 Surface
객체에 의해 지원됩니다.
WindowManager
는 수명 주기, 입력 및 포커스 이벤트, 화면 방향, 전환, 애니메이션, 위치, 변환, Z-order 및 창의 기타 여러 측면을 관리합니다. WindowManager
는 모든 창 메타데이터를 SurfaceFlinger로 전송하므로 SurfaceFlinger는 이 데이터를 사용하여 디스플레이의 노출 영역을 합성할 수 있습니다.
사전 회전
다수의 하드웨어 오버레이는 회전을 지원하지 않지만, 지원하더라도 처리 전력을 소모합니다. 따라서 버퍼가 SurfaceFlinger에 도달하기 전에 버퍼를 변환하는 것이 해결책입니다. Android는 ANativeWindow
의 쿼리 힌트(NATIVE_WINDOW_TRANSFORM_HINT
)를 지원하여 SurfaceFlinger가 버퍼에 적용할 가능성이 가장 큰 변환을 나타냅니다. GL 드라이버는 이 힌트를 사용해 버퍼가 SurfaceFlinger에 도달하기 전에 버퍼를 사전 변환하여 버퍼가 도착할 때 올바르게 변환되도록 할 수 있습니다.
예를 들어 90도 회전 힌트를 수신하면 매트릭스를 생성하여 버퍼에 적용함으로써 버퍼가 페이지 끝을 벗어나서 실행되지 않도록 합니다. 전력을 절약하려면 이 사전 회전을 사용하세요. 자세한 내용은 system/core/include/system/window.h
에 정의된 ANativeWindow
인터페이스를 참고하세요.
이 페이지에 나와 있는 콘텐츠와 코드 샘플에는 콘텐츠 라이선스에서 설명하는 라이선스가 적용됩니다. 자바 및 OpenJDK는 Oracle 및 Oracle 계열사의 상표 또는 등록 상표입니다.
최종 업데이트: 2025-07-27(UTC)
[[["이해하기 쉬움","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,["# SurfaceFlinger and WindowManager\n\nSurfaceFlinger accepts buffers, composes buffers, and sends buffers to the\ndisplay. `WindowManager` provides SurfaceFlinger with buffers and window\nmetadata, which SurfaceFlinger uses to composite surfaces to the display.\n\nSurfaceFlinger\n--------------\n\nSurfaceFlinger can accept buffers in two ways: through BufferQueue and\n`SurfaceControl`, or through `ASurfaceControl`.\n\nOne way SurfaceFlinger accepts buffers is through BufferQueue and\n`SurfaceControl`. When an app comes to the foreground, it requests buffers from\n[`WindowManager`](https://developer.android.com/reference/android/view/WindowManager.html). `WindowManager` then requests a layer from\nSurfaceFlinger. A layer is a combination of a [surface](/docs/core/graphics/arch-sh), which contains the BufferQueue, and\na [`SurfaceControl`](https://developer.android.com/reference/android/view/SurfaceControl) instance,\nwhich contains the layer metadata like the display frame.\nSurfaceFlinger creates the layer and sends it to `WindowManager`. `WindowManager`\nthen sends the surface to the app, but keeps the `SurfaceControl` instance to\nmanipulate the appearance of the app on the screen.\n\nAndroid 10 adds `ASurfaceControl`, which is another\nway that SurfaceFlinger can accept buffers. `ASurfaceControl` combines a surface\nand a `SurfaceControl` instance into one transaction package that is sent to\nSurfaceFlinger. `ASurfaceControl` is associated with a layer, which apps\nupdate through `ASurfaceTransaction` instances. Apps then get information about\n`ASurfaceTransaction` instances through callbacks that pass `ASurfaceTransactionStats`\ncontaining information, such as latch time, acquire times, and so on.\n\nThe following table includes more details about `ASurfaceControl` and its\nassociated components:\n\n| Component | Description |\n|----------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `ASurfaceControl` | Wraps `SurfaceControl` and enables an app to create `SurfaceControl` instances that correspond to layers on the display. Can be created as a child of `ANativeWindow` or as a child of another `ASurfaceControl` instance. |\n| `ASurfaceTransaction` | Wraps `Transaction` to enable the client to edit a layer's descriptive properties, such as geometry, and sends the updated buffers to SurfaceFlinger. |\n| `ASurfaceTransactionStats` | Sends information about transactions that have been presented, such as latch time, acquire times, and previous release fence, to an app through a preregistered callback. |\n\nThough apps can submit buffers at any time, SurfaceFlinger only wakes up to\naccept buffers between display refreshes, which can differ depending on the\ndevice. This minimizes memory usage and avoids visible tearing on the\nscreen, which can occur when updating the display mid-refresh.\n\nWhen the display is between refreshes, the display sends the VSync\nsignal to SurfaceFlinger. The VSync signal indicates that the display can be\nrefreshed without tearing. When SurfaceFlinger receives the VSync signal, SurfaceFlinger\nwalks through its list of layers looking for new buffers. If SurfaceFlinger finds a\nnew buffer, SurfaceFlinger acquires the buffer; if not, SurfaceFlinger continues\nto use the previously acquired buffer. SurfaceFlinger must always display something,\nso it hangs on to one buffer. If no buffers have ever been submitted on a\nlayer, the layer is ignored.\n\nAfter SurfaceFlinger has collected all buffers for visible layers, it asks\nthe Hardware Composer (HWC) how composition should be performed. If the HWC\nmarks layer composition type as client composition, SurfaceFlinger composites those\nlayers. Then, SurfaceFlinger passes the output buffer to the [HWC](/docs/core/graphics/implement-hwc).\n\nWindowManager\n-------------\n\n`WindowManager` controls [`Window`](https://developer.android.com/reference/android/view/Window) objects,\nwhich are containers for [`View`](https://developer.android.com/reference/android/view/View)\nobjects. `Window` objects are always backed by\n[`Surface`](https://developer.android.com/reference/android/view/Surface) objects.\n`WindowManager` oversees lifecycles, input and focus\nevents, screen orientation, transitions, animations, position, transforms,\nz-order, and many other aspects of a window. `WindowManager` sends all of the\nwindow metadata to SurfaceFlinger so SurfaceFlinger can use that data to\ncomposite surfaces on the display.\n\n### Pre-rotation\n\nMany hardware overlays don't support rotation (and even if they do, it costs\nprocessing power); the solution is to transform the buffer before it reaches\nSurfaceFlinger. Android supports a query hint\n(`NATIVE_WINDOW_TRANSFORM_HINT`) in `ANativeWindow` to\nrepresent the most likely transform to be applied to the buffer by\nSurfaceFlinger. GL drivers can use this hint to pre-transform the buffer\nbefore it reaches SurfaceFlinger so that when the buffer arrives, it's correctly\ntransformed.\n\nFor example, when receiving a hint to rotate 90 degrees, generate and apply a\nmatrix to the buffer to prevent it from running off the end of the page. To save\npower, do this pre-rotation. For details, see the `ANativeWindow`\ninterface defined in `system/core/include/system/window.h`."]]