blob: 6cfe0c7c36b1585259b16e80a38feaa3fcb6338d [file] [log] [blame]
Romain Guyac670c02010-07-27 17:39:27 -07001/*
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
Romain Guy5b3b3522010-10-27 18:57:51 -070017#ifndef ANDROID_HWUI_PROGRAM_CACHE_H
18#define ANDROID_HWUI_PROGRAM_CACHE_H
Romain Guyac670c02010-07-27 17:39:27 -070019
20#include <utils/KeyedVector.h>
21#include <utils/Log.h>
Romain Guy06f96e22010-07-30 19:18:16 -070022#include <utils/String8.h>
Romain Guyac670c02010-07-27 17:39:27 -070023
Romain Guy889f8d12010-07-29 14:37:42 -070024#include <GLES2/gl2.h>
25
Romain Guyc15008e2010-11-10 11:59:15 -080026#include "Debug.h"
Romain Guyac670c02010-07-27 17:39:27 -070027#include "Program.h"
Romain Guy24edca82011-12-09 13:08:06 -080028#include "Properties.h"
Romain Guyac670c02010-07-27 17:39:27 -070029
30namespace android {
31namespace uirenderer {
32
33///////////////////////////////////////////////////////////////////////////////
34// Defines
35///////////////////////////////////////////////////////////////////////////////
36
37// Debug
Romain Guyc15008e2010-11-10 11:59:15 -080038#if DEBUG_PROGRAMS
Steve Block5baa3a62011-12-20 16:23:08 +000039 #define PROGRAM_LOGD(...) ALOGD(__VA_ARGS__)
Romain Guyac670c02010-07-27 17:39:27 -070040#else
41 #define PROGRAM_LOGD(...)
42#endif
43
Romain Guyac670c02010-07-27 17:39:27 -070044///////////////////////////////////////////////////////////////////////////////
45// Cache
46///////////////////////////////////////////////////////////////////////////////
47
48/**
Romain Guyac670c02010-07-27 17:39:27 -070049 * 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);
Romain Guy48daa542010-08-10 19:21:34 -070065 void generateBlend(String8& shader, const char* name, SkXfermode::Mode mode);
Romain Guy889f8d12010-07-29 14:37:42 -070066 void generateTextureWrap(String8& shader, GLenum wrapS, GLenum wrapT);
Romain Guyac670c02010-07-27 17:39:27 -070067
Romain Guydb1938e2010-08-02 18:50:22 -070068 void printLongString(const String8& shader) const;
69
Romain Guyac670c02010-07-27 17:39:27 -070070 KeyedVector<programid, Program*> mCache;
Romain Guyac670c02010-07-27 17:39:27 -070071}; // class ProgramCache
72
73}; // namespace uirenderer
74}; // namespace android
75
Romain Guy5b3b3522010-10-27 18:57:51 -070076#endif // ANDROID_HWUI_PROGRAM_CACHE_H