Home | History | Annotate | Download | only in Renderscript
      1 /*
      2  * Copyright 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 BCC_RS_SCRIPT_H
     18 #define BCC_RS_SCRIPT_H
     19 
     20 #include "bcc/Script.h"
     21 #include "bcc/Renderscript/RSInfo.h"
     22 #include "bcc/Support/Sha1Util.h"
     23 
     24 namespace llvm {
     25   class Module;
     26 }  // end namespace llvm
     27 
     28 namespace bcc {
     29 
     30 class RSScript;
     31 class Source;
     32 
     33 class RSScript : public Script {
     34 public:
     35   // This is one-one mapping with the llvm::CodeGenOpt::Level in
     36   // llvm/Support/CodeGen.h. Therefore, value of this type can safely cast
     37   // to llvm::CodeGenOpt::Level. This makes RSScript LLVM-free.
     38   enum OptimizationLevel {
     39     kOptLvl0, // -O0
     40     kOptLvl1, // -O1
     41     kOptLvl2, // -O2, -Os
     42     kOptLvl3  // -O3
     43   };
     44 
     45 private:
     46   const RSInfo *mInfo;
     47 
     48   unsigned mCompilerVersion;
     49 
     50   OptimizationLevel mOptimizationLevel;
     51 
     52   RSLinkRuntimeCallback mLinkRuntimeCallback;
     53 
     54   bool mEmbedInfo;
     55 
     56 private:
     57   // This will be invoked when the containing source has been reset.
     58   virtual bool doReset();
     59 
     60 public:
     61   static bool LinkRuntime(RSScript &pScript, const char *rt_path = NULL);
     62 
     63   RSScript(Source &pSource);
     64 
     65   virtual ~RSScript() {
     66     delete mInfo;
     67   }
     68 
     69   // Set the associated RSInfo of the script.
     70   void setInfo(const RSInfo *pInfo) {
     71     mInfo = pInfo;
     72   }
     73 
     74   const RSInfo *getInfo() const {
     75     return mInfo;
     76   }
     77 
     78   void setCompilerVersion(unsigned pCompilerVersion) {
     79     mCompilerVersion = pCompilerVersion;
     80   }
     81 
     82   unsigned getCompilerVersion() const {
     83     return mCompilerVersion;
     84   }
     85 
     86   void setOptimizationLevel(OptimizationLevel pOptimizationLevel) {
     87     mOptimizationLevel = pOptimizationLevel;
     88   }
     89 
     90   OptimizationLevel getOptimizationLevel() const {
     91     return mOptimizationLevel;
     92   }
     93 
     94   void setLinkRuntimeCallback(RSLinkRuntimeCallback fn){
     95     mLinkRuntimeCallback = fn;
     96   }
     97 
     98   void setEmbedInfo(bool pEnable) {
     99     mEmbedInfo = pEnable;
    100   }
    101 
    102   bool getEmbedInfo() const {
    103     return mEmbedInfo;
    104   }
    105 };
    106 
    107 } // end namespace bcc
    108 
    109 #endif // BCC_RS_SCRIPT_H
    110