This repository defines and implements the following Hardware Driver Interfaces (HDIs) of the display module. The HDIs are classified into the following types:
Figure 1 HDI architecture of the display module
The source code directory structure is as follows:
/drivers/peripheral/display
├── hal # HAL code
│ └── default # Default HDI implementation
├── interfaces # Driver capability APIs provided for upper-layer services
│ └── include # APIs exposed externally
├── test # Test code
│ └── unittest # Unit test code
The display driver provides the Window Manager Service (WMS) with driver capability APIs that can be classified into the DisplayLayer, DisplayGralloc, and DisplayGfx types. By calling these APIs, you can create or destroy a layer, set layer attributes, allocate, release, map, and buffer memory, fill in rectangles, and blit bitmaps.
Table 1 describes major HDIs provided by the display module.
Table 1 Major HDIs of the display module
The core function of this repository is to provide HDIs for upper-layer display system services to implement display driver capabilities.
The following sample code describes how to use the display HDIs:
#include "display_gfx.h"
#include "display_gralloc.h"
#include "display_layer.h"
#include "display_type.h"
#define DEVID 0
DisplayTest g_displayTest;
static GrallocBuffer g_buffer;
static int32_t GetDisplayInterfaces(void)
{
int32_t ret;
ret = LayerInitialize(&g_displayTest.layerFuncs);
if (ret != DISPLAY_SUCCESS || g_displayTest.layerFuncs == NULL) {
HDF_LOGE("initialize layer failed");
return DISPLAY_FAILURE;
}
ret = GrallocInitialize(&g_displayTest.grallocFuncs);
if (ret != DISPLAY_SUCCESS || g_displayTest.layerFuncs == NULL) {
HDF_LOGE("initialize gralloc failed");
return DISPLAY_FAILURE;
}
ret = GfxInitialize(&g_displayTest.gfxFuncs);
if (ret != DISPLAY_SUCCESS || g_displayTest.gfxFuncs == NULL) {
HDF_LOGE("initialize gralloc failed");
return DISPLAY_FAILURE;
}
return DISPLAY_SUCCESS;
}
static int32_t DisplayUninit(void)
{
LayerUninitialize(g_displayTest.layerFuncs);
GrallocUninitialize(g_displayTest.grallocFuncs);
GfxUninitialize(g_displayTest.gfxFuncs);
return DISPLAY_SUCCESS;
}
static void GetLayerInfo(LayerInfo *layInfo)
{
layInfo->width = g_displayTest.displayInfo.width;
layInfo->height = g_displayTest.displayInfo.height;
layInfo->bpp = LAYER_BPP;
layInfo->pixFormat = PIXEL_FMT_RGBA_5551;
layInfo->type = LAYER_TYPE_GRAPHIC;
}
static void WriteDataToBuf(int32_t width, int32_t height, uint16_t *pBuf)
{
int32_t x;
int32_t y;
for (y = ((height / LINE_WIDTH) - LINE_WIDTH); y < ((height / LINE_WIDTH) + LINE_WIDTH); y++) {
for (x = 0; x < width; x++) {
*((uint16_t*)pBuf + y * width + x) = HIFB_RED_1555;
}
}
for (y = 0; y < height; y++) {
for (x = ((width / LINE_WIDTH) - LINE_WIDTH); x < ((width / LINE_WIDTH) + LINE_WIDTH); x++) {
*((uint16_t*)pBuf + y * width + x) = HIFB_RED_1555;
}
}
}
int DisplayServiceSample(void)
{
int32_t ret;
g_displayTest.devId = DEVID;
/* Obtain display driver APIs. */
ret = GetDisplayInterfaces();
if (ret != DISPLAY_SUCCESS) {
HDF_LOGE("get display interfaces ops failed");
return ret;
}
/* Initialize a display device. */
if (g_displayTest.layerFuncs->InitDisplay != NULL) {
ret = g_displayTest.layerFuncs->InitDisplay(g_displayTest.devId);
if (ret != DISPLAY_SUCCESS) {
HDF_LOGE("initialize display failed");
return DISPLAY_FAILURE;
}
}
/* Obtain the display device information. */
if (g_displayTest.layerFuncs->GetDisplayInfo != NULL) {
ret = g_displayTest.layerFuncs->GetDisplayInfo(g_displayTest.devId, &g_displayTest.displayInfo);
if (ret != DISPLAY_SUCCESS) {
HDF_LOGE("get disp info failed");
return DISPLAY_FAILURE;
}
}
/* Open a specific layer of the display device. */
if (g_displayTest.layerFuncs->OpenLayer != NULL) {
LayerInfo layInfo;
GetLayerInfo(&layInfo);
ret = g_displayTest.layerFuncs->OpenLayer(g_displayTest.devId, &layInfo, &g_displayTest.layerId);
if (ret != DISPLAY_SUCCESS) {
HDF_LOGE("open layer failed");
return DISPLAY_FAILURE;
}
}
/* Obtain the buffer of the layer and add data to the buffer. */
if (g_displayTest.layerFuncs->GetLayerBuffer != NULL) {
ret = g_displayTest.layerFuncs->GetLayerBuffer(g_displayTest.devId, g_displayTest.layerId, &g_displayTest.buffer);
if (ret != DISPLAY_SUCCESS) {
HDF_LOGE("get layer buffer failed");
return DISPLAY_FAILURE;
}
uint16_t *pBuf = (uint16_t *)g_displayTest.buffer.data.virAddr;
WriteDataToBuf(g_displayTest.displayInfo.width, g_displayTest.displayInfo.height, pBuf);
}
/* Flush the layer data for display. */
if (g_displayTest.layerFuncs->Flush != NULL) {
ret = g_displayTest.layerFuncs->Flush(g_displayTest.devId, g_displayTest.layerId, &g_displayTest.buffer);
if (ret != DISPLAY_SUCCESS) {
HDF_LOGE("flush layer failed");
return DISPLAY_FAILURE;
}
}
/* Close the specified layer of the display device. */
if (g_displayTest.layerFuncs->CloseLayer != NULL) {
ret = g_displayTest.layerFuncs->CloseLayer(g_displayTest.devId, g_displayTest.layerId);
if (ret != DISPLAY_SUCCESS) {
HDF_LOGE("close layer failed");
return DISPLAY_FAILURE;
}
}
/* Close the display device. */
if (g_displayTest.layerFuncs->DeinitDisplay != NULL) {
ret = g_displayTest.layerFuncs->DeinitDisplay(g_displayTest.devId);
if (ret != DISPLAY_SUCCESS) {
HDF_LOGE("deinit display failed");
return DISPLAY_FAILURE;
}
}
/* Unregister display driver APIs. */
ret = DisplayUninit();
if (ret != DISPLAY_SUCCESS) {
HDF_LOGE("DisplayUninit fail");
return ret;
}
return 0;
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。