create a wrapper to manage --nativeFonts and --gdi

Put it in ToolUtils to avoid cyclic dependencies.

Change-Id: Ie0ad7eb5d1ba58be5ad8c668afdb7c74facd71dc
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/203181
Commit-Queue: Mike Klein <mtklein@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
This commit is contained in:
Mike Klein 2019-03-22 15:30:07 -05:00 committed by Skia Commit-Bot
parent 629f5fc5ec
commit 19cc0f647c
6 changed files with 33 additions and 25 deletions

View File

@ -23,7 +23,6 @@
#include "SkDebugfTracer.h"
#include "SkDocument.h"
#include "SkFontMgr.h"
#include "SkFontMgrPriv.h"
#include "SkGraphics.h"
#include "SkHalf.h"
#include "SkICC.h"
@ -37,7 +36,6 @@
#include "SkTaskGroup.h"
#include "SkTypeface_win.h"
#include "Test.h"
#include "TestFontMgr.h"
#include "ToolUtils.h"
#include "ios_utils.h"
@ -98,8 +96,6 @@ static DEFINE_bool(ignoreSigInt, false, "ignore SIGINT signals during test execu
static DEFINE_string(dont_write, "", "File extensions to skip writing to --writePath."); // See skia:6821
static DEFINE_bool(gdi, false, "On Windows, use GDI instead of DirectWrite for font rendering.");
static DEFINE_bool(checkF16, false, "Ensure that F16Norm pixels are clamped.");
static DEFINE_string(colorImages, "",
@ -1533,16 +1529,6 @@ int main(int argc, char** argv) {
#endif
CommandLineFlags::Parse(argc, argv);
if (!FLAGS_nativeFonts) {
gSkFontMgr_DefaultFactory = &ToolUtils::MakePortableFontMgr;
}
#if defined(SK_BUILD_FOR_WIN)
if (FLAGS_gdi) {
gSkFontMgr_DefaultFactory = &SkFontMgr_New_GDI;
}
#endif
initializeEventTracingForTools();
#if !defined(SK_BUILD_FOR_GOOGLE3) && defined(SK_BUILD_FOR_IOS)
@ -1551,6 +1537,7 @@ int main(int argc, char** argv) {
setbuf(stdout, nullptr);
setup_crash_handler();
ToolUtils::SetDefaultFontMgr();
SetAnalyticAAFromCommonFlags();
if (FLAGS_forceRasterPipeline) {

View File

@ -6,12 +6,14 @@
*/
#include "ToolUtils.h"
#include "CommandLineFlags.h"
#include "SkBitmap.h"
#include "SkBlendMode.h"
#include "SkCanvas.h"
#include "SkColorData.h"
#include "SkColorPriv.h"
#include "SkFloatingPoint.h"
#include "SkFontMgrPriv.h"
#include "SkFontPriv.h"
#include "SkImage.h"
#include "SkMatrix.h"
@ -24,6 +26,8 @@
#include "SkShader.h"
#include "SkSurface.h"
#include "SkTextBlob.h"
#include "SkTypeface_win.h"
#include "TestFontMgr.h"
#include <cmath>
#include <cstring>
@ -436,4 +440,24 @@ sk_sp<SkSurface> makeSurface(SkCanvas* canvas,
}
return surf;
}
static DEFINE_bool(nativeFonts, true,
"If true, use native font manager and rendering. "
"If false, fonts will draw as portably as possible.");
#if defined(SK_BUILD_FOR_WIN)
static DEFINE_bool(gdi, false,
"Use GDI instead of DirectWrite for font rendering.");
#endif
void SetDefaultFontMgr() {
if (!FLAGS_nativeFonts) {
gSkFontMgr_DefaultFactory = &ToolUtils::MakePortableFontMgr;
}
#if defined(SK_BUILD_FOR_WIN)
if (FLAGS_gdi) {
gSkFontMgr_DefaultFactory = &SkFontMgr_New_GDI;
}
#endif
}
} // namespace ToolUtils

View File

@ -69,6 +69,12 @@ static inline sk_sp<SkTypeface> create_portable_typeface() {
return create_portable_typeface(nullptr, SkFontStyle());
}
/**
* Turn on portable (--nonativeFonts) or GDI font rendering (--gdi).
*/
void SetDefaultFontMgr();
void get_text_path(const SkFont&,
const void* text,
size_t length,

View File

@ -36,11 +36,6 @@ DEFINE_string(skps, "skps", "Directory to read skps from.");
DEFINE_string(lotties, "lotties", "Directory to read (Bodymovin) jsons from.");
#endif
DEFINE_bool(nativeFonts,
true,
"If true, use native font manager and rendering. "
"If false, fonts will draw as portably as possible.");
DEFINE_string(svgs, "", "Directory to read SVGs from, or a single SVG file.");
DEFINE_int_2(threads,

View File

@ -17,7 +17,6 @@ DECLARE_bool(quiet);
DECLARE_string(skps);
DECLARE_string(lotties);
DECLARE_string(svgs);
DECLARE_bool(nativeFonts);
DECLARE_int(threads);
DECLARE_string(resourcePath);
DECLARE_bool(verbose);

View File

@ -20,7 +20,6 @@
#include "SampleSlide.h"
#include "SkCanvas.h"
#include "SkColorSpacePriv.h"
#include "SkFontMgrPriv.h"
#include "SkGraphics.h"
#include "SkImagePriv.h"
#include "SkJSONWriter.h"
@ -36,7 +35,7 @@
#include "SkTo.h"
#include "SlideDir.h"
#include "SvgSlide.h"
#include "TestFontMgr.h"
#include "ToolUtils.h"
#include "ccpr/GrCoverageCountingPathRenderer.h"
#include <stdlib.h>
@ -245,9 +244,7 @@ Viewer::Viewer(int argc, char** argv, void* platformData)
SetResourcePath("/data/local/tmp/resources");
#endif
if (!FLAGS_nativeFonts) {
gSkFontMgr_DefaultFactory = &ToolUtils::MakePortableFontMgr;
}
ToolUtils::SetDefaultFontMgr();
initializeEventTracingForTools();
static SkTaskGroup::Enabler kTaskGroupEnabler(FLAGS_threads);