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

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

#include "drawer.hpp"

#include "../graphics/color.hpp"

#include "../geometry/rect2d.hpp"

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


class PaintEvent;
class ScreenBase;
class VideoTimer;

namespace anim
{
  class Controller;
}

namespace graphics
{
  class RenderContext;

  class Skin;
  class GlyphCache;
  class ResourceManager;
}

namespace anim
{
  class Controller;
  class Task;
}

class WindowHandle;

class RenderPolicy
{
public:

  typedef function<void(shared_ptr<PaintEvent>,
                        ScreenBase const &,
                        m2::RectD const &,
                        int)> TRenderFn;

protected:

  graphics::Color m_bgColor;
  shared_ptr<graphics::ResourceManager> m_resourceManager;
  shared_ptr<graphics::Skin> m_skin;
  shared_ptr<graphics::Screen> m_cacheScreen;
  shared_ptr<graphics::RenderContext> m_primaryRC;
  shared_ptr<WindowHandle> m_windowHandle;
  shared_ptr<Drawer> m_drawer;
  TRenderFn m_renderFn;
  bool m_doSupportRotation;
  bool m_doForceUpdate;
  m2::AnyRectD m_invalidRect;
  graphics::EDensity m_density;
  double m_visualScale;
  string m_skinName;
  anim::Controller * m_controller;
  shared_ptr<graphics::Overlay> m_overlay;

  void InitCacheScreen();

public:

  struct Params
  {
    VideoTimer * m_videoTimer;
    bool m_useDefaultFB;
    graphics::ResourceManager::Params m_rmParams;
    shared_ptr<graphics::RenderContext> m_primaryRC;
    graphics::EDensity m_density;
    string m_skinName;
    size_t m_screenWidth;
    size_t m_screenHeight;
  };

  /// constructor
  RenderPolicy(Params const & p,
               bool doSupportRotation,
               size_t idCacheSize);
  /// destructor
  virtual ~RenderPolicy();
  /// starting frame
  virtual void BeginFrame(shared_ptr<PaintEvent> const & e, ScreenBase const & s);
  /// drawing single frame
  virtual void DrawFrame(shared_ptr<PaintEvent> const & e, ScreenBase const & s) = 0;
  /// ending frame
  virtual void EndFrame(shared_ptr<PaintEvent> const & e, ScreenBase const & s);

  /// processing resize request
  virtual void OnSize(int w, int h);

  /// reacting on navigation actions
  /// @{
  virtual void StartDrag();
  virtual void DoDrag();
  virtual void StopDrag();

  virtual void StartScale();
  virtual void DoScale();
  virtual void StopScale();

  virtual void StartRotate(double a, double timeInSec);
  virtual void DoRotate(double a, double timeInSec);
  virtual void StopRotate(double a, double timeInSec);
  /// @}

  /// the start point of rendering in renderpolicy.
  virtual void SetRenderFn(TRenderFn const & renderFn);

  void SetAnimController(anim::Controller * controller);

  bool DoSupportRotation() const;
  virtual bool IsTiling() const;

  virtual bool NeedRedraw() const;
  virtual bool IsEmptyModel() const;

  bool DoForceUpdate() const;
  void SetForceUpdate(bool flag);

  bool IsAnimating() const;

  void SetInvalidRect(m2::AnyRectD const & glbRect);
  m2::AnyRectD const & GetInvalidRect() const;

  shared_ptr<Drawer> const & GetDrawer() const;
  shared_ptr<WindowHandle> const & GetWindowHandle() const;
  graphics::GlyphCache * GetGlyphCache() const;

  double VisualScale() const;
  virtual size_t TileSize() const { return 256; }
  graphics::EDensity Density() const;
  string const & SkinName() const;

  /// This function is used when we need to prevent race
  /// conditions on some resources, which could be modified
  /// from another threads.
  /// One example of such resource is a current graphics::Overlay
  /// object
  /// @{
  virtual void FrameLock();
  virtual void FrameUnlock();
  /// @}

  /// Get current graphics::Overlay object.
  /// Access to this resource should be synchronized using
  /// FrameLock/FrameUnlock methods
  virtual graphics::Overlay * FrameOverlay() const;

  /// Benchmarking protocol
  virtual int InsertBenchmarkFence();
  virtual void JoinBenchmarkFence(int fenceID);

  graphics::Color const GetBgColor() const;

  shared_ptr<graphics::Screen> const & GetCacheScreen() const;
  shared_ptr<graphics::ResourceManager> const & GetResourceManager() const { return m_resourceManager; }
  shared_ptr<graphics::RenderContext> const & GetRenderContext() const { return m_primaryRC; }

  graphics::Screen * CreateScreenWithParams(graphics::Screen::Params const & params) const;

protected:
  void InitWindowsHandle(VideoTimer * timer, shared_ptr<graphics::RenderContext> context);
  Drawer * CreateDrawer(bool isDefaultFB,
                        shared_ptr<graphics::RenderContext> context,
                        graphics::EStorageType storageType,
                        graphics::ETextureType textureType);

  size_t GetLargeTextureSize(bool useNpot);
  size_t GetMediumTextureSize(bool useNpot);
  size_t GetSmallTextureSize(bool useNpot);

  graphics::ResourceManager::StoragePoolParams GetStorageParam(size_t vertexCount,
                                                               size_t indexCount,
                                                               size_t batchSize,
                                                               graphics::EStorageType type);
  graphics::ResourceManager::TexturePoolParams GetTextureParam(size_t size,
                                                               size_t initCount,
                                                               graphics::DataFormat format,
                                                               graphics::ETextureType type);
};

RenderPolicy * CreateRenderPolicy(RenderPolicy::Params const & params);