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:
authorrachytski <siarhei.rachytski@gmail.com>2011-10-24 20:15:40 +0400
committerAlex Zolotarev <alex@maps.me>2015-09-23 01:26:38 +0300
commit943d893105e3e76839be98529994414c4b0b01a0 (patch)
treec9a0dd11971b9bd300323d8b01b6fd11f03ed473
parent9906d541f6b2279b550d05ec6e5a6422c5e7ccf6 (diff)
using VideoTimer in Desktop and iOS version. stopping it, when the pause is longer than 60 cycles. refactored WindowHandle. implemented QtVideoTimer. closes #356
-rw-r--r--iphone/Maps/Classes/EAGLView.h13
-rw-r--r--iphone/Maps/Classes/EAGLView.mm37
-rw-r--r--iphone/Maps/Classes/MapViewController.mm3
-rw-r--r--iphone/Maps/Classes/WindowHandle.h17
-rw-r--r--iphone/Maps/Classes/WindowHandle.mm15
-rw-r--r--iphone/Maps/Maps.xcodeproj/project.pbxproj6
-rw-r--r--map/map.pro1
-rw-r--r--map/window_handle.cpp98
-rw-r--r--map/window_handle.hpp65
-rw-r--r--platform/apple_video_timer.mm40
-rw-r--r--platform/ios_video_timer.mm15
-rw-r--r--platform/video_timer.cpp20
-rw-r--r--platform/video_timer.hpp18
-rw-r--r--qt/draw_widget.cpp59
-rw-r--r--qt/draw_widget.hpp22
15 files changed, 285 insertions, 144 deletions
diff --git a/iphone/Maps/Classes/EAGLView.h b/iphone/Maps/Classes/EAGLView.h
index 4a24c4e958..a7289d4b6f 100644
--- a/iphone/Maps/Classes/EAGLView.h
+++ b/iphone/Maps/Classes/EAGLView.h
@@ -9,7 +9,8 @@
#include "../../map/drawer_yg.hpp"
#include "../../map/framework.hpp"
#include "../../map/feature_vec_model.hpp"
-#include "RenderBuffer.hpp"
+#include "../../platform/video_timer.hpp"
+#include"RenderBuffer.hpp"
namespace iphone
{
@@ -41,17 +42,15 @@ typedef Framework<model::FeaturesFetcher> framework_t;
@public
- shared_ptr<iphone::WindowHandle> windowHandle;
+ shared_ptr<WindowHandle> windowHandle;
+ shared_ptr<VideoTimer> videoTimer;
shared_ptr<DrawerYG> drawer;
shared_ptr<iphone::RenderBuffer> renderBuffer;
}
-// Called as a result of invalidate on iphone::WindowHandle
-- (void)drawViewOnMainThread;
-
-@property (nonatomic, assign) CADisplayLink * displayLink;
+- (void) drawFrame;
@property (nonatomic, assign) framework_t * framework;
-@property (nonatomic, assign) shared_ptr<iphone::WindowHandle> windowHandle;
+@property (nonatomic, assign) shared_ptr<WindowHandle> windowHandle;
@property (nonatomic, assign) shared_ptr<DrawerYG> drawer;
@property (nonatomic, assign) shared_ptr<iphone::RenderContext> renderContext;
@property (nonatomic, assign) shared_ptr<iphone::RenderBuffer> renderBuffer;
diff --git a/iphone/Maps/Classes/EAGLView.mm b/iphone/Maps/Classes/EAGLView.mm
index 842ec24bef..44c4566d3c 100644
--- a/iphone/Maps/Classes/EAGLView.mm
+++ b/iphone/Maps/Classes/EAGLView.mm
@@ -2,7 +2,6 @@
#import <OpenGLES/EAGLDrawable.h>
#import "EAGLView.h"
-#import "WindowHandle.h"
#include "../../yg/screen.hpp"
#include "../../yg/texture.hpp"
@@ -13,18 +12,15 @@
#include "RenderBuffer.hpp"
#include "RenderContext.hpp"
-bool _doRepaint = true;
-bool _inRepaint = false;
-
@implementation EAGLView
@synthesize framework;
@synthesize windowHandle;
+@synthesize videoTimer;
@synthesize drawer;
@synthesize renderContext;
@synthesize renderBuffer;
@synthesize resourceManager;
-@synthesize displayLink;
// You must implement this method
+ (Class)layerClass
@@ -143,13 +139,19 @@ bool _inRepaint = false;
drawer = shared_ptr<DrawerYG>(new DrawerYG(p));
- windowHandle = shared_ptr<iphone::WindowHandle>(new iphone::WindowHandle(_doRepaint));
+ windowHandle.reset(new WindowHandle());
- windowHandle->setRenderContext(renderContext);
+ windowHandle->setUpdatesEnabled(false);
+
+ typedef void (*drawFrameFn)(id, SEL);
+ SEL drawFrameSel = @selector(drawFrame);
+ drawFrameFn drawFrameImpl = (drawFrameFn)[self methodForSelector:drawFrameSel];
+
+ videoTimer.reset(CreateIOSVideoTimer(bind(drawFrameImpl, self, drawFrameSel)));
- displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(drawView)];
- displayLink.frameInterval = 1;
- [displayLink addToRunLoop:[NSRunLoop mainRunLoop] forMode:NSDefaultRunLoopMode];
+ windowHandle->setVideoTimer(videoTimer);
+
+ windowHandle->setRenderContext(renderContext);
}
return self;
@@ -174,7 +176,7 @@ bool _inRepaint = false;
drawer->screen()->endFrame();
}
-- (void)drawView
+- (void)drawFrame
{
shared_ptr<PaintEvent> pe(new PaintEvent(drawer.get()));
if (windowHandle->needRedraw())
@@ -187,16 +189,6 @@ bool _inRepaint = false;
}
}
-- (void)drawViewThunk:(id)obj
-{
- [self drawView];
-}
-
-- (void)drawViewOnMainThread
-{
- [self performSelectorOnMainThread:@selector(drawViewThunk:) withObject:nil waitUntilDone:NO];
-}
-
- (void)layoutSubviews
{
CGFloat const scale = self.contentScaleFactor;
@@ -206,8 +198,7 @@ bool _inRepaint = false;
- (void)dealloc
{
- [displayLink invalidate];
- [displayLink release];
+ videoTimer.reset();
[EAGLContext setCurrentContext:nil];
[super dealloc];
}
diff --git a/iphone/Maps/Classes/MapViewController.mm b/iphone/Maps/Classes/MapViewController.mm
index 2ccd1a0cd9..733f03a610 100644
--- a/iphone/Maps/Classes/MapViewController.mm
+++ b/iphone/Maps/Classes/MapViewController.mm
@@ -2,7 +2,6 @@
#import "SearchVC.h"
#import "MapsAppDelegate.h"
#import "EAGLView.h"
-#import "WindowHandle.h"
#import "../Settings/SettingsManager.h"
#include "RenderContext.hpp"
@@ -122,7 +121,7 @@ storage::Storage m_storage;
// Here we're creating view and window handle in it, and later we should pass framework to the view
EAGLView * v = (EAGLView *)self.view;
- shared_ptr<iphone::WindowHandle> windowHandle = [(EAGLView*)self.view windowHandle];
+ shared_ptr<WindowHandle> windowHandle = [(EAGLView*)self.view windowHandle];
shared_ptr<yg::ResourceManager> resourceManager = [(EAGLView*)self.view resourceManager];
m_framework = FrameworkFactory<model::FeaturesFetcher>::CreateFramework(windowHandle, 40);
diff --git a/iphone/Maps/Classes/WindowHandle.h b/iphone/Maps/Classes/WindowHandle.h
deleted file mode 100644
index 394e82aa81..0000000000
--- a/iphone/Maps/Classes/WindowHandle.h
+++ /dev/null
@@ -1,17 +0,0 @@
-#import "RenderContext.hpp"
-
-#include "../../../map/window_handle.hpp"
-
-@class EAGLView;
-
-namespace iphone
-{
- class WindowHandle : public ::WindowHandle
- {
- bool * m_doRepaint;
-
- public:
- WindowHandle(bool & doRepaint);
- virtual void invalidateImpl();
- };
-}
diff --git a/iphone/Maps/Classes/WindowHandle.mm b/iphone/Maps/Classes/WindowHandle.mm
deleted file mode 100644
index cf657a0019..0000000000
--- a/iphone/Maps/Classes/WindowHandle.mm
+++ /dev/null
@@ -1,15 +0,0 @@
-#import "WindowHandle.h"
-#import "EAGLView.h"
-
-namespace iphone
-{
- WindowHandle::WindowHandle(bool & doRepaint)
- {
- m_doRepaint = &doRepaint;
- }
-
- void WindowHandle::invalidateImpl()
- {
- *m_doRepaint = true;
- }
-} \ No newline at end of file
diff --git a/iphone/Maps/Maps.xcodeproj/project.pbxproj b/iphone/Maps/Maps.xcodeproj/project.pbxproj
index 20fb203878..2c91621e0f 100644
--- a/iphone/Maps/Maps.xcodeproj/project.pbxproj
+++ b/iphone/Maps/Maps.xcodeproj/project.pbxproj
@@ -40,7 +40,6 @@
EE583CBB12F773F00042CBE3 /* unicode_blocks.txt in Resources */ = {isa = PBXBuildFile; fileRef = EE583CBA12F773F00042CBE3 /* unicode_blocks.txt */; };
EE7F29811219ECA300EB67A9 /* RenderBuffer.mm in Sources */ = {isa = PBXBuildFile; fileRef = EE7F297D1219ECA300EB67A9 /* RenderBuffer.mm */; };
EE7F29821219ECA300EB67A9 /* RenderContext.mm in Sources */ = {isa = PBXBuildFile; fileRef = EE7F297E1219ECA300EB67A9 /* RenderContext.mm */; };
- EE7F29831219ECA300EB67A9 /* WindowHandle.mm in Sources */ = {isa = PBXBuildFile; fileRef = EE7F29801219ECA300EB67A9 /* WindowHandle.mm */; };
EEA61601134C496A003A9827 /* 01_dejavusans.ttf in Resources */ = {isa = PBXBuildFile; fileRef = EEA615E5134C4968003A9827 /* 01_dejavusans.ttf */; };
EEA61602134C496A003A9827 /* 02_wqy-microhei.ttf in Resources */ = {isa = PBXBuildFile; fileRef = EEA615E6134C4968003A9827 /* 02_wqy-microhei.ttf */; };
EEA61603134C496A003A9827 /* 03_jomolhari-id-a3d.ttf in Resources */ = {isa = PBXBuildFile; fileRef = EEA615E7134C4968003A9827 /* 03_jomolhari-id-a3d.ttf */; };
@@ -649,8 +648,6 @@
EE7F297C1219ECA300EB67A9 /* RenderBuffer.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; lineEnding = 0; name = RenderBuffer.hpp; path = Classes/RenderBuffer.hpp; sourceTree = SOURCE_ROOT; };
EE7F297D1219ECA300EB67A9 /* RenderBuffer.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; lineEnding = 0; name = RenderBuffer.mm; path = Classes/RenderBuffer.mm; sourceTree = SOURCE_ROOT; };
EE7F297E1219ECA300EB67A9 /* RenderContext.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; lineEnding = 0; name = RenderContext.mm; path = Classes/RenderContext.mm; sourceTree = SOURCE_ROOT; };
- EE7F297F1219ECA300EB67A9 /* WindowHandle.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; name = WindowHandle.h; path = Classes/WindowHandle.h; sourceTree = SOURCE_ROOT; };
- EE7F29801219ECA300EB67A9 /* WindowHandle.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; lineEnding = 0; name = WindowHandle.mm; path = Classes/WindowHandle.mm; sourceTree = SOURCE_ROOT; };
EEA615E5134C4968003A9827 /* 01_dejavusans.ttf */ = {isa = PBXFileReference; lastKnownFileType = file; name = 01_dejavusans.ttf; path = ../../data/01_dejavusans.ttf; sourceTree = SOURCE_ROOT; };
EEA615E6134C4968003A9827 /* 02_wqy-microhei.ttf */ = {isa = PBXFileReference; lastKnownFileType = file; name = "02_wqy-microhei.ttf"; path = "../../data/02_wqy-microhei.ttf"; sourceTree = SOURCE_ROOT; };
EEA615E7134C4968003A9827 /* 03_jomolhari-id-a3d.ttf */ = {isa = PBXFileReference; lastKnownFileType = file; name = "03_jomolhari-id-a3d.ttf"; path = "../../data/03_jomolhari-id-a3d.ttf"; sourceTree = SOURCE_ROOT; };
@@ -1271,8 +1268,6 @@
EE7F297D1219ECA300EB67A9 /* RenderBuffer.mm */,
EE16192B126E374500622BD0 /* RenderContext.hpp */,
EE7F297E1219ECA300EB67A9 /* RenderContext.mm */,
- EE7F297F1219ECA300EB67A9 /* WindowHandle.h */,
- EE7F29801219ECA300EB67A9 /* WindowHandle.mm */,
46F26CD610F623BA00ECCA39 /* EAGLView.h */,
46F26CD710F623BA00ECCA39 /* EAGLView.mm */,
1D3623240D0F684500981E51 /* MapsAppDelegate.h */,
@@ -2609,7 +2604,6 @@
FA4135ED120A263C0062D5B4 /* SettingsManager.mm in Sources */,
EE7F29811219ECA300EB67A9 /* RenderBuffer.mm in Sources */,
EE7F29821219ECA300EB67A9 /* RenderContext.mm in Sources */,
- EE7F29831219ECA300EB67A9 /* WindowHandle.mm in Sources */,
FAF37EFF126DCE6F005EA154 /* IPhoneDownload.mm in Sources */,
FAF37F00126DCE6F005EA154 /* IPhoneDownloadManager.mm in Sources */,
FAFCB63613366E78001A5C59 /* WebViewController.mm in Sources */,
diff --git a/map/map.pro b/map/map.pro
index e0dde339be..8d6f29e933 100644
--- a/map/map.pro
+++ b/map/map.pro
@@ -69,6 +69,7 @@ SOURCES += \
benchmark_render_policy_mt.cpp \
ruler.cpp \
measurement_utils.cpp \
+ window_handle.cpp
!iphone*:!bada*:!android* {
HEADERS += qgl_render_context.hpp
diff --git a/map/window_handle.cpp b/map/window_handle.cpp
new file mode 100644
index 0000000000..cd1b94a8db
--- /dev/null
+++ b/map/window_handle.cpp
@@ -0,0 +1,98 @@
+#include "window_handle.hpp"
+
+WindowHandle::WindowHandle() :
+ m_hasPendingUpdates(false),
+ m_isUpdatesEnabled(true),
+ m_needRedraw(true),
+ m_stallsCount(0)
+{
+}
+
+void WindowHandle::setVideoTimer(shared_ptr<VideoTimer> const & videoTimer)
+{
+ m_videoTimer = videoTimer;
+ m_frameFn = videoTimer->frameFn();
+ m_videoTimer->setFrameFn(bind(&WindowHandle::checkedFrameFn, this));
+ m_stallsCount = 0;
+}
+
+void WindowHandle::checkedFrameFn()
+{
+ if (needRedraw())
+ m_stallsCount = 0;
+ else
+ ++m_stallsCount;
+
+ if (m_stallsCount >= 60)
+ {
+// LOG(LINFO, ("PausedDOWN"));
+ m_videoTimer->pause();
+ }
+ else
+ m_frameFn();
+}
+
+WindowHandle::~WindowHandle() {}
+
+bool WindowHandle::needRedraw() const
+{
+ return m_isUpdatesEnabled && m_needRedraw;
+}
+
+void WindowHandle::checkTimer()
+{
+ switch (m_videoTimer->state())
+ {
+ case VideoTimer::EStopped:
+ m_videoTimer->start();
+ break;
+ case VideoTimer::EPaused:
+// LOG(LINFO, ("WokenUP"));
+ m_videoTimer->resume();
+ break;
+ default:
+ break;
+ }
+}
+
+void WindowHandle::setNeedRedraw(bool flag)
+{
+ m_needRedraw = flag;
+ if (m_needRedraw && m_isUpdatesEnabled)
+ checkTimer();
+}
+
+shared_ptr<yg::gl::RenderContext> const & WindowHandle::renderContext()
+{
+ return m_renderContext;
+}
+
+void WindowHandle::setRenderContext(shared_ptr<yg::gl::RenderContext> const & renderContext)
+{
+ m_renderContext = renderContext;
+}
+
+bool WindowHandle::setUpdatesEnabled(bool doEnable)
+{
+ bool res = false;
+
+ bool wasUpdatesEnabled = m_isUpdatesEnabled;
+ m_isUpdatesEnabled = doEnable;
+
+ if ((!wasUpdatesEnabled) && (doEnable) && (m_hasPendingUpdates))
+ {
+ setNeedRedraw(true);
+ m_hasPendingUpdates = false;
+ res = true;
+ }
+
+ return res;
+}
+
+void WindowHandle::invalidate()
+{
+ if (m_isUpdatesEnabled)
+ setNeedRedraw(true);
+ else
+ m_hasPendingUpdates = true;
+}
diff --git a/map/window_handle.hpp b/map/window_handle.hpp
index f1062ba57c..87ccfa42a0 100644
--- a/map/window_handle.hpp
+++ b/map/window_handle.hpp
@@ -1,6 +1,9 @@
#pragma once
+#include "../platform/video_timer.hpp"
+
#include "../std/shared_ptr.hpp"
+#include "../std/bind.hpp"
#include "events.hpp"
#include "drawer_yg.hpp"
#include "../base/logging.hpp"
@@ -21,52 +24,30 @@ class WindowHandle
bool m_isUpdatesEnabled;
bool m_needRedraw;
+ shared_ptr<VideoTimer> m_videoTimer;
+ VideoTimer::TFrameFn m_frameFn;
+ int m_stallsCount;
+
public:
- WindowHandle() :
- m_hasPendingUpdates(false),
- m_isUpdatesEnabled(true),
- m_needRedraw(true)
- {}
- virtual ~WindowHandle() {}
-
- bool needRedraw() const
- {
- return m_isUpdatesEnabled && m_needRedraw;
- }
- void setNeedRedraw(bool flag)
- {
- m_needRedraw = flag;
- }
+ WindowHandle();
+ virtual ~WindowHandle();
- shared_ptr<yg::gl::RenderContext> const & renderContext()
- {
- return m_renderContext;
- }
+ void setVideoTimer(shared_ptr<VideoTimer> const & videoTimer);
- void setRenderContext(shared_ptr<yg::gl::RenderContext> const & renderContext)
- {
- m_renderContext = renderContext;
- }
+ void checkedFrameFn();
- bool setUpdatesEnabled(bool doEnable)
- {
- bool res = false;
- if ((!m_isUpdatesEnabled) && (doEnable) && (m_hasPendingUpdates))
- {
- setNeedRedraw(true);
- m_hasPendingUpdates = false;
- res = true;
- }
- m_isUpdatesEnabled = doEnable;
- return res;
- }
+ bool needRedraw() const;
- void invalidate()
- {
- if (m_isUpdatesEnabled)
- setNeedRedraw(true);
- else
- m_hasPendingUpdates = true;
- }
+ void checkTimer();
+
+ void setNeedRedraw(bool flag);
+
+ shared_ptr<yg::gl::RenderContext> const & renderContext();
+
+ void setRenderContext(shared_ptr<yg::gl::RenderContext> const & renderContext);
+
+ bool setUpdatesEnabled(bool doEnable);
+
+ void invalidate();
};
diff --git a/platform/apple_video_timer.mm b/platform/apple_video_timer.mm
index 6092d33901..7d0dce0733 100644
--- a/platform/apple_video_timer.mm
+++ b/platform/apple_video_timer.mm
@@ -20,38 +20,52 @@ public:
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);
- CVDisplayLinkStart(m_displayLink);
+ resume();
}
}
- static CVReturn displayLinkCallback(
- CVDisplayLinkRef displayLink,
- const CVTimeStamp *inNow,
- const CVTimeStamp *inOutputTime,
- CVOptionFlags flagsIn,
- CVOptionFlags *flagsOut,
- void *displayLinkContext
- )
+ void resume()
{
- AppleVideoTimer * t = reinterpret_cast<AppleVideoTimer*>(displayLinkContext);
- t->perform();
+ CVDisplayLinkStart(m_displayLink);
+ m_state = ERunning;
+ }
- return kCVReturnSuccess;
+ void pause()
+ {
+ CVDisplayLinkStop(m_displayLink);
+ m_state = EPaused;
}
void stop()
{
if (m_displayLink)
{
- CVDisplayLinkStop(m_displayLink);
+ if (state() == ERunning)
+ pause();
CVDisplayLinkRelease(m_displayLink);
m_displayLink = 0;
+ m_state = EStopped;
}
}
diff --git a/platform/ios_video_timer.mm b/platform/ios_video_timer.mm
index 4a80809ac5..0f2eb42db9 100644
--- a/platform/ios_video_timer.mm
+++ b/platform/ios_video_timer.mm
@@ -38,7 +38,9 @@ public:
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();
}
}
@@ -49,9 +51,22 @@ public:
[m_displayLink invalidate];
[m_objCppWrapper release];
m_displayLink = 0;
+ m_state = EStopped;
}
}
+ void pause()
+ {
+ m_displayLink.paused = true;
+ m_state = EPaused;
+ }
+
+ void resume()
+ {
+ m_displayLink.paused = false;
+ m_state = ERunning;
+ }
+
void perform()
{
m_frameFn();
diff --git a/platform/video_timer.cpp b/platform/video_timer.cpp
index 288534d04a..8f731f58a3 100644
--- a/platform/video_timer.cpp
+++ b/platform/video_timer.cpp
@@ -1,4 +1,22 @@
#include "video_timer.hpp"
-VideoTimer::VideoTimer(TFrameFn fn) : m_frameFn(fn)
+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;
+}
diff --git a/platform/video_timer.hpp b/platform/video_timer.hpp
index d19cf14d13..dc286df6f2 100644
--- a/platform/video_timer.hpp
+++ b/platform/video_timer.hpp
@@ -9,13 +9,29 @@ public:
typedef function<void()> TFrameFn;
+ enum EState
+ {
+ EStopped,
+ EPaused,
+ ERunning
+ };
+
protected:
TFrameFn m_frameFn;
+ EState m_state;
public:
VideoTimer(TFrameFn fn);
- virtual ~VideoTimer() {}
+ 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;
diff --git a/qt/draw_widget.cpp b/qt/draw_widget.cpp
index f607d4a634..1ab00c9cce 100644
--- a/qt/draw_widget.cpp
+++ b/qt/draw_widget.cpp
@@ -15,6 +15,37 @@ using namespace storage;
namespace qt
{
+ QtVideoTimer::QtVideoTimer(DrawWidget * w, TFrameFn frameFn)
+ : ::VideoTimer(frameFn), m_widget(w)
+ {}
+
+ void QtVideoTimer::start()
+ {
+ m_timer = new QTimer();
+ m_widget->connect(m_timer, SIGNAL(timeout()), m_widget, SLOT(AnimTimerElapsed()));
+ resume();
+ }
+
+ void QtVideoTimer::pause()
+ {
+ m_timer->stop();
+ m_state = EPaused;
+ }
+
+ void QtVideoTimer::resume()
+ {
+ m_timer->start(1000 / 60);
+ m_state = ERunning;
+ }
+
+ void QtVideoTimer::stop()
+ {
+ pause();
+ delete m_timer;
+ m_timer = 0;
+ m_state = EStopped;
+ }
+
DrawWidget::DrawWidget(QWidget * pParent, Storage & storage)
: base_type(pParent),
m_handle(new WindowHandle()),
@@ -28,22 +59,21 @@ namespace qt
{
m_framework->InitStorage(storage);
m_timer = new QTimer(this);
-//#ifdef OMIM_OS_MAC
-// m_videoTimer.reset(CreateAppleVideoTimer(bind(&DrawWidget::DrawFrame, this)));
-//#else
- m_animTimer = new QTimer(this);
- connect(m_animTimer, SIGNAL(timeout()), this, SLOT(AnimTimerElapsed()));
-//#endif
+ m_handle->setUpdatesEnabled(false);
+#ifdef OMIM_OS_MAC
+ m_videoTimer.reset(CreateAppleVideoTimer(bind(&DrawWidget::DrawFrame, this)));
+#else
+ m_videoTimer.reset(new QtVideoTimer(this, bind(&DrawWidget::DrawFrame, this)));
+#endif
+
+ m_handle->setVideoTimer(m_videoTimer);
+
connect(m_timer, SIGNAL(timeout()), this, SLOT(ScaleTimerElapsed()));
}
void DrawWidget::PrepareShutdown()
{
-//#ifdef OMIM_OS_MAC
-// m_videoTimer->stop();
-//#else
- m_animTimer->stop();
-//#endif
+ m_videoTimer->stop();
m_framework->PrepareToShutdown();
}
@@ -200,11 +230,8 @@ namespace qt
/// timer should be started upon the first repaint
/// request to fully initialized GLWidget.
m_isTimerStarted = true;
-//#ifdef OMIM_OS_MAC
-// m_videoTimer->start();
-//#else
- m_animTimer->start(1000 / 60);
-//#endif
+ m_handle->setUpdatesEnabled(true);
+ m_handle->invalidate();
}
m_framework->Invalidate();
diff --git a/qt/draw_widget.hpp b/qt/draw_widget.hpp
index 1225433a18..b77c3d792a 100644
--- a/qt/draw_widget.hpp
+++ b/qt/draw_widget.hpp
@@ -26,6 +26,26 @@ namespace qt
/// Replace this to set a draw widget kernel.
typedef GLDrawWidget widget_type;
+ class DrawWidget;
+
+ class QtVideoTimer : public ::VideoTimer
+ {
+ private:
+
+ QTimer * m_timer;
+ DrawWidget * m_widget;
+
+ public:
+
+ QtVideoTimer(DrawWidget * w, ::VideoTimer::TFrameFn frameFn);
+
+ void resume();
+ void pause();
+
+ void start();
+ void stop();
+ };
+
class DrawWidget : public widget_type
{
typedef widget_type base_type;
@@ -40,7 +60,7 @@ namespace qt
scoped_ptr<Framework<model_t> > m_framework;
- scoped_ptr<VideoTimer> m_videoTimer;
+ shared_ptr<VideoTimer> m_videoTimer;
bool m_isDrag;
bool m_isRotate;