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

cpu_drawer.hpp « software_renderer - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 29429158869b6ef4bcb25569eae35162d569b1b5 (plain)
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
#pragma once

#include "software_renderer/frame_image.hpp"
#include "software_renderer/feature_processor.hpp"

#include "drape/drape_global.hpp"

#include "indexer/feature_decl.hpp"

#include "geometry/screenbase.hpp"

#include <cstdint>
#include <functional>
#include <list>
#include <map>
#include <memory>
#include <string>

namespace software_renderer
{
class SoftwareRenderer;

class CPUDrawer
{
public:
  struct Params
  {
    Params(std::string const & resourcesPrefix, double visualScale)
      : m_resourcesPrefix(resourcesPrefix)
      , m_visualScale(visualScale)
    {}

    std::string m_resourcesPrefix;
    double m_visualScale;
  };

  CPUDrawer(Params const & params);
  ~CPUDrawer();

  void BeginFrame(uint32_t width, uint32_t height, dp::Color const & bgColor);
  void Flush();
  void DrawMyPosition(m2::PointD const & myPxPotision);
  void DrawSearchResult(m2::PointD const & pxPosition);
  void DrawSearchArrow(double azimut);
  void EndFrame(FrameImage & image);

  GlyphCache * GetGlyphCache() const;

  double GetVisualScale() const { return m_visualScale; }

  ScreenBase CalculateScreen(m2::PointD const & center, int zoomModifier,
                             uint32_t pxWidth, uint32_t pxHeight,
                             FrameSymbols const & symbols, int & resultZoom);

  void Draw(FeatureData const & data);

protected:
  void DrawSymbol(m2::PointD const & pt, dp::Anchor pos, DrawRule const & rule);
  void DrawPath(PathInfo const & path, DrawRule const * rules, size_t count);
  void DrawArea(AreaInfo const & area, DrawRule const & rule);
  void DrawText(m2::PointD const & pt, dp::Anchor pos,
                FeatureStyler const & fs, DrawRule const & rule);
  void DrawPathText(PathInfo const & info, FeatureStyler const & fs, DrawRule const & rule);
  void DrawPathNumber(PathInfo const & path, FeatureStyler const & fs, DrawRule const & rule);

  using TRoadNumberCallbackFn = std::function<void(m2::PointD const & pt, dp::FontDecl const & font,
                                                   std::string const & text)>;

  void GenerateRoadNumbers(PathInfo const & path, dp::FontDecl const & font,
                           FeatureStyler const & fs, TRoadNumberCallbackFn const & fn);

  void DrawFeatureStart(FeatureID const & id);
  void DrawFeatureEnd(FeatureID const & id);
  FeatureID const & GetCurrentFeatureID() const;

  int GetGeneration() { return m_generationCounter++; }

  FeatureID const & Insert(PathInfo const & info);
  FeatureID const & Insert(AreaInfo const & info);
  FeatureID const & Insert(FeatureStyler const & styler);
  FeatureID const & Insert(std::string const & text);

private:
  void Render();

private:
  std::unique_ptr<SoftwareRenderer> m_renderer;
  int m_generationCounter;

  enum EShapeType
  {
    TYPE_INVALID,
    TYPE_SYMBOL,
    TYPE_CIRCLE,
    TYPE_AREA,
    TYPE_PATH,
    TYPE_PATH_TEXT,
    TYPE_TEXT,
    TYPE_ROAD_NUMBER
  };

  struct BaseShape
  {
    BaseShape(DrawRule const & rule, int generation, EShapeType type)
      : m_drawRule(rule)
      , m_generation(generation)
      , m_type(type)
    {}

    DrawRule m_drawRule;
    int m_generation = 0;
    EShapeType m_type = TYPE_INVALID;
  };

