blob: 5b61c494524a3204c486b6e016e539e2e35bf334 [file] [log] [blame]
sergeyvaf102be2016-09-09 18:02:07 -07001/*
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#include "FontCacheHistoryTracker.h"
18
sergeyvaf102be2016-09-09 18:02:07 -070019#include "CacheTexture.h"
John Reck1bcacfd2017-11-03 10:12:19 -070020#include "CachedGlyphInfo.h"
sergeyvaf102be2016-09-09 18:02:07 -070021
22namespace android {
23namespace uirenderer {
24
25void FontCacheHistoryTracker::dumpCachedGlyph(String8& log, const CachedGlyph& glyph) {
26 log.appendFormat("glyph (texture %p, position: (%d, %d), size: %dx%d, gen: %d)", glyph.texture,
John Reck1bcacfd2017-11-03 10:12:19 -070027 glyph.startX, glyph.startY, glyph.bitmapW, glyph.bitmapH, glyph.generation);
sergeyvaf102be2016-09-09 18:02:07 -070028}
29
30void FontCacheHistoryTracker::dumpRenderEntry(String8& log, const RenderEntry& entry) {
31 if (entry.penX == -1 && entry.penY == -1) {
32 log.appendFormat(" glyph skipped in gen: %d\n", entry.glyph.generation);
33 } else {
34 log.appendFormat(" rendered ");
35 dumpCachedGlyph(log, entry.glyph);
36 log.appendFormat(" at (%d, %d)\n", entry.penX, entry.penY);
37 }
38}
39
40void FontCacheHistoryTracker::dumpUploadEntry(String8& log, const CachedGlyph& glyph) {
41 if (glyph.bitmapW == 0 && glyph.bitmapH == 0) {
42 log.appendFormat(" cleared cachetexture %p in gen %d\n", glyph.texture,
John Reck1bcacfd2017-11-03 10:12:19 -070043 glyph.generation);
sergeyvaf102be2016-09-09 18:02:07 -070044 } else {
45 log.appendFormat(" uploaded ");
46 dumpCachedGlyph(log, glyph);
47 log.appendFormat("\n");
48 }
49}
50
51void FontCacheHistoryTracker::dump(String8& log) const {
52 log.appendFormat("FontCacheHistory: \n");
53 log.appendFormat(" Upload history: \n");
54 for (size_t i = 0; i < mUploadHistory.size(); i++) {
55 dumpUploadEntry(log, mUploadHistory[i]);
56 }
57 log.appendFormat(" Render history: \n");
58 for (size_t i = 0; i < mRenderHistory.size(); i++) {
59 dumpRenderEntry(log, mRenderHistory[i]);
60 }
61}
62
63void FontCacheHistoryTracker::glyphRendered(CachedGlyphInfo* glyphInfo, int penX, int penY) {
64 RenderEntry& entry = mRenderHistory.next();
65 entry.glyph.generation = generation;
66 entry.glyph.texture = glyphInfo->mCacheTexture;
67 entry.glyph.startX = glyphInfo->mStartX;
68 entry.glyph.startY = glyphInfo->mStartY;
69 entry.glyph.bitmapW = glyphInfo->mBitmapWidth;
70 entry.glyph.bitmapH = glyphInfo->mBitmapHeight;
71 entry.penX = penX;
72 entry.penY = penY;
73}
74
75void FontCacheHistoryTracker::glyphUploaded(CacheTexture* texture, uint32_t x, uint32_t y,
John Reck1bcacfd2017-11-03 10:12:19 -070076 uint16_t glyphW, uint16_t glyphH) {
sergeyvaf102be2016-09-09 18:02:07 -070077 CachedGlyph& glyph = mUploadHistory.next();
78 glyph.generation = generation;
79 glyph.texture = texture;
80 glyph.startX = x;
81 glyph.startY = y;
82 glyph.bitmapW = glyphW;
83 glyph.bitmapH = glyphH;
84}
85
86void FontCacheHistoryTracker::glyphsCleared(CacheTexture* texture) {
87 CachedGlyph& glyph = mUploadHistory.next();
88 glyph.generation = generation;
89 glyph.texture = texture;
90 glyph.startX = 0;
91 glyph.startY = 0;
92 glyph.bitmapW = 0;
93 glyph.bitmapH = 0;
94}
95
96void FontCacheHistoryTracker::frameCompleted() {
97 generation++;
98}
John Reck1bcacfd2017-11-03 10:12:19 -070099}; // namespace uirenderer
100}; // namespace android