summaryrefslogtreecommitdiff
path: root/src/graphics/Display.cpp
blob: 22d2c62561424453d47f6f86004cf9d146ab2354 (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
//
//  libavg - Media Playback Engine. 
//  Copyright (C) 2003-2014 Ulrich von Zadow
//
//  This library is free software; you can redistribute it and/or
//  modify it under the terms of the GNU Lesser General Public
//  License as published by the Free Software Foundation; either
//  version 2 of the License, or (at your option) any later version.
//
//  This library is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
//  Lesser General Public License for more details.
//
//  You should have received a copy of the GNU Lesser General Public
//  License along with this library; if not, write to the Free Software
//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
//
//  Current versions can be found at www.libavg.de
//

#include "Display.h"
#ifdef __linux__
#include "X11Display.h"
#endif
#ifdef __APPLE__
#include "AppleDisplay.h"
#endif
#ifdef _WIN32
#include "WinDisplay.h"
#endif
#include "Bitmap.h"

#include "../base/Logger.h"

#include <SDL/SDL.h>
#include <SDL/SDL_syswm.h>

#include <iostream>

using namespace std;

namespace avg {

DisplayPtr Display::s_pInstance = DisplayPtr();

DisplayPtr Display::get()
{
    if (!s_pInstance) {
#ifdef __linux__
        s_pInstance = DisplayPtr(new X11Display());
#elif defined __APPLE__
        s_pInstance = DisplayPtr(new AppleDisplay());
#elif defined _WIN32
        s_pInstance = DisplayPtr(new WinDisplay());
#else
        AVG_ASSERT(false);
#endif
        s_pInstance->init();
    }
    return s_pInstance;
}

bool Display::isInitialized()
{
    return s_pInstance;
}

Display::Display()
    : m_bAutoPPMM(true),
      m_RefreshRate(0.0f)
{
}

Display::~Display()
{
}

void Display::init()
{
    m_ScreenResolution = queryScreenResolution();
    m_PPMM = queryPPMM();
}

void Display::rereadScreenResolution()
{
    m_ScreenResolution = queryScreenResolution();
    if (m_bAutoPPMM) {
        m_PPMM = queryPPMM();
    }
}

IntPoint Display::getScreenResolution()
{
    return m_ScreenResolution;
}

float Display::getPixelsPerMM()
{
    return m_PPMM;
}

void Display::assumePixelsPerMM(float ppmm)
{
    if (ppmm != 0) {
        m_PPMM = ppmm;
        m_bAutoPPMM = false;
    }
}

glm::vec2 Display::getPhysicalScreenDimensions()
{
    glm::vec2 size;
    glm::vec2 screenRes = glm::vec2(getScreenResolution());
    size.x = screenRes.x/m_PPMM;
    size.y = screenRes.y/m_PPMM;
    return size;
}

IntPoint Display::queryScreenResolution()
{
    const SDL_VideoInfo* pInfo = SDL_GetVideoInfo();
    return IntPoint(pInfo->current_w, pInfo->current_h);
}

float Display::getRefreshRate()
{
    if (m_RefreshRate == 0.0) {
        m_RefreshRate = queryRefreshRate();
        AVG_TRACE(Logger::category::CONFIG, Logger::severity::INFO,
                "Vertical Refresh Rate: " << m_RefreshRate);
    }
    return m_RefreshRate;
}

}