1e5c31af7Sopenharmony_ci/*------------------------------------------------------------------------- 2e5c31af7Sopenharmony_ci * drawElements Quality Program EGL Module 3e5c31af7Sopenharmony_ci * --------------------------------------- 4e5c31af7Sopenharmony_ci * 5e5c31af7Sopenharmony_ci * Copyright 2014 The Android Open Source Project 6e5c31af7Sopenharmony_ci * 7e5c31af7Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 8e5c31af7Sopenharmony_ci * you may not use this file except in compliance with the License. 9e5c31af7Sopenharmony_ci * You may obtain a copy of the License at 10e5c31af7Sopenharmony_ci * 11e5c31af7Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 12e5c31af7Sopenharmony_ci * 13e5c31af7Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 14e5c31af7Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 15e5c31af7Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16e5c31af7Sopenharmony_ci * See the License for the specific language governing permissions and 17e5c31af7Sopenharmony_ci * limitations under the License. 18e5c31af7Sopenharmony_ci * 19e5c31af7Sopenharmony_ci *//*! 20e5c31af7Sopenharmony_ci * \file 21e5c31af7Sopenharmony_ci * \brief glw::FunctionLoader using eglGetProcAddress() and tcu::Library. 22e5c31af7Sopenharmony_ci *//*--------------------------------------------------------------------*/ 23e5c31af7Sopenharmony_ci 24e5c31af7Sopenharmony_ci#include "egluGLFunctionLoader.hpp" 25e5c31af7Sopenharmony_ci#include "egluPlatform.hpp" 26e5c31af7Sopenharmony_ci#include "eglwLibrary.hpp" 27e5c31af7Sopenharmony_ci#include "tcuFunctionLibrary.hpp" 28e5c31af7Sopenharmony_ci 29e5c31af7Sopenharmony_cinamespace eglu 30e5c31af7Sopenharmony_ci{ 31e5c31af7Sopenharmony_ci 32e5c31af7Sopenharmony_ciGLFunctionLoader::GLFunctionLoader (const eglw::Library& egl, const tcu::FunctionLibrary* library) 33e5c31af7Sopenharmony_ci : m_egl (egl) 34e5c31af7Sopenharmony_ci , m_library (library) 35e5c31af7Sopenharmony_ci{ 36e5c31af7Sopenharmony_ci} 37e5c31af7Sopenharmony_ci 38e5c31af7Sopenharmony_ciglw::GenericFuncType GLFunctionLoader::get (const char* name) const 39e5c31af7Sopenharmony_ci{ 40e5c31af7Sopenharmony_ci glw::GenericFuncType func = (glw::GenericFuncType)m_library->getFunction(name); 41e5c31af7Sopenharmony_ci 42e5c31af7Sopenharmony_ci if (!func) 43e5c31af7Sopenharmony_ci return (glw::GenericFuncType)m_egl.getProcAddress(name); 44e5c31af7Sopenharmony_ci else 45e5c31af7Sopenharmony_ci return func; 46e5c31af7Sopenharmony_ci} 47e5c31af7Sopenharmony_ci 48e5c31af7Sopenharmony_ciGLLibraryCache::GLLibraryCache (const Platform& platform, const tcu::CommandLine& cmdLine) 49e5c31af7Sopenharmony_ci : m_platform (platform) 50e5c31af7Sopenharmony_ci , m_cmdLine (cmdLine) 51e5c31af7Sopenharmony_ci{ 52e5c31af7Sopenharmony_ci} 53e5c31af7Sopenharmony_ci 54e5c31af7Sopenharmony_ciGLLibraryCache::~GLLibraryCache (void) 55e5c31af7Sopenharmony_ci{ 56e5c31af7Sopenharmony_ci for (LibraryMap::iterator i = m_libraries.begin(); i != m_libraries.end(); ++i) 57e5c31af7Sopenharmony_ci delete i->second; 58e5c31af7Sopenharmony_ci} 59e5c31af7Sopenharmony_ci 60e5c31af7Sopenharmony_ciconst tcu::FunctionLibrary* GLLibraryCache::getLibrary (glu::ApiType apiType) 61e5c31af7Sopenharmony_ci{ 62e5c31af7Sopenharmony_ci tcu::FunctionLibrary* library = DE_NULL; 63e5c31af7Sopenharmony_ci const deUint32 key = apiType.getPacked(); 64e5c31af7Sopenharmony_ci LibraryMap::iterator iter = m_libraries.find(key); 65e5c31af7Sopenharmony_ci 66e5c31af7Sopenharmony_ci if (iter == m_libraries.end()) 67e5c31af7Sopenharmony_ci { 68e5c31af7Sopenharmony_ci library = m_platform.createDefaultGLFunctionLibrary(apiType, m_cmdLine); 69e5c31af7Sopenharmony_ci try 70e5c31af7Sopenharmony_ci { 71e5c31af7Sopenharmony_ci m_libraries.insert(std::make_pair(key, library)); 72e5c31af7Sopenharmony_ci } 73e5c31af7Sopenharmony_ci catch (...) 74e5c31af7Sopenharmony_ci { 75e5c31af7Sopenharmony_ci delete library; 76e5c31af7Sopenharmony_ci throw; 77e5c31af7Sopenharmony_ci } 78e5c31af7Sopenharmony_ci } 79e5c31af7Sopenharmony_ci else 80e5c31af7Sopenharmony_ci library = iter->second; 81e5c31af7Sopenharmony_ci 82e5c31af7Sopenharmony_ci return library; 83e5c31af7Sopenharmony_ci} 84e5c31af7Sopenharmony_ci 85e5c31af7Sopenharmony_ci} // eglu 86