blob: e4a3fd52439aed48a2b39acbde8fb8cd83eed42a [file] [log] [blame]
Pierre Ossmanab9b95f2014-09-24 16:19:52 +02001/* Copyright 2013-2014 Pierre Ossman <ossman@cendio.se> for Cendio AB
2 *
3 * This is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This software is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this software; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
16 * USA.
17 */
18
Pierre Ossman236c03c2014-07-04 14:12:49 +020019#include <stdio.h>
20#include <stdlib.h>
21#include <string.h>
22#include <time.h>
23
24#include <rfb/PixelFormat.h>
Pierre Ossman236c03c2014-07-04 14:12:49 +020025
26#include "util.h"
27
28static const int tile = 64;
29static const int fbsize = 4096;
30
31static rdr::U8 *fb1, *fb2;
32
Pierre Ossman236c03c2014-07-04 14:12:49 +020033typedef void (*testfn) (rfb::PixelFormat&, rfb::PixelFormat&, rdr::U8*, rdr::U8*);
34
35struct TestEntry {
36 const char *label;
37 testfn fn;
38};
39
40static void testMemcpy(rfb::PixelFormat &dstpf, rfb::PixelFormat &srcpf,
41 rdr::U8 *dst, rdr::U8 *src)
42{
43 int h;
44 h = tile;
45 while (h--) {
46 memcpy(dst, src, tile * dstpf.bpp/8);
47 dst += fbsize * dstpf.bpp/8;
48 src += fbsize * dstpf.bpp/8;
49 }
50}
51
Pierre Ossman761fe242014-01-29 17:00:36 +010052static void testBuffer(rfb::PixelFormat &dstpf, rfb::PixelFormat &srcpf,
53 rdr::U8 *dst, rdr::U8 *src)
54{
55 dstpf.bufferFromBuffer(dst, srcpf, src, tile, tile, fbsize, fbsize);
56}
57
Pierre Ossman236c03c2014-07-04 14:12:49 +020058static void testToRGB(rfb::PixelFormat &dstpf, rfb::PixelFormat &srcpf,
59 rdr::U8 *dst, rdr::U8 *src)
60{
61 srcpf.rgbFromBuffer(dst, src, tile, fbsize, tile);
62}
63
64static void testFromRGB(rfb::PixelFormat &dstpf, rfb::PixelFormat &srcpf,
65 rdr::U8 *dst, rdr::U8 *src)
66{
67 dstpf.bufferFromRGB(dst, src, tile, fbsize, tile);
68}
69
70static void doTest(testfn fn, rfb::PixelFormat &dstpf, rfb::PixelFormat &srcpf)
71{
Pierre Ossman236c03c2014-07-04 14:12:49 +020072 startCpuCounter();
73
74 for (int i = 0;i < 10000;i++) {
75 int x, y;
76 rdr::U8 *dst, *src;
77 x = rand() % (fbsize - tile);
78 y = rand() % (fbsize - tile);
79 dst = fb1 + (x + y * fbsize) * dstpf.bpp/8;
80 src = fb2 + (x + y * fbsize) * srcpf.bpp/8;
81 fn(dstpf, srcpf, dst, src);
82 }
83
84 endCpuCounter();
85
86 float data, time;
87
88 data = (double)tile * tile * 10000;
89 time = getCpuCounter();
90
91 printf("%g", data / (1000.0*1000.0) / time);
92}
93
94struct TestEntry tests[] = {
95 {"memcpy", testMemcpy},
Pierre Ossman761fe242014-01-29 17:00:36 +010096 {"bufferFromBuffer", testBuffer},
Pierre Ossman236c03c2014-07-04 14:12:49 +020097 {"rgbFromBuffer", testToRGB},
98 {"bufferFromRGB", testFromRGB},
99};
100
101static void doTests(rfb::PixelFormat &dstpf, rfb::PixelFormat &srcpf)
102{
Pierre Ossman5c23b9e2015-03-03 16:26:03 +0100103 size_t i;
Pierre Ossman236c03c2014-07-04 14:12:49 +0200104 char dstb[256], srcb[256];
105
106 dstpf.print(dstb, sizeof(dstb));
107 srcpf.print(srcb, sizeof(srcb));
108
Pierre Ossman236c03c2014-07-04 14:12:49 +0200109 printf("%s,%s", srcb, dstb);
110
111 for (i = 0;i < sizeof(tests)/sizeof(tests[0]);i++) {
112 printf(",");
113 doTest(tests[i].fn, dstpf, srcpf);
114 }
115
116 printf("\n");
117}
118
119int main(int argc, char **argv)
120{
Pierre Ossman5c23b9e2015-03-03 16:26:03 +0100121 size_t bufsize;
Pierre Ossman236c03c2014-07-04 14:12:49 +0200122
123 time_t t;
124 char datebuffer[256];
125
Pierre Ossman5c23b9e2015-03-03 16:26:03 +0100126 size_t i;
Pierre Ossman236c03c2014-07-04 14:12:49 +0200127
128 bufsize = fbsize * fbsize * 4;
129
130 fb1 = new rdr::U8[bufsize];
131 fb2 = new rdr::U8[bufsize];
132
Pierre Ossman5c23b9e2015-03-03 16:26:03 +0100133 for (i = 0;i < bufsize;i++) {
Pierre Ossman236c03c2014-07-04 14:12:49 +0200134 fb1[i] = rand();
135 fb2[i] = rand();
136 }
137
138 time(&t);
139 strftime(datebuffer, sizeof(datebuffer), "%Y-%m-%d %H:%M UTC", gmtime(&t));
140
Pierre Ossman8c7962b2014-09-24 16:17:42 +0200141 printf("# Pixel Conversion Performance Test %s\n", datebuffer);
Pierre Ossman236c03c2014-07-04 14:12:49 +0200142 printf("#\n");
143 printf("# Frame buffer: %dx%d pixels\n", fbsize, fbsize);
144 printf("# Tile size: %dx%d pixels\n", tile, tile);
145 printf("#\n");
146 printf("# Note: Results are Mpixels/sec\n");
147 printf("#\n");
148
149 printf("Source format,Destination Format");
150 for (i = 0;i < sizeof(tests)/sizeof(tests[0]);i++)
151 printf(",%s", tests[i].label);
152 printf("\n");
153
154 rfb::PixelFormat dstpf, srcpf;
155
156 /* rgb888 targets */
157
Pierre Ossman00bed5c2014-07-09 14:12:39 +0200158 printf("\n");
159
Pierre Ossman236c03c2014-07-04 14:12:49 +0200160 dstpf.parse("rgb888");
161
162 srcpf.parse("rgb888");
163 doTests(dstpf, srcpf);
164
165 srcpf.parse("bgr888");
166 doTests(dstpf, srcpf);
167
168 srcpf.parse("rgb565");
169 doTests(dstpf, srcpf);
170
171 srcpf.parse("rgb232");
172 doTests(dstpf, srcpf);
173
174 /* rgb565 targets */
175
Pierre Ossman00bed5c2014-07-09 14:12:39 +0200176 printf("\n");
177
Pierre Ossman236c03c2014-07-04 14:12:49 +0200178 dstpf.parse("rgb565");
179
180 srcpf.parse("rgb888");
181 doTests(dstpf, srcpf);
182
183 srcpf.parse("bgr565");
184 doTests(dstpf, srcpf);
185
186 srcpf.parse("rgb232");
187 doTests(dstpf, srcpf);
188
Pierre Ossmane18132c2014-07-09 14:12:12 +0200189 /* rgb232 targets */
190
Pierre Ossman00bed5c2014-07-09 14:12:39 +0200191 printf("\n");
192
Pierre Ossmane18132c2014-07-09 14:12:12 +0200193 dstpf.parse("rgb232");
194
195 srcpf.parse("rgb888");
196 doTests(dstpf, srcpf);
197
198 srcpf.parse("rgb565");
199 doTests(dstpf, srcpf);
200
201 srcpf.parse("bgr232");
202 doTests(dstpf, srcpf);
203
Pierre Ossman236c03c2014-07-04 14:12:49 +0200204 /* rgb565 with endian conversion (both ways) */
205
Pierre Ossman00bed5c2014-07-09 14:12:39 +0200206 printf("\n");
207
Pierre Ossman236c03c2014-07-04 14:12:49 +0200208 dstpf = rfb::PixelFormat(32, 24, false, true, 255, 255, 255, 0, 8, 16);
209 srcpf = rfb::PixelFormat(32, 24, true, true, 255, 255, 255, 0, 8, 16);
210
211 doTests(srcpf, dstpf);
212
213 doTests(dstpf, srcpf);
214
215 dstpf = rfb::PixelFormat(16, 16, false, true, 31, 63, 31, 0, 5, 11);
216 srcpf = rfb::PixelFormat(16, 16, true, true, 31, 63, 31, 0, 5, 11);
217
218 doTests(srcpf, dstpf);
219
220 doTests(dstpf, srcpf);
221
222 return 0;
223}
224