From ef59974708dade6fa72fb0218d4f8a9590175c47 Mon Sep 17 00:00:00 2001 From: halcanary Date: Wed, 3 Aug 2016 15:30:37 -0700 Subject: [PATCH] SkRTConf: reduce functionality to what we use, increase simplicity GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2212473002 DOCS_PREVIEW= https://skia.org/?cl=2212473002 CQ_INCLUDE_TRYBOTS=master.client.skia:Test-Ubuntu-GCC-GCE-CPU-AVX2-x86_64-Release-SKNX_NO_SIMD-Trybot [mtklein] TBR=reed@google.com Only removing unused public API. Review-Url: https://codereview.chromium.org/2212473002 --- BUILD.gn | 1 - gyp/utils.gypi | 2 - include/utils/SkRTConf.h | 193 ------------- site/dev/runtime/config.md | 89 ------ site/dev/runtime/index.md | 181 ------------ src/core/SkGraphics.cpp | 10 - src/effects/SkBlurMaskFilter.cpp | 9 +- src/gpu/batches/GrAADistanceFieldPathRenderer.cpp | 1 - src/gpu/gl/GrGLGpuProgramCache.cpp | 5 +- src/gpu/gl/builders/GrGLProgramBuilder.cpp | 1 - src/gpu/gl/builders/GrGLShaderStringBuilder.cpp | 5 +- src/gpu/vk/GrVkPipelineStateCache.cpp | 1 - src/images/SkJPEGImageEncoder.cpp | 1 - src/images/SkPNGImageEncoder.cpp | 9 +- src/opts/opts_check_x86.cpp | 1 - src/utils/SkRTConf.cpp | 325 ---------------------- tests/PathOpsExtendedTest.cpp | 5 - tests/PathOpsSkpClipTest.cpp | 14 +- tests/RTConfRegistryTest.cpp | 25 -- tests/RuntimeConfigTest.cpp | 28 -- tests/SkpSkGrTest.cpp | 1 - 21 files changed, 13 insertions(+), 894 deletions(-) delete mode 100644 include/utils/SkRTConf.h delete mode 100644 site/dev/runtime/config.md delete mode 100644 site/dev/runtime/index.md delete mode 100644 src/utils/SkRTConf.cpp delete mode 100644 tests/RTConfRegistryTest.cpp delete mode 100644 tests/RuntimeConfigTest.cpp diff --git a/BUILD.gn b/BUILD.gn index 0d15f31..5a1ee01 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -461,7 +461,6 @@ test_lib("tests") { sources = tests_sources - [ rebase_path("tests/FontMgrAndroidParserTest.cpp"), # Android only rebase_path("tests/PathOpsSkpClipTest.cpp"), # alternate main - rebase_path("tests/RTConfRegistryTest.cpp"), # TODO: delete rebase_path("tests/SkSLErrorTest.cpp"), # TODO: make work rebase_path("tests/SkSLGLSLTest.cpp"), # TODO: make work rebase_path("tests/SkpSkGrTest.cpp"), # doesn't compile diff --git a/gyp/utils.gypi b/gyp/utils.gypi index ac14a74..4903f3d 100644 --- a/gyp/utils.gypi +++ b/gyp/utils.gypi @@ -28,7 +28,6 @@ '<(skia_include_path)/utils/SkParsePath.h', '<(skia_include_path)/utils/SkPictureUtils.h', '<(skia_include_path)/utils/SkRandom.h', - '<(skia_include_path)/utils/SkRTConf.h', '<(skia_include_path)/utils/SkTextBox.h', '<(skia_src_path)/utils/SkBase64.cpp', @@ -68,7 +67,6 @@ '<(skia_src_path)/utils/SkPatchUtils.h', '<(skia_src_path)/utils/SkRGBAToYUV.cpp', '<(skia_src_path)/utils/SkRGBAToYUV.h', - '<(skia_src_path)/utils/SkRTConf.cpp', '<(skia_src_path)/utils/SkTextBox.cpp', '<(skia_src_path)/utils/SkTextureCompressor.cpp', '<(skia_src_path)/utils/SkTextureCompressor.h', diff --git a/include/utils/SkRTConf.h b/include/utils/SkRTConf.h deleted file mode 100644 index d80e418..0000000 --- a/include/utils/SkRTConf.h +++ /dev/null @@ -1,193 +0,0 @@ -/* - * Copyright 2013 Google, Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - - -#ifndef SkRTConf_DEFINED -#define SkRTConf_DEFINED - -#include "../private/SkTDArray.h" -#include "../private/SkTDict.h" -#include "SkString.h" -#include "SkStream.h" - -/** \class SkRTConfBase - Non-templated base class for the runtime configs -*/ - -class SkRTConfBase { -public: - SkRTConfBase(const char *name) : fName(name) {} - virtual ~SkRTConfBase() {} - virtual const char *getName() const { return fName.c_str(); } - virtual bool isDefault() const = 0; - virtual void print(SkWStream *o) const = 0; - virtual bool equals(const SkRTConfBase *conf) const = 0; -protected: - SkString fName; -}; - -/** \class SkRTConf - A class to provide runtime configurability. -*/ -template class SkRTConf: public SkRTConfBase { -public: - SkRTConf(const char *name, const T &defaultValue, const char *description); - operator const T&() const { return fValue; } - void print(SkWStream *o) const; - bool equals(const SkRTConfBase *conf) const; - bool isDefault() const { return fDefault == fValue; } - void set(const T& value) { fValue = value; } -protected: - void doPrint(char *s) const; - - T fValue; - T fDefault; - SkString fDescription; -}; - -#ifdef SK_DEBUG -#define SK_CONF_DECLARE(confType, varName, confName, defaultValue, description) static SkRTConf varName(confName, defaultValue, description) -#define SK_CONF_SET(confname, value) \ - skRTConfRegistry().set(confname, value, true) -/* SK_CONF_TRY_SET() is like SK_CONF_SET(), but doesn't complain if - confname can't be found. This is useful if the SK_CONF_DECLARE is - inside a source file whose linkage is dependent on the system. */ -#define SK_CONF_TRY_SET(confname, value) \ - skRTConfRegistry().set(confname, value, false) -#else -#define SK_CONF_DECLARE(confType, varName, confName, defaultValue, description) static confType varName = defaultValue -#define SK_CONF_SET(confname, value) (void) confname, (void) value -#define SK_CONF_TRY_SET(confname, value) (void) confname, (void) value -#endif - -/** \class SkRTConfRegistry - A class that maintains a systemwide registry of all runtime configuration - parameters. Mainly used for printing them out and handling multiply-defined - knobs. -*/ - -class SkRTConfRegistry { -public: - SkRTConfRegistry(); - ~SkRTConfRegistry(); - void printAll(const char *fname = NULL) const; - bool hasNonDefault() const; - void printNonDefault(const char *fname = NULL) const; - const char *configFileLocation() const; - void possiblyDumpFile() const; - void validate() const; - template void set(const char *confname, - T value, - bool warnIfNotFound = true); - -private: - template friend class SkRTConf; - - void registerConf(SkRTConfBase *conf); - - template bool parse(const char *name, T* value); - - SkTDArray fConfigFileKeys, fConfigFileValues; - typedef SkTDict< SkTDArray * > ConfMap; - ConfMap fConfs; - - template - friend bool test_rt_conf_parse(SkRTConfRegistry*, const char* name, T* value); -}; - -// our singleton registry - -SkRTConfRegistry &skRTConfRegistry(); - -template -SkRTConf::SkRTConf(const char *name, const T &defaultValue, const char *description) - : SkRTConfBase(name) - , fValue(defaultValue) - , fDefault(defaultValue) - , fDescription(description) { - - T value; - if (skRTConfRegistry().parse(fName.c_str(), &value)) { - fValue = value; - } - skRTConfRegistry().registerConf(this); -} - -template -void SkRTConf::print(SkWStream *o) const { - char outline[200]; // should be ok because we specify a max. width for everything here. - char *outptr; - if (strlen(getName()) >= 30) { - o->writeText(getName()); - o->writeText(" "); - outptr = &(outline[0]); - } else { - sprintf(outline, "%-30.30s", getName()); - outptr = &(outline[30]); - } - - doPrint(outptr); - sprintf(outptr+30, " %.128s", fDescription.c_str()); - for (size_t i = strlen(outline); i --> 0 && ' ' == outline[i];) { - outline[i] = '\0'; - } - o->writeText(outline); -} - -template -void SkRTConf::doPrint(char *s) const { - sprintf(s, "%-30.30s", "How do I print myself??"); -} - -template<> inline void SkRTConf::doPrint(char *s) const { - char tmp[30]; - sprintf(tmp, "%s # [%s]", fValue ? "true" : "false", fDefault ? "true" : "false"); - sprintf(s, "%-30.30s", tmp); -} - -template<> inline void SkRTConf::doPrint(char *s) const { - char tmp[30]; - sprintf(tmp, "%d # [%d]", fValue, fDefault); - sprintf(s, "%-30.30s", tmp); -} - -template<> inline void SkRTConf::doPrint(char *s) const { - char tmp[30]; - sprintf(tmp, "%u # [%u]", fValue, fDefault); - sprintf(s, "%-30.30s", tmp); -} - -template<> inline void SkRTConf::doPrint(char *s) const { - char tmp[30]; - sprintf(tmp, "%6.6f # [%6.6f]", fValue, fDefault); - sprintf(s, "%-30.30s", tmp); -} - -template<> inline void SkRTConf::doPrint(char *s) const { - char tmp[30]; - sprintf(tmp, "%6.6f # [%6.6f]", fValue, fDefault); - sprintf(s, "%-30.30s", tmp); -} - -template<> inline void SkRTConf::doPrint(char *s) const { - char tmp[30]; - sprintf(tmp, "%s # [%s]", fValue, fDefault); - sprintf(s, "%-30.30s", tmp); -} - -template -bool SkRTConf::equals(const SkRTConfBase *conf) const { - // static_cast here is okay because there's only one kind of child class. - const SkRTConf *child_pointer = static_cast *>(conf); - return child_pointer && - fName == child_pointer->fName && - fDescription == child_pointer->fDescription && - fValue == child_pointer->fValue && - fDefault == child_pointer->fDefault; -} - -#endif diff --git a/site/dev/runtime/config.md b/site/dev/runtime/config.md deleted file mode 100644 index fd31af7..0000000 --- a/site/dev/runtime/config.md +++ /dev/null @@ -1,89 +0,0 @@ -Runtime Configuration Settings -============================== - -Here is a (partial) list of Skia's runtime configuration settings: - -## Warning suppression: - -* configuration name: images.gif.suppressDecoderWarnings - environment variable: skia_images_gif_suppressDecoderWarnings - type: boolean - description: Suppress GIF warnings and errors when calling image decode - functions. - default: true. - -* configuration name: images.jpeg.suppressDecoderWarnings - environment variable: skia_images_jpeg_suppressDecoderWarnings - type: boolean - description: Suppress most JPG warnings when calling decode functions. - default: false in debug, true otherwise. - -* configuration name: images.jpeg.suppressDecoderErrors - environment variable: skia_images_jpeg_suppressDecoderErrors - type: boolean - description: Suppress most JPG error messages when decode function fails. - default: false in debug, true otherwise. - -* configuration name: images.png.suppressDecoderWarnings - environment variable: skia_images_png_suppressDecoderWarnings - type: boolean - description: Suppress most PNG warnings when calling image decode functions. - default: false in debug, true otherwise. - -## Other: - -* configuration name: bitmap.filter - environment variable: skia_bitmap_filter - type: string - description: Which scanline bitmap filter to use \[mitchell, lanczos, hamming, - gaussian, triangle, box\] - default: mitchell - -* configuration name: mask.filter.analyticNinePatch - environment variable: skia_mask_filter_analyticNinePatch - type: boolean - description: Use the faster analytic blur approach for ninepatch rects - default: \? - -* configuration name: gpu.deferContext - environment variable: skia_gpu_deferContext - type: boolean - description: Defers rendering in GrContext via GrInOrderDrawBuffer - default: true - -* configuration name: gpu.dumpFontCache - environment variable: skia_gpu_dumpFontCache - type: boolean - description: Dump the contents of the font cache before every purge - default: false - -* configuration name: bitmap.filter.highQualitySSE - environment variable: skia_bitmap_filter_highQualitySSE - type: boolean - description: Use SSE optimized version of high quality image filters - default: false - -## Use: - -These configuration values can be changed at runtime by including this in your -program: - - -~~~~ -#include "SkRTConf.h" -/*...*/ -int main() { - SK_CONF_SET( configuration_name, new_value ); - /*...*/ -~~~~ - -Or by setting the corresponding environment variable before starting the -program. For example, in Bourne shell: - - -~~~~ -#!/bin/sh -export skia_environment_variable="new_value" -your_program -~~~~ - diff --git a/site/dev/runtime/index.md b/site/dev/runtime/index.md deleted file mode 100644 index 7c8246d..0000000 --- a/site/dev/runtime/index.md +++ /dev/null @@ -1,181 +0,0 @@ -Runtime Configuration -===================== - -Skia supports the configuration of various aspects of its behavior at runtime, -allowing developers to enable\/disable features, or to experiment with numerical -quantities without recompiling. - -## Enabling runtime configuration - -In order to use a runtime-configurable variable in your source, simply: - - -~~~~ -#include "SkRTConf.h" -~~~~ - -## Declaring a runtime-configurable variable - -At file scope, declare your variable like so: - - -~~~~ -SK_CONF_DECLARE( confType, varName, confName, defaultValue, description ); -~~~~ - -For example, to declare a boolean variable called ` c_printShaders ` that can be -changed at runtime, you would do something like - - -~~~~ -SK_CONF_DECLARE( bool, c_printShaders, "gpu.printShaders", false, "print the - source code of any internally generated GPU shaders" ); -~~~~ - -It is safe to declare variables this way in header files; the variables will be -declared as static, but since they are read\-only\-ish \(they can be changed -through a special mechanism; see below\), this is safe. - -## Using a runtime-configurable variable - -The variables created by `SK_CONF_DECLARE` can be used in normal C\+\+ code as -if they were regular contant variables. For example: - - -~~~~ -if (c_printShaders) { - // actually print out the shaders -} -~~~~ - -## Changing a runtime-configurable variable after launch - -If, for some reason, you want to change the value of a runtime-configurable -variable after your program has started, you can do this with the `SK_CONF_SET` -macro: - - -~~~~ -SK_CONF_SET( "gpu.printShaders", false ) -~~~~ - -Note that we're using the `confName` parameter to the declaration, not -`varName`. This is because this configuration option may appear in multiple -files \(especially if you declared it in a header!\), and we need to make sure -to update all variables' values, not just the one that's locally visible to the -file you are currently in. - -## Changing a runtime-configurable variable before launch - -This is the primary intended use of these variables. There are two ways that you -can control the values of runtime-configurable variables at launch time: a -skia.conf configuration file, or through the use of environment variables. - -### Using skia.conf - -The skia.conf file is a simple line-based configuration file containing -key-value pairs. It supports python-style \# comments. For our example, we might -see a configuration file that looks like: - - -~~~~ -gpu.printShaders true -gpu.somethingElse 3.14159 -matrix.invertProperly false # math is hard -... -~~~~ - -*Note: boolean values may be set as 1, 0, true, or false. Other values will -result in runtime errors.* - -If the skia library detects a skia.conf file at initialization time, it will -parse it and override the default values of any declared configuration variables -with the values found in the file. - -*Note: although it might appear that the configuration variables have a -hierarchical naming scheme involving periods, that's just a convention I have -adopted so that when all declared configuration variables are sorted -alphabetically, they are roughly grouped by component.* - -## Using environment variables - -You can quickly override the value of one runtime-configurable variable using an -environment variable equal to the variable's key with "skia." prepended. So, for -example, one might run: - - -~~~~ -prompt% skia.gpu.printShaders=true out/Debug/dm -~~~~ - -or - - -~~~~ -prompt% export skia.gpu.printShaders=true -prompt% out/Debug/dm -~~~~ - -On many shells, it is illegal to have a period in an environment variable name, -so skia also supports underscores in place of the periods: - - -~~~~ -prompt% skia_gpu_printShaders=true out/Debug/dm -~~~~ - -or - - -~~~~ -prompt% export skia_gpu_printShaders=true` -prompt% out/Debug/dm -~~~~ - -## Discovering all possible configuration variables - -As this system becomes more widely used in skia, there may be hundreds of -configuration variables. What are they all? What are their defaults? What do -they do? - -In order to find out, simply create a zero-length skia.conf file \(on unix, -`touch skia.conf` will do the trick\). If skia detects a zero-length -configuration file, it will overwrite it with a sorted list of all known -configuration variables, their defaults, and their description strings. Each -line will be commented out and have its value already equal to its default, so -you can then edit this file to your liking. - -To trigger this behavior, call the function -`skRTConfRegistry().possiblyDumpFile(); ` or simply use `SkAutoGraphics -ag;`, which also validates your configuration and print out active non-default -options. - -## Are these things enabled all the time? - -No, they are only enabled in builds where SK_DEBUG is defined. This includes both -`Debug` and `Release_Developer` gyp BUILDTYPES. The `Release_Developer` build type -has exactly the same build flags as `Release`, except it re-enables SK_DEBUG, which -in turn enables runtime configuration behavior. -Specifically: - - -~~~~ -prompt% ninja -C BUILDTYPE=Release_Developer -~~~~ - -... wait a long time ... - - -~~~~ -prompt % skia_gpu_printShaders=true out/Release_Developer/dm -~~~~ - -... enjoy ... - -## Known issues / limitations - -Lines in 'skia.conf', including comments, are limited to 1024 characters. -Runtime configuration variables of type `char \* ` cannot currently have spaces -in them. -Runtime variables are only fully supported for `int`, `unsigned int`, `float`, -`double`, `bool`, and `char \*`. diff --git a/src/core/SkGraphics.cpp b/src/core/SkGraphics.cpp index d7022b7..01b1432 100644 --- a/src/core/SkGraphics.cpp +++ b/src/core/SkGraphics.cpp @@ -22,7 +22,6 @@ #include "SkPixelRef.h" #include "SkRefCnt.h" #include "SkResourceCache.h" -#include "SkRTConf.h" #include "SkScalerContext.h" #include "SkShader.h" #include "SkStream.h" @@ -49,15 +48,6 @@ void SkGraphics::Init() { // SkGraphics::Init() must be thread-safe and idempotent. SkCpu::CacheRuntimeFeatures(); SkOpts::Init(); - -#ifdef SK_DEBUG - skRTConfRegistry().possiblyDumpFile(); - skRTConfRegistry().validate(); - if (skRTConfRegistry().hasNonDefault()) { - SkDebugf("Non-default runtime configuration options:\n"); - skRTConfRegistry().printNonDefault(); - } -#endif } /////////////////////////////////////////////////////////////////////////////// diff --git a/src/effects/SkBlurMaskFilter.cpp b/src/effects/SkBlurMaskFilter.cpp index 9e0315f..38b5313 100644 --- a/src/effects/SkBlurMaskFilter.cpp +++ b/src/effects/SkBlurMaskFilter.cpp @@ -12,7 +12,6 @@ #include "SkWriteBuffer.h" #include "SkMaskFilter.h" #include "SkRRect.h" -#include "SkRTConf.h" #include "SkStringUtils.h" #include "SkStrokeRec.h" @@ -304,9 +303,10 @@ static SkCachedData* add_cached_rects(SkMask* mask, SkScalar sigma, SkBlurStyle } #ifdef SK_IGNORE_FAST_RRECT_BLUR -SK_CONF_DECLARE(bool, c_analyticBlurRRect, "mask.filter.blur.analyticblurrrect", false, "Use the faster analytic blur approach for ninepatch rects"); + // Use the faster analytic blur approach for ninepatch round rects + static const bool c_analyticBlurRRect{false}; #else -SK_CONF_DECLARE(bool, c_analyticBlurRRect, "mask.filter.blur.analyticblurrrect", true, "Use the faster analytic blur approach for ninepatch round rects"); + static const bool c_analyticBlurRRect{true}; #endif SkMaskFilter::FilterReturn @@ -443,7 +443,8 @@ SkBlurMaskFilterImpl::filterRRectToNine(const SkRRect& rrect, const SkMatrix& ma return kTrue_FilterReturn; } -SK_CONF_DECLARE(bool, c_analyticBlurNinepatch, "mask.filter.analyticNinePatch", true, "Use the faster analytic blur approach for ninepatch rects"); +// Use the faster analytic blur approach for ninepatch rects +static const bool c_analyticBlurNinepatch{true}; SkMaskFilter::FilterReturn SkBlurMaskFilterImpl::filterRectsToNine(const SkRect rects[], int count, diff --git a/src/gpu/batches/GrAADistanceFieldPathRenderer.cpp b/src/gpu/batches/GrAADistanceFieldPathRenderer.cpp index a9ba94d..36a9ff0 100644 --- a/src/gpu/batches/GrAADistanceFieldPathRenderer.cpp +++ b/src/gpu/batches/GrAADistanceFieldPathRenderer.cpp @@ -20,7 +20,6 @@ #include "effects/GrDistanceFieldGeoProc.h" #include "SkDistanceFieldGen.h" -#include "SkRTConf.h" #define ATLAS_TEXTURE_WIDTH 2048 #define ATLAS_TEXTURE_HEIGHT 2048 diff --git a/src/gpu/gl/GrGLGpuProgramCache.cpp b/src/gpu/gl/GrGLGpuProgramCache.cpp index 4ba0d23..ae93926 100644 --- a/src/gpu/gl/GrGLGpuProgramCache.cpp +++ b/src/gpu/gl/GrGLGpuProgramCache.cpp @@ -13,12 +13,11 @@ #include "glsl/GrGLSLFragmentProcessor.h" #include "glsl/GrGLSLProgramDataManager.h" #include "glsl/GrGLSLProgramDesc.h" -#include "SkRTConf.h" #include "SkTSearch.h" #ifdef PROGRAM_CACHE_STATS -SK_CONF_DECLARE(bool, c_DisplayCache, "gpu.displayCache", false, - "Display program cache usage."); +// Display program cache usage +static const bool c_DisplayCache{false}; #endif typedef GrGLSLProgramDataManager::UniformHandle UniformHandle; diff --git a/src/gpu/gl/builders/GrGLProgramBuilder.cpp b/src/gpu/gl/builders/GrGLProgramBuilder.cpp index 2d06e43..2bbeb42 100644 --- a/src/gpu/gl/builders/GrGLProgramBuilder.cpp +++ b/src/gpu/gl/builders/GrGLProgramBuilder.cpp @@ -12,7 +12,6 @@ #include "GrGLProgramBuilder.h" #include "GrSwizzle.h" #include "GrTexture.h" -#include "SkRTConf.h" #include "SkTraceEvent.h" #include "gl/GrGLGpu.h" #include "gl/GrGLProgram.h" diff --git a/src/gpu/gl/builders/GrGLShaderStringBuilder.cpp b/src/gpu/gl/builders/GrGLShaderStringBuilder.cpp index b4ce282..296c2be 100644 --- a/src/gpu/gl/builders/GrGLShaderStringBuilder.cpp +++ b/src/gpu/gl/builders/GrGLShaderStringBuilder.cpp @@ -8,14 +8,13 @@ #include "GrGLShaderStringBuilder.h" #include "gl/GrGLGpu.h" #include "gl/GrGLSLPrettyPrint.h" -#include "SkRTConf.h" #include "SkTraceEvent.h" #define GL_CALL(X) GR_GL_CALL(gpu->glInterface(), X) #define GL_CALL_RET(R, X) GR_GL_CALL_RET(gpu->glInterface(), R, X) -SK_CONF_DECLARE(bool, c_PrintShaders, "gpu.printShaders", false, - "Print the source code for all shaders generated."); +// Print the source code for all shaders generated. +static const bool c_PrintShaders{false}; static void print_shader_source(const char** strings, int* lengths, int count); diff --git a/src/gpu/vk/GrVkPipelineStateCache.cpp b/src/gpu/vk/GrVkPipelineStateCache.cpp index b8335e8..494f659 100644 --- a/src/gpu/vk/GrVkPipelineStateCache.cpp +++ b/src/gpu/vk/GrVkPipelineStateCache.cpp @@ -11,7 +11,6 @@ #include "GrProcessor.h" #include "GrVkPipelineState.h" #include "GrVkPipelineStateBuilder.h" -#include "SkRTConf.h" #include "glsl/GrGLSLFragmentProcessor.h" #include "glsl/GrGLSLProgramDataManager.h" diff --git a/src/images/SkJPEGImageEncoder.cpp b/src/images/SkJPEGImageEncoder.cpp index 1051aec..66b2440 100644 --- a/src/images/SkJPEGImageEncoder.cpp +++ b/src/images/SkJPEGImageEncoder.cpp @@ -13,7 +13,6 @@ #include "SkTemplates.h" #include "SkTime.h" #include "SkUtils.h" -#include "SkRTConf.h" #include "SkRect.h" #include "SkCanvas.h" diff --git a/src/images/SkPNGImageEncoder.cpp b/src/images/SkPNGImageEncoder.cpp index c3df5d1..1932e66 100644 --- a/src/images/SkPNGImageEncoder.cpp +++ b/src/images/SkPNGImageEncoder.cpp @@ -10,7 +10,6 @@ #include "SkColorPriv.h" #include "SkDither.h" #include "SkMath.h" -#include "SkRTConf.h" #include "SkStream.h" #include "SkTemplates.h" #include "SkUtils.h" @@ -36,11 +35,9 @@ #endif #define DEFAULT_FOR_SUPPRESS_PNG_IMAGE_DECODER_WARNINGS true -SK_CONF_DECLARE(bool, c_suppressPNGImageDecoderWarnings, - "images.png.suppressDecoderWarnings", - DEFAULT_FOR_SUPPRESS_PNG_IMAGE_DECODER_WARNINGS, - "Suppress most PNG warnings when calling image decode " - "functions."); +// Suppress most PNG warnings when calling image decode functions. +static const bool c_suppressPNGImageDecoderWarnings{ + DEFAULT_FOR_SUPPRESS_PNG_IMAGE_DECODER_WARNINGS}; /////////////////////////////////////////////////////////////////////////////// diff --git a/src/opts/opts_check_x86.cpp b/src/opts/opts_check_x86.cpp index dacb49b..a8003a3 100644 --- a/src/opts/opts_check_x86.cpp +++ b/src/opts/opts_check_x86.cpp @@ -13,7 +13,6 @@ #include "SkBlitRow.h" #include "SkBlitRow_opts_SSE2.h" #include "SkCpu.h" -#include "SkRTConf.h" /* diff --git a/src/utils/SkRTConf.cpp b/src/utils/SkRTConf.cpp deleted file mode 100644 index 2dfa47e..0000000 --- a/src/utils/SkRTConf.cpp +++ /dev/null @@ -1,325 +0,0 @@ -/* - * Copyright 2013 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#include "SkRTConf.h" -#include "SkOSFile.h" - -#include - -SkRTConfRegistry::SkRTConfRegistry(): fConfs(100) { - - FILE *fp = sk_fopen(configFileLocation(), kRead_SkFILE_Flag); - - if (!fp) { - return; - } - - char line[1024]; - - while (!sk_feof(fp)) { - - if (!sk_fgets(line, sizeof(line), fp)) { - break; - } - - char *commentptr = strchr(line, '#'); - if (commentptr == line) { - continue; - } - if (commentptr) { - *commentptr = '\0'; - } - - char sep[] = " \t\r\n"; - - char *keyptr = strtok(line, sep); - if (!keyptr) { - continue; - } - - char *valptr = strtok(nullptr, sep); - if (!valptr) { - continue; - } - - SkString *key = new SkString(keyptr); - SkString *val = new SkString(valptr); - - fConfigFileKeys.append(1, &key); - fConfigFileValues.append(1, &val); - } - sk_fclose(fp); -} - -SkRTConfRegistry::~SkRTConfRegistry() { - ConfMap::Iter iter(fConfs); - SkTDArray *confArray; - - while (iter.next(&confArray)) { - delete confArray; - } - - for (int i = 0 ; i < fConfigFileKeys.count() ; i++) { - delete fConfigFileKeys[i]; - delete fConfigFileValues[i]; - } -} - -const char *SkRTConfRegistry::configFileLocation() const { - return "skia.conf"; // for now -- should probably do something fancier like home directories or whatever. -} - -// dump all known runtime config options to the file with their default values. -// to trigger this, make a config file of zero size. -void SkRTConfRegistry::possiblyDumpFile() const { - const char *path = configFileLocation(); - FILE *fp = sk_fopen(path, kRead_SkFILE_Flag); - if (!fp) { - return; - } - size_t configFileSize = sk_fgetsize(fp); - if (configFileSize == 0) { - printAll(path); - } - sk_fclose(fp); -} - -// Run through every provided configuration option and print a warning if the user hasn't -// declared a correponding configuration object somewhere. -void SkRTConfRegistry::validate() const { - for (int i = 0 ; i < fConfigFileKeys.count() ; i++) { - if (!fConfs.find(fConfigFileKeys[i]->c_str())) { - SkDebugf("WARNING: You have config value %s in your configuration file, but I've never heard of that.\n", fConfigFileKeys[i]->c_str()); - } - } -} - -void SkRTConfRegistry::printAll(const char *fname) const { - SkWStream *o; - - if (fname) { - o = new SkFILEWStream(fname); - } else { - o = new SkDebugWStream(); - } - - ConfMap::Iter iter(fConfs); - SkTDArray *confArray; - - while (iter.next(&confArray)) { - if (confArray->getAt(0)->isDefault()) { - o->writeText("# "); - } - confArray->getAt(0)->print(o); - o->newline(); - } - - delete o; -} - -bool SkRTConfRegistry::hasNonDefault() const { - ConfMap::Iter iter(fConfs); - SkTDArray *confArray; - while (iter.next(&confArray)) { - if (!confArray->getAt(0)->isDefault()) { - return true; - } - } - return false; -} - -void SkRTConfRegistry::printNonDefault(const char *fname) const { - SkWStream *o; - - if (fname) { - o = new SkFILEWStream(fname); - } else { - o = new SkDebugWStream(); - } - ConfMap::Iter iter(fConfs); - SkTDArray *confArray; - - while (iter.next(&confArray)) { - if (!confArray->getAt(0)->isDefault()) { - confArray->getAt(0)->print(o); - o->newline(); - } - } - - delete o; -} - -// register a configuration variable after its value has been set by the parser. -// we maintain a vector of these things instead of just a single one because the -// user might set the value after initialization time and we need to have -// all the pointers lying around, not just one. -void SkRTConfRegistry::registerConf(SkRTConfBase *conf) { - SkTDArray *confArray; - if (fConfs.find(conf->getName(), &confArray)) { - if (!conf->equals(confArray->getAt(0))) { - SkDebugf("WARNING: Skia config \"%s\" was registered more than once in incompatible ways.\n", conf->getName()); - } else { - confArray->append(1, &conf); - } - } else { - confArray = new SkTDArray; - confArray->append(1, &conf); - fConfs.set(conf->getName(),confArray); - } -} - -template T doParse(const char *, bool *success ) { - SkDebugf("WARNING: Invoked non-specialized doParse function...\n"); - if (success) { - *success = false; - } - return (T) 0; -} - -template<> bool doParse(const char *s, bool *success) { - if (success) { - *success = true; - } - if (!strcmp(s,"1") || !strcmp(s,"true")) { - return true; - } - if (!strcmp(s,"0") || !strcmp(s,"false")) { - return false; - } - if (success) { - *success = false; - } - return false; -} - -template<> const char * doParse(const char * s, bool *success) { - if (success) { - *success = true; - } - return s; -} - -template<> int doParse(const char * s, bool *success) { - if (success) { - *success = true; - } - return atoi(s); -} - -template<> unsigned int doParse(const char * s, bool *success) { - if (success) { - *success = true; - } - return (unsigned int) atoi(s); -} - -template<> float doParse(const char * s, bool *success) { - if (success) { - *success = true; - } - return (float) atof(s); -} - -template<> double doParse(const char * s, bool *success) { - if (success) { - *success = true; - } - return atof(s); -} - -static inline void str_replace(char *s, char search, char replace) { - for (char *ptr = s ; *ptr ; ptr++) { - if (*ptr == search) { - *ptr = replace; - } - } -} - -template bool SkRTConfRegistry::parse(const char *name, T* value) { - const char *str = nullptr; - - for (int i = fConfigFileKeys.count() - 1 ; i >= 0; i--) { - if (fConfigFileKeys[i]->equals(name)) { - str = fConfigFileValues[i]->c_str(); - break; - } - } - - SkString environment_variable("skia."); - environment_variable.append(name); - - const char *environment_value = getenv(environment_variable.c_str()); - if (environment_value) { - str = environment_value; - } else { - // apparently my shell doesn't let me have environment variables that - // have periods in them, so also let the user substitute underscores. - SkAutoTMalloc underscore_name(SkStrDup(environment_variable.c_str())); - str_replace(underscore_name.get(), '.', '_'); - environment_value = getenv(underscore_name.get()); - if (environment_value) { - str = environment_value; - } - } - - if (!str) { - return false; - } - - bool success; - T new_value = doParse(str, &success); - if (success) { - *value = new_value; - } else { - SkDebugf("WARNING: Couldn't parse value \'%s\' for variable \'%s\'\n", - str, name); - } - return success; -} - -// need to explicitly instantiate the parsing function for every config type we might have... - -template bool SkRTConfRegistry::parse(const char *name, bool *value); -template bool SkRTConfRegistry::parse(const char *name, int *value); -template bool SkRTConfRegistry::parse(const char *name, unsigned int *value); -template bool SkRTConfRegistry::parse(const char *name, float *value); -template bool SkRTConfRegistry::parse(const char *name, double *value); -template bool SkRTConfRegistry::parse(const char *name, const char **value); - -template void SkRTConfRegistry::set(const char *name, - T value, - bool warnIfNotFound) { - SkTDArray *confArray; - if (!fConfs.find(name, &confArray)) { - if (warnIfNotFound) { - SkDebugf("WARNING: Attempting to set configuration value \"%s\"," - " but I've never heard of that.\n", name); - } - return; - } - SkASSERT(confArray != nullptr); - for (SkRTConfBase **confBase = confArray->begin(); confBase != confArray->end(); confBase++) { - // static_cast here is okay because there's only one kind of child class. - SkRTConf *concrete = static_cast *>(*confBase); - - if (concrete) { - concrete->set(value); - } - } -} - -template void SkRTConfRegistry::set(const char *name, bool value, bool); -template void SkRTConfRegistry::set(const char *name, int value, bool); -template void SkRTConfRegistry::set(const char *name, unsigned int value, bool); -template void SkRTConfRegistry::set(const char *name, float value, bool); -template void SkRTConfRegistry::set(const char *name, double value, bool); -template void SkRTConfRegistry::set(const char *name, char * value, bool); - -SkRTConfRegistry &skRTConfRegistry() { - static SkRTConfRegistry r; - return r; -} diff --git a/tests/PathOpsExtendedTest.cpp b/tests/PathOpsExtendedTest.cpp index 2f6d99d..6ea67fe 100644 --- a/tests/PathOpsExtendedTest.cpp +++ b/tests/PathOpsExtendedTest.cpp @@ -13,7 +13,6 @@ #include "SkMatrix.h" #include "SkMutex.h" #include "SkPaint.h" -#include "SkRTConf.h" #include "SkStream.h" #include @@ -630,10 +629,6 @@ bool testPathOpFail(skiatest::Reporter* reporter, const SkPath& a, const SkPath& SK_DECLARE_STATIC_MUTEX(gMutex); void initializeTests(skiatest::Reporter* reporter, const char* test) { -#if 0 // doesn't work yet - SK_CONF_SET("images.jpeg.suppressDecoderWarnings", true); - SK_CONF_SET("images.png.suppressDecoderWarnings", true); -#endif if (reporter->verbose()) { SkAutoMutexAcquire lock(gMutex); testName = test; diff --git a/tests/PathOpsSkpClipTest.cpp b/tests/PathOpsSkpClipTest.cpp index c96e5bf..3c958f1 100644 --- a/tests/PathOpsSkpClipTest.cpp +++ b/tests/PathOpsSkpClipTest.cpp @@ -19,7 +19,6 @@ #include "SkOSFile.h" #include "SkPathOpsDebug.h" #include "SkPicture.h" -#include "SkRTConf.h" #include "SkTSort.h" #include "SkStream.h" #include "SkString.h" @@ -27,6 +26,7 @@ #include "SkTDArray.h" #include "SkTaskGroup.h" #include "SkTemplates.h" +#include "SkTSearch.h" #include "SkTime.h" #include @@ -740,13 +740,6 @@ checkEarlyExit: return true; } -static void initTest() { -#if !defined SK_BUILD_FOR_WIN && !defined SK_BUILD_FOR_MAC - SK_CONF_SET("images.jpeg.suppressDecoderWarnings", true); - SK_CONF_SET("images.png.suppressDecoderWarnings", true); -#endif -} - static void testSkpClipEncode(TestState* data) { data->fResult.testOne(); if (verbose()) { @@ -827,7 +820,6 @@ typedef SkTRegistry TestRegistry; DEF_TEST(PathOpsSkpClip) { gDirs.setDefault(); - initTest(); SkTArray errors; TestState state; state.init(0); @@ -851,7 +843,6 @@ static void testSkpClipMain(TestState* data) { DEF_TEST(PathOpsSkpClipThreaded) { gDirs.setDefault(); - initTest(); TestRunner testRunner; int dirNo; gDirs.reset(); @@ -890,7 +881,6 @@ DEF_TEST(PathOpsSkpClipUberThreaded) { gDirs.setDefault(); const int firstDirNo = gDirs.next(); const int lastDirNo = gDirs.last(); - initTest(); int dirCount = lastDirNo - firstDirNo + 1; SkAutoTDeleteArray > tests(new SkTDArray[dirCount]); SkAutoTDeleteArray > sorted(new SkTDArray[dirCount]); @@ -973,7 +963,6 @@ DEF_TEST(PathOpsSkpClipOneOff) { if (!skp) { skp = skipOver[testIndex].filename; } - initTest(); SkAssertResult(get_in_path(dirNo, skp).size()); SkString filename(skp); TestResult state; @@ -993,7 +982,6 @@ DEF_TEST(PathOpsTestSkipped) { } int dirNo = skip.directory; const char* skp = skip.filename; - initTest(); SkAssertResult(get_in_path(dirNo, skp).size()); SkString filename(skp); TestResult state; diff --git a/tests/RTConfRegistryTest.cpp b/tests/RTConfRegistryTest.cpp deleted file mode 100644 index be019f7..0000000 --- a/tests/RTConfRegistryTest.cpp +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright 2013 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#include "SkRTConf.h" -#include "SkOSEnvironment.h" -#include "Test.h" - -// Friended proxy for SkRTConfRegistry::parse() -template -bool test_rt_conf_parse(SkRTConfRegistry* reg, const char* key, T* value) { - return reg->parse(key, value); -} - -DEF_TEST(SkRTConfRegistry, reporter) { - SkRTConfRegistry reg; - - sk_setenv("skia_nonexistent_item", "132"); - int result = 0; - test_rt_conf_parse(®, "nonexistent.item", &result); - REPORTER_ASSERT(reporter, result == 132); -} diff --git a/tests/RuntimeConfigTest.cpp b/tests/RuntimeConfigTest.cpp deleted file mode 100644 index b863ee1..0000000 --- a/tests/RuntimeConfigTest.cpp +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright 2013 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ -#include "SkRTConf.h" -#include "Test.h" - -SK_CONF_DECLARE(int, c_RTConfTestVariable, - "test.utils.rtconf.testVariable", 1, - "This is only a test. Do not be alarmed."); -// TODO(skia-team): more comprehensive unit tests of the SkRTConf -// system. -DEF_TEST(RuntimeConfig, reporter) { - REPORTER_ASSERT(reporter, 1 == c_RTConfTestVariable); - - SK_CONF_SET("test.utils.rtconf.testVariable", 2); -#ifdef SK_DEBUG - REPORTER_ASSERT(reporter, 2 == c_RTConfTestVariable); -#else // not SK_DEBUG - // Can not change RTConf variables in SK_RELEASE. - REPORTER_ASSERT(reporter, 1 == c_RTConfTestVariable); -#endif // SK_DEBUG - - // This should not give a warning. - SK_CONF_TRY_SET("test.utils.rtconf.nonexistentVariable", 7); -} diff --git a/tests/SkpSkGrTest.cpp b/tests/SkpSkGrTest.cpp index bf534f4..ccec37b 100644 --- a/tests/SkpSkGrTest.cpp +++ b/tests/SkpSkGrTest.cpp @@ -18,7 +18,6 @@ #include "SkImageEncoder.h" #include "SkOSFile.h" #include "SkPicture.h" -#include "SkRTConf.h" #include "SkStream.h" #include "SkString.h" #include "SkTArray.h" -- 2.7.4