• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "display_test.h"
17 #include "buffer_handle.h"
18 namespace OHOS {
19 namespace HDI {
20 namespace DISPLAY {
21 namespace TEST {
22 // constexpr uint8_t BITS_PER_BYTE = 8;
SetUint32(uint32_t & dst,uint32_t value)23 void SetUint32(uint32_t &dst, uint32_t value)
24 {
25     uint8_t *data = reinterpret_cast<uint8_t *>(&dst);
26     for (uint8_t i = 0; i < sizeof(uint32_t); i++) {
27         *(data + i) = (value >> ((sizeof(uint32_t) - i - 1) * BITS_PER_BYTE)) & 0xff;
28     }
29 }
30 
SetPixel(const BufferHandle & handle,int x,int y,uint32_t color)31 void SetPixel(const BufferHandle &handle, int x, int y, uint32_t color)
32 {
33     constexpr int32_t pixelBytes = 4;
34     DISPLAY_TEST_CHK_RETURN_NOT_VALUE((handle.format <= 0),
35         DISPLAY_TEST_LOGE("CheckPixel do not support format %d", handle.format));
36     DISPLAY_TEST_CHK_RETURN_NOT_VALUE((handle.virAddr == nullptr),
37         DISPLAY_TEST_LOGE("CheckPixel viraddr is null must map it"));
38     DISPLAY_TEST_CHK_RETURN_NOT_VALUE((x < 0 || x >= handle.width),
39         DISPLAY_TEST_LOGE("CheckPixel invalid parameter x:%d width:%d", x, handle.width));
40     DISPLAY_TEST_CHK_RETURN_NOT_VALUE((y < 0 || y >= handle.height),
41         DISPLAY_TEST_LOGE("CheckPixel invalid parameter y:%d height:%d", y, handle.height));
42 
43     int32_t position = y * handle.width + x;
44     if ((position * pixelBytes) > handle.size) {
45         DISPLAY_TEST_LOGE("the pixel postion outside\n");
46     }
47     uint32_t *pixel = reinterpret_cast<uint32_t *>(handle.virAddr) + position;
48     SetUint32(*pixel, color);
49 }
50 
ClearColor(const BufferHandle & handle,uint32_t color)51 void ClearColor(const BufferHandle &handle, uint32_t color)
52 {
53     for (int32_t x = 0; x < handle.width; x++) {
54         for (int32_t y = 0; y < handle.height; y++) {
55             SetPixel(handle, x, y, color);
56         }
57     }
58 }
59 } // OHOS
60 } // HDI
61 } // DISPLAY
62 } // TEST
63