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 
24 using namespace android;
25 using namespace android::renderscript;
26 
rsContextCreate(RsDevice vdev,uint32_t version,uint32_t sdkVersion,RsContextType ct,uint32_t flags)27 extern "C" RsContext rsContextCreate(RsDevice vdev, uint32_t version, uint32_t sdkVersion,
28                                       RsContextType ct, uint32_t flags) {
29     //ALOGV("rsContextCreate dev=%p", vdev);
30     Device * dev = static_cast<Device *>(vdev);
31     Context *rsc = Context::createContext(dev, nullptr, ct, flags);
32     if (rsc) {
33         rsc->setTargetSdkVersion(sdkVersion);
34     }
35     return rsc;
36 }
37 
rsaContextSetNativeLibDir(RsContext con,char * libDir,size_t length)38 extern "C" void rsaContextSetNativeLibDir(RsContext con, char *libDir, size_t length) {
39 #ifdef RS_COMPATIBILITY_LIB
40     Context *rsc = static_cast<Context *>(con);
41     rsc->setNativeLibDir(libDir, length);
42 #endif
43 }
44 
45 #ifndef RS_COMPATIBILITY_LIB
rsContextCreateGL(RsDevice vdev,uint32_t version,uint32_t sdkVersion,RsSurfaceConfig sc,uint32_t dpi)46 RsContext rsContextCreateGL(RsDevice vdev, uint32_t version,
47                             uint32_t sdkVersion, RsSurfaceConfig sc,
48                             uint32_t dpi) {
49     //ALOGV("rsContextCreateGL dev=%p", vdev);
50     Device * dev = static_cast<Device *>(vdev);
51     Context *rsc = Context::createContext(dev, &sc);
52     if (rsc) {
53         rsc->setTargetSdkVersion(sdkVersion);
54         rsc->setDPI(dpi);
55     }
56     //ALOGV("%p rsContextCreateGL ret", rsc);
57     return rsc;
58 }
59 #endif
60 
61 // Only to be called at a3d load time, before object is visible to user
62 // not thread safe
rsaGetName(RsContext con,void * obj,const char ** name)63 extern "C" void rsaGetName(RsContext con, void * obj, const char **name) {
64     ObjectBase *ob = static_cast<ObjectBase *>(obj);
65     (*name) = ob->getName();
66 }
67