OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 Google Inc. |
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 "SkBlitMask.h" | 8 #include "SkBlitMask.h" |
9 #include "SkColor.h" | 9 #include "SkColor.h" |
10 #include "SkColorPriv.h" | 10 #include "SkColorPriv.h" |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 color, clip.width(), clip.height()); | 69 color, clip.width(), clip.height()); |
70 return true; | 70 return true; |
71 } | 71 } |
72 | 72 |
73 return false; | 73 return false; |
74 } | 74 } |
75 | 75 |
76 /////////////////////////////////////////////////////////////////////////////// | 76 /////////////////////////////////////////////////////////////////////////////// |
77 /////////////////////////////////////////////////////////////////////////////// | 77 /////////////////////////////////////////////////////////////////////////////// |
78 | 78 |
79 static void BW_RowProc_Blend( | 79 static void BW_RowProc_Blend(SkPMColor* SK_RESTRICT dst, |
80 SkPMColor* SK_RESTRICT dst, const void* maskIn, const SkPMColor* SK_REST
RICT src, int count) { | 80 const uint8_t* SK_RESTRICT mask, |
81 const uint8_t* SK_RESTRICT mask = static_cast<const uint8_t*>(maskIn); | 81 const SkPMColor* SK_RESTRICT src, int count) { |
82 int i, octuple = (count + 7) >> 3; | 82 int i, octuple = (count + 7) >> 3; |
83 for (i = 0; i < octuple; ++i) { | 83 for (i = 0; i < octuple; ++i) { |
84 int m = *mask++; | 84 int m = *mask++; |
85 if (m & 0x80) { dst[0] = SkPMSrcOver(src[0], dst[0]); } | 85 if (m & 0x80) { dst[0] = SkPMSrcOver(src[0], dst[0]); } |
86 if (m & 0x40) { dst[1] = SkPMSrcOver(src[1], dst[1]); } | 86 if (m & 0x40) { dst[1] = SkPMSrcOver(src[1], dst[1]); } |
87 if (m & 0x20) { dst[2] = SkPMSrcOver(src[2], dst[2]); } | 87 if (m & 0x20) { dst[2] = SkPMSrcOver(src[2], dst[2]); } |
88 if (m & 0x10) { dst[3] = SkPMSrcOver(src[3], dst[3]); } | 88 if (m & 0x10) { dst[3] = SkPMSrcOver(src[3], dst[3]); } |
89 if (m & 0x08) { dst[4] = SkPMSrcOver(src[4], dst[4]); } | 89 if (m & 0x08) { dst[4] = SkPMSrcOver(src[4], dst[4]); } |
90 if (m & 0x04) { dst[5] = SkPMSrcOver(src[5], dst[5]); } | 90 if (m & 0x04) { dst[5] = SkPMSrcOver(src[5], dst[5]); } |
91 if (m & 0x02) { dst[6] = SkPMSrcOver(src[6], dst[6]); } | 91 if (m & 0x02) { dst[6] = SkPMSrcOver(src[6], dst[6]); } |
92 if (m & 0x01) { dst[7] = SkPMSrcOver(src[7], dst[7]); } | 92 if (m & 0x01) { dst[7] = SkPMSrcOver(src[7], dst[7]); } |
93 src += 8; | 93 src += 8; |
94 dst += 8; | 94 dst += 8; |
95 } | 95 } |
96 count &= 7; | 96 count &= 7; |
97 if (count > 0) { | 97 if (count > 0) { |
98 int m = *mask; | 98 int m = *mask; |
99 do { | 99 do { |
100 if (m & 0x80) { dst[0] = SkPMSrcOver(src[0], dst[0]); } | 100 if (m & 0x80) { dst[0] = SkPMSrcOver(src[0], dst[0]); } |
101 m <<= 1; | 101 m <<= 1; |
102 src += 1; | 102 src += 1; |
103 dst += 1; | 103 dst += 1; |
104 } while (--count > 0); | 104 } while (--count > 0); |
105 } | 105 } |
106 } | 106 } |
107 | 107 |
108 static void BW_RowProc_Opaque( | 108 static void BW_RowProc_Opaque(SkPMColor* SK_RESTRICT dst, |
109 SkPMColor* SK_RESTRICT dst, const void* maskIn, const SkPMColor* SK_REST
RICT src, int count) { | 109 const uint8_t* SK_RESTRICT mask, |
110 const uint8_t* SK_RESTRICT mask = static_cast<const uint8_t*>(maskIn); | 110 const SkPMColor* SK_RESTRICT src, int count) { |
111 int i, octuple = (count + 7) >> 3; | 111 int i, octuple = (count + 7) >> 3; |
112 for (i = 0; i < octuple; ++i) { | 112 for (i = 0; i < octuple; ++i) { |
113 int m = *mask++; | 113 int m = *mask++; |
114 if (m & 0x80) { dst[0] = src[0]; } | 114 if (m & 0x80) { dst[0] = src[0]; } |
115 if (m & 0x40) { dst[1] = src[1]; } | 115 if (m & 0x40) { dst[1] = src[1]; } |
116 if (m & 0x20) { dst[2] = src[2]; } | 116 if (m & 0x20) { dst[2] = src[2]; } |
117 if (m & 0x10) { dst[3] = src[3]; } | 117 if (m & 0x10) { dst[3] = src[3]; } |
118 if (m & 0x08) { dst[4] = src[4]; } | 118 if (m & 0x08) { dst[4] = src[4]; } |
119 if (m & 0x04) { dst[5] = src[5]; } | 119 if (m & 0x04) { dst[5] = src[5]; } |
120 if (m & 0x02) { dst[6] = src[6]; } | 120 if (m & 0x02) { dst[6] = src[6]; } |
121 if (m & 0x01) { dst[7] = src[7]; } | 121 if (m & 0x01) { dst[7] = src[7]; } |
122 src += 8; | 122 src += 8; |
123 dst += 8; | 123 dst += 8; |
124 } | 124 } |
125 count &= 7; | 125 count &= 7; |
126 if (count > 0) { | 126 if (count > 0) { |
127 int m = *mask; | 127 int m = *mask; |
128 do { | 128 do { |
129 if (m & 0x80) { dst[0] = SkPMSrcOver(src[0], dst[0]); } | 129 if (m & 0x80) { dst[0] = SkPMSrcOver(src[0], dst[0]); } |
130 m <<= 1; | 130 m <<= 1; |
131 src += 1; | 131 src += 1; |
132 dst += 1; | 132 dst += 1; |
133 } while (--count > 0); | 133 } while (--count > 0); |
134 } | 134 } |
135 } | 135 } |
136 | 136 |
137 static void A8_RowProc_Blend( | 137 static void A8_RowProc_Blend(SkPMColor* SK_RESTRICT dst, |
138 SkPMColor* SK_RESTRICT dst, const void* maskIn, const SkPMColor* SK_REST
RICT src, int count) { | 138 const uint8_t* SK_RESTRICT mask, |
139 const uint8_t* SK_RESTRICT mask = static_cast<const uint8_t*>(maskIn); | 139 const SkPMColor* SK_RESTRICT src, int count) { |
140 for (int i = 0; i < count; ++i) { | 140 for (int i = 0; i < count; ++i) { |
141 if (mask[i]) { | 141 if (mask[i]) { |
142 dst[i] = SkBlendARGB32(src[i], dst[i], mask[i]); | 142 dst[i] = SkBlendARGB32(src[i], dst[i], mask[i]); |
143 } | 143 } |
144 } | 144 } |
145 } | 145 } |
146 | 146 |
147 // expand the steps that SkAlphaMulQ performs, but this way we can | 147 // expand the steps that SkAlphaMulQ performs, but this way we can |
148 // exand.. add.. combine | 148 // exand.. add.. combine |
149 // instead of | 149 // instead of |
150 // expand..combine add expand..combine | 150 // expand..combine add expand..combine |
151 // | 151 // |
152 #define EXPAND0(v, m, s) ((v) & (m)) * (s) | 152 #define EXPAND0(v, m, s) ((v) & (m)) * (s) |
153 #define EXPAND1(v, m, s) (((v) >> 8) & (m)) * (s) | 153 #define EXPAND1(v, m, s) (((v) >> 8) & (m)) * (s) |
154 #define COMBINE(e0, e1, m) ((((e0) >> 8) & (m)) | ((e1) & ~(m))) | 154 #define COMBINE(e0, e1, m) ((((e0) >> 8) & (m)) | ((e1) & ~(m))) |
155 | 155 |
156 static void A8_RowProc_Opaque( | 156 static void A8_RowProc_Opaque(SkPMColor* SK_RESTRICT dst, |
157 SkPMColor* SK_RESTRICT dst, const void* maskIn, const SkPMColor* SK_REST
RICT src, int count) { | 157 const uint8_t* SK_RESTRICT mask, |
158 const uint8_t* SK_RESTRICT mask = static_cast<const uint8_t*>(maskIn); | 158 const SkPMColor* SK_RESTRICT src, int count) { |
159 for (int i = 0; i < count; ++i) { | 159 for (int i = 0; i < count; ++i) { |
160 int m = mask[i]; | 160 int m = mask[i]; |
161 if (m) { | 161 if (m) { |
162 m += (m >> 7); | 162 m += (m >> 7); |
163 #if 1 | 163 #if 1 |
164 // this is slightly slower than the expand/combine version, but it | 164 // this is slightly slower than the expand/combine version, but it |
165 // is much closer to the old results, so we use it for now to reduce | 165 // is much closer to the old results, so we use it for now to reduce |
166 // rebaselining. | 166 // rebaselining. |
167 dst[i] = SkAlphaMulQ(src[i], m) + SkAlphaMulQ(dst[i], 256 - m); | 167 dst[i] = SkAlphaMulQ(src[i], m) + SkAlphaMulQ(dst[i], 256 - m); |
168 #else | 168 #else |
(...skipping 12 matching lines...) Expand all Loading... |
181 static int upscale31To255(int value) { | 181 static int upscale31To255(int value) { |
182 value = (value << 3) | (value >> 2); | 182 value = (value << 3) | (value >> 2); |
183 return value; | 183 return value; |
184 } | 184 } |
185 | 185 |
186 static int src_alpha_blend(int src, int dst, int srcA, int mask) { | 186 static int src_alpha_blend(int src, int dst, int srcA, int mask) { |
187 | 187 |
188 return dst + SkAlphaMul(src - SkAlphaMul(srcA, dst), mask); | 188 return dst + SkAlphaMul(src - SkAlphaMul(srcA, dst), mask); |
189 } | 189 } |
190 | 190 |
191 static void LCD16_RowProc_Blend( | 191 static void LCD16_RowProc_Blend(SkPMColor* SK_RESTRICT dst, |
192 SkPMColor* SK_RESTRICT dst, const void* maskIn, const SkPMColor* SK_REST
RICT src, int count) { | 192 const uint16_t* SK_RESTRICT mask, |
193 const uint8_t* SK_RESTRICT mask = static_cast<const uint8_t*>(maskIn); | 193 const SkPMColor* SK_RESTRICT src, int count) { |
194 for (int i = 0; i < count; ++i) { | 194 for (int i = 0; i < count; ++i) { |
195 uint16_t m = mask[i]; | 195 uint16_t m = mask[i]; |
196 if (0 == m) { | 196 if (0 == m) { |
197 continue; | 197 continue; |
198 } | 198 } |
199 | 199 |
200 SkPMColor s = src[i]; | 200 SkPMColor s = src[i]; |
201 SkPMColor d = dst[i]; | 201 SkPMColor d = dst[i]; |
202 | 202 |
203 int srcA = SkGetPackedA32(s); | 203 int srcA = SkGetPackedA32(s); |
(...skipping 20 matching lines...) Expand all Loading... |
224 | 224 |
225 // LCD blitting is only supported if the dst is known/required | 225 // LCD blitting is only supported if the dst is known/required |
226 // to be opaque | 226 // to be opaque |
227 dst[i] = SkPackARGB32(0xFF, | 227 dst[i] = SkPackARGB32(0xFF, |
228 src_alpha_blend(srcR, dstR, srcA, maskR), | 228 src_alpha_blend(srcR, dstR, srcA, maskR), |
229 src_alpha_blend(srcG, dstG, srcA, maskG), | 229 src_alpha_blend(srcG, dstG, srcA, maskG), |
230 src_alpha_blend(srcB, dstB, srcA, maskB)); | 230 src_alpha_blend(srcB, dstB, srcA, maskB)); |
231 } | 231 } |
232 } | 232 } |
233 | 233 |
234 static void LCD16_RowProc_Opaque( | 234 static void LCD16_RowProc_Opaque(SkPMColor* SK_RESTRICT dst, |
235 SkPMColor* SK_RESTRICT dst, const void* maskIn, const SkPMColor* SK_REST
RICT src, int count) { | 235 const uint16_t* SK_RESTRICT mask, |
236 const uint8_t* SK_RESTRICT mask = static_cast<const uint8_t*>(maskIn); | 236 const SkPMColor* SK_RESTRICT src, int count) { |
237 for (int i = 0; i < count; ++i) { | 237 for (int i = 0; i < count; ++i) { |
238 uint16_t m = mask[i]; | 238 uint16_t m = mask[i]; |
239 if (0 == m) { | 239 if (0 == m) { |
240 continue; | 240 continue; |
241 } | 241 } |
242 | 242 |
243 SkPMColor s = src[i]; | 243 SkPMColor s = src[i]; |
244 SkPMColor d = dst[i]; | 244 SkPMColor d = dst[i]; |
245 | 245 |
246 int srcR = SkGetPackedR32(s); | 246 int srcR = SkGetPackedR32(s); |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
302 if (flags & kSrcIsOpaque_RowFlag) { | 302 if (flags & kSrcIsOpaque_RowFlag) { |
303 index |= 1; | 303 index |= 1; |
304 } | 304 } |
305 SkASSERT((size_t)index < SK_ARRAY_COUNT(gProcs)); | 305 SkASSERT((size_t)index < SK_ARRAY_COUNT(gProcs)); |
306 return gProcs[index]; | 306 return gProcs[index]; |
307 default: | 307 default: |
308 break; | 308 break; |
309 } | 309 } |
310 return nullptr; | 310 return nullptr; |
311 } | 311 } |
OLD | NEW |