1 /* 2 * Copyright (C) 2011 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 #include "EglGlobalInfo.h" 17 #include "EglOsApi.h" 18 #include <string.h> 19 #include "ClientAPIExts.h" 20 21 int EglGlobalInfo::m_refCount = 0; 22 EglGlobalInfo* EglGlobalInfo::m_singleton = NULL; 23 24 25 EglGlobalInfo::EglGlobalInfo(){ 26 m_default = EglOS::getDefaultDisplay(); 27 #ifdef _WIN32 28 EglOS::initPtrToWglFunctions(); 29 #endif 30 memset(m_gles_ifaces,0,sizeof(m_gles_ifaces)); 31 memset(m_gles_extFuncs_inited,0,sizeof(m_gles_extFuncs_inited)); 32 } 33 34 EglGlobalInfo* EglGlobalInfo::getInstance() { 35 if(!m_singleton) { 36 m_singleton = new EglGlobalInfo(); 37 m_refCount = 0; 38 } 39 m_refCount++; 40 return m_singleton; 41 } 42 43 void EglGlobalInfo::delInstance() { 44 m_refCount--; 45 if(m_refCount <= 0 && m_singleton) { 46 delete m_singleton; 47 m_singleton = NULL; 48 } 49 50 } 51 52 EglDisplay* EglGlobalInfo::addDisplay(EGLNativeDisplayType dpy,EGLNativeInternalDisplayType idpy) { 53 //search if it is not already exists 54 android::Mutex::Autolock mutex(m_lock); 55 for(DisplaysMap::iterator it = m_displays.begin(); it != m_displays.end() ;it++) { 56 if((*it).second == dpy) return (*it).first; 57 } 58 59 if (!EglOS::validNativeDisplay(idpy)) 60 return NULL; 61 62 EglDisplay* p_dpy = new EglDisplay(idpy); 63 if(p_dpy) { 64 m_displays[p_dpy] = dpy; 65 return p_dpy; 66 } 67 return NULL; 68 } 69 70 bool EglGlobalInfo::removeDisplay(EGLDisplay dpy) { 71 android::Mutex::Autolock mutex(m_lock); 72 for(DisplaysMap::iterator it = m_displays.begin(); it != m_displays.end() ;it++) { 73 if(static_cast<EGLDisplay>((*it).first) == dpy) { 74 delete (*it).first; 75 m_displays.erase(it); 76 return true; 77 } 78 } 79 return false; 80 } 81 82 EglDisplay* EglGlobalInfo::getDisplay(EGLNativeDisplayType dpy) { 83 android::Mutex::Autolock mutex(m_lock); 84 for(DisplaysMap::iterator it = m_displays.begin(); it != m_displays.end() ;it++) { 85 if((*it).second == dpy) return (*it).first; 86 } 87 return NULL; 88 } 89 90 EglDisplay* EglGlobalInfo::getDisplay(EGLDisplay dpy) { 91 android::Mutex::Autolock mutex(m_lock); 92 DisplaysMap::iterator it = m_displays.find(static_cast<EglDisplay*>(dpy)); 93 return (it != m_displays.end() ? (*it).first : NULL); 94 } 95 96 EGLNativeInternalDisplayType EglGlobalInfo::generateInternalDisplay(EGLNativeDisplayType dpy){ 97 return EglOS::getInternalDisplay(dpy); 98 } 99 100 void EglGlobalInfo::initClientExtFuncTable(GLESVersion ver) 101 { 102 android::Mutex::Autolock mutex(m_lock); 103 if (!m_gles_extFuncs_inited[ver]) { 104 ClientAPIExts::initClientFuncs(m_gles_ifaces[ver], (int)ver - 1); 105 m_gles_extFuncs_inited[ver] = true; 106 } 107 } 108