19762338dSopenharmony_ci/*
29762338dSopenharmony_ci * Copyright (c) 2021 Huawei Device Co., Ltd.
39762338dSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
49762338dSopenharmony_ci * you may not use this file except in compliance with the License.
59762338dSopenharmony_ci * You may obtain a copy of the License at
69762338dSopenharmony_ci *
79762338dSopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
89762338dSopenharmony_ci *
99762338dSopenharmony_ci * Unless required by applicable law or agreed to in writing, software
109762338dSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
119762338dSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
129762338dSopenharmony_ci * See the License for the specific language governing permissions and
139762338dSopenharmony_ci * limitations under the License.
149762338dSopenharmony_ci */
159762338dSopenharmony_ci
169762338dSopenharmony_ci#include "display_test.h"
179762338dSopenharmony_ci#include <stdio.h>
189762338dSopenharmony_ci#include "securec.h"
199762338dSopenharmony_ci#include "hdf_log.h"
209762338dSopenharmony_ci#include "loadbmp_test.h"
219762338dSopenharmony_ci
229762338dSopenharmony_ciDisplayTest g_displayTest;
239762338dSopenharmony_cistatic BufferHandle* g_buffer;
249762338dSopenharmony_ci
259762338dSopenharmony_cistatic int32_t LoadBmp(const int8_t *fileName, BufferHandle **buffer)
269762338dSopenharmony_ci{
279762338dSopenharmony_ci    int32_t ret;
289762338dSopenharmony_ci    uint8_t *pBuf = NULL;
299762338dSopenharmony_ci    OsdSurface esurface;
309762338dSopenharmony_ci    OsdBitMapFileHeader bmpFileHeader = {0};
319762338dSopenharmony_ci    OsdBitMapInfo bmpInfo = {0};
329762338dSopenharmony_ci
339762338dSopenharmony_ci    if (fileName == NULL) {
349762338dSopenharmony_ci        HDF_LOGE("%s: fileName is null", __func__);
359762338dSopenharmony_ci        return DISPLAY_FAILURE;
369762338dSopenharmony_ci    }
379762338dSopenharmony_ci    if (GetBmpInfo(fileName, &bmpFileHeader, &bmpInfo) < 0) {
389762338dSopenharmony_ci        HDF_LOGE("%s: GetBmpInfo err", __func__);
399762338dSopenharmony_ci        return DISPLAY_FAILURE;
409762338dSopenharmony_ci    }
419762338dSopenharmony_ci    AllocInfo info = {
429762338dSopenharmony_ci        .width = bmpInfo.header.width + 1,
439762338dSopenharmony_ci        .height = bmpInfo.header.height + 1,
449762338dSopenharmony_ci        .format = PIXEL_FMT_RGBA_8888,
459762338dSopenharmony_ci        .usage =  HBM_USE_MEM_MMZ
469762338dSopenharmony_ci    };
479762338dSopenharmony_ci    // alloc picture buffer
489762338dSopenharmony_ci    if (g_displayTest.grallocFuncs->AllocMem != NULL) {
499762338dSopenharmony_ci        ret = g_displayTest.grallocFuncs->AllocMem(&info, buffer);
509762338dSopenharmony_ci        if (ret != DISPLAY_SUCCESS) {
519762338dSopenharmony_ci            HDF_LOGE("%s: pictureBuf alloc failure", __func__);
529762338dSopenharmony_ci            return DISPLAY_FAILURE;
539762338dSopenharmony_ci        }
549762338dSopenharmony_ci    }
559762338dSopenharmony_ci    // load bmp picture
569762338dSopenharmony_ci    pBuf = (uint8_t *)(*buffer)->virAddr;
579762338dSopenharmony_ci    esurface.colorFmt = OSD_COLOR_FMT_RGB1555;
589762338dSopenharmony_ci    CreateSurfaceByBitMap(fileName, &esurface, pBuf, (*buffer)->size);
599762338dSopenharmony_ci    return DISPLAY_SUCCESS;
609762338dSopenharmony_ci}
619762338dSopenharmony_ci
629762338dSopenharmony_cistatic void GetLayerInfo(LayerInfo *layInfo)
639762338dSopenharmony_ci{
649762338dSopenharmony_ci    layInfo->width = (uint32_t)g_displayTest.displayInfo.width;
659762338dSopenharmony_ci    layInfo->height = (uint32_t)g_displayTest.displayInfo.height;
669762338dSopenharmony_ci    layInfo->bpp = LAYER_BPP;
679762338dSopenharmony_ci    layInfo->pixFormat = PIXEL_FMT_RGBA_5551;
689762338dSopenharmony_ci    layInfo->type = LAYER_TYPE_GRAPHIC;
699762338dSopenharmony_ci}
709762338dSopenharmony_ci
719762338dSopenharmony_cistatic void WriteDataToBuf(int32_t width, int32_t height, uint16_t *pBuf)
729762338dSopenharmony_ci{
739762338dSopenharmony_ci    int32_t x;
749762338dSopenharmony_ci    int32_t y;
759762338dSopenharmony_ci
769762338dSopenharmony_ci    for (y = ((height / LINE_WIDTH) - LINE_WIDTH); y < ((height / LINE_WIDTH) + LINE_WIDTH); y++) {
779762338dSopenharmony_ci        for (x = 0; x < width; x++) {
789762338dSopenharmony_ci            *((uint16_t*)pBuf + y * width + x) = HIFB_RED_1555;
799762338dSopenharmony_ci        }
809762338dSopenharmony_ci    }
819762338dSopenharmony_ci    for (y = 0; y < height; y++) {
829762338dSopenharmony_ci        for (x = ((width / LINE_WIDTH) - LINE_WIDTH); x < ((width / LINE_WIDTH) + LINE_WIDTH); x++) {
839762338dSopenharmony_ci            *((uint16_t*)pBuf + y * width + x) = HIFB_RED_1555;
849762338dSopenharmony_ci        }
859762338dSopenharmony_ci    }
869762338dSopenharmony_ci}
879762338dSopenharmony_ci
889762338dSopenharmony_cistatic void PicSourceSurfaceInit(ISurface *esurface, uint64_t phyAddr, int32_t bpp)
899762338dSopenharmony_ci{
909762338dSopenharmony_ci    esurface->width = SAMPLE_IMAGE_WIDTH;
919762338dSopenharmony_ci    esurface->height = SAMPLE_IMAGE_HEIGHT;
929762338dSopenharmony_ci    esurface->phyAddr = phyAddr;
939762338dSopenharmony_ci    esurface->enColorFmt = PIXEL_FMT_RGBA_5551;
949762338dSopenharmony_ci    esurface->stride = SAMPLE_IMAGE_WIDTH * bpp / BITS_PER_BYTE;
959762338dSopenharmony_ci    esurface->bAlphaExt1555 = true;
969762338dSopenharmony_ci    esurface->bAlphaMax255  = true;
979762338dSopenharmony_ci    esurface->alpha0 = 0XFF;
989762338dSopenharmony_ci    esurface->alpha1 = 0XFF;
999762338dSopenharmony_ci}
1009762338dSopenharmony_ci
1019762338dSopenharmony_cistatic void DestSurfaceInit(ISurface *esurface, uint64_t phyAddr, int32_t bpp)
1029762338dSopenharmony_ci{
1039762338dSopenharmony_ci    esurface->width = (uint32_t)g_displayTest.displayInfo.width;
1049762338dSopenharmony_ci    esurface->height = (uint32_t)g_displayTest.displayInfo.height;
1059762338dSopenharmony_ci    esurface->phyAddr = phyAddr;
1069762338dSopenharmony_ci    esurface->enColorFmt = PIXEL_FMT_RGBA_5551;
1079762338dSopenharmony_ci    esurface->stride = g_displayTest.displayInfo.width * bpp / BITS_PER_BYTE;
1089762338dSopenharmony_ci    esurface->bAlphaExt1555 = true;
1099762338dSopenharmony_ci    esurface->bAlphaMax255  = true;
1109762338dSopenharmony_ci    esurface->alpha0 = 0XFF;
1119762338dSopenharmony_ci    esurface->alpha1 = 0XFF;
1129762338dSopenharmony_ci    esurface->bYCbCrClut = 0;
1139762338dSopenharmony_ci}
1149762338dSopenharmony_ci
1159762338dSopenharmony_ciint32_t DisplayInit(void)
1169762338dSopenharmony_ci{
1179762338dSopenharmony_ci    int32_t ret;
1189762338dSopenharmony_ci
1199762338dSopenharmony_ci    ret = LayerInitialize(&g_displayTest.layerFuncs);
1209762338dSopenharmony_ci    if (ret != DISPLAY_SUCCESS || g_displayTest.layerFuncs == NULL) {
1219762338dSopenharmony_ci        HDF_LOGE("%s: layer initialize failure", __func__);
1229762338dSopenharmony_ci        return DISPLAY_FAILURE;
1239762338dSopenharmony_ci    }
1249762338dSopenharmony_ci    ret = GrallocInitialize(&g_displayTest.grallocFuncs);
1259762338dSopenharmony_ci    if (ret != DISPLAY_SUCCESS || g_displayTest.layerFuncs == NULL) {
1269762338dSopenharmony_ci        HDF_LOGE("%s: gralloc initialize failure", __func__);
1279762338dSopenharmony_ci        return DISPLAY_FAILURE;
1289762338dSopenharmony_ci    }
1299762338dSopenharmony_ci    ret = GfxInitialize(&g_displayTest.gfxFuncs);
1309762338dSopenharmony_ci    if (ret != DISPLAY_SUCCESS || g_displayTest.gfxFuncs == NULL) {
1319762338dSopenharmony_ci        HDF_LOGE("%s: gfx initialize failure", __func__);
1329762338dSopenharmony_ci        return DISPLAY_FAILURE;
1339762338dSopenharmony_ci    }
1349762338dSopenharmony_ci    return DISPLAY_SUCCESS;
1359762338dSopenharmony_ci}
1369762338dSopenharmony_ci
1379762338dSopenharmony_ciint32_t DisplayUninit(void)
1389762338dSopenharmony_ci{
1399762338dSopenharmony_ci    LayerUninitialize(g_displayTest.layerFuncs);
1409762338dSopenharmony_ci    GrallocUninitialize(g_displayTest.grallocFuncs);
1419762338dSopenharmony_ci    GfxUninitialize(g_displayTest.gfxFuncs);
1429762338dSopenharmony_ci    return DISPLAY_SUCCESS;
1439762338dSopenharmony_ci}
1449762338dSopenharmony_ci
1459762338dSopenharmony_ciint32_t InitDisplayTest(void)
1469762338dSopenharmony_ci{
1479762338dSopenharmony_ci    int32_t ret;
1489762338dSopenharmony_ci
1499762338dSopenharmony_ci    g_displayTest.devId = 0;
1509762338dSopenharmony_ci    // init display
1519762338dSopenharmony_ci    if (g_displayTest.layerFuncs->InitDisplay != NULL) {
1529762338dSopenharmony_ci        ret = g_displayTest.layerFuncs->InitDisplay(g_displayTest.devId);
1539762338dSopenharmony_ci        if (ret != DISPLAY_SUCCESS) {
1549762338dSopenharmony_ci            HDF_LOGE("%s: MPI VO can't be opened repeatedly, so here bypass ret check", __func__);
1559762338dSopenharmony_ci            return DISPLAY_SUCCESS;
1569762338dSopenharmony_ci        }
1579762338dSopenharmony_ci    }
1589762338dSopenharmony_ci    return DISPLAY_SUCCESS;
1599762338dSopenharmony_ci}
1609762338dSopenharmony_ci
1619762338dSopenharmony_ciint32_t DeinitDisplayTest(void)
1629762338dSopenharmony_ci{
1639762338dSopenharmony_ci    int32_t ret = DISPLAY_SUCCESS;
1649762338dSopenharmony_ci
1659762338dSopenharmony_ci    g_displayTest.devId = 0;
1669762338dSopenharmony_ci    // deinit display
1679762338dSopenharmony_ci    if (g_displayTest.layerFuncs->DeinitDisplay != NULL) {
1689762338dSopenharmony_ci        HDF_LOGE("%s: Here bypass call DeinitDisplay func for keep test environment continuable", __func__);
1699762338dSopenharmony_ci        if (ret != DISPLAY_SUCCESS) {
1709762338dSopenharmony_ci            HDF_LOGE("%s: deinit display failed", __func__);
1719762338dSopenharmony_ci            return DISPLAY_FAILURE;
1729762338dSopenharmony_ci        }
1739762338dSopenharmony_ci    }
1749762338dSopenharmony_ci    return DISPLAY_SUCCESS;
1759762338dSopenharmony_ci}
1769762338dSopenharmony_ci
1779762338dSopenharmony_ciint32_t GetDisplayInfoTest(void)
1789762338dSopenharmony_ci{
1799762338dSopenharmony_ci    int32_t ret;
1809762338dSopenharmony_ci
1819762338dSopenharmony_ci    g_displayTest.devId = 0;
1829762338dSopenharmony_ci    // get display info
1839762338dSopenharmony_ci    if (g_displayTest.layerFuncs->GetDisplayInfo != NULL) {
1849762338dSopenharmony_ci        ret = g_displayTest.layerFuncs->GetDisplayInfo(g_displayTest.devId, &g_displayTest.displayInfo);
1859762338dSopenharmony_ci        if (ret != DISPLAY_SUCCESS) {
1869762338dSopenharmony_ci            HDF_LOGE("%s: get disp info failed", __func__);
1879762338dSopenharmony_ci            return DISPLAY_FAILURE;
1889762338dSopenharmony_ci        }
1899762338dSopenharmony_ci    }
1909762338dSopenharmony_ci    HDF_LOGI("%s: dispInfo width = %d", __func__, g_displayTest.displayInfo.width);
1919762338dSopenharmony_ci    HDF_LOGI("%s: dispInfo height = %d", __func__, g_displayTest.displayInfo.height);
1929762338dSopenharmony_ci    HDF_LOGI("%s: dispInfo rotAngle = %d", __func__, g_displayTest.displayInfo.rotAngle);
1939762338dSopenharmony_ci    return DISPLAY_SUCCESS;
1949762338dSopenharmony_ci}
1959762338dSopenharmony_ci
1969762338dSopenharmony_ciint32_t CreateLayerTest(void)
1979762338dSopenharmony_ci{
1989762338dSopenharmony_ci    int32_t ret;
1999762338dSopenharmony_ci    LayerInfo layInfo;
2009762338dSopenharmony_ci
2019762338dSopenharmony_ci    g_displayTest.devId = 0;
2029762338dSopenharmony_ci    // create layer
2039762338dSopenharmony_ci    GetLayerInfo(&layInfo);
2049762338dSopenharmony_ci    if (g_displayTest.layerFuncs->CreateLayer != NULL) {
2059762338dSopenharmony_ci        ret = g_displayTest.layerFuncs->CreateLayer(g_displayTest.devId, &layInfo, &g_displayTest.layerId);
2069762338dSopenharmony_ci        if (ret != DISPLAY_SUCCESS) {
2079762338dSopenharmony_ci            HDF_LOGE("%s: CreateLayer fail", __func__);
2089762338dSopenharmony_ci            return DISPLAY_FAILURE;
2099762338dSopenharmony_ci        }
2109762338dSopenharmony_ci    }
2119762338dSopenharmony_ci    return DISPLAY_SUCCESS;
2129762338dSopenharmony_ci}
2139762338dSopenharmony_ci
2149762338dSopenharmony_ciint32_t CloseLayerTest(void)
2159762338dSopenharmony_ci{
2169762338dSopenharmony_ci    int32_t ret;
2179762338dSopenharmony_ci
2189762338dSopenharmony_ci    if (g_displayTest.layerFuncs->CloseLayer != NULL) {
2199762338dSopenharmony_ci        ret = g_displayTest.layerFuncs->CloseLayer(g_displayTest.devId, g_displayTest.layerId);
2209762338dSopenharmony_ci        if (ret != DISPLAY_SUCCESS) {
2219762338dSopenharmony_ci            HDF_LOGE("%s: CloseLayer fail", __func__);
2229762338dSopenharmony_ci            return DISPLAY_FAILURE;
2239762338dSopenharmony_ci        }
2249762338dSopenharmony_ci    }
2259762338dSopenharmony_ci    return DISPLAY_SUCCESS;
2269762338dSopenharmony_ci}
2279762338dSopenharmony_ci
2289762338dSopenharmony_ciint32_t SetLayerVisibleTest(void)
2299762338dSopenharmony_ci{
2309762338dSopenharmony_ci    int32_t ret;
2319762338dSopenharmony_ci
2329762338dSopenharmony_ci    // set layer visible
2339762338dSopenharmony_ci    if (g_displayTest.layerFuncs->SetLayerVisible != NULL) {
2349762338dSopenharmony_ci        ret = g_displayTest.layerFuncs->SetLayerVisible(g_displayTest.devId, g_displayTest.layerId, true);
2359762338dSopenharmony_ci        if (ret != DISPLAY_SUCCESS) {
2369762338dSopenharmony_ci            HDF_LOGE("%s: SetLayerVisible fail", __func__);
2379762338dSopenharmony_ci            return DISPLAY_FAILURE;
2389762338dSopenharmony_ci        }
2399762338dSopenharmony_ci    }
2409762338dSopenharmony_ci    return DISPLAY_SUCCESS;
2419762338dSopenharmony_ci}
2429762338dSopenharmony_ci
2439762338dSopenharmony_ciint32_t SetLayerDirtyRegionTest(void)
2449762338dSopenharmony_ci{
2459762338dSopenharmony_ci    int32_t ret;
2469762338dSopenharmony_ci    IRect rect = {0, 0, g_displayTest.displayInfo.width, g_displayTest.displayInfo.height};
2479762338dSopenharmony_ci
2489762338dSopenharmony_ci    // set refresh region
2499762338dSopenharmony_ci    if (g_displayTest.layerFuncs->SetLayerDirtyRegion != NULL) {
2509762338dSopenharmony_ci        ret = g_displayTest.layerFuncs->SetLayerDirtyRegion(g_displayTest.devId, g_displayTest.layerId, &rect);
2519762338dSopenharmony_ci        if (ret != DISPLAY_SUCCESS) {
2529762338dSopenharmony_ci            HDF_LOGE("%s: SetLayerDirtyRegion fail", __func__);
2539762338dSopenharmony_ci            return DISPLAY_FAILURE;
2549762338dSopenharmony_ci        }
2559762338dSopenharmony_ci    }
2569762338dSopenharmony_ci    return DISPLAY_SUCCESS;
2579762338dSopenharmony_ci}
2589762338dSopenharmony_ci
2599762338dSopenharmony_ciint32_t GetLayerBufferTest(void)
2609762338dSopenharmony_ci{
2619762338dSopenharmony_ci    int32_t ret;
2629762338dSopenharmony_ci
2639762338dSopenharmony_ci    if (g_displayTest.layerFuncs->GetLayerBuffer != NULL) {
2649762338dSopenharmony_ci        ret = g_displayTest.layerFuncs->GetLayerBuffer(g_displayTest.devId, g_displayTest.layerId,
2659762338dSopenharmony_ci                                                       &g_displayTest.buffer);
2669762338dSopenharmony_ci        if (ret != DISPLAY_SUCCESS) {
2679762338dSopenharmony_ci            HDF_LOGE("%s: GetLayerBuffer fail", __func__);
2689762338dSopenharmony_ci            return DISPLAY_FAILURE;
2699762338dSopenharmony_ci        }
2709762338dSopenharmony_ci    }
2719762338dSopenharmony_ci    // write buffer data
2729762338dSopenharmony_ci    uint16_t *pBuf = (uint16_t *)g_displayTest.buffer.data.virAddr;
2739762338dSopenharmony_ci    WriteDataToBuf(g_displayTest.displayInfo.width, g_displayTest.displayInfo.height, pBuf);
2749762338dSopenharmony_ci    return DISPLAY_SUCCESS;
2759762338dSopenharmony_ci}
2769762338dSopenharmony_ci
2779762338dSopenharmony_ciint32_t FlushTest(void)
2789762338dSopenharmony_ci{
2799762338dSopenharmony_ci    int32_t ret;
2809762338dSopenharmony_ci
2819762338dSopenharmony_ci    // refresh layer to display
2829762338dSopenharmony_ci    if (g_displayTest.layerFuncs->Flush != NULL) {
2839762338dSopenharmony_ci        ret = g_displayTest.layerFuncs->Flush(g_displayTest.devId, g_displayTest.layerId, &g_displayTest.buffer);
2849762338dSopenharmony_ci        if (ret != DISPLAY_SUCCESS) {
2859762338dSopenharmony_ci            HDF_LOGE("%s: flush fail", __func__);
2869762338dSopenharmony_ci            return DISPLAY_FAILURE;
2879762338dSopenharmony_ci        }
2889762338dSopenharmony_ci    }
2899762338dSopenharmony_ci    return DISPLAY_SUCCESS;
2909762338dSopenharmony_ci}
2919762338dSopenharmony_ci
2929762338dSopenharmony_ciint32_t InitGfxTest(void)
2939762338dSopenharmony_ci{
2949762338dSopenharmony_ci    int32_t ret;
2959762338dSopenharmony_ci    // init gfx
2969762338dSopenharmony_ci    if (g_displayTest.gfxFuncs->InitGfx != NULL) {
2979762338dSopenharmony_ci        ret = g_displayTest.gfxFuncs->InitGfx();
2989762338dSopenharmony_ci        if (ret != DISPLAY_SUCCESS) {
2999762338dSopenharmony_ci            HDF_LOGE("%s: init gfx fail", __func__);
3009762338dSopenharmony_ci            return DISPLAY_FAILURE;
3019762338dSopenharmony_ci        }
3029762338dSopenharmony_ci    }
3039762338dSopenharmony_ci    return DISPLAY_SUCCESS;
3049762338dSopenharmony_ci}
3059762338dSopenharmony_ci
3069762338dSopenharmony_ciint32_t DeinitGfxTest(void)
3079762338dSopenharmony_ci{
3089762338dSopenharmony_ci    int32_t ret;
3099762338dSopenharmony_ci    // deinit gfx
3109762338dSopenharmony_ci    if (g_displayTest.gfxFuncs->DeinitGfx != NULL) {
3119762338dSopenharmony_ci        ret = g_displayTest.gfxFuncs->DeinitGfx();
3129762338dSopenharmony_ci        if (ret != DISPLAY_SUCCESS) {
3139762338dSopenharmony_ci            HDF_LOGE("%s: deinit gfx fail", __func__);
3149762338dSopenharmony_ci            return DISPLAY_FAILURE;
3159762338dSopenharmony_ci        }
3169762338dSopenharmony_ci    }
3179762338dSopenharmony_ci    return DISPLAY_SUCCESS;
3189762338dSopenharmony_ci}
3199762338dSopenharmony_ci
3209762338dSopenharmony_ciint32_t BlitTest(void)
3219762338dSopenharmony_ci{
3229762338dSopenharmony_ci    int32_t ret;
3239762338dSopenharmony_ci    ISurface srcSurface = {0};
3249762338dSopenharmony_ci    ISurface dstSurface = {0};
3259762338dSopenharmony_ci    BufferHandle* pictureBuf = NULL;
3269762338dSopenharmony_ci    uint32_t layerBufSize = g_displayTest.displayInfo.width * g_displayTest.displayInfo.height * PIXEL_BYTE;
3279762338dSopenharmony_ci
3289762338dSopenharmony_ci    // clean the layer buffer
3299762338dSopenharmony_ci    (void)memset_s(g_displayTest.buffer.data.virAddr, layerBufSize, 0, layerBufSize);
3309762338dSopenharmony_ci    // load bmp test picture
3319762338dSopenharmony_ci    ret = LoadBmp((const int8_t *)PIC_RES_PATH, &pictureBuf);
3329762338dSopenharmony_ci    if (ret != DISPLAY_SUCCESS) {
3339762338dSopenharmony_ci        HDF_LOGE("%s: LoadBmp fail", __func__);
3349762338dSopenharmony_ci        return DISPLAY_FAILURE;
3359762338dSopenharmony_ci    }
3369762338dSopenharmony_ci    // use picture buffer to create source esurface
3379762338dSopenharmony_ci    IRect srcRect = {0, 0, SAMPLE_IMAGE_WIDTH, SAMPLE_IMAGE_HEIGHT};
3389762338dSopenharmony_ci    PicSourceSurfaceInit(&srcSurface, pictureBuf->phyAddr, LAYER_BPP);
3399762338dSopenharmony_ci    // use layer buffer to create dest esurface
3409762338dSopenharmony_ci    IRect dstRect = srcRect;
3419762338dSopenharmony_ci    DestSurfaceInit(&dstSurface, g_displayTest.buffer.data.phyAddr, LAYER_BPP);
3429762338dSopenharmony_ci    // TDE: copy bmp picture buffer to layer buffer
3439762338dSopenharmony_ci    if (g_displayTest.gfxFuncs->Blit != NULL) {
3449762338dSopenharmony_ci        ret = g_displayTest.gfxFuncs->Blit(&srcSurface, &srcRect, &dstSurface, &dstRect, NULL);
3459762338dSopenharmony_ci        if (ret != DISPLAY_SUCCESS) {
3469762338dSopenharmony_ci            HDF_LOGE("%s: Blit fail", __func__);
3479762338dSopenharmony_ci            goto EXIT;
3489762338dSopenharmony_ci        }
3499762338dSopenharmony_ci    }
3509762338dSopenharmony_ci    return DISPLAY_SUCCESS;
3519762338dSopenharmony_ci
3529762338dSopenharmony_ciEXIT:
3539762338dSopenharmony_ci    /* free picture buffer */
3549762338dSopenharmony_ci    if (g_displayTest.grallocFuncs->FreeMem != NULL) {
3559762338dSopenharmony_ci        g_displayTest.grallocFuncs->FreeMem(pictureBuf);
3569762338dSopenharmony_ci    }
3579762338dSopenharmony_ci    return ret;
3589762338dSopenharmony_ci}
3599762338dSopenharmony_ci
3609762338dSopenharmony_ciint32_t FillRectTest(void)
3619762338dSopenharmony_ci{
3629762338dSopenharmony_ci    int32_t ret;
3639762338dSopenharmony_ci    ISurface dstSurface = {0};
3649762338dSopenharmony_ci    GfxOpt opt = {0};
3659762338dSopenharmony_ci    IRect rect = {0, 0, SAMPLE_RECT_WIDTH, SAMPLE_RECT_HEIGHT};
3669762338dSopenharmony_ci    uint32_t layerBufSize = g_displayTest.displayInfo.width * g_displayTest.displayInfo.height * PIXEL_BYTE;
3679762338dSopenharmony_ci
3689762338dSopenharmony_ci    opt.enGlobalAlpha = true;
3699762338dSopenharmony_ci    opt.globalAlpha = MAX_GLOBLE_ALPHA;
3709762338dSopenharmony_ci    // clean the layer buffer
3719762338dSopenharmony_ci    (void)memset_s(g_displayTest.buffer.data.virAddr, layerBufSize, 0, layerBufSize);
3729762338dSopenharmony_ci    DestSurfaceInit(&dstSurface, g_displayTest.buffer.data.phyAddr, LAYER_BPP);
3739762338dSopenharmony_ci    // TDE: copy bmp picture buffer to layer buffer
3749762338dSopenharmony_ci    if (g_displayTest.gfxFuncs->FillRect != NULL) {
3759762338dSopenharmony_ci        ret = g_displayTest.gfxFuncs->FillRect(&dstSurface, &rect, HIFB_RED_1555, &opt);
3769762338dSopenharmony_ci        if (ret != DISPLAY_SUCCESS) {
3779762338dSopenharmony_ci            HDF_LOGE("%s: FillRect fail", __func__);
3789762338dSopenharmony_ci            return ret;
3799762338dSopenharmony_ci        }
3809762338dSopenharmony_ci    }
3819762338dSopenharmony_ci    return DISPLAY_SUCCESS;
3829762338dSopenharmony_ci}
3839762338dSopenharmony_ci
3849762338dSopenharmony_ciint32_t AllocMemTest1(void)
3859762338dSopenharmony_ci{
3869762338dSopenharmony_ci    int32_t ret = DISPLAY_FAILURE;
3879762338dSopenharmony_ci
3889762338dSopenharmony_ci    AllocInfo info = {
3899762338dSopenharmony_ci        .width = SAMPLE_IMAGE_WIDTH,
3909762338dSopenharmony_ci        .height = SAMPLE_IMAGE_HEIGHT,
3919762338dSopenharmony_ci        .format = PIXEL_FMT_RGBA_8888,
3929762338dSopenharmony_ci        .usage =  HBM_USE_MEM_MMZ
3939762338dSopenharmony_ci    };
3949762338dSopenharmony_ci    if (g_displayTest.grallocFuncs->AllocMem != NULL) {
3959762338dSopenharmony_ci        ret = g_displayTest.grallocFuncs->AllocMem(&info, &g_buffer);
3969762338dSopenharmony_ci    }
3979762338dSopenharmony_ci    if (ret != DISPLAY_SUCCESS) {
3989762338dSopenharmony_ci        HDF_LOGE("%s: normal memory allocMem failed", __func__);
3999762338dSopenharmony_ci        return ret;
4009762338dSopenharmony_ci    }
4019762338dSopenharmony_ci    return DISPLAY_SUCCESS;
4029762338dSopenharmony_ci}
4039762338dSopenharmony_ci
4049762338dSopenharmony_ciint32_t MmapCacheTest(void)
4059762338dSopenharmony_ci{
4069762338dSopenharmony_ci    int32_t ret = DISPLAY_FAILURE;
4079762338dSopenharmony_ci    void *mapCacheAddr = NULL;
4089762338dSopenharmony_ci    AllocInfo info = {
4099762338dSopenharmony_ci        .width = SAMPLE_RECT_WIDTH,
4109762338dSopenharmony_ci        .height = SAMPLE_RECT_HEIGHT,
4119762338dSopenharmony_ci        .format = PIXEL_FMT_RGBA_8888,
4129762338dSopenharmony_ci        .usage =  HBM_USE_MEM_MMZ_CACHE
4139762338dSopenharmony_ci    };
4149762338dSopenharmony_ci
4159762338dSopenharmony_ci    if (g_displayTest.grallocFuncs->AllocMem != NULL) {
4169762338dSopenharmony_ci        ret = g_displayTest.grallocFuncs->AllocMem(&info, &g_buffer);
4179762338dSopenharmony_ci    }
4189762338dSopenharmony_ci    if (ret != DISPLAY_SUCCESS) {
4199762338dSopenharmony_ci        HDF_LOGE("%s: normal memory allocMem failed", __func__);
4209762338dSopenharmony_ci        return ret;
4219762338dSopenharmony_ci    }
4229762338dSopenharmony_ci
4239762338dSopenharmony_ci    if (g_displayTest.grallocFuncs->MmapCache != NULL) {
4249762338dSopenharmony_ci        mapCacheAddr = g_displayTest.grallocFuncs->MmapCache(g_buffer);
4259762338dSopenharmony_ci        if (mapCacheAddr == NULL) {
4269762338dSopenharmony_ci            return DISPLAY_FAILURE;
4279762338dSopenharmony_ci        }
4289762338dSopenharmony_ci    }
4299762338dSopenharmony_ci    return DISPLAY_SUCCESS;
4309762338dSopenharmony_ci}
4319762338dSopenharmony_ci
4329762338dSopenharmony_ciint32_t FreeMemTest(void)
4339762338dSopenharmony_ci{
4349762338dSopenharmony_ci    if (g_displayTest.grallocFuncs->FreeMem != NULL) {
4359762338dSopenharmony_ci        g_displayTest.grallocFuncs->FreeMem(g_buffer);
4369762338dSopenharmony_ci    }
4379762338dSopenharmony_ci    return DISPLAY_SUCCESS;
4389762338dSopenharmony_ci}
4399762338dSopenharmony_ci
4409762338dSopenharmony_ciint32_t AllocMemTest2(void)
4419762338dSopenharmony_ci{
4429762338dSopenharmony_ci    int32_t ret = DISPLAY_FAILURE;
4439762338dSopenharmony_ci    AllocInfo info = {
4449762338dSopenharmony_ci        .width = SAMPLE_IMAGE_WIDTH,
4459762338dSopenharmony_ci        .height = SAMPLE_IMAGE_HEIGHT,
4469762338dSopenharmony_ci        .format = PIXEL_FMT_RGBA_8888,
4479762338dSopenharmony_ci        .usage =  HBM_USE_MEM_MMZ
4489762338dSopenharmony_ci    };
4499762338dSopenharmony_ci
4509762338dSopenharmony_ci    if (g_displayTest.grallocFuncs->AllocMem != NULL) {
4519762338dSopenharmony_ci        ret = g_displayTest.grallocFuncs->AllocMem(&info, &g_buffer);
4529762338dSopenharmony_ci    }
4539762338dSopenharmony_ci    if (ret != DISPLAY_SUCCESS) {
4549762338dSopenharmony_ci        HDF_LOGE("%s: cache memory allocMem failed", __func__);
4559762338dSopenharmony_ci        return ret;
4569762338dSopenharmony_ci    }
4579762338dSopenharmony_ci
4589762338dSopenharmony_ci    return DISPLAY_SUCCESS;
4599762338dSopenharmony_ci}
4609762338dSopenharmony_ci
4619762338dSopenharmony_ciint32_t FlushMCacheTest(void)
4629762338dSopenharmony_ci{
4639762338dSopenharmony_ci    int32_t ret;
4649762338dSopenharmony_ci
4659762338dSopenharmony_ci    if (g_displayTest.grallocFuncs->FlushMCache != NULL) {
4669762338dSopenharmony_ci        ret = g_displayTest.grallocFuncs->FlushMCache(g_buffer);
4679762338dSopenharmony_ci        if (ret != DISPLAY_SUCCESS) {
4689762338dSopenharmony_ci            return ret;
4699762338dSopenharmony_ci        }
4709762338dSopenharmony_ci    }
4719762338dSopenharmony_ci    return DISPLAY_SUCCESS;
4729762338dSopenharmony_ci}
473