From e60390c9c1536a39073494e43d5e3669fb6576fa Mon Sep 17 00:00:00 2001 From: "r.kuznetsov" Date: Fri, 4 Dec 2015 11:22:57 +0300 Subject: [PATCH] Fixed font texture unit tests --- drape/drape_tests/font_texture_tests.cpp | 24 +++++++++++++----------- drape/font_texture.cpp | 6 ++++++ drape/font_texture.hpp | 5 ++++- 3 files changed, 23 insertions(+), 12 deletions(-) diff --git a/drape/drape_tests/font_texture_tests.cpp b/drape/drape_tests/font_texture_tests.cpp index a162a7c5f9..66af9a3e54 100644 --- a/drape/drape_tests/font_texture_tests.cpp +++ b/drape/drape_tests/font_texture_tests.cpp @@ -96,10 +96,11 @@ UNIT_TEST(UploadingGlyphs) GlyphManager mng(args); DummyGlyphIndex index(m2::PointU(128, 128), make_ref(&mng)); - index.MapResource(GlyphKey(0x58)); - index.MapResource(GlyphKey(0x59)); - index.MapResource(GlyphKey(0x61)); - while(index.HasAsyncRoutines()); + size_t count = 1; // invalid symbol glyph has mapped internally. + count += (index.MapResource(GlyphKey(0x58)) != nullptr) ? 1 : 0; + count += (index.MapResource(GlyphKey(0x59)) != nullptr) ? 1 : 0; + count += (index.MapResource(GlyphKey(0x61)) != nullptr) ? 1 : 0; + while (index.GetPendingNodesCount() < count); Texture::Params p; p.m_allocator = GetDefaultAllocator(); @@ -111,13 +112,14 @@ UNIT_TEST(UploadingGlyphs) EXPECTGL(glTexSubImage2D(_, _, _, _, _, _, _)).WillOnce(Invoke(&r, &UploadedRender::glMemoryToQImage)); index.UploadResources(make_ref(&tex)); - index.MapResource(GlyphKey(0x68)); - index.MapResource(GlyphKey(0x30)); - index.MapResource(GlyphKey(0x62)); - index.MapResource(GlyphKey(0x65)); - index.MapResource(GlyphKey(0x400)); - index.MapResource(GlyphKey(0x401)); - while(index.HasAsyncRoutines()); + count = 0; + count += (index.MapResource(GlyphKey(0x68)) != nullptr) ? 1 : 0; + count += (index.MapResource(GlyphKey(0x30)) != nullptr) ? 1 : 0; + count += (index.MapResource(GlyphKey(0x62)) != nullptr) ? 1 : 0; + count += (index.MapResource(GlyphKey(0x65)) != nullptr) ? 1 : 0; + count += (index.MapResource(GlyphKey(0x400)) != nullptr) ? 1 : 0; + count += (index.MapResource(GlyphKey(0x401)) != nullptr) ? 1 : 0; + while (index.GetPendingNodesCount() < count); EXPECTGL(glTexSubImage2D(_, _, _, _, _, _, _)).WillOnce(Invoke(&r, &UploadedRender::glMemoryToQImage)) .WillOnce(Invoke(&r, &UploadedRender::glMemoryToQImage)); diff --git a/drape/font_texture.cpp b/drape/font_texture.cpp index 07dd29e893..d17f5e0646 100644 --- a/drape/font_texture.cpp +++ b/drape/font_texture.cpp @@ -199,6 +199,12 @@ bool GlyphIndex::HasAsyncRoutines() const return !m_generator->IsSuspended(); } +size_t GlyphIndex::GetPendingNodesCount() +{ + threads::MutexGuard g(m_lock); + return m_pendingNodes.size(); +} + void GlyphIndex::OnGlyphGenerationCompletion(m2::RectU const & rect, GlyphManager::Glyph const & glyph) { threads::MutexGuard g(m_lock); diff --git a/drape/font_texture.hpp b/drape/font_texture.hpp index 5d8ccb3bd5..89b13d5261 100644 --- a/drape/font_texture.hpp +++ b/drape/font_texture.hpp @@ -104,12 +104,15 @@ public: GlyphIndex(m2::PointU size, ref_ptr mng); ~GlyphIndex(); - /// can return nullptr + // This function can return nullptr. ref_ptr MapResource(GlyphKey const & key, bool & newResource); void UploadResources(ref_ptr texture); bool HasAsyncRoutines() const; + // ONLY for unit-tests. DO NOT use this function anywhere else. + size_t GetPendingNodesCount(); + private: void OnGlyphGenerationCompletion(m2::RectU const & rect, GlyphManager::Glyph const & glyph);