|
1 # HG changeset patch |
|
2 # Parent 548d0a2f3a22bfac32ec0c3921c6c969c8bf32a9 |
|
3 Skia does not support big endian. The places to fix are too numerous and upstream (skia, not Mozilla) |
|
4 has no interest in maintaining big endian. |
|
5 So here we try to swizzle the input for skia, so that skia always works on LE, and when it comes |
|
6 out again, we transform back to BE. |
|
7 |
|
8 diff -r 548d0a2f3a22 gfx/2d/ConvolutionFilter.cpp |
|
9 --- a/gfx/2d/ConvolutionFilter.cpp Mon Jul 22 16:57:54 2019 +0200 |
|
10 +++ b/gfx/2d/ConvolutionFilter.cpp Thu Jul 25 14:27:59 2019 +0200 |
|
11 @@ -35,9 +35,38 @@ |
|
12 return true; |
|
13 } |
|
14 |
|
15 +static void ByteSwapArray(uint8_t *u8Array, int32_t size) { |
|
16 + uint32_t *array = reinterpret_cast<uint32_t*>(u8Array); |
|
17 + for (int pxl = 0; pxl < size; ++pxl) { |
|
18 + // Use an endian swap to move the bytes, i.e. BGRA -> ARGB. |
|
19 + uint32_t rgba = array[pxl]; |
|
20 + array[pxl] = NativeEndian::swapToLittleEndian(rgba); |
|
21 + } |
|
22 +} |
|
23 + |
|
24 void ConvolutionFilter::ConvolveHorizontally(const uint8_t* aSrc, uint8_t* aDst, |
|
25 bool aHasAlpha) { |
|
26 +#ifdef MOZ_BIG_ENDIAN |
|
27 + int outputSize = mFilter->numValues(); |
|
28 + |
|
29 + // Input size isn't handed in, so we have to calculate it quickly |
|
30 + int inputSize = 0; |
|
31 + for (int xx = 0; xx < outputSize; ++xx) { |
|
32 + // Get the filter that determines the current output pixel. |
|
33 + int filterOffset, filterLength; |
|
34 + mFilter->FilterForValue(xx, &filterOffset, &filterLength); |
|
35 + inputSize = std::max(inputSize, filterOffset + filterLength); |
|
36 + } |
|
37 + |
|
38 + ByteSwapArray((uint8_t*)aSrc, inputSize); |
|
39 +#endif |
|
40 + |
|
41 SkOpts::convolve_horizontally(aSrc, *mFilter, aDst, aHasAlpha); |
|
42 + |
|
43 +#ifdef MOZ_BIG_ENDIAN |
|
44 + ByteSwapArray((uint8_t*)aSrc, inputSize); |
|
45 + ByteSwapArray(aDst, outputSize); |
|
46 +#endif |
|
47 } |
|
48 |
|
49 void ConvolutionFilter::ConvolveVertically(uint8_t* const* aSrc, uint8_t* aDst, |
|
50 @@ -49,8 +78,26 @@ |
|
51 int32_t filterLength; |
|
52 auto filterValues = |
|
53 mFilter->FilterForValue(aRowIndex, &filterOffset, &filterLength); |
|
54 + |
|
55 +#ifdef MOZ_BIG_ENDIAN |
|
56 + for (int filterY = 0; filterY < filterLength; filterY++) { |
|
57 + // Skia only knows LE, so we have to swizzle the input |
|
58 + ByteSwapArray(aSrc[filterY], aRowSize); |
|
59 + } |
|
60 +#endif |
|
61 + |
|
62 SkOpts::convolve_vertically(filterValues, filterLength, aSrc, aRowSize, aDst, |
|
63 aHasAlpha); |
|
64 + |
|
65 +#ifdef MOZ_BIG_ENDIAN |
|
66 + // After skia is finished, we swizzle back to BE, in case |
|
67 + // the input is used again somewhere else |
|
68 + for (int filterY = 0; filterY < filterLength; filterY++) { |
|
69 + ByteSwapArray(aSrc[filterY], aRowSize); |
|
70 + } |
|
71 + // The destination array as well |
|
72 + ByteSwapArray(aDst, aRowSize); |
|
73 +#endif |
|
74 } |
|
75 |
|
76 /* ConvolutionFilter::ComputeResizeFactor is derived from Skia's |
|
77 diff -r 548d0a2f3a22 gfx/skia/skia/include/core/SkPreConfig.h |
|
78 --- a/gfx/skia/skia/include/core/SkPreConfig.h Mon Jul 22 16:57:54 2019 +0200 |
|
79 +++ b/gfx/skia/skia/include/core/SkPreConfig.h Thu Jul 25 14:27:59 2019 +0200 |
|
80 @@ -73,7 +73,7 @@ |
|
81 defined(__ppc__) || defined(__hppa) || \ |
|
82 defined(__PPC__) || defined(__PPC64__) || \ |
|
83 defined(_MIPSEB) || defined(__ARMEB__) || \ |
|
84 - defined(__s390__) || \ |
|
85 + defined(__s390__) || defined(__s390x__) || \ |
|
86 (defined(__sh__) && defined(__BIG_ENDIAN__)) || \ |
|
87 (defined(__ia64) && defined(__BIG_ENDIAN__)) |
|
88 #define SK_CPU_BENDIAN |