Skip to content

Commit

Permalink
Fixed drape engine destruction on iOS, moved some common code to rend…
Browse files Browse the repository at this point in the history
…erer
  • Loading branch information
r.kuznetsov committed Nov 30, 2015
1 parent 8505cb9 commit d7b1edc
Show file tree
Hide file tree
Showing 10 changed files with 69 additions and 35 deletions.
7 changes: 2 additions & 5 deletions drape_frontend/backend_renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@
#include "drape_frontend/map_shape.hpp"
#include "drape_frontend/user_mark_shapes.hpp"

#include "drape_frontend/threads_commutator.hpp"
#include "drape_frontend/message_subclasses.hpp"

#include "drape/oglcontextfactory.hpp"
#include "drape/texture_manager.hpp"

#include "platform/platform.hpp"
Expand All @@ -24,12 +22,11 @@ BackendRenderer::BackendRenderer(dp::RefPointer<ThreadsCommutator> commutator,
dp::RefPointer<dp::OGLContextFactory> oglcontextfactory,
dp::RefPointer<dp::TextureManager> textureManager,
MapDataProvider const & model)
: m_model(model)
: BaseRenderer(commutator, oglcontextfactory)
, m_model(model)
, m_engineContext(commutator)
, m_texturesManager(textureManager)
, m_guiCacher("default")
, m_commutator(commutator)
, m_contextFactory(oglcontextfactory)
{
m_commutator->RegisterThread(ThreadsCommutator::ResourceUploadThread, this);
m_batchersPool.Reset(new BatchersPool(ReadManager::ReadCount(), bind(&BackendRenderer::FlushGeometry, this, _1)));
Expand Down
14 changes: 3 additions & 11 deletions drape_frontend/backend_renderer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
#include "drape_gui/layer_render.hpp"
#include "drape/pointers.hpp"

#include "base/thread.hpp"

namespace dp
{

Expand All @@ -22,7 +20,6 @@ namespace df
{

class Message;
class ThreadsCommutator;
class BatchersPool;
class ReadManager;

Expand Down Expand Up @@ -50,9 +47,9 @@ class BackendRenderer : public BaseRenderer
private:
void AcceptMessage(dp::RefPointer<Message> message);

/////////////////////////////////////////
// ThreadPart //
/////////////////////////////////////////
/////////////////////////////////////////
// ThreadPart //
/////////////////////////////////////////
private:
class Routine : public threads::IRoutine
{
Expand All @@ -72,11 +69,6 @@ class BackendRenderer : public BaseRenderer

void InitGLDependentResource();
void FlushGeometry(dp::TransferPointer<Message> message);

private:
threads::Thread m_selfThread;
dp::RefPointer<ThreadsCommutator> m_commutator;
dp::RefPointer<dp::OGLContextFactory> m_contextFactory;
};

} // namespace df
39 changes: 34 additions & 5 deletions drape_frontend/base_renderer.cpp
Original file line number Diff line number Diff line change
@@ -1,16 +1,40 @@
#include "base_renderer.hpp"
#include "threads_commutator.hpp"
#include "../std/utility.hpp"

#include "../base/logging.hpp"


namespace df
{

BaseRenderer::BaseRenderer()
: m_isEnabled(true)
BaseRenderer::BaseRenderer(dp::RefPointer<ThreadsCommutator> commutator,
dp::RefPointer<dp::OGLContextFactory> oglcontextfactory)
: m_commutator(commutator)
, m_contextFactory(oglcontextfactory)
, m_isEnabled(true)
, m_renderingEnablingCompletionHandler(nullptr)
, m_wasNotified(false)
{
}

void BaseRenderer::StartThread()
{
m_selfThread.Create(this);
}

void BaseRenderer::StopThread()
{
IRoutine::Cancel();

if (!m_isEnabled)
{
WakeUp();
}
CloseQueue();
m_selfThread.Join();
}

void BaseRenderer::SetRenderingEnabled(bool const isEnabled)
{
// here we have to wait for completion of internal SetRenderingEnabled
Expand Down Expand Up @@ -44,9 +68,7 @@ void BaseRenderer::SetRenderingEnabled(bool const isEnabled, TCompletionHandler
if (isEnabled)
{
// wake up rendering thread
lock_guard<mutex> lock(m_renderingEnablingMutex);
m_wasNotified = true;
m_renderingEnablingCondition.notify_one();
WakeUp();
}
else
{
Expand Down Expand Up @@ -87,4 +109,11 @@ void BaseRenderer::Notify()
m_renderingEnablingCompletionHandler = nullptr;
}

void BaseRenderer::WakeUp()
{
lock_guard<mutex> lock(m_renderingEnablingMutex);
m_wasNotified = true;
m_renderingEnablingCondition.notify_one();
}

} // namespace df
21 changes: 19 additions & 2 deletions drape_frontend/base_renderer.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#pragma once

#include "message_acceptor.hpp"
#include "../base/thread.hpp"
#include "../drape/oglcontextfactory.hpp"

#include "../std/atomic.hpp"
#include "../std/condition_variable.hpp"
#include "../std/function.hpp"
Expand All @@ -9,18 +12,31 @@
namespace df
{

class BaseRenderer : public MessageAcceptor
class ThreadsCommutator;

class BaseRenderer : public MessageAcceptor,
public threads::IRoutine
{
public:
using TCompletionHandler = function<void()>;

BaseRenderer();
BaseRenderer(dp::RefPointer<ThreadsCommutator> commutator,
dp::RefPointer<dp::OGLContextFactory> oglcontextfactory);

void SetRenderingEnabled(bool const isEnabled);
void ClearRenderingQueueSynchronously();

protected:
dp::RefPointer<ThreadsCommutator> m_commutator;
dp::RefPointer<dp::OGLContextFactory> m_contextFactory;

void StartThread();
void StopThread();
void CheckRenderingEnabled();

private:
threads::Thread m_selfThread;

mutex m_renderingEnablingMutex;
condition_variable m_renderingEnablingCondition;
atomic<bool> m_isEnabled;
Expand All @@ -29,6 +45,7 @@ class BaseRenderer : public MessageAcceptor

void SetRenderingEnabled(bool const isEnabled, TCompletionHandler completionHandler);
void Notify();
void WakeUp();
};

} // namespace df
7 changes: 3 additions & 4 deletions drape_frontend/frontend_renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ FrontendRenderer::FrontendRenderer(dp::RefPointer<ThreadsCommutator> commutator,
dp::RefPointer<dp::OGLContextFactory> oglcontextfactory,
dp::RefPointer<dp::TextureManager> textureManager,
Viewport viewport)
: m_commutator(commutator)
, m_contextFactory(oglcontextfactory)
: BaseRenderer(commutator, oglcontextfactory)
, m_textureManager(textureManager)
, m_gpuProgramManager(new dp::GpuProgramManager())
, m_viewport(viewport)
Expand Down Expand Up @@ -426,7 +425,7 @@ void FrontendRenderer::Routine::Do()
while (!IsCancelled())
{
context->setDefaultFramebuffer();
m_textureManager->UpdateDynamicTextures();
m_renderer.m_textureManager->UpdateDynamicTextures();
m_renderer.RenderScene();

double availableTime = VSyncInterval - (timer.ElapsedSeconds() /*+ avarageMessageTime*/);
Expand All @@ -446,7 +445,7 @@ void FrontendRenderer::Routine::Do()
context->present();
timer.Reset();

CheckRenderingEnabled();
m_renderer.CheckRenderingEnabled();
}

m_renderer.ReleaseResources();
Expand Down
7 changes: 0 additions & 7 deletions drape_frontend/frontend_renderer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
#include "drape/glstate.hpp"
#include "drape/vertex_array_buffer.hpp"
#include "drape/gpu_program_manager.hpp"
#include "drape/oglcontextfactory.hpp"
#include "drape/overlay_tree.hpp"
#include "drape/uniform_values_storage.hpp"

Expand All @@ -33,9 +32,6 @@ namespace dp { class RenderBucket; }
namespace df
{

struct RenderingEnablingContext;


class FrontendRenderer : public BaseRenderer
{
public:
Expand Down Expand Up @@ -96,12 +92,9 @@ class FrontendRenderer : public BaseRenderer
void DeleteRenderData();

private:
dp::RefPointer<ThreadsCommutator> m_commutator;
dp::RefPointer<dp::OGLContextFactory> m_contextFactory;
dp::RefPointer<dp::TextureManager> m_textureManager;

dp::MasterPointer<dp::GpuProgramManager> m_gpuProgramManager;
threads::Thread m_selfThread;

private:
vector<RenderGroup *> m_renderGroups;
Expand Down
5 changes: 5 additions & 0 deletions drape_frontend/message_subclasses.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,11 @@ class GuiLayerRecachedMessage : public Message
GuiLayerRecachedMessage(dp::TransferPointer<gui::LayerRenderer> renderer)
: m_renderer(renderer) {}

~GuiLayerRecachedMessage()
{
m_renderer.Destroy();
}

Type GetType() const override { return Message::GuiLayerRecached; }

dp::MasterPointer<gui::LayerRenderer> AcceptRenderer()
Expand Down
1 change: 1 addition & 0 deletions iphone/Maps/Classes/EAGLView.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ namespace dp

- (void)initRenderPolicy;
- (void)setMapStyle:(MapStyle)mapStyle;
- (void)deallocateNative;
- (CGPoint)viewPoint2GlobalPoint:(CGPoint)pt;
- (CGPoint)globalPoint2ViewPoint:(CGPoint)pt;

Expand Down
2 changes: 1 addition & 1 deletion iphone/Maps/Classes/EAGLView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ - (void)layoutSubviews
}
}

- (void)dealloc
- (void)deallocateNative
{
GetFramework().PrepareToShutdown();
m_factory.Destroy();
Expand Down
1 change: 1 addition & 0 deletions iphone/Maps/Classes/MapViewController.mm
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,7 @@ - (void)didReceiveMemoryWarning
- (void)onTerminate
{
GetFramework().SaveState();
[(EAGLView *)self.view deallocateNative];
}

- (void)onEnterBackground
Expand Down

0 comments on commit d7b1edc

Please sign in to comment.