intuition.library: implement EasyReqest and BuildEasyRequest that are x64/arm compatible
[AROS.git] / test / benchmarks / graphics / primitives.c
blob0cfd246b147508bfc2e6ed3e5f7dbaa1ffc0798c
1 /*
2 Copyright © 2003, The AROS Development Team. All rights reserved.
3 $Id$
5 Originally written by by Rune Elvemo.
6 Improved and adapted to gcc by Fabio Alemagna.
7 */
9 #include <stdio.h>
10 #include <stdlib.h>
11 #include <math.h>
13 #include <exec/types.h>
14 #include <exec/io.h>
15 #include <devices/timer.h>
16 #include <graphics/gfxbase.h>
17 #include <graphics/gfxmacros.h>
18 #include <graphics/rastport.h>
19 #include <intuition/intuition.h>
21 #include <proto/exec.h>
22 #include <proto/timer.h>
23 #include <proto/intuition.h>
24 #include <proto/graphics.h>
25 #include <proto/dos.h>
26 #include <proto/alib.h>
28 struct Device *TimerBase;
29 struct MsgPort *TimerMP;
30 struct timerequest *TimerIO;
32 struct Window *benchwin;
33 struct Screen *wb_screen;
35 typedef struct
37 ULONG x,y;
38 } xypoint;
40 #define NUMITERATIONS (16*1024)
41 xypoint xytable[NUMITERATIONS];
43 int init(void);
44 void cleanup(void);
46 #define DOTEST(function) \
47 { \
48 int i = 0, pen; \
49 struct timeval start, end; \
50 float total; \
52 GetSysTime(&start); \
53 for (pen = 0; pen < NUMITERATIONS; pen++) \
54 { \
55 const ULONG x = xytable[i].x; \
56 const ULONG y = xytable[i].y; \
57 struct RastPort *rport = benchwin->RPort; \
59 SetAPen(benchwin->RPort, pen); \
61 function; \
63 i++; \
64 } \
65 GetSysTime(&end); \
66 SubTime(&end,&start); \
68 printf("\nResults for " #function ":\n"); \
70 total = end.tv_secs + ((float)end.tv_micro / 1000000); \
72 printf("total time: %f\n", total); \
73 printf("iterations/sec: %f\n", pen/total); \
75 SetAPen(benchwin->RPort, 0); \
76 RectFill(benchwin->RPort, 0,0, benchwin->GZZWidth, benchwin->GZZHeight); \
79 int main(int argc, char **argv)
81 if (init())
83 DOTEST(DrawCircle(rport, x, y, 10));
84 DOTEST(DrawEllipse(rport, x, y, 10, 20));
85 DOTEST({Move(rport, x, y); Text(rport, "BenchMark", 9);});
86 DOTEST(WritePixel(rport, x, y));
87 DOTEST(RectFill(rport, x, y, x+50, y+50));
88 DOTEST
89 (({
90 WORD pnts[] = {x, y, x+10, y+10, x+50, y+50}; PolyDraw(rport, 3,pnts);
91 }));
93 cleanup();
95 return 0;
98 int init() {
99 wb_screen = LockPubScreen(NULL);
100 if (!wb_screen) return 0;
102 benchwin = OpenWindowTags
104 NULL,
105 WA_Left, 10, WA_Top, 20,
106 WA_Width, 640, WA_Height, 480,
107 WA_DragBar, TRUE,
108 WA_SmartRefresh, TRUE,
109 WA_NoCareRefresh, TRUE,
110 WA_GimmeZeroZero, TRUE,
111 WA_Title, (IPTR)"Gfxlib benchmark",
112 WA_PubScreen, (IPTR)wb_screen,
113 TAG_END
116 UnlockPubScreen(NULL, wb_screen);
118 if (!benchwin) return 0;
120 TimerMP = CreatePort(NULL, 0);
121 if (!TimerMP) return 0;
123 TimerIO = (struct timerequest*)CreateExtIO(TimerMP, sizeof(struct timerequest));
124 if (!TimerIO) return 0;
126 if (OpenDevice(TIMERNAME, UNIT_VBLANK, (struct IORequest*)TimerIO, 0))
127 return 0;
129 TimerBase = TimerIO->tr_node.io_Device;
132 struct timeval start;
133 int i;
135 GetSysTime(&start);
136 srand48(start.tv_secs);
138 for (i = 0; i < sizeof(xytable)/sizeof(xytable[0]); i++)
140 xytable[i].x = drand48() * benchwin->GZZWidth;
141 xytable[i].y = drand48() * benchwin->GZZHeight;
145 return 1;
148 void cleanup(void)
150 if (TimerBase) CloseDevice((struct IORequest*)TimerIO);
151 if (TimerIO) DeleteExtIO((struct IORequest*)TimerIO);
152 if (TimerMP) DeletePort(TimerMP);
153 if (benchwin) CloseWindow(benchwin);