Skip to content

Commit

Permalink
[drape] move navigator on frontend renderer
Browse files Browse the repository at this point in the history
  • Loading branch information
ExMix authored and r.kuznetsov committed Nov 30, 2015
1 parent 3d945a9 commit f39751d
Show file tree
Hide file tree
Showing 39 changed files with 1,607 additions and 1,218 deletions.
5 changes: 5 additions & 0 deletions base/timer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,11 @@ uint64_t HighResTimer::ElapsedNano() const
return duration_cast<nanoseconds>(high_resolution_clock::now() - m_start).count();
}

uint64_t HighResTimer::ElapsedMillis() const
{
return duration_cast<milliseconds>(high_resolution_clock::now() - m_start).count();
}

double HighResTimer::ElapsedSeconds() const
{
return duration_cast<duration<double>>(high_resolution_clock::now() - m_start).count();
Expand Down
1 change: 1 addition & 0 deletions base/timer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ class HighResTimer

void Reset();
uint64_t ElapsedNano() const;
uint64_t ElapsedMillis() const;
double ElapsedSeconds() const;
};

Expand Down
3 changes: 3 additions & 0 deletions drape/glyph_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,9 @@ struct UnicodeBlock

int GetFontOffset(int idx) const
{
if (m_fontsWeight.empty())
return -1;

ASSERT(!m_fontsWeight.empty(), ());
int maxWight = 0;
int upperBoundWeight = numeric_limits<int>::max();
Expand Down
24 changes: 10 additions & 14 deletions drape_frontend/backend_renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,11 @@
namespace df
{

BackendRenderer::BackendRenderer(ref_ptr<ThreadsCommutator> commutator,
ref_ptr<dp::OGLContextFactory> oglcontextfactory,
ref_ptr<dp::TextureManager> textureManager,
MapDataProvider const & model)
: BaseRenderer(ThreadsCommutator::ResourceUploadThread, commutator, oglcontextfactory)
, m_model(model)
BackendRenderer::BackendRenderer(Params const & params)
: BaseRenderer(ThreadsCommutator::ResourceUploadThread, params)
, m_model(params.m_model)
, m_batchersPool(make_unique_dp<BatchersPool>(ReadManager::ReadCount(), bind(&BackendRenderer::FlushGeometry, this, _1)))
, m_readManager(make_unique_dp<ReadManager>(commutator, m_model))
, m_texturesManager(textureManager)
, m_readManager(make_unique_dp<ReadManager>(params.m_commutator, m_model))
, m_guiCacher("default")
{
gui::DrapeGui::Instance().SetRecacheSlot([this](gui::Skin::ElementName elements)
Expand All @@ -55,7 +51,7 @@ unique_ptr<threads::IRoutine> BackendRenderer::CreateRoutine()

void BackendRenderer::RecacheGui(gui::Skin::ElementName elements)
{
drape_ptr<gui::LayerRenderer> layerRenderer = m_guiCacher.Recache(elements, m_texturesManager);
drape_ptr<gui::LayerRenderer> layerRenderer = m_guiCacher.Recache(elements, m_texMng);
drape_ptr<Message> outputMsg = make_unique_dp<GuiLayerRecachedMessage>(move(layerRenderer));
m_commutator->PostMessage(ThreadsCommutator::RenderThread, move(outputMsg), MessagePriority::High);
}
Expand Down Expand Up @@ -121,7 +117,7 @@ void BackendRenderer::AcceptMessage(ref_ptr<Message> message)
ref_ptr<MapShapeReadedMessage> msg = static_cast<ref_ptr<MapShapeReadedMessage>>(message);
ref_ptr<dp::Batcher> batcher = m_batchersPool->GetTileBatcher(msg->GetKey());
for (drape_ptr<MapShape> const & shape : msg->GetShapes())
shape->Draw(batcher, m_texturesManager);
shape->Draw(batcher, m_texMng);
break;
}
case Message::UpdateUserMarkLayer:
Expand All @@ -137,7 +133,7 @@ void BackendRenderer::AcceptMessage(ref_ptr<Message> message)

UserMarksProvider const * marksProvider = msg->StartProcess();
if (marksProvider->IsDirty())
CacheUserMarks(marksProvider, m_batchersPool->GetTileBatcher(key), m_texturesManager);
CacheUserMarks(marksProvider, m_batchersPool->GetTileBatcher(key), m_texMng);
msg->EndProcess();
m_batchersPool->ReleaseBatcher(key);
break;
Expand All @@ -163,7 +159,7 @@ void BackendRenderer::ReleaseResources()
m_readManager.reset();
m_batchersPool.reset();

m_texturesManager->Release();
m_texMng->Release();
}

BackendRenderer::Routine::Routine(BackendRenderer & renderer) : m_renderer(renderer) {}
Expand Down Expand Up @@ -193,9 +189,9 @@ void BackendRenderer::InitGLDependentResource()
params.m_glyphMngParams.m_blacklist = "fonts_blacklist.txt";
GetPlatform().GetFontNames(params.m_glyphMngParams.m_fonts);

m_texturesManager->Init(params);
m_texMng->Init(params);

drape_ptr<MyPosition> position = make_unique_dp<MyPosition>(m_texturesManager);
drape_ptr<MyPosition> position = make_unique_dp<MyPosition>(m_texMng);
m_commutator->PostMessage(ThreadsCommutator::RenderThread,
make_unique_dp<MyPositionShapeMessage>(move(position)),
MessagePriority::High);
Expand Down
18 changes: 13 additions & 5 deletions drape_frontend/backend_renderer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,19 @@ class ReadManager;
class BackendRenderer : public BaseRenderer
{
public:
BackendRenderer(ref_ptr<ThreadsCommutator> commutator,
ref_ptr<dp::OGLContextFactory> oglcontextfactory,
ref_ptr<dp::TextureManager> textureManager,
MapDataProvider const & model);
struct Params : BaseRenderer::Params
{
Params(ref_ptr<ThreadsCommutator> commutator, ref_ptr<dp::OGLContextFactory> factory,
ref_ptr<dp::TextureManager> texMng, MapDataProvider const & model)
: BaseRenderer::Params(commutator, factory, texMng)
, m_model(model)
{
}

MapDataProvider const & m_model;
};

BackendRenderer(Params const & params);

~BackendRenderer() override;

Expand All @@ -42,7 +51,6 @@ class BackendRenderer : public BaseRenderer
MapDataProvider m_model;
drape_ptr<BatchersPool> m_batchersPool;
drape_ptr<ReadManager> m_readManager;
ref_ptr<dp::TextureManager> m_texturesManager;
gui::LayerCacher m_guiCacher;

/////////////////////////////////////////
Expand Down
9 changes: 4 additions & 5 deletions drape_frontend/base_renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@
namespace df
{

BaseRenderer::BaseRenderer(ThreadsCommutator::ThreadName name,
ref_ptr<ThreadsCommutator> commutator,
ref_ptr<dp::OGLContextFactory> oglcontextfactory)
: m_commutator(commutator)
, m_contextFactory(oglcontextfactory)
BaseRenderer::BaseRenderer(ThreadsCommutator::ThreadName name, Params const & params)
: m_commutator(params.m_commutator)
, m_contextFactory(params.m_oglContextFactory)
, m_texMng(params.m_texMng)
, m_threadName(name)
, m_isEnabled(true)
, m_renderingEnablingCompletionHandler(nullptr)
Expand Down
26 changes: 21 additions & 5 deletions drape_frontend/base_renderer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "drape_frontend/tile_utils.hpp"

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

#include "base/thread.hpp"

Expand All @@ -19,17 +20,30 @@ namespace df
class BaseRenderer : public MessageAcceptor
{
public:
using TCompletionHandler = function<void()>;

BaseRenderer(ThreadsCommutator::ThreadName name,
ref_ptr<ThreadsCommutator> commutator,
ref_ptr<dp::OGLContextFactory> oglcontextfactory);
struct Params
{
Params(ref_ptr<ThreadsCommutator> commutator,
ref_ptr<dp::OGLContextFactory> factory,
ref_ptr<dp::TextureManager> texMng)
: m_commutator(commutator)
, m_oglContextFactory(factory)
, m_texMng(texMng)
{
}

ref_ptr<ThreadsCommutator> m_commutator;
ref_ptr<dp::OGLContextFactory> m_oglContextFactory;
ref_ptr<dp::TextureManager> m_texMng;
};

BaseRenderer(ThreadsCommutator::ThreadName name, Params const & params);

void SetRenderingEnabled(bool const isEnabled);

protected:
ref_ptr<ThreadsCommutator> m_commutator;
ref_ptr<dp::OGLContextFactory> m_contextFactory;
ref_ptr<dp::TextureManager> m_texMng;

void StartThread();
void StopThread();
Expand All @@ -42,6 +56,8 @@ class BaseRenderer : public MessageAcceptor
private:
bool CanReceiveMessage() override;

using TCompletionHandler = function<void()>;

private:
threads::Thread m_selfThread;
ThreadsCommutator::ThreadName m_threadName;
Expand Down
74 changes: 63 additions & 11 deletions drape_frontend/drape_engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

#include "drape/texture_manager.hpp"

#include "platform/platform.hpp"

#include "std/bind.hpp"
#include "std/condition_variable.hpp"
#include "std/mutex.hpp"

namespace df
{
Expand All @@ -36,11 +36,16 @@ DrapeEngine::DrapeEngine(Params const & params)
m_textureManager = make_unique_dp<dp::TextureManager>();
m_threadCommutator = make_unique_dp<ThreadsCommutator>();

m_frontend = make_unique_dp<FrontendRenderer>(make_ref(m_threadCommutator), params.m_factory,
make_ref(m_textureManager), m_viewport);
FrontendRenderer::Params frParams(make_ref(m_threadCommutator), params.m_factory,
make_ref(m_textureManager), m_viewport,
bind(&DrapeEngine::ModelViewChanged, this, _1),
params.m_model.GetIsCountryLoadedFn());

m_frontend = make_unique_dp<FrontendRenderer>(frParams);

m_backend = make_unique_dp<BackendRenderer>(make_ref(m_threadCommutator), params.m_factory,
make_ref(m_textureManager), params.m_model);
BackendRenderer::Params brParams(frParams.m_commutator, frParams.m_oglContextFactory,
frParams.m_texMng, params.m_model);
m_backend = make_unique_dp<BackendRenderer>(brParams);
}

DrapeEngine::~DrapeEngine()
Expand All @@ -60,14 +65,44 @@ void DrapeEngine::Resize(int w, int h)
return;

m_viewport.SetViewport(0, 0, w, h);
m_threadCommutator->PostMessage(ThreadsCommutator::RenderThread,
make_unique_dp<ResizeMessage>(m_viewport),
MessagePriority::High);
AddUserEvent(ResizeEvent(w, h));
}

void DrapeEngine::AddTouchEvent(TouchEvent const & event)
{
AddUserEvent(event);
}

void DrapeEngine::Scale(double factor, m2::PointD const & pxPoint)
{
AddUserEvent(ScaleEvent(factor, pxPoint));
}

void DrapeEngine::SetModelViewCenter(m2::PointD const & centerPt, int zoom)
{
AddUserEvent(SetCenterEvent(centerPt, zoom));
}

void DrapeEngine::SetModelViewRect(m2::RectD const & rect, bool applyRotation, int zoom)
{
AddUserEvent(SetRectEvent(rect, applyRotation, zoom));
}

void DrapeEngine::UpdateCoverage(ScreenBase const & screen)
void DrapeEngine::SetModelViewAnyRect(m2::AnyRectD const & rect)
{
m_frontend->SetModelView(screen);
AddUserEvent(SetAnyRectEvent(rect));
}

int DrapeEngine::AddModelViewListener(TModelViewListenerFn const & listener)
{
static int currentSlotID = 0;
VERIFY(m_listeners.insert(make_pair(++currentSlotID, listener)).second, ());
return currentSlotID;
}

void DrapeEngine::RemoveModeViewListener(int slotID)
{
m_listeners.erase(slotID);
}

void DrapeEngine::ClearUserMarksLayer(df::TileKey const & tileKey)
Expand Down Expand Up @@ -99,4 +134,21 @@ void DrapeEngine::SetRenderingEnabled(bool const isEnabled)
LOG(LDEBUG, (isEnabled ? "Rendering enabled" : "Rendering disabled"));
}

void DrapeEngine::AddUserEvent(UserEvent const & e)
{
m_frontend->AddUserEvent(e);
}

void DrapeEngine::ModelViewChanged(ScreenBase const & screen)
{
Platform & pl = GetPlatform();
pl.RunOnGuiThread(bind(&DrapeEngine::ModelViewChangedGuiThread, this, screen));
}

void DrapeEngine::ModelViewChangedGuiThread(ScreenBase const & screen)
{
for (pair<int, TModelViewListenerFn> const & p : m_listeners)
p.second(screen);
}

} // namespace df
24 changes: 23 additions & 1 deletion drape_frontend/drape_engine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@

#include "base/strings_bundle.hpp"

#include "std/map.hpp"
#include "std/mutex.hpp"

namespace dp { class OGLContextFactory; }
namespace gui { class StorageAccessor; }

Expand Down Expand Up @@ -53,21 +56,40 @@ class DrapeEngine
~DrapeEngine();

void Resize(int w, int h);
void UpdateCoverage(ScreenBase const & screen);

void AddTouchEvent(TouchEvent const & event);
void Scale(double factor, m2::PointD const & pxPoint);

/// if zoom == -1, then current zoom will not change
void SetModelViewCenter(m2::PointD const & centerPt, int zoom);
void SetModelViewRect(m2::RectD const & rect, bool applyRotation, int zoom);
void SetModelViewAnyRect(m2::AnyRectD const & rect);

using TModelViewListenerFn = FrontendRenderer::TModelViewChanged;
int AddModelViewListener(TModelViewListenerFn const & listener);
void RemoveModeViewListener(int slotID);

void ClearUserMarksLayer(TileKey const & tileKey);
void ChangeVisibilityUserMarksLayer(TileKey const & tileKey, bool isVisible);
void UpdateUserMarksLayer(TileKey const & tileKey, UserMarksProvider * provider);

void SetRenderingEnabled(bool const isEnabled);

private:
void AddUserEvent(UserEvent const & e);
void ModelViewChanged(ScreenBase const & screen);
void ModelViewChangedGuiThread(ScreenBase const & screen);

private:
drape_ptr<FrontendRenderer> m_frontend;
drape_ptr<BackendRenderer> m_backend;
drape_ptr<ThreadsCommutator> m_threadCommutator;
drape_ptr<dp::TextureManager> m_textureManager;

Viewport m_viewport;

using TListenerMap = map<int, TModelViewListenerFn>;
TListenerMap m_listeners;
};

} // namespace df
8 changes: 6 additions & 2 deletions drape_frontend/drape_frontend.pro
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ SOURCES += \
memory_feature_index.cpp \
message_acceptor.cpp \
message_queue.cpp \
navigator.cpp \
path_symbol_shape.cpp \
path_text_shape.cpp \
poi_symbol_shape.cpp \
Expand All @@ -43,7 +44,8 @@ SOURCES += \
user_marks_provider.cpp \
viewport.cpp \
visual_params.cpp \
my_position.cpp
my_position.cpp \
user_event_stream.cpp

HEADERS += \
apply_feature_functors.hpp \
Expand All @@ -64,6 +66,7 @@ HEADERS += \
message_acceptor.hpp \
message_queue.hpp \
message_subclasses.hpp \
navigator.hpp \
path_symbol_shape.hpp \
path_text_shape.hpp \
poi_symbol_shape.hpp \
Expand All @@ -85,4 +88,5 @@ HEADERS += \
user_marks_provider.hpp \
viewport.hpp \
visual_params.hpp \
my_position.hpp
my_position.hpp \
user_event_stream.hpp
Loading

0 comments on commit f39751d

Please sign in to comment.