GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/test/testlauncher.cpp Lines: 0 358 0.0 %
Date: 2017-11-29 Branches: 0 350 0.0 %

Line Branch Exec Source
1
/*
2
 *  The ManaPlus Client
3
 *  Copyright (C) 2011-2017  The ManaPlus Developers
4
 *
5
 *  This file is part of The ManaPlus Client.
6
 *
7
 *  This program is free software; you can redistribute it and/or modify
8
 *  it under the terms of the GNU General Public License as published by
9
 *  the Free Software Foundation; either version 2 of the License, or
10
 *  any later version.
11
 *
12
 *  This program is distributed in the hope that it will be useful,
13
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 *  GNU General Public License for more details.
16
 *
17
 *  You should have received a copy of the GNU General Public License
18
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
19
 */
20
21
#include "test/testlauncher.h"
22
23
#ifdef USE_OPENGL
24
25
#include "graphicsmanager.h"
26
#include "settings.h"
27
#include "soundmanager.h"
28
29
#include "fs/virtfs/rwops.h"
30
31
#include "gui/skin.h"
32
#include "gui/theme.h"
33
34
#include "gui/fonts/font.h"
35
36
#include "utils/pnglib.h"
37
#include "utils/stringutils.h"
38
39
#include "render/graphics.h"
40
41
#include "render/vertexes/imagecollection.h"
42
43
#include "resources/openglimagehelper.h"
44
#include "resources/screenshothelper.h"
45
#include "resources/surfaceimagehelper.h"
46
#include "resources/wallpaper.h"
47
48
#include "resources/dye/dye.h"
49
#if defined __linux__ || defined __linux
50
#ifdef SIMD_SUPPORTED
51
#include "resources/dye/dyepalette.h"
52
#endif  // SIMD_SUPPORTED
53
#endif  // defined __linux__ || defined __linux
54
55
#include "resources/image/image.h"
56
57
PRAGMA48(GCC diagnostic push)
58
PRAGMA48(GCC diagnostic ignored "-Wshadow")
59
#ifndef USE_SDL2
60
#include <SDL_gfxBlitFunc.h>
61
#endif  // USE_SDL2
62
PRAGMA48(GCC diagnostic pop)
63
64
#include <unistd.h>
65
66
#ifdef WIN32
67
#include <windows.h>
68
#define sleep(seconds) Sleep((seconds) * 1000)
69
#endif  // WIN32
70
71
#include <sys/time.h>
72
73
#include "localconsts.h"
74
75
#ifndef SDL_BIG_ENDIAN
76
#error missing SDL_endian.h
77
#endif  // SDL_BYTEORDER
78
79
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
80
#ifndef USE_SDL2
81
#include "resources/sdlgfxblitfunc.h"
82
#endif  // USE_SDL2
83
#endif  // SDL_BYTEORDER == SDL_LIL_ENDIAN
84
85
#include "debug.h"
86
87
extern Font *boldFont;
88
89
TestLauncher::TestLauncher(std::string test) :
90
    mTest(test),
91
    file()
