1326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams/*
24419977d78018a9933c7f455fe001f644f2d638bStephen Hines * Copyright (C) 2009-2012 The Android Open Source Project
3326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams *
4326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams * Licensed under the Apache License, Version 2.0 (the "License");
5326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams * you may not use this file except in compliance with the License.
6326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams * You may obtain a copy of the License at
7326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams *
8326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams *      http://www.apache.org/licenses/LICENSE-2.0
9326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams *
10326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams * Unless required by applicable law or agreed to in writing, software
11326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams * distributed under the License is distributed on an "AS IS" BASIS,
12326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams * See the License for the specific language governing permissions and
14326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams * limitations under the License.
15326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams */
16326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams
17326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams#ifndef ANDROID_RS_SCRIPT_H
18326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams#define ANDROID_RS_SCRIPT_H
19326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams
20326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams#include "rsAllocation.h"
21326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams
2247935ac8e3dd619f758abd576605a564e33bb59cTobias Grosser#include <utility>
23a0a1b6fbece2eb8d72d788422ab3e5f58d5a9216Jason Sams
24326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams// ---------------------------------------------------------------------------
25326e0ddf89e8df2837752fbfd7a014814b32082cJason Samsnamespace android {
26326e0ddf89e8df2837752fbfd7a014814b32082cJason Samsnamespace renderscript {
27326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams
2893eacc7ce0aad4314b4cb41a281f59ce54bb3286Jason Sams#ifndef RS_COMPATIBILITY_LIB
29a0a1b6fbece2eb8d72d788422ab3e5f58d5a9216Jason Samsclass ProgramVertex;
30a0a1b6fbece2eb8d72d788422ab3e5f58d5a9216Jason Samsclass ProgramFragment;
31a0a1b6fbece2eb8d72d788422ab3e5f58d5a9216Jason Samsclass ProgramRaster;
32ccc010bb7c0f89e162bf60033968a20be90a903aJason Samsclass ProgramStore;
3393eacc7ce0aad4314b4cb41a281f59ce54bb3286Jason Sams#endif
34326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams
35dbe66d6783c1e53cd1572de0ef6ef6fdf6f76f48Jason Samsclass ScriptKernelID : public ObjectBase {
36dbe66d6783c1e53cd1572de0ef6ef6fdf6f76f48Jason Samspublic:
37dbe66d6783c1e53cd1572de0ef6ef6fdf6f76f48Jason Sams    ScriptKernelID(Context *rsc, Script *s, int slot, int sig);
38dbe66d6783c1e53cd1572de0ef6ef6fdf6f76f48Jason Sams    virtual ~ScriptKernelID();
39dbe66d6783c1e53cd1572de0ef6ef6fdf6f76f48Jason Sams
40dbe66d6783c1e53cd1572de0ef6ef6fdf6f76f48Jason Sams    virtual void serialize(Context *rsc, OStream *stream) const;
41dbe66d6783c1e53cd1572de0ef6ef6fdf6f76f48Jason Sams    virtual RsA3DClassID getClassId() const;
42dbe66d6783c1e53cd1572de0ef6ef6fdf6f76f48Jason Sams
43dbe66d6783c1e53cd1572de0ef6ef6fdf6f76f48Jason Sams    Script *mScript;
44dbe66d6783c1e53cd1572de0ef6ef6fdf6f76f48Jason Sams    int mSlot;
45dbe66d6783c1e53cd1572de0ef6ef6fdf6f76f48Jason Sams    bool mHasKernelInput;
46dbe66d6783c1e53cd1572de0ef6ef6fdf6f76f48Jason Sams    bool mHasKernelOutput;
47dbe66d6783c1e53cd1572de0ef6ef6fdf6f76f48Jason Sams};
48dbe66d6783c1e53cd1572de0ef6ef6fdf6f76f48Jason Sams
49dbe66d6783c1e53cd1572de0ef6ef6fdf6f76f48Jason Samsclass ScriptFieldID : public ObjectBase {
50dbe66d6783c1e53cd1572de0ef6ef6fdf6f76f48Jason Samspublic:
51dbe66d6783c1e53cd1572de0ef6ef6fdf6f76f48Jason Sams    ScriptFieldID(Context *rsc, Script *s, int slot);
52dbe66d6783c1e53cd1572de0ef6ef6fdf6f76f48Jason Sams    virtual ~ScriptFieldID();
53dbe66d6783c1e53cd1572de0ef6ef6fdf6f76f48Jason Sams
54dbe66d6783c1e53cd1572de0ef6ef6fdf6f76f48Jason Sams    virtual void serialize(Context *rsc, OStream *stream) const;
55dbe66d6783c1e53cd1572de0ef6ef6fdf6f76f48Jason Sams    virtual RsA3DClassID getClassId() const;
56dbe66d6783c1e53cd1572de0ef6ef6fdf6f76f48Jason Sams
57dbe66d6783c1e53cd1572de0ef6ef6fdf6f76f48Jason Sams    Script *mScript;
58dbe66d6783c1e53cd1572de0ef6ef6fdf6f76f48Jason Sams    int mSlot;
59dbe66d6783c1e53cd1572de0ef6ef6fdf6f76f48Jason Sams};
60dbe66d6783c1e53cd1572de0ef6ef6fdf6f76f48Jason Sams
61afb743aca56c18beb7ab924e75cb6e070ef3e55aAlex Sakhartchoukclass Script : public ObjectBase {
62326e0ddf89e8df2837752fbfd7a014814b32082cJason Samspublic:
63dbe66d6783c1e53cd1572de0ef6ef6fdf6f76f48Jason Sams
64bad807405b2b9764372af1ad24bcfd4fb1f33d8eJason Sams    struct Hal {
65bad807405b2b9764372af1ad24bcfd4fb1f33d8eJason Sams        void * drv;
66bad807405b2b9764372af1ad24bcfd4fb1f33d8eJason Sams
67bad807405b2b9764372af1ad24bcfd4fb1f33d8eJason Sams        struct DriverInfo {
68bad807405b2b9764372af1ad24bcfd4fb1f33d8eJason Sams            int mVersionMajor;
69bad807405b2b9764372af1ad24bcfd4fb1f33d8eJason Sams            int mVersionMinor;
70bad807405b2b9764372af1ad24bcfd4fb1f33d8eJason Sams
71bad807405b2b9764372af1ad24bcfd4fb1f33d8eJason Sams            size_t exportedVariableCount;
72bad807405b2b9764372af1ad24bcfd4fb1f33d8eJason Sams            size_t exportedFunctionCount;
73bad807405b2b9764372af1ad24bcfd4fb1f33d8eJason Sams            size_t exportedPragmaCount;
74bad807405b2b9764372af1ad24bcfd4fb1f33d8eJason Sams            char const **exportedPragmaKeyList;
75bad807405b2b9764372af1ad24bcfd4fb1f33d8eJason Sams            char const **exportedPragmaValueList;
7647935ac8e3dd619f758abd576605a564e33bb59cTobias Grosser            const std::pair<const char *, uint32_t> *exportedForeachFuncList;
77bad807405b2b9764372af1ad24bcfd4fb1f33d8eJason Sams
78bad807405b2b9764372af1ad24bcfd4fb1f33d8eJason Sams            int (* root)();
79bad807405b2b9764372af1ad24bcfd4fb1f33d8eJason Sams        };
80bad807405b2b9764372af1ad24bcfd4fb1f33d8eJason Sams        DriverInfo info;
81bad807405b2b9764372af1ad24bcfd4fb1f33d8eJason Sams    };
82bad807405b2b9764372af1ad24bcfd4fb1f33d8eJason Sams    Hal mHal;
83bad807405b2b9764372af1ad24bcfd4fb1f33d8eJason Sams
848c6bc6930d4996b897de8e5113da4a4efae2310cJason Sams    typedef void (* InvokeFunc_t)(void);
85326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams
86e514b45de8561fbc6ef6770845102ca10b0a69d7Jason Sams    Script(Context *);
87326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams    virtual ~Script();
88326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams
89928b734b2fbba0800567c8b7e686bcf5f45483ccJason Sams    struct Enviroment_t {
90ef5867a6785807f90cfe8af26da4b964ee8ebee4Jason Sams        int64_t mStartTimeMillis;
91709a0978ae141198018ca9769f8d96292a8928e6Jason Sams        mutable int64_t mLastDtTime;
9298e10fd7438f2e925e7fb5c2ec97c1f8cc583634Romain Guy
9393eacc7ce0aad4314b4cb41a281f59ce54bb3286Jason Sams#ifndef RS_COMPATIBILITY_LIB
94a0a1b6fbece2eb8d72d788422ab3e5f58d5a9216Jason Sams        ObjectBaseRef<ProgramVertex> mVertex;
95a0a1b6fbece2eb8d72d788422ab3e5f58d5a9216Jason Sams        ObjectBaseRef<ProgramFragment> mFragment;
96b681c8af69ef6938c80dd5cc5fc920db94ee9f43Jason Sams        ObjectBaseRef<ProgramRaster> mRaster;
97ccc010bb7c0f89e162bf60033968a20be90a903aJason Sams        ObjectBaseRef<ProgramStore> mFragmentStore;
9893eacc7ce0aad4314b4cb41a281f59ce54bb3286Jason Sams#endif
99928b734b2fbba0800567c8b7e686bcf5f45483ccJason Sams    };
100928b734b2fbba0800567c8b7e686bcf5f45483ccJason Sams    Enviroment_t mEnviroment;
101326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams
102700ba38f022208686523ab4280c4fc9f102aa273Alex Sakhartchouk    void setSlot(uint32_t slot, Allocation *a);
103b81a0eb8180791e4eaab1253b59fa8bd562b046bAlex Sakhartchouk    void setVar(uint32_t slot, const void *val, size_t len);
1049c64239ebbfa4170190ede812e69150035e008e0Tim Murray    void getVar(uint32_t slot, const void *val, size_t len);
1052980f07d3dbbca727e8efe24ace7e7928a935648Stephen Hines    void setVar(uint32_t slot, const void *val, size_t len, Element *e,
106f0a5078aaf6426e5524a847a0b17d09570fc00b8Stephen Hines                const uint32_t *dims, size_t dimLen);
107a5eb6e17c08426deeedf989d6be280d89662ee82Jason Sams    void setVarObj(uint32_t slot, ObjectBase *val);
1088c6bc6930d4996b897de8e5113da4a4efae2310cJason Sams
1094ee16ffbd9d1d72e1757c9b26715597fdc044117Stephen Hines    virtual bool freeChildren();
1104ee16ffbd9d1d72e1757c9b26715597fdc044117Stephen Hines
111ace3e01f07252ee0fa47fcf1ac48864d8220b90eJason Sams    virtual void runForEach(Context *rsc,
1124419977d78018a9933c7f455fe001f644f2d638bStephen Hines                            uint32_t slot,
113ace3e01f07252ee0fa47fcf1ac48864d8220b90eJason Sams                            const Allocation * ain,
114ace3e01f07252ee0fa47fcf1ac48864d8220b90eJason Sams                            Allocation * aout,
115ace3e01f07252ee0fa47fcf1ac48864d8220b90eJason Sams                            const void * usr,
11687fe59a2f4d4c74539bfa0bff5f9a7e320e99415Jason Sams                            size_t usrBytes,
117ace3e01f07252ee0fa47fcf1ac48864d8220b90eJason Sams                            const RsScriptCall *sc = NULL) = 0;
118c61346b91434307c5003029017b54ce9c49112beJason Sams
1194b3c34e6833e39bc89c2128002806b654b8e623dChris Wailes    virtual void runForEach(Context* rsc,
1204b3c34e6833e39bc89c2128002806b654b8e623dChris Wailes                            uint32_t slot,
1214b3c34e6833e39bc89c2128002806b654b8e623dChris Wailes                            const Allocation** ains,
1224b3c34e6833e39bc89c2128002806b654b8e623dChris Wailes                            size_t inLen,
1234b3c34e6833e39bc89c2128002806b654b8e623dChris Wailes                            Allocation* aout,
1244b3c34e6833e39bc89c2128002806b654b8e623dChris Wailes                            const void* usr,
1254b3c34e6833e39bc89c2128002806b654b8e623dChris Wailes                            size_t usrBytes,
1264b3c34e6833e39bc89c2128002806b654b8e623dChris Wailes                            const RsScriptCall *sc = NULL) = 0;
1274b3c34e6833e39bc89c2128002806b654b8e623dChris Wailes
128b81a0eb8180791e4eaab1253b59fa8bd562b046bAlex Sakhartchouk    virtual void Invoke(Context *rsc, uint32_t slot, const void *data, size_t len) = 0;
129c61346b91434307c5003029017b54ce9c49112beJason Sams    virtual void setupScript(Context *rsc) = 0;
130c61346b91434307c5003029017b54ce9c49112beJason Sams    virtual uint32_t run(Context *) = 0;
131c78839b5bbcffae7d64a5a1c9aa60c9a4c5d3918Stephen Hines
132c78839b5bbcffae7d64a5a1c9aa60c9a4c5d3918Stephen Hines    bool hasObjectSlots() const {
133c78839b5bbcffae7d64a5a1c9aa60c9a4c5d3918Stephen Hines        return mHasObjectSlots;
134c78839b5bbcffae7d64a5a1c9aa60c9a4c5d3918Stephen Hines    }
135a36c50a6ab87f4c9049318d4c6c8ec7b0a1e6e12Jason Sams    virtual void callUpdateCacheObject(const Context *rsc, void *dstObj) const;
136a36c50a6ab87f4c9049318d4c6c8ec7b0a1e6e12Jason Sams
137700ba38f022208686523ab4280c4fc9f102aa273Alex Sakhartchoukprotected:
13877020c5248ca0921d7d24fb60dec5105ba39026cJason Sams    bool mInitialized;
139c78839b5bbcffae7d64a5a1c9aa60c9a4c5d3918Stephen Hines    bool mHasObjectSlots;
140700ba38f022208686523ab4280c4fc9f102aa273Alex Sakhartchouk    ObjectBaseRef<Allocation> *mSlots;
141700ba38f022208686523ab4280c4fc9f102aa273Alex Sakhartchouk    ObjectBaseRef<const Type> *mTypes;
142700ba38f022208686523ab4280c4fc9f102aa273Alex Sakhartchouk
143326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams};
144326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams
145326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams
146326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams}
147326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams}
148326e0ddf89e8df2837752fbfd7a014814b32082cJason Sams#endif
149