Home | History | Annotate | Download | only in hwui
      1 /*
      2  * Copyright (C) 2010 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_HWUI_PROGRAM_CACHE_H
     18 #define ANDROID_HWUI_PROGRAM_CACHE_H
     19 
     20 #include <utils/KeyedVector.h>
     21 #include <utils/Log.h>
     22 #include <utils/String8.h>
     23 #include <map>
     24 
     25 #include <GLES2/gl2.h>
     26 
     27 #include "Debug.h"
     28 #include "Program.h"
     29 
     30 namespace android {
     31 namespace uirenderer {
     32 
     33 ///////////////////////////////////////////////////////////////////////////////
     34 // Cache
     35 ///////////////////////////////////////////////////////////////////////////////
     36 
     37 /**
     38  * Generates and caches program. Programs are generated based on
     39  * ProgramDescriptions.
     40  */
     41 class ProgramCache {
     42 public:
     43     explicit ProgramCache(const Extensions& extensions);
     44     ~ProgramCache();
     45 
     46     Program* get(const ProgramDescription& description);
     47 
     48     void clear();
     49 
     50 private:
     51     Program* generateProgram(const ProgramDescription& description, programid key);
     52     String8 generateVertexShader(const ProgramDescription& description);
     53     String8 generateFragmentShader(const ProgramDescription& description);
     54     void generateBlend(String8& shader, const char* name, SkBlendMode mode);
     55     void generateTextureWrap(String8& shader, GLenum wrapS, GLenum wrapT);
     56 
     57     void printLongString(const String8& shader) const;
     58 
     59     std::map<programid, std::unique_ptr<Program>> mCache;
     60 
     61     const bool mHasES3;
     62     const bool mHasLinearBlending;
     63 };  // class ProgramCache
     64 
     65 };  // namespace uirenderer
     66 };  // namespace android
     67 
     68 #endif  // ANDROID_HWUI_PROGRAM_CACHE_H
     69