Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Functions
SkBlitRow_D32.cpp File Reference
#include "include/core/SkColor.h"
#include "include/core/SkColorPriv.h"
#include "include/core/SkTypes.h"
#include "include/private/SkColorData.h"
#include "include/private/base/SkCPUTypes.h"
#include "src/core/SkBlitRow.h"
#include "src/core/SkMemset.h"
#include <cstring>
#include <iterator>
#include <emmintrin.h>
#include <xmmintrin.h>

Go to the source code of this file.

Functions

static void blit_row_s32_opaque (SkPMColor *dst, const SkPMColor *src, int count, U8CPU alpha)
 
static __m128i SkPMLerp_SSE2 (const __m128i &src, const __m128i &dst, const unsigned src_scale)
 
static void blit_row_s32_blend (SkPMColor *dst, const SkPMColor *src, int count, U8CPU alpha)
 
static __m128i SkBlendARGB32_SSE2 (const __m128i &src, const __m128i &dst, const unsigned aa)
 
static void blit_row_s32a_blend (SkPMColor *dst, const SkPMColor *src, int count, U8CPU alpha)
 

Function Documentation

◆ blit_row_s32_blend()

static void blit_row_s32_blend ( SkPMColor dst,
const SkPMColor src,
int  count,
U8CPU  alpha 
)
static

Definition at line 66 of file SkBlitRow_D32.cpp.

66 {
67 SkASSERT(alpha <= 255);
68
69 auto src4 = (const __m128i*)src;
70 auto dst4 = ( __m128i*)dst;
71
72 while (count >= 4) {
73 _mm_storeu_si128(dst4, SkPMLerp_SSE2(_mm_loadu_si128(src4),
74 _mm_loadu_si128(dst4),
75 SkAlpha255To256(alpha)));
76 src4++;
77 dst4++;
78 count -= 4;
79 }
80
81 src = (const SkPMColor*)src4;
82 dst = ( SkPMColor*)dst4;
83
84 while (count --> 0) {
85 *dst = SkPMLerp(*src, *dst, SkAlpha255To256(alpha));
86 src++;
87 dst++;
88 }
89 }
int count
#define SkASSERT(cond)
Definition SkAssert.h:116
static __m128i SkPMLerp_SSE2(const __m128i &src, const __m128i &dst, const unsigned src_scale)
static SkPMColor SkPMLerp(SkPMColor src, SkPMColor dst, unsigned scale)
static unsigned SkAlpha255To256(U8CPU alpha)
Definition SkColorPriv.h:24
uint32_t SkPMColor
Definition SkColor.h:205
dst
Definition cp.py:12

◆ blit_row_s32_opaque()

static void blit_row_s32_opaque ( SkPMColor dst,
const SkPMColor src,
int  count,
U8CPU  alpha 
)
static

Definition at line 20 of file SkBlitRow_D32.cpp.

23 {
24 SkASSERT(255 == alpha);
25 memcpy(dst, src, count * sizeof(SkPMColor));
26}

◆ blit_row_s32a_blend()

static void blit_row_s32a_blend ( SkPMColor dst,
const SkPMColor src,
int  count,
U8CPU  alpha 
)
static

Definition at line 131 of file SkBlitRow_D32.cpp.

131 {
132 SkASSERT(alpha <= 255);
133
134 auto src4 = (const __m128i*)src;
135 auto dst4 = ( __m128i*)dst;
136
137 while (count >= 4) {
138 _mm_storeu_si128(dst4, SkBlendARGB32_SSE2(_mm_loadu_si128(src4),
139 _mm_loadu_si128(dst4),
140 alpha));
141 src4++;
142 dst4++;
143 count -= 4;
144 }
145
146 src = (const SkPMColor*)src4;
147 dst = ( SkPMColor*)dst4;
148
149 while (count --> 0) {
150 *dst = SkBlendARGB32(*src, *dst, alpha);
151 src++;
152 dst++;
153 }
154 }
static __m128i SkBlendARGB32_SSE2(const __m128i &src, const __m128i &dst, const unsigned aa)
static SkPMColor SkBlendARGB32(SkPMColor src, SkPMColor dst, U8CPU aa)

◆ SkBlendARGB32_SSE2()

