225ef2
# HG changeset patch
225ef2
# Parent  36563351309ddbc6c29559ba50a41d005f925abb
225ef2
Skia does not support big endian. The places to fix are too numerous and upstream (skia, not Mozilla)
225ef2
has no interest in maintaining big endian.
225ef2
So here we try to swizzle the input for skia, so that skia always works on LE, and when it comes
225ef2
out again, we transform back to BE.
225ef2
225ef2
diff -r 36563351309d gfx/2d/ConvolutionFilter.cpp
225ef2
--- a/gfx/2d/ConvolutionFilter.cpp	Mon Sep 09 17:59:28 2019 +0200
225ef2
+++ b/gfx/2d/ConvolutionFilter.cpp	Tue Sep 10 08:25:13 2019 +0200
225ef2
@@ -35,9 +35,38 @@
225ef2
   return true;
225ef2
 }
225ef2
 
225ef2
+static void ByteSwapArray(uint8_t *u8Array, int32_t size) {
225ef2
+    uint32_t *array = reinterpret_cast<uint32_t*>(u8Array);
225ef2
+    for (int pxl = 0; pxl < size; ++pxl) {
225ef2
+        // Use an endian swap to move the bytes, i.e. BGRA -> ARGB.
225ef2
+        uint32_t rgba = array[pxl];
225ef2
+        array[pxl] = NativeEndian::swapToLittleEndian(rgba);
225ef2
+    }
225ef2
+}
225ef2
+
225ef2
 void ConvolutionFilter::ConvolveHorizontally(const uint8_t* aSrc, uint8_t* aDst,
225ef2
                                              bool aHasAlpha) {
225ef2
+#if MOZ_BIG_ENDIAN
225ef2
+    int outputSize = mFilter->numValues();
225ef2
+
225ef2
+    // Input size isn't handed in, so we have to calculate it quickly
225ef2
+    int inputSize = 0;
225ef2
+    for (int xx = 0; xx < outputSize; ++xx) {
225ef2
+        // Get the filter that determines the current output pixel.
225ef2
+        int filterOffset, filterLength;
225ef2
+        mFilter->FilterForValue(xx, &filterOffset, &filterLength);
225ef2
+        inputSize = std::max(inputSize, filterOffset + filterLength);
225ef2
+    }
225ef2
+
225ef2
+    ByteSwapArray((uint8_t*)aSrc, inputSize);
225ef2
+#endif
225ef2
+
225ef2
   SkOpts::convolve_horizontally(aSrc, *mFilter, aDst, aHasAlpha);
225ef2
+
225ef2
+#if MOZ_BIG_ENDIAN
225ef2
+    ByteSwapArray((uint8_t*)aSrc, inputSize);
225ef2
+    ByteSwapArray(aDst, outputSize);
225ef2
+#endif
225ef2
 }
225ef2
 
225ef2
 void ConvolutionFilter::ConvolveVertically(uint8_t* const* aSrc, uint8_t* aDst,
225ef2
@@ -49,8 +78,26 @@
225ef2
   int32_t filterLength;
225ef2
   auto filterValues =
225ef2
       mFilter->FilterForValue(aRowIndex, &filterOffset, &filterLength);
225ef2
+
225ef2
+#if MOZ_BIG_ENDIAN
225ef2
+  for (int filterY = 0; filterY < filterLength; filterY++) {
225ef2
+      // Skia only knows LE, so we have to swizzle the input
225ef2
+    ByteSwapArray(aSrc[filterY], aRowSize);
225ef2
+  }
225ef2
+#endif
225ef2
+
225ef2
   SkOpts::convolve_vertically(filterValues, filterLength, aSrc, aRowSize, aDst,
225ef2
                               aHasAlpha);
225ef2
+
225ef2
+#if MOZ_BIG_ENDIAN
225ef2
+  // After skia is finished, we swizzle back to BE, in case
225ef2
+  // the input is used again somewhere else
225ef2
+  for (int filterY = 0; filterY < filterLength; filterY++) {
225ef2
+    ByteSwapArray(aSrc[filterY], aRowSize);
225ef2
+  }
225ef2
+  // The destination array as well
225ef2
+  ByteSwapArray(aDst, aRowSize);
225ef2
+#endif
225ef2
 }
225ef2
 
225ef2
 /* ConvolutionFilter::ComputeResizeFactor is derived from Skia's
225ef2
diff -r 36563351309d gfx/skia/skia/include/core/SkPreConfig.h
225ef2
--- a/gfx/skia/skia/include/core/SkPreConfig.h	Mon Sep 09 17:59:28 2019 +0200
225ef2
+++ b/gfx/skia/skia/include/core/SkPreConfig.h	Tue Sep 10 08:25:13 2019 +0200
225ef2
@@ -73,7 +73,7 @@
225ef2
       defined(__ppc__) || defined(__hppa) || \
225ef2
       defined(__PPC__) || defined(__PPC64__) || \
225ef2
       defined(_MIPSEB) || defined(__ARMEB__) || \
225ef2
-      defined(__s390__) || \
225ef2
+      defined(__s390__) || defined(__s390x__) || \
225ef2
       (defined(__sh__) && defined(__BIG_ENDIAN__)) || \
225ef2
       (defined(__ia64) && defined(__BIG_ENDIAN__))
225ef2
          #define SK_CPU_BENDIAN