• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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 
17 #ifndef ANDROID_HWUI_GAMMA_FONT_RENDERER_H
18 #define ANDROID_HWUI_GAMMA_FONT_RENDERER_H
19 
20 #include <SkPaint.h>
21 
22 #include "FontRenderer.h"
23 #include "Program.h"
24 
25 namespace android {
26 namespace uirenderer {
27 
28 class GammaFontRenderer {
29 public:
30     virtual ~GammaFontRenderer();
31 
32     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;
38     virtual uint32_t getFontRendererSize(uint32_t fontRenderer) const = 0;
39 
40     virtual void describe(ProgramDescription& description, const SkPaint* paint) const = 0;
41     virtual void setupProgram(ProgramDescription& description, Program* program) const = 0;
42 
43     static GammaFontRenderer* createRenderer();
44 
45 protected:
46     GammaFontRenderer();
47 
48     int mBlackThreshold;
49     int mWhiteThreshold;
50 
51     float mGamma;
52 };
53 
54 class ShaderGammaFontRenderer: public GammaFontRenderer {
55 public:
~ShaderGammaFontRenderer()56     ~ShaderGammaFontRenderer() {
57         delete mRenderer;
58     }
59 
clear()60     void clear() {
61         delete mRenderer;
62         mRenderer = NULL;
63     }
64 
flush()65     void flush() {
66         if (mRenderer) {
67             mRenderer->flushLargeCaches();
68         }
69     }
70 
getFontRenderer(const SkPaint * paint)71     FontRenderer& getFontRenderer(const SkPaint* paint) {
72         if (!mRenderer) {
73             mRenderer = new FontRenderer;
74         }
75         return *mRenderer;
76     }
77 
getFontRendererCount()78     uint32_t getFontRendererCount() const {
79         return 1;
80     }
81 
getFontRendererSize(uint32_t fontRenderer)82     uint32_t getFontRendererSize(uint32_t fontRenderer) const {
83         return mRenderer ? mRenderer->getCacheSize() : 0;
84     }
85 
86     void describe(ProgramDescription& description, const SkPaint* paint) const;
87     void setupProgram(ProgramDescription& description, Program* program) const;
88 
89 private:
90     ShaderGammaFontRenderer(bool multiGamma);
91 
92     FontRenderer* mRenderer;
93     bool mMultiGamma;
94 
95     friend class GammaFontRenderer;
96 };
97 
98 class LookupGammaFontRenderer: public GammaFontRenderer {
99 public:
~LookupGammaFontRenderer()100     ~LookupGammaFontRenderer() {
101         delete mRenderer;
102     }
103 
clear()104     void clear() {
105         delete mRenderer;
106         mRenderer = NULL;
107     }
108 
flush()109     void flush() {
110         if (mRenderer) {
111             mRenderer->flushLargeCaches();
112         }
113     }
114 
getFontRenderer(const SkPaint * paint)115     FontRenderer& getFontRenderer(const SkPaint* paint) {
116         if (!mRenderer) {
117             mRenderer = new FontRenderer;
118             mRenderer->setGammaTable(&mGammaTable[0]);
119         }
120         return *mRenderer;
121     }
122 
getFontRendererCount()123     uint32_t getFontRendererCount() const {
124         return 1;
125     }
126 
getFontRendererSize(uint32_t fontRenderer)127     uint32_t getFontRendererSize(uint32_t fontRenderer) const {
128         return mRenderer ? mRenderer->getCacheSize() : 0;
129     }
130 
describe(ProgramDescription & description,const SkPaint * paint)131     void describe(ProgramDescription& description, const SkPaint* paint) const {
132     }
133 
setupProgram(ProgramDescription & description,Program * program)134     void setupProgram(ProgramDescription& description, Program* program) const {
135     }
136 
137 private:
138     LookupGammaFontRenderer();
139 
140     FontRenderer* mRenderer;
141     uint8_t mGammaTable[256];
142 
143     friend class GammaFontRenderer;
144 };
145 
146 class Lookup3GammaFontRenderer: public GammaFontRenderer {
147 public:
148     ~Lookup3GammaFontRenderer();
149 
150     void clear();
151     void flush();
152 
153     FontRenderer& getFontRenderer(const SkPaint* paint);
154 
getFontRendererCount()155     uint32_t getFontRendererCount() const {
156         return kGammaCount;
157     }
158 
getFontRendererSize(uint32_t fontRenderer)159     uint32_t getFontRendererSize(uint32_t fontRenderer) const {
160         if (fontRenderer >= kGammaCount) return 0;
161 
162         FontRenderer* renderer = mRenderers[fontRenderer];
163         if (!renderer) return 0;
164 
165         return renderer->getCacheSize();
166     }
167 
describe(ProgramDescription & description,const SkPaint * paint)168     void describe(ProgramDescription& description, const SkPaint* paint) const {
169     }
170 
setupProgram(ProgramDescription & description,Program * program)171     void setupProgram(ProgramDescription& description, Program* program) const {
172     }
173 
174 private:
175     Lookup3GammaFontRenderer();
176 
177     enum Gamma {
178         kGammaDefault = 0,
179         kGammaBlack = 1,
180         kGammaWhite = 2,
181         kGammaCount = 3
182     };
183 
184     FontRenderer* getRenderer(Gamma gamma);
185 
186     uint32_t mRenderersUsageCount[kGammaCount];
187     FontRenderer* mRenderers[kGammaCount];
188 
189     uint8_t mGammaTable[256 * kGammaCount];
190 
191     friend class GammaFontRenderer;
192 };
193 
194 }; // namespace uirenderer
195 }; // namespace android
196 
197 #endif // ANDROID_HWUI_GAMMA_FONT_RENDERER_H
198