static __m128i SkBlendARGB32_SSE2 ( const __m128i &  src,
const __m128i &  dst,
const unsigned  aa 
)
inlinestatic

Definition at line 91 of file SkBlitRow_D32.cpp.

93 {
94 unsigned alpha = SkAlpha255To256(aa);
95 __m128i src_scale = _mm_set1_epi16(alpha);
96 // SkAlphaMulInv256(SkGetPackedA32(src), src_scale)
97 __m128i dst_scale = _mm_srli_epi32(src, 24);
98 // High words in dst_scale are 0, so it's safe to multiply with 16-bit src_scale.
99 dst_scale = _mm_mullo_epi16(dst_scale, src_scale);
100 dst_scale = _mm_sub_epi32(_mm_set1_epi32(0xFFFF), dst_scale);
101 dst_scale = _mm_add_epi32(dst_scale, _mm_srli_epi32(dst_scale, 8));
102 dst_scale = _mm_srli_epi32(dst_scale, 8);
103 // Duplicate scales into 2x16-bit pattern per pixel.
104 dst_scale = _mm_shufflelo_epi16(dst_scale, _MM_SHUFFLE(2, 2, 0, 0));
105 dst_scale = _mm_shufflehi_epi16(dst_scale, _MM_SHUFFLE(2, 2, 0, 0));
106
107 const __m128i mask = _mm_set1_epi32(0x00FF00FF);
108
109 // Unpack the 16x8-bit source/destination into 2 8x16-bit splayed halves.
110 __m128i src_rb = _mm_and_si128(mask, src);
111 __m128i src_ag = _mm_srli_epi16(src, 8);
112 __m128i dst_rb = _mm_and_si128(mask, dst);
113 __m128i dst_ag = _mm_srli_epi16(dst, 8);
114
115 // Scale them.
116 src_rb = _mm_mullo_epi16(src_rb, src_scale);
117 src_ag = _mm_mullo_epi16(src_ag, src_scale);
118 dst_rb = _mm_mullo_epi16(dst_rb, dst_scale);
119 dst_ag = _mm_mullo_epi16(dst_ag, dst_scale);
120
121 // Add the scaled source and destination.
122 dst_rb = _mm_add_epi16(src_rb, dst_rb);
123 dst_ag = _mm_add_epi16(src_ag, dst_ag);
124
125 // Unsplay the halves back together.
126 dst_rb = _mm_srli_epi16(dst_rb, 8);
127 dst_ag = _mm_andnot_si128(mask, dst_ag);
128 return _mm_or_si128(dst_rb, dst_ag);
129 }

◆ SkPMLerp_SSE2()

static __m128i SkPMLerp_SSE2 ( const __m128i &  src,
const __m128i &  dst,
const unsigned  src_scale 
)
inlinestatic

Definition at line 37 of file SkBlitRow_D32.cpp.

39 {
40 // Computes dst + (((src - dst)*src_scale)>>8)
41 const __m128i mask = _mm_set1_epi32(0x00FF00FF);
42
43 // Unpack the 16x8-bit source into 2 8x16-bit splayed halves.
44 __m128i src_rb = _mm_and_si128(mask, src);
45 __m128i src_ag = _mm_srli_epi16(src, 8);
46 __m128i dst_rb = _mm_and_si128(mask, dst);
47 __m128i dst_ag = _mm_srli_epi16(dst, 8);
48
49 // Compute scaled differences.
50 __m128i diff_rb = _mm_sub_epi16(src_rb, dst_rb);
51 __m128i diff_ag = _mm_sub_epi16(src_ag, dst_ag);
52 __m128i s = _mm_set1_epi16(src_scale);
53 diff_rb = _mm_mullo_epi16(diff_rb, s);
54 diff_ag = _mm_mullo_epi16(diff_ag, s);
55
56 // Pack the differences back together.
57 diff_rb = _mm_srli_epi16(diff_rb, 8);
58 diff_ag = _mm_andnot_si128(mask, diff_ag);
59 __m128i diff = _mm_or_si128(diff_rb, diff_ag);
60
61 // Add difference to destination.
62 return _mm_add_epi8(dst, diff);
63 }
struct MyStruct s