mozilla-bmo1504834-part2.patch
changeset 1113 8e9195853a32
parent 1109 972f68ac6b1a
child 1119 4c5d44d40a03
equal deleted inserted replaced
1088:84cdfb476431 1113:8e9195853a32
       
     1 # HG changeset patch
       
     2 # Parent  6fa4b62427433e8f445d05c557e5db096667d880
       
     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 --git a/gfx/2d/ConvolutionFilter.cpp b/gfx/2d/ConvolutionFilter.cpp
       
     9 --- a/gfx/2d/ConvolutionFilter.cpp
       
    10 +++ b/gfx/2d/ConvolutionFilter.cpp
       
    11 @@ -30,32 +30,79 @@ bool ConvolutionFilter::GetFilterOffsetA
       
    12                                                   int32_t* aResultLength) {
       
    13    if (aRowIndex >= mFilter->numValues()) {
       
    14      return false;
       
    15    }
       
    16    mFilter->FilterForValue(aRowIndex, aResultOffset, aResultLength);
       
    17    return true;
       
    18  }
       
    19  
       
    20 +static void ByteSwapArray(uint8_t *u8Array, int32_t size) {
       
    21 +    uint32_t *array = reinterpret_cast<uint32_t*>(u8Array);
       
    22 +    for (int pxl = 0; pxl < size; ++pxl) {
       
    23 +        // Use an endian swap to move the bytes, i.e. BGRA -> ARGB.
       
    24 +        uint32_t rgba = array[pxl];
       
    25 +        array[pxl] = NativeEndian::swapToLittleEndian(rgba);
       
    26 +    }
       
    27 +}
       
    28 +
       
    29  void ConvolutionFilter::ConvolveHorizontally(const uint8_t* aSrc, uint8_t* aDst,
       
    30                                               bool aHasAlpha) {
       
    31 +#if MOZ_BIG_ENDIAN
       
    32 +    int outputSize = mFilter->numValues();
       
    33 +
       
    34 +    // Input size isn't handed in, so we have to calculate it quickly
       
    35 +    int inputSize = 0;
       
    36 +    for (int xx = 0; xx < outputSize; ++xx) {
       
    37 +        // Get the filter that determines the current output pixel.
       
    38 +        int filterOffset, filterLength;
       
    39 +        mFilter->FilterForValue(xx, &filterOffset, &filterLength);
       
    40 +        inputSize = std::max(inputSize, filterOffset + filterLength);
       
    41 +    }
       
    42 +
       
    43 +    ByteSwapArray((uint8_t*)aSrc, inputSize);
       
    44 +#endif
       
    45 +
       
    46    SkOpts::convolve_horizontally(aSrc, *mFilter, aDst, aHasAlpha);
       
    47 +
       
    48 +#if MOZ_BIG_ENDIAN
       
    49 +    ByteSwapArray((uint8_t*)aSrc, inputSize);
       
    50 +    ByteSwapArray(aDst, outputSize);
       
    51 +#endif
       
    52  }
       
    53  
       
    54  void ConvolutionFilter::ConvolveVertically(uint8_t* const* aSrc, uint8_t* aDst,
       
    55                                             int32_t aRowIndex, int32_t aRowSize,
       
    56                                             bool aHasAlpha) {
       
    57    MOZ_ASSERT(aRowIndex < mFilter->numValues());
       
    58  
       
    59    int32_t filterOffset;
       
    60    int32_t filterLength;
       
    61    auto filterValues =
       
    62        mFilter->FilterForValue(aRowIndex, &filterOffset, &filterLength);
       
    63 +
       
    64 +#if MOZ_BIG_ENDIAN
       
    65 +  for (int filterY = 0; filterY < filterLength; filterY++) {
       
    66 +      // Skia only knows LE, so we have to swizzle the input
       
    67 +    ByteSwapArray(aSrc[filterY], aRowSize);
       
    68 +  }
       
    69 +#endif
       
    70 +
       
    71    SkOpts::convolve_vertically(filterValues, filterLength, aSrc, aRowSize, aDst,
       
    72                                aHasAlpha);
       
    73 +
       
    74 +#if MOZ_BIG_ENDIAN
       
    75 +  // After skia is finished, we swizzle back to BE, in case
       
    76 +  // the input is used again somewhere else
       
    77 +  for (int filterY = 0; filterY < filterLength; filterY++) {
       
    78 +    ByteSwapArray(aSrc[filterY], aRowSize);
       
    79 +  }
       
    80 +  // The destination array as well
       
    81 +  ByteSwapArray(aDst, aRowSize);
       
    82 +#endif
       
    83  }
       
    84  
       
    85  /* ConvolutionFilter::ComputeResizeFactor is derived from Skia's
       
    86   * SkBitmapScaler/SkResizeFilter::computeFactors. It is governed by Skia's
       
    87   * BSD-style license (see gfx/skia/LICENSE) and the following copyright:
       
    88   * Copyright (c) 2015 Google Inc.
       
    89   */
       
    90  bool ConvolutionFilter::ComputeResizeFilter(ResizeMethod aResizeMethod,
       
    91 diff --git a/gfx/skia/skia/include/core/SkPreConfig.h b/gfx/skia/skia/include/core/SkPreConfig.h
       
    92 --- a/gfx/skia/skia/include/core/SkPreConfig.h
       
    93 +++ b/gfx/skia/skia/include/core/SkPreConfig.h
       
    94 @@ -68,17 +68,17 @@
       
    95          #define SK_CPU_BENDIAN
       
    96      #elif defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)
       
    97          #define SK_CPU_LENDIAN
       
    98      #elif defined(__sparc) || defined(__sparc__) || \
       
    99        defined(_POWER) || defined(__powerpc__) || \
       
   100        defined(__ppc__) || defined(__hppa) || \
       
   101        defined(__PPC__) || defined(__PPC64__) || \
       
   102        defined(_MIPSEB) || defined(__ARMEB__) || \
       
   103 -      defined(__s390__) || \
       
   104 +      defined(__s390__) || defined(__s390x__) || \
       
   105        (defined(__sh__) && defined(__BIG_ENDIAN__)) || \
       
   106        (defined(__ia64) && defined(__BIG_ENDIAN__))
       
   107           #define SK_CPU_BENDIAN
       
   108      #else
       
   109          #define SK_CPU_LENDIAN
       
   110      #endif
       
   111  #endif
       
   112