gfx/skia/trunk/src/opts/SkBlurImage_opts_SSE2.cpp

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

     1 /*
     2  * Copyright 2013 The Android Open Source Project
     3  *
     4  * Use of this source code is governed by a BSD-style license that can be
     5  * found in the LICENSE file.
     6  */
     9 #include "SkBitmap.h"
    10 #include "SkColorPriv.h"
    11 #include "SkBlurImage_opts_SSE2.h"
    12 #include "SkRect.h"
    14 #include <emmintrin.h>
    16 namespace {
    18 enum BlurDirection {
    19     kX, kY
    20 };
    22 /**
    23  * Helper function to spread the components of a 32-bit integer into the
    24  * lower 8 bits of each 32-bit element of an SSE register.
    25  */
    27 inline __m128i expand(int a) {
    28       const __m128i zero = _mm_setzero_si128();
    30       // 0 0 0 0   0 0 0 0   0 0 0 0   A R G B
    31       __m128i result = _mm_cvtsi32_si128(a);
    33       // 0 0 0 0   0 0 0 0   0 A 0 R   0 G 0 B
    34       result = _mm_unpacklo_epi8(result, zero);
    36       // 0 0 0 A   0 0 0 R   0 0 0 G   0 0 0 B
    37       return _mm_unpacklo_epi16(result, zero);
    38 }
    40 template<BlurDirection srcDirection, BlurDirection dstDirection>
    41 void SkBoxBlur_SSE2(const SkPMColor* src, int srcStride, SkPMColor* dst, int kernelSize,
    42                     int leftOffset, int rightOffset, int width, int height)
    43 {
    44     const int rightBorder = SkMin32(rightOffset + 1, width);
    45     const int srcStrideX = srcDirection == kX ? 1 : srcStride;
    46     const int dstStrideX = dstDirection == kX ? 1 : height;
    47     const int srcStrideY = srcDirection == kX ? srcStride : 1;
    48     const int dstStrideY = dstDirection == kX ? width : 1;
    49     const __m128i scale = _mm_set1_epi32((1 << 24) / kernelSize);
    50     const __m128i half = _mm_set1_epi32(1 << 23);
    51     const __m128i zero = _mm_setzero_si128();
    52     for (int y = 0; y < height; ++y) {
    53         __m128i sum = zero;
    54         const SkPMColor* p = src;
    55         for (int i = 0; i < rightBorder; ++i) {
    56             sum = _mm_add_epi32(sum, expand(*p));
    57             p += srcStrideX;
    58         }
    60         const SkPMColor* sptr = src;
    61         SkColor* dptr = dst;
    62         for (int x = 0; x < width; ++x) {
    63 #if 0
    64             // In SSE4.1, this would be
    65             __m128i result = _mm_mullo_epi32(sum, scale);
    66 #else
    67             // But SSE2 has no PMULLUD, so we must do AG and RB separately.
    68             __m128i tmp1 = _mm_mul_epu32(sum, scale);
    69             __m128i tmp2 = _mm_mul_epu32(_mm_srli_si128(sum, 4),
    70                                          _mm_srli_si128(scale, 4));
    71             __m128i result = _mm_unpacklo_epi32(_mm_shuffle_epi32(tmp1, _MM_SHUFFLE(0,0,2,0)),
    72                                                 _mm_shuffle_epi32(tmp2, _MM_SHUFFLE(0,0,2,0)));
    73 #endif
    74             // sumA*scale+.5 sumB*scale+.5 sumG*scale+.5 sumB*scale+.5
    75             result = _mm_add_epi32(result, half);
    77             // 0 0 0 A   0 0 0 R   0 0 0 G   0 0 0 B
    78             result = _mm_srli_epi32(result, 24);
    80             // 0 0 0 0   0 0 0 0   0 A 0 R   0 G 0 B
    81             result = _mm_packs_epi32(result, zero);
    83             // 0 0 0 0   0 0 0 0   0 0 0 0   A R G B
    84             result = _mm_packus_epi16(result, zero);
    85             *dptr = _mm_cvtsi128_si32(result);
    86             if (x >= leftOffset) {
    87                 SkColor l = *(sptr - leftOffset * srcStrideX);
    88                 sum = _mm_sub_epi32(sum, expand(l));
    89             }
    90             if (x + rightOffset + 1 < width) {
    91                 SkColor r = *(sptr + (rightOffset + 1) * srcStrideX);
    92                 sum = _mm_add_epi32(sum, expand(r));
    93             }
    94             sptr += srcStrideX;
    95             if (srcDirection == kY) {
    96                 _mm_prefetch(reinterpret_cast<const char*>(sptr + (rightOffset + 1) * srcStrideX),
    97                              _MM_HINT_T0);
    98             }
    99             dptr += dstStrideX;
   100         }
   101         src += srcStrideY;
   102         dst += dstStrideY;
   103     }
   104 }
   106 } // namespace
   108 bool SkBoxBlurGetPlatformProcs_SSE2(SkBoxBlurProc* boxBlurX,
   109                                     SkBoxBlurProc* boxBlurY,
   110                                     SkBoxBlurProc* boxBlurXY,
   111                                     SkBoxBlurProc* boxBlurYX) {
   112     *boxBlurX = SkBoxBlur_SSE2<kX, kX>;
   113     *boxBlurY = SkBoxBlur_SSE2<kY, kY>;
   114     *boxBlurXY = SkBoxBlur_SSE2<kX, kY>;
   115     *boxBlurYX = SkBoxBlur_SSE2<kY, kX>;
   116     return true;
   117 }

mercurial