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 "EglContext.h" 17 #include "EglDisplay.h" 18 #include "EglGlobalInfo.h" 19 #include "EglOsApi.h" 20 21 unsigned int EglContext::s_nextContextHndl = 0; 22 23 extern EglGlobalInfo* g_eglInfo; // defined in EglImp.cpp 24 25 bool EglContext::usingSurface(SurfacePtr surface) { 26 return surface.Ptr() == m_read.Ptr() || surface.Ptr() == m_draw.Ptr(); 27 } 28 29 EglContext::EglContext(EglDisplay *dpy, EGLNativeContextType context,ContextPtr shared_context, 30 EglConfig* config,GLEScontext* glesCtx,GLESVersion ver,ObjectNameManager* mngr): 31 m_dpy(dpy), 32 m_native(context), 33 m_config(config), 34 m_glesContext(glesCtx), 35 m_read(NULL), 36 m_draw(NULL), 37 m_version(ver), 38 m_mngr(mngr) 39 { 40 m_shareGroup = shared_context.Ptr()? 41 mngr->attachShareGroup(context,shared_context->nativeType()): 42 mngr->createShareGroup(context); 43 m_hndl = ++s_nextContextHndl; 44 } 45 46 EglContext::~EglContext() 47 { 48 49 // 50 // remove the context in the underlying OS layer 51 // 52 EglOS::destroyContext(m_dpy->nativeType(),m_native); 53 54 // 55 // call the client-api to remove the GLES context 56 // 57 g_eglInfo->getIface(version())->deleteGLESContext(m_glesContext); 58 59 if (m_mngr) 60 { 61 m_mngr->deleteShareGroup(m_native); 62 } 63 } 64 65 void EglContext::setSurfaces(SurfacePtr read,SurfacePtr draw) 66 { 67 m_read = read; 68 m_draw = draw; 69 } 70 71 bool EglContext::getAttrib(EGLint attrib,EGLint* value) { 72 switch(attrib) { 73 case EGL_CONFIG_ID: 74 *value = m_config->id(); 75 break; 76 default: 77 return false; 78 } 79 return true; 80 } 81 82 bool EglContext::attachImage(unsigned int imageId,ImagePtr img){ 83 if(m_attachedImages.find(imageId) == m_attachedImages.end()){ 84 m_attachedImages[imageId] = img; 85 return true; 86 } 87 return false; 88 } 89 90 void EglContext::detachImage(unsigned int imageId){ 91 m_attachedImages.erase(imageId); 92 } 93 94