blob: c4a50bed3ad2a2a155b02db2bb2b6c2fb91aeb8d [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;
106 }
107
108 void flush() {
109 if (mRenderer) {
110 mRenderer->flushLargeCaches();
111 }
112 }
113
114 FontRenderer& getFontRenderer(const SkPaint* paint) {
115 if (!mRenderer) {
116 mRenderer = new FontRenderer;
117 mRenderer->setGammaTable(&mGammaTable[0]);
118 }
119 return *mRenderer;
120 }
121
122 uint32_t getFontRendererCount() const {
123 return 1;
124 }
125
126 uint32_t getFontRendererSize(uint32_t fontRenderer) const {
127 return mRenderer ? mRenderer->getCacheSize() : 0;
128 }
129
130 void describe(ProgramDescription& description, const SkPaint* paint) const {
131 }
132
133 void setupProgram(ProgramDescription& description, Program* program) const {
134 }
135
136private:
137 LookupGammaFontRenderer();
138
139 FontRenderer* mRenderer;
140 uint8_t mGammaTable[256];
141
142 friend class GammaFontRenderer;
143};
144
145class Lookup3GammaFontRenderer: public GammaFontRenderer {
146public:
147 ~Lookup3GammaFontRenderer();
Romain Guyeca0ca22011-11-04 15:12:29 -0700148
149 void clear();
150 void flush();
Romain Guyb45c0c92010-08-26 20:35:23 -0700151
152 FontRenderer& getFontRenderer(const SkPaint* paint);
153
Romain Guyc15008e2010-11-10 11:59:15 -0800154 uint32_t getFontRendererCount() const {
Romain Guyeca0ca22011-11-04 15:12:29 -0700155 return kGammaCount;
Romain Guyc15008e2010-11-10 11:59:15 -0800156 }
157
158 uint32_t getFontRendererSize(uint32_t fontRenderer) const {
Romain Guyeca0ca22011-11-04 15:12:29 -0700159 if (fontRenderer >= kGammaCount) return 0;
160
161 FontRenderer* renderer = mRenderers[fontRenderer];
162 if (!renderer) return 0;
163
Chet Haase7de0cb12011-12-05 16:35:38 -0800164 return renderer->getCacheSize();
Romain Guyc15008e2010-11-10 11:59:15 -0800165 }
166
Romain Guy41210632012-07-16 17:04:24 -0700167 void describe(ProgramDescription& description, const SkPaint* paint) const {
168 }
169
170 void setupProgram(ProgramDescription& description, Program* program) const {
171 }
172
Romain Guyb45c0c92010-08-26 20:35:23 -0700173private:
Romain Guy6e25e382012-07-18 15:50:29 -0700174 Lookup3GammaFontRenderer();
Romain Guyb1d0a4e2012-07-13 18:25:35 -0700175
176 enum Gamma {
177 kGammaDefault = 0,
178 kGammaBlack = 1,
179 kGammaWhite = 2,
180 kGammaCount = 3
181 };
182
Romain Guyeca0ca22011-11-04 15:12:29 -0700183 FontRenderer* getRenderer(Gamma gamma);
184
185 uint32_t mRenderersUsageCount[kGammaCount];
186 FontRenderer* mRenderers[kGammaCount];
Romain Guyb45c0c92010-08-26 20:35:23 -0700187
Romain Guyeca0ca22011-11-04 15:12:29 -0700188 uint8_t mGammaTable[256 * kGammaCount];
Romain Guyb1d0a4e2012-07-13 18:25:35 -0700189
190 friend class GammaFontRenderer;
Romain Guyb45c0c92010-08-26 20:35:23 -0700191};
192
193}; // namespace uirenderer
194}; // namespace android
195
Romain Guy5b3b3522010-10-27 18:57:51 -0700196#endif // ANDROID_HWUI_GAMMA_FONT_RENDERER_H