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 "FontRenderer.h"
21 
22 namespace android {
23 namespace uirenderer {
24 
25 class GammaFontRenderer {
26 public:
27     GammaFontRenderer();
28 
clear()29     void clear() { mRenderer.reset(nullptr); }
30 
flush()31     void flush() {
32         if (mRenderer) {
33             mRenderer->flushLargeCaches();
34         }
35     }
36 
getFontRenderer()37     FontRenderer& getFontRenderer() {
38         if (!mRenderer) {
39             const uint8_t* table = nullptr;
40 #ifndef ANDROID_ENABLE_LINEAR_BLENDING
41             table = &mGammaTable[0];
42 #endif
43             mRenderer.reset(new FontRenderer(table));
44         }
45         return *mRenderer;
46     }
47 
dumpMemoryUsage(String8 & log)48     void dumpMemoryUsage(String8& log) const {
49         if (mRenderer) {
50             mRenderer->dumpMemoryUsage(log);
51         } else {
52             log.appendFormat("FontRenderer doesn't exist.\n");
53         }
54     }
55 
getSize()56     uint32_t getSize() const { return mRenderer ? mRenderer->getSize() : 0; }
57 
58     void endPrecaching();
59 
60 private:
61     std::unique_ptr<FontRenderer> mRenderer;
62 #ifndef ANDROID_ENABLE_LINEAR_BLENDING
63     uint8_t mGammaTable[256];
64 #endif
65 };
66 
67 };  // namespace uirenderer
68 };  // namespace android
69 
70 #endif  // ANDROID_HWUI_GAMMA_FONT_RENDERER_H
71