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 #include "FontCacheHistoryTracker.h" 18 19 #include "CachedGlyphInfo.h" 20 #include "CacheTexture.h" 21 22 namespace android { 23 namespace uirenderer { 24 25 void FontCacheHistoryTracker::dumpCachedGlyph(String8& log, const CachedGlyph& glyph) { 26 log.appendFormat("glyph (texture %p, position: (%d, %d), size: %dx%d, gen: %d)", glyph.texture, 27 glyph.startX, glyph.startY, glyph.bitmapW, glyph.bitmapH, glyph.generation); 28 } 29 30 void 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 40 void 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, 43 glyph.generation); 44 } else { 45 log.appendFormat(" uploaded "); 46 dumpCachedGlyph(log, glyph); 47 log.appendFormat("\n"); 48 } 49 } 50 51 void 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 63 void 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 75 void FontCacheHistoryTracker::glyphUploaded(CacheTexture* texture, uint32_t x, uint32_t y, 76 uint16_t glyphW, uint16_t glyphH) { 77 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 86 void 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 96 void FontCacheHistoryTracker::frameCompleted() { 97 generation++; 98 } 99 }; // namespace uirenderer 100 }; // namespace android 101