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_gfx_test.h"
17 #include <chrono>
18 #include <dlfcn.h>
19 #include <securec.h>
20 #include "display_gfx.h"
21 #include "display_gralloc.h"
22 #include "display_test.h"
23 #include "soft_blit.h"
24
25 #define LIB_HDI_GFX_NAME "libdisplay_gfx.z.so"
26 #define LIB_GFX_FUNC_INIT "GfxInitialize"
27 #define LIB_GFX_FUNC_DEINIT "GfxUninitialize"
28
29 namespace {
30 const uint32_t DEFAULT_COLOR = 0x11225588;
31 const uint32_t CHECK_COLOR = 0x22336699;
32 const uint32_t ROTATE_DEFULT_X = 200;
33 const uint32_t ROTATE_DEFULT_Y = 100;
34
SourceSurfaceInit(ISurface & surface,const BufferHandle & buffer)35 static void SourceSurfaceInit(ISurface &surface, const BufferHandle &buffer)
36 {
37 surface.width = buffer.width;
38 surface.height = buffer.height;
39 surface.phyAddr = buffer.phyAddr;
40 surface.enColorFmt = (PixelFormat)buffer.format;
41 surface.stride = buffer.stride;
42 surface.bAlphaExt1555 = true;
43 surface.bAlphaMax255 = true;
44 surface.alpha0 = 0XFF;
45 surface.alpha1 = 0XFF;
46 }
47
GetPixelFormatBpp(PixelFormat format)48 static int32_t GetPixelFormatBpp(PixelFormat format)
49 {
50 const int32_t bppRgba8888 = 32;
51 switch (format) {
52 case PIXEL_FMT_RGBA_8888:
53 return bppRgba8888;
54 case PIXEL_FMT_BGRA_8888:
55 return bppRgba8888;
56 default:
57 return -1;
58 }
59 }
60
GetPixelValue(const BufferHandle & handle,int x,int y)61 static uint32_t GetPixelValue(const BufferHandle &handle, int x, int y)
62 {
63 const int32_t pixelBytes = 4;
64 int32_t bpp = GetPixelFormatBpp((PixelFormat)handle.format);
65 DISPLAY_TEST_CHK_RETURN((bpp <= 0), 0, DISPLAY_TEST_LOGE("CheckPixel do not support format %d", handle.format));
66 DISPLAY_TEST_CHK_RETURN((handle.virAddr == nullptr), 0,
67 DISPLAY_TEST_LOGE("CheckPixel viraddr is null must map it"));
68 DISPLAY_TEST_CHK_RETURN((x < 0 || x >= handle.width), 0,
69 DISPLAY_TEST_LOGE("CheckPixel invalid parameter x:%d width:%d", x, handle.width));
70 DISPLAY_TEST_CHK_RETURN((y < 0 || y >= handle.height), 0,
71 DISPLAY_TEST_LOGE("CheckPixel invalid parameter y:%d height:%d", y, handle.height));
72
73 int32_t position = y * handle.width + x;
74 if ((position * pixelBytes) > handle.size) {
75 DISPLAY_TEST_LOGE("the pixel postion outside\n");
76 }
77 uint32_t *pixel = reinterpret_cast<uint32_t *>(handle.virAddr) + position;
78 return *pixel;
79 }
80
CheckPixel(const BufferHandle & handle,int x,int y,uint32_t color)81 static uint32_t CheckPixel(const BufferHandle &handle, int x, int y, uint32_t color)
82 {
83 const int32_t pixelBytes = 4;
84 int32_t bpp = GetPixelFormatBpp((PixelFormat)handle.format);
85 DISPLAY_TEST_CHK_RETURN((bpp <= 0), 0, DISPLAY_TEST_LOGE("CheckPixel do not support format %d", handle.format));
86 DISPLAY_TEST_CHK_RETURN((handle.virAddr == nullptr), DISPLAY_FAILURE,
87 DISPLAY_TEST_LOGE("CheckPixel viraddr is null must map it"));
88 DISPLAY_TEST_CHK_RETURN((x < 0 || x >= handle.width), DISPLAY_FAILURE,
89 DISPLAY_TEST_LOGE("CheckPixel invalid parameter x:%d width:%d", x, handle.width));
90 DISPLAY_TEST_CHK_RETURN((y < 0 || y >= handle.height), DISPLAY_FAILURE,
91 DISPLAY_TEST_LOGE("CheckPixel invalid parameter y:%d height:%d", y, handle.height));
92
93 int32_t position = y * handle.width + x;
94 if ((position * pixelBytes) > handle.size) {
95 DISPLAY_TEST_LOGE("the pixel postion outside\n");
96 }
97 uint32_t *pixel = reinterpret_cast<uint32_t *>(handle.virAddr) + position;
98 if (*pixel != color) {
99 DISPLAY_TEST_LOGD("the pixel color not match vAddr:%p position:%d pixel:%x color:%x", handle.virAddr, position,
100 *pixel, color);
101 DISPLAY_TEST_LOGD("x:%d y:%d width:%d", x, y, handle.width);
102 }
103 return *pixel;
104 }
105
SetPixel(const BufferHandle & handle,int x,int y,uint32_t color)106 static void SetPixel(const BufferHandle &handle, int x, int y, uint32_t color)
107 {
108 const int32_t pixelBytes = 4;
109 int32_t bpp = GetPixelFormatBpp((PixelFormat)handle.format);
110 DISPLAY_TEST_CHK_RETURN_NOT_VALUE((bpp <= 0),
111 DISPLAY_TEST_LOGE("CheckPixel do not support format %d", handle.format));
112 DISPLAY_TEST_CHK_RETURN_NOT_VALUE((handle.virAddr == nullptr),
113 DISPLAY_TEST_LOGE("CheckPixel viraddr is null must map it"));
114 DISPLAY_TEST_CHK_RETURN_NOT_VALUE((x < 0 || x >= handle.width),
115 DISPLAY_TEST_LOGE("CheckPixel invalid parameter x:%d width:%d", x, handle.width));
116 DISPLAY_TEST_CHK_RETURN_NOT_VALUE((y < 0 || y >= handle.height),
117 DISPLAY_TEST_LOGE("CheckPixel invalid parameter y:%d height:%d", y, handle.height));
118
119 int32_t position = y * handle.width + x;
120 if ((position * pixelBytes) > handle.size) {
121 DISPLAY_TEST_LOGE("the pixel postion outside\n");
122 }
123 uint32_t *pixel = reinterpret_cast<uint32_t *>(handle.virAddr) + position;
124 *pixel = color;
125 }
126
CalculRotateSize(TransformType angle,int & width,int & height)127 static void CalculRotateSize(TransformType angle, int &width, int &height)
128 {
129 switch (angle) {
130 case ROTATE_NONE:
131 break;
132 case ROTATE_180:
133 break;
134 case ROTATE_90:
135 case ROTATE_270:
136 width = width ^ height;
137 height = width ^ height;
138 width = width ^ height;
139 break;
140 default:
141 break;
142 }
143 }
144
AllocateTestMemory(const GrallocFuncs & grallocFuncs,const AllocInfo & info,uint32_t color)145 static BufferHandle *AllocateTestMemory(const GrallocFuncs &grallocFuncs, const AllocInfo &info, uint32_t color)
146 {
147 int32_t ret;
148 BufferHandle *buffer = nullptr;
149 ret = grallocFuncs.AllocMem(&info, &buffer);
150 if (ret != DISPLAY_SUCCESS) {
151 return nullptr;
152 }
153
154 void *vAddr = grallocFuncs.Mmap(buffer);
155 if (vAddr == nullptr) {
156 return nullptr;
157 }
158
159 DISPLAY_TEST_LOGD(" vAddr %p buffer->size %d", vAddr, buffer->size);
160 for (int x = 0; x < buffer->width; x++) {
161 for (int y = 0; y < buffer->height; y++) {
162 SetPixel(*buffer, x, y, color);
163 }
164 }
165
166 ret = grallocFuncs.FlushCache(buffer);
167 if (ret != DISPLAY_SUCCESS) {
168 return nullptr;
169 }
170 return buffer;
171 }
172
AllocateRotateTestMemory(const GrallocFuncs & grallocFuncs,const AllocInfo & info,int position_x,int position_y)173 static BufferHandle *AllocateRotateTestMemory(const GrallocFuncs &grallocFuncs, const AllocInfo &info, int position_x,
174 int position_y)
175 {
176 BufferHandle *buffer = nullptr;
177 int32_t ret = grallocFuncs.AllocMem(&info, &buffer);
178 if (ret != DISPLAY_SUCCESS) {
179 DISPLAY_TEST_LOGE("RotateTest allocMem failed!");
180 return nullptr;
181 }
182
183 void *vAddr = grallocFuncs.Mmap(buffer);
184 if (vAddr == nullptr) {
185 DISPLAY_TEST_LOGE("RotateTest mmap failed!");
186 grallocFuncs.FreeMem(buffer);
187 return nullptr;
188 }
189
190 DISPLAY_TEST_LOGD(" vAddr %p buffer->size %d", vAddr, buffer->size);
191 for (int x = 0; x < buffer->width; x++) {
192 for (int y = 0; y < buffer->height; y++) {
193 if (position_x == x && position_y == y) {
194 SetPixel(*buffer, x, y, CHECK_COLOR);
195 } else {
196 SetPixel(*buffer, x, y, DEFAULT_COLOR);
197 }
198 }
199 }
200 ret = grallocFuncs.FlushCache(buffer);
201 if (ret != DISPLAY_SUCCESS) {
202 DISPLAY_TEST_LOGE("RotateTest FlushCache failed!");
203 grallocFuncs.Unmap(buffer);
204 grallocFuncs.FreeMem(buffer);
205 return nullptr;
206 }
207 return buffer;
208 }
209
ReleaseTestMemory(const GrallocFuncs & grallocFuncs,BufferHandle & bufferHdl)210 static void ReleaseTestMemory(const GrallocFuncs &grallocFuncs, BufferHandle &bufferHdl)
211 {
212 grallocFuncs.Unmap((&bufferHdl));
213 grallocFuncs.FreeMem(&bufferHdl);
214 }
215
TestSetUp()216 void GfxTestBase::TestSetUp()
217 {
218 int32_t ret = GrallocInitialize(&mGrallocFuncs);
219 DISPLAY_TEST_CHK_RETURN_NOT_VALUE((ret != DISPLAY_SUCCESS), DISPLAY_TEST_LOGE("gralloc initialize failure");
220 ASSERT_TRUE(0));
221 ret = GfxTestModuleInit();
222 DISPLAY_TEST_CHK_RETURN_NOT_VALUE((ret != DISPLAY_SUCCESS) || (mGfxFuncs == nullptr),
223 DISPLAY_TEST_LOGE("gfx initialize failure"); ASSERT_TRUE(0));
224 ret = mGfxFuncs->InitGfx();
225 DISPLAY_TEST_CHK_RETURN_NOT_VALUE((ret != DISPLAY_SUCCESS), DISPLAY_TEST_LOGE("gfx intgfx failure");
226 ASSERT_TRUE(0));
227 InitTestBuffer();
228 }
229
TestTearDown()230 void GfxTestBase::TestTearDown()
231 {
232 int32_t ret;
233 DeInitTestBuffer();
234 if (mGfxFuncs == nullptr) {
235 DISPLAY_TEST_LOGE("mGfxFuncs is null");
236 return;
237 }
238 ret = mGfxFuncs->DeinitGfx();
239 DISPLAY_TEST_CHK_RETURN_NOT_VALUE((ret != DISPLAY_SUCCESS), DISPLAY_TEST_LOGE("gfx intgfx failure");
240 ASSERT_TRUE(0));
241 ret = GrallocUninitialize(mGrallocFuncs);
242 if (ret != DISPLAY_SUCCESS) {
243 DISPLAY_TEST_LOGE("gralloc uninitialize failure");
244 ASSERT_TRUE(0);
245 }
246 ret = GfxTestModuleDeinit();
247 if (ret != DISPLAY_SUCCESS) {
248 DISPLAY_TEST_LOGE("gfx uninitialize failure");
249 ASSERT_TRUE(0);
250 }
251 }
252
InitTestBuffer()253 void GfxTestBase::InitTestBuffer()
254 {
255 const int testWidth = 1080;
256 const int testHeight = 1920;
257 const uint32_t initSrcRgba = 0x555555ee; // RGBA
258 const uint32_t initDstRgba = 0xaaaaaa22; // RGBA
259
260 mSrcRect = { 0, 0, testWidth, testHeight };
261 mDstRect = { 0, 0, testWidth, testHeight };
262 // allocate a 1080p memory.
263 AllocInfo allocInfo = {
264 .width = testWidth, // 1080p width memory
265 .height = testHeight, // 1080p height memory
266 .usage = (uint64_t)(HBM_USE_CPU_WRITE | HBM_USE_CPU_READ | HBM_USE_MEM_DMA),
267 .format = PIXEL_FMT_RGBA_8888
268 };
269
270 mSrcBuffer = AllocateTestMemory(*mGrallocFuncs, allocInfo, initSrcRgba);
271 mDstBuffer = AllocateTestMemory(*mGrallocFuncs, allocInfo, initDstRgba);
272 mSoftBlendBuffer = AllocateTestMemory(*mGrallocFuncs, allocInfo, initDstRgba);
273 if ((mSrcBuffer == nullptr) || (mDstBuffer == nullptr) || (mSoftBlendBuffer == nullptr)) {
274 DISPLAY_TEST_LOGE("init memory failed");
275 ASSERT_TRUE(0);
276 }
277 }
278
DeInitTestBuffer()279 void GfxTestBase::DeInitTestBuffer()
280 {
281 if (mSrcBuffer != nullptr) {
282 ReleaseTestMemory(*mGrallocFuncs, *mSrcBuffer);
283 }
284 if (mDstBuffer != nullptr) {
285 ReleaseTestMemory(*mGrallocFuncs, *mDstBuffer);
286 }
287 if (mSoftBlendBuffer != nullptr) {
288 ReleaseTestMemory(*mGrallocFuncs, *mSoftBlendBuffer);
289 }
290 }
291
GfxTestModuleInit(void)292 int32_t GfxTestBase::GfxTestModuleInit(void)
293 {
294 mGfxTestModule = dlopen(LIB_HDI_GFX_NAME, RTLD_NOW | RTLD_NOLOAD);
295 if (mGfxTestModule != nullptr) {
296 DISPLAY_TEST_LOGD("Module %s already loaded", LIB_HDI_GFX_NAME);
297 } else {
298 DISPLAY_TEST_LOGD("Loading module %s", LIB_HDI_GFX_NAME);
299 mGfxTestModule = dlopen(LIB_HDI_GFX_NAME, RTLD_NOW);
300 if (mGfxTestModule == nullptr) {
301 DISPLAY_TEST_LOGE("Failed to load module: %s", dlerror());
302 return DISPLAY_FAILURE;
303 }
304 }
305
306 using InitFunc = int32_t (*)(GfxFuncs **funcs);
307 InitFunc func = reinterpret_cast<InitFunc>(dlsym(mGfxTestModule, LIB_GFX_FUNC_INIT));
308 if (func == nullptr) {
309 DISPLAY_TEST_LOGE("Failed to lookup %s function: %s", LIB_GFX_FUNC_INIT, dlerror());
310 dlclose(mGfxTestModule);
311 return DISPLAY_FAILURE;
312 }
313 return func(&mGfxFuncs);
314 }
315
GfxTestModuleDeinit(void)316 int32_t GfxTestBase::GfxTestModuleDeinit(void)
317 {
318 int32_t ret = DISPLAY_SUCCESS;
319 if (mGfxTestModule == nullptr) {
320 using DeinitFunc = int32_t (*)(GfxFuncs *funcs);
321 DeinitFunc func = reinterpret_cast<DeinitFunc>(dlsym(mGfxTestModule, LIB_GFX_FUNC_DEINIT));
322 if (func == nullptr) {
323 DISPLAY_TEST_LOGE("Failed to lookup %s function: %s", LIB_GFX_FUNC_DEINIT, dlerror());
324 } else {
325 ret = func(mGfxFuncs);
326 }
327 dlclose(mGfxTestModule);
328 }
329 return ret;
330 }
331
SetUp()332 void GfxBlendTypeTest::SetUp()
333 {
334 TestSetUp();
335 }
336
TearDown()337 void GfxBlendTypeTest::TearDown()
338 {
339 TestTearDown();
340 }
341
GfxBlitBlendTypeTest(BlendType type)342 int32_t GfxBlendTypeTest::GfxBlitBlendTypeTest(BlendType type)
343 {
344 int ret;
345 GfxOpt opt = { 0 };
346 opt.blendType = type;
347 opt.enPixelAlpha = true;
348 if (mGfxFuncs == nullptr) {
349 DISPLAY_TEST_LOGE("mGfxFuncs is null");
350 return DISPLAY_FAILURE;
351 }
352 ret = GfxBlitTest(*mGfxFuncs, *mGrallocFuncs, opt);
353 return ret;
354 }
355
GfxBlitTest(const GfxFuncs & gfxFuncs,const GrallocFuncs & grallocFuncs,GfxOpt & opt)356 int32_t GfxBlendTypeTest::GfxBlitTest(const GfxFuncs &gfxFuncs, const GrallocFuncs &grallocFuncs, GfxOpt &opt)
357 {
358 int32_t ret;
359 ISurface dstSurface = { 0 };
360 ISurface srcSurface = { 0 };
361
362 SourceSurfaceInit(srcSurface, *mSrcBuffer);
363 SourceSurfaceInit(dstSurface, *mDstBuffer);
364 SoftBlit softBlit(*mSrcBuffer, mSrcRect, *mSoftBlendBuffer, mDstRect, opt.blendType);
365
366 auto blitBegin = std::chrono::steady_clock::now();
367 ret = gfxFuncs.Blit(&srcSurface, &mSrcRect, &dstSurface, &mDstRect, &opt);
368 auto blitEnd = std::chrono::steady_clock::now();
369 double durationBlit = std::chrono::duration<double, std::milli>(blitEnd - blitBegin).count();
370 DISPLAY_TEST_CHK_RETURN((ret != DISPLAY_SUCCESS), ret, DISPLAY_TEST_LOGE("Blit failed ret:%d", ret));
371 auto syncBegin = std::chrono::steady_clock::now();
372 ret = grallocFuncs.InvalidateCache(mDstBuffer);
373 auto syncEnd = std::chrono::steady_clock::now();
374 double durationSync = std::chrono::duration<double, std::milli>(syncEnd - syncBegin).count();
375 DISPLAY_TEST_LOGD("gfx blit cost %lf ms, sync cost %lf ms", durationBlit, durationSync);
376 DISPLAY_TEST_CHK_RETURN((ret != DISPLAY_SUCCESS), ret,
377 DISPLAY_TEST_LOGE("gralloc buffer flush cache failed ret:%d", ret));
378 if (!softBlit.RunAndCheck(*mDstBuffer)) {
379 ret = DISPLAY_FAILURE;
380 }
381 return ret;
382 }
383
SetUp()384 void GfxFillTest ::SetUp()
385 {
386 TestSetUp();
387 }
388
TearDown()389 void GfxFillTest::TearDown()
390 {
391 TestTearDown();
392 }
393
FillRectTest(uint32_t testColor)394 int32_t GfxFillTest::FillRectTest(uint32_t testColor)
395 {
396 int32_t ret;
397 ISurface dstSurface = { 0 };
398 GfxOpt opt = { 0 };
399 if (mGfxFuncs == nullptr) {
400 DISPLAY_TEST_LOGE("mGfxFuncs is null");
401 return DISPLAY_FAILURE;
402 }
403 SourceSurfaceInit(dstSurface, *mDstBuffer);
404 ret = mGfxFuncs->InitGfx();
405 DISPLAY_TEST_CHK_RETURN((ret != DISPLAY_SUCCESS), ret, DISPLAY_TEST_LOGE("InitGfx failed ret:%d", ret));
406
407 ret = mGfxFuncs->FillRect(&dstSurface, &mDstRect, testColor, &opt);
408 DISPLAY_TEST_CHK_RETURN((ret != DISPLAY_SUCCESS), ret, DISPLAY_TEST_LOGE("FillRect failed ret:%d", ret));
409
410 ret = mGfxFuncs->DeinitGfx();
411 DISPLAY_TEST_CHK_RETURN((ret != DISPLAY_SUCCESS), ret, DISPLAY_TEST_LOGE("DeinitGfx failed ret:%d", ret));
412
413 ret = mGrallocFuncs->InvalidateCache(mDstBuffer);
414 DISPLAY_TEST_CHK_RETURN((ret != DISPLAY_SUCCESS), ret,
415 DISPLAY_TEST_LOGE("gralloc buffer flush cache failed ret:%d", ret));
416 // check the buffer
417 for (int x = 0; x < mDstBuffer->width; x++) {
418 for (int y = 0; y < mDstBuffer->height; y++) {
419 uint32_t pixel = CheckPixel(*mDstBuffer, x, y, testColor);
420 if (pixel != testColor) {
421 DISPLAY_TEST_LOGE("the color check failed pixel x: %d y:%d color: 0x%x", x, y, pixel);
422 return DISPLAY_FAILURE;
423 }
424 }
425 }
426 return ret;
427 }
428
SetUp()429 void GfxRotateTest::SetUp()
430 {
431 int32_t ret = GrallocInitialize(&mGrallocFuncs);
432 DISPLAY_TEST_CHK_RETURN_NOT_VALUE((ret != DISPLAY_SUCCESS), DISPLAY_TEST_LOGE("gralloc initialize failure");
433 ASSERT_TRUE(0));
434 ret = GfxTestModuleInit();
435 DISPLAY_TEST_CHK_RETURN_NOT_VALUE((ret != DISPLAY_SUCCESS) || (mGfxFuncs == nullptr),
436 DISPLAY_TEST_LOGE("gfx initialize failure"); ASSERT_TRUE(0));
437 ret = mGfxFuncs->InitGfx();
438 DISPLAY_TEST_CHK_RETURN_NOT_VALUE((ret != DISPLAY_SUCCESS), DISPLAY_TEST_LOGE("gfx intgfx failure");
439 ASSERT_TRUE(0));
440 const int width = 1920;
441 const int height = 1080;
442
443 mSrcRect = { 0, 0, width, height };
444 AllocInfo srcAllocInfo = {
445 .width = width,
446 .height = height,
447 .usage = (uint64_t)(HBM_USE_CPU_WRITE | HBM_USE_CPU_READ | HBM_USE_MEM_DMA),
448 .format = PIXEL_FMT_BGRA_8888
449 };
450
451 mSrcBuffer = AllocateRotateTestMemory(*mGrallocFuncs, srcAllocInfo, ROTATE_DEFULT_X, ROTATE_DEFULT_Y);
452 }
453
TearDown()454 void GfxRotateTest::TearDown()
455 {
456 TestTearDown();
457 }
458
RotateTest(RotateParam param)459 int32_t GfxRotateTest::RotateTest(RotateParam param)
460 {
461 int32_t ret;
462 ISurface dstSurface = { 0 };
463 ISurface srcSurface = { 0 };
464 GfxOpt opt = { 0 };
465 opt.rotateType = param.transformType;
466 opt.blendType = param.blendType;
467 int width = 1920;
468 int height = 1080;
469
470 if (mGfxFuncs == nullptr) {
471 DISPLAY_TEST_LOGE("mGfxFuncs is null");
472 return DISPLAY_FAILURE;
473 }
474 CalculRotateSize(param.transformType, width, height);
475 mDstRect = { 0, 0, width, height };
476 AllocInfo dstAllocInfo = {
477 .width = width,
478 .height = height,
479 .usage = HBM_USE_CPU_WRITE | HBM_USE_CPU_READ | HBM_USE_MEM_DMA,
480 .format = PIXEL_FMT_BGRA_8888
481 };
482 mDstBuffer = AllocateRotateTestMemory(*mGrallocFuncs, dstAllocInfo, -1, -1);
483
484 SourceSurfaceInit(srcSurface, *mSrcBuffer);
485 SourceSurfaceInit(dstSurface, *mDstBuffer);
486 ret = mGfxFuncs->InitGfx();
487 DISPLAY_TEST_CHK_RETURN((ret != DISPLAY_SUCCESS), ret, DISPLAY_TEST_LOGE("InitGfx failed ret:%d", ret));
488 ret = mGfxFuncs->Blit(&srcSurface, &mSrcRect, &dstSurface, &mDstRect, &opt);
489 DISPLAY_TEST_CHK_RETURN((ret != DISPLAY_SUCCESS), ret, DISPLAY_TEST_LOGE("RotateTest failed ret:%d", ret));
490 ret = mGfxFuncs->DeinitGfx();
491 DISPLAY_TEST_CHK_RETURN((ret != DISPLAY_SUCCESS), ret, DISPLAY_TEST_LOGE("DeinitGfx failed ret:%d", ret));
492
493 ret = mGrallocFuncs->InvalidateCache(mDstBuffer);
494 DISPLAY_TEST_CHK_RETURN((ret != DISPLAY_SUCCESS), ret,
495 DISPLAY_TEST_LOGE("gralloc buffer flush cache failed ret:%d", ret));
496 // check the buffer
497 ret = DISPLAY_FAILURE;
498 for (int x = 0; x < mDstBuffer->width; x++) {
499 for (int y = 0; y < mDstBuffer->height; y++) {
500 uint32_t pixel = GetPixelValue(*mDstBuffer, x, y);
501 if ((pixel == CHECK_COLOR) && (x == param.expectX) && (y == param.expectY)) {
502 DISPLAY_TEST_LOGD("angle = %d, current position = %d,%d", param.transformType, x, y);
503 ret = DISPLAY_SUCCESS;
504 }
505 }
506 }
507 return ret;
508 }
509
TEST_P(GfxBlendTypeTest,BlendType)510 TEST_P(GfxBlendTypeTest, BlendType)
511 {
512 BlendType type = GetParam();
513 int ret = GfxBlitBlendTypeTest(type);
514 ASSERT_TRUE(ret == DISPLAY_SUCCESS);
515 }
TEST_P(GfxFillTest,FillRect)516 TEST_P(GfxFillTest, FillRect)
517 {
518 uint32_t testColor = GetParam();
519 int ret = FillRectTest(testColor);
520 ASSERT_TRUE(ret == DISPLAY_SUCCESS);
521 }
TEST_P(GfxRotateTest,Blit)522 TEST_P(GfxRotateTest, Blit)
523 {
524 RotateParam rotateParams = GetParam();
525 int ret = RotateTest(rotateParams);
526 ASSERT_TRUE(ret == DISPLAY_SUCCESS);
527 }
528 // BLEND_AKD BLEND_AKS has no function to test it
529 static const BlendType BLEND_TYPES[] = {
530 BLEND_NONE,
531 BLEND_CLEAR, /* < CLEAR blending {0, 0} */
532 BLEND_SRC, /* < SRC blending {Sa, Sc} */
533 BLEND_SRCOVER, /* < SRC_OVER blending {Sa + (1 - Sa)*Da, Rc = Sc + (1 - Sa)*Dc} */
534 BLEND_DSTOVER, /* < DST_OVER blending {Sa + (1 - Sa)*Da, Rc = Dc + (1 - Da)*Sc} */
535 BLEND_SRCIN, /* < SRC_IN blending */
536 BLEND_DSTIN, /* < DST_IN blending */
537 BLEND_SRCOUT, /* < SRC_OUT blending */
538 BLEND_DSTOUT, /* < DST_OUT blending */
539 BLEND_SRCATOP, /* < SRC_ATOP blending */
540 BLEND_DSTATOP, /* < DST_ATOP blending */
541 BLEND_ADD, /* < ADD blending */
542 BLEND_XOR, /* < XOR blending */
543 BLEND_DST, /* < DST blending */
544 };
545
546 static const uint32_t FILL_COLORS[] = {
547 0,
548 0xffffffff,
549 0xaaaaaaaa,
550 };
551
552 static const RotateParam TEST_ROTATE_PARAMS[] = {
553 {ROTATE_NONE, BLEND_SRC, 200, 100},
554 {ROTATE_90, BLEND_SRC, 979, 200},
555 {ROTATE_180, BLEND_SRC, 1719, 979},
556 {ROTATE_270, BLEND_SRC, 100, 1719},
557 };
558
559 INSTANTIATE_TEST_CASE_P(GfxTest, GfxBlendTypeTest, ::testing::ValuesIn(BLEND_TYPES));
560 INSTANTIATE_TEST_CASE_P(GfxTest, GfxFillTest, ::testing::ValuesIn(FILL_COLORS));
561 INSTANTIATE_TEST_CASE_P(GfxTest, GfxRotateTest, ::testing::ValuesIn(TEST_ROTATE_PARAMS));
562 }
563