Dzięki tej prostej usłudze platformy dostawcy usług procesy używają SurfaceFlinger/EGL w implementacjach HAL bez łączenia libgui. AOSP udostępnia domyślną implementację tej usługi, która jest w pełni i funkcjonalność. Aby udostępnić tę usługę, dostawca musi też wdrożyć interfejsy API. na swojej platformie.
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);
}
Aby korzystać z tej usługi:
- Pobierz
IAutomotiveDisplayProxyService
.android::sp<IAutomotiveDisplayProxyService> windowProxyService =
IAutomotiveDisplayProxyService::getService("default");
if (windowProxyService == nullptr) {
LOG(ERROR) << "Cannot use AutomotiveDisplayProxyService. Exiting.";
return 1;
} - Aby określić rozdzielczość, pobierz z usługi informacje o aktywnym wyświetlaczu.
// 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;
}); - Pobierz sprzęt
IGraphicBufferProducer
(lub HIDL GraphicBufferProducer (HGBP) w firmieIAutomotiveDisplayProxyService
:mGfxBufferProducer = pWindowProxy->getIGraphicBufferProducer(displayId);
if (mGfxBufferProducer == nullptr) {
LOG(ERROR) << "Failed to get IGraphicBufferProducer from "
<< "IAutomotiveDisplayProxyService.";
return false;
} - Uzyskaj
SurfaceHolder
z pobranego HGBP przy użyciu interfejsu APIlibbufferqueueconverter
:mSurfaceHolder = getSurfaceFromHGBP(mGfxBufferProducer);
if (mSurfaceHolder == nullptr) {
LOG(ERROR) << "Failed to get a Surface from HGBP.";
return false;
} - Przekonwertuj
SurfaceHolder
w okno natywne za pomocąlibbufferqueueconverter
API:mWindow = getNativeWindow(mSurfaceHolder.get());
if (mWindow == nullptr) {
LOG(ERROR) << "Failed to get a native window from Surface.";
return false;
} - Utwórz powierzchnię okna EGL z natywnym oknem, a następnie wyrenderuj:
// 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;
}
... - Zadzwoń pod numer
IAutomotiveDisplayProxyService::showWindow()
do wyświetlić na ekranie wyrenderowany widok. Ta usługa ma najwyższy priorytet oraz dlatego zawsze przejmuje kontrolę nad ekranem od obecnego właściciela:mAutomotiveDisplayProxyService->showWindow();
Zobacz service.cpp
i GlWrapper.cpp
w $ANDROID_BUILD_TOP/packages/services/Car/evs/sampleDriver/
dla
o wdrażaniu.
Implementacja danych HAL EVS wymaga dodatkowych bibliotek wyświetlanych w pogrubienie poniżej.
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",
],
Obsługa wielu wyświetlaczy
Wyświetlanie wyliczania urządzeń i pobieranie informacji o wyświetlaniu
Podobnie jak w przypadku wyliczania aparatów, platforma EVS umożliwia
i wyliczać dostępne ekrany.
statycznego identyfikatora wyświetlania koduje identyfikator typu długi,
informacje o porcie w dolnym bajcie i Extended Display IDentification
Data
w górnych bitach.
IAutomotiveDisplayProxyService::getDisplayIdList()
zwraca listę
identyfikatorów wyświetlanych identyfikatorów lokalnych wyświetlaczy, które są dostępne dla usługi EVS;
a IEvsEnumerator::getDisplayIdList()
zwraca listę wartości displayowych
i porty, do których są podłączone wykryte ekrany. Pierwszy identyfikator na liście to zawsze
głównego wyświetlacza.
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);
};
Otwarte urządzenie docelowe
Aplikacja EVS wywołuje metodę IEvsEnumerator::openDisplay_1_1() z wyświetlaczem docelowym numer portu:
android::sp<IEvsDisplay> pDisplay = pEvs->openDisplay_1_1(displayId);
if (pDisplay.get() == nullptr) {
LOG(ERROR) << "EVS Display unavailable. Exiting.";
return 1;
}
Uwaga: w danym momencie można używać tylko jednego wyświetlacza. Oznacza to, że obecny klient EVS traci ekran, gdy inny klient EVS żądania otwarcia wyświetlacza, nawet jeśli nie są identyczne.