92
{
93
    file.open(pathJoin(settings.localDataDir, "test.log").c_str(),
94
        std::ios::out);
95
}
96
97
TestLauncher::~TestLauncher()
98
{
99
    file.close();
100
}
101
102
int TestLauncher::exec()
103
{
104
    if (mTest == "1" || mTest == "2" || mTest == "3" || mTest == "19")
105
        return testBackend();
106
    else if (mTest == "4")
107
        return testSound();
108
    else if (mTest == "5" || mTest == "6" || mTest == "7" || mTest == "18")
109
        return testRescale();
110
    else if (mTest == "8" || mTest == "9" || mTest == "10" || mTest == "17")
111
        return testFps();
112
    else if (mTest == "11")
113
        return testBatches();
114
    else if (mTest == "14" || mTest == "15" || mTest == "16" || mTest == "20")
115
        return testTextures();
116
    else if (mTest == "99")
117
        return testVideoDetection();
118
    else if (mTest == "100")
119
        return testInternal();
120
    else if (mTest == "101")
121
        return testDye();
122
    else if (mTest == "102")
123
        return testDraw();
124
    else if (mTest == "103")
125
        return testFps2();
126
    else if (mTest == "104")
127
        return testFps3();
128
    else if (mTest == "105")
129
        return testDyeSSpeed();
130
    else if (mTest == "106")
131
        return testStackSpeed();
132
    else if (mTest == "107")
133
        return testDyeASpeed();
134
    else if (mTest == "108")
135
        return testBlitSpeed();
136
137
    return -1;
138
}
139
140
int TestLauncher::testBackend() const
141
{
142
    const Image *const img = Theme::getImageFromTheme(
143
        "graphics/sprites/arrow_up.png");
144
    if (img == nullptr)
145
        return 1;
146
    const int cnt = 100;
147
148
    for (int f = 0; f < cnt; f ++)
149
    {
150
        mainGraphics->drawImage(img, cnt * 7, cnt * 5);
151
        mainGraphics->updateScreen();
152
    }
153
154
    sleep(1);
155
    return 0;
156
}
157
158
int TestLauncher::testSound() const
159
{
160
    soundManager.playGuiSfx("system/newmessage.ogg");
161
    sleep(1);
162
    soundManager.playSfx("system/newmessage.ogg", 0, 0);
163
    soundManager.playMusic("sfx/system/newmessage.ogg", SkipError_false);
164
    sleep(3);
165
    soundManager.stopMusic();
166
    return 0;
167
}
168
169
int TestLauncher::testRescale() const
170
{
171
    Wallpaper::loadWallpapers();
172
    const std::string wallpaperName = Wallpaper::getWallpaper(800, 600);
173
    const volatile Image *const img = Theme::getImageFromTheme(wallpaperName);
174
    if (img == nullptr)
175
        return 1;
176
177
    sleep(1);
178
    return 0;
179
}
180
181
PRAGMA45(GCC diagnostic push)
182
PRAGMA45(GCC diagnostic ignored "-Wunused-result")
183
184
int TestLauncher::testFps()
185
{
186
    timeval start;
187
    timeval end;
188
189
    Wallpaper::loadWallpapers();
190
    Wallpaper::getWallpaper(800, 600);
191
    Image *img[5];
192
    const int sz = 4;
193
194
    img[0] = Theme::getImageFromTheme("graphics/sprites/arrow_up.png");
195
    img[1] = Theme::getImageFromTheme(
196
        "graphics/gui/target-cursor-normal-l.png");
197
    img[2] = Theme::getImageFromTheme("themes/wood/window.png");
198
    img[3] = Theme::getImageFromTheme("themes/pink/window.png");
199
    img[4] = Theme::getImageFromTheme("graphics/images/login_wallpaper.png");
200
    int idx = 0;
201
202
    const int cnt = 50;
203
204
    gettimeofday(&start, nullptr);
205
    for (int k = 0; k < cnt; k ++)
206
    {
207
        for (int x = 0; x < 800; x += 30)
208
        {
209
            for (int y = 0; y < 600; y += 50)
210
            {
211
                mainGraphics->drawImage(img[idx], x, y);
212
                idx ++;
213
                if (idx > sz)
214
                    idx = 0;
215
                mainGraphics->drawImage(img[idx], x, y);
216
                idx ++;
217
                if (idx > sz)
218
                    idx = 0;
219
            }
220
        }
221
        mainGraphics->updateScreen();
222
    }
223
224
    gettimeofday(&end, nullptr);
225
    const int tFps = calcFps(start, end, cnt);
226
    file << mTest << std::endl;
227
    file << tFps << std::endl;
228
229
    printf("fps: %d\n", tFps / 10);
230
    sleep(1);
231
    return 0;
232
}
233
234
int TestLauncher::testFps2()
235
{
236
    timeval start;
237
    timeval end;
238
239
    Wallpaper::loadWallpapers();
240
    Wallpaper::getWallpaper(800, 600);
241
    Image *img[1];
242
243
    img[0] = Theme::getImageFromTheme("graphics/images/login_wallpaper.png");
244
    mainGraphics->drawImage(img[0], 0, 0);
245
246
    const int cnt = 500;
247
248
    gettimeofday(&start, nullptr);
249
    for (int k = 0; k < cnt; k ++)
250
    {
251
        for (int f = 0; f < 300; f ++)
252
            mainGraphics->testDraw();
253
        mainGraphics->updateScreen();
254
    }
255
256
    gettimeofday(&end, nullptr);
257
    const int tFps = calcFps(start, end, cnt);
258
    file << mTest << std::endl;
259
    file << tFps << std::endl;
260
261
    printf("fps: %d\n", tFps / 10);
262
    sleep(1);
263
    return 0;
264
}
265
266
int TestLauncher::testFps3()
267
{
268
    timeval start;
269
    timeval end;
270
271
    Wallpaper::loadWallpapers();
272
    Wallpaper::getWallpaper(800, 600);
273
    Image *img[2];
274
275
    img[0] = Theme::getImageFromTheme("graphics/sprites/arrow_up.png");
276
    img[1] = Theme::getImageFromTheme("graphics/sprites/arrow_left.png");
277
    ImageVertexes *const vert1 = new ImageVertexes;
278
    vert1->image = img[0];
279
    ImageVertexes *const vert2 = new ImageVertexes;
280
    vert2->image = img[1];
281
282
    for (int f = 0; f < 50; f ++)
283
    {
284
        for (int d = 0; d < 50; d ++)
285
        {
286
            mainGraphics->calcTileVertexes(vert1, img[0], f * 16, d * 12);
287
            mainGraphics->calcTileVertexes(vert1, img[1], f * 16 + 5, d * 12);
288
        }
289
    }
290
    mainGraphics->finalize(vert1);
291
    mainGraphics->finalize(vert2);
292
293
    const int cnt = 2000;
294
295
    gettimeofday(&start, nullptr);
296
    for (int k = 0; k < cnt; k ++)
297
    {
298
        mainGraphics->drawTileVertexes(vert1);
299
        mainGraphics->drawTileVertexes(vert2);
300
        mainGraphics->updateScreen();
301
    }
302
303
    gettimeofday(&end, nullptr);
304
    const int tFps = calcFps(start, end, cnt);
305
    file << mTest << std::endl;
306
    file << tFps << std::endl;
307
308
    printf("fps: %d\n", tFps / 10);
309
    sleep(1);
310
    return 0;
311
}
312
PRAGMA45(GCC diagnostic pop)
313
314
int TestLauncher::testBatches()
315
{
316
    int batches = 512;
317
318
    file << mTest << std::endl;
319
    file << batches << std::endl;
320
    return 0;
321
}
322
323
int TestLauncher::testTextures()
324
{
325
    int maxSize = 512;
326
    int nextSize = 512;
327
    int sz = OpenGLImageHelper::getTextureSize() + 1;
328
    if (sz > 16500)
329
        sz = 16500;
330
331
    const uint32_t bytes1[] =
332
    {
333
        0xFFFF0000U, 0xFFFFFF00U, 0xFF00FFFFU, 0xFF0000FFU,
334
        0xFF000000U, 0xFFFF00FFU
335
    };
336
337
    const uint32_t bytes2[] =
338
    {
339
        0xFF0000FFU, 0xFF00FFFFU, 0xFFFFFF00U, 0xFFFF0000U,
340
        0xFF000000U, 0xFFFF00FFU
341
    };
342
343
    for (nextSize = 512; nextSize < sz; nextSize *= 2)
344
    {
345
        mainGraphics->clearScreen();
346
        SDL_Surface *const surface = imageHelper->create32BitSurface(
347
            nextSize, nextSize);
348
        if (surface == nullptr)
349
            break;
350
        uint32_t *pixels = static_cast<uint32_t*>(surface->pixels);
351
        for (int f = 0; f < 6; f ++)
352
            pixels[f] = bytes1[f];
353
        graphicsManager.getLastError();
354
        graphicsManager.resetCachedError();
355
        Image *const image = imageHelper->loadSurface(surface);
356
        SDL_FreeSurface(surface);
357
        if (image == nullptr)
358
            break;
359
360
        if (graphicsManager.getLastErrorCached() != GL_NO_ERROR)
361
        {
362
            delete image;
363
            break;
364
        }
365
        Image *const subImage = image->getSubImage(0, 0, 10, 10);
366
        if (subImage == nullptr)
367
        {
368
            delete image;
369
            break;
370
        }
371
        mainGraphics->drawImage(subImage, 0, 0);
372
        mainGraphics->updateScreen();
373
        mainGraphics->drawImage(subImage, 0, 0);
374
        delete subImage;
375
        SDL_Surface *const screen1 = screenshortHelper->getScreenshot();
376
        SDL_Surface *const screen2 = ImageHelper::convertTo32Bit(screen1);
377
        SDL_FreeSurface(screen1);
378
        if (screen2 == nullptr)
379
            break;
380
        pixels = static_cast<uint32_t*>(screen2->pixels);
381
        bool fail(false);
382
        for (int f = 0; f < 6; f ++)
383
        {
384
            if (pixels[f] != bytes2[f])
385
            {
386
                fail = true;
387
                break;
388
            }
389
        }
390
391
        SDL_FreeSurface(screen2);
392
        if (fail)
393
            break;
394
395
        maxSize = nextSize;
396
    }
397
398
    file << mTest << std::endl;
399
    file << maxSize << std::endl;
400
    printf("OpenGL max size: %d\n", sz);
401
    printf("actual max size: %d\n", maxSize);
402
    return 0;
403
}
404
405
PRAGMA45(GCC diagnostic push)
406
PRAGMA45(GCC diagnostic ignored "-Wunused-result")
407
408
int TestLauncher::testInternal()
409
{
410
    timeval start;
411
    timeval end;
412
413
    Wallpaper::loadWallpapers();
414
    Wallpaper::getWallpaper(800, 600);
415
    Image *img[4];
416
417
    img[0] = Theme::getImageFromTheme(
418
        "graphics/sprites/manaplus_emotions.png");
419
    img[1] = Theme::getImageFromTheme(
420
        "graphics/sprites/manaplus_emotions.png");
421
    img[2] = Theme::getImageFromTheme("graphics/sprites/arrow_left.png");
422
    img[3] = Theme::getImageFromTheme("graphics/sprites/arrow_right.png");
423
    int idx = 0;
424
    const int mem =  mainGraphics->getMemoryUsage();
425
426
//    int cnt = 5;
427
    const int cnt = 5000;
428
429
    gettimeofday(&start, nullptr);
430
    for (int k = 0; k < cnt; k ++)
431
    {
432
        for (int x = 0; x < 800; x += 20)
433
        {
434
            for (int y = 0; y < 600; y += 25)
435
            {
436
                mainGraphics->drawImage(img[idx], x, y);
437
                mainGraphics->drawImage(img[idx], x + 1, y);
438
                mainGraphics->drawImage(img[idx], x, y + 5);
439
440
                idx ++;
441
                if (idx > 3)
442
                    idx = 0;
443
            }
444
        }
445
        mainGraphics->updateScreen();
446
    }
447
448
    gettimeofday(&end, nullptr);
449
    const int tFps = calcFps(start, end, cnt);
450
    file << mTest << std::endl;
451
    file << tFps << std::endl;
452
    file << mem << std::endl;
453
454
    sleep(1);
455
    return 0;
456
}
457
458
PRAGMA45(GCC diagnostic pop)
459
460
int TestLauncher::testDye()
461
{
462
    SDL_RWops *rw = VirtFs::rwopsOpenRead(
463
        "graphics/sprites/arrow_up.png");
464
    Dye *d = nullptr;
465
466
    if (rw != nullptr)
467
    {
468
        Image *image = d != nullptr ? surfaceImageHelper->load(rw, *d)
469
            : surfaceImageHelper->load(rw);
470
        if (image != nullptr)
471
        {
472
            const SDL_Rect &rect = image->mBounds;
473
            SDL_Surface *surface = surfaceImageHelper->create32BitSurface(
474
                rect.w, rect.h);
475
            if (surface != nullptr)
476
            {
477
                SurfaceImageHelper::combineSurface(image->mSDLSurface, nullptr,
478
                    surface, nullptr);
479
                PngLib::writePNG(image->mSDLSurface,
480
                    settings.tempDir + "/testimage1.png");
481
                PngLib::writePNG(surface,
482
                    settings.tempDir + "/testimage2.png");
483
            }
484
485
            rw = VirtFs::rwopsOpenRead(
486
                "graphics/sprites/arrow_up.png");
487
            d = new Dye("S:#0000ff,00ff00,5c5cff,ff0000");
488
            image = surfaceImageHelper->load(rw, *d);
489
            if (image != nullptr)
490
            {
491
                surface = surfaceImageHelper->create32BitSurface(
492
                    rect.w, rect.h);
493
                if (surface != nullptr)
494
                {
495
                    SurfaceImageHelper::combineSurface(image->mSDLSurface,
496
                        nullptr, surface, nullptr);
497
                    PngLib::writePNG(image->mSDLSurface,
498
                        settings.tempDir + "/testimage3.png");
499
                    PngLib::writePNG(surface,
500
                        settings.tempDir + "/testimage4.png");
501
                }
502
            }
503
        }
504
    }
505
    return 0;
506
}
507
508
#if defined __linux__ || defined __linux
509
#if defined(SIMD_SUPPORTED) || (SDL_BYTEORDER == SDL_LIL_ENDIAN \
510
&& !defined(USE_SDL2))
511
static void calcTime(const char *const msg1,
512
                     const char *const msg2,
513
                     const timespec &time1,
514
                     timespec &time2,
515
                     const uint32_t *const buf)
