epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2011 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
reed@google.com | 58af9a6 | 2011-10-12 13:43:52 +0000 | [diff] [blame] | 7 | |
reed@android.com | c4cae85 | 2009-09-23 15:06:10 +0000 | [diff] [blame] | 8 | #include "SkBlitRow.h" |
reed@google.com | 58af9a6 | 2011-10-12 13:43:52 +0000 | [diff] [blame] | 9 | #include "SkBlitMask.h" |
reed@android.com | c4cae85 | 2009-09-23 15:06:10 +0000 | [diff] [blame] | 10 | #include "SkColorPriv.h" |
mtklein | 4a37d08 | 2015-09-10 10:38:02 -0700 | [diff] [blame] | 11 | #include "SkOpts.h" |
reed@android.com | c4cae85 | 2009-09-23 15:06:10 +0000 | [diff] [blame] | 12 | #include "SkUtils.h" |
| 13 | |
djsollen@google.com | 57f4969 | 2011-02-23 20:46:31 +0000 | [diff] [blame] | 14 | #define UNROLL |
| 15 | |
reed@android.com | c4cae85 | 2009-09-23 15:06:10 +0000 | [diff] [blame] | 16 | static void S32_Opaque_BlitRow32(SkPMColor* SK_RESTRICT dst, |
| 17 | const SkPMColor* SK_RESTRICT src, |
| 18 | int count, U8CPU alpha) { |
| 19 | SkASSERT(255 == alpha); |
mtklein | 58fd2c8 | 2015-07-27 11:08:28 -0700 | [diff] [blame] | 20 | memcpy(dst, src, count * 4); |
reed@android.com | c4cae85 | 2009-09-23 15:06:10 +0000 | [diff] [blame] | 21 | } |
| 22 | |
| 23 | static void S32_Blend_BlitRow32(SkPMColor* SK_RESTRICT dst, |
| 24 | const SkPMColor* SK_RESTRICT src, |
| 25 | int count, U8CPU alpha) { |
| 26 | SkASSERT(alpha <= 255); |
| 27 | if (count > 0) { |
| 28 | unsigned src_scale = SkAlpha255To256(alpha); |
djsollen@google.com | 57f4969 | 2011-02-23 20:46:31 +0000 | [diff] [blame] | 29 | |
| 30 | #ifdef UNROLL |
| 31 | if (count & 1) { |
lsalzman | 40254c2 | 2016-08-05 11:48:45 -0700 | [diff] [blame^] | 32 | *dst = SkPMLerp(*src, *dst, src_scale); |
| 33 | src += 1; |
djsollen@google.com | 57f4969 | 2011-02-23 20:46:31 +0000 | [diff] [blame] | 34 | dst += 1; |
| 35 | count -= 1; |
| 36 | } |
| 37 | |
| 38 | const SkPMColor* SK_RESTRICT srcEnd = src + count; |
| 39 | while (src != srcEnd) { |
lsalzman | 40254c2 | 2016-08-05 11:48:45 -0700 | [diff] [blame^] | 40 | *dst = SkPMLerp(*src, *dst, src_scale); |
| 41 | src += 1; |
djsollen@google.com | 57f4969 | 2011-02-23 20:46:31 +0000 | [diff] [blame] | 42 | dst += 1; |
lsalzman | 40254c2 | 2016-08-05 11:48:45 -0700 | [diff] [blame^] | 43 | *dst = SkPMLerp(*src, *dst, src_scale); |
| 44 | src += 1; |
djsollen@google.com | 57f4969 | 2011-02-23 20:46:31 +0000 | [diff] [blame] | 45 | dst += 1; |
| 46 | } |
| 47 | #else |
reed@android.com | c4cae85 | 2009-09-23 15:06:10 +0000 | [diff] [blame] | 48 | do { |
lsalzman | 40254c2 | 2016-08-05 11:48:45 -0700 | [diff] [blame^] | 49 | *dst = SkPMLerp(*src, *dst, src_scale); |
reed@android.com | c4cae85 | 2009-09-23 15:06:10 +0000 | [diff] [blame] | 50 | src += 1; |
| 51 | dst += 1; |
| 52 | } while (--count > 0); |
djsollen@google.com | 57f4969 | 2011-02-23 20:46:31 +0000 | [diff] [blame] | 53 | #endif |
reed@android.com | c4cae85 | 2009-09-23 15:06:10 +0000 | [diff] [blame] | 54 | } |
| 55 | } |
| 56 | |
reed@android.com | c4cae85 | 2009-09-23 15:06:10 +0000 | [diff] [blame] | 57 | static void S32A_Blend_BlitRow32(SkPMColor* SK_RESTRICT dst, |
| 58 | const SkPMColor* SK_RESTRICT src, |
| 59 | int count, U8CPU alpha) { |
| 60 | SkASSERT(alpha <= 255); |
| 61 | if (count > 0) { |
djsollen@google.com | 57f4969 | 2011-02-23 20:46:31 +0000 | [diff] [blame] | 62 | #ifdef UNROLL |
| 63 | if (count & 1) { |
| 64 | *dst = SkBlendARGB32(*(src++), *dst, alpha); |
| 65 | dst += 1; |
| 66 | count -= 1; |
| 67 | } |
| 68 | |
| 69 | const SkPMColor* SK_RESTRICT srcEnd = src + count; |
| 70 | while (src != srcEnd) { |
| 71 | *dst = SkBlendARGB32(*(src++), *dst, alpha); |
| 72 | dst += 1; |
| 73 | *dst = SkBlendARGB32(*(src++), *dst, alpha); |
| 74 | dst += 1; |
| 75 | } |
| 76 | #else |
reed@android.com | c4cae85 | 2009-09-23 15:06:10 +0000 | [diff] [blame] | 77 | do { |
| 78 | *dst = SkBlendARGB32(*src, *dst, alpha); |
| 79 | src += 1; |
| 80 | dst += 1; |
| 81 | } while (--count > 0); |
djsollen@google.com | 57f4969 | 2011-02-23 20:46:31 +0000 | [diff] [blame] | 82 | #endif |
reed@android.com | c4cae85 | 2009-09-23 15:06:10 +0000 | [diff] [blame] | 83 | } |
| 84 | } |
| 85 | |
| 86 | /////////////////////////////////////////////////////////////////////////////// |
| 87 | |
| 88 | static const SkBlitRow::Proc32 gDefault_Procs32[] = { |
| 89 | S32_Opaque_BlitRow32, |
| 90 | S32_Blend_BlitRow32, |
mtklein | b4a7dc9 | 2016-03-23 06:29:12 -0700 | [diff] [blame] | 91 | nullptr, |
reed@android.com | c4cae85 | 2009-09-23 15:06:10 +0000 | [diff] [blame] | 92 | S32A_Blend_BlitRow32 |
| 93 | }; |
| 94 | |
| 95 | SkBlitRow::Proc32 SkBlitRow::Factory32(unsigned flags) { |
| 96 | SkASSERT(flags < SK_ARRAY_COUNT(gDefault_Procs32)); |
| 97 | // just so we don't crash |
| 98 | flags &= kFlags32_Mask; |
reed@google.com | 981d479 | 2011-03-09 12:55:47 +0000 | [diff] [blame] | 99 | |
mtklein | b4a7dc9 | 2016-03-23 06:29:12 -0700 | [diff] [blame] | 100 | if (flags == 2) { |
| 101 | // S32A_Opaque_BlitRow32 has been ported to SkOpts, but not the others yet. |
| 102 | return SkOpts::blit_row_s32a_opaque; |
| 103 | } |
| 104 | |
senorblanco@chromium.org | 9272761 | 2009-11-04 20:51:06 +0000 | [diff] [blame] | 105 | SkBlitRow::Proc32 proc = PlatformProcs32(flags); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 106 | if (nullptr == proc) { |
reed@android.com | c4cae85 | 2009-09-23 15:06:10 +0000 | [diff] [blame] | 107 | proc = gDefault_Procs32[flags]; |
| 108 | } |
| 109 | SkASSERT(proc); |
| 110 | return proc; |
| 111 | } |
| 112 | |
mtklein | 95cc012 | 2015-04-27 15:11:01 -0700 | [diff] [blame] | 113 | void SkBlitRow::Color32(SkPMColor dst[], const SkPMColor src[], int count, SkPMColor color) { |
mtklein | afe2ffb | 2015-04-17 11:00:54 -0700 | [diff] [blame] | 114 | switch (SkGetPackedA32(color)) { |
| 115 | case 0: memmove(dst, src, count * sizeof(SkPMColor)); return; |
| 116 | case 255: sk_memset32(dst, color, count); return; |
| 117 | } |
mtklein | 4a37d08 | 2015-09-10 10:38:02 -0700 | [diff] [blame] | 118 | return SkOpts::blit_row_color32(dst, src, count, color); |
reed@android.com | c4cae85 | 2009-09-23 15:06:10 +0000 | [diff] [blame] | 119 | } |