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

coverage_generator.hpp « render - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 4def88c41d9e4c8493d4c1661dc9719abfaa3540 (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
#pragma once

#include "render_policy.hpp"
#include "tiler.hpp"
#include "tile.hpp"
#include "window_handle.hpp"

#include "geometry/screenbase.hpp"

#include "graphics/overlay.hpp"

#include "base/thread.hpp"
#include "base/threaded_list.hpp"
#include "base/mutex.hpp"
#include "base/commands_queue.hpp"

#include "std/vector.hpp"
#include "std/shared_ptr.hpp"

class TileRenderer;
class TileCache;
class ScreenCoverage;

namespace graphics
{
  class Skin;

  namespace gl
  {
    class Screen;
  }
  class ResourceStyleCache;
}

/// Control class for TilingRenderPolicy. It processes request from the RenderPolicy
/// to draw a specific ScreenBase by splitting it in tiles that is not rendered now and
/// feeding them into TileRenderer. Each command to render a tile is enqueued with
/// a small command, which is feeding the CoverageGenerator with the command to process
/// newly rendered tile(p.e. merge it into current ScreenCoverage).
class CoverageGenerator
{
public:

  CoverageGenerator(TileRenderer * tileRenderer,
                    shared_ptr<WindowHandle> const & windowHandle,
                    shared_ptr<graphics::RenderContext> const & primaryRC,
                    shared_ptr<graphics::ResourceManager> const & rm,
                    graphics::PacketsQueue * glQueue);

  ~CoverageGenerator();

  void Shutdown();

  //@{ Add task to run on CoverageGenerator thread
  void InvalidateTiles(m2::AnyRectD const & rect, int startScale);
  void CoverScreen(ScreenBase const & screen, bool doForce);
  //}@

  //@{ Benchmark support
  int InsertBenchmarkFence();
  void JoinBenchmarkFence(int fenceID);
  //}@

  void Draw(graphics::Screen * s, ScreenBase const & screen);

  //@{ Frame lock
  void Lock();
  void Unlock();
  //}@

  void Pause();
  void Resume();

  graphics::Overlay * GetOverlay() const;

  bool IsEmptyDrawing() const;
  bool DoForceUpdate() const;

private:
  //@{ Called only on android, with Single thread policy
  void InitializeThreadGL(shared_ptr<graphics::RenderContext> context,
                          shared_ptr<graphics::ResourceManager> resourceManager,
                          graphics::PacketsQueue * glQueue);
  void FinalizeThreadGL(shared_ptr<graphics::RenderContext> context,
                        shared_ptr<graphics::ResourceManager> resourceManager);
  //@}

  void MergeTile(Tiler::RectInfo const & rectInfo, int sequenceID);

private:
  void CoverScreenImpl(core::CommandsQueue::Environment const & env,
                       ScreenBase const & screen,
                       int sequenceID);

  void MergeTileImpl(core::CommandsQueue::Environment const & env,
                     Tiler::RectInfo const & rectInfo,
                     int sequenceID);

  void InvalidateTilesImpl(m2::AnyRectD const & rect, int startScale);

  bool IsBackEmptyDrawing() const;

private:
  void FinishSequenceIfNeeded();
  void ComputeCoverTasks();
  void MergeOverlay();
  void MergeSingleTile(Tiler::RectInfo const & rectInfo);
  bool CacheCoverage(core::CommandsQueue::Environment const & env);

  void ClearCoverage();

private:
  struct BenchmarkInfo
  {
    int m_benchmarkSequenceID;
    int m_tilesCount;

    FenceManager m_fenceManager;
    int m_currentFenceID;

    bool m_isBenchmarking;

    BenchmarkInfo();

    void DecrementTileCount(int sequenceID);

    int InsertBenchmarkFence();
    void JoinBenchmarkFence(int fenceID);
    void SignalBenchmarkFence();
    void TryFinishSequence();
  } m_benchmarkInfo;

  struct StateInfo
  {
    bool m_isPause;
    bool m_needForceUpdate;
    int m_sequenceID;
    ScreenBase m_currentScreen;
    threads::Mutex m_mutex;

    StateInfo();

    void SetSequenceID(int sequenceID);
    void SetForceUpdate(bool needForceUpdate);

    void Pause();
    void Resume();
  } m_stateInfo;

  struct CoverageInfo
  {
    CoverageInfo(TileRenderer * tileRenderer);
    ~CoverageInfo();

    Tiler m_tiler;
    TileRenderer * m_tileRenderer;

    typedef set<Tile const *, LessRectInfo> TTileSet;
    TTileSet m_tiles;

    graphics::Overlay * m_overlay;
  } m_coverageInfo;

  struct CachedCoverageInfo
  {
    CachedCoverageInfo();
    ~CachedCoverageInfo();

    void ResetDL();

    graphics::DisplayList * m_mainElements;
    graphics::DisplayList * m_sharpElements;
    ScreenBase m_screen;
    int m_renderLeafTilesCount;
    bool m_isEmptyDrawing;
  };

  CachedCoverageInfo * m_currentCoverage;
  CachedCoverageInfo * m_backCoverage;

  core::CommandsQueue m_queue;
  shared_ptr<WindowHandle> m_windowHandle;
  shared_ptr<graphics::Screen> m_cacheScreen;
};