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