diff --git a/base/shared_buffer_manager.cpp b/base/shared_buffer_manager.cpp index 1df55adb26..ddad9522e6 100644 --- a/base/shared_buffer_manager.cpp +++ b/base/shared_buffer_manager.cpp @@ -31,3 +31,8 @@ void SharedBufferManager::freeSharedBuffer(size_t s, shared_buffer_ptr_t buf) l.push_back(buf); } + +uint8_t * SharedBufferManager::GetRawPointer(SharedBufferManager::shared_buffer_ptr_t ptr) +{ + return &((*ptr)[0]); +} diff --git a/base/shared_buffer_manager.hpp b/base/shared_buffer_manager.hpp index e4b57ac187..2dd745a348 100644 --- a/base/shared_buffer_manager.hpp +++ b/base/shared_buffer_manager.hpp @@ -9,7 +9,7 @@ class SharedBufferManager { public: - typedef vector shared_buffer_t; + typedef vector shared_buffer_t; typedef shared_ptr shared_buffer_ptr_t; typedef list shared_buffer_ptr_list_t; typedef map shared_buffers_t; @@ -23,4 +23,6 @@ public: shared_buffer_ptr_t reserveSharedBuffer(size_t s); void freeSharedBuffer(size_t s, shared_buffer_ptr_t buf); + + static uint8_t * GetRawPointer(shared_buffer_ptr_t ptr); }; diff --git a/drape/drape_tests/batcher_tests.cpp b/drape/drape_tests/batcher_tests.cpp index 527d0ff57b..9805156d20 100644 --- a/drape/drape_tests/batcher_tests.cpp +++ b/drape/drape_tests/batcher_tests.cpp @@ -1,4 +1,5 @@ #include "../../testing/testing.hpp" +#include "memory_comparer.hpp" #include "../glconstants.hpp" #include "../batcher.hpp" @@ -39,24 +40,6 @@ struct VAOAcceptor vector > m_vao; }; -struct MemoryComparer -{ - void * m_mem; - int m_size; - - MemoryComparer(void * memory, int size) - : m_mem(memory) - , m_size(size) - { - } - - void cmp(glConst /*type*/, uint32_t size, void const * data, uint32_t /*offset*/) const - { - TEST_EQUAL(size, m_size, ()); - TEST_EQUAL(memcmp(m_mem, data, size), 0, ()); - } -}; - class BatcherExpectations { public: @@ -115,7 +98,7 @@ public: // upload indexes EXPECTGL(glBindBuffer(m_indexBufferID, gl_const::GLElementArrayBuffer)); EXPECTGL(glBufferSubData(gl_const::GLElementArrayBuffer, indexCount * sizeof(unsigned short), _, 0)) - .WillOnce(Invoke(&indexCmp, &MemoryComparer::cmp)); + .WillOnce(Invoke(&indexCmp, &MemoryComparer::cmpSubBuffer)); // data buffer creation EXPECTGL(glGenBuffer()).WillOnce(Return(m_dataBufferID)); @@ -125,7 +108,7 @@ public: // upload data EXPECTGL(glBindBuffer(m_dataBufferID, gl_const::GLArrayBuffer)); EXPECTGL(glBufferSubData(gl_const::GLArrayBuffer, vertxeCount * sizeof(float), _, 0)) - .WillOnce(Invoke(&vertexCmp, &MemoryComparer::cmp)); + .WillOnce(Invoke(&vertexCmp, &MemoryComparer::cmpSubBuffer)); } void ExpectBufferDeletion() @@ -288,7 +271,7 @@ namespace // upload indexes EXPECTGL(glBindBuffer(currentNode.m_indexBufferID, gl_const::GLElementArrayBuffer)); EXPECTGL(glBufferSubData(gl_const::GLElementArrayBuffer, currentNode.m_indexByteCount, _, 0)) - .WillOnce(Invoke(indexComparer, &MemoryComparer::cmp)); + .WillOnce(Invoke(indexComparer, &MemoryComparer::cmpSubBuffer)); // data buffer creation EXPECTGL(glGenBuffer()).WillOnce(Return(currentNode.m_vertexBufferID)); @@ -300,7 +283,7 @@ namespace // upload data EXPECTGL(glBindBuffer(currentNode.m_vertexBufferID, gl_const::GLArrayBuffer)); EXPECTGL(glBufferSubData(gl_const::GLArrayBuffer, currentNode.m_vertexByteCount, _, 0)) - .WillOnce(Invoke(vertexComparer, &MemoryComparer::cmp)); + .WillOnce(Invoke(vertexComparer, &MemoryComparer::cmpSubBuffer)); } void CloseExpection() diff --git a/drape/drape_tests/drape_tests.pro b/drape/drape_tests/drape_tests.pro index 26e1b79da2..6cbff61f60 100644 --- a/drape/drape_tests/drape_tests.pro +++ b/drape/drape_tests/drape_tests.pro @@ -44,3 +44,4 @@ SOURCES += \ HEADERS += \ glmock_functions.hpp \ enum_shaders.hpp \ + memory_comparer.hpp diff --git a/drape/drape_tests/memory_comparer.hpp b/drape/drape_tests/memory_comparer.hpp new file mode 100644 index 0000000000..ba0ebf82ac --- /dev/null +++ b/drape/drape_tests/memory_comparer.hpp @@ -0,0 +1,33 @@ +#pragma once + +#include "../../testing/testing.hpp" +#include "../glconstants.hpp" +#include "../../base/logging.hpp" + +namespace dp +{ + struct MemoryComparer + { + void * m_mem; + int m_size; + + MemoryComparer(void * memory, int size) + : m_mem(memory) + , m_size(size) + { + } + + void cmpSubBuffer(glConst /*type*/, uint32_t size, void const * data, uint32_t /*offset*/) const + { + TEST_EQUAL(size, m_size, ()); + TEST_EQUAL(memcmp(m_mem, data, size), 0, ()); + } + + void cmpSubImage(uint32_t /*x*/, uint32_t /*y*/, uint32_t /*width*/, uint32_t /*height*/, + glConst /*layout*/, glConst /*pixelFormat*/, void const * data) const + { + TEST_EQUAL(memcmp(m_mem, data, m_size), 0, ()); + } + }; + +} diff --git a/drape/drape_tests/stipple_pen_tests.cpp b/drape/drape_tests/stipple_pen_tests.cpp index 29b18cc7e5..10a329f9bb 100644 --- a/drape/drape_tests/stipple_pen_tests.cpp +++ b/drape/drape_tests/stipple_pen_tests.cpp @@ -1,16 +1,46 @@ #include "../../testing/testing.hpp" -#include "../stipple_pen_resource.hpp" +#include "memory_comparer.hpp" +#include "../glconstants.hpp" +#include "../stipple_pen_resource.hpp" +#include "../texture.hpp" + +#include "glmock_functions.hpp" + +#include + +using testing::_; +using testing::Return; +using testing::InSequence; +using testing::Invoke; +using testing::IgnoreResult; +using testing::AnyOf; using namespace dp; namespace { + class DummyTexture : public Texture + { + public: + DummyTexture() {} + + virtual ResourceInfo const * FindResource(Key const & key) const { return NULL; } + }; + void TestPacker(StipplePenPacker & packer, uint32_t width, m2::RectU const & expect) { m2::RectU rect = packer.PackResource(width); TEST_EQUAL(rect, expect, ()); } + + bool IsRectsEqual(m2::RectF const & r1, m2::RectF const & r2) + { + return my::AlmostEqual(r1.minX(), r2.minX()) && + my::AlmostEqual(r1.minY(), r2.minY()) && + my::AlmostEqual(r1.maxX(), r2.maxX()) && + my::AlmostEqual(r1.maxY(), r2.maxY()); + } } UNIT_TEST(SimpleStipplePackTest) @@ -21,6 +51,9 @@ UNIT_TEST(SimpleStipplePackTest) TestPacker(packer, 1, m2::RectU(1, 5, 2, 6)); TestPacker(packer, 250, m2::RectU(256, 1, 506, 2)); TestPacker(packer, 249, m2::RectU(256, 3, 505, 4)); + + m2::RectF mapped = packer.MapTextureCoords(m2::RectU(1, 3, 255, 4)); + TEST(IsRectsEqual(mapped, m2::RectF(0.00146484375, 0.4375, 0.2485351563, 0.4375)), ()); } UNIT_TEST(SimpleStippleTest) @@ -110,3 +143,299 @@ UNIT_TEST(SimplePatternKey) TEST_EQUAL(StipplePenKey(info), StipplePenKey(0xE2C58711FFFA74E0), ()); } } + +namespace +{ + uint8_t firstUploadEtalon[] = + { +/*1*/ 0xFF, 0xFF, 0x0, 0x0, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, +/*2*/ 0xFF, 0xFF, 0x0, 0x0, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, +/*3*/ 0xFF, 0xFF, 0x0, 0x0, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, +/*4*/ 0xFF, 0xFF, 0x0, 0x0, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, +/*5*/ 0xFF, 0xFF, 0x0, 0x0, 0xFF, 0xFF, 0xF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xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +/*4*/ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +/*5*/ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +/*6*/ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + }; + + uint8_t secondUploadSecondPartEtalon[] = + { +/*1*/ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +/*2*/ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +/*3*/ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +/*4*/ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + }; +} + +UNIT_TEST(StippleMappingTest) +{ + uint32_t const width = 512; + uint32_t const height = 10; + StipplePenIndex index(m2::PointU(512, 10)); + + StipplePenInfo info; + info.m_pattern.push_back(2); + info.m_pattern.push_back(2); + info.m_pattern.push_back(10); + info.m_pattern.push_back(10); + + m2::RectF const & r1 = index.MapResource(info); + TEST(IsRectsEqual(r1, m2::RectF(1.5f / 512.0f, 1.5f / 10.0f, + 240.5f/ 512.0f, 1.5f / 10.0f)), ()); + + m2::RectF const & r2 = index.MapResource(info); + TEST(IsRectsEqual(r1, r2), ()); + + info.m_pattern.push_back(4); + info.m_pattern.push_back(4); + m2::RectF const & r3 = index.MapResource(info); + TEST(IsRectsEqual(r3, m2::RectF(1.5f / 512.0f, 3.5f / 10.0f, + 224.5f / 512.0f, 3.5f / 10.0f)), ()); + + info.m_pattern.push_back(3); + info.m_pattern.push_back(20); + m2::RectF const & r4 = index.MapResource(info); + TEST(IsRectsEqual(r4, m2::RectF(1.5f / 512.0f, 5.5f / 10.0f, + 220.5f / 512.0f, 5.5f / 10.0f)), ()); + + InSequence seq; + EXPECTGL(glHasExtension(_)).WillRepeatedly(Return(true)); + EXPECTGL(glGenTexture()).WillOnce(Return(1)); + EXPECTGL(glBindTexture(1)).WillOnce(Return()); + EXPECTGL(glTexImage2D(512, 16, gl_const::GLAlpha, gl_const::GL8BitOnChannel, NULL)); + EXPECTGL(glTexParameter(gl_const::GLMinFilter, gl_const::GLLinear)); + EXPECTGL(glTexParameter(gl_const::GLMagFilter, gl_const::GLLinear)); + EXPECTGL(glTexParameter(gl_const::GLWrapS, gl_const::GLClampToEdge)); + EXPECTGL(glTexParameter(gl_const::GLWrapT, gl_const::GLClampToEdge)); + MemoryComparer cmp(firstUploadEtalon, ARRAY_SIZE(firstUploadEtalon)); + EXPECTGL(glTexSubImage2D(1, 1, 254, 6, gl_const::GLAlpha, gl_const::GL8BitOnChannel, _)) + .WillOnce(Invoke(&cmp, &MemoryComparer::cmpSubImage)); + + DummyTexture texture; + texture.Create(width, height, dp::ALPHA); + index.UploadResources(MakeStackRefPointer(&texture)); + + StipplePenInfo secInfo; + secInfo.m_pattern.push_back(20); + secInfo.m_pattern.push_back(20); + m2::RectF const & r12 = index.MapResource(secInfo); + TEST(IsRectsEqual(r12, m2::RectF(1.5f / 512.0f, 7.5f / 10.0f, + 240.5f / 512.0f, 7.5f / 10.0f)), ()); + + secInfo.m_pattern.push_back(10); + secInfo.m_pattern.push_back(10); + m2::RectF const & r22 = index.MapResource(secInfo); + TEST(IsRectsEqual(r22, m2::RectF(256.5f / 512.0f, 1.5f / 10.0f, + 495.5f / 512.0f, 1.5f / 10.0f)), ()); + + MemoryComparer cmp21(secondUploadFirstPartEtalon, ARRAY_SIZE(secondUploadFirstPartEtalon)); + EXPECTGL(glTexSubImage2D(1, 7, 254, 2, gl_const::GLAlpha, gl_const::GL8BitOnChannel, _)) + .WillOnce(Invoke(&cmp21, &MemoryComparer::cmpSubImage)); + + MemoryComparer cmp22(secondUploadSecondPartEtalon, ARRAY_SIZE(secondUploadSecondPartEtalon)); + EXPECTGL(glTexSubImage2D(256, 1, 254, 2, gl_const::GLAlpha, gl_const::GL8BitOnChannel, _)) + .WillOnce(Invoke(&cmp22, &MemoryComparer::cmpSubImage)); + index.UploadResources(MakeStackRefPointer(&texture)); + EXPECTGL(glDeleteTexture(1)); +} diff --git a/drape/stipple_pen_resource.cpp b/drape/stipple_pen_resource.cpp index 53e6f46f61..cded323db5 100644 --- a/drape/stipple_pen_resource.cpp +++ b/drape/stipple_pen_resource.cpp @@ -1,5 +1,9 @@ #include "stipple_pen_resource.hpp" +#include "texture.hpp" + +#include "../base/shared_buffer_manager.hpp" + #include "../std/numeric.hpp" #include "../std/sstream.hpp" @@ -43,8 +47,27 @@ m2::RectU StipplePenPacker::PackResource(uint32_t width) return m2::RectU(xOffset, yOffset, xOffset + width, yOffset + 1); } +m2::RectF StipplePenPacker::MapTextureCoords(m2::RectU const & pixelRect) const +{ + return m2::RectF((pixelRect.minX() + 0.5f) / m_canvasSize.x, + (pixelRect.minY() + 0.5f) / m_canvasSize.y, + (pixelRect.maxX() - 0.5f) / m_canvasSize.x, + (pixelRect.maxY() - 0.5f) / m_canvasSize.y); +} + +StipplePenKey::StipplePenKey(buffer_vector const & pattern) + : m_keyValue(0) +{ + Init(pattern); +} + StipplePenKey::StipplePenKey(StipplePenInfo const & info) : m_keyValue(0) +{ + Init(info.m_pattern); +} + +void StipplePenKey::Init(const buffer_vector & pattern) { // encoding scheme // 63 - 61 bits = size of pattern in range [1 : 8] @@ -53,7 +76,7 @@ StipplePenKey::StipplePenKey(StipplePenInfo const & info) // .... // 0 - 5 bits = reserved - uint32_t patternSize = info.m_pattern.size(); + uint32_t patternSize = pattern.size(); ASSERT(patternSize > 1, ()); ASSERT(patternSize < 9, ()); @@ -61,9 +84,9 @@ StipplePenKey::StipplePenKey(StipplePenInfo const & info) for (size_t i = 0; i < patternSize; ++i) { m_keyValue <<=7; - ASSERT(info.m_pattern[i] > 0, ()); // we have 7 bytes for value. value = 1 encode like 0000000 - ASSERT(info.m_pattern[i] < 129, ()); // value = 128 encode like 1111111 - uint32_t value = info.m_pattern[i] - 1; + ASSERT(pattern[i] > 0, ()); // we have 7 bytes for value. value = 1 encode like 0000000 + ASSERT(pattern[i] < 129, ()); // value = 128 encode like 1111111 + uint32_t value = pattern[i] - 1; m_keyValue += value; } @@ -89,11 +112,6 @@ uint32_t StipplePenResource::GetBufferSize() const return m_pixelLength; } -TextureFormat StipplePenResource::GetExpectedFormat() const -{ - return ALPHA; -} - void StipplePenResource::Rasterize(void * buffer) { uint8_t * pixels = static_cast(buffer); @@ -115,7 +133,91 @@ void StipplePenResource::Rasterize(void * buffer) } } -string DebugPrint(const StipplePenKey & key) +m2::RectF const & StipplePenIndex::MapResource(StipplePenInfo const & info) +{ + StipplePenKey key(info); + TResourceMapping::const_iterator it = m_resourceMapping.find(key); + if (it != m_resourceMapping.end()) + return it->second; + + StipplePenResource resource(info); + m2::RectU pixelRect = m_packer.PackResource(resource.GetSize()); + m_pendingNodes.push_back(make_pair(pixelRect, resource)); + + typedef pair TInsertionNode; + TInsertionNode result = m_resourceMapping.insert(make_pair(key, m_packer.MapTextureCoords(pixelRect))); + ASSERT(result.second, ()); + return result.first->second; +} + +void StipplePenIndex::UploadResources(RefPointer texture) +{ + ASSERT(texture->GetFormat() == dp::ALPHA, ()); + if (m_pendingNodes.empty()) + return; + + buffer_vector ranges; + ranges.push_back(0); + + uint32_t xOffset = m_pendingNodes[0].first.minX(); + for (size_t i = 1; i < m_pendingNodes.size(); ++i) + { + m2::RectU & node = m_pendingNodes[i].first; +#ifdef DEBUG + ASSERT(xOffset <= node.minX(), ()); + if (xOffset == node.minX()) + { + m2::RectU const & prevNode = m_pendingNodes[i - 1].first; + ASSERT(prevNode.minY() < node.minY(), ()); + } +#endif + if (node.minX() > xOffset) + ranges.push_back(i); + xOffset = node.minX(); + } + + ranges.push_back(m_pendingNodes.size()); + SharedBufferManager & mng = SharedBufferManager::instance(); + + for (size_t i = 1; i < ranges.size(); ++i) + { + uint32_t rangeStart = ranges[i - 1]; + uint32_t rangeEnd = ranges[i]; + // rangeEnd - rangeStart give us count of patterns in this package + // 2 * range - count of lines for patterns + uint32_t lineCount = 2 * (rangeEnd - rangeStart); + // MAX_STIPPLE_PEN_LENGTH * lineCount - byte count on all patterns + uint32_t bufferSize = MAX_STIPPLE_PEN_LENGTH * lineCount; + uint32_t reserveBufferSize = my::NextPowOf2(bufferSize); + SharedBufferManager::shared_buffer_ptr_t ptr = mng.reserveSharedBuffer(reserveBufferSize); + uint8_t * rawBuffer = SharedBufferManager::GetRawPointer(ptr); + memset(rawBuffer, 0, reserveBufferSize); + + m2::RectU const & startNode = m_pendingNodes[rangeStart].first; + uint32_t minX = startNode.minX(); + uint32_t minY = startNode.minY(); +#ifdef DEBUG + m2::RectU const & endNode = m_pendingNodes[rangeEnd - 1].first; + ASSERT(endNode.maxY() + 1 == (minY + lineCount), ()); +#endif + + for (size_t r = rangeStart; r < rangeEnd; ++r) + { + m_pendingNodes[r].second.Rasterize(rawBuffer); + rawBuffer += 2 * MAX_STIPPLE_PEN_LENGTH; + } + + rawBuffer = SharedBufferManager::GetRawPointer(ptr); + texture->UploadData(minX, minY, MAX_STIPPLE_PEN_LENGTH, lineCount, + dp::ALPHA, MakeStackRefPointer(rawBuffer)); + + mng.freeSharedBuffer(reserveBufferSize, ptr); + } + + m_pendingNodes.clear(); +} + +string DebugPrint(StipplePenKey const & key) { ostringstream out; out << "0x" << hex << key.m_keyValue; diff --git a/drape/stipple_pen_resource.hpp b/drape/stipple_pen_resource.hpp index b324e10a56..95172c1423 100644 --- a/drape/stipple_pen_resource.hpp +++ b/drape/stipple_pen_resource.hpp @@ -1,12 +1,15 @@ #pragma once #include "drape_global.hpp" +#include "pointers.hpp" #include "../base/buffer_vector.hpp" #include "../geometry/point2d.hpp" #include "../geometry/rect2d.hpp" +#include "../std/map.hpp" + namespace dp { @@ -16,6 +19,7 @@ public: StipplePenPacker(m2::PointU const & canvasSize); m2::RectU PackResource(uint32_t width); + m2::RectF MapTextureCoords(m2::RectU const & pixelRect) const; private: m2::PointU m_canvasSize; @@ -33,11 +37,15 @@ struct StipplePenKey enum { Tag = StipplePenTag }; StipplePenKey(uint64_t value) : m_keyValue(value) {} // don't use this ctor. Only for tests + StipplePenKey(buffer_vector const & pattern); StipplePenKey(StipplePenInfo const & info); bool operator == (StipplePenKey const & other) const { return m_keyValue == other.m_keyValue; } bool operator < (StipplePenKey const & other) const { return m_keyValue < other.m_keyValue; } +private: + void Init(buffer_vector const & pattern); + private: friend string DebugPrint(StipplePenKey const & ); uint64_t m_keyValue; @@ -46,11 +54,11 @@ private: class StipplePenResource { public: + StipplePenResource() : m_pixelLength(0) {} StipplePenResource(StipplePenInfo const & key); uint32_t GetSize() const; uint32_t GetBufferSize() const; - TextureFormat GetExpectedFormat() const; void Rasterize(void * buffer); @@ -59,6 +67,24 @@ private: uint32_t m_pixelLength; }; +class Texture; +class StipplePenIndex +{ +public: + StipplePenIndex(m2::PointU const & canvasSize) : m_packer(canvasSize) {} + m2::RectF const & MapResource(StipplePenInfo const &info); + void UploadResources(RefPointer texture); + +private: + typedef map TResourceMapping; + typedef pair TPendingNode; + typedef buffer_vector TPendingNodes; + + TResourceMapping m_resourceMapping; + TPendingNodes m_pendingNodes; + StipplePenPacker m_packer; +}; + string DebugPrint(StipplePenKey const & key); }