Simplify matrix uniform data management.

We can use `if constexpr` to avoid the need for a helper function that
uses template specialization, and we can use `getBufferPtrAndMarkDirty`
instead of performing the equivalent operations by hand.

Change-Id: I548c719bae4f215e0a9c658a942deaec38ce27ad
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/462098
Auto-Submit: John Stiles <johnstiles@google.com>
Reviewed-by: Jim Van Verth <jvanverth@google.com>
Commit-Queue: John Stiles <johnstiles@google.com>
diff --git a/src/gpu/GrUniformDataManager.cpp b/src/gpu/GrUniformDataManager.cpp
index 69842d0..dbf61e6 100644
--- a/src/gpu/GrUniformDataManager.cpp
+++ b/src/gpu/GrUniformDataManager.cpp
@@ -259,11 +259,9 @@
     this->setMatrices<4>(u, arrayCount, m);
 }
 
-template<int N> struct set_uniform_matrix;
-
-template<int N> inline void GrUniformDataManager::setMatrices(UniformHandle u,
-                                                              int arrayCount,
-                                                              const float matrices[]) const {
+template <int N> inline void GrUniformDataManager::setMatrices(UniformHandle u,
+                                                               int arrayCount,
+                                                               const float matrices[]) const {
     const Uniform& uni = fUniforms[u.toIndex()];
     SkASSERT(uni.fType == kFloat2x2_GrSLType + (N - 2) ||
              uni.fType == kHalf2x2_GrSLType + (N - 2));
@@ -271,16 +269,11 @@
     SkASSERT(arrayCount <= uni.fArrayCount ||
              (1 == arrayCount && GrShaderVar::kNonArray == uni.fArrayCount));
 
-    void* buffer = fUniformData.get();
-    fUniformsDirty = true;
-
-    set_uniform_matrix<N>::set(buffer, uni.fOffset, arrayCount, matrices);
-}
-
-template<int N> struct set_uniform_matrix {
-    inline static void set(void* buffer, int uniformOffset, int count, const float matrices[]) {
-        buffer = static_cast<char*>(buffer) + uniformOffset;
-        for (int i = 0; i < count; ++i) {
+    void* buffer = this->getBufferPtrAndMarkDirty(uni);
+    if constexpr (N == 4) {
+        memcpy(buffer, matrices, arrayCount * 16 * sizeof(float));
+    } else {
+        for (int i = 0; i < arrayCount; ++i) {
             const float* matrix = &matrices[N * N * i];
             for (int j = 0; j < N; ++j) {
                 memcpy(buffer, &matrix[j * N], N * sizeof(float));
@@ -288,12 +281,4 @@
             }
         }
     }
-};
-
-template<> struct set_uniform_matrix<4> {
-    inline static void set(void* buffer, int uniformOffset, int count, const float matrices[]) {
-        buffer = static_cast<char*>(buffer) + uniformOffset;
-        memcpy(buffer, matrices, count * 16 * sizeof(float));
-    }
-};
-
+}