forked from organicmaps/organicmaps
added BeginFrame and EndFrame functions to fine-tune multithreaded OpenGL resources access.
This commit is contained in:
parent
fe9ca47619
commit
2923bd3f80
12 changed files with 73 additions and 22 deletions
|
@ -181,8 +181,10 @@ bool _inRepaint = false;
|
|||
if (_doRepaint)
|
||||
{
|
||||
_doRepaint = false;
|
||||
[controller onPaint];
|
||||
[controller beginPaint];
|
||||
[controller doPaint];
|
||||
renderBuffer->present();
|
||||
[controller endPaint];
|
||||
}
|
||||
_inRepaint = false;
|
||||
}
|
||||
|
|
|
@ -32,7 +32,9 @@
|
|||
- (void) ZoomToRect: (m2::RectD const &) rect;
|
||||
|
||||
- (void) onResize: (GLint)width withHeight: (GLint)height;
|
||||
- (void) onPaint;
|
||||
- (void) beginPaint;
|
||||
- (void) doPaint;
|
||||
- (void) endPaint;
|
||||
|
||||
// called when app is terminated by system
|
||||
- (void) OnTerminate;
|
||||
|
|
|
@ -275,11 +275,21 @@ NSInteger compareAddress(id l, id r, void * context)
|
|||
m_framework->Scale(0.5);
|
||||
}
|
||||
|
||||
- (void)onPaint
|
||||
- (void)beginPaint
|
||||
{
|
||||
m_framework->BeginPaint();
|
||||
}
|
||||
|
||||
- (void)endPaint
|
||||
{
|
||||
m_framework->EndPaint();
|
||||
}
|
||||
|
||||
- (void)doPaint
|
||||
{
|
||||
shared_ptr<iphone::WindowHandle> windowHandle = [(EAGLView*)self.view windowHandle];
|
||||
shared_ptr<PaintEvent> paintEvent(new PaintEvent(windowHandle->drawer().get()));
|
||||
m_framework->Paint(paintEvent);
|
||||
m_framework->DoPaint(paintEvent);
|
||||
}
|
||||
|
||||
- (BOOL) shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation) interfaceOrientation
|
||||
|
|
|
@ -293,10 +293,10 @@ void BenchmarkFramework<TModel>::OnSize(int w, int h)
|
|||
}
|
||||
|
||||
template <typename TModel>
|
||||
void BenchmarkFramework<TModel>::Paint(shared_ptr<PaintEvent> e)
|
||||
void BenchmarkFramework<TModel>::DoPaint(shared_ptr<PaintEvent> e)
|
||||
{
|
||||
double s = m_benchmarksTimer.ElapsedSeconds();
|
||||
Framework<TModel>::Paint(e);
|
||||
Framework<TModel>::DoPaint(e);
|
||||
m_paintDuration += m_benchmarksTimer.ElapsedSeconds() - s;
|
||||
if (!m_isBenchmarkFinished)
|
||||
BenchmarkCommandFinished();
|
||||
|
|
|
@ -71,5 +71,5 @@ public:
|
|||
|
||||
void OnSize(int w, int h);
|
||||
|
||||
virtual void Paint(shared_ptr<PaintEvent> e);
|
||||
virtual void DoPaint(shared_ptr<PaintEvent> e);
|
||||
};
|
||||
|
|
|
@ -323,9 +323,21 @@ void Framework<TModel>::DrawModel(shared_ptr<PaintEvent> const & e,
|
|||
Invalidate();
|
||||
}
|
||||
|
||||
template <typename TModel>
|
||||
void Framework<TModel>::BeginPaint()
|
||||
{
|
||||
m_renderPolicy->BeginFrame();
|
||||
}
|
||||
|
||||
template <typename TModel>
|
||||
void Framework<TModel>::EndPaint()
|
||||
{
|
||||
m_renderPolicy->EndFrame();
|
||||
}
|
||||
|
||||
/// Function for calling from platform dependent-paint function.
|
||||
template <typename TModel>
|
||||
void Framework<TModel>::Paint(shared_ptr<PaintEvent> e)
|
||||
void Framework<TModel>::DoPaint(shared_ptr<PaintEvent> e)
|
||||
{
|
||||
DrawerYG * pDrawer = e->drawer();
|
||||
|
||||
|
|
|
@ -207,8 +207,11 @@ public:
|
|||
|
||||
double GetCurrentScale() const;
|
||||
|
||||
virtual void BeginPaint();
|
||||
/// Function for calling from platform dependent-paint function.
|
||||
virtual void Paint(shared_ptr<PaintEvent> e);
|
||||
virtual void DoPaint(shared_ptr<PaintEvent> e);
|
||||
|
||||
virtual void EndPaint();
|
||||
|
||||
void CenterViewport(m2::PointD const & pt);
|
||||
|
||||
|
|
|
@ -69,3 +69,9 @@ void RenderPolicy::StopScale(m2::PointD const &, m2::PointD const &, double)
|
|||
{
|
||||
m_windowHandle->invalidate();
|
||||
}
|
||||
|
||||
void RenderPolicy::BeginFrame()
|
||||
{}
|
||||
|
||||
void RenderPolicy::EndFrame()
|
||||
{}
|
||||
|
|
|
@ -47,8 +47,12 @@ public:
|
|||
/// constructor
|
||||
RenderPolicy(shared_ptr<WindowHandle> const & windowHandle, TRenderFn const & renderFn);
|
||||
virtual ~RenderPolicy() {}
|
||||
/// starting frame
|
||||
virtual void BeginFrame();
|
||||
/// drawing single frame
|
||||
virtual void DrawFrame(shared_ptr<PaintEvent> const & paintEvent, ScreenBase const & currentScreen) = 0;
|
||||
/// ending frame
|
||||
virtual void EndFrame();
|
||||
/// processing resize request
|
||||
virtual m2::RectI const OnSize(int w, int h);
|
||||
/// initialize render policy
|
||||
|
|
|
@ -43,6 +43,16 @@ m2::RectI const RenderPolicyMT::OnSize(int w, int h)
|
|||
return m2::RectI(pt.x, pt.y, pt.x + w, pt.y + h);
|
||||
}
|
||||
|
||||
void RenderPolicyMT::BeginFrame()
|
||||
{
|
||||
m_renderQueue.renderState().m_mutex->Lock();
|
||||
}
|
||||
|
||||
void RenderPolicyMT::EndFrame()
|
||||
{
|
||||
m_renderQueue.renderState().m_mutex->Unlock();
|
||||
}
|
||||
|
||||
void RenderPolicyMT::DrawFrame(shared_ptr<PaintEvent> const & e,
|
||||
ScreenBase const & s)
|
||||
{
|
||||
|
@ -51,25 +61,21 @@ void RenderPolicyMT::DrawFrame(shared_ptr<PaintEvent> const & e,
|
|||
|
||||
DrawerYG * pDrawer = e->drawer();
|
||||
|
||||
e->drawer()->screen()->clear(bgColor());
|
||||
|
||||
if (m_renderQueue.renderState().m_actualTarget.get() != 0)
|
||||
{
|
||||
threads::MutexGuard g(*m_renderQueue.renderState().m_mutex.get());
|
||||
|
||||
e->drawer()->screen()->clear(bgColor());
|
||||
|
||||
if (m_renderQueue.renderState().m_actualTarget.get() != 0)
|
||||
{
|
||||
m2::PointD ptShift = m_renderQueue.renderState().coordSystemShift(false);
|
||||
m2::PointD ptShift = m_renderQueue.renderState().coordSystemShift(false);
|
||||
|
||||
// OGLCHECK(glMatrixMode(GL_MODELVIEW));
|
||||
// OGLCHECK(glPushMatrix());
|
||||
// OGLCHECK(glTranslatef(-ptShift.x, -ptShift.y, 0));
|
||||
|
||||
math::Matrix<double, 3, 3> m = m_renderQueue.renderState().m_actualScreen.PtoGMatrix() * s.GtoPMatrix();
|
||||
m = math::Shift(m, -ptShift);
|
||||
math::Matrix<double, 3, 3> m = m_renderQueue.renderState().m_actualScreen.PtoGMatrix() * s.GtoPMatrix();
|
||||
m = math::Shift(m, -ptShift);
|
||||
|
||||
pDrawer->screen()->blit(m_renderQueue.renderState().m_actualTarget,
|
||||
m);
|
||||
}
|
||||
pDrawer->screen()->blit(m_renderQueue.renderState().m_actualTarget,
|
||||
m);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -20,9 +20,13 @@ public:
|
|||
void Initialize(shared_ptr<yg::gl::RenderContext> const & rc,
|
||||
shared_ptr<yg::ResourceManager> const & rm);
|
||||
|
||||
void BeginFrame();
|
||||
|
||||
void DrawFrame(shared_ptr<PaintEvent> const & paintEvent,
|
||||
ScreenBase const & screenBase);
|
||||
|
||||
void EndFrame();
|
||||
|
||||
m2::RectI const OnSize(int w, int h);
|
||||
|
||||
void StartDrag(m2::PointD const & pt, double timeInSec);
|
||||
|
|
|
@ -171,8 +171,10 @@ namespace qt
|
|||
|
||||
void DrawWidget::DoDraw(shared_ptr<drawer_t> p)
|
||||
{
|
||||
m_framework->BeginPaint();
|
||||
shared_ptr<PaintEvent> paintEvent(new PaintEvent(p.get()));
|
||||
m_framework->Paint(paintEvent);
|
||||
m_framework->DoPaint(paintEvent);
|
||||
m_framework->EndPaint();
|
||||
}
|
||||
|
||||
void DrawWidget::DoResize(int w, int h)
|
||||
|
|
Loading…
Add table
Reference in a new issue