Start a custom .clang-format rule

Also add clang-format-all.sh and clang-format-separate.sh to perform this operation.

These files sit in the ./src directory.

Bug: b/144825072
Change-Id: I5228ac59f7781ad1307c305949af7e7f9e0c31d1
Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/24308
Tested-by: Ben Clayton <bclayton@google.com>
Reviewed-by: Nicolas Capens <nicolascapens@google.com>
Kokoro-Presubmit: kokoro <noreply+kokoro@google.com>
diff --git a/src/.clang-format b/src/.clang-format
new file mode 100644
index 0000000..4baea7f
--- /dev/null
+++ b/src/.clang-format
@@ -0,0 +1,116 @@
+---
+Language:        Cpp
+# BasedOnStyle:  Google
+AccessModifierOffset: -4
+AlignAfterOpenBracket: Align
+AlignConsecutiveAssignments: false
+AlignConsecutiveDeclarations: false
+AlignEscapedNewlines: Left
+AlignOperands:   true
+AlignTrailingComments: true
+AllowAllParametersOfDeclarationOnNextLine: true
+AllowShortBlocksOnASingleLine: true
+AllowShortCaseLabelsOnASingleLine: true
+AllowShortFunctionsOnASingleLine: Inline
+AllowShortIfStatementsOnASingleLine: true
+AllowShortLoopsOnASingleLine: true
+AlwaysBreakAfterDefinitionReturnType: None
+AlwaysBreakAfterReturnType: None
+AlwaysBreakBeforeMultilineStrings: true
+AlwaysBreakTemplateDeclarations: true
+BinPackArguments: true
+BinPackParameters: true
+BraceWrapping:
+  AfterClass: true
+  AfterControlStatement: true
+  AfterEnum: true
+  AfterExternBlock: false
+  AfterFunction: true
+  AfterNamespace: false
+  AfterStruct: true
+  AfterUnion: true
+  BeforeCatch: true
+  BeforeElse: true
+  IndentBraces: false
+  SplitEmptyFunction: false
+  SplitEmptyNamespace: false
+  SplitEmptyRecord: false
+BreakBeforeBinaryOperators: None
+BreakBeforeBraces: Custom
+BreakBeforeInheritanceComma: false
+BreakBeforeTernaryOperators: true
+BreakConstructorInitializersBeforeComma: false
+BreakConstructorInitializers: BeforeComma
+BreakAfterJavaFieldAnnotations: false
+BreakStringLiterals: true
+ColumnLimit: 0
+CommentPragmas:  '^ IWYU pragma:'
+CompactNamespaces: false
+ConstructorInitializerAllOnOneLineOrOnePerLine: false
+ConstructorInitializerIndentWidth: 4
+ContinuationIndentWidth: 4
+Cpp11BracedListStyle: false
+DerivePointerAlignment: false
+DisableFormat:   false
+ExperimentalAutoDetectBinPacking: false
+FixNamespaceComments: true
+ForEachMacros:
+  - Q_FOREACH
+  - BOOST_FOREACH
+IncludeBlocks:   Preserve
+IncludeCategories:
+  - Regex:           '^"[^/]*"'
+    Priority:        1
+  - Regex:           '^".*/.*"'
+    Priority:        2
+  - Regex:           '^<.*\..*>'
+    Priority:        3
+  - Regex:           '^<[^.]*>'
+    Priority:        4
+  - Regex:           '.*'
+    Priority:        5
+IncludeIsMainRegex: '([-_](test|unittest))?$'
+IndentCaseLabels: true
+IndentPPDirectives: AfterHash
+IndentWidth:     4
+IndentWrappedFunctionNames: false
+JavaScriptQuotes: Leave
+JavaScriptWrapImports: true
+KeepEmptyLinesAtTheStartOfBlocks: true
+MacroBlockBegin: ''
+MacroBlockEnd:   ''
+MaxEmptyLinesToKeep: 1
+NamespaceIndentation: None
+ObjCBlockIndentWidth: 2
+ObjCSpaceAfterProperty: false
+ObjCSpaceBeforeProtocolList: false
+PenaltyBreakAssignment: 2
+PenaltyBreakBeforeFirstCallParameter: 1
+PenaltyBreakComment: 300
+PenaltyBreakFirstLessLess: 120
+PenaltyBreakString: 1000
+PenaltyExcessCharacter: 1000000
+PenaltyReturnTypeOnItsOwnLine: 200
+PointerAlignment: Right
+RawStringFormats:
+  - Language:        TextProto
+    BasedOnStyle:    google
+ReflowComments:  true
+SortIncludes:    true
+SortUsingDeclarations: true
+SpaceAfterCStyleCast: false
+SpaceAfterTemplateKeyword: false
+SpaceBeforeAssignmentOperators: true
+SpaceBeforeParens: Never
+SpaceInEmptyParentheses: false
+SpacesBeforeTrailingComments: 2
+SpacesInAngles:  false
+SpacesInContainerLiterals: true
+SpacesInCStyleCastParentheses: false
+SpacesInParentheses: false
+SpacesInSquareBrackets: false
+Standard:        Auto
+TabWidth:        4
+UseTab:          ForIndentation
+...
+
diff --git a/src/clang-format-all.sh b/src/clang-format-all.sh
new file mode 100755
index 0000000..c39ce41
--- /dev/null
+++ b/src/clang-format-all.sh
@@ -0,0 +1,10 @@
+SRC_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
+pushd ${SRC_DIR}
+for DIR in "Device" "Pipeline" "Reactor" "System" "Vulkan" "WSI"
+do
+    # Double clang-format, as it seems that one pass isn't always enough
+    find ${SRC_DIR}/$DIR  -iname "*.hpp" -o -iname "*.cpp" -o -iname "*.inl" | xargs clang-format -i
+    find ${SRC_DIR}/$DIR  -iname "*.hpp" -o -iname "*.cpp" -o -iname "*.inl" | xargs clang-format -i
+done
+popd
+
diff --git a/src/clang-format-separate.sh b/src/clang-format-separate.sh
new file mode 100755
index 0000000..3f2a511
--- /dev/null
+++ b/src/clang-format-separate.sh
@@ -0,0 +1,15 @@
+SRC_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
+
+pushd ${SRC_DIR}
+for DIR in "Device" "Pipeline" "Reactor" "System" "Vulkan" "WSI"
+do
+    # Double clang-format, as it seems that one pass isn't always enough
+    find ${SRC_DIR}/$DIR  -iname "*.hpp" -o -iname "*.cpp" -o -iname "*.inl" | xargs clang-format -i
+    find ${SRC_DIR}/$DIR  -iname "*.hpp" -o -iname "*.cpp" -o -iname "*.inl" | xargs clang-format -i
+
+    git add ${SRC_DIR}/$DIR
+    CHANGE_ID="$(echo $CHANGE_ID_SEED $DIR | openssl sha1)"
+    git commit -m "clang-format the src/$DIR directory" -m "Bug: b/144825072" -m "Change-Id:I$CHANGE_ID"
+done
+popd
+