Add API for glyph cache read failures

This will allow chromium to do a dump without crashing so we can get
more information about what's going wrong on webview in the field.

Bug: chromium:977231
Change-Id: I9022921aded735764d36868bb6606674654439bc
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/228389
Reviewed-by: Mike Klein <mtklein@google.com>
Reviewed-by: Khushal Sagar <khushalsagar@chromium.org>
Commit-Queue: Mike Klein <mtklein@google.com>
Auto-Submit: Adrienne Walker <enne@chromium.org>
This commit is contained in:
Adrienne Walker 2019-07-18 14:03:18 -07:00 committed by Skia Commit-Bot
parent ebab03ffbf
commit 1874ccbd5c
2 changed files with 24 additions and 7 deletions

View File

@ -151,6 +151,8 @@ public:
return this->ensureAtLeast(size, alignment); return this->ensureAtLeast(size, alignment);
} }
size_t bytesRead() const { return fBytesRead; }
private: private:
const volatile char* ensureAtLeast(size_t size, size_t alignment) { const volatile char* ensureAtLeast(size_t size, size_t alignment) {
size_t padded = pad(fBytesRead, alignment); size_t padded = pad(fBytesRead, alignment);
@ -622,10 +624,14 @@ SkStrikeClient::SkStrikeClient(sk_sp<DiscardableHandleManager> discardableManage
SkStrikeClient::~SkStrikeClient() = default; SkStrikeClient::~SkStrikeClient() = default;
#define READ_FAILURE \ #define READ_FAILURE \
{ \ { \
SkDebugf("Bad font data serialization line: %d", __LINE__); \ SkDebugf("Bad font data serialization line: %d", __LINE__); \
return false; \ DiscardableHandleManager::ReadFailureData data = { \
memorySize, deserializer.bytesRead(), typefaceSize, \
strikeCount, glyphImagesCount, glyphPathsCount}; \
fDiscardableHandleManager->notifyReadFailure(data); \
return false; \
} }
// No need to read fForceBW because it is a flag private to SkScalerContext_DW, which will never // No need to read fForceBW because it is a flag private to SkScalerContext_DW, which will never
@ -651,6 +657,10 @@ bool SkStrikeClient::readStrikeData(const volatile void* memory, size_t memorySi
Deserializer deserializer(static_cast<const volatile char*>(memory), memorySize); Deserializer deserializer(static_cast<const volatile char*>(memory), memorySize);
uint64_t typefaceSize = 0u; uint64_t typefaceSize = 0u;
uint64_t strikeCount = 0u;
uint64_t glyphImagesCount = 0u;
uint64_t glyphPathsCount = 0u;
if (!deserializer.read<uint64_t>(&typefaceSize)) READ_FAILURE if (!deserializer.read<uint64_t>(&typefaceSize)) READ_FAILURE
for (size_t i = 0; i < typefaceSize; ++i) { for (size_t i = 0; i < typefaceSize; ++i) {
@ -663,7 +673,6 @@ bool SkStrikeClient::readStrikeData(const volatile void* memory, size_t memorySi
addTypeface(wire); addTypeface(wire);
} }
uint64_t strikeCount = 0u;
if (!deserializer.read<uint64_t>(&strikeCount)) READ_FAILURE if (!deserializer.read<uint64_t>(&strikeCount)) READ_FAILURE
for (size_t i = 0; i < strikeCount; ++i) { for (size_t i = 0; i < strikeCount; ++i) {
@ -708,7 +717,6 @@ bool SkStrikeClient::readStrikeData(const volatile void* memory, size_t memorySi
proxyContext->initCache(strike.get(), fStrikeCache); proxyContext->initCache(strike.get(), fStrikeCache);
} }
uint64_t glyphImagesCount = 0u;
if (!deserializer.read<uint64_t>(&glyphImagesCount)) READ_FAILURE if (!deserializer.read<uint64_t>(&glyphImagesCount)) READ_FAILURE
for (size_t j = 0; j < glyphImagesCount; j++) { for (size_t j = 0; j < glyphImagesCount; j++) {
SkTLazy<SkGlyph> glyph; SkTLazy<SkGlyph> glyph;
@ -724,7 +732,6 @@ bool SkStrikeClient::readStrikeData(const volatile void* memory, size_t memorySi
strike->mergeGlyphAndImage(glyph->getPackedID(), *glyph); strike->mergeGlyphAndImage(glyph->getPackedID(), *glyph);
} }
uint64_t glyphPathsCount = 0u;
if (!deserializer.read<uint64_t>(&glyphPathsCount)) READ_FAILURE if (!deserializer.read<uint64_t>(&glyphPathsCount)) READ_FAILURE
for (size_t j = 0; j < glyphPathsCount; j++) { for (size_t j = 0; j < glyphPathsCount; j++) {
SkTLazy<SkGlyph> glyph; SkTLazy<SkGlyph> glyph;

View File

@ -195,6 +195,16 @@ public:
virtual bool deleteHandle(SkDiscardableHandleId) = 0; virtual bool deleteHandle(SkDiscardableHandleId) = 0;
virtual void notifyCacheMiss(CacheMissType) {} virtual void notifyCacheMiss(CacheMissType) {}
struct ReadFailureData {
size_t memorySize;
size_t bytesRead;
uint64_t typefaceSize;
uint64_t strikeCount;
uint64_t glyphImagesCount;
uint64_t glyphPathsCount;
};
virtual void notifyReadFailure(const ReadFailureData& data) {}
}; };
explicit SkStrikeClient(sk_sp<DiscardableHandleManager>, explicit SkStrikeClient(sk_sp<DiscardableHandleManager>,