1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
|
#pragma once
#include "drape/drape_global.hpp"
#include "drape/pointers.hpp"
#include "drape/texture.hpp"
#include "drape/dynamic_texture.hpp"
#include "base/buffer_vector.hpp"
#include "geometry/point2d.hpp"
#include "geometry/rect2d.hpp"
#include "std/map.hpp"
#include "std/mutex.hpp"
namespace dp
{
class StipplePenKey : public Texture::Key
{
public:
StipplePenKey() = default;
StipplePenKey(buffer_vector<uint8_t, 8> const & pattern) : m_pattern(pattern) {}
virtual Texture::ResourceType GetType() const { return Texture::StipplePen; }
buffer_vector<uint8_t, 8> m_pattern;
};
class StipplePenHandle
{
public:
StipplePenHandle(uint64_t value) : m_keyValue(value) {} // don't use this ctor. Only for tests
StipplePenHandle(buffer_vector<uint8_t, 8> const & pattern);
StipplePenHandle(StipplePenKey const & info);
bool operator == (StipplePenHandle const & other) const { return m_keyValue == other.m_keyValue; }
bool operator < (StipplePenHandle const & other) const { return m_keyValue < other.m_keyValue; }
private:
void Init(buffer_vector<uint8_t, 8> const & pattern);
private:
friend string DebugPrint(StipplePenHandle const & );
uint64_t m_keyValue;
};
class StipplePenRasterizator
{
public:
StipplePenRasterizator() : m_pixelLength(0), m_patternLength(0) {}
StipplePenRasterizator(StipplePenKey const & key);
uint32_t GetSize() const;
uint32_t GetPatternSize() const;
void Rasterize(void * buffer);
private:
StipplePenKey m_key;
uint32_t m_pixelLength;
uint32_t m_patternLength;
};
class StipplePenResourceInfo : public Texture::ResourceInfo
{
public:
StipplePenResourceInfo(m2::RectF const & texRect, uint32_t pixelLength, uint32_t patternLength)
: Texture::ResourceInfo(texRect)
, m_pixelLength(pixelLength)
, m_patternLength(patternLength)
{
}
virtual Texture::ResourceType GetType() const { return Texture::StipplePen; }
uint32_t GetMaskPixelLength() const { return m_pixelLength; }
uint32_t GetPatternPixelLength() const { return m_patternLength; }
private:
uint32_t m_pixelLength;
uint32_t m_patternLength;
};
class StipplePenPacker
{
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;
uint32_t m_currentRow;
};
class StipplePenIndex
{
public:
StipplePenIndex(m2::PointU const & canvasSize) : m_packer(canvasSize) {}
ref_ptr<Texture::ResourceInfo> ReserveResource(bool predefined, StipplePenKey const & key, bool & newResource);
ref_ptr<Texture::ResourceInfo> MapResource(StipplePenKey const & key, bool & newResource);
void UploadResources(ref_ptr<Texture> texture);
private:
typedef map<StipplePenHandle, StipplePenResourceInfo> TResourceMapping;
typedef pair<m2::RectU, StipplePenRasterizator> TPendingNode;
typedef buffer_vector<TPendingNode, 32> TPendingNodes;
TResourceMapping m_predefinedResourceMapping;
TResourceMapping m_resourceMapping;
TPendingNodes m_pendingNodes;
StipplePenPacker m_packer;
mutex m_lock;
mutex m_mappingLock;
};
string DebugPrint(StipplePenHandle const & key);
class StipplePenTexture : public DynamicTexture<StipplePenIndex, StipplePenKey, Texture::StipplePen>
{
typedef DynamicTexture<StipplePenIndex, StipplePenKey, Texture::StipplePen> TBase;
public:
StipplePenTexture(m2::PointU const & size, ref_ptr<HWTextureAllocator> allocator)
: m_index(size)
{
TBase::TextureParams params{size, TextureFormat::ALPHA, gl_const::GLNearest, false /* m_usePixelBuffer */};
TBase::Init(allocator, make_ref(&m_index), params);
}
~StipplePenTexture() { TBase::Reset(); }
void ReservePattern(buffer_vector<uint8_t, 8> const & pattern);
private:
StipplePenIndex m_index;
};
} // namespace dp
|