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

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

#include "drape_frontend/viewport.hpp"

#include "base/logging.hpp"

DrapeSurface::DrapeSurface()
  : m_contextFactory(nullptr)
{
  setSurfaceType(QSurface::OpenGLSurface);

  QObject::connect(this, SIGNAL(heightChanged(int)), this, SLOT(sizeChanged(int)));
  QObject::connect(this, SIGNAL(widthChanged(int)), this,  SLOT(sizeChanged(int)));
}

DrapeSurface::~DrapeSurface()
{
  m_drapeEngine.Destroy();
  m_contextFactory.Destroy();
}

void DrapeSurface::exposeEvent(QExposeEvent *e)
{
  Q_UNUSED(e);

  if (isExposed())
  {
    if (m_contextFactory.IsNull())
    {
      dp::ThreadSafeFactory * factory = new dp::ThreadSafeFactory(new QtOGLContextFactory(this), false);
      m_contextFactory = dp::MasterPointer<dp::OGLContextFactory>(factory);
      CreateEngine();
    }
  }
}

void DrapeSurface::CreateEngine()
{
  dp::RefPointer<dp::OGLContextFactory> f(m_contextFactory.GetRefPointer());

  float const pixelRatio = devicePixelRatio();

  m_drapeEngine = TEnginePrt(new df::TestingEngine(f, df::Viewport(0, 0, pixelRatio * width(), pixelRatio * height()), pixelRatio));
}

void DrapeSurface::sizeChanged(int)
{
  if (!m_drapeEngine.IsNull())
  {
    float const vs = devicePixelRatio();
    int const w = width() * vs;
    int const h = height() * vs;
    m_drapeEngine->Resize(w, h);
  }
}