1 /*
2  * Copyright (C) 2018 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 #ifndef ANDROID_HARDWARE_RENDERSCRIPT_V1_0_CONTEXT_H
18 #define ANDROID_HARDWARE_RENDERSCRIPT_V1_0_CONTEXT_H
19 
20 #include "cpp/rsDispatch.h"
21 #include "dlfcn.h"
22 #include <android/hardware/renderscript/1.0/IContext.h>
23 #include <hidl/MQDescriptor.h>
24 #include <hidl/Status.h>
25 
26 namespace android {
27 namespace hardware {
28 namespace renderscript {
29 namespace V1_0 {
30 namespace implementation {
31 
32 using ::android::hardware::renderscript::V1_0::AllocationCubemapFace;
33 using ::android::hardware::renderscript::V1_0::AllocationMipmapControl;
34 using ::android::hardware::renderscript::V1_0::AllocationUsageType;
35 using ::android::hardware::renderscript::V1_0::ContextType;
36 using ::android::hardware::renderscript::V1_0::DataKind;
37 using ::android::hardware::renderscript::V1_0::DataType;
38 using ::android::hardware::renderscript::V1_0::IContext;
39 using ::android::hardware::renderscript::V1_0::MessageToClientType;
40 using ::android::hardware::renderscript::V1_0::SamplerValue;
41 using ::android::hardware::renderscript::V1_0::ScriptCall;
42 using ::android::hardware::renderscript::V1_0::ScriptIntrinsicID;
43 using ::android::hardware::renderscript::V1_0::ThreadPriorities;
44 using ::android::hardware::renderscript::V1_0::YuvFormat;
45 using ::android::hidl::base::V1_0::IBase;
46 using ::android::hardware::hidl_string;
47 using ::android::hardware::hidl_vec;
48 using ::android::hardware::Return;
49 using ::android::hardware::Void;
50 using ::android::sp;
51 
52 struct Context : public IContext {
53     Context(uint32_t sdkVersion, ContextType ct, int32_t flags);
54 
55     // Methods from ::android::hardware::renderscript::V1_0::IContext follow.
56     Return<Allocation> allocationAdapterCreate(Type type, Allocation baseAlloc) override;
57     Return<void> allocationAdapterOffset(Allocation alloc, const hidl_vec<uint32_t>& offsets) override;
58     Return<Type> allocationGetType(Allocation allocation) override;
59     Return<Allocation> allocationCreateTyped(Type type, AllocationMipmapControl amips, int32_t usage, Ptr ptr) override;
60     Return<Allocation> allocationCreateFromBitmap(Type type, AllocationMipmapControl amips, const hidl_vec<uint8_t>& bitmap, int32_t usage) override;
61     Return<Allocation> allocationCubeCreateFromBitmap(Type type, AllocationMipmapControl amips, const hidl_vec<uint8_t>& bitmap, int32_t usage) override;
62     Return<NativeWindow> allocationGetNativeWindow(Allocation allocation) override;
63     Return<void> allocationSetNativeWindow(Allocation allocation, NativeWindow nativewindow) override;
64     Return<void> allocationSetupBufferQueue(Allocation alloc, uint32_t numBuffer) override;
65     Return<void> allocationShareBufferQueue(Allocation baseAlloc, Allocation subAlloc) override;
66     Return<void> allocationCopyToBitmap(Allocation allocation, Ptr data, Size sizeBytes) override;
67     Return<void> allocation1DWrite(Allocation allocation, uint32_t offset, uint32_t lod, uint32_t count, const hidl_vec<uint8_t>& data) override;
68     Return<void> allocationElementWrite(Allocation allocation, uint32_t x, uint32_t y, uint32_t z, uint32_t lod, const hidl_vec<uint8_t>& data, Size compIdx) override;
69     Return<void> allocation2DWrite(Allocation allocation, uint32_t xoff, uint32_t yoff, uint32_t lod, AllocationCubemapFace face, uint32_t w, uint32_t h, const hidl_vec<uint8_t>& data, Size stride) override;
70     Return<void> allocation3DWrite(Allocation allocation, uint32_t xoff, uint32_t yoff, uint32_t zoff, uint32_t lod, uint32_t w, uint32_t h, uint32_t d, const hidl_vec<uint8_t>& data, Size stride) override;
71     Return<void> allocationGenerateMipmaps(Allocation allocation) override;
72     Return<void> allocationRead(Allocation allocation, Ptr data, Size sizeBytes) override;
73     Return<void> allocation1DRead(Allocation allocation, uint32_t xoff, uint32_t lod, uint32_t count, Ptr data, Size sizeBytes) override;
74     Return<void> allocationElementRead(Allocation allocation, uint32_t x, uint32_t y, uint32_t z, uint32_t lod, Ptr data, Size sizeBytes, Size compIdx) override;
75     Return<void> allocation2DRead(Allocation allocation, uint32_t xoff, uint32_t yoff, uint32_t lod, AllocationCubemapFace face, uint32_t w, uint32_t h, Ptr data, Size sizeBytes, Size stride) override;
76     Return<void> allocation3DRead(Allocation allocation, uint32_t xoff, uint32_t yoff, uint32_t zoff, uint32_t lod, uint32_t w, uint32_t h, uint32_t d, Ptr data, Size sizeBytes, Size stride) override;
77     Return<void> allocationSyncAll(Allocation allocation, AllocationUsageType usageType) override;
78     Return<void> allocationResize1D(Allocation allocation, uint32_t dimX) override;
79     Return<void> allocationCopy2DRange(Allocation dstAlloc, uint32_t dstXoff, uint32_t dstYoff, uint32_t dstMip, AllocationCubemapFace dstFace, uint32_t width, uint32_t height, Allocation srcAlloc, uint32_t srcXoff, uint32_t srcYoff, uint32_t srcMip, AllocationCubemapFace srcFace) override;
80     Return<void> allocationCopy3DRange(Allocation dstAlloc, uint32_t dstXoff, uint32_t dstYoff, uint32_t dstZoff, uint32_t dstMip, uint32_t width, uint32_t height, uint32_t depth, Allocation srcAlloc, uint32_t srcXoff, uint32_t srcYoff, uint32_t srcZoff, uint32_t srcMip) override;
81     Return<void> allocationIoSend(Allocation allocation) override;
82     Return<void> allocationIoReceive(Allocation allocation) override;
83     Return<void> allocationGetPointer(Allocation allocation, uint32_t lod, AllocationCubemapFace face, uint32_t z, allocationGetPointer_cb _hidl_cb) override;
84     Return<void> elementGetNativeMetadata(Element element, elementGetNativeMetadata_cb _hidl_cb) override;
85     Return<void> elementGetSubElements(Element element, Size numSubElem, elementGetSubElements_cb _hidl_cb) override;
86     Return<Element> elementCreate(DataType dt, DataKind dk, bool norm, uint32_t size) override;
87     Return<Element> elementComplexCreate(const hidl_vec<Element>& eins, const hidl_vec<hidl_string>& names, const hidl_vec<Size>& arraySizes) override;
88     Return<void> typeGetNativeMetadata(Type type, typeGetNativeMetadata_cb _hidl_cb) override;
89     Return<Type> typeCreate(Element element, uint32_t dimX, uint32_t dimY, uint32_t dimZ, bool mipmaps, bool faces, YuvFormat yuv) override;
90     Return<void> contextDestroy() override;
91     Return<void> contextGetMessage(Ptr data, Size size, contextGetMessage_cb _hidl_cb) override;
92     Return<void> contextPeekMessage(contextPeekMessage_cb _hidl_cb) override;
93     Return<void> contextSendMessage(uint32_t id, const hidl_vec<uint8_t>& data) override;
94     Return<void> contextInitToClient() override;
95     Return<void> contextDeinitToClient() override;
96     Return<void> contextFinish() override;
97     Return<void> contextLog() override;
98     Return<void> contextSetPriority(ThreadPriorities priority) override;
99     Return<void> contextSetCacheDir(const hidl_string& cacheDir) override;
100     Return<void> assignName(ObjectBase obj, const hidl_string& name) override;
101     Return<void> getName(ObjectBase obj, getName_cb _hidl_cb) override;
102     Return<Closure> closureCreate(ScriptKernelID kernelID, Allocation returnValue, const hidl_vec<ScriptFieldID>& fieldIDS, const hidl_vec<int64_t>& values, const hidl_vec<int32_t>& sizes, const hidl_vec<Closure>& depClosures, const hidl_vec<ScriptFieldID>& depFieldIDS) override;
103     Return<Closure> invokeClosureCreate(ScriptInvokeID invokeID, const hidl_vec<uint8_t>& params, const hidl_vec<ScriptFieldID>& fieldIDS, const hidl_vec<int64_t>& values, const hidl_vec<int32_t>& sizes) override;
104     Return<void> closureSetArg(Closure closure, uint32_t index, Ptr value, int32_t size) override;
105     Return<void> closureSetGlobal(Closure closure, ScriptFieldID fieldID, int64_t value, int32_t size) override;
106     Return<ScriptKernelID> scriptKernelIDCreate(Script script, int32_t slot, int32_t sig) override;
107     Return<ScriptInvokeID> scriptInvokeIDCreate(Script script, int32_t slot) override;
108     Return<ScriptFieldID> scriptFieldIDCreate(Script script, int32_t slot) override;
109     Return<ScriptGroup> scriptGroupCreate(const hidl_vec<ScriptKernelID>& kernels, const hidl_vec<ScriptKernelID>& srcK, const hidl_vec<ScriptKernelID>& dstK, const hidl_vec<ScriptFieldID>& dstF, const hidl_vec<Type>& types) override;
110     Return<ScriptGroup2> scriptGroup2Create(const hidl_string& name, const hidl_string& cacheDir, const hidl_vec<Closure>& closures) override;
111     Return<void> scriptGroupSetOutput(ScriptGroup sg, ScriptKernelID kid, Allocation alloc) override;
112     Return<void> scriptGroupSetInput(ScriptGroup sg, ScriptKernelID kid, Allocation alloc) override;
113     Return<void> scriptGroupExecute(ScriptGroup sg) override;
114     Return<void> objDestroy(ObjectBase obj) override;
115     Return<Sampler> samplerCreate(SamplerValue magFilter, SamplerValue minFilter, SamplerValue wrapS, SamplerValue wrapT, SamplerValue wrapR, float aniso) override;
116     Return<void> scriptBindAllocation(Script script, Allocation allocation, uint32_t slot) override;
117     Return<void> scriptSetTimeZone(Script script, const hidl_string& timeZone) override;
118     Return<void> scriptInvoke(Script vs, uint32_t slot) override;
119     Return<void> scriptInvokeV(Script vs, uint32_t slot, const hidl_vec<uint8_t>& data) override;
120     Return<void> scriptForEach(Script vs, uint32_t slot, const hidl_vec<Allocation>& vains, Allocation vaout, const hidl_vec<uint8_t>& params, Ptr sc) override;
121     Return<void> scriptReduce(Script vs, uint32_t slot, const hidl_vec<Allocation>& vains, Allocation vaout, Ptr sc) override;
122     Return<void> scriptSetVarI(Script vs, uint32_t slot, int32_t value) override;
123     Return<void> scriptSetVarObj(Script vs, uint32_t slot, ObjectBase obj) override;
124     Return<void> scriptSetVarJ(Script vs, uint32_t slot, int64_t value) override;
125     Return<void> scriptSetVarF(Script vs, uint32_t slot, float value) override;
126     Return<void> scriptSetVarD(Script vs, uint32_t slot, double value) override;
127     Return<void> scriptSetVarV(Script vs, uint32_t slot, const hidl_vec<uint8_t>& data) override;
128     Return<void> scriptGetVarV(Script vs, uint32_t slot, Size len, scriptGetVarV_cb _hidl_cb) override;
129     Return<void> scriptSetVarVE(Script vs, uint32_t slot, const hidl_vec<uint8_t>& data, Element ve, const hidl_vec<uint32_t>& dims) override;
130     Return<Script> scriptCCreate(const hidl_string& resName, const hidl_string& cacheDir, const hidl_vec<uint8_t>& text) override;
131     Return<Script> scriptIntrinsicCreate(ScriptIntrinsicID id, Element elem) override;
132 
133     // Methods from ::android::hidl::base::V1_0::IBase follow.
134 
135  private:
136     RsContext mContext;
137 };
138 
139 }  // namespace implementation
140 }  // namespace V1_0
141 }  // namespace renderscript
142 }  // namespace hardware
143 }  // namespace android
144 
145 #endif  // ANDROID_HARDWARE_RENDERSCRIPT_V1_0_CONTEXT_H
146