intuition.library: implement EasyReqest and BuildEasyRequest that are x64/arm compatible
[AROS.git] / test / benchmarks / graphics / text.c
blob5edb7a2add72e655c6da26f138ebeb1195acab22
1 /*
2 Copyright © 2011, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Benchmark for:
6 graphics.library/Text
7 Lang: English
8 */
9 /*****************************************************************************
11 NAME
13 text
15 SYNOPSIS
17 LOCATION
19 FUNCTION
21 RESULT
23 NOTES
25 BUGS
27 INTERNALS
29 ******************************************************************************/
31 #if !defined(ONLY_BENCH_CODE)
32 #include <cybergraphx/cybergraphics.h>
33 #include <devices/timer.h>
35 #include <proto/exec.h>
36 #include <proto/dos.h>
37 #include <proto/graphics.h>
38 #include <proto/intuition.h>
39 #include <proto/cybergraphics.h>
40 #include <proto/diskfont.h>
42 #include <stdlib.h>
43 #include <stdio.h>
44 #include <string.h>
45 #include <aros/debug.h>
47 /****************************************************************************************/
49 #define ARG_TEMPLATE "WIDTH=W/N/K,HEIGHT=H/N/K,LEN=W/N/K,MODE=P/K,ANTIALIAS/S"
50 #define ARG_W 0
51 #define ARG_H 1
52 #define ARG_LEN 2
53 #define ARG_MODE 3
54 #define ARG_ANTIALIAS 4
55 #define NUM_ARGS 5
57 /****************************************************************************************/
59 struct RDArgs *myargs;
60 IPTR args[NUM_ARGS];
61 UBYTE s[256];
62 LONG width = 1280;
63 LONG height = 720;
64 LONG linelen = 100;
65 STRPTR modename = "JAM1";
66 STRPTR aa = "NON-ANTIALIASED";
67 LONG mode = JAM1;
68 BOOL antialias = FALSE;
69 STRPTR consttext = "The AROS Development Team. All rights reserved.";
71 struct Window *win;
73 /****************************************************************************************/
75 static void cleanup(STRPTR msg, ULONG retcode)
77 if (msg)
79 fprintf(stderr, "text: %s\n", msg);
82 if (myargs) FreeArgs(myargs);
84 exit(retcode);
87 /****************************************************************************************/
89 static void getarguments(void)
91 if (!(myargs = ReadArgs(ARG_TEMPLATE, args, 0)))
93 Fault(IoErr(), 0, s, 255);
94 cleanup(s, RETURN_FAIL);
97 if (args[ARG_W]) width = *(LONG *)args[ARG_W];
99 if (args[ARG_H]) height = *(LONG *)args[ARG_H];
101 if (args[ARG_LEN]) linelen = *(LONG *)args[ARG_LEN];
103 if (args[ARG_MODE])
105 if (strcasecmp((STRPTR)args[ARG_MODE], "JAM1") == 0)
107 mode = JAM1;
108 modename = "JAM1";
111 if (strcasecmp((STRPTR)args[ARG_MODE], "JAM2") == 0)
113 mode = JAM2;
114 modename = "JAM2";
117 if (strcasecmp((STRPTR)args[ARG_MODE], "COMPLEMENT") == 0)
119 mode = COMPLEMENT;
120 modename = "COMPLEMENT";
123 antialias = (BOOL)args[ARG_ANTIALIAS];
124 if (antialias) aa = "ANTIALIASED";
129 /****************************************************************************************/
130 static void printresults(LONG t, LONG i)
132 LONG bpp;
133 QUAD q;
135 printf("Mode : %s, %s\n", modename, aa);
136 printf("Elapsed time : %d us (%f s)\n", (int)t, (double)t / 1000000);
137 printf("Blits : %d\n", (int)i);
138 printf("Blits/sec : %f\n", i * 1000000.0 / t);
139 printf("Time/blit : %f us (%f s) (%d%% of 25Hz Frame)\n",
140 (double)t / i,
141 (double)t / i / 1000000.0,
142 (int)(100.0 * ((double)t / i) / (1000000.0 / 25.0)));
144 bpp = GetCyberMapAttr(win->WScreen->RastPort.BitMap, CYBRMATTR_BPPIX);
145 printf("\nScreen Bytes Per Pixel: %d\n", (int)bpp);
146 printf("Area size in Pixels : %d\n", (int)(width * height));
147 printf("Area size in Bytes : %d\n", (int)(width * height * bpp));
149 q = ((QUAD)width) * ((QUAD)height) * ((QUAD)bpp) * ((QUAD)i) * ((QUAD)1000000) / (QUAD)t;
150 printf("Bytes/sec to gfx card : %lld (%lld MB)\n", (long long)q, (long long)q / 1048576);
152 #endif /* !defined(ONLY_BENCH_CODE) */
154 /****************************************************************************************/
156 static void action_text(void)
158 struct timeval tv_start, tv_end;
159 LONG t, i;
160 STRPTR buffer = NULL;
161 ULONG x,y;
162 ULONG consttextlen = strlen(consttext);
164 struct TextExtent extend;
166 win = OpenWindowTags(NULL, WA_Borderless, TRUE,
167 WA_InnerWidth, width,
168 WA_InnerHeight, height,
169 WA_Activate, TRUE,
170 WA_IDCMP, IDCMP_VANILLAKEY,
171 TAG_DONE);
173 if (!win)
175 cleanup("Can't open window!", RETURN_FAIL);
178 width = win->Width;
179 height = win->Height;
181 SetAPen(win->RPort, 2);
182 RectFill(win->RPort, 0, 0, width, height);
184 Delay(2 * 50);
186 CurrentTime(&tv_start.tv_secs, &tv_start.tv_micro);
188 /* Set text mode */
189 SetAPen(win->RPort, 1);
190 SetDrMd(win->RPort, mode);
192 if (antialias)
194 struct TextAttr ta;
195 struct TextFont * font;
196 ta.ta_Name = "Vera Sans.font";
197 ta.ta_YSize = 15;
198 ta.ta_Style = 0;
199 ta.ta_Flags = 0;
201 font = OpenDiskFont(&ta);
203 if (font != NULL)
204 SetFont(win->RPort, font);
205 else
207 CloseWindow(win);
208 printf("Failed to set antialiazed font\n");
209 return;
213 /* Generate repetetive content buffer */
214 buffer = AllocVec(linelen + 1, MEMF_PUBLIC | MEMF_CLEAR);
215 for (i = 0; i < linelen; i++)
216 buffer[i] = consttext[i % consttextlen];
218 TextExtent(win->RPort, buffer, linelen, &extend);
220 for(i = 0; ; i++)
222 CurrentTime(&tv_end.tv_secs, &tv_end.tv_micro);
223 t = (tv_end.tv_sec - tv_start.tv_sec) * 1000000 + tv_end.tv_micro - tv_start.tv_micro;
224 if (t >= 10 * 1000000) break;
226 for (y = i % extend.te_Height; y < height; y += extend.te_Height)
227 for (x = 0; x < width; x += extend.te_Width)
229 Move(win->RPort, x, y);
230 Text(win->RPort, buffer, linelen);
234 printresults(t, i);
237 CloseWindow(win);
239 FreeVec(buffer);
242 #if !defined(ONLY_BENCH_CODE)
243 /****************************************************************************************/
245 int main(void)
247 getarguments();
248 action_text();
249 cleanup(NULL, 0);
251 return 0;
253 #endif