Romain Guy | b45c0c9 | 2010-08-26 20:35:23 -0700 | [diff] [blame] | 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 | |
Romain Guy | 5b3b352 | 2010-10-27 18:57:51 -0700 | [diff] [blame] | 17 | #ifndef ANDROID_HWUI_GAMMA_FONT_RENDERER_H |
| 18 | #define ANDROID_HWUI_GAMMA_FONT_RENDERER_H |
Romain Guy | b45c0c9 | 2010-08-26 20:35:23 -0700 | [diff] [blame] | 19 | |
| 20 | #include <SkPaint.h> |
| 21 | |
| 22 | #include "FontRenderer.h" |
Romain Guy | 4121063 | 2012-07-16 17:04:24 -0700 | [diff] [blame] | 23 | #include "Program.h" |
Romain Guy | b45c0c9 | 2010-08-26 20:35:23 -0700 | [diff] [blame] | 24 | |
| 25 | namespace android { |
| 26 | namespace uirenderer { |
| 27 | |
Romain Guy | b1d0a4e | 2012-07-13 18:25:35 -0700 | [diff] [blame] | 28 | class GammaFontRenderer { |
| 29 | public: |
| 30 | virtual ~GammaFontRenderer(); |
Romain Guy | eca0ca2 | 2011-11-04 15:12:29 -0700 | [diff] [blame] | 31 | |
Romain Guy | b1d0a4e | 2012-07-13 18:25:35 -0700 | [diff] [blame] | 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; |
Romain Guy | b1d0a4e | 2012-07-13 18:25:35 -0700 | [diff] [blame] | 38 | virtual uint32_t getFontRendererSize(uint32_t fontRenderer) const = 0; |
| 39 | |
Romain Guy | 4121063 | 2012-07-16 17:04:24 -0700 | [diff] [blame] | 40 | virtual void describe(ProgramDescription& description, const SkPaint* paint) const = 0; |
| 41 | virtual void setupProgram(ProgramDescription& description, Program* program) const = 0; |
| 42 | |
Romain Guy | b1d0a4e | 2012-07-13 18:25:35 -0700 | [diff] [blame] | 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: |
| 56 | ~ShaderGammaFontRenderer() { |
| 57 | delete mRenderer; |
| 58 | } |
| 59 | |
| 60 | void clear() { |
| 61 | delete mRenderer; |
Romain Guy | 0aa87bb | 2012-07-20 11:14:32 -0700 | [diff] [blame] | 62 | mRenderer = NULL; |
Romain Guy | b1d0a4e | 2012-07-13 18:25:35 -0700 | [diff] [blame] | 63 | } |
| 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 Guy | 6e25e38 | 2012-07-18 15:50:29 -0700 | [diff] [blame] | 83 | return mRenderer ? mRenderer->getCacheSize() : 0; |
Romain Guy | b1d0a4e | 2012-07-13 18:25:35 -0700 | [diff] [blame] | 84 | } |
| 85 | |
Romain Guy | 4121063 | 2012-07-16 17:04:24 -0700 | [diff] [blame] | 86 | void describe(ProgramDescription& description, const SkPaint* paint) const; |
| 87 | void setupProgram(ProgramDescription& description, Program* program) const; |
| 88 | |
Romain Guy | b1d0a4e | 2012-07-13 18:25:35 -0700 | [diff] [blame] | 89 | private: |
Romain Guy | 6e25e38 | 2012-07-18 15:50:29 -0700 | [diff] [blame] | 90 | ShaderGammaFontRenderer(bool multiGamma); |
Romain Guy | b1d0a4e | 2012-07-13 18:25:35 -0700 | [diff] [blame] | 91 | |
| 92 | FontRenderer* mRenderer; |
Romain Guy | 6e25e38 | 2012-07-18 15:50:29 -0700 | [diff] [blame] | 93 | bool mMultiGamma; |
Romain Guy | b1d0a4e | 2012-07-13 18:25:35 -0700 | [diff] [blame] | 94 | |
| 95 | friend class GammaFontRenderer; |
| 96 | }; |
| 97 | |
| 98 | class LookupGammaFontRenderer: public GammaFontRenderer { |
| 99 | public: |
Romain Guy | 6e25e38 | 2012-07-18 15:50:29 -0700 | [diff] [blame] | 100 | ~LookupGammaFontRenderer() { |
| 101 | delete mRenderer; |
| 102 | } |
| 103 | |
| 104 | void clear() { |
| 105 | delete mRenderer; |
Romain Guy | 8801b2f | 2012-08-03 17:43:31 -0700 | [diff] [blame] | 106 | mRenderer = NULL; |
Romain Guy | 6e25e38 | 2012-07-18 15:50:29 -0700 | [diff] [blame] | 107 | } |
| 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 | |
| 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(); |
Romain Guy | eca0ca2 | 2011-11-04 15:12:29 -0700 | [diff] [blame] | 149 | |
| 150 | void clear(); |
| 151 | void flush(); |
Romain Guy | b45c0c9 | 2010-08-26 20:35:23 -0700 | [diff] [blame] | 152 | |
| 153 | FontRenderer& getFontRenderer(const SkPaint* paint); |
| 154 | |
Romain Guy | c15008e | 2010-11-10 11:59:15 -0800 | [diff] [blame] | 155 | uint32_t getFontRendererCount() const { |
Romain Guy | eca0ca2 | 2011-11-04 15:12:29 -0700 | [diff] [blame] | 156 | return kGammaCount; |
Romain Guy | c15008e | 2010-11-10 11:59:15 -0800 | [diff] [blame] | 157 | } |
| 158 | |
| 159 | uint32_t getFontRendererSize(uint32_t fontRenderer) const { |
Romain Guy | eca0ca2 | 2011-11-04 15:12:29 -0700 | [diff] [blame] | 160 | if (fontRenderer >= kGammaCount) return 0; |
| 161 | |
| 162 | FontRenderer* renderer = mRenderers[fontRenderer]; |
| 163 | if (!renderer) return 0; |
| 164 | |
Chet Haase | 7de0cb1 | 2011-12-05 16:35:38 -0800 | [diff] [blame] | 165 | return renderer->getCacheSize(); |
Romain Guy | c15008e | 2010-11-10 11:59:15 -0800 | [diff] [blame] | 166 | } |
| 167 | |
Romain Guy | 4121063 | 2012-07-16 17:04:24 -0700 | [diff] [blame] | 168 | void describe(ProgramDescription& description, const SkPaint* paint) const { |
| 169 | } |
| 170 | |
| 171 | void setupProgram(ProgramDescription& description, Program* program) const { |
| 172 | } |
| 173 | |
Romain Guy | b45c0c9 | 2010-08-26 20:35:23 -0700 | [diff] [blame] | 174 | private: |
Romain Guy | 6e25e38 | 2012-07-18 15:50:29 -0700 | [diff] [blame] | 175 | Lookup3GammaFontRenderer(); |
Romain Guy | b1d0a4e | 2012-07-13 18:25:35 -0700 | [diff] [blame] | 176 | |
| 177 | enum Gamma { |
| 178 | kGammaDefault = 0, |
| 179 | kGammaBlack = 1, |
| 180 | kGammaWhite = 2, |
| 181 | kGammaCount = 3 |
| 182 | }; |
| 183 | |
Romain Guy | eca0ca2 | 2011-11-04 15:12:29 -0700 | [diff] [blame] | 184 | FontRenderer* getRenderer(Gamma gamma); |
| 185 | |
| 186 | uint32_t mRenderersUsageCount[kGammaCount]; |
| 187 | FontRenderer* mRenderers[kGammaCount]; |
Romain Guy | b45c0c9 | 2010-08-26 20:35:23 -0700 | [diff] [blame] | 188 | |
Romain Guy | eca0ca2 | 2011-11-04 15:12:29 -0700 | [diff] [blame] | 189 | uint8_t mGammaTable[256 * kGammaCount]; |
Romain Guy | b1d0a4e | 2012-07-13 18:25:35 -0700 | [diff] [blame] | 190 | |
| 191 | friend class GammaFontRenderer; |
Romain Guy | b45c0c9 | 2010-08-26 20:35:23 -0700 | [diff] [blame] | 192 | }; |
| 193 | |
| 194 | }; // namespace uirenderer |
| 195 | }; // namespace android |
| 196 | |
Romain Guy | 5b3b352 | 2010-10-27 18:57:51 -0700 | [diff] [blame] | 197 | #endif // ANDROID_HWUI_GAMMA_FONT_RENDERER_H |