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
24#include <GLES2/gl2.h>
25
26#include "Debug.h"
27#include "Program.h"
28#include "Properties.h"
29
30namespace android {
31namespace uirenderer {
32
33///////////////////////////////////////////////////////////////////////////////
34// Defines
35///////////////////////////////////////////////////////////////////////////////
36
37// Debug
38#if DEBUG_PROGRAMS
39    #define PROGRAM_LOGD(...) ALOGD(__VA_ARGS__)
40#else
41    #define PROGRAM_LOGD(...)
42#endif
43
44///////////////////////////////////////////////////////////////////////////////
45// Cache
46///////////////////////////////////////////////////////////////////////////////
47
48/**
49 * Generates and caches program. Programs are generated based on
50 * ProgramDescriptions.
51 */
52class ProgramCache {
53public:
54    ProgramCache();
55    ~ProgramCache();
56
57    Program* get(const ProgramDescription& description);
58
59    void clear();
60
61private:
62    Program* generateProgram(const ProgramDescription& description, programid key);
63    String8 generateVertexShader(const ProgramDescription& description);
64    String8 generateFragmentShader(const ProgramDescription& description);
65    void generateBlend(String8& shader, const char* name, SkXfermode::Mode mode);
66    void generateTextureWrap(String8& shader, GLenum wrapS, GLenum wrapT);
67
68    void printLongString(const String8& shader) const;
69
70    KeyedVector<programid, Program*> mCache;
71}; // class ProgramCache
72
73}; // namespace uirenderer
74}; // namespace android
75
76#endif // ANDROID_HWUI_PROGRAM_CACHE_H
77