Home | History | Annotate | Download | only in EGL
      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     EglDisplay* p_dpy = new EglDisplay(idpy);
     60     if(p_dpy) {
     61         m_displays[p_dpy] = dpy;
     62         return p_dpy;
     63     }
     64     return NULL;
     65 }
     66 
     67 bool  EglGlobalInfo::removeDisplay(EGLDisplay dpy) {
     68     android::Mutex::Autolock mutex(m_lock);
     69     for(DisplaysMap::iterator it = m_displays.begin(); it != m_displays.end() ;it++) {
     70         if(static_cast<EGLDisplay>((*it).first) == dpy) {
     71             delete (*it).first;
     72             m_displays.erase(it);
     73             return true;
     74         }
     75     }
     76     return false;
     77 }
     78 
     79 EglDisplay* EglGlobalInfo::getDisplay(EGLNativeDisplayType dpy) {
     80     android::Mutex::Autolock mutex(m_lock);
     81     for(DisplaysMap::iterator it = m_displays.begin(); it != m_displays.end() ;it++) {
     82         if((*it).second == dpy) return (*it).first;
     83     }
     84     return NULL;
     85 }
     86 
     87 EglDisplay* EglGlobalInfo::getDisplay(EGLDisplay dpy) {
     88     android::Mutex::Autolock mutex(m_lock);
     89     DisplaysMap::iterator it = m_displays.find(static_cast<EglDisplay*>(dpy));
     90     return (it != m_displays.end() ? (*it).first : NULL);
     91 }
     92 
     93 EGLNativeInternalDisplayType EglGlobalInfo::generateInternalDisplay(EGLNativeDisplayType dpy){
     94     return EglOS::getInternalDisplay(dpy);
     95 }
     96 
     97 void EglGlobalInfo::initClientExtFuncTable(GLESVersion ver)
     98 {
     99     android::Mutex::Autolock mutex(m_lock);
    100     if (!m_gles_extFuncs_inited[ver]) {
    101         ClientAPIExts::initClientFuncs(m_gles_ifaces[ver], (int)ver - 1);
    102         m_gles_extFuncs_inited[ver] = true;
    103     }
    104 }
    105