Fixed drape engine destruction on iOS, moved some common code to renderer

This commit is contained in:
r.kuznetsov 2015-03-16 16:25:41 +03:00
parent 8505cb9824
commit d7b1edc1c2
10 changed files with 69 additions and 35 deletions

View file

@ -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"
@ -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)));

View file

@ -8,8 +8,6 @@
#include "drape_gui/layer_render.hpp"
#include "drape/pointers.hpp"
#include "base/thread.hpp"
namespace dp
{
@ -22,7 +20,6 @@ namespace df
{
class Message;
class ThreadsCommutator;
class BatchersPool;
class ReadManager;
@ -50,9 +47,9 @@ private:
private:
void AcceptMessage(dp::RefPointer<Message> message);
/////////////////////////////////////////
// ThreadPart //
/////////////////////////////////////////
/////////////////////////////////////////
// ThreadPart //
/////////////////////////////////////////
private:
class Routine : public threads::IRoutine
{
@ -72,11 +69,6 @@ private:
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

View file

@ -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
@ -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
{
@ -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

View file

@ -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"
@ -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;
@ -29,6 +45,7 @@ private:
void SetRenderingEnabled(bool const isEnabled, TCompletionHandler completionHandler);
void Notify();
void WakeUp();
};
} // namespace df

View file

@ -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)
@ -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*/);
@ -446,7 +445,7 @@ void FrontendRenderer::Routine::Do()
context->present();
timer.Reset();
CheckRenderingEnabled();
m_renderer.CheckRenderingEnabled();
}
m_renderer.ReleaseResources();

View file

@ -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"
@ -33,9 +32,6 @@ namespace dp { class RenderBucket; }
namespace df
{
struct RenderingEnablingContext;
class FrontendRenderer : public BaseRenderer
{
public:
@ -96,12 +92,9 @@ private:
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;

View file

@ -226,6 +226,11 @@ public:
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()

View file

@ -23,6 +23,7 @@ namespace dp
- (void)initRenderPolicy;
- (void)setMapStyle:(MapStyle)mapStyle;
- (void)deallocateNative;
- (CGPoint)viewPoint2GlobalPoint:(CGPoint)pt;
- (CGPoint)globalPoint2ViewPoint:(CGPoint)pt;

View file

@ -153,7 +153,7 @@ graphics::EDensity getDensityType(int exactDensityDPI, double scale)
}
}
- (void)dealloc
- (void)deallocateNative
{
GetFramework().PrepareToShutdown();
m_factory.Destroy();

View file

@ -507,6 +507,7 @@ typedef NS_ENUM(NSUInteger, UserTouchesAction)
- (void)onTerminate
{
GetFramework().SaveState();
[(EAGLView *)self.view deallocateNative];
}
- (void)onEnterBackground