516
{
517
    clock_gettime(CLOCK_MONOTONIC, &time2);
518
    long diff = ((static_cast<long int>(time2.tv_sec) * 1000000000L
519
        + static_cast<long int>(time2.tv_nsec)) / 1) -
520
        ((static_cast<long int>(time1.tv_sec) * 1000000000L
521
        + static_cast<long int>(time1.tv_nsec)) / 1);
522
    printf("%s: %u\n", msg1, buf[0]);
523
    printf("%s: %011ld\n", msg2, diff);
524
}
525
#endif  // defined(SIMD_SUPPORTED) || (SDL_BYTEORDER == SDL_LIL_ENDIAN
526
527
#ifdef SIMD_SUPPORTED
528
static void initBuffer(uint32_t *const buf,
529
                       const int sz)
530
{
531
    for (int f = 0; f < sz; f ++)
532
        buf[f] = f;
533
}
534
535
#define runDyeTest(msg1, msg2, func) \
536
    initBuffer(buf, sz); \
537
    pal.func(buf, sz); \
538
    clock_gettime(CLOCK_MONOTONIC, &time1); \
539
    for (int f = 0; f < 50000; f ++) \
540
        pal.func(buf, sz); \
541
    calcTime(msg1, \
542
        msg2, \
543
        time1, \
544
        time2, \
545
        buf)
