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; |
Chris Craik | 6c15ffa | 2015-02-02 13:50:55 -0800 | [diff] [blame] | 41 | virtual void setupProgram(ProgramDescription& description, Program& program) const = 0; |
Romain Guy | 4121063 | 2012-07-16 17:04:24 -0700 | [diff] [blame] | 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 | |
Chris Craik | e84a208 | 2014-12-22 14:28:49 -0800 | [diff] [blame] | 62 | void clear() override { |
Romain Guy | b1d0a4e | 2012-07-13 18:25:35 -0700 | [diff] [blame] | 63 | delete mRenderer; |
Chris Craik | e84a208 | 2014-12-22 14:28:49 -0800 | [diff] [blame] | 64 | mRenderer = nullptr; |
Romain Guy | b1d0a4e | 2012-07-13 18:25:35 -0700 | [diff] [blame] | 65 | } |
| 66 | |
Chris Craik | e84a208 | 2014-12-22 14:28:49 -0800 | [diff] [blame] | 67 | void flush() override { |
Romain Guy | b1d0a4e | 2012-07-13 18:25:35 -0700 | [diff] [blame] | 68 | if (mRenderer) { |
| 69 | mRenderer->flushLargeCaches(); |
| 70 | } |
| 71 | } |
| 72 | |
Chris Craik | e84a208 | 2014-12-22 14:28:49 -0800 | [diff] [blame] | 73 | FontRenderer& getFontRenderer(const SkPaint* paint) override { |
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 | |
Chris Craik | e84a208 | 2014-12-22 14:28:49 -0800 | [diff] [blame] | 80 | uint32_t getFontRendererCount() const override { |
Romain Guy | b1d0a4e | 2012-07-13 18:25:35 -0700 | [diff] [blame] | 81 | return 1; |
| 82 | } |
| 83 | |
Chris Craik | e84a208 | 2014-12-22 14:28:49 -0800 | [diff] [blame] | 84 | uint32_t getFontRendererSize(uint32_t fontRenderer, GLenum format) const override { |
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 | |
Chris Craik | e84a208 | 2014-12-22 14:28:49 -0800 | [diff] [blame] | 88 | void describe(ProgramDescription& description, const SkPaint* paint) const override; |
Chris Craik | 6c15ffa | 2015-02-02 13:50:55 -0800 | [diff] [blame] | 89 | void setupProgram(ProgramDescription& description, Program& program) const override; |
Romain Guy | 4121063 | 2012-07-16 17:04:24 -0700 | [diff] [blame] | 90 | |
Chris Craik | e84a208 | 2014-12-22 14:28:49 -0800 | [diff] [blame] | 91 | void endPrecaching() override; |
Romain Guy | cf51a41 | 2013-04-08 19:40:31 -0700 | [diff] [blame] | 92 | |
Romain Guy | b1d0a4e | 2012-07-13 18:25:35 -0700 | [diff] [blame] | 93 | private: |
Chih-Hung Hsieh | f35c939 | 2016-08-10 14:08:35 -0700 | [diff] [blame^] | 94 | explicit 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 | |
Chris Craik | e84a208 | 2014-12-22 14:28:49 -0800 | [diff] [blame] | 108 | void clear() override { |
Romain Guy | 6e25e38 | 2012-07-18 15:50:29 -0700 | [diff] [blame] | 109 | delete mRenderer; |
Chris Craik | e84a208 | 2014-12-22 14:28:49 -0800 | [diff] [blame] | 110 | mRenderer = nullptr; |
Romain Guy | 6e25e38 | 2012-07-18 15:50:29 -0700 | [diff] [blame] | 111 | } |
| 112 | |
Chris Craik | e84a208 | 2014-12-22 14:28:49 -0800 | [diff] [blame] | 113 | void flush() override { |
Romain Guy | 6e25e38 | 2012-07-18 15:50:29 -0700 | [diff] [blame] | 114 | if (mRenderer) { |
| 115 | mRenderer->flushLargeCaches(); |
| 116 | } |
| 117 | } |
| 118 | |
Chris Craik | e84a208 | 2014-12-22 14:28:49 -0800 | [diff] [blame] | 119 | FontRenderer& getFontRenderer(const SkPaint* paint) override { |
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 | |
Chris Craik | e84a208 | 2014-12-22 14:28:49 -0800 | [diff] [blame] | 127 | uint32_t getFontRendererCount() const override { |
Romain Guy | 6e25e38 | 2012-07-18 15:50:29 -0700 | [diff] [blame] | 128 | return 1; |
| 129 | } |
| 130 | |
Chris Craik | e84a208 | 2014-12-22 14:28:49 -0800 | [diff] [blame] | 131 | uint32_t getFontRendererSize(uint32_t fontRenderer, GLenum format) const override { |
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 | |
Chris Craik | e84a208 | 2014-12-22 14:28:49 -0800 | [diff] [blame] | 135 | void describe(ProgramDescription& description, const SkPaint* paint) const override { |
Romain Guy | 6e25e38 | 2012-07-18 15:50:29 -0700 | [diff] [blame] | 136 | } |
| 137 | |
Chris Craik | 6c15ffa | 2015-02-02 13:50:55 -0800 | [diff] [blame] | 138 | void setupProgram(ProgramDescription& description, Program& program) const override { |
Romain Guy | 6e25e38 | 2012-07-18 15:50:29 -0700 | [diff] [blame] | 139 | } |
| 140 | |
Chris Craik | e84a208 | 2014-12-22 14:28:49 -0800 | [diff] [blame] | 141 | void endPrecaching() override; |
Romain Guy | cf51a41 | 2013-04-08 19:40:31 -0700 | [diff] [blame] | 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: |
Chris Craik | e84a208 | 2014-12-22 14:28:49 -0800 | [diff] [blame] | 154 | void clear() override; |
| 155 | void flush() override; |
Romain Guy | b45c0c9 | 2010-08-26 20:35:23 -0700 | [diff] [blame] | 156 | |
Chris Craik | e84a208 | 2014-12-22 14:28:49 -0800 | [diff] [blame] | 157 | FontRenderer& getFontRenderer(const SkPaint* paint) override; |
Romain Guy | b45c0c9 | 2010-08-26 20:35:23 -0700 | [diff] [blame] | 158 | |
Chris Craik | e84a208 | 2014-12-22 14:28:49 -0800 | [diff] [blame] | 159 | uint32_t getFontRendererCount() const override { |
Romain Guy | eca0ca2 | 2011-11-04 15:12:29 -0700 | [diff] [blame] | 160 | return kGammaCount; |
Romain Guy | c15008e | 2010-11-10 11:59:15 -0800 | [diff] [blame] | 161 | } |
| 162 | |
Chris Craik | e84a208 | 2014-12-22 14:28:49 -0800 | [diff] [blame] | 163 | uint32_t getFontRendererSize(uint32_t fontRenderer, GLenum format) const override { |
Romain Guy | eca0ca2 | 2011-11-04 15:12:29 -0700 | [diff] [blame] | 164 | if (fontRenderer >= kGammaCount) return 0; |
| 165 | |
Chris Craik | 51d6a3d | 2014-12-22 17:16:56 -0800 | [diff] [blame] | 166 | if (!mRenderers[fontRenderer]) return 0; |
Romain Guy | eca0ca2 | 2011-11-04 15:12:29 -0700 | [diff] [blame] | 167 | |
Chris Craik | 51d6a3d | 2014-12-22 17:16:56 -0800 | [diff] [blame] | 168 | return mRenderers[fontRenderer]->getCacheSize(format); |
Romain Guy | c15008e | 2010-11-10 11:59:15 -0800 | [diff] [blame] | 169 | } |
| 170 | |
Chris Craik | e84a208 | 2014-12-22 14:28:49 -0800 | [diff] [blame] | 171 | void describe(ProgramDescription& description, const SkPaint* paint) const override { |
Romain Guy | 4121063 | 2012-07-16 17:04:24 -0700 | [diff] [blame] | 172 | } |
| 173 | |
Chris Craik | 6c15ffa | 2015-02-02 13:50:55 -0800 | [diff] [blame] | 174 | void setupProgram(ProgramDescription& description, Program& program) const override { |
Romain Guy | 4121063 | 2012-07-16 17:04:24 -0700 | [diff] [blame] | 175 | } |
| 176 | |
Chris Craik | e84a208 | 2014-12-22 14:28:49 -0800 | [diff] [blame] | 177 | void endPrecaching() override; |
Romain Guy | cf51a41 | 2013-04-08 19:40:31 -0700 | [diff] [blame] | 178 | |
Romain Guy | b45c0c9 | 2010-08-26 20:35:23 -0700 | [diff] [blame] | 179 | private: |
Romain Guy | 6e25e38 | 2012-07-18 15:50:29 -0700 | [diff] [blame] | 180 | Lookup3GammaFontRenderer(); |
Romain Guy | b1d0a4e | 2012-07-13 18:25:35 -0700 | [diff] [blame] | 181 | |
| 182 | enum Gamma { |
| 183 | kGammaDefault = 0, |
| 184 | kGammaBlack = 1, |
| 185 | kGammaWhite = 2, |
| 186 | kGammaCount = 3 |
| 187 | }; |
| 188 | |
Romain Guy | eca0ca2 | 2011-11-04 15:12:29 -0700 | [diff] [blame] | 189 | FontRenderer* getRenderer(Gamma gamma); |
| 190 | |
| 191 | uint32_t mRenderersUsageCount[kGammaCount]; |
Chris Craik | 51d6a3d | 2014-12-22 17:16:56 -0800 | [diff] [blame] | 192 | std::unique_ptr<FontRenderer> mRenderers[kGammaCount]; |
Romain Guy | b45c0c9 | 2010-08-26 20:35:23 -0700 | [diff] [blame] | 193 | |
Romain Guy | eca0ca2 | 2011-11-04 15:12:29 -0700 | [diff] [blame] | 194 | uint8_t mGammaTable[256 * kGammaCount]; |
Romain Guy | b1d0a4e | 2012-07-13 18:25:35 -0700 | [diff] [blame] | 195 | |
| 196 | friend class GammaFontRenderer; |
Romain Guy | b45c0c9 | 2010-08-26 20:35:23 -0700 | [diff] [blame] | 197 | }; |
| 198 | |
| 199 | }; // namespace uirenderer |
| 200 | }; // namespace android |
| 201 | |
Romain Guy | 5b3b352 | 2010-10-27 18:57:51 -0700 | [diff] [blame] | 202 | #endif // ANDROID_HWUI_GAMMA_FONT_RENDERER_H |