header self-sufficiency and idempotency

Change-Id: I4ec74a358e11d85c6eaf1658efd6f1391ee5e387
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/223930
Commit-Queue: Hal Canary <halcanary@google.com>
Commit-Queue: Ben Wagner <bungeman@google.com>
Auto-Submit: Hal Canary <halcanary@google.com>
Reviewed-by: Ben Wagner <bungeman@google.com>
diff --git a/src/codec/SkFrameHolder.h b/src/codec/SkFrameHolder.h
index 1990acb..c44d2e0 100644
--- a/src/codec/SkFrameHolder.h
+++ b/src/codec/SkFrameHolder.h
@@ -11,6 +11,8 @@
 #include "include/codec/SkCodecAnimation.h"
 #include "include/core/SkRect.h"
 #include "include/core/SkTypes.h"
+#include "include/private/SkEncodedInfo.h"
+#include "include/private/SkNoncopyable.h"
 #include "src/codec/SkCodecAnimationPriv.h"
 
 /**
diff --git a/src/codec/SkScalingCodec.h b/src/codec/SkScalingCodec.h
index a53ecf3..799ca38 100644
--- a/src/codec/SkScalingCodec.h
+++ b/src/codec/SkScalingCodec.h
@@ -4,6 +4,8 @@
  * Use of this source code is governed by a BSD-style license that can be
  * found in the LICENSE file.
  */
+#ifndef SkScalingCodec_DEFINED
+#define SkScalingCodec_DEFINED
 
 #include "include/codec/SkCodec.h"
 
@@ -34,3 +36,4 @@
     typedef SkCodec INHERITED;
 };
 
+#endif  // SkScalingCodec_DEFINED
diff --git a/src/core/SkMSAN.h b/src/core/SkMSAN.h
index 35ad785..acde144 100644
--- a/src/core/SkMSAN.h
+++ b/src/core/SkMSAN.h
@@ -10,6 +10,8 @@
 
 #include "include/core/SkTypes.h"
 
