Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Yershov <syershov@maps.me>2016-11-16 16:05:37 +0300
committerSergey Yershov <syershov@maps.me>2016-11-17 13:27:22 +0300
commit19600faf61beb3a36b02ccb458eaffa0a39edb17 (patch)
tree0a2970e4d7081e585a15cbd3ef20bd40ff3fdd40 /platform
parente8ebcca6b51c26c7ea69e5b8a1575e119f17d563 (diff)
Remove video timer
Diffstat (limited to 'platform')
-rw-r--r--platform/apple_video_timer.mm81
-rw-r--r--platform/ios_video_timer.mm103
-rw-r--r--platform/platform_tests/video_timer_test.cpp49
-rw-r--r--platform/pthread_video_timer.cpp141
-rw-r--r--platform/video_timer.cpp70
-rw-r--r--platform/video_timer.hpp57
6 files changed, 0 insertions, 501 deletions
diff --git a/platform/apple_video_timer.mm b/platform/apple_video_timer.mm
deleted file mode 100644
index b60e7a9f00..0000000000
--- a/platform/apple_video_timer.mm
+++ /dev/null
@@ -1,81 +0,0 @@
-#include "platform/video_timer.hpp"
-
-#include "std/target_os.hpp"
-
-#include <CoreVideo/CVDisplayLink.h>
-
-class AppleVideoTimer : public VideoTimer
-{
-
- CVDisplayLinkRef m_displayLink;
-
-public:
-
- AppleVideoTimer(VideoTimer::TFrameFn frameFn)
- : VideoTimer(frameFn), m_displayLink(0)
- {}
-
- ~AppleVideoTimer()
- {
- stop();
- }
-
- static CVReturn displayLinkCallback(
- CVDisplayLinkRef /*displayLink*/,
- const CVTimeStamp * /*inNow*/,
- const CVTimeStamp * /*inOutputTime*/,
- CVOptionFlags /*flagsIn*/,
- CVOptionFlags * /*flagsOut*/,
- void * displayLinkContext
- )
- {
- AppleVideoTimer * t = reinterpret_cast<AppleVideoTimer*>(displayLinkContext);
- t->perform();
-
- return kCVReturnSuccess;
- }
-
- void start()
- {
- if (m_displayLink == 0)
- {
- CVDisplayLinkCreateWithActiveCGDisplays(&m_displayLink);
- CVDisplayLinkSetOutputCallback(m_displayLink, &displayLinkCallback, (void*)this);
- resume();
- }
- }
-
- void resume()
- {
- CVDisplayLinkStart(m_displayLink);
- m_state = ERunning;
- }
-
- void pause()
- {
- CVDisplayLinkStop(m_displayLink);
- m_state = EPaused;
- }
-
- void stop()
- {
- if (m_displayLink)
- {
- if (state() == ERunning)
- pause();
- CVDisplayLinkRelease(m_displayLink);
- m_displayLink = 0;
- m_state = EStopped;
- }
- }
-
- void perform()
- {
- m_frameFn();
- }
-};
-
-VideoTimer * CreateAppleVideoTimer(VideoTimer::TFrameFn frameFn)
-{
- return new AppleVideoTimer(frameFn);
-}
diff --git a/platform/ios_video_timer.mm b/platform/ios_video_timer.mm
deleted file mode 100644
index ec3077d40e..0000000000
--- a/platform/ios_video_timer.mm
+++ /dev/null
@@ -1,103 +0,0 @@
-#include "platform/video_timer.hpp"
-
-#include "std/target_os.hpp"
-
-#import <QuartzCore/CADisplayLink.h>
-#import <Foundation/NSRunLoop.h>
-
-class IOSVideoTimer;
-
-@interface VideoTimerWrapper : NSObject {
-@private
- IOSVideoTimer * m_timer;
-}
-- (id)initWithTimer:(IOSVideoTimer *) timer;
-- (void)perform;
-@end
-
-class IOSVideoTimer : public VideoTimer
-{
-
- VideoTimerWrapper * m_objCppWrapper;
- CADisplayLink * m_displayLink;
-
-public:
-
- IOSVideoTimer(VideoTimer::TFrameFn frameFn) : VideoTimer(frameFn), m_objCppWrapper(0), m_displayLink(0)
- {}
-
- ~IOSVideoTimer()
- {
- stop();
- }
-
- void start()
- {
- if (m_displayLink == 0)
- {
- m_objCppWrapper = [[VideoTimerWrapper alloc] initWithTimer:this];
- m_displayLink = [CADisplayLink displayLinkWithTarget:m_objCppWrapper selector:@selector(perform)];
- m_displayLink.frameInterval = 1;
- m_displayLink.paused = true;
- [m_displayLink addToRunLoop:[NSRunLoop mainRunLoop] forMode:NSDefaultRunLoopMode];
- resume();
- }
- }
-
- void stop()
- {
- if (m_displayLink)
- {
- // Set EStopped flag first. It seems like 'CADisplayLink::invalidate' can invoke pending 'perform'.
- // So we should check EStopped flag in 'perform' to skip pending call.
- m_state = EStopped;
- [m_displayLink invalidate];
- m_displayLink = 0;
- }
- }
-
- void pause()
- {
- m_displayLink.paused = true;
- m_state = EPaused;
- }
-
- void resume()
- {
- m_displayLink.paused = false;
- m_state = ERunning;
- }
-
- void perform()
- {
- // In case when we stopped and have pending perform at the same time.
- // It's not allowed to call m_frameFn after stopping (see WindowHandle::~WindowHandle).
- if (m_state != EStopped)
- m_frameFn();
- }
-};
-
-@implementation VideoTimerWrapper
-
-- (id)initWithTimer:(IOSVideoTimer*) timer
-{
- self = [super init];
- if (self) {
- m_timer = timer;
- }
- return self;
-}
-
-- (void)perform
-{
- m_timer->perform();
-}
-
-@end
-
-VideoTimer * CreateIOSVideoTimer(VideoTimer::TFrameFn frameFn)
-{
- return new IOSVideoTimer(frameFn);
-}
-
-
diff --git a/platform/platform_tests/video_timer_test.cpp b/platform/platform_tests/video_timer_test.cpp
deleted file mode 100644
index f004917798..0000000000
--- a/platform/platform_tests/video_timer_test.cpp
+++ /dev/null
@@ -1,49 +0,0 @@
-#include "testing/testing.hpp"
-
-#include "platform/video_timer.hpp"
-
-#include "base/thread.hpp"
-#include "base/logging.hpp"
-
-#include "std/bind.hpp"
-
-
-void incrementValue(int & i)
-{
- ++i;
-}
-
-#ifdef OMIM_OS_MAC
-
-UNIT_TEST(TimerTest)
-{
- /*
- int i = 0;
-
- VideoTimer * videoTimer = CreatePThreadVideoTimer(bind(&incrementValue, ref(i)));
-
- LOG(LINFO, ("checking for approximately 60 cycles in second"));
-
- videoTimer->start();
-
- threads::Sleep(1000);
-
- videoTimer->pause();
-
- TEST((i >= 57) && (i <= 61), ("timer doesn't work, i=", i));
-
- videoTimer->resume();
-
- threads::Sleep(200);
-
- videoTimer->stop();
-
- videoTimer->start();
-
- threads::Sleep(200);
-
- videoTimer->stop();
- */
-}
-
-#endif
diff --git a/platform/pthread_video_timer.cpp b/platform/pthread_video_timer.cpp
deleted file mode 100644
index 5777519a59..0000000000
--- a/platform/pthread_video_timer.cpp
+++ /dev/null
@@ -1,141 +0,0 @@
-#include "std/target_os.hpp"
-
-#ifndef OMIM_OS_WINDOWS_NATIVE
-
-#include "platform/video_timer.hpp"
-
-#include "base/logging.hpp"
-
-#include <pthread.h>
-#include <sys/time.h>
-#include <sys/errno.h>
-
-
-class PThreadVideoTimer : public VideoTimer
-{
-private:
-
- pthread_t m_handle;
- pthread_mutex_t m_mutex;
- pthread_cond_t m_cond;
- int m_frameRate;
-
-public:
- PThreadVideoTimer(VideoTimer::TFrameFn frameFn)
- : VideoTimer(frameFn), m_frameRate(60)
- {
- ::pthread_mutex_init(&m_mutex, 0);
- ::pthread_cond_init(&m_cond, 0);
- }
-
- ~PThreadVideoTimer()
- {
- stop();
-
- ::pthread_mutex_destroy(&m_mutex);
- ::pthread_cond_destroy(&m_cond);
- }
-
- static void * TimerProc(void * p)
- {
- PThreadVideoTimer * t = reinterpret_cast<PThreadVideoTimer*>(p);
-
- ::timeval prevtv;
- ::gettimeofday(&prevtv, 0);
-
- ::timeval curtv;
-
- int64_t interval = 1000000000 / t->m_frameRate;
- int64_t halfInterval = interval / 2;
-
- while (true)
- {
- ::pthread_mutex_lock(&t->m_mutex);
-
- t->perform();
-
- ::gettimeofday(&curtv, 0);
-
- int64_t sec = (int64_t)curtv.tv_sec - (int64_t)prevtv.tv_sec;
- int64_t nsec = ((int64_t)curtv.tv_usec - (int64_t)prevtv.tv_usec) * 1000;
-
- int64_t nsecDiff = sec * (int64_t)1000000000 + nsec;
- int64_t ceiledDiff = ((nsecDiff + interval - 1) / interval) * interval;
-
- /// how much we should wait
-
- if ((ceiledDiff - nsecDiff) < halfInterval)
- /// less than a half-frame left, should wait till next frame
- ceiledDiff += interval;
-
- ::timespec ts;
-
- ts.tv_sec = prevtv.tv_sec + (prevtv.tv_usec * 1000 + ceiledDiff) / 1000000000;
- ts.tv_nsec = (prevtv.tv_usec * 1000 + ceiledDiff) % 1000000000;
-
- ::pthread_cond_timedwait(&t->m_cond, &t->m_mutex, &ts);
-
- ::gettimeofday(&prevtv, 0);
-
- if (t->m_state == EStopped)
- {
- ::pthread_mutex_unlock(&t->m_mutex);
- break;
- }
-
- ::pthread_mutex_unlock(&t->m_mutex);
- }
-
- ::pthread_exit(0);
-
- return 0;
- }
-
- void start()
- {
- if (m_state == EStopped)
- {
- ::pthread_create(&m_handle, 0, &TimerProc, reinterpret_cast<void*>(this));
- m_state = ERunning;
- }
- }
-
- void resume()
- {
- if (m_state == EPaused)
- {
- m_state = EStopped;
- start();
- }
- }
-
- void pause()
- {
- stop();
- m_state = EPaused;
- }
-
- void stop()
- {
- if (m_state == ERunning)
- {
- ::pthread_mutex_lock(&m_mutex);
- m_state = EStopped;
- ::pthread_cond_signal(&m_cond);
- ::pthread_mutex_unlock(&m_mutex);
- ::pthread_join(m_handle, 0);
- }
- }
-
- void perform()
- {
- m_frameFn();
- }
-};
-
-VideoTimer * CreatePThreadVideoTimer(VideoTimer::TFrameFn frameFn)
-{
- return new PThreadVideoTimer(frameFn);
-}
-
-#endif
diff --git a/platform/video_timer.cpp b/platform/video_timer.cpp
deleted file mode 100644
index 2a785cd027..0000000000
--- a/platform/video_timer.cpp
+++ /dev/null
@@ -1,70 +0,0 @@
-#include "platform/video_timer.hpp"
-
-#include "std/bind.hpp"
-
-VideoTimer::VideoTimer(TFrameFn fn) : m_frameFn(fn), m_state(EStopped)
-{}
-
-VideoTimer::EState VideoTimer::state() const
-{
- return m_state;
-}
-
-VideoTimer::~VideoTimer()
-{}
-
-VideoTimer::TFrameFn VideoTimer::frameFn() const
-{
- return m_frameFn;
-}
-
-void VideoTimer::setFrameFn(TFrameFn fn)
-{
- m_frameFn = fn;
-}
-
-namespace
-{
- void empty() {}
-}
-
-EmptyVideoTimer::EmptyVideoTimer()
- : base_t(bind(&empty))
-{
-}
-
-EmptyVideoTimer::~EmptyVideoTimer()
-{
- stop();
-}
-
-void EmptyVideoTimer::start()
-{
- if (m_state == EStopped)
- m_state = ERunning;
-}
-
-void EmptyVideoTimer::resume()
-{
- if (m_state == EPaused)
- {
- m_state = EStopped;
- start();
- }
-}
-
-void EmptyVideoTimer::pause()
-{
- stop();
- m_state = EPaused;
-}
-
-void EmptyVideoTimer::stop()
-{
- if (m_state == ERunning)
- m_state = EStopped;
-}
-
-void EmptyVideoTimer::perform()
-{
-}
diff --git a/platform/video_timer.hpp b/platform/video_timer.hpp
deleted file mode 100644
index 715dc84e5c..0000000000
--- a/platform/video_timer.hpp
+++ /dev/null
@@ -1,57 +0,0 @@
-#pragma once
-
-#include "std/function.hpp"
-
-/// Timer, synchronized to Vertical Sync
-class VideoTimer
-{
-public:
-
- typedef function<void()> TFrameFn;
-
- enum EState
- {
- EStopped,
- EPaused,
- ERunning
- };
-
-protected:
-
- TFrameFn m_frameFn;
- EState m_state;
-
-public:
- VideoTimer(TFrameFn fn);
- virtual ~VideoTimer();
-
- TFrameFn frameFn() const;
- void setFrameFn(TFrameFn fn);
-
- EState state() const;
-
- virtual void resume() = 0;
- virtual void pause() = 0;
-
- virtual void start() = 0;
- virtual void stop() = 0;
-};
-
-class EmptyVideoTimer : public VideoTimer
-{
- typedef VideoTimer base_t;
-public:
- EmptyVideoTimer();
- ~EmptyVideoTimer();
-
- void start();
- void resume();
- void pause();
- void stop();
- void perform();
-};
-
-extern "C" VideoTimer * CreateIOSVideoTimer(VideoTimer::TFrameFn frameFn);
-extern "C" VideoTimer * CreateAppleVideoTimer(VideoTimer::TFrameFn frameFn);
-extern "C" VideoTimer * CreateWin32VideoTimer(VideoTimer::TFrameFn frameFn);
-extern "C" VideoTimer * CreatePThreadVideoTimer(VideoTimer::TFrameFn frameFn);