rsApiContext.cpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*
  2. * Copyright (C) 2016 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 "rsDevice.h"
  17. #include "rsContext.h"
  18. #include "rsThreadIO.h"
  19. #include "rsgApiStructs.h"
  20. #include "rsgApiFuncDecl.h"
  21. #include "rsFifo.h"
  22. using android::renderscript::Context;
  23. using android::renderscript::Device;
  24. using android::renderscript::ObjectBase;
  25. extern "C" RsContext rsContextCreateVendor(RsDevice vdev, uint32_t version, uint32_t sdkVersion,
  26. RsContextType ct, uint32_t flags,
  27. const char* vendorDriverName) {
  28. Device * dev = static_cast<Device *>(vdev);
  29. Context *rsc = Context::createContext(dev, nullptr, ct, flags, vendorDriverName);
  30. if (rsc) {
  31. rsc->setTargetSdkVersion(sdkVersion);
  32. }
  33. return rsc;
  34. }
  35. extern "C" RsContext rsContextCreate(RsDevice vdev, uint32_t version, uint32_t sdkVersion,
  36. RsContextType ct, uint32_t flags) {
  37. return rsContextCreateVendor(vdev, version, sdkVersion, ct, flags, nullptr);
  38. }
  39. extern "C" void rsaContextSetNativeLibDir(RsContext con, char *libDir, size_t length) {
  40. #ifdef RS_COMPATIBILITY_LIB
  41. Context *rsc = static_cast<Context *>(con);
  42. rsc->setNativeLibDir(libDir, length);
  43. #endif
  44. }
  45. // TODO: Figure out better naming schemes for all the rs* functions.
  46. // Currently they share the same names as the NDK counterparts, and that is
  47. // causing lots of confusion.
  48. #if !defined(RS_VENDOR_LIB) && !defined(RS_COMPATIBILITY_LIB)
  49. extern "C" RsContext rsContextCreateGL(RsDevice vdev, uint32_t version,
  50. uint32_t sdkVersion, RsSurfaceConfig sc,
  51. uint32_t dpi) {
  52. //ALOGV("rsContextCreateGL dev=%p", vdev);
  53. Device * dev = static_cast<Device *>(vdev);
  54. Context *rsc = Context::createContext(dev, &sc);
  55. if (rsc) {
  56. rsc->setTargetSdkVersion(sdkVersion);
  57. rsc->setDPI(dpi);
  58. }
  59. //ALOGV("%p rsContextCreateGL ret", rsc);
  60. return rsc;
  61. }
  62. #endif
  63. // Only to be called at a3d load time, before object is visible to user
  64. // not thread safe
  65. extern "C" void rsaGetName(RsContext con, void * obj, const char **name) {
  66. ObjectBase *ob = static_cast<ObjectBase *>(obj);
  67. (*name) = ob->getName();
  68. }