From bea0f2b792c027bd911ea8cd15f7fa496561cfac Mon Sep 17 00:00:00 2001 From: rachytski Date: Tue, 13 Sep 2011 17:52:34 +0300 Subject: [PATCH] renamed pageID into pipelineID --- map/drawer_yg.cpp | 14 +-- map/drawer_yg.hpp | 2 +- yg/area_renderer.cpp | 18 ++-- yg/geometry_batcher.cpp | 218 +++++++++++++++++++++++++--------------- yg/geometry_batcher.hpp | 31 +++--- yg/path_renderer.cpp | 12 +-- yg/resource_style.cpp | 24 ++--- yg/resource_style.hpp | 14 +-- yg/shape_renderer.cpp | 8 +- yg/skin.cpp | 114 ++++++++++++++++----- yg/skin.hpp | 17 ++-- yg/skin_page.cpp | 30 ++++-- yg/skin_page.hpp | 10 +- yg/symbol_element.cpp | 2 +- yg/text_renderer.cpp | 2 +- 15 files changed, 329 insertions(+), 187 deletions(-) diff --git a/map/drawer_yg.cpp b/map/drawer_yg.cpp index b325f13f55..0301d667a7 100644 --- a/map/drawer_yg.cpp +++ b/map/drawer_yg.cpp @@ -54,25 +54,25 @@ namespace struct make_invalid { size_t m_threadID; - uint32_t m_pageIDMask; + uint32_t m_pipelineIDMask; - make_invalid(size_t threadID, uint8_t pageID) - : m_threadID(threadID), m_pageIDMask(pageID << 24) + make_invalid(size_t threadID, uint8_t pipelineID) + : m_threadID(threadID), m_pipelineIDMask(pipelineID << 24) {} void operator() (int, int, drule::BaseRule * p) { - if ((p->GetID(m_threadID) & 0xFF000000) == m_pageIDMask) + if ((p->GetID(m_threadID) & 0xFF000000) == m_pipelineIDMask) p->MakeEmptyID(m_threadID); - if ((p->GetID2(m_threadID) & 0xFF000000) == m_pageIDMask) + if ((p->GetID2(m_threadID) & 0xFF000000) == m_pipelineIDMask) p->MakeEmptyID2(m_threadID); } }; } -void DrawerYG::ClearSkinPage(size_t threadID, uint8_t pageID) +void DrawerYG::ClearSkinPage(size_t threadID, uint8_t pipelineID) { - drule::rules().ForEachRule(make_invalid(threadID, pageID)); + drule::rules().ForEachRule(make_invalid(threadID, pipelineID)); } void DrawerYG::beginFrame() diff --git a/map/drawer_yg.hpp b/map/drawer_yg.hpp index 1a9dc3a602..9c44099bd7 100644 --- a/map/drawer_yg.hpp +++ b/map/drawer_yg.hpp @@ -71,7 +71,7 @@ class DrawerYG shared_ptr m_pScreen; shared_ptr m_pSkin; - static void ClearSkinPage(size_t threadID, uint8_t pageID); + static void ClearSkinPage(size_t threadID, uint8_t pipelineID); protected: void drawSymbol(m2::PointD const & pt, rule_ptr_t pRule, yg::EPosition pos, int depth); diff --git a/yg/area_renderer.cpp b/yg/area_renderer.cpp index 80b006c9c1..6fa493953b 100644 --- a/yg/area_renderer.cpp +++ b/yg/area_renderer.cpp @@ -52,15 +52,15 @@ namespace yg return; } - if (!hasRoom(pointsCount, pointsCount, style->m_pageID)) - flush(style->m_pageID); + if (!hasRoom(pointsCount, pointsCount, style->m_pipelineID)) + flush(style->m_pipelineID); ASSERT_GREATER_OR_EQUAL(pointsCount, 2, ()); float texX = style->m_texRect.minX() + 1.0f; float texY = style->m_texRect.minY() + 1.0f; - skin()->pages()[style->m_pageID]->texture()->mapPixel(texX, texY); + skin()->getPage(style->m_pipelineID)->texture()->mapPixel(texX, texY); size_t pointsLeft = pointsCount; size_t batchOffset = 0; @@ -69,23 +69,23 @@ namespace yg { size_t batchSize = pointsLeft; - if (batchSize > verticesLeft(style->m_pageID)) + if (batchSize > verticesLeft(style->m_pipelineID)) /// Rounding to the boundary of 3 vertices - batchSize = verticesLeft(style->m_pageID) / 3 * 3; + batchSize = verticesLeft(style->m_pipelineID) / 3 * 3; - if (batchSize > indicesLeft(style->m_pageID)) - batchSize = indicesLeft(style->m_pageID) / 3 * 3; + if (batchSize > indicesLeft(style->m_pipelineID)) + batchSize = indicesLeft(style->m_pipelineID) / 3 * 3; bool needToFlush = (batchSize < pointsLeft); m2::PointF texCoord(texX, texY); - addTexturedListStrided(&points[batchOffset], sizeof(m2::PointD), &texCoord, 0, batchSize, depth, style->m_pageID); + addTexturedListStrided(&points[batchOffset], sizeof(m2::PointD), &texCoord, 0, batchSize, depth, style->m_pipelineID); batchOffset += batchSize; pointsLeft -= batchSize; if (needToFlush) - flush(style->m_pageID); + flush(style->m_pipelineID); if (pointsLeft == 0) break; diff --git a/yg/geometry_batcher.cpp b/yg/geometry_batcher.cpp index ddaf7eb667..4808886e03 100644 --- a/yg/geometry_batcher.cpp +++ b/yg/geometry_batcher.cpp @@ -66,11 +66,11 @@ namespace yg GeometryBatcher::~GeometryBatcher() {} - void GeometryBatcher::reset(int pageID) + void GeometryBatcher::reset(int pipelineID) { for (size_t i = 0; i < m_pipelines.size(); ++i) { - if ((pageID == -1) || ((size_t)pageID == i)) + if ((pipelineID == -1) || ((size_t)pipelineID == i)) { m_pipelines[i].m_currentVertex = 0; m_pipelines[i].m_currentIndex = 0; @@ -97,12 +97,52 @@ namespace yg } } + void GeometryBatcher::setAdditionalSkinPages(vector > const & v) + { + if (m_skin != 0) + { + m_skin->setAdditionalPages(v); + int pagesCount = m_skin->getPagesCount(); + m_pipelines.resize(pagesCount + v.size()); + + /// additional pages are fixed + /*m_skin->addOverflowFn(bind(&GeometryBatcher::flush, this, _1), 100); + + m_skin->addClearPageFn(bind(&GeometryBatcher::flush, this, _1), 100); + m_skin->addClearPageFn(bind(&GeometryBatcher::switchTextures, this, _1), 99);*/ + + for (size_t i = 0; i < v.size(); ++i) + { + m_pipelines[i + pagesCount].m_useTinyStorage = m_useTinyStorage; + m_pipelines[i + pagesCount].m_currentVertex = 0; + m_pipelines[i + pagesCount].m_currentIndex = 0; + + m_pipelines[i + pagesCount].m_hasStorage = false; + + m_pipelines[i + pagesCount].m_maxVertices = 0; + m_pipelines[i + pagesCount].m_maxIndices = 0; + + m_pipelines[i + pagesCount].m_vertices = 0; + m_pipelines[i + pagesCount].m_indices = 0; + } + } + } + + void GeometryBatcher::clearAdditionalSkinPages() + { + if (m_skin != 0) + { + m_skin->clearAdditionalPages(); + m_pipelines.resize(m_skin->getPagesCount()); + } + } + void GeometryBatcher::setSkin(shared_ptr skin) { m_skin = skin; if (m_skin != 0) { - m_pipelines.resize(m_skin->pages().size()); + m_pipelines.resize(m_skin->getPagesCount()); m_skin->addOverflowFn(bind(&GeometryBatcher::flush, this, _1), 100); @@ -172,32 +212,38 @@ namespace yg } } + clearAdditionalSkinPages(); + base_t::endFrame(); } - - bool GeometryBatcher::hasRoom(size_t verticesCount, size_t indicesCount, int pageID) const + bool GeometryBatcher::hasRoom(size_t verticesCount, size_t indicesCount, int pipelineID) const { - m_pipelines[pageID].checkStorage(resourceManager(), skin()->pages()[pageID]->usage()); + GeometryPipeline const & pipeline = m_pipelines[pipelineID]; - return ((m_pipelines[pageID].m_currentVertex + verticesCount <= m_pipelines[pageID].m_maxVertices) - && (m_pipelines[pageID].m_currentIndex + indicesCount <= m_pipelines[pageID].m_maxIndices)); + pipeline.checkStorage(resourceManager(), skin()->getPage(pipelineID)->usage()); + + return ((pipeline.m_currentVertex + verticesCount <= pipeline.m_maxVertices) + && (pipeline.m_currentIndex + indicesCount <= pipeline.m_maxIndices)); } - size_t GeometryBatcher::verticesLeft(int pageID) + size_t GeometryBatcher::verticesLeft(int pipelineID) const { - m_pipelines[pageID].checkStorage(resourceManager(), skin()->pages()[pageID]->usage()); + GeometryPipeline const & pipeline = m_pipelines[pipelineID]; - return m_pipelines[pageID].m_maxVertices - m_pipelines[pageID].m_currentVertex; + pipeline.checkStorage(resourceManager(), skin()->getPage(pipelineID)->usage()); + + return pipeline.m_maxVertices - pipeline.m_currentVertex; } - size_t GeometryBatcher::indicesLeft(int pageID) + size_t GeometryBatcher::indicesLeft(int pipelineID) const { - m_pipelines[pageID].checkStorage(resourceManager(), skin()->pages()[pageID]->usage()); - return m_pipelines[pageID].m_maxIndices - m_pipelines[pageID].m_currentIndex; + GeometryPipeline const & pipeline = m_pipelines[pipelineID]; + pipeline.checkStorage(resourceManager(), skin()->getPage(pipelineID)->usage()); + return pipeline.m_maxIndices - pipeline.m_currentIndex; } - void GeometryBatcher::flush(int pageID) + void GeometryBatcher::flush(int pipelineID) { bool renderedData = false; @@ -205,9 +251,9 @@ namespace yg { for (size_t i = m_pipelines.size(); i > 0; --i) { - if ((pageID == -1) || ((i - 1) == (size_t)pageID)) + if ((pipelineID == -1) || ((i - 1) == (size_t)pipelineID)) { - shared_ptr skinPage = m_skin->pages()[i - 1]; + shared_ptr skinPage = m_skin->getPage(i - 1); GeometryPipeline & pipeline = m_pipelines[i - 1]; skinPage->uploadData(); @@ -255,10 +301,9 @@ namespace yg } } - void GeometryBatcher::switchTextures(int pageID) + void GeometryBatcher::switchTextures(int pipelineID) { - m_skin->pages()[pageID]->freeTexture(); -// m_skin->pages()[pageID]->reserveTexture(); + m_skin->getPage(pipelineID)->freeTexture(); } void GeometryBatcher::drawTexturedPolygon( @@ -267,19 +312,19 @@ namespace yg float tx0, float ty0, float tx1, float ty1, float x0, float y0, float x1, float y1, double depth, - int pageID) + int pipelineID) { - if (!hasRoom(4, 6, pageID)) - flush(pageID); + if (!hasRoom(4, 6, pipelineID)) + flush(pipelineID); - m_pipelines[pageID].checkStorage(resourceManager(), skin()->pages()[pageID]->usage()); + m_pipelines[pipelineID].checkStorage(resourceManager(), skin()->getPage(pipelineID)->usage()); float texMinX = tx0; float texMaxX = tx1; float texMinY = ty0; float texMaxY = ty1; - shared_ptr texture = m_skin->pages()[pageID]->texture(); + shared_ptr const & texture = m_skin->getPage(pipelineID)->texture(); texture->mapPixel(texMinX, texMinY); texture->mapPixel(texMaxX, texMaxY); @@ -315,39 +360,40 @@ namespace yg m2::PointF(texMaxX, texMinY) }; - addTexturedFan(coords, texCoords, 4, depth, pageID); + addTexturedFan(coords, texCoords, 4, depth, pipelineID); } - void GeometryBatcher::addTexturedFan(m2::PointF const * coords, m2::PointF const * texCoords, unsigned size, double depth, int pageID) + void GeometryBatcher::addTexturedFan(m2::PointF const * coords, m2::PointF const * texCoords, unsigned size, double depth, int pipelineID) { - if (!hasRoom(size, (size - 2) * 3, pageID)) - flush(pageID); + if (!hasRoom(size, (size - 2) * 3, pipelineID)) + flush(pipelineID); - m_pipelines[pageID].checkStorage(resourceManager(), skin()->pages()[pageID]->usage()); + GeometryPipeline & pipeline = m_pipelines[pipelineID]; + + pipeline.checkStorage(resourceManager(), skin()->getPage(pipelineID)->usage()); ASSERT(size > 2, ()); - size_t vOffset = m_pipelines[pageID].m_currentVertex; - size_t iOffset = m_pipelines[pageID].m_currentIndex; + size_t vOffset = pipeline.m_currentVertex; + size_t iOffset = pipeline.m_currentIndex; for (unsigned i = 0; i < size; ++i) { - m_pipelines[pageID].m_vertices[vOffset + i].pt = coords[i]; - m_pipelines[pageID].m_vertices[vOffset + i].tex = texCoords[i]; - m_pipelines[pageID].m_vertices[vOffset + i].depth = depth; + pipeline.m_vertices[vOffset + i].pt = coords[i]; + pipeline.m_vertices[vOffset + i].tex = texCoords[i]; + pipeline.m_vertices[vOffset + i].depth = depth; } - - m_pipelines[pageID].m_currentVertex += size; + pipeline.m_currentVertex += size; for (size_t j = 0; j < size - 2; ++j) { - m_pipelines[pageID].m_indices[iOffset + j * 3] = vOffset; - m_pipelines[pageID].m_indices[iOffset + j * 3 + 1] = vOffset + j + 1; - m_pipelines[pageID].m_indices[iOffset + j * 3 + 2] = vOffset + j + 2; + pipeline.m_indices[iOffset + j * 3] = vOffset; + pipeline.m_indices[iOffset + j * 3 + 1] = vOffset + j + 1; + pipeline.m_indices[iOffset + j * 3 + 2] = vOffset + j + 2; } - m_pipelines[pageID].m_currentIndex += (size - 2) * 3; + pipeline.m_currentIndex += (size - 2) * 3; } void GeometryBatcher::addTexturedStrip( @@ -355,10 +401,10 @@ namespace yg m2::PointF const * texCoords, unsigned size, double depth, - int pageID + int pipelineID ) { - addTexturedStripStrided(coords, sizeof(m2::PointF), texCoords, sizeof(m2::PointF), size, depth, pageID); + addTexturedStripStrided(coords, sizeof(m2::PointF), texCoords, sizeof(m2::PointF), size, depth, pipelineID); } void GeometryBatcher::addTexturedStripStrided( @@ -368,43 +414,45 @@ namespace yg size_t texCoordsStride, unsigned size, double depth, - int pageID) + int pipelineID) { - if (!hasRoom(size, (size - 2) * 3, pageID)) - flush(pageID); + if (!hasRoom(size, (size - 2) * 3, pipelineID)) + flush(pipelineID); - m_pipelines[pageID].checkStorage(resourceManager(), skin()->pages()[pageID]->usage()); + GeometryPipeline & pipeline = m_pipelines[pipelineID]; + + pipeline.checkStorage(resourceManager(), skin()->getPage(pipelineID)->usage()); ASSERT(size > 2, ()); - size_t vOffset = m_pipelines[pageID].m_currentVertex; - size_t iOffset = m_pipelines[pageID].m_currentIndex; + size_t vOffset = pipeline.m_currentVertex; + size_t iOffset = pipeline.m_currentIndex; for (unsigned i = 0; i < size; ++i) { - m_pipelines[pageID].m_vertices[vOffset + i].pt = *coords; - m_pipelines[pageID].m_vertices[vOffset + i].tex = *texCoords; - m_pipelines[pageID].m_vertices[vOffset + i].depth = depth; + pipeline.m_vertices[vOffset + i].pt = *coords; + pipeline.m_vertices[vOffset + i].tex = *texCoords; + pipeline.m_vertices[vOffset + i].depth = depth; coords = reinterpret_cast(reinterpret_cast(coords) + coordsStride); texCoords = reinterpret_cast(reinterpret_cast(texCoords) + texCoordsStride); } - m_pipelines[pageID].m_currentVertex += size; + pipeline.m_currentVertex += size; size_t oldIdx1 = vOffset; size_t oldIdx2 = vOffset + 1; for (size_t j = 0; j < size - 2; ++j) { - m_pipelines[pageID].m_indices[iOffset + j * 3] = oldIdx1; - m_pipelines[pageID].m_indices[iOffset + j * 3 + 1] = oldIdx2; - m_pipelines[pageID].m_indices[iOffset + j * 3 + 2] = vOffset + j + 2; + pipeline.m_indices[iOffset + j * 3] = oldIdx1; + pipeline.m_indices[iOffset + j * 3 + 1] = oldIdx2; + pipeline.m_indices[iOffset + j * 3 + 2] = vOffset + j + 2; oldIdx1 = oldIdx2; oldIdx2 = vOffset + j + 2; } - m_pipelines[pageID].m_currentIndex += (size - 2) * 3; + pipeline.m_currentIndex += (size - 2) * 3; } void GeometryBatcher::addTexturedListStrided( @@ -414,33 +462,35 @@ namespace yg size_t texCoordsStride, unsigned size, double depth, - int pageID) + int pipelineID) { - if (!hasRoom(size, size, pageID)) - flush(pageID); + if (!hasRoom(size, size, pipelineID)) + flush(pipelineID); - m_pipelines[pageID].checkStorage(resourceManager(), skin()->pages()[pageID]->usage()); + GeometryPipeline & pipeline = m_pipelines[pipelineID]; + + pipeline.checkStorage(resourceManager(), skin()->getPage(pipelineID)->usage()); ASSERT(size > 2, ()); - size_t vOffset = m_pipelines[pageID].m_currentVertex; - size_t iOffset = m_pipelines[pageID].m_currentIndex; + size_t vOffset = pipeline.m_currentVertex; + size_t iOffset = pipeline.m_currentIndex; for (size_t i = 0; i < size; ++i) { - m_pipelines[pageID].m_vertices[vOffset + i].pt = m2::PointF(coords->x, coords->y); - m_pipelines[pageID].m_vertices[vOffset + i].tex = *texCoords; - m_pipelines[pageID].m_vertices[vOffset + i].depth = depth; + pipeline.m_vertices[vOffset + i].pt = m2::PointF(coords->x, coords->y); + pipeline.m_vertices[vOffset + i].tex = *texCoords; + pipeline.m_vertices[vOffset + i].depth = depth; coords = reinterpret_cast(reinterpret_cast(coords) + coordsStride); texCoords = reinterpret_cast(reinterpret_cast(texCoords) + texCoordsStride); } - m_pipelines[pageID].m_currentVertex += size; + pipeline.m_currentVertex += size; for (size_t i = 0; i < size; ++i) - m_pipelines[pageID].m_indices[iOffset + i] = vOffset + i; + pipeline.m_indices[iOffset + i] = vOffset + i; - m_pipelines[pageID].m_currentIndex += size; + pipeline.m_currentIndex += size; } @@ -451,38 +501,40 @@ namespace yg size_t texCoordsStride, unsigned size, double depth, - int pageID) + int pipelineID) { - if (!hasRoom(size, size, pageID)) - flush(pageID); + if (!hasRoom(size, size, pipelineID)) + flush(pipelineID); - m_pipelines[pageID].checkStorage(resourceManager(), skin()->pages()[pageID]->usage()); + GeometryPipeline & pipeline = m_pipelines[pipelineID]; + + pipeline.checkStorage(resourceManager(), skin()->getPage(pipelineID)->usage()); ASSERT(size > 2, ()); - size_t vOffset = m_pipelines[pageID].m_currentVertex; - size_t iOffset = m_pipelines[pageID].m_currentIndex; + size_t vOffset = pipeline.m_currentVertex; + size_t iOffset = pipeline.m_currentIndex; for (size_t i = 0; i < size; ++i) { - m_pipelines[pageID].m_vertices[vOffset + i].pt = *coords; - m_pipelines[pageID].m_vertices[vOffset + i].tex = *texCoords; - m_pipelines[pageID].m_vertices[vOffset + i].depth = depth; + pipeline.m_vertices[vOffset + i].pt = *coords; + pipeline.m_vertices[vOffset + i].tex = *texCoords; + pipeline.m_vertices[vOffset + i].depth = depth; coords = reinterpret_cast(reinterpret_cast(coords) + coordsStride); texCoords = reinterpret_cast(reinterpret_cast(texCoords) + texCoordsStride); } - m_pipelines[pageID].m_currentVertex += size; + pipeline.m_currentVertex += size; for (size_t i = 0; i < size; ++i) - m_pipelines[pageID].m_indices[iOffset + i] = vOffset + i; + pipeline.m_indices[iOffset + i] = vOffset + i; - m_pipelines[pageID].m_currentIndex += size; + pipeline.m_currentIndex += size; } - void GeometryBatcher::addTexturedList(m2::PointF const * coords, m2::PointF const * texCoords, unsigned size, double depth, int pageID) + void GeometryBatcher::addTexturedList(m2::PointF const * coords, m2::PointF const * texCoords, unsigned size, double depth, int pipelineID) { - addTexturedListStrided(coords, sizeof(m2::PointF), texCoords, sizeof(m2::PointF), size, depth, pageID); + addTexturedListStrided(coords, sizeof(m2::PointF), texCoords, sizeof(m2::PointF), size, depth, pipelineID); } void GeometryBatcher::enableClipRect(bool flag) diff --git a/yg/geometry_batcher.hpp b/yg/geometry_batcher.hpp index 2505e1447a..3330a1a4c9 100644 --- a/yg/geometry_batcher.hpp +++ b/yg/geometry_batcher.hpp @@ -67,14 +67,14 @@ namespace yg size_t verticesLeft(); size_t indicesLeft(); - void checkStorage(shared_ptr const & resourceManager, SkinPage::EUsage usage) const; + void checkStorage(shared_ptr const & resourceManager, yg::SkinPage::EUsage usage) const; }; vector m_pipelines; - void reset(int pageID); + void reset(int pipelineID); - void switchTextures(int pageID); + void switchTextures(int pipelineID); /// Apply all states needed for rendering a batch of geometry. void applyStates(); @@ -89,10 +89,10 @@ namespace yg public: /// INTERNAL API! USE WITH CAUTION - void flush(int pageID); - bool hasRoom(size_t verticesCount, size_t indicesCount, int pageID) const; - size_t verticesLeft(int pageID); - size_t indicesLeft(int pageID); + void flush(int pipelineID); + bool hasRoom(size_t verticesCount, size_t indicesCount, int pipelineID) const; + size_t verticesLeft(int pipelineID) const; + size_t indicesLeft(int pipelineID) const; struct Params : public base_t::Params { @@ -128,7 +128,7 @@ namespace yg m2::PointF const * texCoords, unsigned size, double depth, - int pageID); + int pipelineID); void addTexturedStripStrided(m2::PointF const * coords, size_t coordsStride, @@ -136,13 +136,13 @@ namespace yg size_t texCoordsStride, unsigned size, double depth, - int pageID); + int pipelineID); void addTexturedStrip(m2::PointF const * coords, m2::PointF const * texCoords, unsigned size, double depth, - int pageID); + int pipelineID); void addTexturedListStrided(m2::PointD const * coords, size_t coordsStride, @@ -150,7 +150,7 @@ namespace yg size_t texCoordsStride, unsigned size, double depth, - int pageID); + int pipelineID); void addTexturedListStrided(m2::PointF const * coords, size_t coordsStride, @@ -158,13 +158,13 @@ namespace yg size_t texCoordsStride, unsigned size, double depth, - int pageID); + int pipelineID); void addTexturedList(m2::PointF const * coords, m2::PointF const * texCoords, unsigned size, double depth, - int pageID); + int pipelineID); int aaShift() const; @@ -177,11 +177,14 @@ namespace yg float tx0, float ty0, float tx1, float ty1, float x0, float y0, float x1, float y1, double depth, - int pageID); + int pipelineID); void memoryWarning(); void enterBackground(); void enterForeground(); + + void setAdditionalSkinPages(vector > const & v); + void clearAdditionalSkinPages(); }; } } diff --git a/yg/path_renderer.cpp b/yg/path_renderer.cpp index b396a2556d..711c1cdde6 100644 --- a/yg/path_renderer.cpp +++ b/yg/path_renderer.cpp @@ -114,7 +114,7 @@ namespace yg m2::PointF(rawTileEndPt.x + fNorm.x, rawTileEndPt.y + fNorm.y) }; - shared_ptr texture = skin()->pages()[lineStyle->m_pageID]->texture(); + shared_ptr texture = skin()->getPage(lineStyle->m_pipelineID)->texture(); m2::PointF texCoords[4] = { @@ -124,7 +124,7 @@ namespace yg texture->mapPixel(m2::PointF(texMaxX, texMinY)) }; - addTexturedFan(coords, texCoords, 4, depth, lineStyle->m_pageID); + addTexturedFan(coords, texCoords, 4, depth, lineStyle->m_pipelineID); segLenRemain -= rawTileLen; @@ -160,7 +160,7 @@ namespace yg startVec = norm; } - shared_ptr texture = skin()->pages()[lineStyle->m_pageID]->texture(); + shared_ptr texture = skin()->getPage(lineStyle->m_pipelineID)->texture(); m2::PointF joinSegTex[3] = { @@ -183,7 +183,7 @@ namespace yg m2::PointF(points[i + 1] + prevStartVec * geomHalfWidth) }; - addTexturedFan(joinSeg, joinSegTex, 3, depth, lineStyle->m_pageID); + addTexturedFan(joinSeg, joinSegTex, 3, depth, lineStyle->m_pipelineID); prevStartVec = startVec; } @@ -237,7 +237,7 @@ namespace yg nextPt + fDir - fNorm }; - shared_ptr texture = skin()->pages()[lineStyle->m_pageID]->texture(); + shared_ptr texture = skin()->getPage(lineStyle->m_pipelineID)->texture(); m2::PointF texCoords[8] = { @@ -251,7 +251,7 @@ namespace yg texture->mapPixel(m2::PointF(texMaxX, texMaxY)) }; - addTexturedStrip(coords, texCoords, 8, depth, lineStyle->m_pageID); + addTexturedStrip(coords, texCoords, 8, depth, lineStyle->m_pipelineID); } } diff --git a/yg/resource_style.cpp b/yg/resource_style.cpp index 20e75d903d..bfff22e47d 100644 --- a/yg/resource_style.cpp +++ b/yg/resource_style.cpp @@ -9,23 +9,23 @@ namespace yg ResourceStyle::ResourceStyle( m2::RectU const & texRect, - int pageID + int pipelineID ) : m_cat(EGenericStyle), m_texRect(texRect), - m_pageID(pageID) + m_pipelineID(pipelineID) {} ResourceStyle::ResourceStyle( Category cat, m2::RectU const & texRect, - int pageID) + int pipelineID) : m_cat(cat), m_texRect(texRect), - m_pageID(pageID) + m_pipelineID(pipelineID) {} - LineStyle::LineStyle(bool isWrapped, m2::RectU const & texRect, int pageID, yg::PenInfo const & penInfo) : - ResourceStyle(ELineStyle, texRect, pageID), + LineStyle::LineStyle(bool isWrapped, m2::RectU const & texRect, int pipelineID, yg::PenInfo const & penInfo) : + ResourceStyle(ELineStyle, texRect, pipelineID), m_isWrapped(isWrapped), m_isSolid(penInfo.m_isSolid), m_penInfo(penInfo) @@ -64,15 +64,15 @@ namespace yg return m_texRect.SizeY() - 4; } - CharStyle::CharStyle(m2::RectU const & texRect, int pageID, int8_t xOffset, int8_t yOffset, int8_t xAdvance) - : ResourceStyle(ECharStyle, texRect, pageID), m_xOffset(xOffset), m_yOffset(yOffset), m_xAdvance(xAdvance) + CharStyle::CharStyle(m2::RectU const & texRect, int pipelineID, int8_t xOffset, int8_t yOffset, int8_t xAdvance) + : ResourceStyle(ECharStyle, texRect, pipelineID), m_xOffset(xOffset), m_yOffset(yOffset), m_xAdvance(xAdvance) {} - PointStyle::PointStyle(m2::RectU const & texRect, int pageID, string const & styleName) - : ResourceStyle(EPointStyle, texRect, pageID), m_styleName(styleName) + PointStyle::PointStyle(m2::RectU const & texRect, int pipelineID, string const & styleName) + : ResourceStyle(EPointStyle, texRect, pipelineID), m_styleName(styleName) {} - GenericStyle::GenericStyle(m2::RectU const & texRect, int pageID) - : ResourceStyle(EGenericStyle, texRect, pageID) + GenericStyle::GenericStyle(m2::RectU const & texRect, int pipelineID) + : ResourceStyle(EGenericStyle, texRect, pipelineID) {} } diff --git a/yg/resource_style.hpp b/yg/resource_style.hpp index d80d368c93..d91e097266 100644 --- a/yg/resource_style.hpp +++ b/yg/resource_style.hpp @@ -17,13 +17,13 @@ namespace yg Category m_cat; m2::RectU m_texRect; - int m_pageID; + int m_pipelineID; ResourceStyle(); - ResourceStyle(m2::RectU const & texRect, int pageID); + ResourceStyle(m2::RectU const & texRect, int pipelineID); protected: - ResourceStyle(Category cat, m2::RectU const & texRect, int pageID); + ResourceStyle(Category cat, m2::RectU const & texRect, int pipelineID); }; struct LineStyle : public ResourceStyle @@ -33,7 +33,7 @@ namespace yg yg::PenInfo m_penInfo; m2::PointU m_centerColorPixel; m2::PointU m_borderColorPixel; - LineStyle(bool isWrapped, m2::RectU const & texRect, int pageID, yg::PenInfo const & penInfo); + LineStyle(bool isWrapped, m2::RectU const & texRect, int pipelineID, yg::PenInfo const & penInfo); /// with antialiasing zones double geometryTileLen() const; @@ -51,17 +51,17 @@ namespace yg int8_t m_yOffset; int8_t m_xAdvance; - CharStyle(m2::RectU const & texRect, int pageID, int8_t xOffset, int8_t yOffset, int8_t xAdvance); + CharStyle(m2::RectU const & texRect, int pipelineID, int8_t xOffset, int8_t yOffset, int8_t xAdvance); }; struct PointStyle : public ResourceStyle { string m_styleName; - PointStyle(m2::RectU const & texRect, int pageID, string const & styleName); + PointStyle(m2::RectU const & texRect, int pipelineID, string const & styleName); }; struct GenericStyle : public ResourceStyle { - GenericStyle(m2::RectU const & texRect, int pageID); + GenericStyle(m2::RectU const & texRect, int pipelineID); }; } diff --git a/yg/shape_renderer.cpp b/yg/shape_renderer.cpp index 878d603e66..79c8759938 100644 --- a/yg/shape_renderer.cpp +++ b/yg/shape_renderer.cpp @@ -97,7 +97,7 @@ namespace yg for (int i = 0; i < 4; ++i) rectPtsF[i] = m2::PointF(rectPts[i].x, rectPts[i].y); - m2::PointF texPt = skin()->pages()[style->m_pageID]->texture()->mapPixel(m2::RectF(style->m_texRect).Center()); + m2::PointF texPt = skin()->getPage(style->m_pipelineID)->texture()->mapPixel(m2::RectF(style->m_texRect).Center()); addTexturedStripStrided( rectPtsF, @@ -106,7 +106,7 @@ namespace yg 0, 4, depth, - style->m_pageID); + style->m_pipelineID); } void ShapeRenderer::drawRectangle(m2::RectD const & r, yg::Color const & c, double depth) @@ -126,7 +126,7 @@ namespace yg m2::PointD(r.maxX(), r.maxY()) }; - m2::PointF texPt = skin()->pages()[style->m_pageID]->texture()->mapPixel(m2::RectF(style->m_texRect).Center()); + m2::PointF texPt = skin()->getPage(style->m_pipelineID)->texture()->mapPixel(m2::RectF(style->m_texRect).Center()); addTexturedStripStrided( rectPts, @@ -135,7 +135,7 @@ namespace yg 0, 4, depth, - style->m_pageID + style->m_pipelineID ); } } diff --git a/yg/skin.cpp b/yg/skin.cpp index 519ef913ee..ff1cdb7d52 100644 --- a/yg/skin.cpp +++ b/yg/skin.cpp @@ -43,9 +43,9 @@ namespace yg for (int i = 0; i < count; ++i) { - uint8_t pageID = (uint8_t)m_pages.size(); - m_pages.push_back(make_shared_ptr(new SkinPage(m_resourceManager, SkinPage::EFontsUsage, pageID))); - m_pages.back()->addOverflowFn(bind(&Skin::onTextOverflow, this, pageID), 0); + uint8_t pipelineID = (uint8_t)m_pages.size(); + m_pages.push_back(make_shared_ptr(new SkinPage(m_resourceManager, SkinPage::EFontsUsage, pipelineID))); + m_pages.back()->addOverflowFn(bind(&Skin::onTextOverflow, this, pipelineID), 0); } } @@ -57,9 +57,9 @@ namespace yg for (int i = 0; i < count; ++i) { - uint8_t pageID = (uint8_t)m_pages.size(); - m_pages.push_back(make_shared_ptr(new SkinPage(m_resourceManager, SkinPage::EDynamicUsage, pageID))); - m_pages.back()->addOverflowFn(bind(&Skin::onDynamicOverflow, this, pageID), 0); + uint8_t pipelineID = (uint8_t)m_pages.size(); + m_pages.push_back(make_shared_ptr(new SkinPage(m_resourceManager, SkinPage::EDynamicUsage, pipelineID))); + m_pages.back()->addOverflowFn(bind(&Skin::onDynamicOverflow, this, pipelineID), 0); } } @@ -68,22 +68,25 @@ namespace yg pair Skin::unpackID(uint32_t id) const { - uint8_t pageID = (id & 0xFF000000) >> 24; + uint8_t pipelineID = (id & 0xFF000000) >> 24; uint32_t h = (id & 0x00FFFFFF); - return make_pair(pageID, h); + return make_pair(pipelineID, h); } - uint32_t Skin::packID(uint8_t pageID, uint32_t handle) const + uint32_t Skin::packID(uint8_t pipelineID, uint32_t handle) const { - uint32_t pageIDMask = (uint32_t)pageID << 24; + uint32_t pipelineIDMask = (uint32_t)pipelineID << 24; uint32_t h = (handle & 0x00FFFFFF); - return (uint32_t)(pageIDMask | h); + return (uint32_t)(pipelineIDMask | h); } ResourceStyle const * Skin::fromID(uint32_t id) { id_pair_t p = unpackID(id); - return m_pages[p.first]->fromID(p.second); + if (p.first < m_pages.size()) + return m_pages[p.first]->fromID(p.second); + else + return m_additionalPages[p.first - m_pages.size()]->fromID(p.second); } uint32_t Skin::mapSymbol(char const * symbolName) @@ -94,6 +97,14 @@ namespace yg if (res != invalidPageHandle()) return packID(i, res); } + + for (uint8_t i = 0; i < m_additionalPages.size(); ++i) + { + uint32_t res = m_additionalPages[i]->findSymbol(symbolName); + if (res != invalidPageHandle()) + return packID(i + m_pages.size(), res); + } + return invalidHandle(); } @@ -108,6 +119,13 @@ namespace yg return packID(i, res); } + for (uint8_t i = 0; i < m_additionalPages.size(); ++i) + { + res = m_additionalPages[i]->findColor(c); + if (res != invalidPageHandle()) + return packID(i + m_pages.size(), res); + } + if (!m_pages[m_currentDynamicPage]->hasRoom(c)) changeCurrentDynamicPage(); @@ -117,6 +135,7 @@ namespace yg uint32_t Skin::mapPenInfo(PenInfo const & penInfo) { uint32_t res = invalidPageHandle(); + for (uint8_t i = 0; i < m_pages.size(); ++i) { res = m_pages[i]->findPenInfo(penInfo); @@ -124,6 +143,13 @@ namespace yg return packID(i, res); } + for (uint8_t i = 0; i < m_additionalPages.size(); ++i) + { + res = m_additionalPages[i]->findPenInfo(penInfo); + if (res != invalidPageHandle()) + return packID(i + m_pages.size(), res); + } + if (!m_pages[m_currentDynamicPage]->hasRoom(penInfo)) changeCurrentDynamicPage(); @@ -133,6 +159,7 @@ namespace yg uint32_t Skin::mapCircleInfo(CircleInfo const & circleInfo) { uint32_t res = invalidPageHandle(); + for (uint8_t i = 0; i < m_pages.size(); ++i) { res = m_pages[i]->findCircleInfo(circleInfo); @@ -140,6 +167,13 @@ namespace yg return packID(i, res); } + for (uint8_t i = 0; i < m_additionalPages.size(); ++i) + { + res = m_additionalPages[i]->findCircleInfo(circleInfo); + if (res != invalidPageHandle()) + return packID(i, res); + } + if (!m_pages[m_currentDynamicPage]->hasRoom(circleInfo)) changeCurrentDynamicPage(); @@ -190,15 +224,35 @@ namespace yg return packID(i, res); } + for (uint8_t i = 0; i < m_additionalPages.size(); ++i) + { + res = m_additionalPages[i]->findGlyph(gk); + if (res != invalidPageHandle()) + return packID(i + m_pages.size(), res); + } + if (!m_pages[m_currentTextPage]->hasRoom(gk, glyphCache)) changeCurrentTextPage(); return packID(m_currentTextPage, m_pages[m_currentTextPage]->mapGlyph(gk, glyphCache)); } - Skin::TSkinPages const & Skin::pages() const +/* Skin::TSkinPages const & Skin::pages() const { return m_pages; + }*/ + + shared_ptr const & Skin::getPage(int i) const + { + if (i < m_pages.size()) + return m_pages[i]; + else + return m_additionalPages[i - m_pages.size()]; + } + + size_t Skin::getPagesCount() const + { + return m_pages.size(); } void Skin::addClearPageFn(clearPageFn fn, int priority) @@ -206,12 +260,12 @@ namespace yg m_clearPageFns.push(std::pair(priority, fn)); } - void Skin::callClearPageFns(uint8_t pageID) + void Skin::callClearPageFns(uint8_t pipelineID) { clearPageFns handlersCopy = m_clearPageFns; while (!handlersCopy.empty()) { - handlersCopy.top().second(pageID); + handlersCopy.top().second(pipelineID); handlersCopy.pop(); } } @@ -221,33 +275,33 @@ namespace yg m_overflowFns.push(std::pair(priority, fn)); } - void Skin::callOverflowFns(uint8_t pageID) + void Skin::callOverflowFns(uint8_t pipelineID) { overflowFns handlersCopy = m_overflowFns; while (!handlersCopy.empty()) { - handlersCopy.top().second(pageID); + handlersCopy.top().second(pipelineID); handlersCopy.pop(); } } - void Skin::clearPageHandles(uint8_t pageID) + void Skin::clearPageHandles(uint8_t pipelineID) { - m_pages[pageID]->clearHandles(); + getPage(pipelineID)->clearHandles(); } /// This function is set to perform as a callback on texture or handles overflow /// BUT! Never called on texture overflow, as this situation /// is explicitly checked in the mapXXX() functions. - void Skin::onDynamicOverflow(uint8_t pageID) + void Skin::onDynamicOverflow(uint8_t pipelineID) { - LOG(LINFO, ("DynamicPage switching, pageID=", (uint32_t)pageID)); + LOG(LINFO, ("DynamicPage switching, pipelineID=", (uint32_t)pipelineID)); changeCurrentDynamicPage(); } - void Skin::onTextOverflow(uint8_t pageID) + void Skin::onTextOverflow(uint8_t pipelineID) { - LOG(LINFO, ("TextPage switching, pageID=", (uint32_t)pageID)); + LOG(LINFO, ("TextPage switching, pipelineID=", (uint32_t)pipelineID)); changeCurrentTextPage(); } @@ -313,4 +367,18 @@ namespace yg void Skin::enterForeground() { } + + void Skin::setAdditionalPages(vector > const & pages) + { + m_additionalPages = pages; + for (unsigned i = 0; i < pages.size(); ++i) + m_additionalPages[i]->setPipelineID(i + m_pages.size()); + } + + void Skin::clearAdditionalPages() + { + for (unsigned i = 0; i < m_additionalPages.size(); ++i) + m_additionalPages[i]->freeTexture(); + m_additionalPages.clear(); + } } diff --git a/yg/skin.hpp b/yg/skin.hpp index 415ab8e1e8..182d1abbe9 100644 --- a/yg/skin.hpp +++ b/yg/skin.hpp @@ -46,6 +46,7 @@ namespace yg private: TSkinPages m_pages; + TSkinPages m_additionalPages; uint8_t m_startDynamicPage; uint8_t m_currentDynamicPage; @@ -85,7 +86,7 @@ namespace yg > clearPageFns; clearPageFns m_clearPageFns; - void callClearPageFns(uint8_t pageID); + void callClearPageFns(uint8_t pipelineID); typedef priority_queue, vector >, @@ -93,11 +94,11 @@ namespace yg > overflowFns; overflowFns m_overflowFns; - void callOverflowFns(uint8_t pageID); + void callOverflowFns(uint8_t pipelineID); - void clearPageHandles(uint8_t pageID); - void onDynamicOverflow(uint8_t pageID); - void onTextOverflow(uint8_t pageID); + void clearPageHandles(uint8_t pipelineID); + void onDynamicOverflow(uint8_t pipelineID); + void onTextOverflow(uint8_t pipelineID); void changeCurrentDynamicPage(); void changeCurrentTextPage(); @@ -138,7 +139,8 @@ namespace yg FontInfo const & getFont(int size) const; - TSkinPages const & pages() const; + shared_ptr const & getPage(int i) const; + size_t getPagesCount() const; uint32_t invalidHandle() const; uint32_t invalidPageHandle() const; @@ -146,6 +148,9 @@ namespace yg uint8_t currentTextPage() const; uint8_t currentDynamicPage() const; + void setAdditionalPages(vector > const & pages); + void clearAdditionalPages(); + void memoryWarning(); void enterBackground(); void enterForeground(); diff --git a/yg/skin_page.cpp b/yg/skin_page.cpp index 539a5df013..18ae9d71da 100644 --- a/yg/skin_page.cpp +++ b/yg/skin_page.cpp @@ -91,12 +91,13 @@ namespace yg return it->second.first.get(); } + SkinPage::SkinPage(shared_ptr const & resourceManager, char const * name, - uint8_t pageID) + uint8_t pipelineID) : m_texture(resourceManager->getTexture(name)), m_usage(EStaticUsage), - m_pageID(pageID) + m_pipelineID(pipelineID) { m_packer = m2::Packer(m_texture->width(), m_texture->height(), 0x00FFFFFF - 1); } @@ -104,10 +105,10 @@ namespace yg SkinPage::SkinPage(shared_ptr const & resourceManager, EUsage usage, - uint8_t pageID) + uint8_t pipelineID) : m_resourceManager(resourceManager), m_usage(usage), - m_pageID(pageID) + m_pipelineID(pipelineID) { createPacker(); /// clear handles will be called only upon handles overflow, @@ -169,6 +170,7 @@ namespace yg uint32_t SkinPage::mapColor(yg::Color const & c) { uint32_t foundHandle = findColor(c); + if (foundHandle != m_packer.invalidHandle()) return foundHandle; @@ -179,7 +181,7 @@ namespace yg m_colorUploadCommands.push_back(ColorUploadCmd(c, texRect)); m_colorMap[c] = h; - m_styles[h] = shared_ptr(new GenericStyle(texRect, m_pageID)); + m_styles[h] = shared_ptr(new GenericStyle(texRect, m_pipelineID)); return h; } @@ -224,7 +226,7 @@ namespace yg m_styles[handle] = boost::shared_ptr( new CharStyle(texRect, - m_pageID, + m_pipelineID, gi->m_metrics.m_xOffset, gi->m_metrics.m_yOffset, gi->m_metrics.m_xAdvance)); @@ -264,7 +266,7 @@ namespace yg m_circleUploadCommands.push_back(CircleUploadCmd(circleInfo, texRect)); m_circleInfoMap[circleInfo] = handle; - m_styles[handle] = shared_ptr(new GenericStyle(texRect, m_pageID) ); + m_styles[handle] = shared_ptr(new GenericStyle(texRect, m_pipelineID) ); return m_circleInfoMap[circleInfo]; } @@ -302,7 +304,7 @@ namespace yg m_styles[handle] = boost::shared_ptr( new LineStyle(false, texRect, - m_pageID, + m_pipelineID, penInfo)); return m_penInfoMap[penInfo]; @@ -727,6 +729,13 @@ namespace yg reserveTexture(); } + void SkinPage::setPipelineID(uint8_t pipelineID) + { + m_pipelineID = pipelineID; + for (TStyles::iterator it = m_styles.begin(); it != m_styles.end(); ++it) + it->second->m_pipelineID = pipelineID; + } + void SkinPage::uploadData() { if ((m_usage != EStaticUsage) && (hasData())) @@ -815,4 +824,9 @@ namespace yg LOG(LINFO, ("createPacker call for invalid usage param")); } } + + shared_ptr const & SkinPage::resourceManager() const + { + return m_resourceManager; + } } diff --git a/yg/skin_page.hpp b/yg/skin_page.hpp index f05f953ec4..3cc5d20493 100644 --- a/yg/skin_page.hpp +++ b/yg/skin_page.hpp @@ -120,7 +120,7 @@ namespace yg TFonts m_fonts; EUsage m_usage; - uint32_t m_pageID; + uint32_t m_pipelineID; bool m_fillAlpha; @@ -143,18 +143,17 @@ namespace yg void uploadData(); void checkTexture() const; - - SkinPage(); + void setPipelineID(uint8_t pipelineID); /// creation of a static page SkinPage(shared_ptr const & resourceManager, char const * name, - uint8_t pageID); + uint8_t pipelineID); /// creation of a dynamic page SkinPage(shared_ptr const & resourceManager, EUsage usage, - uint8_t pageID); + uint8_t pipelineID); void reserveTexture() const; void freeTexture(); @@ -181,6 +180,7 @@ namespace yg ResourceStyle * fromID(uint32_t idx) const; EUsage usage() const; + shared_ptr const & resourceManager() const; void addOverflowFn(overflowFn fn, int priority); diff --git a/yg/symbol_element.cpp b/yg/symbol_element.cpp index 2b750b8c68..3480f9645a 100644 --- a/yg/symbol_element.cpp +++ b/yg/symbol_element.cpp @@ -65,7 +65,7 @@ namespace yg texRect.minX(), texRect.minY(), texRect.maxX(), texRect.maxY(), posPt.x, posPt.y, posPt.x + texRect.SizeX(), posPt.y + texRect.SizeY(), depth(), - m_style->m_pageID); + m_style->m_pipelineID); } uint32_t SymbolElement::styleID() const diff --git a/yg/text_renderer.cpp b/yg/text_renderer.cpp index 43bab4555e..d885876b1b 100644 --- a/yg/text_renderer.cpp +++ b/yg/text_renderer.cpp @@ -42,7 +42,7 @@ namespace yg p->m_texRect.maxY() - 1, x0, y0, x1, y1, depth, - p->m_pageID); + p->m_pipelineID); } GlyphCache * TextRenderer::glyphCache() const