  struct PointShape : BaseShape
  {
    PointShape(m2::PointD const & pt, dp::Anchor anchor, EShapeType type,
               DrawRule const & rule, int generation)
      : BaseShape(rule, generation, type)
      , m_position(pt)
      , m_anchor(anchor)
    {
      ASSERT(type == TYPE_SYMBOL || type == TYPE_CIRCLE, ());
    }

    m2::PointD m_position = m2::PointD::Zero();
    dp::Anchor m_anchor = dp::Center;
  };

  struct ComplexShape : BaseShape
  {
    ComplexShape(FeatureID const & geomID, DrawRule const & rule, int generation, EShapeType type)
      : BaseShape(rule, generation, type)
      , m_geomID(geomID)
    {
      ASSERT(type == TYPE_AREA ||
             type == TYPE_PATH ||
             type == TYPE_PATH_TEXT ||
             type == TYPE_TEXT ||
             type == TYPE_ROAD_NUMBER, ());

      ASSERT(type == TYPE_ROAD_NUMBER || m_drawRule.m_rule != nullptr, ());
    }

    FeatureID m_geomID;
  };

  struct TextShape : ComplexShape
  {
    TextShape(m2::PointD const & pt, dp::Anchor anchor, FeatureID const & id,
              DrawRule const & rule, int generation, EShapeType type)
      : ComplexShape(id, rule, generation, type)
      , m_position(pt)
      , m_anchor(anchor)
    {}

    m2::PointD m_position = m2::PointD::Zero();
    dp::Anchor m_anchor = dp::Center;
  };

  void DrawSymbol(PointShape const * shape);
  void DrawCircle(PointShape const * shape);
  void DrawPath(ComplexShape const * shape);
  void DrawArea(ComplexShape const * shape);
  void DrawPathText(ComplexShape const * shape);
  void DrawRoadNumber(TextShape const * shape);
  void DrawText(TextShape const * shape);

  class CPUOverlayTree;
  struct OverlayWrapper
  {
    OverlayWrapper(BaseShape const ** rules, size_t count)
      : m_ruleCount(count)
    {
      ASSERT(count > 0 && count < 3, ());
      m_rules[0] = rules[0];
      if (m_ruleCount == 2)
        m_rules[1] = rules[1];
    }

    BaseShape const * m_rules[2];
    size_t m_ruleCount;
    std::vector<m2::RectD> m_rects;
    m2::RectD m_boundRect;
  };

  OverlayWrapper & AddOverlay(BaseShape const * shape1, BaseShape const * shape2 = nullptr);

  using TTextRendererCall =
      std::function<void(m2::PointD const &, dp::Anchor, dp::FontDecl const &, dp::FontDecl const &,
                         strings::UniString const &, strings::UniString const &)>;

  void CallTextRendererFn(TextShape const * shape, TTextRendererCall const & fn);

  using TRoadNumberRendererCall = std::function<void(
      m2::PointD const &, dp::Anchor, dp::FontDecl const &, strings::UniString const &)>;

  void CallTextRendererFn(TextShape const * shape, TRoadNumberRendererCall const & fn);

  using TPathTextRendererCall = std::function<void (PathInfo const &, dp::FontDecl const &,
                                                    strings::UniString const & text)>;
  void CallTextRendererFn(ComplexShape const * shape, TPathTextRendererCall const & fn);

  std::list<ComplexShape> m_areaPathShapes;

  // overlay part
  std::list<PointShape> m_pointShapes;
  std::list<ComplexShape> m_pathTextShapes;
  std::list<TextShape> m_textShapes;
  std::list<OverlayWrapper> m_overlayList;

  std::map<FeatureID, FeatureStyler> m_stylers;
  std::map<FeatureID, AreaInfo> m_areasGeometry;
  std::map<FeatureID, PathInfo> m_pathGeometry;
  std::map<FeatureID, string> m_roadNames;
  dp::FontDecl m_roadNumberFont;

  double m_visualScale;

  FeatureID m_currentFeatureID;
};
}  // namespace software_renderer