1 // Copyright (C) 2017 The Android Open Source Project 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 #include "OpenGLDispatchLoader.h" 16 17 #include "OpenGLESDispatch/DispatchTables.h" 18 19 GLESv1Dispatch s_gles1; 20 GLESv2Dispatch s_gles2; 21 22 using emugl::LazyLoadedGLESv1Dispatch; 23 using emugl::LazyLoadedGLESv2Dispatch; 24 using emugl::LazyLoadedEGLDispatch; 25 26 // Must be declared outside of LazyLoaded*Dispatch scope due to the use of 27 // sizeof(T) within the template definition. sGLESv1Dispatch()28static LazyLoadedGLESv1Dispatch* sGLESv1Dispatch() { 29 static LazyLoadedGLESv1Dispatch* l = new LazyLoadedGLESv1Dispatch; 30 return l; 31 } sGLESv2Dispatch()32static LazyLoadedGLESv2Dispatch* sGLESv2Dispatch() { 33 static LazyLoadedGLESv2Dispatch* l = new LazyLoadedGLESv2Dispatch; 34 return l; 35 } sEGLDispatch()36static LazyLoadedEGLDispatch* sEGLDispatch() { 37 static LazyLoadedEGLDispatch* l = new LazyLoadedEGLDispatch; 38 return l; 39 } 40 41 // static get()42const GLESv1Dispatch* LazyLoadedGLESv1Dispatch::get() { 43 LazyLoadedGLESv1Dispatch* instance = sGLESv1Dispatch(); 44 if (instance->mValid) { 45 return &s_gles1; 46 } else { 47 return nullptr; 48 } 49 } 50 LazyLoadedGLESv1Dispatch()51LazyLoadedGLESv1Dispatch::LazyLoadedGLESv1Dispatch() { 52 LazyLoadedEGLDispatch::get(); 53 mValid = gles1_dispatch_init(&s_gles1); 54 } 55 56 // static get()57const GLESv2Dispatch* LazyLoadedGLESv2Dispatch::get() { 58 LazyLoadedGLESv2Dispatch* instance = sGLESv2Dispatch(); 59 if (instance->mValid) { 60 return &s_gles2; 61 } else { 62 return nullptr; 63 } 64 } 65 LazyLoadedGLESv2Dispatch()66LazyLoadedGLESv2Dispatch::LazyLoadedGLESv2Dispatch() { 67 LazyLoadedEGLDispatch::get(); 68 mValid = gles2_dispatch_init(&s_gles2); 69 } 70 71 // static get()72const EGLDispatch* LazyLoadedEGLDispatch::get() { 73 LazyLoadedEGLDispatch* instance = sEGLDispatch(); 74 if (instance->mValid) { 75 return &s_egl; 76 } else { 77 return nullptr; 78 } 79 } 80 LazyLoadedEGLDispatch()81LazyLoadedEGLDispatch::LazyLoadedEGLDispatch() { mValid = init_egl_dispatch(); } 82