このシンプルなフレームワーク サービスにより、ベンダー プロセスは、libgui をリンクせずに、HAL 実装で SurfaceFlinger/EGL を使用できるようになります。 AOSP は、完全に機能するこのサービスのデフォルト実装を提供します。ただし、ベンダーはプラットフォーム上でこのサービスを提供するために API も実装する必要があります。
package android.frameworks.automotive.display@1.0; import android.hardware.graphics.bufferqueue@2.0::IGraphicBufferProducer; interface IAutomotiveDisplayProxyService { /** * Gets an IGraphicBufferProducer instance from the service. * * @param id Target's stable display identifier * * @return igbp Returns an IGraphicBufferProducer object, that can be * converted to an ANativeWindow object. */ getIGraphicBufferProducer(uint64_t id) generates (IGraphicBufferProducer igbp); /** * Sets the ANativeWindow, which is associated with the * IGraphicBufferProducer, to be visible and to take over the display. * * @param id Target display ID * * @return success Returns true on success. */ showWindow(uint64_t id) generates (bool success); /** * Sets the ANativeWindow, which is associated with the * IGraphicBufferProducer, to be invisible and to release the control * over display. * * @param id Target display ID * * @return success Returns true on success. */ hideWindow(uint64_t id) generates (bool success); /** * Returns the stable identifiers of all available displays. * * @return ids A list of stable display identifiers. */ getDisplayIdList() generates (vec<uint64_t> ids); /** * Returns the descriptor of the target display. * * @param id Stable ID of a target display. * @return cfg DisplayConfig of the active display. * @return state Current state of the active display. */ getDisplayInfo(uint64_t id) generates (HwDisplayConfig cfg, HwDisplayState state); }
このサービスを使用するには:
-
IAutomotiveDisplayProxyService
を取得します。android::sp<IAutomotiveDisplayProxyService> windowProxyService = IAutomotiveDisplayProxyService::getService("default"); if (windowProxyService == nullptr) { LOG(ERROR) << "Cannot use AutomotiveDisplayProxyService. Exiting."; return 1; }
- サービスからアクティブなディスプレイ情報を取得して解像度を決定します。
// We use the first display in the list as the primary. pWindowProxy->getDisplayInfo(displayId, [this](auto dpyConfig, auto dpyState) { DisplayConfig *pConfig = (DisplayConfig*)dpyConfig.data(); mWidth = pConfig->resolution.getWidth(); mHeight = pConfig->resolution.getHeight(); ui::DisplayState* pState = (ui::DisplayState*)dpyState.data(); if (pState->orientation != ui::ROTATION_0 && pState->orientation != ui::ROTATION_180) { // rotate std::swap(mWidth, mHeight); } LOG(DEBUG) << "Display resolution is " << mWidth << " x " << mHeight; });
-
IAutomotiveDisplayProxyService
からハードウェアIGraphicBufferProducer
(または HIDL GraphicBufferProducer (HGBP)) を取得します:mGfxBufferProducer = pWindowProxy->getIGraphicBufferProducer(displayId); if (mGfxBufferProducer == nullptr) { LOG(ERROR) << "Failed to get IGraphicBufferProducer from " << "IAutomotiveDisplayProxyService."; return false; }
- API
libbufferqueueconverter
を使用して、取得した HGBP からSurfaceHolder
を取得します:mSurfaceHolder = getSurfaceFromHGBP(mGfxBufferProducer); if (mSurfaceHolder == nullptr) { LOG(ERROR) << "Failed to get a Surface from HGBP."; return false; }
- API
libbufferqueueconverter
を使用して、SurfaceHolder
ネイティブ ウィンドウに変換します:mWindow = getNativeWindow(mSurfaceHolder.get()); if (mWindow == nullptr) { LOG(ERROR) << "Failed to get a native window from Surface."; return false; }
- ネイティブ ウィンドウを使用して EGL ウィンドウ サーフェスを作成し、レンダリングします:
// Set up our OpenGL ES context associated with the default display mDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY); if (mDisplay == EGL_NO_DISPLAY) { LOG(ERROR) << "Failed to get egl display"; return false; } ... // Create the EGL render target surface mSurface = eglCreateWindowSurface(mDisplay, egl_config, mWindow, nullptr); if (mSurface == EGL_NO_SURFACE) { LOG(ERROR) << "eglCreateWindowSurface failed."; return false; } ...
-
IAutomotiveDisplayProxyService::showWindow()
を呼び出して、レンダリングされたビューを画面に表示します。このサービスは最も高い優先度を持っているため、常に現在の所有者から画面の制御を引き継ぎます:mAutomotiveDisplayProxyService->showWindow();
実装の詳細については$ANDROID_BUILD_TOP/packages/services/Car/evs/sampleDriver/
のservice.cpp
およびGlWrapper.cpp
を参照してください。
EVS HAL 実装には、以下に太字で表示されている追加ライブラリが必要です。
cc_binary { name: "android.hardware.automotive.evs@1.1-sample", vendor: true, srcs: [ ... ], shared_libs: [ ... "libbufferqueueconverter", "android.hidl.token@1.0-utils", "android.frameworks.automotive.display@1.0", "android.hardware.graphics.bufferqueue@1.0", "android.hardware.graphics.bufferqueue@2.0", ],
マルチディスプレイのサポート
デバイスの列挙を表示し、表示情報を取得します
カメラ デバイスの列挙と同様に、EVS フレームワークは利用可能なディスプレイを列挙するメソッドを提供します。静的ディスプレイ識別子は、タイプロング識別子、下位バイトのディスプレイ ポート情報、および上位ビットのExtended Display IDentification Data
エンコードします。 IAutomotiveDisplayProxyService::getDisplayIdList()
EVS サービスで使用できる物理ローカル ディスプレイのディスプレイ ID のリストを返し、 IEvsEnumerator::getDisplayIdList()
は、ディスプレイが接続されていることが検出されたディスプレイ ポートのリストを返します。リストの最初の ID は常にプライマリ ディスプレイの ID です。
interface IEvsEnumerator extends @1.0::IEvsEnumerator { ... /** * Returns a list of all EVS displays available to the system * * @return displayIds Identifiers of available displays. */ getDisplayIdList() generates (vec<uint8_t> displayIds); };
ターゲット表示デバイスを開く
EVS アプリは、ターゲット ディスプレイ ポート番号を指定して IEvsEnumerator::openDisplay_1_1() を呼び出します。
android::sp<IEvsDisplay> pDisplay = pEvs->openDisplay_1_1(displayId); if (pDisplay.get() == nullptr) { LOG(ERROR) << "EVS Display unavailable. Exiting."; return 1; }
注:一度に使用できるディスプレイは 1 つだけです。つまり、別の EVS クライアントがディスプレイを開くように要求すると、たとえそれらが同じでなくても、現在の EVS クライアントはディスプレイを失います。