Home | History | Annotate | Download | only in rs
      1 /*
      2  * Copyright (C) 2009 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_C_H
     18 #define ANDROID_RS_SCRIPT_C_H
     19 
     20 #include "rsScript.h"
     21 
     22 #include "RenderScriptEnv.h"
     23 
     24 #ifndef ANDROID_RS_SERIALIZE
     25 #include "bcinfo/BitcodeTranslator.h"
     26 #endif
     27 
     28 // ---------------------------------------------------------------------------
     29 namespace android {
     30 namespace renderscript {
     31 
     32 
     33 class ScriptC : public Script {
     34 public:
     35     typedef int (*RunScript_t)();
     36     typedef void (*VoidFunc_t)();
     37 
     38     ScriptC(Context *);
     39     virtual ~ScriptC();
     40 
     41 
     42     const Allocation *ptrToAllocation(const void *) const;
     43 
     44 
     45     virtual void Invoke(Context *rsc, uint32_t slot, const void *data, size_t len);
     46 
     47     virtual uint32_t run(Context *);
     48 
     49     virtual void runForEach(Context *rsc,
     50                             const Allocation * ain,
     51                             Allocation * aout,
     52                             const void * usr,
     53                             size_t usrBytes,
     54                             const RsScriptCall *sc = NULL);
     55 
     56     virtual void serialize(OStream *stream) const {    }
     57     virtual RsA3DClassID getClassId() const { return RS_A3D_CLASS_ID_SCRIPT_C; }
     58     static Type *createFromStream(Context *rsc, IStream *stream) { return NULL; }
     59 
     60     bool runCompiler(Context *rsc, const char *resName, const char *cacheDir,
     61                      const uint8_t *bitcode, size_t bitcodeLen);
     62 
     63 //protected:
     64     void setupScript(Context *);
     65     void setupGLState(Context *);
     66     Script * setTLS(Script *);
     67   private:
     68 #ifndef ANDROID_RS_SERIALIZE
     69     bcinfo::BitcodeTranslator *BT;
     70 #endif
     71 };
     72 
     73 class ScriptCState {
     74 public:
     75     ScriptCState();
     76     ~ScriptCState();
     77 
     78     char * mScriptText;
     79     size_t mScriptLen;
     80 
     81     struct SymbolTable_t {
     82         const char * mName;
     83         void * mPtr;
     84         bool threadable;
     85     };
     86     static const SymbolTable_t * lookupSymbol(const char *);
     87     static const SymbolTable_t * lookupSymbolCL(const char *);
     88     static const SymbolTable_t * lookupSymbolGL(const char *);
     89 };
     90 
     91 
     92 }
     93 }
     94 #endif
     95