aa97a84404
Reason for revert: Chrome is calling SK_CRASH Original issue's description: > Consolidate SK_CRASH and sk_throw into SK_ABORT > GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1610823002 > > Committed: https://skia.googlesource.com/skia/+/4c5cd7d527ed29aabfa72aa47b23a4496eeda357 TBR=reed@google.com # Skipping CQ checks because original CL landed less than 1 days ago. NOPRESUBMIT=true NOTREECHECKS=true NOTRY=true Review URL: https://codereview.chromium.org/1620333002
72 lines
2.1 KiB
C++
72 lines
2.1 KiB
C++
/*
|
|
* Copyright 2014 Google Inc.
|
|
*
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
* found in the LICENSE file.
|
|
*/
|
|
|
|
#include "Resources.h"
|
|
#include "SkFontMgr.h"
|
|
#include "SkMutex.h"
|
|
#include "SkOSFile.h"
|
|
#include "SkTestScalerContext.h"
|
|
#include "SkUtils.h"
|
|
#include "sk_tool_utils.h"
|
|
|
|
namespace sk_tool_utils {
|
|
|
|
#include "test_font_monospace.cpp"
|
|
#include "test_font_sans_serif.cpp"
|
|
#include "test_font_serif.cpp"
|
|
#include "test_font_index.cpp"
|
|
|
|
void release_portable_typefaces() {
|
|
for (int index = 0; index < gTestFontsCount; ++index) {
|
|
SkTestFontData& fontData = gTestFonts[index];
|
|
SkSafeUnref(fontData.fFontCache);
|
|
}
|
|
}
|
|
|
|
SK_DECLARE_STATIC_MUTEX(gTestFontMutex);
|
|
|
|
SkTypeface* create_font(const char* name, SkTypeface::Style style) {
|
|
SkTestFontData* fontData = nullptr;
|
|
const SubFont* sub;
|
|
if (name) {
|
|
for (int index = 0; index < gSubFontsCount; ++index) {
|
|
sub = &gSubFonts[index];
|
|
if (!strcmp(name, sub->fName) && sub->fStyle == style) {
|
|
fontData = &sub->fFont;
|
|
break;
|
|
}
|
|
}
|
|
if (!fontData) {
|
|
// Once all legacy callers to portable fonts are converted, replace this with
|
|
// SK_CRASH();
|
|
SkDebugf("missing %s %d\n", name, style);
|
|
// If we called SkTypeface::CreateFromName() here we'd recurse infinitely,
|
|
// so we reimplement its core logic here inline without the recursive aspect.
|
|
SkAutoTUnref<SkFontMgr> fm(SkFontMgr::RefDefault());
|
|
return fm->legacyCreateTypeface(name, style);
|
|
}
|
|
} else {
|
|
sub = &gSubFonts[gDefaultFontIndex];
|
|
fontData = &sub->fFont;
|
|
}
|
|
SkTestFont* font;
|
|
{
|
|
SkAutoMutexAcquire ac(gTestFontMutex);
|
|
if (fontData->fFontCache) {
|
|
font = SkSafeRef(fontData->fFontCache);
|
|
} else {
|
|
font = new SkTestFont(*fontData);
|
|
SkDEBUGCODE(font->fDebugName = sub->fName);
|
|
SkDEBUGCODE(font->fDebugStyle = sub->fStyle);
|
|
fontData->fFontCache = SkSafeRef(font);
|
|
}
|
|
}
|
|
return new SkTestTypeface(font, SkFontStyle(style));
|
|
}
|
|
|
|
}
|