1/*
2 * Copyright (C) 2016 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#pragma once
18#include "../utils/RingBuffer.h"
19
20#include <utils/String8.h>
21
22namespace android {
23namespace uirenderer {
24
25class CacheTexture;
26struct CachedGlyphInfo;
27
28// Tracks glyph uploads and recent rendered/skipped glyphs, so it can give an idea
29// what a missing character is: skipped glyph, wrong coordinates in cache texture etc.
30class FontCacheHistoryTracker {
31public:
32    void glyphRendered(CachedGlyphInfo*, int penX, int penY);
33    void glyphUploaded(CacheTexture*, uint32_t x, uint32_t y, uint16_t glyphW, uint16_t glyphH);
34    void glyphsCleared(CacheTexture*);
35    void frameCompleted();
36
37    void dump(String8& log) const;
38private:
39    struct CachedGlyph {
40        void* texture;
41        uint16_t generation;
42        uint16_t startX;
43        uint16_t startY;
44        uint16_t bitmapW;
45        uint16_t bitmapH;
46    };
47
48    struct RenderEntry {
49        CachedGlyph glyph;
50        int penX;
51        int penY;
52    };
53
54    static void dumpCachedGlyph(String8& log, const CachedGlyph& glyph);
55    static void dumpRenderEntry(String8& log, const RenderEntry& entry);
56    static void dumpUploadEntry(String8& log, const CachedGlyph& glyph);
57
58    RingBuffer<RenderEntry, 300> mRenderHistory;
59    RingBuffer<CachedGlyph, 120> mUploadHistory;
60    uint16_t generation = 0;
61};
62
63}; // namespace uirenderer
64}; // namespace android