1+ /*
2+ * Twin - A Tiny Window System
3+ * Copyright (c) 2024 National Cheng Kung University, Taiwan
4+ * All rights reserved.
5+ */
6+
7+ #include <assert.h>
8+ #include <stdio.h>
9+ #include <string.h>
10+ #include <sys/time.h>
11+ #include <time.h>
12+
13+ #include "twin.h"
14+
15+ #define TEST_PIX_WIDTH 1200
16+ #define TEST_PIX_HEIGHT 800
17+
18+ static twin_pixmap_t * src32 , * dst32 ;
19+ static int twidth , theight , titers ;
20+
21+ static void test_argb32_source_argb32 (void )
22+ {
23+ twin_operand_t srco = {.source_kind = TWIN_PIXMAP , .u .pixmap = src32 };
24+ twin_composite (dst32 , 0 , 0 , & srco , 0 , 0 , NULL , 0 , 0 , TWIN_SOURCE , twidth ,
25+ theight );
26+ }
27+
28+ static void test_argb32_over_argb32 (void )
29+ {
30+ twin_operand_t srco = {.source_kind = TWIN_PIXMAP , .u .pixmap = src32 };
31+ twin_composite (dst32 , 0 , 0 , & srco , 0 , 0 , NULL , 0 , 0 , TWIN_OVER , twidth ,
32+ theight );
33+ }
34+
35+ static void do_test (const char * name , void (* test )(void ))
36+ {
37+ struct timeval start , end ;
38+ unsigned long long sus , eus ;
39+ char spc [128 ];
40+ char * s ;
41+ int i ;
42+
43+ printf ("%s" , name );
44+
45+ gettimeofday (& start , NULL );
46+ for (i = 0 ; i < titers ; i ++ )
47+ test ();
48+ gettimeofday (& end , NULL );
49+ sus = (unsigned long long ) start .tv_sec * 1000000ull + start .tv_usec ;
50+ eus = (unsigned long long ) end .tv_sec * 1000000ull + end .tv_usec ;
51+
52+ s = spc ;
53+ for (i = strlen (name ); i < 40 ; i ++ )
54+ * (s ++ ) = ' ' ;
55+ * s = 0 ;
56+ printf ("%s %f sec\n" , spc , ((float ) (eus - sus )) / 1000000.0 );
57+ }
58+
59+ #define DO_TEST (name ) do_test(#name, test_##name)
60+
61+ static void do_tests (int width , int height , int iters )
62+ {
63+ twidth = width ;
64+ theight = height ;
65+ titers = iters ;
66+
67+ DO_TEST (argb32_source_argb32 );
68+ DO_TEST (argb32_over_argb32 );
69+ }
70+
71+ static void do_all_tests (const char * title ,
72+ int len_init ,
73+ int len_max ,
74+ int len_incre ,
75+ int iters )
76+ {
77+ for (int len = len_init ; len < len_max ; len += len_incre ) {
78+ printf ("[ %s: %dx%dx%d ]\n" , title , len , len , iters );
79+ do_tests (len , len , iters );
80+ }
81+
82+ printf ("\n" );
83+ }
84+
85+ int main (void )
86+ {
87+ /* Create some test pixmaps */
88+ src32 = twin_pixmap_from_file ("assets/tux.png" , TWIN_ARGB32 );
89+ assert (src32 );
90+ dst32 = twin_pixmap_create (TWIN_ARGB32 , TEST_PIX_WIDTH , TEST_PIX_HEIGHT );
91+ assert (dst32 );
92+
93+ /* fill pixmaps */
94+ twin_fill (dst32 , 0x80112233 , TWIN_SOURCE , 0 , 0 , TEST_PIX_WIDTH ,
95+ TEST_PIX_HEIGHT );
96+
97+ /* pre-touch data */
98+ test_argb32_source_argb32 ();
99+
100+ do_all_tests ("Pixmap" , 7 , 18 , 2 , 1000000 );
101+
102+ return 0 ;
103+ }
0 commit comments