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