• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2022 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 {
SetUint32(uint32_t & dst,uint32_t value)22 void SetUint32(uint32_t &dst, uint32_t value)
23 {
24     uint8_t *data = reinterpret_cast<uint8_t *>(&dst);
25     for (uint8_t i = 0; i < sizeof(uint32_t); i++) {
26         *(data + i) = (value >> ((sizeof(uint32_t) - i - 1) * BITS_PER_BYTE)) & 0xff;
27     }
28 }
29 
SetPixel(const BufferHandle & handle,int x,int y,uint32_t color)30 void SetPixel(const BufferHandle &handle, int x, int y, uint32_t color)
31 {
32     constexpr int32_t pixelBytes = 4;
33     DISPLAY_TEST_CHK_RETURN_NOT_VALUE((handle.format <= 0),
34         DISPLAY_TEST_LOGE("CheckPixel do not support format %d", handle.format));
35     DISPLAY_TEST_CHK_RETURN_NOT_VALUE((handle.virAddr == nullptr),
36         DISPLAY_TEST_LOGE("CheckPixel viraddr is null must map it"));
37     DISPLAY_TEST_CHK_RETURN_NOT_VALUE((x < 0 || x >= handle.width),
38         DISPLAY_TEST_LOGE("CheckPixel invalid parameter x:%d width:%d", x, handle.width));
39     DISPLAY_TEST_CHK_RETURN_NOT_VALUE((y < 0 || y >= handle.height),
40         DISPLAY_TEST_LOGE("CheckPixel invalid parameter y:%d height:%d", y, handle.height));
41 
42     int32_t position = y * handle.width + x;
43     if ((position * pixelBytes) > handle.size) {
44         DISPLAY_TEST_LOGE("the pixel position outside\n");
45     }
46     uint32_t *pixel = reinterpret_cast<uint32_t *>(handle.virAddr) + position;
47     SetUint32(*pixel, color);
48 }
49 
ClearColor(const BufferHandle & handle,uint32_t color)50 void ClearColor(const BufferHandle &handle, uint32_t color)
51 {
52     for (int32_t x = 0; x < handle.width; x++) {
53         for (int32_t y = 0; y < handle.height; y++) {
54             SetPixel(handle, x, y, color);
55         }
56     }
57 }
58 } // OHOS
59 } // HDI
60 } // DISPLAY
61 } // TEST
62