|
8 | 8 | #include "../pxTimer.h"
|
9 | 9 | #include "../pxWindowUtil.h"
|
10 | 10 | #include "../pxKeycodes.h"
|
| 11 | +#include "../rtLog.h" |
11 | 12 |
|
12 | 13 | #include <stdlib.h>
|
13 | 14 | #include <string.h>
|
@@ -381,6 +382,12 @@ void displayRef::cleanupWaylandDisplay()
|
381 | 382 |
|
382 | 383 | bool exitFlag = false;
|
383 | 384 |
|
| 385 | +pxWindowNative::pxWindowNative(): mTimerFPS(0), mLastWidth(-1), mLastHeight(-1), |
| 386 | + mResizeFlag(false), mLastAnimationTime(0.0), mVisible(false), |
| 387 | + mWaylandSurface(NULL), mWaylandBuffer(), waylandBufferIndex(0) |
| 388 | +{ |
| 389 | +} |
| 390 | + |
384 | 391 | pxWindowNative::~pxWindowNative()
|
385 | 392 | {
|
386 | 393 | cleanupWaylandData();
|
@@ -549,27 +556,52 @@ void pxWindowNative::runEventLoop()
|
549 | 556 | waylandDisplay* display = dRef.getDisplay();
|
550 | 557 | std::vector<pxWindowNative*> windowVector = pxWindowNative::getNativeWindows();
|
551 | 558 |
|
| 559 | + int framerate = WAYLAND_PX_CORE_FPS; |
| 560 | + |
| 561 | + char const *s = getenv("PXCORE_FRAMERATE"); |
| 562 | + if (s) |
| 563 | + { |
| 564 | + int fps = atoi(s); |
| 565 | + if (fps > 0) |
| 566 | + { |
| 567 | + framerate = fps; |
| 568 | + } |
| 569 | + } |
| 570 | + |
| 571 | + rtLogInfo("pxcore framerate: %d", framerate); |
| 572 | + |
| 573 | + uint64_t* offsets = new uint64_t[ framerate ]; |
| 574 | + for( int i = 0; i < framerate; ++i ) |
| 575 | + offsets[ i ] = (i*1000000+framerate-1)/framerate; |
| 576 | + |
| 577 | + int frameNo = 1; |
| 578 | + double wakeUpBase = pxMicroseconds(); |
| 579 | + int count = 0, lastCount = -1; |
552 | 580 | while(!exitFlag)
|
553 | 581 | {
|
554 |
| - double startMilliseconds = pxMilliseconds(); |
| 582 | + count++; |
555 | 583 | std::vector<pxWindowNative*>::iterator i;
|
556 | 584 | for (i = windowVector.begin(); i < windowVector.end(); i++)
|
557 | 585 | {
|
558 | 586 | pxWindowNative* w = (*i);
|
559 | 587 | w->animateAndRender();
|
560 | 588 | }
|
561 | 589 | wl_display_dispatch_pending(display->display);
|
562 |
| - int processTime = (int)pxMilliseconds() - (int)startMilliseconds; |
563 |
| - if (processTime < 0) |
564 |
| - { |
565 |
| - processTime = 0; |
566 |
| - } |
567 |
| - if (processTime < 32) |
568 |
| - { |
569 |
| - usleep((32-processTime)*1000); |
| 590 | + double delay = pxMicroseconds(); |
| 591 | + double nextWakeUp = wakeUpBase + offsets[ frameNo ]; |
| 592 | + while( delay > nextWakeUp ) { |
| 593 | + frameNo++; |
| 594 | + if( frameNo >= framerate ) { |
| 595 | + count = 0; |
| 596 | + wakeUpBase += 1000000; |
| 597 | + frameNo = 0; |
| 598 | + } |
| 599 | + nextWakeUp = wakeUpBase + offsets[ frameNo ]; |
570 | 600 | }
|
571 |
| - //pxSleepMS(1000); // Breath |
| 601 | + delay = nextWakeUp - delay; |
| 602 | + usleep( delay ); |
572 | 603 | }
|
| 604 | + delete [] offsets; |
573 | 605 | }
|
574 | 606 |
|
575 | 607 |
|
@@ -791,28 +823,16 @@ waylandBuffer* pxWindowNative::nextBuffer()
|
791 | 823 |
|
792 | 824 | void pxWindowNative::animateAndRender()
|
793 | 825 | {
|
794 |
| - static double lastAnimationTime = pxMilliseconds(); |
795 |
| - double currentAnimationTime = pxMilliseconds(); |
796 | 826 | drawFrame();
|
797 | 827 |
|
798 |
| - double animationDelta = currentAnimationTime-lastAnimationTime; |
799 | 828 | if (mResizeFlag)
|
800 | 829 | {
|
801 | 830 | mResizeFlag = false;
|
802 | 831 | onSize(mLastWidth, mLastHeight);
|
803 | 832 | invalidateRectInternal(NULL);
|
804 | 833 | }
|
805 | 834 |
|
806 |
| - if (mTimerFPS) |
807 |
| - { |
808 |
| - animationDelta = currentAnimationTime - getLastAnimationTime(); |
809 |
| - |
810 |
| - if (animationDelta > (1000/mTimerFPS)) |
811 |
| - { |
812 |
| - onAnimationTimerInternal(); |
813 |
| - setLastAnimationTime(currentAnimationTime); |
814 |
| - } |
815 |
| - } |
| 835 | + onAnimationTimerInternal(); |
816 | 836 | }
|
817 | 837 |
|
818 | 838 | void pxWindowNative::setLastAnimationTime(double time)
|
@@ -881,7 +901,7 @@ void pxWindowNative::initializeEgl()
|
881 | 901 |
|
882 | 902 | waylandDisplay* display = mDisplayRef.getDisplay();
|
883 | 903 |
|
884 |
| - display->egl.dpy = eglGetDisplay(display->display); |
| 904 | + display->egl.dpy = eglGetDisplay((EGLNativeDisplayType)display->display); |
885 | 905 | assert(display->egl.dpy);
|
886 | 906 |
|
887 | 907 | ret = eglInitialize(display->egl.dpy, &major, &minor);
|
|
0 commit comments