546
#endif  // SIMD_SUPPORTED
547
#endif  // defined __linux__ || defined __linux
548
549
int TestLauncher::testDyeSSpeed()
550
{
551
#if defined __linux__ || defined __linux
552
#ifdef SIMD_SUPPORTED
553
    const int sz = 100000;
554
    uint32_t buf[sz];
555
    timespec time1;
556
    timespec time2;
557
558
    DyePalette pal("#0000ff,000000,000020,706050", 6);
559
560
    runDyeTest("dye s salt", "default time", replaceSColorDefault);
561
    runDyeTest("dye s salt", "sse2 time   ", replaceSColorSse2);
562
    runDyeTest("dye s salt", "avx2 time   ", replaceSColorAvx2);
563
#endif  // SIMD_SUPPORTED
564
#endif  // defined __linux__ || defined __linux
565
    return 0;
566
}
567
568
int TestLauncher::testDyeASpeed()
569
{
570
#if defined __linux__ || defined __linux
571
#ifdef SIMD_SUPPORTED
572
    const int sz = 100000;
573
    uint32_t buf[sz];
574
    timespec time1;
575
    timespec time2;
576
577
    DyePalette pal("#0000ffff,00000000,000020ff,70605040", 8);
578
579
    runDyeTest("dye a salt", "default time", replaceAColorDefault);
580
    runDyeTest("dye a salt", "sse2 time   ", replaceAColorSse2);
581
    runDyeTest("dye a salt", "avx2 time   ", replaceAColorAvx2);
582
#endif  // SIMD_SUPPORTED
583
#endif  // defined __linux__ || defined __linux
584
    return 0;
585
}
586
587
int TestLauncher::testBlitSpeed()
588
{
589
#if defined __linux__ || defined __linux
590
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
591
#ifndef USE_SDL2
592
593
    timespec time1;
594
    timespec time2;
595
    const int cnt1 = 10000;
596
    const int cnt2 = 10;
597
598
    SDL_Surface *const srcSurface = imageHelper->create32BitSurface(
599
        64, 64);
600
    SDL_Surface *const dstSurface = imageHelper->create32BitSurface(
601
        512, 512);
602
    for (int f = 0; f < 64 * 64; f ++)
603
        static_cast<uint32_t*>(srcSurface->pixels)[f] = 0x11223344;
604
    clock_gettime(CLOCK_MONOTONIC, &time1);
605
    for (int d = 0; d < cnt2; d ++)
606
    {
607
        for (int f = 0; f < 512 * 512; f ++)
608
            static_cast<uint32_t*>(dstSurface->pixels)[f] = 0x55667788;
609
        for (int f = 0; f < cnt1; f ++)
610
        {
611
            SDLgfxBlitRGBA(srcSurface,
612
                nullptr,
613
                dstSurface,
614
                nullptr);
615
        }
616
    }
617
    calcTime("blit test",
618
        "custom time",
619
        time1,
620
        time2,
621
        static_cast<uint32_t*>(dstSurface->pixels));
622
623
    clock_gettime(CLOCK_MONOTONIC, &time1);
624
    for (int d = 0; d < cnt2; d ++)
625
    {
626
        for (int f = 0; f < 512 * 512; f ++)
627
            static_cast<uint32_t*>(dstSurface->pixels)[f] = 0x55667788;
628
        for (int f = 0; f < cnt1; f ++)
629
        {
630
            SDL_gfxBlitRGBA(srcSurface,
631
                nullptr,
632
                dstSurface,
633
                nullptr);
634
        }
635
    }
636
    calcTime("blit test",
637
        "SDL_gfx time",
638
        time1,
639
        time2,
640
        static_cast<uint32_t*>(dstSurface->pixels));
641
642
#endif  // USE_SDL2
643
#endif  // SDL_BYTEORDER == SDL_LIL_ENDIAN
644
#endif  // defined __linux__ || defined __linux
645
    return 0;
646
}
647
648
int TestLauncher::testStackSpeed()
649
{
650
/*
651
    const int sz = 100000;
652
    const int k = 100;
653
    const int sz2 = sz * k;
654
655
    std::stack<ClipRect> stack1;
656
    MStack<ClipRect> stack2(sz2);
657
    timespec time1;
658
    timespec time2;
659
660
#if defined __linux__ || defined __linux
661
    for (int d = 0; d < 100; d ++)
662
    {
663
        for (int f = 0; f < sz; f ++)
664
        {
665
            ClipRect rect;
666
            rect.xOffset = f;
667
            rect.yOffset = f;
668
            stack1.push(rect);
669
        }
670
    }
671
    while (!stack1.empty())
672
        stack1.pop();
673
674
    clock_gettime(CLOCK_MONOTONIC, &time1);
675
676
    for (int d = 0; d < 100; d ++)
677
    {
678
        for (int f = 0; f < sz; f ++)
679
        {
680
            ClipRect rect;
681
            rect.xOffset = f;
682
            rect.yOffset = f;
683
            stack1.push(rect);
684
        }
685
    }
686
687
    clock_gettime(CLOCK_MONOTONIC, &time2);
688
    long diff = ((static_cast<long int>(time2.tv_sec) * 1000000000L
689
        + static_cast<long int>(time2.tv_nsec)) / 1) -
690
        ((static_cast<long int>(time1.tv_sec) * 1000000000L
691
        + static_cast<long int>(time1.tv_nsec)) / 1);
692
    printf("debug: %d\n", stack1.top().xOffset);
693
    printf("stl time: %ld\n", diff);
694
695
    for (int d = 0; d < 100; d ++)
696
    {
697
        for (int f = 0; f < sz; f ++)
698
        {
699
            ClipRect &rect = stack2.push();
700
            rect.xOffset = f;
701
            rect.yOffset = f;
702
        }
703
    }
704
    stack2.clear();
705
706
    clock_gettime(CLOCK_MONOTONIC, &time1);
707
708
    for (int d = 0; d < 100; d ++)
709
    {
710
        for (int f = 0; f < sz; f ++)
711
        {
712
            ClipRect &rect = stack2.push();
713
            rect.xOffset = f;
714
            rect.yOffset = f;
715
        }
716
    }
717
718
    clock_gettime(CLOCK_MONOTONIC, &time2);
719
    diff = ((static_cast<long int>(time2.tv_sec) * 1000000000L
720
        + static_cast<long int>(time2.tv_nsec)) / 1) -
721
        ((static_cast<long int>(time1.tv_sec) * 1000000000L
722
        + static_cast<long int>(time1.tv_nsec)) / 1);
723
    printf("debug: %d\n", stack2.top().xOffset);
724
    printf("my time:  %ld\n", diff);
725
726
#endif
727
*/
728
    return 0;
729
}
730
731
int TestLauncher::testDraw()
732
{
733
    Image *img[3];
734
    img[0] = Theme::getImageFromTheme("graphics/sprites/arrow_left.png");
735
    img[1] = Theme::getImageFromTheme("graphics/sprites/arrow_right.png");
736
    img[2] = Theme::getImageFromTheme("graphics/sprites/arrow_up.png");
737
    Skin *skin = theme->load("button.xml", "button.xml");
738
    if (skin == nullptr)
739
        return 0;
740
741
    ImageCollection *const col = new ImageCollection;
742
    ImageCollection *const col2 = new ImageCollection;
743
    ImageVertexes *const vert = new ImageVertexes;
744
    vert->image = img[2];
745
746
    mainGraphics->pushClipArea(Rect(10, 20, 790, 580));
747
    mainGraphics->setColor(Color(0xFFU, 0xFFU, 0x00U, 0xFFU));
748
    mainGraphics->drawRectangle(Rect(0, 0, 400, 200));
749
750
    mainGraphics->setColor(Color(0xFFU, 0x00U, 0x00U, 0xB0U));
751
    img[0]->setAlpha(0.5f);
752
    mainGraphics->drawImage(img[0], 190, 383);
753
    img[0]->setAlpha(1.0f);
754
755
    mainGraphics->calcWindow(col2,
756
                5, 40,
757
                500, 40,
758
                skin->getBorder());
759
    mainGraphics->finalize(col2);
760
761
    mainGraphics->calcTileVertexes(vert, img[2], 10, 10);
762
    mainGraphics->calcTileVertexes(vert, img[2], 40, 10);
763
    mainGraphics->finalize(vert);
764
765
    mainGraphics->setColor(Color(0x80U, 0x00U, 0xA0U, 0x90U));
766
    mainGraphics->fillRectangle(Rect(200, 100, 300, 300));
767
    mainGraphics->popClipArea();
768
769
    Color color(0xFFU, 0x00U, 0x00U, 0xB0U);
770
    Color color2(0x00U, 0xFFU, 0x00U, 0xB0U);
771
    boldFont->drawString(mainGraphics,
772
        color, color2,
773
        "test test test test test test test test ", 300, 100);
774
775
    mainGraphics->drawTileCollection(col2);
776
777
    mainGraphics->drawPattern(img[0], 10, 400, 300, 180);
778
779
    mainGraphics->calcPattern(col, img[1], 500, 400, 150, 100);
780
    mainGraphics->finalize(col);
781
782
    mainGraphics->drawTileVertexes(vert);
783
784
    mainGraphics->drawRescaledImage(img[0], 250, 350, 35, 90);
785
786
    mainGraphics->setColor(Color(0x00U, 0xFFU, 0x00U, 0x90U));
787
    mainGraphics->drawNet(450, 10, 600, 300, 32, 20);
788
789
    mainGraphics->drawTileCollection(col);
790
791
    img[0]->setAlpha(0.3f);
792
    mainGraphics->drawRescaledPattern(img[0], 250, 150, 250, 300, 30, 100);
793
794
    for (int f = 0; f < 255; f ++)
795
    {
796
        mainGraphics->setColor(Color(0x20U, 0x60U, f, 0x90U));
797
        mainGraphics->drawLine(300 + f, 490, 300 + f, 480);
798
        for (int d = 0; d < 10; d ++)
799
            mainGraphics->drawPoint(300 + f, 500 + d);
800
    }
801
    mainGraphics->updateScreen();
802
    sleep(10);
803
804
    delete col;
805
    delete col2;
806
    delete vert;
807
    return 0;
808
}
809
810
int TestLauncher::testVideoDetection()
811
{
812
    file << mTest << std::endl;
813
    file << graphicsManager.detectGraphics() << std::endl;
814
    return 0;
815
}
816
817
int TestLauncher::calcFps(const timeval &start,
818
                          const timeval &end,
819
                          const int calls) const
820
{
821
    long mtime;
822
    long seconds;
823
    long useconds;
824
825
    seconds  = end.tv_sec  - start.tv_sec;
826
    useconds = end.tv_usec - start.tv_usec;
827
828
    mtime = (seconds * 1000 + useconds / 1000.0) + 0.5;
829
    if (mtime == 0)
830
        return 100000;
831
832
    return CAST_S32(static_cast<long>(calls) * 10000 / mtime);
833
}
834
835
#endif  // USE_OPENGL