| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2012 The Android Open Source Project | 2 * Copyright 2012 The Android Open Source Project |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include <emmintrin.h> | 8 #include <emmintrin.h> |
| 9 #include "SkBitmapProcState_opts_SSE2.h" | 9 #include "SkBitmapProcState_opts_SSE2.h" |
| 10 #include "SkBlitRow_opts_SSE2.h" | 10 #include "SkBlitRow_opts_SSE2.h" |
| 11 #include "SkColorPriv.h" | 11 #include "SkColorPriv.h" |
| 12 #include "SkColor_opts_SSE2.h" | 12 #include "SkColor_opts_SSE2.h" |
| 13 #include "SkDither.h" | 13 #include "SkDither.h" |
| 14 #include "SkMSAN.h" | 14 #include "SkMSAN.h" |
| 15 #include "SkUtils.h" | 15 #include "SkUtils.h" |
| 16 | 16 |
| 17 /* SSE2 version of S32_Blend_BlitRow32() | 17 /* SSE2 version of S32_Blend_BlitRow32() |
| 18 * portable version is in core/SkBlitRow_D32.cpp | 18 * portable version is in core/SkBlitRow_D32.cpp |
| 19 */ | 19 */ |
| 20 void S32_Blend_BlitRow32_SSE2(SkPMColor* SK_RESTRICT dst, | 20 void S32_Blend_BlitRow32_SSE2(SkPMColor* SK_RESTRICT dst, |
| 21 const SkPMColor* SK_RESTRICT src, | 21 const SkPMColor* SK_RESTRICT src, |
| 22 int count, U8CPU alpha) { | 22 int count, U8CPU alpha) { |
| 23 SkASSERT(alpha <= 255); | 23 SkASSERT(alpha <= 255); |
| 24 if (count <= 0) { | 24 if (count <= 0) { |
| 25 return; | 25 return; |
| 26 } | 26 } |
| 27 | 27 |
| 28 uint32_t src_scale = SkAlpha255To256(alpha); | 28 uint32_t src_scale = SkAlpha255To256(alpha); |
| 29 uint32_t dst_scale = 256 - src_scale; | |
| 30 | 29 |
| 31 if (count >= 4) { | 30 if (count >= 4) { |
| 32 SkASSERT(((size_t)dst & 0x03) == 0); | 31 SkASSERT(((size_t)dst & 0x03) == 0); |
| 33 while (((size_t)dst & 0x0F) != 0) { | 32 while (((size_t)dst & 0x0F) != 0) { |
| 34 *dst = SkAlphaMulQ(*src, src_scale) + SkAlphaMulQ(*dst, dst_scale); | 33 *dst = SkPMLerp(*src, *dst, src_scale); |
| 35 src++; | 34 src++; |
| 36 dst++; | 35 dst++; |
| 37 count--; | 36 count--; |
| 38 } | 37 } |
| 39 | 38 |
| 40 const __m128i *s = reinterpret_cast<const __m128i*>(src); | 39 const __m128i *s = reinterpret_cast<const __m128i*>(src); |
| 41 __m128i *d = reinterpret_cast<__m128i*>(dst); | 40 __m128i *d = reinterpret_cast<__m128i*>(dst); |
| 42 | 41 |
| 43 while (count >= 4) { | 42 while (count >= 4) { |
| 44 // Load 4 pixels each of src and dest. | 43 // Load 4 pixels each of src and dest. |
| 45 __m128i src_pixel = _mm_loadu_si128(s); | 44 __m128i src_pixel = _mm_loadu_si128(s); |
| 46 __m128i dst_pixel = _mm_load_si128(d); | 45 __m128i dst_pixel = _mm_load_si128(d); |
| 47 | 46 |
| 48 src_pixel = SkAlphaMulQ_SSE2(src_pixel, src_scale); | 47 __m128i result = SkPMLerp_SSE2(src_pixel, dst_pixel, src_scale); |
| 49 dst_pixel = SkAlphaMulQ_SSE2(dst_pixel, dst_scale); | |
| 50 | |
| 51 // Add result | |
| 52 __m128i result = _mm_add_epi8(src_pixel, dst_pixel); | |
| 53 _mm_store_si128(d, result); | 48 _mm_store_si128(d, result); |
| 54 s++; | 49 s++; |
| 55 d++; | 50 d++; |
| 56 count -= 4; | 51 count -= 4; |
| 57 } | 52 } |
| 58 src = reinterpret_cast<const SkPMColor*>(s); | 53 src = reinterpret_cast<const SkPMColor*>(s); |
| 59 dst = reinterpret_cast<SkPMColor*>(d); | 54 dst = reinterpret_cast<SkPMColor*>(d); |
| 60 } | 55 } |
| 61 | 56 |
| 62 while (count > 0) { | 57 while (count > 0) { |
| 63 *dst = SkAlphaMulQ(*src, src_scale) + SkAlphaMulQ(*dst, dst_scale); | 58 *dst = SkPMLerp(*src, *dst, src_scale); |
| 64 src++; | 59 src++; |
| 65 dst++; | 60 dst++; |
| 66 count--; | 61 count--; |
| 67 } | 62 } |
| 68 } | 63 } |
| 69 | 64 |
| 70 void S32A_Blend_BlitRow32_SSE2(SkPMColor* SK_RESTRICT dst, | 65 void S32A_Blend_BlitRow32_SSE2(SkPMColor* SK_RESTRICT dst, |
| 71 const SkPMColor* SK_RESTRICT src, | 66 const SkPMColor* SK_RESTRICT src, |
| 72 int count, U8CPU alpha) { | 67 int count, U8CPU alpha) { |
| 73 SkASSERT(alpha <= 255); | 68 SkASSERT(alpha <= 255); |
| (...skipping 912 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 986 uint32_t dst_expanded = SkExpand_rgb_16(*dst); | 981 uint32_t dst_expanded = SkExpand_rgb_16(*dst); |
| 987 dst_expanded = dst_expanded * (SkAlpha255To256(255 - a) >> 3); | 982 dst_expanded = dst_expanded * (SkAlpha255To256(255 - a) >> 3); |
| 988 // now src and dst expanded are in g:11 r:10 x:1 b:10 | 983 // now src and dst expanded are in g:11 r:10 x:1 b:10 |
| 989 *dst = SkCompact_rgb_16((src_expanded + dst_expanded) >> 5); | 984 *dst = SkCompact_rgb_16((src_expanded + dst_expanded) >> 5); |
| 990 } | 985 } |
| 991 dst += 1; | 986 dst += 1; |
| 992 DITHER_INC_X(x); | 987 DITHER_INC_X(x); |
| 993 } while (--count != 0); | 988 } while (--count != 0); |
| 994 } | 989 } |
| 995 } | 990 } |
| OLD | NEW |