1*e1eccf28SAndroid Build Coastguard Worker /* 2*e1eccf28SAndroid Build Coastguard Worker * Copyright (C) 2017 The Android Open Source Project 3*e1eccf28SAndroid Build Coastguard Worker * 4*e1eccf28SAndroid Build Coastguard Worker * Licensed under the Apache License, Version 2.0 (the "License"); 5*e1eccf28SAndroid Build Coastguard Worker * you may not use this file except in compliance with the License. 6*e1eccf28SAndroid Build Coastguard Worker * You may obtain a copy of the License at 7*e1eccf28SAndroid Build Coastguard Worker * 8*e1eccf28SAndroid Build Coastguard Worker * http://www.apache.org/licenses/LICENSE-2.0 9*e1eccf28SAndroid Build Coastguard Worker * 10*e1eccf28SAndroid Build Coastguard Worker * Unless required by applicable law or agreed to in writing, software 11*e1eccf28SAndroid Build Coastguard Worker * distributed under the License is distributed on an "AS IS" BASIS, 12*e1eccf28SAndroid Build Coastguard Worker * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13*e1eccf28SAndroid Build Coastguard Worker * See the License for the specific language governing permissions and 14*e1eccf28SAndroid Build Coastguard Worker * limitations under the License. 15*e1eccf28SAndroid Build Coastguard Worker */ 16*e1eccf28SAndroid Build Coastguard Worker 17*e1eccf28SAndroid Build Coastguard Worker #include "cpp/rsDispatch.h" 18*e1eccf28SAndroid Build Coastguard Worker #include "rsFallbackAdaptation.h" 19*e1eccf28SAndroid Build Coastguard Worker 20*e1eccf28SAndroid Build Coastguard Worker #include <log/log.h> 21*e1eccf28SAndroid Build Coastguard Worker #include <dlfcn.h> 22*e1eccf28SAndroid Build Coastguard Worker 23*e1eccf28SAndroid Build Coastguard Worker #undef LOG_TAG 24*e1eccf28SAndroid Build Coastguard Worker #define LOG_TAG "RenderScript Graphics Fallback" 25*e1eccf28SAndroid Build Coastguard Worker 26*e1eccf28SAndroid Build Coastguard Worker dispatchTable RsFallbackAdaptation::mEntryFuncs; 27*e1eccf28SAndroid Build Coastguard Worker RsFallbackAdaptation()28*e1eccf28SAndroid Build Coastguard WorkerRsFallbackAdaptation::RsFallbackAdaptation() 29*e1eccf28SAndroid Build Coastguard Worker { 30*e1eccf28SAndroid Build Coastguard Worker void* handle = dlopen("libRS_internal.so", RTLD_LAZY | RTLD_LOCAL); 31*e1eccf28SAndroid Build Coastguard Worker if (handle == NULL) { 32*e1eccf28SAndroid Build Coastguard Worker ALOGE("couldn't dlopen %s.", dlerror()); 33*e1eccf28SAndroid Build Coastguard Worker return; 34*e1eccf28SAndroid Build Coastguard Worker } 35*e1eccf28SAndroid Build Coastguard Worker if (loadSymbols(handle, mEntryFuncs) == false) { 36*e1eccf28SAndroid Build Coastguard Worker // If dispatch table initialization failed, the dispatch table 37*e1eccf28SAndroid Build Coastguard Worker // will be reset, and calling function pointers of uninitialized 38*e1eccf28SAndroid Build Coastguard Worker // dispatch table will crash the application. 39*e1eccf28SAndroid Build Coastguard Worker ALOGE("Fallback dispatch table init failed!"); 40*e1eccf28SAndroid Build Coastguard Worker mEntryFuncs = {}; 41*e1eccf28SAndroid Build Coastguard Worker dlclose(handle); 42*e1eccf28SAndroid Build Coastguard Worker } 43*e1eccf28SAndroid Build Coastguard Worker } 44*e1eccf28SAndroid Build Coastguard Worker GetInstance()45*e1eccf28SAndroid Build Coastguard WorkerRsFallbackAdaptation& RsFallbackAdaptation::GetInstance() 46*e1eccf28SAndroid Build Coastguard Worker { 47*e1eccf28SAndroid Build Coastguard Worker // This function-local-static guarantees the instance is a singleton. The 48*e1eccf28SAndroid Build Coastguard Worker // constructor of RsHidlAdaptation will only be called when GetInstance is 49*e1eccf28SAndroid Build Coastguard Worker // called for the first time. 50*e1eccf28SAndroid Build Coastguard Worker static RsFallbackAdaptation instance; 51*e1eccf28SAndroid Build Coastguard Worker return instance; 52*e1eccf28SAndroid Build Coastguard Worker } 53*e1eccf28SAndroid Build Coastguard Worker GetEntryFuncs()54*e1eccf28SAndroid Build Coastguard Workerconst dispatchTable* RsFallbackAdaptation::GetEntryFuncs() 55*e1eccf28SAndroid Build Coastguard Worker { 56*e1eccf28SAndroid Build Coastguard Worker return &mEntryFuncs; 57*e1eccf28SAndroid Build Coastguard Worker } 58*e1eccf28SAndroid Build Coastguard Worker 59