rsFallbackAdaptation.cpp 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*
  2. * Copyright (C) 2017 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 "cpp/rsDispatch.h"
  17. #include "rsFallbackAdaptation.h"
  18. #include <log/log.h>
  19. #include <dlfcn.h>
  20. #undef LOG_TAG
  21. #define LOG_TAG "RenderScript Graphics Fallback"
  22. dispatchTable RsFallbackAdaptation::mEntryFuncs;
  23. RsFallbackAdaptation::RsFallbackAdaptation()
  24. {
  25. void* handle = dlopen("libRS_internal.so", RTLD_LAZY | RTLD_LOCAL);
  26. if (handle == NULL) {
  27. ALOGE("couldn't dlopen %s.", dlerror());
  28. return;
  29. }
  30. if (loadSymbols(handle, mEntryFuncs) == false) {
  31. // If dispatch table initialization failed, the dispatch table
  32. // will be reset, and calling function pointers of uninitialized
  33. // dispatch table will crash the application.
  34. ALOGE("Fallback dispatch table init failed!");
  35. mEntryFuncs = {};
  36. dlclose(handle);
  37. }
  38. }
  39. RsFallbackAdaptation& RsFallbackAdaptation::GetInstance()
  40. {
  41. // This function-local-static guarantees the instance is a singleton. The
  42. // constructor of RsHidlAdaptation will only be called when GetInstance is
  43. // called for the first time.
  44. static RsFallbackAdaptation instance;
  45. return instance;
  46. }
  47. const dispatchTable* RsFallbackAdaptation::GetEntryFuncs()
  48. {
  49. return &mEntryFuncs;
  50. }