Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(267)

Side by Side Diff: src/opts/SkBlitRow_opts_SSE2.cpp

Issue 1278253003: Sk4px blit mask. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: note overflow Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/opts/SkBlitRow_opts_SSE2.h ('k') | src/opts/SkOpts_neon.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after
294 } 294 }
295 295
296 // Small loop to handle remaining pixels. 296 // Small loop to handle remaining pixels.
297 while (count > 0) { 297 while (count > 0) {
298 *dst = SkBlend32_RGB16(src_expand, *dst, scale); 298 *dst = SkBlend32_RGB16(src_expand, *dst, scale);
299 dst += 1; 299 dst += 1;
300 count--; 300 count--;
301 } 301 }
302 } 302 }
303 303
304 void SkARGB32_A8_BlitMask_SSE2(void* device, size_t dstRB, const void* maskPtr,
305 size_t maskRB, SkColor origColor,
306 int width, int height) {
307 SkPMColor color = SkPreMultiplyColor(origColor);
308 size_t dstOffset = dstRB - (width << 2);
309 size_t maskOffset = maskRB - width;
310 SkPMColor* dst = (SkPMColor *)device;
311 const uint8_t* mask = (const uint8_t*)maskPtr;
312 do {
313 int count = width;
314 if (count >= 4) {
315 while (((size_t)dst & 0x0F) != 0 && (count > 0)) {
316 *dst = SkBlendARGB32(color, *dst, *mask);
317 mask++;
318 dst++;
319 count--;
320 }
321 __m128i *d = reinterpret_cast<__m128i*>(dst);
322 __m128i src_pixel = _mm_set1_epi32(color);
323 while (count >= 4) {
324 // Load 4 dst pixels
325 __m128i dst_pixel = _mm_load_si128(d);
326
327 // Set the alpha value
328 __m128i alpha_wide = _mm_cvtsi32_si128(*reinterpret_cast<const u int32_t*>(mask));
329 alpha_wide = _mm_unpacklo_epi8(alpha_wide, _mm_setzero_si128());
330 alpha_wide = _mm_unpacklo_epi16(alpha_wide, _mm_setzero_si128()) ;
331
332 __m128i result = SkBlendARGB32_SSE2(src_pixel, dst_pixel, alpha_ wide);
333 _mm_store_si128(d, result);
334 // Load the next 4 dst pixels and alphas
335 mask = mask + 4;
336 d++;
337 count -= 4;
338 }
339 dst = reinterpret_cast<SkPMColor*>(d);
340 }
341 while (count > 0) {
342 *dst= SkBlendARGB32(color, *dst, *mask);
343 dst += 1;
344 mask++;
345 count --;
346 }
347 dst = (SkPMColor *)((char*)dst + dstOffset);
348 mask += maskOffset;
349 } while (--height != 0);
350 }
351
352 // The following (left) shifts cause the top 5 bits of the mask components to 304 // The following (left) shifts cause the top 5 bits of the mask components to
353 // line up with the corresponding components in an SkPMColor. 305 // line up with the corresponding components in an SkPMColor.
354 // Note that the mask's RGB16 order may differ from the SkPMColor order. 306 // Note that the mask's RGB16 order may differ from the SkPMColor order.
355 #define SK_R16x5_R32x5_SHIFT (SK_R32_SHIFT - SK_R16_SHIFT - SK_R16_BITS + 5) 307 #define SK_R16x5_R32x5_SHIFT (SK_R32_SHIFT - SK_R16_SHIFT - SK_R16_BITS + 5)
356 #define SK_G16x5_G32x5_SHIFT (SK_G32_SHIFT - SK_G16_SHIFT - SK_G16_BITS + 5) 308 #define SK_G16x5_G32x5_SHIFT (SK_G32_SHIFT - SK_G16_SHIFT - SK_G16_BITS + 5)
357 #define SK_B16x5_B32x5_SHIFT (SK_B32_SHIFT - SK_B16_SHIFT - SK_B16_BITS + 5) 309 #define SK_B16x5_B32x5_SHIFT (SK_B32_SHIFT - SK_B16_SHIFT - SK_B16_BITS + 5)
358 310
359 #if SK_R16x5_R32x5_SHIFT == 0 311 #if SK_R16x5_R32x5_SHIFT == 0
360 #define SkPackedR16x5ToUnmaskedR32x5_SSE2(x) (x) 312 #define SkPackedR16x5ToUnmaskedR32x5_SSE2(x) (x)
361 #elif SK_R16x5_R32x5_SHIFT > 0 313 #elif SK_R16x5_R32x5_SHIFT > 0
(...skipping 796 matching lines...) Expand 10 before | Expand all | Expand 10 after
1158 uint32_t dst_expanded = SkExpand_rgb_16(*dst); 1110 uint32_t dst_expanded = SkExpand_rgb_16(*dst);
1159 dst_expanded = dst_expanded * (SkAlpha255To256(255 - a) >> 3); 1111 dst_expanded = dst_expanded * (SkAlpha255To256(255 - a) >> 3);
1160 // now src and dst expanded are in g:11 r:10 x:1 b:10 1112 // now src and dst expanded are in g:11 r:10 x:1 b:10
1161 *dst = SkCompact_rgb_16((src_expanded + dst_expanded) >> 5); 1113 *dst = SkCompact_rgb_16((src_expanded + dst_expanded) >> 5);
1162 } 1114 }
1163 dst += 1; 1115 dst += 1;
1164 DITHER_INC_X(x); 1116 DITHER_INC_X(x);
1165 } while (--count != 0); 1117 } while (--count != 0);
1166 } 1118 }
1167 } 1119 }
OLDNEW
« no previous file with comments | « src/opts/SkBlitRow_opts_SSE2.h ('k') | src/opts/SkOpts_neon.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698