• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (C) 2023 The Android Open Source Project
2 //
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 #include <string>
16 
17 #include "GfxstreamEnd2EndTests.h"
18 
19 namespace gfxstream {
20 namespace tests {
21 namespace {
22 
23 using testing::Eq;
24 
25 class GfxstreamEnd2EndCompositionTest : public GfxstreamEnd2EndTest {};
26 
TEST_P(GfxstreamEnd2EndCompositionTest,BasicComposition)27 TEST_P(GfxstreamEnd2EndCompositionTest, BasicComposition) {
28     ScopedRenderControlDevice rcDevice(*mRc);
29 
30     auto layer1Ahb = GL_ASSERT(CreateAHBFromImage("256x256_android.png"));
31     auto layer2Ahb = GL_ASSERT(CreateAHBFromImage("256x256_android_with_transparency.png"));
32     auto resultAhb =
33         GL_ASSERT(ScopedAHardwareBuffer::Allocate(*mGralloc, 256, 256, GFXSTREAM_AHB_FORMAT_R8G8B8A8_UNORM));
34 
35     const RenderControlComposition composition = {
36         .displayId = 0,
37         .compositionResultColorBufferHandle = mGralloc->getHostHandle(resultAhb),
38     };
39     const RenderControlCompositionLayer compositionLayers[2] = {
40         {
41             .colorBufferHandle = mGralloc->getHostHandle(layer1Ahb),
42             .composeMode = HWC2_COMPOSITION_DEVICE,
43             .displayFrame =
44                 {
45                     .left = 0,
46                     .top = 0,
47                     .right = 256,
48                     .bottom = 256,
49                 },
50             .crop =
51                 {
52                     .left = 0,
53                     .top = 0,
54                     .right = static_cast<float>(256),
55                     .bottom = static_cast<float>(256),
56                 },
57             .blendMode = HWC2_BLEND_MODE_PREMULTIPLIED,
58             .alpha = 1.0,
59             .color =
60                 {
61                     .r = 0,
62                     .g = 0,
63                     .b = 0,
64                     .a = 0,
65                 },
66             .transform = static_cast<hwc_transform_t>(0),
67         },
68         {
69             .colorBufferHandle = mGralloc->getHostHandle(layer2Ahb),
70             .composeMode = HWC2_COMPOSITION_DEVICE,
71             .displayFrame =
72                 {
73                     .left = 64,
74                     .top = 32,
75                     .right = 128,
76                     .bottom = 160,
77                 },
78             .crop =
79                 {
80                     .left = 0,
81                     .top = 0,
82                     .right = static_cast<float>(256),
83                     .bottom = static_cast<float>(256),
84                 },
85             .blendMode = HWC2_BLEND_MODE_PREMULTIPLIED,
86             .alpha = 1.0,
87             .color =
88                 {
89                     .r = 0,
90                     .g = 0,
91                     .b = 0,
92                     .a = 0,
93                 },
94             .transform = static_cast<hwc_transform_t>(0),
95         },
96     };
97 
98     ASSERT_THAT(mRc->rcCompose(rcDevice, &composition, 2, compositionLayers), Eq(0));
99 
100     GL_ASSERT(CompareAHBWithGolden(resultAhb, "256x256_golden_basic_composition.png"));
101 }
102 
TEST_P(GfxstreamEnd2EndCompositionTest,BasicCompositionBGRA)103 TEST_P(GfxstreamEnd2EndCompositionTest, BasicCompositionBGRA) {
104     ScopedRenderControlDevice rcDevice(*mRc);
105 
106     auto layer1Ahb = GL_ASSERT(CreateAHBFromImage("256x256_android.png"));
107     auto layer2Ahb = GL_ASSERT(CreateAHBFromImage("256x256_android_with_transparency.png"));
108     auto resultAhb = GL_ASSERT(
109         ScopedAHardwareBuffer::Allocate(*mGralloc, 256, 256, GFXSTREAM_AHB_FORMAT_B8G8R8A8_UNORM));
110 
111     const RenderControlComposition composition = {
112         .displayId = 0,
113         .compositionResultColorBufferHandle = mGralloc->getHostHandle(resultAhb),
114     };
115     const RenderControlCompositionLayer compositionLayers[2] = {
116         {
117             .colorBufferHandle = mGralloc->getHostHandle(layer1Ahb),
118             .composeMode = HWC2_COMPOSITION_DEVICE,
119             .displayFrame =
120                 {
121                     .left = 0,
122                     .top = 0,
123                     .right = 256,
124                     .bottom = 256,
125                 },
126             .crop =
127                 {
128                     .left = 0,
129                     .top = 0,
130                     .right = static_cast<float>(256),
131                     .bottom = static_cast<float>(256),
132                 },
133             .blendMode = HWC2_BLEND_MODE_PREMULTIPLIED,
134             .alpha = 1.0,
135             .color =
136                 {
137                     .r = 0,
138                     .g = 0,
139                     .b = 0,
140                     .a = 0,
141                 },
142             .transform = static_cast<hwc_transform_t>(0),
143         },
144         {
145             .colorBufferHandle = mGralloc->getHostHandle(layer2Ahb),
146             .composeMode = HWC2_COMPOSITION_DEVICE,
147             .displayFrame =
148                 {
149                     .left = 64,
150                     .top = 32,
151                     .right = 128,
152                     .bottom = 160,
153                 },
154             .crop =
155                 {
156                     .left = 0,
157                     .top = 0,
158                     .right = static_cast<float>(256),
159                     .bottom = static_cast<float>(256),
160                 },
161             .blendMode = HWC2_BLEND_MODE_PREMULTIPLIED,
162             .alpha = 1.0,
163             .color =
164                 {
165                     .r = 0,
166                     .g = 0,
167                     .b = 0,
168                     .a = 0,
169                 },
170             .transform = static_cast<hwc_transform_t>(0),
171         },
172     };
173 
174     ASSERT_THAT(mRc->rcCompose(rcDevice, &composition, 2, compositionLayers), Eq(0));
175 
176     GL_ASSERT(CompareAHBWithGolden(resultAhb, "256x256_golden_basic_composition.png"));
177 }
178 
179 INSTANTIATE_TEST_CASE_P(GfxstreamEnd2EndTests, GfxstreamEnd2EndCompositionTest,
180                         ::testing::ValuesIn({
181                             TestParams{
182                                 .with_gl = true,
183                                 .with_vk = false,
184                             },
185                             TestParams{
186                                 .with_gl = true,
187                                 .with_vk = true,
188                             },
189                             TestParams{
190                                 .with_gl = false,
191                                 .with_vk = true,
192                             },
193                         }),
194                         &GetTestName);
195 
196 }  // namespace
197 }  // namespace tests
198 }  // namespace gfxstream
199