blob: 9180778e9aa9b2b78bc106771ac6da95f6222984 [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;
Romain Guyb1d0a4e2012-07-13 18:25:35 -070038 virtual uint32_t getFontRendererSize(uint32_t fontRenderer) const = 0;
39
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 Guyb1d0a4e2012-07-13 18:25:35 -070043 static GammaFontRenderer* createRenderer();
44
45protected:
46 GammaFontRenderer();
47
48 int mBlackThreshold;
49 int mWhiteThreshold;
50
51 float mGamma;
52};
53
54class ShaderGammaFontRenderer: public GammaFontRenderer {
55public:
56 ~ShaderGammaFontRenderer() {
57 delete mRenderer;
58 }
59
60 void clear() {
61 delete mRenderer;
62 }
63
64 void flush() {
65 if (mRenderer) {
66 mRenderer->flushLargeCaches();
67 }
68 }
69
70 FontRenderer& getFontRenderer(const SkPaint* paint) {
71 if (!mRenderer) {
72 mRenderer = new FontRenderer;
73 }
74 return *mRenderer;
75 }
76
77 uint32_t getFontRendererCount() const {
78 return 1;
79 }
80
81 uint32_t getFontRendererSize(uint32_t fontRenderer) const {
Romain Guy6e25e382012-07-18 15:50:29 -070082 return mRenderer ? mRenderer->getCacheSize() : 0;
Romain Guyb1d0a4e2012-07-13 18:25:35 -070083 }
84
Romain Guy41210632012-07-16 17:04:24 -070085 void describe(ProgramDescription& description, const SkPaint* paint) const;
86 void setupProgram(ProgramDescription& description, Program* program) const;
87
Romain Guyb1d0a4e2012-07-13 18:25:35 -070088private:
Romain Guy6e25e382012-07-18 15:50:29 -070089 ShaderGammaFontRenderer(bool multiGamma);
Romain Guyb1d0a4e2012-07-13 18:25:35 -070090
91 FontRenderer* mRenderer;
Romain Guy6e25e382012-07-18 15:50:29 -070092 bool mMultiGamma;
Romain Guyb1d0a4e2012-07-13 18:25:35 -070093
94 friend class GammaFontRenderer;
95};
96
97class LookupGammaFontRenderer: public GammaFontRenderer {
98public:
Romain Guy6e25e382012-07-18 15:50:29 -070099 ~LookupGammaFontRenderer() {
100 delete mRenderer;
101 }
102
103 void clear() {
104 delete mRenderer;
105 }
106
107 void flush() {
108 if (mRenderer) {
109 mRenderer->flushLargeCaches();
110 }
111 }
112
113 FontRenderer& getFontRenderer(const SkPaint* paint) {
114 if (!mRenderer) {
115 mRenderer = new FontRenderer;
116 mRenderer->setGammaTable(&mGammaTable[0]);
117 }
118 return *mRenderer;
119 }
120
121 uint32_t getFontRendererCount() const {
122 return 1;
123 }
124
125 uint32_t getFontRendererSize(uint32_t fontRenderer) const {
126 return mRenderer ? mRenderer->getCacheSize() : 0;
127 }
128
129 void describe(ProgramDescription& description, const SkPaint* paint) const {
130 }
131
132 void setupProgram(ProgramDescription& description, Program* program) const {
133 }
134
135private:
136 LookupGammaFontRenderer();
137
138 FontRenderer* mRenderer;
139 uint8_t mGammaTable[256];
140
141 friend class GammaFontRenderer;
142};
143
144class Lookup3GammaFontRenderer: public GammaFontRenderer {
145public:
146 ~Lookup3GammaFontRenderer();
Romain Guyeca0ca22011-11-04 15:12:29 -0700147
148 void clear();
149 void flush();
Romain Guyb45c0c92010-08-26 20:35:23 -0700150
151 FontRenderer& getFontRenderer(const SkPaint* paint);
152
Romain Guyc15008e2010-11-10 11:59:15 -0800153 uint32_t getFontRendererCount() const {
Romain Guyeca0ca22011-11-04 15:12:29 -0700154 return kGammaCount;
Romain Guyc15008e2010-11-10 11:59:15 -0800155 }
156
157 uint32_t getFontRendererSize(uint32_t fontRenderer) const {
Romain Guyeca0ca22011-11-04 15:12:29 -0700158 if (fontRenderer >= kGammaCount) return 0;
159
160 FontRenderer* renderer = mRenderers[fontRenderer];
161 if (!renderer) return 0;
162
Chet Haase7de0cb12011-12-05 16:35:38 -0800163 return renderer->getCacheSize();
Romain Guyc15008e2010-11-10 11:59:15 -0800164 }
165
Romain Guy41210632012-07-16 17:04:24 -0700166 void describe(ProgramDescription& description, const SkPaint* paint) const {
167 }
168
169 void setupProgram(ProgramDescription& description, Program* program) const {
170 }
171
Romain Guyb45c0c92010-08-26 20:35:23 -0700172private:
Romain Guy6e25e382012-07-18 15:50:29 -0700173 Lookup3GammaFontRenderer();
Romain Guyb1d0a4e2012-07-13 18:25:35 -0700174
175 enum Gamma {
176 kGammaDefault = 0,
177 kGammaBlack = 1,
178 kGammaWhite = 2,
179 kGammaCount = 3
180 };
181
Romain Guyeca0ca22011-11-04 15:12:29 -0700182 FontRenderer* getRenderer(Gamma gamma);
183
184 uint32_t mRenderersUsageCount[kGammaCount];
185 FontRenderer* mRenderers[kGammaCount];
Romain Guyb45c0c92010-08-26 20:35:23 -0700186
Romain Guyeca0ca22011-11-04 15:12:29 -0700187 uint8_t mGammaTable[256 * kGammaCount];
Romain Guyb1d0a4e2012-07-13 18:25:35 -0700188
189 friend class GammaFontRenderer;
Romain Guyb45c0c92010-08-26 20:35:23 -0700190};
191
192}; // namespace uirenderer
193}; // namespace android
194
Romain Guy5b3b3522010-10-27 18:57:51 -0700195#endif // ANDROID_HWUI_GAMMA_FONT_RENDERER_H