Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--drape/drape_tests/drape_tests.pro5
-rw-r--r--drape/drape_tests/font_texture_tests.cpp216
-rw-r--r--drape/drape_tests/glyph_mng_tests.cpp21
-rw-r--r--drape/drape_tests/glyph_packer_test.cpp26
-rw-r--r--drape/drape_tests/img.cpp24
-rw-r--r--drape/drape_tests/img.hpp5
-rw-r--r--drape/font_texture.cpp4
-rw-r--r--qt_tstfrm/test_main_loop.cpp5
-rw-r--r--qt_tstfrm/test_main_loop.hpp2
9 files changed, 141 insertions, 167 deletions
diff --git a/drape/drape_tests/drape_tests.pro b/drape/drape_tests/drape_tests.pro
index 570267106c..82d9b17d1e 100644
--- a/drape/drape_tests/drape_tests.pro
+++ b/drape/drape_tests/drape_tests.pro
@@ -40,8 +40,11 @@ SOURCES += \
stipple_pen_tests.cpp \
texture_of_colors_tests.cpp \
glyph_mng_tests.cpp \
- glyph_packer_test.cpp
+ glyph_packer_test.cpp \
+ font_texture_tests.cpp \
+ img.cpp \
HEADERS += \
glmock_functions.hpp \
memory_comparer.hpp \
+ img.hpp \
diff --git a/drape/drape_tests/font_texture_tests.cpp b/drape/drape_tests/font_texture_tests.cpp
index c7fe334078..61012a045d 100644
--- a/drape/drape_tests/font_texture_tests.cpp
+++ b/drape/drape_tests/font_texture_tests.cpp
@@ -1,12 +1,18 @@
#include "../../testing/testing.hpp"
+#include "img.hpp"
+
#include "../font_texture.hpp"
+#include "../glyph_manager.hpp"
-#include "glmock_functions.hpp"
-#include "../../base/stl_add.hpp"
#include "../../platform/platform.hpp"
+#include "../../qt_tstfrm/test_main_loop.hpp"
+
+#include "../../std/bind.hpp"
+
+#include <QtGui/QPainter>
+#include <QtCore/QPoint>
-#include "../../geometry/rect2d.hpp"
-#include "../../geometry/point2d.hpp"
+#include "glmock_functions.hpp"
#include <gmock/gmock.h>
@@ -14,166 +20,88 @@ using ::testing::_;
using ::testing::Return;
using ::testing::InSequence;
using ::testing::AnyNumber;
+using ::testing::Invoke;
using namespace dp;
namespace
{
- void PrepareOpenGL(int size)
- {
- EXPECTGL(glHasExtension(_)).Times(AnyNumber());
- EXPECTGL(glGetInteger(gl_const::GLMaxTextureSize)).WillOnce(Return(size));
- EXPECTGL(glBindTexture(_)).Times(AnyNumber());
- EXPECTGL(glDeleteTexture(_)).Times(AnyNumber());
- EXPECTGL(glTexParameter(_, _)).Times(AnyNumber());
- EXPECTGL(glTexImage2D(_, _, _, _, _)).Times(AnyNumber());
- EXPECTGL(glGenTexture()).Times(AnyNumber());
- }
-
- FontTexture::GlyphInfo const * FindSymbol(int uni, vector<MasterPointer<Texture> > const & textures,
- int & w, int & h)
+ class DummyTexture : public dp::Texture
{
- FontTexture::GlyphKey key(uni);
- for (size_t i = 0; i < textures.size(); ++i)
- {
- RefPointer<Texture> texture = textures[i].GetRefPointer();
- Texture::ResourceInfo const * info = texture->FindResource(key);
- if (info != NULL)
- {
- w = texture->GetWidth();
- h = texture->GetHeight();
- return static_cast<FontTexture::GlyphInfo const *>(info);
- }
- }
-
- ASSERT(false, ());
- return NULL;
- }
-
- void TestSymbol(FontTexture::GlyphInfo const * srcInfo, FontTexture::GlyphInfo dstInfo, int texW, int texH)
- {
- m2::RectF srcTexRect = srcInfo->GetTexRect();
- m2::RectU srcRect(srcTexRect.minX() * texW, srcTexRect.minY() * texH,
- srcTexRect.maxX() * texW, srcTexRect.maxY() * texH);
-
- m2::RectF dstTexRect = dstInfo.GetTexRect();
- m2::RectU dstRect(dstTexRect.minX() * texW, dstTexRect.minY() * texH,
- dstTexRect.maxX() * texW, dstTexRect.maxY() * texH);
-
- TEST_EQUAL(dstRect, srcRect, ());
-
- float srcXoff, srcYoff, srcAdvance;
- srcInfo->GetMetrics(srcXoff, srcYoff, srcAdvance);
- float dstXoff, dstYoff, dstAdvance;
- dstInfo.GetMetrics(dstXoff, dstYoff, dstAdvance);
-
- TEST_ALMOST_EQUAL(srcXoff, dstXoff, ());
- TEST_ALMOST_EQUAL(srcYoff, dstYoff, ());
- TEST_ALMOST_EQUAL(srcAdvance, dstAdvance, ());
- }
+ public:
+ virtual ResourceInfo const * FindResource(Key const & key) const { return nullptr; }
+ };
- class Tester
+ class UploadedRender
{
public:
- Tester(int textureSize)
+ UploadedRender(QPoint const & pen)
+ : m_pen(pen)
{
- PrepareOpenGL(textureSize);
}
- void AddInfo(int id, FontTexture::GlyphInfo const & info)
+ void glMemoryToQImage(int x, int y, int w, int h, glConst f, glConst t, void const * memory)
{
- m_infos.push_back(make_pair(id, info));
+ TEST(f == gl_const::GLAlpha || f == gl_const::GLAlpha8, ());
+ TEST(t == gl_const::GLUnsignedByteType, ());
+
+ uint8_t const * image = reinterpret_cast<uint8_t const *>(memory);
+
+ QPoint p(m_pen);
+ p.rx() += x;
+ m_images.push_back(qMakePair(p, CreateImage(w, h, image)));
+ m_pen.ry() += h;
}
- void TestThis(string const & resPath)
+ void Render(QPaintDevice * device)
{
- vector<MasterPointer<Texture> > textures;
- vector<TransferPointer<Texture> > tempTextures;
- LoadFont(resPath, tempTextures);
- textures.reserve(tempTextures.size());
- for (size_t i = 0; i < tempTextures.size(); ++i)
- textures.push_back(MasterPointer<Texture>(tempTextures[i]));
-
- for (size_t i = 0; i < m_infos.size(); ++i)
- {
- int id = m_infos[i].first;
-
- int w, h;
- FontTexture::GlyphInfo const * info = FindSymbol(id, textures, w, h);
- TestSymbol(info, m_infos[i].second, w, h);
- }
-
- DeleteRange(textures, MasterPointerDeleter());
+ QPainter p(device);
+ for (auto d : m_images)
+ p.drawImage(d.first, d.second);
}
private:
- vector<pair<int, FontTexture::GlyphInfo> > m_infos;
+ QPoint m_pen;
+ QVector<QPair<QPoint, QImage> > m_images;
};
}
-typedef FontTexture::GlyphInfo glyph_t;
-
-UNIT_TEST(CutTextureTest_1024)
-{
- Tester t(1024);
- int w = 1024;
- int h = 1024;
- t.AddInfo(1, glyph_t(m2::RectF(0.0 / w, 0.0 / h,
- 20.0 / w, 20.0 / h), 0.0, 0.0, 0.1));
- t.AddInfo(2, glyph_t(m2::RectF(20.0 / w, 20.0 / h,
- 45.0 / w, 45.0 / h), 2.0, 4.3, 0.2));
- t.AddInfo(3, glyph_t(m2::RectF(512.0 / w, 256.0 / h,
- 768.0 / w, 512.0 / h), 0.1, 0.2, 1.2));
- t.AddInfo(4, glyph_t(m2::RectF(768.0 / w, 512.0 / h,
- 868.0 / w, 612.0 / h), 0.8, 1.0, 1.3));
-
- t.TestThis("font_test");
-}
-
-UNIT_TEST(CutTextureTest_512)
-{
- Tester t(512);
- int w = 512;
- int h = 512;
- t.AddInfo(1, glyph_t(m2::RectF(0.0 / w, 0.0 / h,
- 20.0 / w, 20.0 / h), 0.0, 0.0, 0.1));
- t.AddInfo(2, glyph_t(m2::RectF(20.0 / w, 20.0 / h,
- 45.0 / w, 45.0 / h), 2.0, 4.3, 0.2));
- t.AddInfo(3, glyph_t(m2::RectF(0.0 / w, 256.0 / h,
- 256.0 / w, 512.0 / h), 0.1, 0.2, 1.2));
- t.AddInfo(4, glyph_t(m2::RectF(256.0 / w, 0.0 / h,
- 356.0 / w, 100.0 / h), 0.8, 1.0, 1.3));
-
- t.TestThis("font_test");
-}
-
-UNIT_TEST(RectangleCut_1024)
-{
- Tester t(1024);
- int w1 = 512;
- int h1 = 512;
- int w2 = 256;
- int h2 = 256;
- t.AddInfo(1, glyph_t(m2::RectF(0.0 / w1, 0.0 / h1,
- 20.0 / w1, 20.0 / h1), 0.0, 0.0, 0.1));
- t.AddInfo(2, glyph_t(m2::RectF(0.0 / w1, 412.0 / h1,
- 100.0 / w1, 512.0 / h1), 2.0, 4.3, 0.2));
- t.AddInfo(3, glyph_t(m2::RectF(0.0 / w2, 0.0 / h2,
- 50.0 / w2, 50.0 / h2), 0.1, 0.2, 1.2));
-
- t.TestThis("font_test2");
-}
-
-UNIT_TEST(RectangleCut_256)
+UNIT_TEST(UploadingGlyphs)
{
- Tester t(256);
- int w = 256;
- int h = 256;
- t.AddInfo(1, glyph_t(m2::RectF(0.0 / w, 0.0 / h,
- 20.0 / w, 20.0 / h), 0.0, 0.0, 0.1));
- t.AddInfo(2, glyph_t(m2::RectF(0.0 / w, 156.0 / h,
- 100.0 / w, 256.0 / h), 2.0, 4.3, 0.2));
- t.AddInfo(3, glyph_t(m2::RectF(0.0 / w, 0.0 / h,
- 50.0 / w, 50.0 / h), 0.1, 0.2, 1.2));
-
- t.TestThis("font_test2");
+ EXPECTGL(glHasExtension(_)).Times(AnyNumber());
+ EXPECTGL(glBindTexture(_)).Times(AnyNumber());
+ EXPECTGL(glDeleteTexture(_)).Times(AnyNumber());
+ EXPECTGL(glTexParameter(_, _)).Times(AnyNumber());
+ EXPECTGL(glTexImage2D(_, _, _, _, _)).Times(AnyNumber());
+ EXPECTGL(glGenTexture()).Times(AnyNumber());
+
+ UploadedRender r(QPoint(10, 10));
+ dp::GlyphManager::Params args;
+ args.m_uniBlocks = "unicode_blocks.txt";
+ args.m_whitelist = "fonts_whitelist.txt";
+ args.m_blacklist = "fonts_blacklist.txt";
+ GetPlatform().GetFontNames(args.m_fonts);
+
+ GlyphManager mng(args);
+ GlyphIndex index(m2::PointU(64, 64), MakeStackRefPointer(&mng));
+ index.MapResource(GlyphKey(0x58));
+ index.MapResource(GlyphKey(0x59));
+ index.MapResource(GlyphKey(0x61));
+
+ DummyTexture tex;
+ tex.Create(64, 64, dp::ALPHA, MakeStackRefPointer<void>(nullptr));
+ EXPECTGL(glTexSubImage2D(_, _, _, _, _, _, _)).WillOnce(Invoke(&r, &UploadedRender::glMemoryToQImage));
+ index.UploadResources(MakeStackRefPointer<Texture>(&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));
+ EXPECTGL(glTexSubImage2D(_, _, _, _, _, _, _)).WillOnce(Invoke(&r, &UploadedRender::glMemoryToQImage))
+ .WillOnce(Invoke(&r, &UploadedRender::glMemoryToQImage));
+ index.UploadResources(MakeStackRefPointer<Texture>(&tex));
+
+ TestMainLoop loop(bind(&UploadedRender::Render, &r, _1));
+ loop.exec("UploadingGlyphs");
}
diff --git a/drape/drape_tests/glyph_mng_tests.cpp b/drape/drape_tests/glyph_mng_tests.cpp
index 6515ef1d7c..9c06159d37 100644
--- a/drape/drape_tests/glyph_mng_tests.cpp
+++ b/drape/drape_tests/glyph_mng_tests.cpp
@@ -1,5 +1,7 @@
#include "../../testing/testing.hpp"
+#include "img.hpp"
+
#include <QtGui/QPainter>
#include "../../qt_tstfrm/test_main_loop.hpp"
@@ -49,29 +51,14 @@ namespace
continue;
uint8_t * d = SharedBufferManager::GetRawPointer(g.m_image.m_data);
- int pitch = 32 * (((g.m_image.m_width - 1) / 32) + 1);
- int byteCount = pitch * g.m_image.m_height;
- unsigned char * buf = (unsigned char *)malloc(byteCount);
- memset(buf, 0, byteCount);
- for (int i = 0; i < g.m_image.m_height; ++i)
- memcpy(buf + pitch * i, d + g.m_image.m_width * i, g.m_image.m_width);
-
- QImage img = QImage(buf,
- pitch,
- g.m_image.m_height,
- QImage::Format_Indexed8);
-
- img.setColorCount(0xFF);
- for (int i = 0; i < 256; ++i)
- img.setColor(i, qRgb(255 - i, 255 - i, 255 - i));
+
QPoint currentPen = pen;
currentPen.rx() += g.m_metrics.m_xOffset;
currentPen.ry() -= g.m_metrics.m_yOffset;
- painter.drawImage(currentPen, img, QRect(0, 0, g.m_image.m_width, g.m_image.m_height));
+ painter.drawImage(currentPen, CreateImage(g.m_image.m_width, g.m_image.m_height, d), QRect(0, 0, g.m_image.m_width, g.m_image.m_height));
pen.rx() += g.m_metrics.m_xAdvance;
pen.ry() += g.m_metrics.m_yAdvance;
- free(buf);
g.m_image.Destroy();
}
}
diff --git a/drape/drape_tests/glyph_packer_test.cpp b/drape/drape_tests/glyph_packer_test.cpp
new file mode 100644
index 0000000000..15f32a3057
--- /dev/null
+++ b/drape/drape_tests/glyph_packer_test.cpp
@@ -0,0 +1,26 @@
+#include "../../testing/testing.hpp"
+#include "../font_texture.hpp"
+
+UNIT_TEST(SimplePackTest)
+{
+ dp::GlyphPacker packer(m2::PointU(32, 32));
+
+ m2::RectU r;
+
+ TEST(packer.PackGlyph(10, 13, r), ());
+ TEST_EQUAL(r, m2::RectU(0, 0, 10, 13), ());
+
+ TEST(packer.PackGlyph(18, 8, r), ());
+ TEST_EQUAL(r, m2::RectU(10, 0, 28, 8), ());
+
+ TEST(packer.PackGlyph(4, 15, r), ());
+ TEST_EQUAL(r, m2::RectU(28, 0, 32, 15), ());
+
+ TEST(packer.PackGlyph(7, 10, r), ());
+ TEST(!packer.IsFull(), ());
+ TEST_EQUAL(r, m2::RectU(0, 15, 7, 25), ());
+
+ TEST(!packer.PackGlyph(12, 18, r),());
+ TEST(packer.IsFull(), ());
+ TEST_EQUAL(r, m2::RectU(0, 15, 7, 25), ());
+}
diff --git a/drape/drape_tests/img.cpp b/drape/drape_tests/img.cpp
new file mode 100644
index 0000000000..b05088debf
--- /dev/null
+++ b/drape/drape_tests/img.cpp
@@ -0,0 +1,24 @@
+#include "img.hpp"
+
+void cleanUpQImageMemory(void * mem)
+{
+ free(mem);
+}
+
+QImage CreateImage(uint32_t w, uint32_t h, uint8_t const * mem)
+{
+ int pitch = 32 * (((w - 1) / 32) + 1);
+ int byteCount = pitch * h;
+ unsigned char * buf = (unsigned char *)malloc(byteCount);
+ memset(buf, 0, byteCount);
+ for (int i = 0; i < h; ++i)
+ memcpy(buf + pitch * i, mem + w * i, w);
+
+ QImage img = QImage(buf, pitch, h, QImage::Format_Indexed8, &cleanUpQImageMemory, buf);
+
+ img.setColorCount(0xFF);
+ for (int i = 0; i < 256; ++i)
+ img.setColor(i, qRgb(255 - i, 255 - i, 255 - i));
+
+ return img;
+}
diff --git a/drape/drape_tests/img.hpp b/drape/drape_tests/img.hpp
new file mode 100644
index 0000000000..3efda89467
--- /dev/null
+++ b/drape/drape_tests/img.hpp
@@ -0,0 +1,5 @@
+#pragma once
+
+#include <QtGui/QImage>
+
+QImage CreateImage(uint32_t w, uint32_t h, const uint8_t * mem);
diff --git a/drape/font_texture.cpp b/drape/font_texture.cpp
index a4888c216b..1c157c1168 100644
--- a/drape/font_texture.cpp
+++ b/drape/font_texture.cpp
@@ -114,8 +114,8 @@ void GlyphIndex::UploadResources(RefPointer<Texture> texture)
buffer_vector<size_t, 3> ranges;
buffer_vector<uint32_t, 2> maxHeights;
- uint32_t maxHeight = 0;
ranges.push_back(0);
+ uint32_t maxHeight = m_pendingNodes[0].first.SizeY();
for (size_t i = 1; i < m_pendingNodes.size(); ++i)
{
TPendingNode const & prevNode = m_pendingNodes[i - 1];
@@ -139,7 +139,7 @@ void GlyphIndex::UploadResources(RefPointer<Texture> texture)
size_t startIndex = ranges[i - 1];
size_t endIndex = ranges[i];
uint32_t height = maxHeights[i - 1];
- uint32_t width = m_pendingNodes[endIndex].first.maxX() - m_pendingNodes[startIndex].first.maxX();
+ uint32_t width = m_pendingNodes[endIndex - 1].first.maxX() - m_pendingNodes[startIndex].first.minX();
uint32_t byteCount = my::NextPowOf2(height * width);
m2::PointU zeroPoint = m_pendingNodes[startIndex].first.LeftBottom();
diff --git a/qt_tstfrm/test_main_loop.cpp b/qt_tstfrm/test_main_loop.cpp
index 9108b2ceb0..1e71a14041 100644
--- a/qt_tstfrm/test_main_loop.cpp
+++ b/qt_tstfrm/test_main_loop.cpp
@@ -13,7 +13,7 @@ TestMainLoop::TestMainLoop(TestMainLoop::TRednerFn const & fn)
{
}
-void TestMainLoop::exec(char const * testName)
+void TestMainLoop::exec(char const * testName, bool autoExit)
{
char * buf = (char *)malloc(strlen(testName) + 1);
MY_SCOPE_GUARD(argvFreeFun, [&buf](){ free(buf); });
@@ -21,7 +21,8 @@ void TestMainLoop::exec(char const * testName)
int argc = 1;
QApplication app(argc, &buf);
- QTimer::singleShot(3000, &app, SLOT(quit()));
+ if (autoExit)
+ QTimer::singleShot(3000, &app, SLOT(quit()));
QWidget w;
w.setWindowTitle(testName);
diff --git a/qt_tstfrm/test_main_loop.hpp b/qt_tstfrm/test_main_loop.hpp
index 6e0b41b1d1..ea879afee6 100644
--- a/qt_tstfrm/test_main_loop.hpp
+++ b/qt_tstfrm/test_main_loop.hpp
@@ -15,7 +15,7 @@ public:
TestMainLoop(TRednerFn const & fn);
virtual ~TestMainLoop() {}
- void exec(char const * testName);
+ void exec(char const * testName, bool autoExit = true);
protected:
bool eventFilter(QObject * obj, QEvent * event);