Este serviço de estrutura simples permite que os processos do fornecedor usem SurfaceFlinger/EGL em implementações HAL, sem vincular libgui. AOSP fornece a implementação padrão deste serviço, que é totalmente funcional. No entanto, o fornecedor também deve implementar APIs para fornecer este serviço na sua plataforma.
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); }
Para usar este serviço:
- Obtenha
IAutomotiveDisplayProxyService
.android::sp<IAutomotiveDisplayProxyService> windowProxyService = IAutomotiveDisplayProxyService::getService("default"); if (windowProxyService == nullptr) { LOG(ERROR) << "Cannot use AutomotiveDisplayProxyService. Exiting."; return 1; }
- Recupere informações de exibição ativa do serviço para determinar a resolução.
// 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; });
- Recupere um
IGraphicBufferProducer
de hardware (ou HIDL GraphicBufferProducer (HGBP) deIAutomotiveDisplayProxyService
:mGfxBufferProducer = pWindowProxy->getIGraphicBufferProducer(displayId); if (mGfxBufferProducer == nullptr) { LOG(ERROR) << "Failed to get IGraphicBufferProducer from " << "IAutomotiveDisplayProxyService."; return false; }
- Obtenha um
SurfaceHolder
de um HGBP recuperado, usando a APIlibbufferqueueconverter
:mSurfaceHolder = getSurfaceFromHGBP(mGfxBufferProducer); if (mSurfaceHolder == nullptr) { LOG(ERROR) << "Failed to get a Surface from HGBP."; return false; }
- Converta um
SurfaceHolder
em uma janela nativa usando a APIlibbufferqueueconverter
:mWindow = getNativeWindow(mSurfaceHolder.get()); if (mWindow == nullptr) { LOG(ERROR) << "Failed to get a native window from Surface."; return false; }
- Crie uma superfície de janela EGL com uma janela nativa e depois renderize:
// 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; } ...
- Chame
IAutomotiveDisplayProxyService::showWindow()
para exibir a visualização renderizada na tela. Este serviço tem a maior prioridade e, portanto, sempre assume o controle da tela do proprietário atual:mAutomotiveDisplayProxyService->showWindow();
Consulte service.cpp
e GlWrapper.cpp
em $ANDROID_BUILD_TOP/packages/services/Car/evs/sampleDriver/
para obter mais detalhes de implementação.
Uma implementação EVS HAL requer as bibliotecas adicionais exibidas em negrito abaixo.
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", ],
Suporte para vários monitores
Exibir enumeração de dispositivos e recuperar informações de exibição
Assim como a enumeração de dispositivos de câmera, a estrutura EVS fornece um método para enumerar as exibições disponíveis. O identificador de exibição estático codifica um identificador de tipo longo, as informações da porta de exibição no byte inferior e Extended Display IDentification Data
nos bits superiores. IAutomotiveDisplayProxyService::getDisplayIdList()
retorna uma lista de IDs de exibição de monitores físicos locais, que estão disponíveis para o serviço EVS, e IEvsEnumerator::getDisplayIdList()
retorna uma lista de portas de exibição às quais os monitores detectados estão conectados. O primeiro ID na lista é sempre do display principal.
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); };
Abra o dispositivo de exibição de destino
O aplicativo EVS chama IEvsEnumerator::openDisplay_1_1() com um número de porta de exibição de destino:
android::sp<IEvsDisplay> pDisplay = pEvs->openDisplay_1_1(displayId); if (pDisplay.get() == nullptr) { LOG(ERROR) << "EVS Display unavailable. Exiting."; return 1; }
Nota: Apenas um único monitor pode estar em uso de cada vez, o que significa que o cliente EVS atual perde o seu monitor quando outro cliente EVS solicita a abertura do monitor, mesmo quando não são iguais.