1ac670c0433d19397d4e36ced2110475b6f54fe26Romain Guy/*
2ac670c0433d19397d4e36ced2110475b6f54fe26Romain Guy * Copyright (C) 2010 The Android Open Source Project
3ac670c0433d19397d4e36ced2110475b6f54fe26Romain Guy *
4ac670c0433d19397d4e36ced2110475b6f54fe26Romain Guy * Licensed under the Apache License, Version 2.0 (the "License");
5ac670c0433d19397d4e36ced2110475b6f54fe26Romain Guy * you may not use this file except in compliance with the License.
6ac670c0433d19397d4e36ced2110475b6f54fe26Romain Guy * You may obtain a copy of the License at
7ac670c0433d19397d4e36ced2110475b6f54fe26Romain Guy *
8ac670c0433d19397d4e36ced2110475b6f54fe26Romain Guy *      http://www.apache.org/licenses/LICENSE-2.0
9ac670c0433d19397d4e36ced2110475b6f54fe26Romain Guy *
10ac670c0433d19397d4e36ced2110475b6f54fe26Romain Guy * Unless required by applicable law or agreed to in writing, software
11ac670c0433d19397d4e36ced2110475b6f54fe26Romain Guy * distributed under the License is distributed on an "AS IS" BASIS,
12ac670c0433d19397d4e36ced2110475b6f54fe26Romain Guy * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13ac670c0433d19397d4e36ced2110475b6f54fe26Romain Guy * See the License for the specific language governing permissions and
14ac670c0433d19397d4e36ced2110475b6f54fe26Romain Guy * limitations under the License.
15ac670c0433d19397d4e36ced2110475b6f54fe26Romain Guy */
16ac670c0433d19397d4e36ced2110475b6f54fe26Romain Guy
175b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy#ifndef ANDROID_HWUI_PROGRAM_CACHE_H
185b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy#define ANDROID_HWUI_PROGRAM_CACHE_H
19ac670c0433d19397d4e36ced2110475b6f54fe26Romain Guy
20ac670c0433d19397d4e36ced2110475b6f54fe26Romain Guy#include <utils/KeyedVector.h>
21ac670c0433d19397d4e36ced2110475b6f54fe26Romain Guy#include <utils/Log.h>
2206f96e2652e4855b6520ad9dd70583677605b79aRomain Guy#include <utils/String8.h>
23ac670c0433d19397d4e36ced2110475b6f54fe26Romain Guy
24889f8d1403761d5668115ced6cbb3f767cfe966dRomain Guy#include <GLES2/gl2.h>
25889f8d1403761d5668115ced6cbb3f767cfe966dRomain Guy
26c15008e72ec00ca20a271c3006dac649fd07533bRomain Guy#include "Debug.h"
27ac670c0433d19397d4e36ced2110475b6f54fe26Romain Guy#include "Program.h"
2824edca8b526515979778e577191089a57f5277d7Romain Guy#include "Properties.h"
29ac670c0433d19397d4e36ced2110475b6f54fe26Romain Guy
30ac670c0433d19397d4e36ced2110475b6f54fe26Romain Guynamespace android {
31ac670c0433d19397d4e36ced2110475b6f54fe26Romain Guynamespace uirenderer {
32ac670c0433d19397d4e36ced2110475b6f54fe26Romain Guy
33ac670c0433d19397d4e36ced2110475b6f54fe26Romain Guy///////////////////////////////////////////////////////////////////////////////
34ac670c0433d19397d4e36ced2110475b6f54fe26Romain Guy// Defines
35ac670c0433d19397d4e36ced2110475b6f54fe26Romain Guy///////////////////////////////////////////////////////////////////////////////
36ac670c0433d19397d4e36ced2110475b6f54fe26Romain Guy
37ac670c0433d19397d4e36ced2110475b6f54fe26Romain Guy// Debug
38c15008e72ec00ca20a271c3006dac649fd07533bRomain Guy#if DEBUG_PROGRAMS
395baa3a62a97544669fba6d65a11c07f252e654ddSteve Block    #define PROGRAM_LOGD(...) ALOGD(__VA_ARGS__)
40ac670c0433d19397d4e36ced2110475b6f54fe26Romain Guy#else
41ac670c0433d19397d4e36ced2110475b6f54fe26Romain Guy    #define PROGRAM_LOGD(...)
42ac670c0433d19397d4e36ced2110475b6f54fe26Romain Guy#endif
43ac670c0433d19397d4e36ced2110475b6f54fe26Romain Guy
44ac670c0433d19397d4e36ced2110475b6f54fe26Romain Guy///////////////////////////////////////////////////////////////////////////////
45ac670c0433d19397d4e36ced2110475b6f54fe26Romain Guy// Cache
46ac670c0433d19397d4e36ced2110475b6f54fe26Romain Guy///////////////////////////////////////////////////////////////////////////////
47ac670c0433d19397d4e36ced2110475b6f54fe26Romain Guy
48ac670c0433d19397d4e36ced2110475b6f54fe26Romain Guy/**
49ac670c0433d19397d4e36ced2110475b6f54fe26Romain Guy * Generates and caches program. Programs are generated based on
50ac670c0433d19397d4e36ced2110475b6f54fe26Romain Guy * ProgramDescriptions.
51ac670c0433d19397d4e36ced2110475b6f54fe26Romain Guy */
52ac670c0433d19397d4e36ced2110475b6f54fe26Romain Guyclass ProgramCache {
53ac670c0433d19397d4e36ced2110475b6f54fe26Romain Guypublic:
54ac670c0433d19397d4e36ced2110475b6f54fe26Romain Guy    ProgramCache();
55ac670c0433d19397d4e36ced2110475b6f54fe26Romain Guy    ~ProgramCache();
56ac670c0433d19397d4e36ced2110475b6f54fe26Romain Guy
57ac670c0433d19397d4e36ced2110475b6f54fe26Romain Guy    Program* get(const ProgramDescription& description);
58ac670c0433d19397d4e36ced2110475b6f54fe26Romain Guy
59ac670c0433d19397d4e36ced2110475b6f54fe26Romain Guy    void clear();
60ac670c0433d19397d4e36ced2110475b6f54fe26Romain Guy
61ac670c0433d19397d4e36ced2110475b6f54fe26Romain Guyprivate:
62ac670c0433d19397d4e36ced2110475b6f54fe26Romain Guy    Program* generateProgram(const ProgramDescription& description, programid key);
63ac670c0433d19397d4e36ced2110475b6f54fe26Romain Guy    String8 generateVertexShader(const ProgramDescription& description);
64ac670c0433d19397d4e36ced2110475b6f54fe26Romain Guy    String8 generateFragmentShader(const ProgramDescription& description);
6548daa54d31fc59ec969dcff65eb3cbb0ce879a8dRomain Guy    void generateBlend(String8& shader, const char* name, SkXfermode::Mode mode);
66889f8d1403761d5668115ced6cbb3f767cfe966dRomain Guy    void generateTextureWrap(String8& shader, GLenum wrapS, GLenum wrapT);
67ac670c0433d19397d4e36ced2110475b6f54fe26Romain Guy
68db1938e0e6ef816e228c815adccebd5cb05f2aa8Romain Guy    void printLongString(const String8& shader) const;
69db1938e0e6ef816e228c815adccebd5cb05f2aa8Romain Guy
70ac670c0433d19397d4e36ced2110475b6f54fe26Romain Guy    KeyedVector<programid, Program*> mCache;
71ac670c0433d19397d4e36ced2110475b6f54fe26Romain Guy}; // class ProgramCache
72ac670c0433d19397d4e36ced2110475b6f54fe26Romain Guy
73ac670c0433d19397d4e36ced2110475b6f54fe26Romain Guy}; // namespace uirenderer
74ac670c0433d19397d4e36ced2110475b6f54fe26Romain Guy}; // namespace android
75ac670c0433d19397d4e36ced2110475b6f54fe26Romain Guy
765b3b35296e8b2c8d3f07d32bb645d5414db41a1dRomain Guy#endif // ANDROID_HWUI_PROGRAM_CACHE_H
77