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; |
Victoria Lease | 1e54681 | 2013-06-25 14:25:17 -0700 | [diff] [blame] | 38 | virtual uint32_t getFontRendererSize(uint32_t fontRenderer, GLenum format) const = 0; |
Romain Guy | b1d0a4e | 2012-07-13 18:25:35 -0700 | [diff] [blame] | 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 | cf51a41 | 2013-04-08 19:40:31 -0700 | [diff] [blame] | 43 | virtual void endPrecaching() = 0; |
| 44 | |
Romain Guy | b1d0a4e | 2012-07-13 18:25:35 -0700 | [diff] [blame] | 45 | static GammaFontRenderer* createRenderer(); |
| 46 | |
| 47 | protected: |
| 48 | GammaFontRenderer(); |
| 49 | |
| 50 | int mBlackThreshold; |
| 51 | int mWhiteThreshold; |
| 52 | |
| 53 | float mGamma; |
| 54 | }; |
| 55 | |
| 56 | class ShaderGammaFontRenderer: public GammaFontRenderer { |
| 57 | public: |
| 58 | ~ShaderGammaFontRenderer() { |
| 59 | delete mRenderer; |
| 60 | } |
| 61 | |
| 62 | void clear() { |
| 63 | delete mRenderer; |
Romain Guy | 0aa87bb | 2012-07-20 11:14:32 -0700 | [diff] [blame] | 64 | mRenderer = NULL; |
Romain Guy | b1d0a4e | 2012-07-13 18:25:35 -0700 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | void flush() { |
| 68 | if (mRenderer) { |
| 69 | mRenderer->flushLargeCaches(); |
| 70 | } |
| 71 | } |
| 72 | |
John Reck | f088c34 | 2014-12-12 09:49:29 -0800 | [diff] [blame] | 73 | FontRenderer& getFontRenderer(const SkPaint* paint) { |
Romain Guy | b1d0a4e | 2012-07-13 18:25:35 -0700 | [diff] [blame] | 74 | if (!mRenderer) { |
| 75 | mRenderer = new FontRenderer; |
| 76 | } |
| 77 | return *mRenderer; |
| 78 | } |
| 79 | |
| 80 | uint32_t getFontRendererCount() const { |
| 81 | return 1; |
| 82 | } |
| 83 | |
John Reck | f088c34 | 2014-12-12 09:49:29 -0800 | [diff] [blame] | 84 | uint32_t getFontRendererSize(uint32_t fontRenderer, GLenum format) const { |
Victoria Lease | 1e54681 | 2013-06-25 14:25:17 -0700 | [diff] [blame] | 85 | return mRenderer ? mRenderer->getCacheSize(format) : 0; |
Romain Guy | b1d0a4e | 2012-07-13 18:25:35 -0700 | [diff] [blame] | 86 | } |
| 87 | |
Romain Guy | 4121063 | 2012-07-16 17:04:24 -0700 | [diff] [blame] | 88 | void describe(ProgramDescription& description, const SkPaint* paint) const; |
| 89 | void setupProgram(ProgramDescription& description, Program* program) const; |
| 90 | |
Romain Guy | cf51a41 | 2013-04-08 19:40:31 -0700 | [diff] [blame] | 91 | void endPrecaching(); |
| 92 | |
Romain Guy | b1d0a4e | 2012-07-13 18:25:35 -0700 | [diff] [blame] | 93 | private: |
Romain Guy | 6e25e38 | 2012-07-18 15:50:29 -0700 | [diff] [blame] | 94 | ShaderGammaFontRenderer(bool multiGamma); |
Romain Guy | b1d0a4e | 2012-07-13 18:25:35 -0700 | [diff] [blame] | 95 | |
| 96 | FontRenderer* mRenderer; |
Romain Guy | 6e25e38 | 2012-07-18 15:50:29 -0700 | [diff] [blame] | 97 | bool mMultiGamma; |
Romain Guy | b1d0a4e | 2012-07-13 18:25:35 -0700 | [diff] [blame] | 98 | |
| 99 | friend class GammaFontRenderer; |
| 100 | }; |
| 101 | |
| 102 | class LookupGammaFontRenderer: public GammaFontRenderer { |
| 103 | public: |
Romain Guy | 6e25e38 | 2012-07-18 15:50:29 -0700 | [diff] [blame] | 104 | ~LookupGammaFontRenderer() { |
| 105 | delete mRenderer; |
| 106 | } |
| 107 | |
| 108 | void clear() { |
| 109 | delete mRenderer; |
Romain Guy | 8801b2f | 2012-08-03 17:43:31 -0700 | [diff] [blame] | 110 | mRenderer = NULL; |
Romain Guy | 6e25e38 | 2012-07-18 15:50:29 -0700 | [diff] [blame] | 111 | } |
| 112 | |
| 113 | void flush() { |
| 114 | if (mRenderer) { |
| 115 | mRenderer->flushLargeCaches(); |
| 116 | } |
| 117 | } |
| 118 | |
John Reck | f088c34 | 2014-12-12 09:49:29 -0800 | [diff] [blame] | 119 | FontRenderer& getFontRenderer(const SkPaint* paint) { |
Romain Guy | 6e25e38 | 2012-07-18 15:50:29 -0700 | [diff] [blame] | 120 | if (!mRenderer) { |
| 121 | mRenderer = new FontRenderer; |
| 122 | mRenderer->setGammaTable(&mGammaTable[0]); |
| 123 | } |
| 124 | return *mRenderer; |
| 125 | } |
| 126 | |
| 127 | uint32_t getFontRendererCount() const { |
| 128 | return 1; |
| 129 | } |
| 130 | |
John Reck | f088c34 | 2014-12-12 09:49:29 -0800 | [diff] [blame] | 131 | uint32_t getFontRendererSize(uint32_t fontRenderer, GLenum format) const { |
Victoria Lease | 1e54681 | 2013-06-25 14:25:17 -0700 | [diff] [blame] | 132 | return mRenderer ? mRenderer->getCacheSize(format) : 0; |
Romain Guy | 6e25e38 | 2012-07-18 15:50:29 -0700 | [diff] [blame] | 133 | } |
| 134 | |
John Reck | f088c34 | 2014-12-12 09:49:29 -0800 | [diff] [blame] | 135 | void describe(ProgramDescription& description, const SkPaint* paint) const { |
Romain Guy | 6e25e38 | 2012-07-18 15:50:29 -0700 | [diff] [blame] | 136 | } |
| 137 | |
John Reck | f088c34 | 2014-12-12 09:49:29 -0800 | [diff] [blame] | 138 | void setupProgram(ProgramDescription& description, Program* program) const { |
Romain Guy | 6e25e38 | 2012-07-18 15:50:29 -0700 | [diff] [blame] | 139 | } |
| 140 | |
Romain Guy | cf51a41 | 2013-04-08 19:40:31 -0700 | [diff] [blame] | 141 | void endPrecaching(); |
| 142 | |
Romain Guy | 6e25e38 | 2012-07-18 15:50:29 -0700 | [diff] [blame] | 143 | private: |
| 144 | LookupGammaFontRenderer(); |
| 145 | |
| 146 | FontRenderer* mRenderer; |
| 147 | uint8_t mGammaTable[256]; |
| 148 | |
| 149 | friend class GammaFontRenderer; |
| 150 | }; |
| 151 | |
| 152 | class Lookup3GammaFontRenderer: public GammaFontRenderer { |
| 153 | public: |
| 154 | ~Lookup3GammaFontRenderer(); |
Romain Guy | eca0ca2 | 2011-11-04 15:12:29 -0700 | [diff] [blame] | 155 | |
| 156 | void clear(); |
| 157 | void flush(); |
Romain Guy | b45c0c9 | 2010-08-26 20:35:23 -0700 | [diff] [blame] | 158 | |
| 159 | FontRenderer& getFontRenderer(const SkPaint* paint); |
| 160 | |
Romain Guy | c15008e | 2010-11-10 11:59:15 -0800 | [diff] [blame] | 161 | uint32_t getFontRendererCount() const { |
Romain Guy | eca0ca2 | 2011-11-04 15:12:29 -0700 | [diff] [blame] | 162 | return kGammaCount; |
Romain Guy | c15008e | 2010-11-10 11:59:15 -0800 | [diff] [blame] | 163 | } |
| 164 | |
Victoria Lease | 1e54681 | 2013-06-25 14:25:17 -0700 | [diff] [blame] | 165 | uint32_t getFontRendererSize(uint32_t fontRenderer, GLenum format) const { |
Romain Guy | eca0ca2 | 2011-11-04 15:12:29 -0700 | [diff] [blame] | 166 | if (fontRenderer >= kGammaCount) return 0; |
| 167 | |
| 168 | FontRenderer* renderer = mRenderers[fontRenderer]; |
| 169 | if (!renderer) return 0; |
| 170 | |
Victoria Lease | 1e54681 | 2013-06-25 14:25:17 -0700 | [diff] [blame] | 171 | return renderer->getCacheSize(format); |
Romain Guy | c15008e | 2010-11-10 11:59:15 -0800 | [diff] [blame] | 172 | } |
| 173 | |
John Reck | f088c34 | 2014-12-12 09:49:29 -0800 | [diff] [blame] | 174 | void describe(ProgramDescription& description, const SkPaint* paint) const { |
Romain Guy | 4121063 | 2012-07-16 17:04:24 -0700 | [diff] [blame] | 175 | } |
| 176 | |
John Reck | f088c34 | 2014-12-12 09:49:29 -0800 | [diff] [blame] | 177 | void setupProgram(ProgramDescription& description, Program* program) const { |
Romain Guy | 4121063 | 2012-07-16 17:04:24 -0700 | [diff] [blame] | 178 | } |
| 179 | |
Romain Guy | cf51a41 | 2013-04-08 19:40:31 -0700 | [diff] [blame] | 180 | void endPrecaching(); |
| 181 | |
Romain Guy | b45c0c9 | 2010-08-26 20:35:23 -0700 | [diff] [blame] | 182 | private: |
Romain Guy | 6e25e38 | 2012-07-18 15:50:29 -0700 | [diff] [blame] | 183 | Lookup3GammaFontRenderer(); |
Romain Guy | b1d0a4e | 2012-07-13 18:25:35 -0700 | [diff] [blame] | 184 | |
| 185 | enum Gamma { |
| 186 | kGammaDefault = 0, |
| 187 | kGammaBlack = 1, |
| 188 | kGammaWhite = 2, |
| 189 | kGammaCount = 3 |
| 190 | }; |
| 191 | |
Romain Guy | eca0ca2 | 2011-11-04 15:12:29 -0700 | [diff] [blame] | 192 | FontRenderer* getRenderer(Gamma gamma); |
| 193 | |
| 194 | uint32_t mRenderersUsageCount[kGammaCount]; |
| 195 | FontRenderer* mRenderers[kGammaCount]; |
Romain Guy | b45c0c9 | 2010-08-26 20:35:23 -0700 | [diff] [blame] | 196 | |
Romain Guy | eca0ca2 | 2011-11-04 15:12:29 -0700 | [diff] [blame] | 197 | uint8_t mGammaTable[256 * kGammaCount]; |
Romain Guy | b1d0a4e | 2012-07-13 18:25:35 -0700 | [diff] [blame] | 198 | |
| 199 | friend class GammaFontRenderer; |
Romain Guy | b45c0c9 | 2010-08-26 20:35:23 -0700 | [diff] [blame] | 200 | }; |
| 201 | |
| 202 | }; // namespace uirenderer |
| 203 | }; // namespace android |
| 204 | |
Romain Guy | 5b3b352 | 2010-10-27 18:57:51 -0700 | [diff] [blame] | 205 | #endif // ANDROID_HWUI_GAMMA_FONT_RENDERER_H |