blob: 46cfd04d9cccea91c37583916ecb84507c027552 [file] [log] [blame]
Romain Guyb45c0c92010-08-26 20:35:23 -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_GAMMA_FONT_RENDERER_H
18#define ANDROID_HWUI_GAMMA_FONT_RENDERER_H
Romain Guyb45c0c92010-08-26 20:35:23 -070019
20#include <SkPaint.h>
21
22#include "FontRenderer.h"
Romain Guy41210632012-07-16 17:04:24 -070023#include "Program.h"
Romain Guyb45c0c92010-08-26 20:35:23 -070024
25namespace android {
26namespace uirenderer {
27
Romain Guyb1d0a4e2012-07-13 18:25:35 -070028class GammaFontRenderer {
29public:
30 virtual ~GammaFontRenderer();
Romain Guyeca0ca22011-11-04 15:12:29 -070031
Romain Guyb1d0a4e2012-07-13 18:25:35 -070032 virtual void clear() = 0;
33 virtual void flush() = 0;
34
35 virtual FontRenderer& getFontRenderer(const SkPaint* paint) = 0;
36
37 virtual uint32_t getFontRendererCount() const = 0;
Victoria Lease1e546812013-06-25 14:25:17 -070038 virtual uint32_t getFontRendererSize(uint32_t fontRenderer, GLenum format) const = 0;
Romain Guyb1d0a4e2012-07-13 18:25:35 -070039
Romain Guy41210632012-07-16 17:04:24 -070040 virtual void describe(ProgramDescription& description, const SkPaint* paint) const = 0;
41 virtual void setupProgram(ProgramDescription& description, Program* program) const = 0;
42
Romain Guycf51a412013-04-08 19:40:31 -070043 virtual void endPrecaching() = 0;
44
Romain Guyb1d0a4e2012-07-13 18:25:35 -070045 static GammaFontRenderer* createRenderer();
46
47protected:
48 GammaFontRenderer();
49
50 int mBlackThreshold;
51 int mWhiteThreshold;
52
53 float mGamma;
54};
55
56class ShaderGammaFontRenderer: public GammaFontRenderer {
57public:
58 ~ShaderGammaFontRenderer() {
59 delete mRenderer;
60 }
61
62 void clear() {
63 delete mRenderer;
Romain Guy0aa87bb2012-07-20 11:14:32 -070064 mRenderer = NULL;
Romain Guyb1d0a4e2012-07-13 18:25:35 -070065 }
66
67 void flush() {
68 if (mRenderer) {
69 mRenderer->flushLargeCaches();
70 }
71 }
72
John Reck8b59a522014-11-22 00:10:02 +000073 FontRenderer& getFontRenderer(const SkPaint* paint) {
Romain Guyb1d0a4e2012-07-13 18:25:35 -070074 if (!mRenderer) {
75 mRenderer = new FontRenderer;
76 }
77 return *mRenderer;
78 }
79
80 uint32_t getFontRendererCount() const {
81 return 1;
82 }
83
John Reck8b59a522014-11-22 00:10:02 +000084 uint32_t getFontRendererSize(uint32_t fontRenderer, GLenum format) const {
Victoria Lease1e546812013-06-25 14:25:17 -070085 return mRenderer ? mRenderer->getCacheSize(format) : 0;
Romain Guyb1d0a4e2012-07-13 18:25:35 -070086 }
87
Romain Guy41210632012-07-16 17:04:24 -070088 void describe(ProgramDescription& description, const SkPaint* paint) const;
89 void setupProgram(ProgramDescription& description, Program* program) const;
90
Romain Guycf51a412013-04-08 19:40:31 -070091 void endPrecaching();
92
Romain Guyb1d0a4e2012-07-13 18:25:35 -070093private:
Romain Guy6e25e382012-07-18 15:50:29 -070094 ShaderGammaFontRenderer(bool multiGamma);
Romain Guyb1d0a4e2012-07-13 18:25:35 -070095
96 FontRenderer* mRenderer;
Romain Guy6e25e382012-07-18 15:50:29 -070097 bool mMultiGamma;
Romain Guyb1d0a4e2012-07-13 18:25:35 -070098
99 friend class GammaFontRenderer;
100};
101
102class LookupGammaFontRenderer: public GammaFontRenderer {
103public:
Romain Guy6e25e382012-07-18 15:50:29 -0700104 ~LookupGammaFontRenderer() {
105 delete mRenderer;
106 }
107
108 void clear() {
109 delete mRenderer;
Romain Guy8801b2f2012-08-03 17:43:31 -0700110 mRenderer = NULL;
Romain Guy6e25e382012-07-18 15:50:29 -0700111 }
112
113 void flush() {
114 if (mRenderer) {
115 mRenderer->flushLargeCaches();
116 }
117 }
118
John Reck8b59a522014-11-22 00:10:02 +0000119 FontRenderer& getFontRenderer(const SkPaint* paint) {
Romain Guy6e25e382012-07-18 15:50:29 -0700120 if (!mRenderer) {
121 mRenderer = new FontRenderer;
122 mRenderer->setGammaTable(&mGammaTable[0]);
123 }
124 return *mRenderer;
125 }
126
127 uint32_t getFontRendererCount() const {
128 return 1;
129 }
130
John Reck8b59a522014-11-22 00:10:02 +0000131 uint32_t getFontRendererSize(uint32_t fontRenderer, GLenum format) const {
Victoria Lease1e546812013-06-25 14:25:17 -0700132 return mRenderer ? mRenderer->getCacheSize(format) : 0;
Romain Guy6e25e382012-07-18 15:50:29 -0700133 }
134
John Reck8b59a522014-11-22 00:10:02 +0000135 void describe(ProgramDescription& description, const SkPaint* paint) const {
Romain Guy6e25e382012-07-18 15:50:29 -0700136 }
137
John Reck8b59a522014-11-22 00:10:02 +0000138 void setupProgram(ProgramDescription& description, Program* program) const {
Romain Guy6e25e382012-07-18 15:50:29 -0700139 }
140
Romain Guycf51a412013-04-08 19:40:31 -0700141 void endPrecaching();
142
Romain Guy6e25e382012-07-18 15:50:29 -0700143private:
144 LookupGammaFontRenderer();
145
146 FontRenderer* mRenderer;
147 uint8_t mGammaTable[256];
148
149 friend class GammaFontRenderer;
150};
151
152class Lookup3GammaFontRenderer: public GammaFontRenderer {
153public:
154 ~Lookup3GammaFontRenderer();
Romain Guyeca0ca22011-11-04 15:12:29 -0700155
156 void clear();
157 void flush();
Romain Guyb45c0c92010-08-26 20:35:23 -0700158
159 FontRenderer& getFontRenderer(const SkPaint* paint);
160
Romain Guyc15008e2010-11-10 11:59:15 -0800161 uint32_t getFontRendererCount() const {
Romain Guyeca0ca22011-11-04 15:12:29 -0700162 return kGammaCount;
Romain Guyc15008e2010-11-10 11:59:15 -0800163 }
164
Victoria Lease1e546812013-06-25 14:25:17 -0700165 uint32_t getFontRendererSize(uint32_t fontRenderer, GLenum format) const {
Romain Guyeca0ca22011-11-04 15:12:29 -0700166 if (fontRenderer >= kGammaCount) return 0;
167
168 FontRenderer* renderer = mRenderers[fontRenderer];
169 if (!renderer) return 0;
170
Victoria Lease1e546812013-06-25 14:25:17 -0700171 return renderer->getCacheSize(format);
Romain Guyc15008e2010-11-10 11:59:15 -0800172 }
173
John Reck8b59a522014-11-22 00:10:02 +0000174 void describe(ProgramDescription& description, const SkPaint* paint) const {
Romain Guy41210632012-07-16 17:04:24 -0700175 }
176
John Reck8b59a522014-11-22 00:10:02 +0000177 void setupProgram(ProgramDescription& description, Program* program) const {
Romain Guy41210632012-07-16 17:04:24 -0700178 }
179
Romain Guycf51a412013-04-08 19:40:31 -0700180 void endPrecaching();
181
Romain Guyb45c0c92010-08-26 20:35:23 -0700182private:
Romain Guy6e25e382012-07-18 15:50:29 -0700183 Lookup3GammaFontRenderer();
Romain Guyb1d0a4e2012-07-13 18:25:35 -0700184
185 enum Gamma {
186 kGammaDefault = 0,
187 kGammaBlack = 1,
188 kGammaWhite = 2,
189 kGammaCount = 3
190 };
191
Romain Guyeca0ca22011-11-04 15:12:29 -0700192 FontRenderer* getRenderer(Gamma gamma);
193
194 uint32_t mRenderersUsageCount[kGammaCount];
195 FontRenderer* mRenderers[kGammaCount];
Romain Guyb45c0c92010-08-26 20:35:23 -0700196
Romain Guyeca0ca22011-11-04 15:12:29 -0700197 uint8_t mGammaTable[256 * kGammaCount];
Romain Guyb1d0a4e2012-07-13 18:25:35 -0700198
199 friend class GammaFontRenderer;
Romain Guyb45c0c92010-08-26 20:35:23 -0700200};
201
202}; // namespace uirenderer
203}; // namespace android
204
Romain Guy5b3b3522010-10-27 18:57:51 -0700205#endif // ANDROID_HWUI_GAMMA_FONT_RENDERER_H