+#include <string.h>
+
 // Typically declared in LLVM's msan_interface.h.  Easier for us to just re-declare.
 extern "C" {
     void __msan_check_mem_is_initialized(const volatile void*, size_t);
diff --git a/src/core/SkSafeRange.h b/src/core/SkSafeRange.h
index ef068c2..0d322cc 100644
--- a/src/core/SkSafeRange.h
+++ b/src/core/SkSafeRange.h
@@ -8,6 +8,10 @@
 #ifndef SkSafeRange_DEFINED
 #define SkSafeRange_DEFINED
 
+#include "include/core/SkTypes.h"
+
+#include <cstdint>
+
 // SkSafeRange always check that a series of operations are in-range.
 // This check is sticky, so that if any one operation fails, the object will remember that and
 // return false from ok().
diff --git a/src/core/SkSpecialSurface.h b/src/core/SkSpecialSurface.h
index 6628791..75f2392 100644
--- a/src/core/SkSpecialSurface.h
+++ b/src/core/SkSpecialSurface.h
@@ -18,6 +18,7 @@
 
 class GrBackendFormat;
 class GrContext;
+class GrRecordingContext;
 class SkBitmap;
 class SkCanvas;
 class SkSpecialImage;
diff --git a/src/core/SkStrikeInterface.h b/src/core/SkStrikeInterface.h
index 59804f6..06a5235 100644
--- a/src/core/SkStrikeInterface.h
+++ b/src/core/SkStrikeInterface.h
@@ -8,12 +8,13 @@
 #ifndef SkStrikeInterface_DEFINED
 #define SkStrikeInterface_DEFINED
 
-#include <memory>
-
+#include "include/core/SkPaint.h"
 #include "include/core/SkPoint.h"
 #include "include/core/SkTypes.h"
 #include "src/core/SkSpan.h"
 
+#include <memory>
+
 class SkDescriptor;
 class SkGlyph;
 class SkMaskFilter;
diff --git a/src/core/SkWritePixelsRec.h b/src/core/SkWritePixelsRec.h
index 2414d96..4f02c4e 100644
--- a/src/core/SkWritePixelsRec.h
+++ b/src/core/SkWritePixelsRec.h
@@ -9,6 +9,7 @@
 #define SkWritePixelsRec_DEFINED
 
 #include "include/core/SkImageInfo.h"
+#include "include/core/SkPixmap.h"
 
 /**
  *  Helper class to package and trim the parameters passed to writePixels()
diff --git a/src/gpu/GrContextThreadSafeProxyPriv.h b/src/gpu/GrContextThreadSafeProxyPriv.h
index bf09305..9f83e4b 100644
--- a/src/gpu/GrContextThreadSafeProxyPriv.h
+++ b/src/gpu/GrContextThreadSafeProxyPriv.h
@@ -10,6 +10,8 @@
 
 #include "include/gpu/GrContextThreadSafeProxy.h"
 
+#include "src/gpu/GrCaps.h"
+
 /**
  * Class that adds methods to GrContextThreadSafeProxy that are only intended for use internal to
  * Skia. This class is purely a privileged window into GrContextThreadSafeProxy. It should never
diff --git a/src/gpu/geometry/GrRect.h b/src/gpu/geometry/GrRect.h
index ffded09..9a0bee7 100644
--- a/src/gpu/geometry/GrRect.h
+++ b/src/gpu/geometry/GrRect.h
@@ -8,6 +8,7 @@
 #ifndef GrRect_DEFINED
 #define GrRect_DEFINED
 
+#include "include/core/SkMatrix.h"
 #include "include/core/SkRect.h"
 #include "include/core/SkTypes.h"
 #include "include/private/SkTo.h"
diff --git a/src/gpu/mock/GrMockTexture.h b/src/gpu/mock/GrMockTexture.h
index d7aa866..ddf5e52 100644
--- a/src/gpu/mock/GrMockTexture.h
+++ b/src/gpu/mock/GrMockTexture.h
@@ -11,6 +11,7 @@
 #include "include/gpu/GrTexture.h"
 #include "include/gpu/mock/GrMockTypes.h"
 #include "src/gpu/GrRenderTargetPriv.h"
+#include "src/gpu/GrStencilAttachment.h"
 #include "src/gpu/GrTexturePriv.h"
 #include "src/gpu/mock/GrMockGpu.h"
 
diff --git a/src/image/SkReadPixelsRec.h b/src/image/SkReadPixelsRec.h
index 2257e5c..dd88d6c 100644
--- a/src/image/SkReadPixelsRec.h
+++ b/src/image/SkReadPixelsRec.h
@@ -9,6 +9,7 @@
 #define SkReadPixelsRec_DEFINED
 
 #include "include/core/SkImageInfo.h"
+#include "include/core/SkPixmap.h"
 
 /**
  *  Helper class to package and trim the parameters passed to readPixels()
diff --git a/src/image/SkSurface_Gpu.h b/src/image/SkSurface_Gpu.h
index 84299e0..9ac45d5 100644
--- a/src/image/SkSurface_Gpu.h
+++ b/src/image/SkSurface_Gpu.h
@@ -13,6 +13,7 @@
 
 #if SK_SUPPORT_GPU
 
+class GrBackendFormat;
 class SkGpuDevice;
 
 class SkSurface_Gpu : public SkSurface_Base {
diff --git a/src/opts/SkVM_opts.h b/src/opts/SkVM_opts.h
index ce7dcf9..0655960 100644
--- a/src/opts/SkVM_opts.h
+++ b/src/opts/SkVM_opts.h
@@ -10,6 +10,8 @@
 
 #include "src/core/SkVM.h"
 
+#include "include/private/SkVx.h"
+
 namespace SK_OPTS_NS {
 
     inline void eval(const skvm::Program::Instruction insts[], const int ninsts,
diff --git a/src/pdf/SkPDFTag.h b/src/pdf/SkPDFTag.h
index 0b859bb..d0718d3 100644
--- a/src/pdf/SkPDFTag.h
+++ b/src/pdf/SkPDFTag.h
@@ -14,6 +14,7 @@
 #include "src/core/SkArenaAlloc.h"
 
 class SkPDFDocument;
+struct SkPDFIndirectReference;
 struct SkPDFTagNode;
 
 class SkPDFTagTree {
diff --git a/src/sksl/SkSLCPP.h b/src/sksl/SkSLCPP.h
index 40d876d..11b5b00 100644
--- a/src/sksl/SkSLCPP.h
+++ b/src/sksl/SkSLCPP.h
@@ -12,6 +12,7 @@
 
 #include <cmath>
 #include "include/core/SkPoint.h"
+#include "include/core/SkRect.h"
 
 using std::abs;
 
diff --git a/src/sksl/ir/SkSLEnum.h b/src/sksl/ir/SkSLEnum.h
index 885b17e..a22db36 100644
--- a/src/sksl/ir/SkSLEnum.h
+++ b/src/sksl/ir/SkSLEnum.h
@@ -8,12 +8,18 @@
 #ifndef SKSL_ENUM
 #define SKSL_ENUM
 
+#include "src/sksl/ir/SkSLExpression.h"
 #include "src/sksl/ir/SkSLProgramElement.h"
+#include "src/sksl/ir/SkSLSymbolTable.h"
+#include "src/sksl/ir/SkSLVariable.h"
 
 #include <algorithm>
+#include <vector>
 
 namespace SkSL {
 
+struct Symbol;
+
 struct Enum : public ProgramElement {
     Enum(int offset, StringFragment typeName, std::shared_ptr<SymbolTable> symbols)
     : INHERITED(offset, kEnum_Kind)
diff --git a/src/sksl/ir/SkSLPostfixExpression.h b/src/sksl/ir/SkSLPostfixExpression.h
index 2fcb202..c11e208 100644
--- a/src/sksl/ir/SkSLPostfixExpression.h
+++ b/src/sksl/ir/SkSLPostfixExpression.h
@@ -8,6 +8,7 @@
 #ifndef SKSL_POSTFIXEXPRESSION
 #define SKSL_POSTFIXEXPRESSION
 
+#include "src/sksl/SkSLCompiler.h"
 #include "src/sksl/SkSLLexer.h"
 #include "src/sksl/ir/SkSLExpression.h"
 
diff --git a/src/sksl/ir/SkSLProgramElement.h b/src/sksl/ir/SkSLProgramElement.h
index 84b764e..4caaebe 100644
--- a/src/sksl/ir/SkSLProgramElement.h
+++ b/src/sksl/ir/SkSLProgramElement.h
@@ -10,6 +10,8 @@
 
 #include "src/sksl/ir/SkSLIRNode.h"
 
+#include <memory>
+
 namespace SkSL {
 
 /**
diff --git a/src/sksl/ir/SkSLSwitchStatement.h b/src/sksl/ir/SkSLSwitchStatement.h
index 3f6a7a0..0777c5c 100644
--- a/src/sksl/ir/SkSLSwitchStatement.h
+++ b/src/sksl/ir/SkSLSwitchStatement.h
@@ -13,6 +13,8 @@
 
 namespace SkSL {
 
+class SymbolTable;
+
 /**
  * A 'switch' statement.
  */
diff --git a/src/sksl/lex/DFAState.h b/src/sksl/lex/DFAState.h
index e600637..141078a 100644
--- a/src/sksl/lex/DFAState.h
+++ b/src/sksl/lex/DFAState.h
@@ -10,6 +10,9 @@
 
 #include "src/sksl/lex/LexUtil.h"
 
+#include <vector>
+#include <string>
+
 struct DFAState {
     struct Label {
         std::vector<int> fStates;
diff --git a/src/sksl/lex/NFAtoDFA.h b/src/sksl/lex/NFAtoDFA.h
index d566132..3c90380 100644
--- a/src/sksl/lex/NFAtoDFA.h
+++ b/src/sksl/lex/NFAtoDFA.h
@@ -4,6 +4,8 @@
  * Use of this source code is governed by a BSD-style license that can be
  * found in the LICENSE file.
  */
+#ifndef NFAtoDFA_DEFINED
+#define NFAtoDFA_DEFINED
 
 #include "src/sksl/lex/DFA.h"
 #include "src/sksl/lex/DFAState.h"
@@ -163,3 +165,4 @@
     std::vector<int> fCharMappings;
     std::vector<int> fAccepts;
 };
+#endif  // NFAtoDFA_DEFINED
diff --git a/src/utils/SkCallableTraits.h b/src/utils/SkCallableTraits.h
index 7df0124..003db21 100644
--- a/src/utils/SkCallableTraits.h
+++ b/src/utils/SkCallableTraits.h
@@ -9,6 +9,7 @@
 #define SkCallableTraits_DEFINED
 
 #include <type_traits>
+#include <tuple>
 
 template <typename R, typename... Args> struct sk_base_callable_traits {
     using return_type = R;
diff --git a/tools/check-headers-self-sufficient b/tools/check-headers-self-sufficient
index e60aa86..8ecb76b 100755
--- a/tools/check-headers-self-sufficient
+++ b/tools/check-headers-self-sufficient
@@ -5,9 +5,9 @@
 # Use of this source code is governed by a BSD-style license that can be
 # found in the LICENSE file.
 
-import fnmatch
 import multiprocessing
 import os
+import re
 import subprocess
 import sys
 
@@ -18,115 +18,55 @@
 Otherwise, test all checked-in headers except for those in the ignore list.
 '''
 
-public_header_args = [
-    '-Iinclude/core',
-    '-Iinclude/config',
-    '-Iinclude/android',
-    '-Iinclude/codec',
-    '-Iinclude/effects',
-    '-Iinclude/gpu',
-    '-Iinclude/gpu/gl',
-    '-Iinclude/pathops',
-    '-Iinclude/ports',
-    '-Iinclude/private',
-    '-Iinclude/svg',
-    '-Iinclude/third_party/vulkan',
-    '-Iinclude/utils',
-    '-Iinclude/utils/mac',
-    '-Iinclude/views',
-]
+ignore = re.compile('|'.join([
+    r'debugger/QT/.*',
+    r'example/.*',
+    r'experimental/.*',
+    r'include/config/.*',
+    r'include/core/SkPostConfig\.h',
+    r'include/gpu/mtl/.*',
+    r'include/gpu/vk/.*',
+    r'include/ports/SkFontMgr_android\.h',
+    r'include/ports/SkFontMgr_fontconfig\.h',
+    r'include/ports/SkFontMgr_fuchsia\.h',
+    r'include/ports/SkTypeface_win\.h',
+    r'include/private/.*_impl\.h',
+    r'include/private/.*_neon\.h',
+    r'include/private/.*_sse\.h',
+    r'include/third_party/vulkan/.*',
+    r'include/utils/mac/SkCGUtils\.h',
+    r'include/views/SkOSWindow_.*\.h',
+    r'modules/.*',
+    r'platform_tools/.*',
+    r'src/c/sk_c_from_to\.h',
+    r'src/core/.*Template\.h',
+    r'src/core/SkBitmapProcState_.*\.h',
+    r'src/core/SkLinearBitmapPipeline\.h',
+    r'src/core/SkLinearBitmapPipeline_.*\.h',
+    r'src/gpu/mtl/.*',
+    r'src/gpu/vk/.*',
+    r'src/opts/.*_SSE2\.h',
+    r'src/opts/.*_SSSE3\.h',
+    r'src/opts/.*_neon\.h',
+    r'src/opts/.*_sse\.h',
+    r'src/opts/Sk4px_.*\.h',
+    r'src/ports/.*',
+    r'src/utils/.*_win\.h',
+    r'src/utils/win/.*',
+    r'src/views/.*',
+    r'third_party/.*',
+    r'tools/fiddle/.*',
+    r'tools/gpu/vk/.*',
+    r'tools/mdbviz/.*',
+    r'tools/sk_app/.*',
+    r'tools/viewer/.*',
+    ]))
 
-all_header_args = [
-    '-Iinclude/core',
-    '-Iinclude/config',
-    '-Iinclude/android',
-    '-Iinclude/c',
-    '-Iinclude/codec',
-    '-Iinclude/effects',
-    '-Iinclude/gpu',
-    '-Iinclude/gpu/gl',
-    '-Iinclude/pathops',
-    '-Iinclude/ports',
-    '-Iinclude/private',
-    '-Iinclude/svg',
-    '-Iinclude/third_party/vulkan',
-    '-Iinclude/utils',
-    '-Iinclude/utils/mac',
-    '-Iinclude/views',
-    '-Isrc/codec',
-    '-Isrc/core',
-    '-Isrc/effects',
-    '-Isrc/effects/gradients',
-    '-Isrc/fonts',
-    '-Isrc/gpu',
-    '-Isrc/image',
-    '-Isrc/images',
-    '-Isrc/lazy',
-    '-Isrc/opts',
-    '-Isrc/pathops',
-    '-Isrc/ports',
-    '-Isrc/sfnt',
-    '-Isrc/shaders',
-    '-Isrc/sksl',
-    '-Isrc/utils',
-    '-Isrc/utils/win',
-    '-Isrc/xml',
-    '-Igm',
-    '-Itests',
-    '-Itools',
-    '-Itools/debugger',
-    '-Itools/flags',
-    '-Itools/gpu',
-    '-Itools/timer',
-    '-Ithird_party/etc1',
-    '-Ithird_party/externals/libjpeg-turbo',
-    '-Ithird_party/externals/sfntly/cpp/src',
-    '-Ithird_party/externals/zlib',
-    '-Ithird_party/gif',
-]
-
-ignore = [
-    '*/lex.*.h',
-    '*/osmesa_wrapper.h',
-    'debugger/QT/*',
-    'example/*',
-    'experimental/*',
-    'include/config/*',
-    'include/core/SkPostConfig.h',
-    'include/gpu/vk/*',
-    'include/ports/SkFontMgr_android.h',
-    'include/ports/SkFontMgr_fontconfig.h',
-    'include/ports/SkTypeface_win.h',
-    'include/private/*_impl.h',
-    'include/utils/mac/SkCGUtils.h',
-    'include/views/SkOSWindow_*.h',
-    'src/c/sk_c_from_to.h',
-    'src/core/*Template.h',
-    'src/core/SkBitmapProcState_*.h',
-    'src/core/SkLinearBitmapPipeline.h',
-    'src/core/SkLinearBitmapPipeline_*.h',
-    'src/gpu/vk/*',
-    'src/opts/*_SSE2.h',
-    'src/opts/*_SSSE3.h',
-    'src/opts/*_neon.h',
-    'src/opts/*_sse.h',
-    'src/opts/Sk4px_*.h',
-    'src/ports/*',
-    'src/utils/*_win.h',
-    'src/utils/win/*',
-    'src/views/*',
-    'third_party/*',
-    'tools/fiddle/*',
-    'tools/viewer/*',
-]
 
 # test header for self-sufficiency and idempotency.
 # Returns a string containing errors, or None iff there are no errors.
 def compile_header(header):
-    args = ([]                 if fnmatch.fnmatch(header, 'include/c/*') else
-            public_header_args if fnmatch.fnmatch(header, 'include/*')   else
-            all_header_args)
-    cmd = ['c++', '--std=c++14'] + args + [ '-o', '/dev/null', '-c', '-x', 'c++', '-']
+    cmd = ['c++', '--std=c++14', '-I.', '-o', '/dev/null', '-c', '-x', 'c++', '-']
     proc = subprocess.Popen(cmd, stdin=subprocess.PIPE,
                             stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
     proc.stdin.write('#include "%s"\n#include "%s"\n' % (header, header))
@@ -136,6 +76,7 @@
         return '\n\033[7m ERROR: %s \033[0m\n%s\n\n' % (header, errors)
     return None
 
+
 #     for h in headers:
 #         compile_header(h)
 # ...Except use a multiprocessing pool.
@@ -168,8 +109,7 @@
     else:
         os.chdir(skia_dir)
         paths = [path for path in subprocess.check_output(['git', 'ls-files']).splitlines()
-                 if path.endswith('.h')
-                 and not any(fnmatch.fnmatch(path, pattern) for pattern in ignore)]
+                 if path.endswith('.h') and not ignore.match(path)]
     compile_headers(paths)
 
 
diff --git a/tools/fonts/TestEmptyTypeface.h b/tools/fonts/TestEmptyTypeface.h
index 62dce3e..3d61762 100644
--- a/tools/fonts/TestEmptyTypeface.h
+++ b/tools/fonts/TestEmptyTypeface.h
@@ -8,7 +8,9 @@
 #ifndef TestEmptyTypeface_DEFINED
 #define TestEmptyTypeface_DEFINED
 
+#include "include/core/SkStream.h"
 #include "include/core/SkTypeface.h"
+#include "src/core/SkAdvancedTypefaceMetrics.h"
 
 class TestEmptyTypeface : public SkTypeface {
 public:
diff --git a/tools/fonts/TestTypeface.h b/tools/fonts/TestTypeface.h
index 9ebf3f1..0d43d09 100644
--- a/tools/fonts/TestTypeface.h
+++ b/tools/fonts/TestTypeface.h
@@ -14,6 +14,7 @@
 #include "include/core/SkPaint.h"
 #include "include/core/SkRefCnt.h"
 #include "include/core/SkScalar.h"
+#include "include/core/SkStream.h"
 #include "include/core/SkTypeface.h"
 #include "include/core/SkTypes.h"
 #include "include/private/SkFixed.h"