| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 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 #ifndef Sk4px_DEFINED | 8 #ifndef Sk4px_DEFINED |
| 9 #define Sk4px_DEFINED | 9 #define Sk4px_DEFINED |
| 10 | 10 |
| 11 #include "SkNx.h" | 11 #include "SkNx.h" |
| 12 #include "SkColor.h" | 12 #include "SkColor.h" |
| 13 | 13 |
| 14 // 1, 2 or 4 SkPMColors, generally vectorized. | 14 // 1, 2 or 4 SkPMColors, generally vectorized. |
| 15 class Sk4px : public Sk16b { | 15 class Sk4px : public Sk16b { |
| 16 public: | 16 public: |
| 17 Sk4px(SkPMColor); // Duplicate 4x. | 17 Sk4px(SkAlpha a) : INHERITED(a) {} // Duplicate 16x. |
| 18 Sk4px(const Sk16b& v) : Sk16b(v) {} | 18 Sk4px(SkPMColor); // Duplicate 4x. |
| 19 Sk4px(const Sk16b& v) : INHERITED(v) {} |
| 20 |
| 21 // ARGB argb XYZW xyzw -> AAAA aaaa XXXX xxxx |
| 22 Sk4px alphas() const; |
| 19 | 23 |
| 20 // When loading or storing fewer than 4 SkPMColors, we use the low lanes. | 24 // When loading or storing fewer than 4 SkPMColors, we use the low lanes. |
| 21 static Sk4px Load4(const SkPMColor[4]); | 25 static Sk4px Load4(const SkPMColor[4]); |
| 22 static Sk4px Load2(const SkPMColor[2]); | 26 static Sk4px Load2(const SkPMColor[2]); |
| 23 static Sk4px Load1(const SkPMColor[1]); | 27 static Sk4px Load1(const SkPMColor[1]); |
| 24 | 28 |
| 29 // Ditto for Alphas... Load2Alphas fills the low two lanes of Sk4px. |
| 30 static Sk4px Load4Alphas(const SkAlpha[4]); // AaXx -> AAAA aaaa XXXX xxxx |
| 31 static Sk4px Load2Alphas(const SkAlpha[2]); // Aa -> AAAA aaaa 0000 0000 |
| 32 |
| 25 void store4(SkPMColor[4]) const; | 33 void store4(SkPMColor[4]) const; |
| 26 void store2(SkPMColor[2]) const; | 34 void store2(SkPMColor[2]) const; |
| 27 void store1(SkPMColor[1]) const; | 35 void store1(SkPMColor[1]) const; |
| 28 | 36 |
| 29 // 1, 2, or 4 SkPMColors with 16-bit components. | 37 // 1, 2, or 4 SkPMColors with 16-bit components. |
| 30 // This is most useful as the result of a multiply, e.g. from mulWiden(). | 38 // This is most useful as the result of a multiply, e.g. from mulWiden(). |
| 31 class Wide : public Sk16h { | 39 class Wide : public Sk16h { |
| 32 public: | 40 public: |
| 33 Wide(const Sk16h& v) : Sk16h(v) {} | 41 Wide(const Sk16h& v) : Sk16h(v) {} |
| 34 | 42 |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 fn(Load1(dst), Load1(src)).store1(dst); | 112 fn(Load1(dst), Load1(src)).store1(dst); |
| 105 } | 113 } |
| 106 break; | 114 break; |
| 107 } | 115 } |
| 108 } | 116 } |
| 109 | 117 |
| 110 // As above, but with dst4' = fn(dst4, src4, alpha4). | 118 // As above, but with dst4' = fn(dst4, src4, alpha4). |
| 111 template <typename Fn> | 119 template <typename Fn> |
| 112 static void MapDstSrcAlpha( | 120 static void MapDstSrcAlpha( |
| 113 int count, SkPMColor* dst, const SkPMColor* src, const SkAlpha* a, F
n fn) { | 121 int count, SkPMColor* dst, const SkPMColor* src, const SkAlpha* a, F
n fn) { |
| 114 // TODO: find a terser / faster way to construct Sk16b alphas. | |
| 115 while (count > 0) { | 122 while (count > 0) { |
| 116 if (count >= 8) { | 123 if (count >= 8) { |
| 117 Sk16b alpha0(a[0],a[0],a[0],a[0], a[1],a[1],a[1],a[1], | 124 Sk4px alpha0 = Load4Alphas(a+0), |
| 118 a[2],a[2],a[2],a[2], a[3],a[3],a[3],a[3]), | 125 alpha4 = Load4Alphas(a+4); |
| 119 alpha4(a[4],a[4],a[4],a[4], a[5],a[5],a[5],a[5], | |
| 120 a[6],a[6],a[6],a[6], a[7],a[7],a[7],a[7]); | |
| 121 Sk4px dst0 = fn(Load4(dst+0), Load4(src+0), alpha0), | 126 Sk4px dst0 = fn(Load4(dst+0), Load4(src+0), alpha0), |
| 122 dst4 = fn(Load4(dst+4), Load4(src+4), alpha4); | 127 dst4 = fn(Load4(dst+4), Load4(src+4), alpha4); |
| 123 dst0.store4(dst+0); | 128 dst0.store4(dst+0); |
| 124 dst4.store4(dst+4); | 129 dst4.store4(dst+4); |
| 125 dst += 8; src += 8; a += 8; count -= 8; | 130 dst += 8; src += 8; a += 8; count -= 8; |
| 126 continue; // Keep our stride at 8 pixels as long as possible. | 131 continue; // Keep our stride at 8 pixels as long as possible. |
| 127 } | 132 } |
| 128 SkASSERT(count <= 7); | 133 SkASSERT(count <= 7); |
| 129 if (count >= 4) { | 134 if (count >= 4) { |
| 130 Sk16b alpha(a[0],a[0],a[0],a[0], a[1],a[1],a[1],a[1], | 135 Sk4px alpha = Load4Alphas(a); |
| 131 a[2],a[2],a[2],a[2], a[3],a[3],a[3],a[3]); | |
| 132 fn(Load4(dst), Load4(src), alpha).store4(dst); | 136 fn(Load4(dst), Load4(src), alpha).store4(dst); |
| 133 dst += 4; src += 4; a += 4; count -= 4; | 137 dst += 4; src += 4; a += 4; count -= 4; |
| 134 } | 138 } |
| 135 if (count >= 2) { | 139 if (count >= 2) { |
| 136 Sk16b alpha(a[0],a[0],a[0],a[0], a[1],a[1],a[1],a[1], 0,0,0,0, 0
,0,0,0); | 140 Sk4px alpha = Load2Alphas(a); |
| 137 fn(Load2(dst), Load2(src), alpha).store2(dst); | 141 fn(Load2(dst), Load2(src), alpha).store2(dst); |
| 138 dst += 2; src += 2; a += 2; count -= 2; | 142 dst += 2; src += 2; a += 2; count -= 2; |
| 139 } | 143 } |
| 140 if (count >= 1) { | 144 if (count >= 1) { |
| 141 Sk16b alpha(a[0],a[0],a[0],a[0], 0,0,0,0, 0,0,0,0, 0,0,0,0); | 145 Sk4px alpha(*a); |
| 142 fn(Load1(dst), Load1(src), alpha).store1(dst); | 146 fn(Load1(dst), Load1(src), alpha).store1(dst); |
| 143 } | 147 } |
| 144 break; | 148 break; |
| 145 } | 149 } |
| 146 } | 150 } |
| 147 | 151 |
| 148 private: | 152 private: |
| 149 typedef Sk16b INHERITED; | 153 typedef Sk16b INHERITED; |
| 150 }; | 154 }; |
| 151 | 155 |
| 152 #ifdef SKNX_NO_SIMD | 156 #ifdef SKNX_NO_SIMD |
| 153 #include "../opts/Sk4px_none.h" | 157 #include "../opts/Sk4px_none.h" |
| 154 #else | 158 #else |
| 155 #if SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_SSE2 | 159 #if SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_SSE2 |
| 156 #include "../opts/Sk4px_SSE2.h" | 160 #include "../opts/Sk4px_SSE2.h" |
| 157 #elif defined(SK_ARM_HAS_NEON) | 161 #elif defined(SK_ARM_HAS_NEON) |
| 158 #include "../opts/Sk4px_NEON.h" | 162 #include "../opts/Sk4px_NEON.h" |
| 159 #else | 163 #else |
| 160 #include "../opts/Sk4px_none.h" | 164 #include "../opts/Sk4px_none.h" |
| 161 #endif | 165 #endif |
| 162 #endif | 166 #endif |
| 163 | 167 |
| 164 #endif//Sk4px_DEFINED | 168 #endif//Sk4px_DEFINED |
| OLD | NEW |