aboutsummaryrefslogtreecommitdiffstats
path: root/emulator/opengl/host/libs/Translator/EGL/EglGlobalInfo.cpp
blob: 95b696e2b9ff63981896c4e53fd1f8e283382178 (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
/*
* Copyright (C) 2011 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "EglGlobalInfo.h"
#include "EglOsApi.h"
#include <string.h>
#include "ClientAPIExts.h"

int EglGlobalInfo::m_refCount = 0;
EglGlobalInfo* EglGlobalInfo::m_singleton = NULL;


EglGlobalInfo::EglGlobalInfo(){
    m_default = EglOS::getDefaultDisplay();
#ifdef _WIN32
    EglOS::initPtrToWglFunctions();
#endif
    memset(m_gles_ifaces,0,sizeof(m_gles_ifaces));
    memset(m_gles_extFuncs_inited,0,sizeof(m_gles_extFuncs_inited));
}

EglGlobalInfo* EglGlobalInfo::getInstance() {
    if(!m_singleton) {
        m_singleton = new EglGlobalInfo();
        m_refCount = 0;
    }
    m_refCount++;
    return m_singleton;
}

void EglGlobalInfo::delInstance() {
    m_refCount--;
    if(m_refCount <= 0 && m_singleton) {
        delete m_singleton;
        m_singleton = NULL;
    }

}

EglDisplay* EglGlobalInfo::addDisplay(EGLNativeDisplayType dpy,EGLNativeInternalDisplayType idpy) {
    //search if it is not already exists
    emugl::Mutex::AutoLock mutex(m_lock);
    for(DisplaysMap::iterator it = m_displays.begin(); it != m_displays.end() ;it++) {
        if((*it).second == dpy) return (*it).first;
    }

    if (!EglOS::validNativeDisplay(idpy))
        return NULL;

    EglDisplay* p_dpy = new EglDisplay(idpy);
    if(p_dpy) {
        m_displays[p_dpy] = dpy;
        return p_dpy;
    }
    return NULL;
}

bool  EglGlobalInfo::removeDisplay(EGLDisplay dpy) {
    emugl::Mutex::AutoLock mutex(m_lock);
    for(DisplaysMap::iterator it = m_displays.begin(); it != m_displays.end() ;it++) {
        if(static_cast<EGLDisplay>((*it).first) == dpy) {
            delete (*it).first;
            m_displays.erase(it);
            return true;
        }
    }
    return false;
}

EglDisplay* EglGlobalInfo::getDisplay(EGLNativeDisplayType dpy) {
    emugl::Mutex::AutoLock mutex(m_lock);
    for(DisplaysMap::iterator it = m_displays.begin(); it != m_displays.end() ;it++) {
        if((*it).second == dpy) return (*it).first;
    }
    return NULL;
}

EglDisplay* EglGlobalInfo::getDisplay(EGLDisplay dpy) {
    emugl::Mutex::AutoLock mutex(m_lock);
    DisplaysMap::iterator it = m_displays.find(static_cast<EglDisplay*>(dpy));
    return (it != m_displays.end() ? (*it).first : NULL);
}

EGLNativeInternalDisplayType EglGlobalInfo::generateInternalDisplay(EGLNativeDisplayType dpy){
    return EglOS::getInternalDisplay(dpy);
}

void EglGlobalInfo::initClientExtFuncTable(GLESVersion ver)
{
    emugl::Mutex::AutoLock mutex(m_lock);
    if (!m_gles_extFuncs_inited[ver]) {
        ClientAPIExts::initClientFuncs(m_gles_ifaces[ver], (int)ver - 1);
        m_gles_extFuncs_inited[ver] = true;
    }
}