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 
     23 // ---------------------------------------------------------------------------
     24 namespace android {
     25 namespace renderscript {
     26 
     27 class ProgramVertex;
     28 class ProgramFragment;
     29 class ProgramRaster;
     30 class ProgramStore;
     31 
     32 class ScriptKernelID : public ObjectBase {
     33 public:
     34     ScriptKernelID(Context *rsc, Script *s, int slot, int sig);
     35     virtual ~ScriptKernelID();
     36 
     37     virtual void serialize(Context *rsc, OStream *stream) const;
     38     virtual RsA3DClassID getClassId() const;
     39 
     40     Script *mScript;
     41     int mSlot;
     42     bool mHasKernelInput;
     43     bool mHasKernelOutput;
     44 };
     45 
     46 class ScriptFieldID : public ObjectBase {
     47 public:
     48     ScriptFieldID(Context *rsc, Script *s, int slot);
     49     virtual ~ScriptFieldID();
     50 
     51     virtual void serialize(Context *rsc, OStream *stream) const;
     52     virtual RsA3DClassID getClassId() const;
     53 
     54     Script *mScript;
     55     int mSlot;
     56 };
     57 
     58 class Script : public ObjectBase {
     59 public:
     60 
     61     struct Hal {
     62         void * drv;
     63 
     64         struct DriverInfo {
     65             int mVersionMajor;
     66             int mVersionMinor;
     67 
     68             size_t exportedVariableCount;
     69             size_t exportedFunctionCount;
     70             size_t exportedPragmaCount;
     71             char const **exportedPragmaKeyList;
     72             char const **exportedPragmaValueList;
     73 
     74             int (* root)();
     75             bool isThreadable;
     76         };
     77         DriverInfo info;
     78     };
     79     Hal mHal;
     80 
     81     typedef void (* InvokeFunc_t)(void);
     82 
     83     Script(Context *);
     84     virtual ~Script();
     85 
     86     struct Enviroment_t {
     87         int64_t mStartTimeMillis;
     88         int64_t mLastDtTime;
     89 
     90         ObjectBaseRef<ProgramVertex> mVertex;
     91         ObjectBaseRef<ProgramFragment> mFragment;
     92         ObjectBaseRef<ProgramRaster> mRaster;
     93         ObjectBaseRef<ProgramStore> mFragmentStore;
     94     };
     95     Enviroment_t mEnviroment;
     96 
     97     void setSlot(uint32_t slot, Allocation *a);
     98     void setVar(uint32_t slot, const void *val, size_t len);
     99     void setVar(uint32_t slot, const void *val, size_t len, Element *e,
    100                 const size_t *dims, size_t dimLen);
    101     void setVarObj(uint32_t slot, ObjectBase *val);
    102 
    103     virtual bool freeChildren();
    104 
    105     virtual void runForEach(Context *rsc,
    106                             uint32_t slot,
    107                             const Allocation * ain,
    108                             Allocation * aout,
    109                             const void * usr,
    110                             size_t usrBytes,
    111                             const RsScriptCall *sc = NULL) = 0;
    112 
    113     virtual void Invoke(Context *rsc, uint32_t slot, const void *data, size_t len) = 0;
    114     virtual void setupScript(Context *rsc) = 0;
    115     virtual uint32_t run(Context *) = 0;
    116 protected:
    117     bool mInitialized;
    118     ObjectBaseRef<Allocation> *mSlots;
    119     ObjectBaseRef<const Type> *mTypes;
    120 
    121 };
    122 
    123 
    124 }
    125 }
    126 #endif
    127 
    128