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

text_handle.cpp « drape_frontend - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: f256158f7f40eff88f13075acaa29413a4e1f978 (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
#include "drape_frontend/text_handle.hpp"

#include "drape/texture_manager.hpp"

#include "base/logging.hpp"

namespace df
{

TextHandle::TextHandle(FeatureID const & id, strings::UniString const & text,
                       dp::Anchor anchor, uint64_t priority,
                       ref_ptr<dp::TextureManager> textureManager,
                       bool isBillboard)
  : OverlayHandle(id, anchor, priority, isBillboard)
  , m_forceUpdateNormals(false)
  , m_isLastVisible(false)
  , m_text(text)
  , m_textureManager(textureManager)
  , m_glyphsReady(false)
{}

TextHandle::TextHandle(FeatureID const & id, strings::UniString const & text,
                       dp::Anchor anchor, uint64_t priority,
                       ref_ptr<dp::TextureManager> textureManager,
                       gpu::TTextDynamicVertexBuffer && normals,
                       bool isBillboard)
  : OverlayHandle(id, anchor, priority, isBillboard)
  , m_buffer(move(normals))
  , m_forceUpdateNormals(false)
  , m_isLastVisible(false)
  , m_text(text)
  , m_textureManager(textureManager)
  , m_glyphsReady(false)
{}

void TextHandle::GetAttributeMutation(ref_ptr<dp::AttributeBufferMutator> mutator) const
{
  bool const isVisible = IsVisible();
  if (!m_forceUpdateNormals && m_isLastVisible == isVisible)
    return;

  TOffsetNode const & node = GetOffsetNode(gpu::TextDynamicVertex::GetDynamicStreamID());
  ASSERT(node.first.GetElementSize() == sizeof(gpu::TextDynamicVertex), ());
  ASSERT(node.second.m_count == m_buffer.size(), ());

  uint32_t byteCount = m_buffer.size() * sizeof(gpu::TextDynamicVertex);
  void * buffer = mutator->AllocateMutationBuffer(byteCount);
  if (isVisible)
    memcpy(buffer, m_buffer.data(), byteCount);
  else
    memset(buffer, 0, byteCount);

  dp::MutateNode mutateNode;
  mutateNode.m_region = node.second;
  mutateNode.m_data = make_ref(buffer);
  mutator->AddMutation(node.first, mutateNode);

  m_isLastVisible = isVisible;
}

bool TextHandle::Update(ScreenBase const & screen)
{
  if (!m_glyphsReady)
    m_glyphsReady = m_textureManager->AreGlyphsReady(m_text);

  return m_glyphsReady;
}

bool TextHandle::IndexesRequired() const
{
  // Disable indices usage for text handles.
  return false;
}

void TextHandle::SetForceUpdateNormals(bool forceUpdate) const
{
  m_forceUpdateNormals = forceUpdate;
}

#ifdef DEBUG_OVERLAYS_OUTPUT
string TextHandle::GetOverlayDebugInfo()
{
  ostringstream out;
  out << "Text Priority(" << GetPriority() << ") " << GetFeatureID().m_index << " " << strings::ToUtf8(m_text);
  return out.str();
}
#endif

} // namespace df