Jason Sams | cf9ea9f | 2012-09-23 17:00:54 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2012 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | |
Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 18 | #include "rsCpuIntrinsic.h" |
| 19 | #include "rsCpuIntrinsicInlines.h" |
Jason Sams | cf9ea9f | 2012-09-23 17:00:54 -0700 | [diff] [blame] | 20 | |
| 21 | using namespace android; |
| 22 | using namespace android::renderscript; |
| 23 | |
Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 24 | namespace android { |
| 25 | namespace renderscript { |
| 26 | |
| 27 | |
| 28 | class RsdCpuScriptIntrinsicBlend : public RsdCpuScriptIntrinsic { |
| 29 | public: |
| 30 | virtual void populateScript(Script *); |
| 31 | |
| 32 | virtual ~RsdCpuScriptIntrinsicBlend(); |
Jason Sams | c905efd | 2012-11-26 15:20:18 -0800 | [diff] [blame] | 33 | RsdCpuScriptIntrinsicBlend(RsdCpuReferenceImpl *ctx, const Script *s, const Element *e); |
Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 34 | |
| 35 | protected: |
Chris Wailes | 9ed7910 | 2014-07-25 15:53:28 -0700 | [diff] [blame] | 36 | static void kernel(const RsExpandKernelParams *p, uint32_t xstart, |
| 37 | uint32_t xend, uint32_t outstep); |
Jason Sams | cf9ea9f | 2012-09-23 17:00:54 -0700 | [diff] [blame] | 38 | }; |
| 39 | |
Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 40 | } |
| 41 | } |
| 42 | |
Jason Sams | cf9ea9f | 2012-09-23 17:00:54 -0700 | [diff] [blame] | 43 | |
Jason Sams | cf9ea9f | 2012-09-23 17:00:54 -0700 | [diff] [blame] | 44 | enum { |
| 45 | BLEND_CLEAR = 0, |
| 46 | BLEND_SRC = 1, |
| 47 | BLEND_DST = 2, |
| 48 | BLEND_SRC_OVER = 3, |
| 49 | BLEND_DST_OVER = 4, |
| 50 | BLEND_SRC_IN = 5, |
| 51 | BLEND_DST_IN = 6, |
| 52 | BLEND_SRC_OUT = 7, |
| 53 | BLEND_DST_OUT = 8, |
| 54 | BLEND_SRC_ATOP = 9, |
| 55 | BLEND_DST_ATOP = 10, |
| 56 | BLEND_XOR = 11, |
| 57 | |
| 58 | BLEND_NORMAL = 12, |
| 59 | BLEND_AVERAGE = 13, |
| 60 | BLEND_MULTIPLY = 14, |
| 61 | BLEND_SCREEN = 15, |
| 62 | BLEND_DARKEN = 16, |
| 63 | BLEND_LIGHTEN = 17, |
| 64 | BLEND_OVERLAY = 18, |
| 65 | BLEND_HARDLIGHT = 19, |
| 66 | BLEND_SOFTLIGHT = 20, |
| 67 | BLEND_DIFFERENCE = 21, |
| 68 | BLEND_NEGATION = 22, |
| 69 | BLEND_EXCLUSION = 23, |
| 70 | BLEND_COLOR_DODGE = 24, |
| 71 | BLEND_INVERSE_COLOR_DODGE = 25, |
| 72 | BLEND_SOFT_DODGE = 26, |
| 73 | BLEND_COLOR_BURN = 27, |
| 74 | BLEND_INVERSE_COLOR_BURN = 28, |
| 75 | BLEND_SOFT_BURN = 29, |
| 76 | BLEND_REFLECT = 30, |
| 77 | BLEND_GLOW = 31, |
| 78 | BLEND_FREEZE = 32, |
| 79 | BLEND_HEAT = 33, |
| 80 | BLEND_ADD = 34, |
| 81 | BLEND_SUBTRACT = 35, |
| 82 | BLEND_STAMP = 36, |
| 83 | BLEND_RED = 37, |
| 84 | BLEND_GREEN = 38, |
| 85 | BLEND_BLUE = 39, |
| 86 | BLEND_HUE = 40, |
| 87 | BLEND_SATURATION = 41, |
| 88 | BLEND_COLOR = 42, |
| 89 | BLEND_LUMINOSITY = 43 |
| 90 | }; |
| 91 | |
Jason Sams | 074424a | 2014-05-22 13:30:03 -0700 | [diff] [blame] | 92 | #if defined(ARCH_ARM_USE_INTRINSICS) |
Simon Hosie | 5d06919 | 2014-02-19 16:33:45 -0800 | [diff] [blame] | 93 | extern "C" int rsdIntrinsicBlend_K(uchar4 *out, uchar4 const *in, int slot, |
| 94 | uint32_t xstart, uint32_t xend); |
Rose, James | 7b7060c | 2014-04-22 12:08:06 +0800 | [diff] [blame] | 95 | #endif |
| 96 | |
| 97 | #if defined(ARCH_X86_HAVE_SSSE3) |
| 98 | extern "C" void rsdIntrinsicBlendSrcOver_K(void *dst, const void *src, uint32_t count8); |
| 99 | extern "C" void rsdIntrinsicBlendDstOver_K(void *dst, const void *src, uint32_t count8); |
| 100 | extern "C" void rsdIntrinsicBlendSrcIn_K(void *dst, const void *src, uint32_t count8); |
| 101 | extern "C" void rsdIntrinsicBlendDstIn_K(void *dst, const void *src, uint32_t count8); |
| 102 | extern "C" void rsdIntrinsicBlendSrcOut_K(void *dst, const void *src, uint32_t count8); |
| 103 | extern "C" void rsdIntrinsicBlendDstOut_K(void *dst, const void *src, uint32_t count8); |
| 104 | extern "C" void rsdIntrinsicBlendSrcAtop_K(void *dst, const void *src, uint32_t count8); |
| 105 | extern "C" void rsdIntrinsicBlendDstAtop_K(void *dst, const void *src, uint32_t count8); |
| 106 | extern "C" void rsdIntrinsicBlendXor_K(void *dst, const void *src, uint32_t count8); |
| 107 | extern "C" void rsdIntrinsicBlendMultiply_K(void *dst, const void *src, uint32_t count8); |
| 108 | extern "C" void rsdIntrinsicBlendAdd_K(void *dst, const void *src, uint32_t count8); |
| 109 | extern "C" void rsdIntrinsicBlendSub_K(void *dst, const void *src, uint32_t count8); |
| 110 | #endif |
Jason Sams | fa17cda | 2012-09-26 18:33:58 -0700 | [diff] [blame] | 111 | |
Chris Wailes | 80ef693 | 2014-07-08 11:22:18 -0700 | [diff] [blame] | 112 | void RsdCpuScriptIntrinsicBlend::kernel(const RsExpandKernelParams *p, |
Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 113 | uint32_t xstart, uint32_t xend, |
Chris Wailes | 9ed7910 | 2014-07-25 15:53:28 -0700 | [diff] [blame] | 114 | uint32_t outstep) { |
Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 115 | RsdCpuScriptIntrinsicBlend *cp = (RsdCpuScriptIntrinsicBlend *)p->usr; |
Tim Murray | 36889a0 | 2012-09-24 14:52:48 -0700 | [diff] [blame] | 116 | |
| 117 | // instep/outstep can be ignored--sizeof(uchar4) known at compile time |
Jason Sams | cf9ea9f | 2012-09-23 17:00:54 -0700 | [diff] [blame] | 118 | uchar4 *out = (uchar4 *)p->out; |
Chris Wailes | f371213 | 2014-07-16 15:18:30 -0700 | [diff] [blame] | 119 | uchar4 *in = (uchar4 *)p->ins[0]; |
Jason Sams | cf9ea9f | 2012-09-23 17:00:54 -0700 | [diff] [blame] | 120 | uint32_t x1 = xstart; |
| 121 | uint32_t x2 = xend; |
| 122 | |
Jason Sams | 074424a | 2014-05-22 13:30:03 -0700 | [diff] [blame] | 123 | #if defined(ARCH_ARM_USE_INTRINSICS) && !defined(ARCH_ARM64_USE_INTRINSICS) |
Simon Hosie | 5d06919 | 2014-02-19 16:33:45 -0800 | [diff] [blame] | 124 | if (gArchUseSIMD) { |
| 125 | if (rsdIntrinsicBlend_K(out, in, p->slot, x1, x2) >= 0) |
| 126 | return; |
| 127 | } |
| 128 | #endif |
Jason Sams | cf9ea9f | 2012-09-23 17:00:54 -0700 | [diff] [blame] | 129 | switch (p->slot) { |
| 130 | case BLEND_CLEAR: |
| 131 | for (;x1 < x2; x1++, out++) { |
| 132 | *out = 0; |
| 133 | } |
| 134 | break; |
| 135 | case BLEND_SRC: |
| 136 | for (;x1 < x2; x1++, out++, in++) { |
Tim Murray | 36889a0 | 2012-09-24 14:52:48 -0700 | [diff] [blame] | 137 | *out = *in; |
Jason Sams | cf9ea9f | 2012-09-23 17:00:54 -0700 | [diff] [blame] | 138 | } |
| 139 | break; |
Tim Murray | 36889a0 | 2012-09-24 14:52:48 -0700 | [diff] [blame] | 140 | //BLEND_DST is a NOP |
Jason Sams | cf9ea9f | 2012-09-23 17:00:54 -0700 | [diff] [blame] | 141 | case BLEND_DST: |
Tim Murray | 36889a0 | 2012-09-24 14:52:48 -0700 | [diff] [blame] | 142 | break; |
| 143 | case BLEND_SRC_OVER: |
Rose, James | 7b7060c | 2014-04-22 12:08:06 +0800 | [diff] [blame] | 144 | #if defined(ARCH_X86_HAVE_SSSE3) |
| 145 | if (gArchUseSIMD) { |
| 146 | if ((x1 + 8) < x2) { |
| 147 | uint32_t len = (x2 - x1) >> 3; |
| 148 | rsdIntrinsicBlendSrcOver_K(out, in, len); |
| 149 | x1 += len << 3; |
| 150 | out += len << 3; |
| 151 | in += len << 3; |
| 152 | } |
| 153 | } |
| 154 | #endif |
Jason Sams | cf9ea9f | 2012-09-23 17:00:54 -0700 | [diff] [blame] | 155 | for (;x1 < x2; x1++, out++, in++) { |
Tim Murray | 36889a0 | 2012-09-24 14:52:48 -0700 | [diff] [blame] | 156 | short4 in_s = convert_short4(*in); |
| 157 | short4 out_s = convert_short4(*out); |
Tim Murray | 0b575de | 2013-03-15 15:56:43 -0700 | [diff] [blame] | 158 | in_s = in_s + ((out_s * (short4)(255 - in_s.w)) >> (short4)8); |
Tim Murray | 36889a0 | 2012-09-24 14:52:48 -0700 | [diff] [blame] | 159 | *out = convert_uchar4(in_s); |
Jason Sams | cf9ea9f | 2012-09-23 17:00:54 -0700 | [diff] [blame] | 160 | } |
| 161 | break; |
Tim Murray | 36889a0 | 2012-09-24 14:52:48 -0700 | [diff] [blame] | 162 | case BLEND_DST_OVER: |
Rose, James | 7b7060c | 2014-04-22 12:08:06 +0800 | [diff] [blame] | 163 | #if defined(ARCH_X86_HAVE_SSSE3) |
| 164 | if (gArchUseSIMD) { |
| 165 | if ((x1 + 8) < x2) { |
| 166 | uint32_t len = (x2 - x1) >> 3; |
| 167 | rsdIntrinsicBlendDstOver_K(out, in, len); |
| 168 | x1 += len << 3; |
| 169 | out += len << 3; |
| 170 | in += len << 3; |
| 171 | } |
| 172 | } |
| 173 | #endif |
Tim Murray | 36889a0 | 2012-09-24 14:52:48 -0700 | [diff] [blame] | 174 | for (;x1 < x2; x1++, out++, in++) { |
| 175 | short4 in_s = convert_short4(*in); |
| 176 | short4 out_s = convert_short4(*out); |
Tim Murray | 0b575de | 2013-03-15 15:56:43 -0700 | [diff] [blame] | 177 | in_s = out_s + ((in_s * (short4)(255 - out_s.w)) >> (short4)8); |
Tim Murray | 36889a0 | 2012-09-24 14:52:48 -0700 | [diff] [blame] | 178 | *out = convert_uchar4(in_s); |
| 179 | } |
| 180 | break; |
| 181 | case BLEND_SRC_IN: |
Rose, James | 7b7060c | 2014-04-22 12:08:06 +0800 | [diff] [blame] | 182 | #if defined(ARCH_X86_HAVE_SSSE3) |
| 183 | if (gArchUseSIMD) { |
| 184 | if ((x1 + 8) < x2) { |
| 185 | uint32_t len = (x2 - x1) >> 3; |
| 186 | rsdIntrinsicBlendSrcIn_K(out, in, len); |
| 187 | x1 += len << 3; |
| 188 | out += len << 3; |
| 189 | in += len << 3; |
| 190 | } |
| 191 | } |
| 192 | #endif |
Tim Murray | 36889a0 | 2012-09-24 14:52:48 -0700 | [diff] [blame] | 193 | for (;x1 < x2; x1++, out++, in++) { |
| 194 | short4 in_s = convert_short4(*in); |
Tim Murray | 0b575de | 2013-03-15 15:56:43 -0700 | [diff] [blame] | 195 | in_s = (in_s * out->w) >> (short4)8; |
Tim Murray | 36889a0 | 2012-09-24 14:52:48 -0700 | [diff] [blame] | 196 | *out = convert_uchar4(in_s); |
| 197 | } |
| 198 | break; |
| 199 | case BLEND_DST_IN: |
Rose, James | 7b7060c | 2014-04-22 12:08:06 +0800 | [diff] [blame] | 200 | #if defined(ARCH_X86_HAVE_SSSE3) |
| 201 | if (gArchUseSIMD) { |
| 202 | if ((x1 + 8) < x2) { |
| 203 | uint32_t len = (x2 - x1) >> 3; |
| 204 | rsdIntrinsicBlendDstIn_K(out, in, len); |
| 205 | x1 += len << 3; |
| 206 | out += len << 3; |
| 207 | in += len << 3; |
| 208 | } |
| 209 | } |
| 210 | #endif |
Tim Murray | 36889a0 | 2012-09-24 14:52:48 -0700 | [diff] [blame] | 211 | for (;x1 < x2; x1++, out++, in++) { |
| 212 | short4 out_s = convert_short4(*out); |
Tim Murray | 0b575de | 2013-03-15 15:56:43 -0700 | [diff] [blame] | 213 | out_s = (out_s * in->w) >> (short4)8; |
Tim Murray | 36889a0 | 2012-09-24 14:52:48 -0700 | [diff] [blame] | 214 | *out = convert_uchar4(out_s); |
| 215 | } |
| 216 | break; |
| 217 | case BLEND_SRC_OUT: |
Rose, James | 7b7060c | 2014-04-22 12:08:06 +0800 | [diff] [blame] | 218 | #if defined(ARCH_X86_HAVE_SSSE3) |
| 219 | if (gArchUseSIMD) { |
| 220 | if ((x1 + 8) < x2) { |
| 221 | uint32_t len = (x2 - x1) >> 3; |
| 222 | rsdIntrinsicBlendSrcOut_K(out, in, len); |
| 223 | x1 += len << 3; |
| 224 | out += len << 3; |
| 225 | in += len << 3; |
| 226 | } |
| 227 | } |
| 228 | #endif |
Tim Murray | 36889a0 | 2012-09-24 14:52:48 -0700 | [diff] [blame] | 229 | for (;x1 < x2; x1++, out++, in++) { |
| 230 | short4 in_s = convert_short4(*in); |
Tim Murray | 0b575de | 2013-03-15 15:56:43 -0700 | [diff] [blame] | 231 | in_s = (in_s * (short4)(255 - out->w)) >> (short4)8; |
Tim Murray | 36889a0 | 2012-09-24 14:52:48 -0700 | [diff] [blame] | 232 | *out = convert_uchar4(in_s); |
| 233 | } |
| 234 | break; |
| 235 | case BLEND_DST_OUT: |
Rose, James | 7b7060c | 2014-04-22 12:08:06 +0800 | [diff] [blame] | 236 | #if defined(ARCH_X86_HAVE_SSSE3) |
| 237 | if (gArchUseSIMD) { |
| 238 | if ((x1 + 8) < x2) { |
| 239 | uint32_t len = (x2 - x1) >> 3; |
| 240 | rsdIntrinsicBlendDstOut_K(out, in, len); |
| 241 | x1 += len << 3; |
| 242 | out += len << 3; |
| 243 | in += len << 3; |
| 244 | } |
| 245 | } |
| 246 | #endif |
Tim Murray | 36889a0 | 2012-09-24 14:52:48 -0700 | [diff] [blame] | 247 | for (;x1 < x2; x1++, out++, in++) { |
| 248 | short4 out_s = convert_short4(*out); |
Tim Murray | 0b575de | 2013-03-15 15:56:43 -0700 | [diff] [blame] | 249 | out_s = (out_s * (short4)(255 - in->w)) >> (short4)8; |
Tim Murray | 36889a0 | 2012-09-24 14:52:48 -0700 | [diff] [blame] | 250 | *out = convert_uchar4(out_s); |
| 251 | } |
| 252 | break; |
| 253 | case BLEND_SRC_ATOP: |
Rose, James | 7b7060c | 2014-04-22 12:08:06 +0800 | [diff] [blame] | 254 | #if defined(ARCH_X86_HAVE_SSSE3) |
| 255 | if (gArchUseSIMD) { |
| 256 | if ((x1 + 8) < x2) { |
| 257 | uint32_t len = (x2 - x1) >> 3; |
| 258 | rsdIntrinsicBlendSrcAtop_K(out, in, len); |
| 259 | x1 += len << 3; |
| 260 | out += len << 3; |
| 261 | in += len << 3; |
| 262 | } |
| 263 | } |
| 264 | #endif |
Tim Murray | 36889a0 | 2012-09-24 14:52:48 -0700 | [diff] [blame] | 265 | for (;x1 < x2; x1++, out++, in++) { |
| 266 | short4 in_s = convert_short4(*in); |
| 267 | short4 out_s = convert_short4(*out); |
Tim Murray | 0b575de | 2013-03-15 15:56:43 -0700 | [diff] [blame] | 268 | out_s.xyz = ((in_s.xyz * out_s.w) + |
| 269 | (out_s.xyz * ((short3)255 - (short3)in_s.w))) >> (short3)8; |
Tim Murray | 36889a0 | 2012-09-24 14:52:48 -0700 | [diff] [blame] | 270 | *out = convert_uchar4(out_s); |
| 271 | } |
| 272 | break; |
| 273 | case BLEND_DST_ATOP: |
Rose, James | 7b7060c | 2014-04-22 12:08:06 +0800 | [diff] [blame] | 274 | #if defined(ARCH_X86_HAVE_SSSE3) |
| 275 | if (gArchUseSIMD) { |
| 276 | if ((x1 + 8) < x2) { |
| 277 | uint32_t len = (x2 - x1) >> 3; |
| 278 | rsdIntrinsicBlendDstAtop_K(out, in, len); |
| 279 | x1 += len << 3; |
| 280 | out += len << 3; |
| 281 | in += len << 3; |
| 282 | } |
| 283 | } |
| 284 | #endif |
Tim Murray | 36889a0 | 2012-09-24 14:52:48 -0700 | [diff] [blame] | 285 | for (;x1 < x2; x1++, out++, in++) { |
| 286 | short4 in_s = convert_short4(*in); |
| 287 | short4 out_s = convert_short4(*out); |
Tim Murray | 0b575de | 2013-03-15 15:56:43 -0700 | [diff] [blame] | 288 | out_s.xyz = ((out_s.xyz * in_s.w) + |
| 289 | (in_s.xyz * ((short3)255 - (short3)out_s.w))) >> (short3)8; |
Tim Murray | 36889a0 | 2012-09-24 14:52:48 -0700 | [diff] [blame] | 290 | *out = convert_uchar4(out_s); |
| 291 | } |
| 292 | break; |
| 293 | case BLEND_XOR: |
Rose, James | 7b7060c | 2014-04-22 12:08:06 +0800 | [diff] [blame] | 294 | #if defined(ARCH_X86_HAVE_SSSE3) |
| 295 | if (gArchUseSIMD) { |
| 296 | if ((x1 + 8) < x2) { |
| 297 | uint32_t len = (x2 - x1) >> 3; |
| 298 | rsdIntrinsicBlendXor_K(out, in, len); |
| 299 | x1 += len << 3; |
| 300 | out += len << 3; |
| 301 | in += len << 3; |
| 302 | } |
| 303 | } |
| 304 | #endif |
Tim Murray | 36889a0 | 2012-09-24 14:52:48 -0700 | [diff] [blame] | 305 | for (;x1 < x2; x1++, out++, in++) { |
| 306 | *out = *in ^ *out; |
| 307 | } |
| 308 | break; |
| 309 | case BLEND_NORMAL: |
| 310 | ALOGE("Called unimplemented blend intrinsic BLEND_NORMAL"); |
| 311 | rsAssert(false); |
| 312 | break; |
| 313 | case BLEND_AVERAGE: |
| 314 | ALOGE("Called unimplemented blend intrinsic BLEND_AVERAGE"); |
| 315 | rsAssert(false); |
| 316 | break; |
| 317 | case BLEND_MULTIPLY: |
Rose, James | 7b7060c | 2014-04-22 12:08:06 +0800 | [diff] [blame] | 318 | #if defined(ARCH_X86_HAVE_SSSE3) |
| 319 | if (gArchUseSIMD) { |
| 320 | if ((x1 + 8) < x2) { |
| 321 | uint32_t len = (x2 - x1) >> 3; |
| 322 | rsdIntrinsicBlendMultiply_K(out, in, len); |
| 323 | x1 += len << 3; |
| 324 | out += len << 3; |
| 325 | in += len << 3; |
| 326 | } |
| 327 | } |
| 328 | #endif |
Tim Murray | 36889a0 | 2012-09-24 14:52:48 -0700 | [diff] [blame] | 329 | for (;x1 < x2; x1++, out++, in++) { |
| 330 | *out = convert_uchar4((convert_short4(*in) * convert_short4(*out)) |
| 331 | >> (short4)8); |
| 332 | } |
| 333 | break; |
| 334 | case BLEND_SCREEN: |
| 335 | ALOGE("Called unimplemented blend intrinsic BLEND_SCREEN"); |
| 336 | rsAssert(false); |
| 337 | break; |
| 338 | case BLEND_DARKEN: |
| 339 | ALOGE("Called unimplemented blend intrinsic BLEND_DARKEN"); |
| 340 | rsAssert(false); |
| 341 | break; |
| 342 | case BLEND_LIGHTEN: |
| 343 | ALOGE("Called unimplemented blend intrinsic BLEND_LIGHTEN"); |
| 344 | rsAssert(false); |
| 345 | break; |
| 346 | case BLEND_OVERLAY: |
| 347 | ALOGE("Called unimplemented blend intrinsic BLEND_OVERLAY"); |
| 348 | rsAssert(false); |
| 349 | break; |
| 350 | case BLEND_HARDLIGHT: |
| 351 | ALOGE("Called unimplemented blend intrinsic BLEND_HARDLIGHT"); |
| 352 | rsAssert(false); |
| 353 | break; |
| 354 | case BLEND_SOFTLIGHT: |
| 355 | ALOGE("Called unimplemented blend intrinsic BLEND_SOFTLIGHT"); |
| 356 | rsAssert(false); |
| 357 | break; |
| 358 | case BLEND_DIFFERENCE: |
| 359 | ALOGE("Called unimplemented blend intrinsic BLEND_DIFFERENCE"); |
| 360 | rsAssert(false); |
| 361 | break; |
| 362 | case BLEND_NEGATION: |
| 363 | ALOGE("Called unimplemented blend intrinsic BLEND_NEGATION"); |
| 364 | rsAssert(false); |
| 365 | break; |
| 366 | case BLEND_EXCLUSION: |
| 367 | ALOGE("Called unimplemented blend intrinsic BLEND_EXCLUSION"); |
| 368 | rsAssert(false); |
| 369 | break; |
| 370 | case BLEND_COLOR_DODGE: |
| 371 | ALOGE("Called unimplemented blend intrinsic BLEND_COLOR_DODGE"); |
| 372 | rsAssert(false); |
| 373 | break; |
| 374 | case BLEND_INVERSE_COLOR_DODGE: |
| 375 | ALOGE("Called unimplemented blend intrinsic BLEND_INVERSE_COLOR_DODGE"); |
| 376 | rsAssert(false); |
| 377 | break; |
| 378 | case BLEND_SOFT_DODGE: |
| 379 | ALOGE("Called unimplemented blend intrinsic BLEND_SOFT_DODGE"); |
| 380 | rsAssert(false); |
| 381 | break; |
| 382 | case BLEND_COLOR_BURN: |
| 383 | ALOGE("Called unimplemented blend intrinsic BLEND_COLOR_BURN"); |
| 384 | rsAssert(false); |
| 385 | break; |
| 386 | case BLEND_INVERSE_COLOR_BURN: |
| 387 | ALOGE("Called unimplemented blend intrinsic BLEND_INVERSE_COLOR_BURN"); |
| 388 | rsAssert(false); |
| 389 | break; |
| 390 | case BLEND_SOFT_BURN: |
| 391 | ALOGE("Called unimplemented blend intrinsic BLEND_SOFT_BURN"); |
| 392 | rsAssert(false); |
| 393 | break; |
| 394 | case BLEND_REFLECT: |
| 395 | ALOGE("Called unimplemented blend intrinsic BLEND_REFLECT"); |
| 396 | rsAssert(false); |
| 397 | break; |
| 398 | case BLEND_GLOW: |
| 399 | ALOGE("Called unimplemented blend intrinsic BLEND_GLOW"); |
| 400 | rsAssert(false); |
| 401 | break; |
| 402 | case BLEND_FREEZE: |
| 403 | ALOGE("Called unimplemented blend intrinsic BLEND_FREEZE"); |
| 404 | rsAssert(false); |
| 405 | break; |
| 406 | case BLEND_HEAT: |
| 407 | ALOGE("Called unimplemented blend intrinsic BLEND_HEAT"); |
| 408 | rsAssert(false); |
| 409 | break; |
| 410 | case BLEND_ADD: |
Rose, James | 7b7060c | 2014-04-22 12:08:06 +0800 | [diff] [blame] | 411 | #if defined(ARCH_X86_HAVE_SSSE3) |
| 412 | if (gArchUseSIMD) { |
| 413 | if((x1 + 8) < x2) { |
| 414 | uint32_t len = (x2 - x1) >> 3; |
| 415 | rsdIntrinsicBlendAdd_K(out, in, len); |
| 416 | x1 += len << 3; |
| 417 | out += len << 3; |
| 418 | in += len << 3; |
| 419 | } |
| 420 | } |
| 421 | #endif |
Tim Murray | 36889a0 | 2012-09-24 14:52:48 -0700 | [diff] [blame] | 422 | for (;x1 < x2; x1++, out++, in++) { |
Tim Murray | 0b575de | 2013-03-15 15:56:43 -0700 | [diff] [blame] | 423 | uint32_t iR = in->x, iG = in->y, iB = in->z, iA = in->w, |
| 424 | oR = out->x, oG = out->y, oB = out->z, oA = out->w; |
| 425 | out->x = (oR + iR) > 255 ? 255 : oR + iR; |
| 426 | out->y = (oG + iG) > 255 ? 255 : oG + iG; |
| 427 | out->z = (oB + iB) > 255 ? 255 : oB + iB; |
| 428 | out->w = (oA + iA) > 255 ? 255 : oA + iA; |
Tim Murray | 36889a0 | 2012-09-24 14:52:48 -0700 | [diff] [blame] | 429 | } |
| 430 | break; |
| 431 | case BLEND_SUBTRACT: |
Rose, James | 7b7060c | 2014-04-22 12:08:06 +0800 | [diff] [blame] | 432 | #if defined(ARCH_X86_HAVE_SSSE3) |
| 433 | if (gArchUseSIMD) { |
| 434 | if((x1 + 8) < x2) { |
| 435 | uint32_t len = (x2 - x1) >> 3; |
| 436 | rsdIntrinsicBlendSub_K(out, in, len); |
| 437 | x1 += len << 3; |
| 438 | out += len << 3; |
| 439 | in += len << 3; |
| 440 | } |
| 441 | } |
| 442 | #endif |
Tim Murray | 36889a0 | 2012-09-24 14:52:48 -0700 | [diff] [blame] | 443 | for (;x1 < x2; x1++, out++, in++) { |
Tim Murray | 0b575de | 2013-03-15 15:56:43 -0700 | [diff] [blame] | 444 | int32_t iR = in->x, iG = in->y, iB = in->z, iA = in->w, |
| 445 | oR = out->x, oG = out->y, oB = out->z, oA = out->w; |
| 446 | out->x = (oR - iR) < 0 ? 0 : oR - iR; |
| 447 | out->y = (oG - iG) < 0 ? 0 : oG - iG; |
| 448 | out->z = (oB - iB) < 0 ? 0 : oB - iB; |
| 449 | out->w = (oA - iA) < 0 ? 0 : oA - iA; |
Tim Murray | 36889a0 | 2012-09-24 14:52:48 -0700 | [diff] [blame] | 450 | } |
| 451 | break; |
| 452 | case BLEND_STAMP: |
| 453 | ALOGE("Called unimplemented blend intrinsic BLEND_STAMP"); |
| 454 | rsAssert(false); |
| 455 | break; |
| 456 | case BLEND_RED: |
| 457 | ALOGE("Called unimplemented blend intrinsic BLEND_RED"); |
| 458 | rsAssert(false); |
| 459 | break; |
| 460 | case BLEND_GREEN: |
| 461 | ALOGE("Called unimplemented blend intrinsic BLEND_GREEN"); |
| 462 | rsAssert(false); |
| 463 | break; |
| 464 | case BLEND_BLUE: |
| 465 | ALOGE("Called unimplemented blend intrinsic BLEND_BLUE"); |
| 466 | rsAssert(false); |
| 467 | break; |
| 468 | case BLEND_HUE: |
| 469 | ALOGE("Called unimplemented blend intrinsic BLEND_HUE"); |
| 470 | rsAssert(false); |
| 471 | break; |
| 472 | case BLEND_SATURATION: |
| 473 | ALOGE("Called unimplemented blend intrinsic BLEND_SATURATION"); |
| 474 | rsAssert(false); |
| 475 | break; |
| 476 | case BLEND_COLOR: |
| 477 | ALOGE("Called unimplemented blend intrinsic BLEND_COLOR"); |
| 478 | rsAssert(false); |
| 479 | break; |
| 480 | case BLEND_LUMINOSITY: |
| 481 | ALOGE("Called unimplemented blend intrinsic BLEND_LUMINOSITY"); |
| 482 | rsAssert(false); |
| 483 | break; |
Jason Sams | cf9ea9f | 2012-09-23 17:00:54 -0700 | [diff] [blame] | 484 | |
Tim Murray | 36889a0 | 2012-09-24 14:52:48 -0700 | [diff] [blame] | 485 | default: |
| 486 | ALOGE("Called unimplemented value %d", p->slot); |
| 487 | rsAssert(false); |
Jason Sams | cf9ea9f | 2012-09-23 17:00:54 -0700 | [diff] [blame] | 488 | |
| 489 | } |
Jason Sams | cf9ea9f | 2012-09-23 17:00:54 -0700 | [diff] [blame] | 490 | } |
| 491 | |
Jason Sams | cf9ea9f | 2012-09-23 17:00:54 -0700 | [diff] [blame] | 492 | |
Jason Sams | c905efd | 2012-11-26 15:20:18 -0800 | [diff] [blame] | 493 | RsdCpuScriptIntrinsicBlend::RsdCpuScriptIntrinsicBlend(RsdCpuReferenceImpl *ctx, |
| 494 | const Script *s, const Element *e) |
| 495 | : RsdCpuScriptIntrinsic(ctx, s, e, RS_SCRIPT_INTRINSIC_ID_BLEND) { |
Jason Sams | cf9ea9f | 2012-09-23 17:00:54 -0700 | [diff] [blame] | 496 | |
Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 497 | mRootPtr = &kernel; |
Jason Sams | cf9ea9f | 2012-09-23 17:00:54 -0700 | [diff] [blame] | 498 | } |
| 499 | |
Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 500 | RsdCpuScriptIntrinsicBlend::~RsdCpuScriptIntrinsicBlend() { |
| 501 | } |
| 502 | |
| 503 | void RsdCpuScriptIntrinsicBlend::populateScript(Script *s) { |
| 504 | s->mHal.info.exportedVariableCount = 0; |
| 505 | } |
| 506 | |
Jason Sams | c905efd | 2012-11-26 15:20:18 -0800 | [diff] [blame] | 507 | RsdCpuScriptImpl * rsdIntrinsic_Blend(RsdCpuReferenceImpl *ctx, |
| 508 | const Script *s, const Element *e) { |
| 509 | return new RsdCpuScriptIntrinsicBlend(ctx, s, e); |
Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 510 | } |