1 /*
2 * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
3 * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without modification,
6 * are permitted provided that the following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright notice, this list of
9 * conditions and the following disclaimer.
10 *
11 * 2. Redistributions in binary form must reproduce the above copyright notice, this list
12 * of conditions and the following disclaimer in the documentation and/or other materials
13 * provided with the distribution.
14 *
15 * 3. Neither the name of the copyright holder nor the names of its contributors may be used
16 * to endorse or promote products derived from this software without specific prior written
17 * permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
23 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
26 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
27 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
28 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
29 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 */
31
32 #include "display_gfx.h"
33 #include "display_gralloc.h"
34 #include "display_layer.h"
35 #include "display_type.h"
36 #include "hdf_log.h"
37 #include "test_demo.h"
38
39 #define DEVID 0
40 #define LAYER_BPP 16
41 #define LINE_WIDTH 2
42 #define HIFB_RED_1555 0xFF
43
44
45 DisplayTest g_displayTest;
46
GetDisplayInterfaces(void)47 static int32_t GetDisplayInterfaces(void)
48 {
49 int32_t ret;
50 ret = LayerInitialize(&g_displayTest.layerFuncs);
51 if (ret != DISPLAY_SUCCESS || g_displayTest.layerFuncs == NULL) {
52 HDF_LOGE("initialize layer failed");
53 return DISPLAY_FAILURE;
54 }
55 ret = GrallocInitialize(&g_displayTest.grallocFuncs);
56 if (ret != DISPLAY_SUCCESS || g_displayTest.grallocFuncs == NULL) {
57 HDF_LOGE("initialize gralloc failed");
58 return DISPLAY_FAILURE;
59 }
60 ret = GfxInitialize(&g_displayTest.gfxFuncs);
61 if (ret != DISPLAY_SUCCESS) {
62 HDF_LOGE("initialize gfx failed");
63 return DISPLAY_FAILURE;
64 }
65 return DISPLAY_SUCCESS;
66 }
67
DisplayUninit(void)68 static int32_t DisplayUninit(void)
69 {
70 LayerUninitialize(g_displayTest.layerFuncs);
71 GrallocUninitialize(g_displayTest.grallocFuncs);
72 GfxUninitialize(g_displayTest.gfxFuncs);
73 return DISPLAY_SUCCESS;
74 }
75
GetLayerInfo(LayerInfo * layInfo)76 static void GetLayerInfo(LayerInfo *layInfo)
77 {
78 layInfo->width = g_displayTest.displayInfo.width;
79 layInfo->height = g_displayTest.displayInfo.height;
80 layInfo->bpp = LAYER_BPP;
81 layInfo->pixFormat = PIXEL_FMT_RGBA_5551;
82 layInfo->type = LAYER_TYPE_GRAPHIC;
83 }
84
WriteDataToBuf(int32_t width,int32_t height,uint16_t * pBuf)85 static void WriteDataToBuf(int32_t width, int32_t height, uint16_t *pBuf)
86 {
87 int32_t x;
88 int32_t y;
89
90 for (y = ((height / LINE_WIDTH) - LINE_WIDTH); y < ((height / LINE_WIDTH) + LINE_WIDTH); y++) {
91 for (x = 0; x < width; x++) {
92 *((uint16_t*)pBuf + y * width + x) = HIFB_RED_1555;
93 }
94 }
95 for (y = 0; y < height; y++) {
96 for (x = ((width / LINE_WIDTH) - LINE_WIDTH); x < ((width / LINE_WIDTH) + LINE_WIDTH); x++) {
97 *((uint16_t*)pBuf + y * width + x) = HIFB_RED_1555;
98 }
99 }
100
101 }
102
DisplayServiceSample(void)103 int DisplayServiceSample(void)
104 {
105 int32_t ret;
106 g_displayTest.devId = DEVID;
107
108 /* 获取display驱动接口 */
109 ret = GetDisplayInterfaces();
110 if (ret != DISPLAY_SUCCESS) {
111 HDF_LOGE("get display interfaces ops failed");
112 return ret;
113 }
114
115 /* 初始化显示设备 */
116 if (g_displayTest.layerFuncs->InitDisplay != NULL) {
117 ret = g_displayTest.layerFuncs->InitDisplay(g_displayTest.devId);
118 if (ret != DISPLAY_SUCCESS) {
119 HDF_LOGE("initialize display failed");
120 return DISPLAY_FAILURE;
121 }
122 }
123
124 /* 获取显示设备的信息 */
125 if (g_displayTest.layerFuncs->GetDisplayInfo != NULL) {
126 ret = g_displayTest.layerFuncs->GetDisplayInfo(g_displayTest.devId, &g_displayTest.displayInfo);
127 if (ret != DISPLAY_SUCCESS) {
128 HDF_LOGE("get disp info failed");
129 return DISPLAY_FAILURE;
130 }
131 }
132
133 /* 打开显示设备的特定图层 */
134 if (g_displayTest.layerFuncs->CreateLayer != NULL) {
135 LayerInfo layInfo;
136 GetLayerInfo(&layInfo);
137 ret = g_displayTest.layerFuncs->CreateLayer(g_displayTest.devId, &layInfo, &g_displayTest.layerId);
138 if (ret != DISPLAY_SUCCESS) {
139 HDF_LOGE("open layer failed");
140 return DISPLAY_FAILURE;
141 }
142 }
143
144 /* 获取图层buffer并填充buffer */
145 if (g_displayTest.layerFuncs->GetLayerBuffer != NULL) {
146 ret = g_displayTest.layerFuncs->GetLayerBuffer(g_displayTest.devId, g_displayTest.layerId, &g_displayTest.buffer);
147 if (ret != DISPLAY_SUCCESS) {
148 HDF_LOGE("get layer buffer failed");
149 return DISPLAY_FAILURE;
150 }
151 uint16_t *pBuf = (uint16_t *)g_displayTest.buffer.data.virAddr;
152 WriteDataToBuf(g_displayTest.displayInfo.width, g_displayTest.displayInfo.height, pBuf);
153 }
154
155 /* 刷新图层数据进行显示 */
156 if (g_displayTest.layerFuncs->Flush != NULL) {
157 ret = g_displayTest.layerFuncs->Flush(g_displayTest.devId, g_displayTest.layerId, &g_displayTest.buffer);
158 if (ret != DISPLAY_SUCCESS) {
159 HDF_LOGE("flush layer failed");
160 return DISPLAY_FAILURE;
161 }
162 }
163
164 return 0;
165 }