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 "hdi_composition_check.h"
17 #include "display_test.h"
18 #include "display_test_utils.h"
19 namespace OHOS {
20 namespace HDI {
21 namespace DISPLAY {
22 namespace TEST {
GetCheckPoints(Point center,std::vector<Point> & points)23 void HdiCompositionCheck::GetCheckPoints(Point center, std::vector<Point> &points)
24 {
25 constexpr uint32_t step = 3;
26 points.push_back(center);
27 points.push_back({ center.x + step, center.y });
28 points.push_back({ center.x + step, center.y + step });
29 points.push_back({ center.x + step, center.y - step });
30 points.push_back({ center.x, center.y + step });
31 points.push_back({ center.x - step, center.y });
32 points.push_back({ center.x - step, center.y - step });
33 points.push_back({ center.x - step, center.y + step });
34 points.push_back({ center.x, center.y - step });
35 }
36 // simple handle the alpha it may not compatible with all scenarios
SimpleHandleAlpha(const LayerSettings & layers,uint32_t & color)37 void HdiCompositionCheck::SimpleHandleAlpha(const LayerSettings &layers, uint32_t &color)
38 {
39 const float inv = 1.0f / 255.0f;
40 if (layers.alpha != -1) {
41 switch (layers.blendType) {
42 case BLEND_SRC:
43 color = (color & 0xffffff00) | (layers.alpha & 0xff); // get the alpha
44 break;
45 case BLEND_SRCOVER:
46 color = color * (layers.alpha * inv);
47 color = (color & 0xffffff00) | (layers.alpha & 0xff); // get the alpha
48 break;
49 default:
50 break;
51 }
52 }
53 }
54
GetCheckColors(std::vector<LayerSettings> & layers,const std::vector<Point> & points)55 std::vector<uint32_t> HdiCompositionCheck::GetCheckColors(std::vector<LayerSettings> &layers,
56 const std::vector<Point> &points)
57 {
58 std::vector<uint32_t> colors;
59 for (auto point : points) {
60 uint32_t color = 0;
61 for (uint32_t i = layers.size(); i > 0; i--) {
62 auto layer = layers[i - 1];
63 const IRect &rect = layer.displayRect;
64 // check whether the point is inside the rect
65 if ((point.x >= rect.x) && (point.x < (rect.x + rect.w)) && (point.y >= rect.y) &&
66 (point.y < (rect.y + rect.h))) {
67 if (layer.compositionType != COMPOSITION_VIDEO) {
68 color = layer.color;
69 SimpleHandleAlpha(layer, color);
70 }
71 break;
72 }
73 }
74 colors.push_back(color);
75 }
76 return colors;
77 }
78
Check(std::vector<LayerSettings> & layers,BufferHandle & clientBuffer,uint32_t checkType)79 int32_t HdiCompositionCheck::Check(std::vector<LayerSettings> &layers, BufferHandle &clientBuffer, uint32_t checkType)
80 {
81 int ret = DISPLAY_SUCCESS;
82 const int midPos = 2;
83 // get the all check point
84 std::vector<Point> points;
85 for (auto layer : layers) {
86 const IRect &rect = layer.displayRect;
87 if (checkType == CHECK_VERTEX) {
88 GetCheckPoints({ rect.x, rect.y }, points);
89 GetCheckPoints({ rect.x, rect.y + rect.h }, points);
90 GetCheckPoints({ rect.x + rect.w, rect.y }, points);
91 GetCheckPoints({ rect.x + rect.w, rect.y + rect.h }, points);
92 } else {
93 GetCheckPoints({ rect.x + rect.w / midPos, rect.y + rect.h / midPos }, points); // center point
94 }
95 }
96
97 // get all the check color
98 std::vector<uint32_t> colors = GetCheckColors(layers, points);
99 DISPLAY_TEST_CHK_RETURN((colors.size() != points.size()), DISPLAY_FAILURE,
100 DISPLAY_TEST_LOGE("Points and colors don't match"));
101 for (uint32_t i = 0; i < points.size(); i++) {
102 if ((points[i].x >= clientBuffer.width) || (points[i].x < 0) || (points[i].y < 0) ||
103 (points[i].y >= clientBuffer.height)) {
104 continue;
105 }
106 ret = CheckPixel(clientBuffer, points[i].x, points[i].y, colors[i]);
107 if (ret != DISPLAY_SUCCESS) {
108 DISPLAY_TEST_LOGE("check failed");
109 break;
110 }
111 }
112 return ret;
113 }
114 } // OHOS
115 } // HDI
116 } // DISPLAY
117 } // TEST