blob: 5c1860ea5c8eecd60b8be7024866fdc83b28b931 [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;
Romain Guy0aa87bb2012-07-20 11:14:32 -070062 mRenderer = NULL;
Romain Guyb1d0a4e2012-07-13 18:25:35 -070063 }
64
65 void flush() {
66 if (mRenderer) {
67 mRenderer->flushLargeCaches();
68 }
69 }
70
71 FontRenderer& getFontRenderer(const SkPaint* paint) {
72 if (!mRenderer) {
73 mRenderer = new FontRenderer;
74 }
75 return *mRenderer;
76 }
77
78 uint32_t getFontRendererCount() const {
79 return 1;
80 }
81
82 uint32_t getFontRendererSize(uint32_t fontRenderer) const {
Romain Guy6e25e382012-07-18 15:50:29 -070083 return mRenderer ? mRenderer->getCacheSize() : 0;
Romain Guyb1d0a4e2012-07-13 18:25:35 -070084 }
85
Romain Guy41210632012-07-16 17:04:24 -070086 void describe(ProgramDescription& description, const SkPaint* paint) const;
87 void setupProgram(ProgramDescription& description, Program* program) const;
88
Romain Guyb1d0a4e2012-07-13 18:25:35 -070089private:
Romain Guy6e25e382012-07-18 15:50:29 -070090 ShaderGammaFontRenderer(bool multiGamma);
Romain Guyb1d0a4e2012-07-13 18:25:35 -070091
92 FontRenderer* mRenderer;
Romain Guy6e25e382012-07-18 15:50:29 -070093 bool mMultiGamma;
Romain Guyb1d0a4e2012-07-13 18:25:35 -070094
95 friend class GammaFontRenderer;
96};
97
98class LookupGammaFontRenderer: public GammaFontRenderer {
99public:
Romain Guy6e25e382012-07-18 15:50:29 -0700100 ~LookupGammaFontRenderer() {
101 delete mRenderer;
102 }
103
104 void clear() {
105 delete mRenderer;
Romain Guy8801b2f2012-08-03 17:43:31 -0700106 mRenderer = NULL;
Romain Guy6e25e382012-07-18 15:50:29 -0700107 }
108
109 void flush() {
110 if (mRenderer) {
111 mRenderer->flushLargeCaches();
112 }
113 }
114
115 FontRenderer& getFontRenderer(const SkPaint* paint) {
116 if (!mRenderer) {
117 mRenderer = new FontRenderer;
118 mRenderer->setGammaTable(&mGammaTable[0]);
119 }
120 return *mRenderer;
121 }
122
123 uint32_t getFontRendererCount() const {
124 return 1;
125 }
126
127 uint32_t getFontRendererSize(uint32_t fontRenderer) const {
128 return mRenderer ? mRenderer->getCacheSize() : 0;
129 }
130
131 void describe(ProgramDescription& description, const SkPaint* paint) const {
132 }
133
134 void setupProgram(ProgramDescription& description, Program* program) const {
135 }
136
137private:
138 LookupGammaFontRenderer();
139
140 FontRenderer* mRenderer;
141 uint8_t mGammaTable[256];
142
143 friend class GammaFontRenderer;
144};
145
146class Lookup3GammaFontRenderer: public GammaFontRenderer {
147public:
148 ~Lookup3GammaFontRenderer();
Romain Guyeca0ca22011-11-04 15:12:29 -0700149
150 void clear();
151 void flush();
Romain Guyb45c0c92010-08-26 20:35:23 -0700152
153 FontRenderer& getFontRenderer(const SkPaint* paint);
154
Romain Guyc15008e2010-11-10 11:59:15 -0800155 uint32_t getFontRendererCount() const {
Romain Guyeca0ca22011-11-04 15:12:29 -0700156 return kGammaCount;
Romain Guyc15008e2010-11-10 11:59:15 -0800157 }
158
159 uint32_t getFontRendererSize(uint32_t fontRenderer) const {
Romain Guyeca0ca22011-11-04 15:12:29 -0700160 if (fontRenderer >= kGammaCount) return 0;
161
162 FontRenderer* renderer = mRenderers[fontRenderer];
163 if (!renderer) return 0;
164
Chet Haase7de0cb12011-12-05 16:35:38 -0800165 return renderer->getCacheSize();
Romain Guyc15008e2010-11-10 11:59:15 -0800166 }
167
Romain Guy41210632012-07-16 17:04:24 -0700168 void describe(ProgramDescription& description, const SkPaint* paint) const {
169 }
170
171 void setupProgram(ProgramDescription& description, Program* program) const {
172 }
173
Romain Guyb45c0c92010-08-26 20:35:23 -0700174private:
Romain Guy6e25e382012-07-18 15:50:29 -0700175 Lookup3GammaFontRenderer();
Romain Guyb1d0a4e2012-07-13 18:25:35 -0700176
177 enum Gamma {
178 kGammaDefault = 0,
179 kGammaBlack = 1,
180 kGammaWhite = 2,
181 kGammaCount = 3
182 };
183
Romain Guyeca0ca22011-11-04 15:12:29 -0700184 FontRenderer* getRenderer(Gamma gamma);
185
186 uint32_t mRenderersUsageCount[kGammaCount];
187 FontRenderer* mRenderers[kGammaCount];
Romain Guyb45c0c92010-08-26 20:35:23 -0700188
Romain Guyeca0ca22011-11-04 15:12:29 -0700189 uint8_t mGammaTable[256 * kGammaCount];
Romain Guyb1d0a4e2012-07-13 18:25:35 -0700190
191 friend class GammaFontRenderer;
Romain Guyb45c0c92010-08-26 20:35:23 -0700192};
193
194}; // namespace uirenderer
195}; // namespace android
196
Romain Guy5b3b3522010-10-27 18:57:51 -0700197#endif // ANDROID_HWUI_GAMMA_FONT_RENDERER_H