• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 android::renderscript::Context;
25 using android::renderscript::Device;
26 using android::renderscript::ObjectBase;
27 
rsContextCreateVendor(RsDevice vdev,uint32_t version,uint32_t sdkVersion,RsContextType ct,uint32_t flags,const char * vendorDriverName)28 extern "C" RsContext rsContextCreateVendor(RsDevice vdev, uint32_t version, uint32_t sdkVersion,
29                                            RsContextType ct, uint32_t flags,
30                                            const char* vendorDriverName) {
31     Device * dev = static_cast<Device *>(vdev);
32     Context *rsc = Context::createContext(dev, nullptr, ct, flags, vendorDriverName);
33     if (rsc) {
34         rsc->setTargetSdkVersion(sdkVersion);
35     }
36     return rsc;
37 }
38 
rsContextCreate(RsDevice vdev,uint32_t version,uint32_t sdkVersion,RsContextType ct,uint32_t flags)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 
rsaContextSetNativeLibDir(RsContext con,char * libDir,size_t length)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 
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.
54 #if !defined(RS_VENDOR_LIB) && !defined(RS_COMPATIBILITY_LIB)
rsContextCreateGL(RsDevice vdev,uint32_t version,uint32_t sdkVersion,RsSurfaceConfig sc,uint32_t dpi)55 extern "C" RsContext rsContextCreateGL(RsDevice vdev, uint32_t version,
56                                        uint32_t sdkVersion, RsSurfaceConfig sc,
57                                        uint32_t dpi) {
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
rsaGetName(RsContext con,void * obj,const char ** name)72 extern "C" void rsaGetName(RsContext con, void * obj, const char **name) {
73     ObjectBase *ob = static_cast<ObjectBase *>(obj);
74     (*name) = ob->getName();
75 }
76