這項簡單的架構服務 程序會在 HAL 實作中使用 SurfaceFlinger/EGL,但未連結 libgui。Android 開放原始碼計畫提供這項服務的預設實作方式, 以及功能正常運作不過,廠商也必須導入 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;
}); - 擷取硬體
IGraphicBufferProducer
(或者 來自IAutomotiveDisplayProxyService
的 HIDL GraphicBufferProducer (HGBP):mGfxBufferProducer = pWindowProxy->getIGraphicBufferProducer(displayId);
if (mGfxBufferProducer == nullptr) {
LOG(ERROR) << "Failed to get IGraphicBufferProducer from "
<< "IAutomotiveDisplayProxyService.";
return false;
} - 使用 API 從擷取的 HGBP 取得
SurfaceHolder
libbufferqueueconverter
:mSurfaceHolder = getSurfaceFromHGBP(mGfxBufferProducer);
if (mSurfaceHolder == nullptr) {
LOG(ERROR) << "Failed to get a Surface from HGBP.";
return false;
} - 使用
SurfaceHolder
APIlibbufferqueueconverter
: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();
請參閱《service.cpp
》和《GlWrapper.cpp
》
在$ANDROID_BUILD_TOP/packages/services/Car/evs/sampleDriver/
搜尋
更多實作詳細資料
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 架構與相機裝置列舉一樣,提供了
列舉可用的螢幕。
靜態顯示 ID 對類型為類型 ID 編碼
以小寫位元組和 Extended Display IDentification
Data
表示。
IAutomotiveDisplayProxyService::getDisplayIdList()
會傳回清單
實體本地螢幕的顯示 ID,這類螢幕適用於 EVS 服務
且 IEvsEnumerator::getDisplayIdList()
會傳回顯示內容清單
偵測到的螢幕已連線清單中第一個 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;
}
注意:一次只能使用一部螢幕, 這代表目前的 EVS 用戶端在另一個 EVS 用戶端時遺失顯示內容 要求開啟螢幕。