Home | History | Annotate | Download | only in rs
      1 /*
      2  * Copyright (C) 2009-2012 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_RS_SCRIPT_H
     18 #define ANDROID_RS_SCRIPT_H
     19 
     20 #include "rsAllocation.h"
     21 
     22 #include <utility>
     23 
     24 // ---------------------------------------------------------------------------
     25 namespace android {
     26 namespace renderscript {
     27 
     28 #ifndef RS_COMPATIBILITY_LIB
     29 class ProgramVertex;
     30 class ProgramFragment;
     31 class ProgramRaster;
     32 class ProgramStore;
     33 #endif
     34 
     35 class ScriptKernelID : public ObjectBase {
     36 public:
     37     ScriptKernelID(Context *rsc, Script *s, int slot, int sig);
     38     virtual ~ScriptKernelID();
     39 
     40     virtual void serialize(Context *rsc, OStream *stream) const;
     41     virtual RsA3DClassID getClassId() const;
     42 
     43     Script *mScript;
     44     int mSlot;
     45     bool mHasKernelInput;
     46     bool mHasKernelOutput;
     47 };
     48 
     49 class ScriptFieldID : public ObjectBase {
     50 public:
     51     ScriptFieldID(Context *rsc, Script *s, int slot);
     52     virtual ~ScriptFieldID();
     53 
     54     virtual void serialize(Context *rsc, OStream *stream) const;
     55     virtual RsA3DClassID getClassId() const;
     56 
     57     Script *mScript;
     58     int mSlot;
     59 };
     60 
     61 class Script : public ObjectBase {
     62 public:
     63 
     64     struct Hal {
     65         void * drv;
     66 
     67         struct DriverInfo {
     68             int mVersionMajor;
     69             int mVersionMinor;
     70 
     71             size_t exportedVariableCount;
     72             size_t exportedFunctionCount;
     73             size_t exportedPragmaCount;
     74             char const **exportedPragmaKeyList;
     75             char const **exportedPragmaValueList;
     76             const std::pair<const char *, uint32_t> *exportedForeachFuncList;
     77 
     78             int (* root)();
     79         };
     80         DriverInfo info;
     81     };
     82     Hal mHal;
     83 
     84     typedef void (* InvokeFunc_t)(void);
     85 
     86     Script(Context *);
     87     virtual ~Script();
     88 
     89     struct Enviroment_t {
     90         int64_t mStartTimeMillis;
     91         mutable int64_t mLastDtTime;
     92 
     93 #ifndef RS_COMPATIBILITY_LIB
     94         ObjectBaseRef<ProgramVertex> mVertex;
     95         ObjectBaseRef<ProgramFragment> mFragment;
     96         ObjectBaseRef<ProgramRaster> mRaster;
     97         ObjectBaseRef<ProgramStore> mFragmentStore;
     98 #endif
     99     };
    100     Enviroment_t mEnviroment;
    101 
    102     void setSlot(uint32_t slot, Allocation *a);
    103     void setVar(uint32_t slot, const void *val, size_t len);
    104     void getVar(uint32_t slot, const void *val, size_t len);
    105     void setVar(uint32_t slot, const void *val, size_t len, Element *e,
    106                 const uint32_t *dims, size_t dimLen);
    107     void setVarObj(uint32_t slot, ObjectBase *val);
    108 
    109     virtual bool freeChildren();
    110 
    111     virtual void runForEach(Context *rsc,
    112                             uint32_t slot,
    113                             const Allocation * ain,
    114                             Allocation * aout,
    115                             const void * usr,
    116                             size_t usrBytes,
    117                             const RsScriptCall *sc = NULL) = 0;
    118 
    119     virtual void runForEach(Context* rsc,
    120                             uint32_t slot,
    121                             const Allocation** ains,
    122                             size_t inLen,
    123                             Allocation* aout,
    124                             const void* usr,
    125                             size_t usrBytes,
    126                             const RsScriptCall *sc = NULL) = 0;
    127 
    128     virtual void Invoke(Context *rsc, uint32_t slot, const void *data, size_t len) = 0;
    129     virtual void setupScript(Context *rsc) = 0;
    130     virtual uint32_t run(Context *) = 0;
    131 
    132     bool hasObjectSlots() const {
    133         return mHasObjectSlots;
    134     }
    135     virtual void callUpdateCacheObject(const Context *rsc, void *dstObj) const;
    136 
    137 protected:
    138     bool mInitialized;
    139     bool mHasObjectSlots;
    140     ObjectBaseRef<Allocation> *mSlots;
    141     ObjectBaseRef<const Type> *mTypes;
    142 
    143 };
    144 
    145 
    146 }
    147 }
    148 #endif
    149