From b67234634bcce9673386bbf7a86b6c075488d8af Mon Sep 17 00:00:00 2001 From: ExMix Date: Fri, 10 Jan 2014 15:59:48 +0300 Subject: [PATCH] [drape] review fix --- drape/binding_info.cpp | 6 ++--- drape/drape_common.pri | 6 +++-- drape/glfunctions.cpp | 2 +- drape/oglcontextfactory.cpp | 24 +++++++++++++++++++ drape/oglcontextfactory.hpp | 15 ++++++++++++ drape_frontend/impl/backend_renderer_impl.cpp | 5 +++- drape_frontend/impl/backend_renderer_impl.hpp | 2 +- drape_frontend/read_mwm_task.hpp | 16 ++++++------- drape_frontend/tile_info.hpp | 4 ++-- drape_head/drape_surface.cpp | 3 ++- drape_head/drape_surface.hpp | 4 ++-- drape_head/qtoglcontextfactory.cpp | 4 ---- drape_head/qtoglcontextfactory.hpp | 4 ---- 13 files changed, 66 insertions(+), 29 deletions(-) create mode 100644 drape/oglcontextfactory.cpp diff --git a/drape/binding_info.cpp b/drape/binding_info.cpp index 65030c7613..09a36d69b0 100644 --- a/drape/binding_info.cpp +++ b/drape/binding_info.cpp @@ -25,10 +25,10 @@ namespace bool BindingDecl::operator !=(const BindingDecl & other) const { - return m_attributeName != other.m_attributeName || + return m_attributeName != other.m_attributeName || m_componentCount != other.m_componentCount || - m_componentType != other.m_componentType || - m_stride != other.m_stride || + m_componentType != other.m_componentType || + m_stride != other.m_stride || m_offset != other.m_offset; } diff --git a/drape/drape_common.pri b/drape/drape_common.pri index 6e8a4e4407..cb24a7e133 100644 --- a/drape/drape_common.pri +++ b/drape/drape_common.pri @@ -21,7 +21,8 @@ SOURCES += \ $$DRAPE_DIR/glextensions_list.cpp \ $$DRAPE_DIR/pointers.cpp \ $$DRAPE_DIR/uniform_values_storage.cpp \ - $$DRAPE_DIR/color.cpp + $$DRAPE_DIR/color.cpp \ + $$DRAPE_DIR/oglcontextfactory.cpp HEADERS += \ $$DRAPE_DIR/data_buffer.hpp \ @@ -46,4 +47,5 @@ HEADERS += \ $$DRAPE_DIR/glextensions_list.hpp \ $$DRAPE_DIR/oglcontext.hpp \ $$DRAPE_DIR/uniform_values_storage.hpp \ - $$DRAPE_DIR/color.hpp + $$DRAPE_DIR/color.hpp \ + $$DRAPE_DIR/oglcontextfactory.hpp diff --git a/drape/glfunctions.cpp b/drape/glfunctions.cpp index 37bdecb057..176143b8b3 100644 --- a/drape/glfunctions.cpp +++ b/drape/glfunctions.cpp @@ -15,7 +15,7 @@ namespace void (*glClearColorFn)(GLfloat r, GLfloat g, GLfloat b, GLfloat a) = NULL; void (*glClearFn)(GLbitfield mask) = NULL; void (*glViewportFn)(GLint x, GLint y, GLsizei w, GLsizei h) = NULL; - void (*glFlushFn)() = NULL; + void (*glFlushFn)() = NULL; /// VAO void (*glGenVertexArraysFn)(GLsizei n, GLuint * ids) = NULL; diff --git a/drape/oglcontextfactory.cpp b/drape/oglcontextfactory.cpp new file mode 100644 index 0000000000..6a9aeb4a42 --- /dev/null +++ b/drape/oglcontextfactory.cpp @@ -0,0 +1,24 @@ +#include "oglcontextfactory.hpp" + + +ThreadSafeFactory::ThreadSafeFactory(OGLContextFactory * factory) + : m_factory(factory) +{ +} + +ThreadSafeFactory::~ThreadSafeFactory() +{ + delete m_factory; +} + +OGLContext *ThreadSafeFactory::getDrawContext() +{ + threads::MutexGuard lock(m_mutex); + return m_factory->getDrawContext(); +} + +OGLContext *ThreadSafeFactory::getResourcesUploadContext() +{ + threads::MutexGuard lock(m_mutex); + return m_factory->getResourcesUploadContext(); +} diff --git a/drape/oglcontextfactory.hpp b/drape/oglcontextfactory.hpp index 6f4a96539f..47730fa54a 100644 --- a/drape/oglcontextfactory.hpp +++ b/drape/oglcontextfactory.hpp @@ -2,6 +2,8 @@ #include "oglcontext.hpp" +#include "../base/mutex.hpp" + class OGLContextFactory { public: @@ -9,3 +11,16 @@ public: virtual OGLContext * getDrawContext() = 0; virtual OGLContext * getResourcesUploadContext() = 0; }; + +class ThreadSafeFactory : public OGLContextFactory +{ +public: + ThreadSafeFactory(OGLContextFactory * factory); + ~ThreadSafeFactory(); + virtual OGLContext * getDrawContext(); + virtual OGLContext * getResourcesUploadContext(); + +private: + OGLContextFactory * m_factory; + threads::Mutex m_mutex; +}; diff --git a/drape_frontend/impl/backend_renderer_impl.cpp b/drape_frontend/impl/backend_renderer_impl.cpp index fcdcb1af99..e223978ae7 100644 --- a/drape_frontend/impl/backend_renderer_impl.cpp +++ b/drape_frontend/impl/backend_renderer_impl.cpp @@ -93,7 +93,10 @@ namespace df { set rectInfoSet; for (size_t i = 0 ; i < tiles.size(); ++i) - rectInfoSet.insert(TileKey(tiles[i].m_x, tiles[i].m_y, tiles[i].m_tileScale)); + { + const Tiler::RectInfo & info = tiles[i]; + rectInfoSet.insert(TileKey(info.m_x, info.m_y, info.m_tileScale)); + } // Find rects that go out from viewport buffer_vector outdatedTasks; diff --git a/drape_frontend/impl/backend_renderer_impl.hpp b/drape_frontend/impl/backend_renderer_impl.hpp index 24536a5289..c0902fc78a 100644 --- a/drape_frontend/impl/backend_renderer_impl.hpp +++ b/drape_frontend/impl/backend_renderer_impl.hpp @@ -51,7 +51,7 @@ namespace df private: ScreenBase m_currentViewport; - set m_taskIndex; + set m_taskIndex; ///////////////////////////////////////// /// Calculate rect for read from MWM diff --git a/drape_frontend/read_mwm_task.hpp b/drape_frontend/read_mwm_task.hpp index c870825ba3..a1560def7f 100644 --- a/drape_frontend/read_mwm_task.hpp +++ b/drape_frontend/read_mwm_task.hpp @@ -12,6 +12,14 @@ namespace df class ReadMWMTask : public threads::IRoutine { public: + struct LessByTileKey + { + bool operator()( const ReadMWMTask * l, const ReadMWMTask * r ) const + { + return l->GetTileInfo().m_key < r->GetTileInfo().m_key; + } + }; + ReadMWMTask(TileKey const & tileKey, MemoryFeatureIndex & index, EngineContext & context); @@ -38,12 +46,4 @@ namespace df dbg::ObjectTracker m_objTracker; #endif }; - - struct ReadMWMTaskLess - { - bool operator()( const ReadMWMTask * l, const ReadMWMTask * r ) const - { - return l->GetTileInfo().m_key < r->GetTileInfo().m_key; - } - }; } diff --git a/drape_frontend/tile_info.hpp b/drape_frontend/tile_info.hpp index 4dc06f0087..a4a4453d16 100644 --- a/drape_frontend/tile_info.hpp +++ b/drape_frontend/tile_info.hpp @@ -36,8 +36,8 @@ namespace df bool operator == (const TileKey & other) const { return m_x == other.m_x && - m_y == other.m_y && - m_zoomLevel == other.m_zoomLevel; + m_y == other.m_y && + m_zoomLevel == other.m_zoomLevel; } int m_x; diff --git a/drape_head/drape_surface.cpp b/drape_head/drape_surface.cpp index e3adbbe396..b095d91302 100644 --- a/drape_head/drape_surface.cpp +++ b/drape_head/drape_surface.cpp @@ -33,7 +33,8 @@ void DrapeSurface::exposeEvent(QExposeEvent *e) { if (m_contextFactory.IsNull()) { - m_contextFactory = MasterPointer(new QtOGLContextFactory(this)); + ThreadSafeFactory * factory = new ThreadSafeFactory(new QtOGLContextFactory(this)); + m_contextFactory = MasterPointer(factory); CreateEngine(); m_drapeEngine->SetAngle(0.0); } diff --git a/drape_head/drape_surface.hpp b/drape_head/drape_surface.hpp index fdad3857ce..1182cb3e65 100644 --- a/drape_head/drape_surface.hpp +++ b/drape_head/drape_surface.hpp @@ -32,6 +32,6 @@ private: int m_timerID; private: - MasterPointer m_contextFactory; - MasterPointer m_drapeEngine; + MasterPointer m_contextFactory; + MasterPointer m_drapeEngine; }; diff --git a/drape_head/qtoglcontextfactory.cpp b/drape_head/qtoglcontextfactory.cpp index 8efbcd5b2c..551e1b23b5 100644 --- a/drape_head/qtoglcontextfactory.cpp +++ b/drape_head/qtoglcontextfactory.cpp @@ -16,20 +16,16 @@ QtOGLContextFactory::~QtOGLContextFactory() OGLContext * QtOGLContextFactory::getDrawContext() { - m_mutex.Lock(); if (m_drawContext == NULL) m_drawContext = new QtOGLContext(m_surface, m_uploadContext); - m_mutex.Unlock(); return m_drawContext; } OGLContext * QtOGLContextFactory::getResourcesUploadContext() { - m_mutex.Lock(); if (m_uploadContext == NULL) m_uploadContext = new QtOGLContext(m_surface, m_drawContext); - m_mutex.Unlock(); return m_uploadContext; } diff --git a/drape_head/qtoglcontextfactory.hpp b/drape_head/qtoglcontextfactory.hpp index 04dbd447de..7fa9228340 100644 --- a/drape_head/qtoglcontextfactory.hpp +++ b/drape_head/qtoglcontextfactory.hpp @@ -1,7 +1,5 @@ #pragma once -#include "../base/mutex.hpp" - #include "../../drape/oglcontextfactory.hpp" #include "qtoglcontext.hpp" @@ -20,6 +18,4 @@ private: QWindow * m_surface; QtOGLContext * m_drawContext; QtOGLContext * m_uploadContext; - - threads::Mutex m_mutex; };