1cf9ea9f4145cae663f439b1c2dab956fa37180bbJason Sams/*
2cf9ea9f4145cae663f439b1c2dab956fa37180bbJason Sams * Copyright (C) 2012 The Android Open Source Project
3cf9ea9f4145cae663f439b1c2dab956fa37180bbJason Sams *
4cf9ea9f4145cae663f439b1c2dab956fa37180bbJason Sams * Licensed under the Apache License, Version 2.0 (the "License");
5cf9ea9f4145cae663f439b1c2dab956fa37180bbJason Sams * you may not use this file except in compliance with the License.
6cf9ea9f4145cae663f439b1c2dab956fa37180bbJason Sams * You may obtain a copy of the License at
7cf9ea9f4145cae663f439b1c2dab956fa37180bbJason Sams *
8cf9ea9f4145cae663f439b1c2dab956fa37180bbJason Sams *      http://www.apache.org/licenses/LICENSE-2.0
9cf9ea9f4145cae663f439b1c2dab956fa37180bbJason Sams *
10cf9ea9f4145cae663f439b1c2dab956fa37180bbJason Sams * Unless required by applicable law or agreed to in writing, software
11cf9ea9f4145cae663f439b1c2dab956fa37180bbJason Sams * distributed under the License is distributed on an "AS IS" BASIS,
12cf9ea9f4145cae663f439b1c2dab956fa37180bbJason Sams * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13cf9ea9f4145cae663f439b1c2dab956fa37180bbJason Sams * See the License for the specific language governing permissions and
14cf9ea9f4145cae663f439b1c2dab956fa37180bbJason Sams * limitations under the License.
15cf9ea9f4145cae663f439b1c2dab956fa37180bbJason Sams */
16cf9ea9f4145cae663f439b1c2dab956fa37180bbJason Sams
17cf9ea9f4145cae663f439b1c2dab956fa37180bbJason Sams
18709a0978ae141198018ca9769f8d96292a8928e6Jason Sams#include "rsCpuIntrinsic.h"
19709a0978ae141198018ca9769f8d96292a8928e6Jason Sams#include "rsCpuIntrinsicInlines.h"
20cf9ea9f4145cae663f439b1c2dab956fa37180bbJason Sams
21cf9ea9f4145cae663f439b1c2dab956fa37180bbJason Samsusing namespace android;
22cf9ea9f4145cae663f439b1c2dab956fa37180bbJason Samsusing namespace android::renderscript;
23cf9ea9f4145cae663f439b1c2dab956fa37180bbJason Sams
24709a0978ae141198018ca9769f8d96292a8928e6Jason Samsnamespace android {
25709a0978ae141198018ca9769f8d96292a8928e6Jason Samsnamespace renderscript {
26709a0978ae141198018ca9769f8d96292a8928e6Jason Sams
27709a0978ae141198018ca9769f8d96292a8928e6Jason Sams
28709a0978ae141198018ca9769f8d96292a8928e6Jason Samsclass RsdCpuScriptIntrinsicBlend : public RsdCpuScriptIntrinsic {
29709a0978ae141198018ca9769f8d96292a8928e6Jason Samspublic:
30709a0978ae141198018ca9769f8d96292a8928e6Jason Sams    virtual void populateScript(Script *);
31709a0978ae141198018ca9769f8d96292a8928e6Jason Sams
32709a0978ae141198018ca9769f8d96292a8928e6Jason Sams    virtual ~RsdCpuScriptIntrinsicBlend();
33c905efd76fdcc1b8846b229bf7d991d185a7b4b7Jason Sams    RsdCpuScriptIntrinsicBlend(RsdCpuReferenceImpl *ctx, const Script *s, const Element *e);
34709a0978ae141198018ca9769f8d96292a8928e6Jason Sams
35709a0978ae141198018ca9769f8d96292a8928e6Jason Samsprotected:
36709a0978ae141198018ca9769f8d96292a8928e6Jason Sams    static void kernel(const RsForEachStubParamStruct *p,
37709a0978ae141198018ca9769f8d96292a8928e6Jason Sams                          uint32_t xstart, uint32_t xend,
38709a0978ae141198018ca9769f8d96292a8928e6Jason Sams                          uint32_t instep, uint32_t outstep);
39cf9ea9f4145cae663f439b1c2dab956fa37180bbJason Sams};
40cf9ea9f4145cae663f439b1c2dab956fa37180bbJason Sams
41709a0978ae141198018ca9769f8d96292a8928e6Jason Sams}
42709a0978ae141198018ca9769f8d96292a8928e6Jason Sams}
43709a0978ae141198018ca9769f8d96292a8928e6Jason Sams
44cf9ea9f4145cae663f439b1c2dab956fa37180bbJason Sams
45cf9ea9f4145cae663f439b1c2dab956fa37180bbJason Samsenum {
46cf9ea9f4145cae663f439b1c2dab956fa37180bbJason Sams    BLEND_CLEAR = 0,
47cf9ea9f4145cae663f439b1c2dab956fa37180bbJason Sams    BLEND_SRC = 1,
48cf9ea9f4145cae663f439b1c2dab956fa37180bbJason Sams    BLEND_DST = 2,
49cf9ea9f4145cae663f439b1c2dab956fa37180bbJason Sams    BLEND_SRC_OVER = 3,
50cf9ea9f4145cae663f439b1c2dab956fa37180bbJason Sams    BLEND_DST_OVER = 4,
51cf9ea9f4145cae663f439b1c2dab956fa37180bbJason Sams    BLEND_SRC_IN = 5,
52cf9ea9f4145cae663f439b1c2dab956fa37180bbJason Sams    BLEND_DST_IN = 6,
53cf9ea9f4145cae663f439b1c2dab956fa37180bbJason Sams    BLEND_SRC_OUT = 7,
54cf9ea9f4145cae663f439b1c2dab956fa37180bbJason Sams    BLEND_DST_OUT = 8,
55cf9ea9f4145cae663f439b1c2dab956fa37180bbJason Sams    BLEND_SRC_ATOP = 9,
56cf9ea9f4145cae663f439b1c2dab956fa37180bbJason Sams    BLEND_DST_ATOP = 10,
57cf9ea9f4145cae663f439b1c2dab956fa37180bbJason Sams    BLEND_XOR = 11,
58cf9ea9f4145cae663f439b1c2dab956fa37180bbJason Sams
59cf9ea9f4145cae663f439b1c2dab956fa37180bbJason Sams    BLEND_NORMAL = 12,
60cf9ea9f4145cae663f439b1c2dab956fa37180bbJason Sams    BLEND_AVERAGE = 13,
61cf9ea9f4145cae663f439b1c2dab956fa37180bbJason Sams    BLEND_MULTIPLY = 14,
62cf9ea9f4145cae663f439b1c2dab956fa37180bbJason Sams    BLEND_SCREEN = 15,
63cf9ea9f4145cae663f439b1c2dab956fa37180bbJason Sams    BLEND_DARKEN = 16,
64cf9ea9f4145cae663f439b1c2dab956fa37180bbJason Sams    BLEND_LIGHTEN = 17,
65cf9ea9f4145cae663f439b1c2dab956fa37180bbJason Sams    BLEND_OVERLAY = 18,
66cf9ea9f4145cae663f439b1c2dab956fa37180bbJason Sams    BLEND_HARDLIGHT = 19,
67cf9ea9f4145cae663f439b1c2dab956fa37180bbJason Sams    BLEND_SOFTLIGHT = 20,
68cf9ea9f4145cae663f439b1c2dab956fa37180bbJason Sams    BLEND_DIFFERENCE = 21,
69cf9ea9f4145cae663f439b1c2dab956fa37180bbJason Sams    BLEND_NEGATION = 22,
70cf9ea9f4145cae663f439b1c2dab956fa37180bbJason Sams    BLEND_EXCLUSION = 23,
71cf9ea9f4145cae663f439b1c2dab956fa37180bbJason Sams    BLEND_COLOR_DODGE = 24,
72cf9ea9f4145cae663f439b1c2dab956fa37180bbJason Sams    BLEND_INVERSE_COLOR_DODGE = 25,
73cf9ea9f4145cae663f439b1c2dab956fa37180bbJason Sams    BLEND_SOFT_DODGE = 26,
74cf9ea9f4145cae663f439b1c2dab956fa37180bbJason Sams    BLEND_COLOR_BURN = 27,
75cf9ea9f4145cae663f439b1c2dab956fa37180bbJason Sams    BLEND_INVERSE_COLOR_BURN = 28,
76cf9ea9f4145cae663f439b1c2dab956fa37180bbJason Sams    BLEND_SOFT_BURN = 29,
77cf9ea9f4145cae663f439b1c2dab956fa37180bbJason Sams    BLEND_REFLECT = 30,
78cf9ea9f4145cae663f439b1c2dab956fa37180bbJason Sams    BLEND_GLOW = 31,
79cf9ea9f4145cae663f439b1c2dab956fa37180bbJason Sams    BLEND_FREEZE = 32,
80cf9ea9f4145cae663f439b1c2dab956fa37180bbJason Sams    BLEND_HEAT = 33,
81cf9ea9f4145cae663f439b1c2dab956fa37180bbJason Sams    BLEND_ADD = 34,
82cf9ea9f4145cae663f439b1c2dab956fa37180bbJason Sams    BLEND_SUBTRACT = 35,
83cf9ea9f4145cae663f439b1c2dab956fa37180bbJason Sams    BLEND_STAMP = 36,
84cf9ea9f4145cae663f439b1c2dab956fa37180bbJason Sams    BLEND_RED = 37,
85cf9ea9f4145cae663f439b1c2dab956fa37180bbJason Sams    BLEND_GREEN = 38,
86cf9ea9f4145cae663f439b1c2dab956fa37180bbJason Sams    BLEND_BLUE = 39,
87cf9ea9f4145cae663f439b1c2dab956fa37180bbJason Sams    BLEND_HUE = 40,
88cf9ea9f4145cae663f439b1c2dab956fa37180bbJason Sams    BLEND_SATURATION = 41,
89cf9ea9f4145cae663f439b1c2dab956fa37180bbJason Sams    BLEND_COLOR = 42,
90cf9ea9f4145cae663f439b1c2dab956fa37180bbJason Sams    BLEND_LUMINOSITY = 43
91cf9ea9f4145cae663f439b1c2dab956fa37180bbJason Sams};
92cf9ea9f4145cae663f439b1c2dab956fa37180bbJason Sams
93074424a4ac5b093331df2c92e7a5bcbfff136b71Jason Sams#if defined(ARCH_ARM_USE_INTRINSICS)
945d06919bc8019322180ea34768a7a4137fa64d11Simon Hosieextern "C" int rsdIntrinsicBlend_K(uchar4 *out, uchar4 const *in, int slot,
955d06919bc8019322180ea34768a7a4137fa64d11Simon Hosie                    uint32_t xstart, uint32_t xend);
967b7060c61e4182b29186849c5a857ea5f0898e56Rose, James#endif
977b7060c61e4182b29186849c5a857ea5f0898e56Rose, James
987b7060c61e4182b29186849c5a857ea5f0898e56Rose, James#if defined(ARCH_X86_HAVE_SSSE3)
997b7060c61e4182b29186849c5a857ea5f0898e56Rose, Jamesextern "C" void rsdIntrinsicBlendSrcOver_K(void *dst, const void *src, uint32_t count8);
1007b7060c61e4182b29186849c5a857ea5f0898e56Rose, Jamesextern "C" void rsdIntrinsicBlendDstOver_K(void *dst, const void *src, uint32_t count8);
1017b7060c61e4182b29186849c5a857ea5f0898e56Rose, Jamesextern "C" void rsdIntrinsicBlendSrcIn_K(void *dst, const void *src, uint32_t count8);
1027b7060c61e4182b29186849c5a857ea5f0898e56Rose, Jamesextern "C" void rsdIntrinsicBlendDstIn_K(void *dst, const void *src, uint32_t count8);
1037b7060c61e4182b29186849c5a857ea5f0898e56Rose, Jamesextern "C" void rsdIntrinsicBlendSrcOut_K(void *dst, const void *src, uint32_t count8);
1047b7060c61e4182b29186849c5a857ea5f0898e56Rose, Jamesextern "C" void rsdIntrinsicBlendDstOut_K(void *dst, const void *src, uint32_t count8);
1057b7060c61e4182b29186849c5a857ea5f0898e56Rose, Jamesextern "C" void rsdIntrinsicBlendSrcAtop_K(void *dst, const void *src, uint32_t count8);
1067b7060c61e4182b29186849c5a857ea5f0898e56Rose, Jamesextern "C" void rsdIntrinsicBlendDstAtop_K(void *dst, const void *src, uint32_t count8);
1077b7060c61e4182b29186849c5a857ea5f0898e56Rose, Jamesextern "C" void rsdIntrinsicBlendXor_K(void *dst, const void *src, uint32_t count8);
1087b7060c61e4182b29186849c5a857ea5f0898e56Rose, Jamesextern "C" void rsdIntrinsicBlendMultiply_K(void *dst, const void *src, uint32_t count8);
1097b7060c61e4182b29186849c5a857ea5f0898e56Rose, Jamesextern "C" void rsdIntrinsicBlendAdd_K(void *dst, const void *src, uint32_t count8);
1107b7060c61e4182b29186849c5a857ea5f0898e56Rose, Jamesextern "C" void rsdIntrinsicBlendSub_K(void *dst, const void *src, uint32_t count8);
1117b7060c61e4182b29186849c5a857ea5f0898e56Rose, James#endif
112fa17cda2d7e0948677035890e40498ad0b639c92Jason Sams
113709a0978ae141198018ca9769f8d96292a8928e6Jason Samsvoid RsdCpuScriptIntrinsicBlend::kernel(const RsForEachStubParamStruct *p,
114709a0978ae141198018ca9769f8d96292a8928e6Jason Sams                                        uint32_t xstart, uint32_t xend,
115709a0978ae141198018ca9769f8d96292a8928e6Jason Sams                                        uint32_t instep, uint32_t outstep) {
116709a0978ae141198018ca9769f8d96292a8928e6Jason Sams    RsdCpuScriptIntrinsicBlend *cp = (RsdCpuScriptIntrinsicBlend *)p->usr;
11736889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray
11836889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray    // instep/outstep can be ignored--sizeof(uchar4) known at compile time
119cf9ea9f4145cae663f439b1c2dab956fa37180bbJason Sams    uchar4 *out = (uchar4 *)p->out;
120cf9ea9f4145cae663f439b1c2dab956fa37180bbJason Sams    uchar4 *in = (uchar4 *)p->in;
121cf9ea9f4145cae663f439b1c2dab956fa37180bbJason Sams    uint32_t x1 = xstart;
122cf9ea9f4145cae663f439b1c2dab956fa37180bbJason Sams    uint32_t x2 = xend;
123cf9ea9f4145cae663f439b1c2dab956fa37180bbJason Sams
124074424a4ac5b093331df2c92e7a5bcbfff136b71Jason Sams#if defined(ARCH_ARM_USE_INTRINSICS) && !defined(ARCH_ARM64_USE_INTRINSICS)
1255d06919bc8019322180ea34768a7a4137fa64d11Simon Hosie    if (gArchUseSIMD) {
1265d06919bc8019322180ea34768a7a4137fa64d11Simon Hosie        if (rsdIntrinsicBlend_K(out, in, p->slot, x1, x2) >= 0)
1275d06919bc8019322180ea34768a7a4137fa64d11Simon Hosie            return;
1285d06919bc8019322180ea34768a7a4137fa64d11Simon Hosie    }
1295d06919bc8019322180ea34768a7a4137fa64d11Simon Hosie#endif
130cf9ea9f4145cae663f439b1c2dab956fa37180bbJason Sams    switch (p->slot) {
131cf9ea9f4145cae663f439b1c2dab956fa37180bbJason Sams    case BLEND_CLEAR:
132cf9ea9f4145cae663f439b1c2dab956fa37180bbJason Sams        for (;x1 < x2; x1++, out++) {
133cf9ea9f4145cae663f439b1c2dab956fa37180bbJason Sams            *out = 0;
134cf9ea9f4145cae663f439b1c2dab956fa37180bbJason Sams        }
135cf9ea9f4145cae663f439b1c2dab956fa37180bbJason Sams        break;
136cf9ea9f4145cae663f439b1c2dab956fa37180bbJason Sams    case BLEND_SRC:
137cf9ea9f4145cae663f439b1c2dab956fa37180bbJason Sams        for (;x1 < x2; x1++, out++, in++) {
13836889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray          *out = *in;
139cf9ea9f4145cae663f439b1c2dab956fa37180bbJason Sams        }
140cf9ea9f4145cae663f439b1c2dab956fa37180bbJason Sams        break;
14136889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray    //BLEND_DST is a NOP
142cf9ea9f4145cae663f439b1c2dab956fa37180bbJason Sams    case BLEND_DST:
14336889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray        break;
14436889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray    case BLEND_SRC_OVER:
1457b7060c61e4182b29186849c5a857ea5f0898e56Rose, James    #if defined(ARCH_X86_HAVE_SSSE3)
1467b7060c61e4182b29186849c5a857ea5f0898e56Rose, James        if (gArchUseSIMD) {
1477b7060c61e4182b29186849c5a857ea5f0898e56Rose, James            if ((x1 + 8) < x2) {
1487b7060c61e4182b29186849c5a857ea5f0898e56Rose, James                uint32_t len = (x2 - x1) >> 3;
1497b7060c61e4182b29186849c5a857ea5f0898e56Rose, James                rsdIntrinsicBlendSrcOver_K(out, in, len);
1507b7060c61e4182b29186849c5a857ea5f0898e56Rose, James                x1 += len << 3;
1517b7060c61e4182b29186849c5a857ea5f0898e56Rose, James                out += len << 3;
1527b7060c61e4182b29186849c5a857ea5f0898e56Rose, James                in += len << 3;
1537b7060c61e4182b29186849c5a857ea5f0898e56Rose, James            }
1547b7060c61e4182b29186849c5a857ea5f0898e56Rose, James        }
1557b7060c61e4182b29186849c5a857ea5f0898e56Rose, James    #endif
156cf9ea9f4145cae663f439b1c2dab956fa37180bbJason Sams        for (;x1 < x2; x1++, out++, in++) {
15736889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray            short4 in_s = convert_short4(*in);
15836889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray            short4 out_s = convert_short4(*out);
1590b575de8ed0b628d84d256f5846500b0385979bdTim Murray            in_s = in_s + ((out_s * (short4)(255 - in_s.w)) >> (short4)8);
16036889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray            *out = convert_uchar4(in_s);
161cf9ea9f4145cae663f439b1c2dab956fa37180bbJason Sams        }
162cf9ea9f4145cae663f439b1c2dab956fa37180bbJason Sams        break;
16336889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray    case BLEND_DST_OVER:
1647b7060c61e4182b29186849c5a857ea5f0898e56Rose, James    #if defined(ARCH_X86_HAVE_SSSE3)
1657b7060c61e4182b29186849c5a857ea5f0898e56Rose, James        if (gArchUseSIMD) {
1667b7060c61e4182b29186849c5a857ea5f0898e56Rose, James            if ((x1 + 8) < x2) {
1677b7060c61e4182b29186849c5a857ea5f0898e56Rose, James                uint32_t len = (x2 - x1) >> 3;
1687b7060c61e4182b29186849c5a857ea5f0898e56Rose, James                rsdIntrinsicBlendDstOver_K(out, in, len);
1697b7060c61e4182b29186849c5a857ea5f0898e56Rose, James                x1 += len << 3;
1707b7060c61e4182b29186849c5a857ea5f0898e56Rose, James                out += len << 3;
1717b7060c61e4182b29186849c5a857ea5f0898e56Rose, James                in += len << 3;
1727b7060c61e4182b29186849c5a857ea5f0898e56Rose, James            }
1737b7060c61e4182b29186849c5a857ea5f0898e56Rose, James        }
1747b7060c61e4182b29186849c5a857ea5f0898e56Rose, James     #endif
17536889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray        for (;x1 < x2; x1++, out++, in++) {
17636889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray            short4 in_s = convert_short4(*in);
17736889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray            short4 out_s = convert_short4(*out);
1780b575de8ed0b628d84d256f5846500b0385979bdTim Murray            in_s = out_s + ((in_s * (short4)(255 - out_s.w)) >> (short4)8);
17936889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray            *out = convert_uchar4(in_s);
18036889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray        }
18136889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray        break;
18236889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray    case BLEND_SRC_IN:
1837b7060c61e4182b29186849c5a857ea5f0898e56Rose, James    #if defined(ARCH_X86_HAVE_SSSE3)
1847b7060c61e4182b29186849c5a857ea5f0898e56Rose, James        if (gArchUseSIMD) {
1857b7060c61e4182b29186849c5a857ea5f0898e56Rose, James            if ((x1 + 8) < x2) {
1867b7060c61e4182b29186849c5a857ea5f0898e56Rose, James                uint32_t len = (x2 - x1) >> 3;
1877b7060c61e4182b29186849c5a857ea5f0898e56Rose, James                rsdIntrinsicBlendSrcIn_K(out, in, len);
1887b7060c61e4182b29186849c5a857ea5f0898e56Rose, James                x1 += len << 3;
1897b7060c61e4182b29186849c5a857ea5f0898e56Rose, James                out += len << 3;
1907b7060c61e4182b29186849c5a857ea5f0898e56Rose, James                in += len << 3;
1917b7060c61e4182b29186849c5a857ea5f0898e56Rose, James            }
1927b7060c61e4182b29186849c5a857ea5f0898e56Rose, James        }
1937b7060c61e4182b29186849c5a857ea5f0898e56Rose, James    #endif
19436889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray        for (;x1 < x2; x1++, out++, in++) {
19536889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray            short4 in_s = convert_short4(*in);
1960b575de8ed0b628d84d256f5846500b0385979bdTim Murray            in_s = (in_s * out->w) >> (short4)8;
19736889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray            *out = convert_uchar4(in_s);
19836889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray        }
19936889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray        break;
20036889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray    case BLEND_DST_IN:
2017b7060c61e4182b29186849c5a857ea5f0898e56Rose, James    #if defined(ARCH_X86_HAVE_SSSE3)
2027b7060c61e4182b29186849c5a857ea5f0898e56Rose, James        if (gArchUseSIMD) {
2037b7060c61e4182b29186849c5a857ea5f0898e56Rose, James            if ((x1 + 8) < x2) {
2047b7060c61e4182b29186849c5a857ea5f0898e56Rose, James                uint32_t len = (x2 - x1) >> 3;
2057b7060c61e4182b29186849c5a857ea5f0898e56Rose, James                rsdIntrinsicBlendDstIn_K(out, in, len);
2067b7060c61e4182b29186849c5a857ea5f0898e56Rose, James                x1 += len << 3;
2077b7060c61e4182b29186849c5a857ea5f0898e56Rose, James                out += len << 3;
2087b7060c61e4182b29186849c5a857ea5f0898e56Rose, James                in += len << 3;
2097b7060c61e4182b29186849c5a857ea5f0898e56Rose, James            }
2107b7060c61e4182b29186849c5a857ea5f0898e56Rose, James        }
2117b7060c61e4182b29186849c5a857ea5f0898e56Rose, James     #endif
21236889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray        for (;x1 < x2; x1++, out++, in++) {
21336889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray            short4 out_s = convert_short4(*out);
2140b575de8ed0b628d84d256f5846500b0385979bdTim Murray            out_s = (out_s * in->w) >> (short4)8;
21536889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray            *out = convert_uchar4(out_s);
21636889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray        }
21736889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray        break;
21836889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray    case BLEND_SRC_OUT:
2197b7060c61e4182b29186849c5a857ea5f0898e56Rose, James    #if defined(ARCH_X86_HAVE_SSSE3)
2207b7060c61e4182b29186849c5a857ea5f0898e56Rose, James        if (gArchUseSIMD) {
2217b7060c61e4182b29186849c5a857ea5f0898e56Rose, James            if ((x1 + 8) < x2) {
2227b7060c61e4182b29186849c5a857ea5f0898e56Rose, James                uint32_t len = (x2 - x1) >> 3;
2237b7060c61e4182b29186849c5a857ea5f0898e56Rose, James                rsdIntrinsicBlendSrcOut_K(out, in, len);
2247b7060c61e4182b29186849c5a857ea5f0898e56Rose, James                x1 += len << 3;
2257b7060c61e4182b29186849c5a857ea5f0898e56Rose, James                out += len << 3;
2267b7060c61e4182b29186849c5a857ea5f0898e56Rose, James                in += len << 3;
2277b7060c61e4182b29186849c5a857ea5f0898e56Rose, James            }
2287b7060c61e4182b29186849c5a857ea5f0898e56Rose, James        }
2297b7060c61e4182b29186849c5a857ea5f0898e56Rose, James    #endif
23036889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray        for (;x1 < x2; x1++, out++, in++) {
23136889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray            short4 in_s = convert_short4(*in);
2320b575de8ed0b628d84d256f5846500b0385979bdTim Murray            in_s = (in_s * (short4)(255 - out->w)) >> (short4)8;
23336889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray            *out = convert_uchar4(in_s);
23436889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray        }
23536889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray        break;
23636889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray    case BLEND_DST_OUT:
2377b7060c61e4182b29186849c5a857ea5f0898e56Rose, James    #if defined(ARCH_X86_HAVE_SSSE3)
2387b7060c61e4182b29186849c5a857ea5f0898e56Rose, James        if (gArchUseSIMD) {
2397b7060c61e4182b29186849c5a857ea5f0898e56Rose, James            if ((x1 + 8) < x2) {
2407b7060c61e4182b29186849c5a857ea5f0898e56Rose, James                uint32_t len = (x2 - x1) >> 3;
2417b7060c61e4182b29186849c5a857ea5f0898e56Rose, James                rsdIntrinsicBlendDstOut_K(out, in, len);
2427b7060c61e4182b29186849c5a857ea5f0898e56Rose, James                x1 += len << 3;
2437b7060c61e4182b29186849c5a857ea5f0898e56Rose, James                out += len << 3;
2447b7060c61e4182b29186849c5a857ea5f0898e56Rose, James                in += len << 3;
2457b7060c61e4182b29186849c5a857ea5f0898e56Rose, James            }
2467b7060c61e4182b29186849c5a857ea5f0898e56Rose, James        }
2477b7060c61e4182b29186849c5a857ea5f0898e56Rose, James    #endif
24836889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray        for (;x1 < x2; x1++, out++, in++) {
24936889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray            short4 out_s = convert_short4(*out);
2500b575de8ed0b628d84d256f5846500b0385979bdTim Murray            out_s = (out_s * (short4)(255 - in->w)) >> (short4)8;
25136889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray            *out = convert_uchar4(out_s);
25236889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray        }
25336889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray        break;
25436889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray    case BLEND_SRC_ATOP:
2557b7060c61e4182b29186849c5a857ea5f0898e56Rose, James    #if defined(ARCH_X86_HAVE_SSSE3)
2567b7060c61e4182b29186849c5a857ea5f0898e56Rose, James        if (gArchUseSIMD) {
2577b7060c61e4182b29186849c5a857ea5f0898e56Rose, James            if ((x1 + 8) < x2) {
2587b7060c61e4182b29186849c5a857ea5f0898e56Rose, James                uint32_t len = (x2 - x1) >> 3;
2597b7060c61e4182b29186849c5a857ea5f0898e56Rose, James                rsdIntrinsicBlendSrcAtop_K(out, in, len);
2607b7060c61e4182b29186849c5a857ea5f0898e56Rose, James                x1 += len << 3;
2617b7060c61e4182b29186849c5a857ea5f0898e56Rose, James                out += len << 3;
2627b7060c61e4182b29186849c5a857ea5f0898e56Rose, James                in += len << 3;
2637b7060c61e4182b29186849c5a857ea5f0898e56Rose, James            }
2647b7060c61e4182b29186849c5a857ea5f0898e56Rose, James        }
2657b7060c61e4182b29186849c5a857ea5f0898e56Rose, James    #endif
26636889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray        for (;x1 < x2; x1++, out++, in++) {
26736889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray            short4 in_s = convert_short4(*in);
26836889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray            short4 out_s = convert_short4(*out);
2690b575de8ed0b628d84d256f5846500b0385979bdTim Murray            out_s.xyz = ((in_s.xyz * out_s.w) +
2700b575de8ed0b628d84d256f5846500b0385979bdTim Murray              (out_s.xyz * ((short3)255 - (short3)in_s.w))) >> (short3)8;
27136889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray            *out = convert_uchar4(out_s);
27236889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray        }
27336889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray        break;
27436889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray    case BLEND_DST_ATOP:
2757b7060c61e4182b29186849c5a857ea5f0898e56Rose, James    #if defined(ARCH_X86_HAVE_SSSE3)
2767b7060c61e4182b29186849c5a857ea5f0898e56Rose, James        if (gArchUseSIMD) {
2777b7060c61e4182b29186849c5a857ea5f0898e56Rose, James            if ((x1 + 8) < x2) {
2787b7060c61e4182b29186849c5a857ea5f0898e56Rose, James                uint32_t len = (x2 - x1) >> 3;
2797b7060c61e4182b29186849c5a857ea5f0898e56Rose, James                rsdIntrinsicBlendDstAtop_K(out, in, len);
2807b7060c61e4182b29186849c5a857ea5f0898e56Rose, James                x1 += len << 3;
2817b7060c61e4182b29186849c5a857ea5f0898e56Rose, James                out += len << 3;
2827b7060c61e4182b29186849c5a857ea5f0898e56Rose, James                in += len << 3;
2837b7060c61e4182b29186849c5a857ea5f0898e56Rose, James            }
2847b7060c61e4182b29186849c5a857ea5f0898e56Rose, James        }
2857b7060c61e4182b29186849c5a857ea5f0898e56Rose, James     #endif
28636889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray        for (;x1 < x2; x1++, out++, in++) {
28736889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray            short4 in_s = convert_short4(*in);
28836889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray            short4 out_s = convert_short4(*out);
2890b575de8ed0b628d84d256f5846500b0385979bdTim Murray            out_s.xyz = ((out_s.xyz * in_s.w) +
2900b575de8ed0b628d84d256f5846500b0385979bdTim Murray              (in_s.xyz * ((short3)255 - (short3)out_s.w))) >> (short3)8;
29136889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray            *out = convert_uchar4(out_s);
29236889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray        }
29336889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray        break;
29436889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray    case BLEND_XOR:
2957b7060c61e4182b29186849c5a857ea5f0898e56Rose, James    #if defined(ARCH_X86_HAVE_SSSE3)
2967b7060c61e4182b29186849c5a857ea5f0898e56Rose, James        if (gArchUseSIMD) {
2977b7060c61e4182b29186849c5a857ea5f0898e56Rose, James            if ((x1 + 8) < x2) {
2987b7060c61e4182b29186849c5a857ea5f0898e56Rose, James                uint32_t len = (x2 - x1) >> 3;
2997b7060c61e4182b29186849c5a857ea5f0898e56Rose, James                rsdIntrinsicBlendXor_K(out, in, len);
3007b7060c61e4182b29186849c5a857ea5f0898e56Rose, James                x1 += len << 3;
3017b7060c61e4182b29186849c5a857ea5f0898e56Rose, James                out += len << 3;
3027b7060c61e4182b29186849c5a857ea5f0898e56Rose, James                in += len << 3;
3037b7060c61e4182b29186849c5a857ea5f0898e56Rose, James            }
3047b7060c61e4182b29186849c5a857ea5f0898e56Rose, James        }
3057b7060c61e4182b29186849c5a857ea5f0898e56Rose, James    #endif
30636889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray        for (;x1 < x2; x1++, out++, in++) {
30736889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray            *out = *in ^ *out;
30836889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray        }
30936889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray        break;
31036889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray    case BLEND_NORMAL:
31136889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray        ALOGE("Called unimplemented blend intrinsic BLEND_NORMAL");
31236889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray        rsAssert(false);
31336889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray        break;
31436889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray    case BLEND_AVERAGE:
31536889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray        ALOGE("Called unimplemented blend intrinsic BLEND_AVERAGE");
31636889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray        rsAssert(false);
31736889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray        break;
31836889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray    case BLEND_MULTIPLY:
3197b7060c61e4182b29186849c5a857ea5f0898e56Rose, James    #if defined(ARCH_X86_HAVE_SSSE3)
3207b7060c61e4182b29186849c5a857ea5f0898e56Rose, James        if (gArchUseSIMD) {
3217b7060c61e4182b29186849c5a857ea5f0898e56Rose, James            if ((x1 + 8) < x2) {
3227b7060c61e4182b29186849c5a857ea5f0898e56Rose, James                uint32_t len = (x2 - x1) >> 3;
3237b7060c61e4182b29186849c5a857ea5f0898e56Rose, James                rsdIntrinsicBlendMultiply_K(out, in, len);
3247b7060c61e4182b29186849c5a857ea5f0898e56Rose, James                x1 += len << 3;
3257b7060c61e4182b29186849c5a857ea5f0898e56Rose, James                out += len << 3;
3267b7060c61e4182b29186849c5a857ea5f0898e56Rose, James                in += len << 3;
3277b7060c61e4182b29186849c5a857ea5f0898e56Rose, James            }
3287b7060c61e4182b29186849c5a857ea5f0898e56Rose, James        }
3297b7060c61e4182b29186849c5a857ea5f0898e56Rose, James    #endif
33036889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray        for (;x1 < x2; x1++, out++, in++) {
33136889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray          *out = convert_uchar4((convert_short4(*in) * convert_short4(*out))
33236889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray                                >> (short4)8);
33336889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray        }
33436889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray        break;
33536889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray    case BLEND_SCREEN:
33636889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray        ALOGE("Called unimplemented blend intrinsic BLEND_SCREEN");
33736889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray        rsAssert(false);
33836889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray        break;
33936889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray    case BLEND_DARKEN:
34036889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray        ALOGE("Called unimplemented blend intrinsic BLEND_DARKEN");
34136889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray        rsAssert(false);
34236889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray        break;
34336889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray    case BLEND_LIGHTEN:
34436889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray        ALOGE("Called unimplemented blend intrinsic BLEND_LIGHTEN");
34536889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray        rsAssert(false);
34636889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray        break;
34736889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray    case BLEND_OVERLAY:
34836889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray        ALOGE("Called unimplemented blend intrinsic BLEND_OVERLAY");
34936889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray        rsAssert(false);
35036889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray        break;
35136889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray    case BLEND_HARDLIGHT:
35236889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray        ALOGE("Called unimplemented blend intrinsic BLEND_HARDLIGHT");
35336889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray        rsAssert(false);
35436889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray        break;
35536889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray    case BLEND_SOFTLIGHT:
35636889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray        ALOGE("Called unimplemented blend intrinsic BLEND_SOFTLIGHT");
35736889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray        rsAssert(false);
35836889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray        break;
35936889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray    case BLEND_DIFFERENCE:
36036889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray        ALOGE("Called unimplemented blend intrinsic BLEND_DIFFERENCE");
36136889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray        rsAssert(false);
36236889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray        break;
36336889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray    case BLEND_NEGATION:
36436889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray        ALOGE("Called unimplemented blend intrinsic BLEND_NEGATION");
36536889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray        rsAssert(false);
36636889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray        break;
36736889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray    case BLEND_EXCLUSION:
36836889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray        ALOGE("Called unimplemented blend intrinsic BLEND_EXCLUSION");
36936889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray        rsAssert(false);
37036889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray        break;
37136889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray    case BLEND_COLOR_DODGE:
37236889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray        ALOGE("Called unimplemented blend intrinsic BLEND_COLOR_DODGE");
37336889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray        rsAssert(false);
37436889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray        break;
37536889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray    case BLEND_INVERSE_COLOR_DODGE:
37636889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray        ALOGE("Called unimplemented blend intrinsic BLEND_INVERSE_COLOR_DODGE");
37736889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray        rsAssert(false);
37836889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray        break;
37936889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray    case BLEND_SOFT_DODGE:
38036889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray        ALOGE("Called unimplemented blend intrinsic BLEND_SOFT_DODGE");
38136889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray        rsAssert(false);
38236889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray        break;
38336889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray    case BLEND_COLOR_BURN:
38436889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray        ALOGE("Called unimplemented blend intrinsic BLEND_COLOR_BURN");
38536889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray        rsAssert(false);
38636889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray        break;
38736889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray    case BLEND_INVERSE_COLOR_BURN:
38836889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray        ALOGE("Called unimplemented blend intrinsic BLEND_INVERSE_COLOR_BURN");
38936889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray        rsAssert(false);
39036889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray        break;
39136889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray    case BLEND_SOFT_BURN:
39236889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray        ALOGE("Called unimplemented blend intrinsic BLEND_SOFT_BURN");
39336889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray        rsAssert(false);
39436889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray        break;
39536889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray    case BLEND_REFLECT:
39636889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray        ALOGE("Called unimplemented blend intrinsic BLEND_REFLECT");
39736889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray        rsAssert(false);
39836889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray        break;
39936889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray    case BLEND_GLOW:
40036889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray        ALOGE("Called unimplemented blend intrinsic BLEND_GLOW");
40136889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray        rsAssert(false);
40236889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray        break;
40336889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray    case BLEND_FREEZE:
40436889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray        ALOGE("Called unimplemented blend intrinsic BLEND_FREEZE");
40536889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray        rsAssert(false);
40636889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray        break;
40736889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray    case BLEND_HEAT:
40836889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray        ALOGE("Called unimplemented blend intrinsic BLEND_HEAT");
40936889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray        rsAssert(false);
41036889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray        break;
41136889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray    case BLEND_ADD:
4127b7060c61e4182b29186849c5a857ea5f0898e56Rose, James    #if defined(ARCH_X86_HAVE_SSSE3)
4137b7060c61e4182b29186849c5a857ea5f0898e56Rose, James        if (gArchUseSIMD) {
4147b7060c61e4182b29186849c5a857ea5f0898e56Rose, James            if((x1 + 8) < x2) {
4157b7060c61e4182b29186849c5a857ea5f0898e56Rose, James                uint32_t len = (x2 - x1) >> 3;
4167b7060c61e4182b29186849c5a857ea5f0898e56Rose, James                rsdIntrinsicBlendAdd_K(out, in, len);
4177b7060c61e4182b29186849c5a857ea5f0898e56Rose, James                x1 += len << 3;
4187b7060c61e4182b29186849c5a857ea5f0898e56Rose, James                out += len << 3;
4197b7060c61e4182b29186849c5a857ea5f0898e56Rose, James                in += len << 3;
4207b7060c61e4182b29186849c5a857ea5f0898e56Rose, James            }
4217b7060c61e4182b29186849c5a857ea5f0898e56Rose, James        }
4227b7060c61e4182b29186849c5a857ea5f0898e56Rose, James    #endif
42336889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray        for (;x1 < x2; x1++, out++, in++) {
4240b575de8ed0b628d84d256f5846500b0385979bdTim Murray            uint32_t iR = in->x, iG = in->y, iB = in->z, iA = in->w,
4250b575de8ed0b628d84d256f5846500b0385979bdTim Murray                oR = out->x, oG = out->y, oB = out->z, oA = out->w;
4260b575de8ed0b628d84d256f5846500b0385979bdTim Murray            out->x = (oR + iR) > 255 ? 255 : oR + iR;
4270b575de8ed0b628d84d256f5846500b0385979bdTim Murray            out->y = (oG + iG) > 255 ? 255 : oG + iG;
4280b575de8ed0b628d84d256f5846500b0385979bdTim Murray            out->z = (oB + iB) > 255 ? 255 : oB + iB;
4290b575de8ed0b628d84d256f5846500b0385979bdTim Murray            out->w = (oA + iA) > 255 ? 255 : oA + iA;
43036889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray        }
43136889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray        break;
43236889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray    case BLEND_SUBTRACT:
4337b7060c61e4182b29186849c5a857ea5f0898e56Rose, James    #if defined(ARCH_X86_HAVE_SSSE3)
4347b7060c61e4182b29186849c5a857ea5f0898e56Rose, James        if (gArchUseSIMD) {
4357b7060c61e4182b29186849c5a857ea5f0898e56Rose, James            if((x1 + 8) < x2) {
4367b7060c61e4182b29186849c5a857ea5f0898e56Rose, James                uint32_t len = (x2 - x1) >> 3;
4377b7060c61e4182b29186849c5a857ea5f0898e56Rose, James                rsdIntrinsicBlendSub_K(out, in, len);
4387b7060c61e4182b29186849c5a857ea5f0898e56Rose, James                x1 += len << 3;
4397b7060c61e4182b29186849c5a857ea5f0898e56Rose, James                out += len << 3;
4407b7060c61e4182b29186849c5a857ea5f0898e56Rose, James                in += len << 3;
4417b7060c61e4182b29186849c5a857ea5f0898e56Rose, James            }
4427b7060c61e4182b29186849c5a857ea5f0898e56Rose, James        }
4437b7060c61e4182b29186849c5a857ea5f0898e56Rose, James    #endif
44436889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray        for (;x1 < x2; x1++, out++, in++) {
4450b575de8ed0b628d84d256f5846500b0385979bdTim Murray            int32_t iR = in->x, iG = in->y, iB = in->z, iA = in->w,
4460b575de8ed0b628d84d256f5846500b0385979bdTim Murray                oR = out->x, oG = out->y, oB = out->z, oA = out->w;
4470b575de8ed0b628d84d256f5846500b0385979bdTim Murray            out->x = (oR - iR) < 0 ? 0 : oR - iR;
4480b575de8ed0b628d84d256f5846500b0385979bdTim Murray            out->y = (oG - iG) < 0 ? 0 : oG - iG;
4490b575de8ed0b628d84d256f5846500b0385979bdTim Murray            out->z = (oB - iB) < 0 ? 0 : oB - iB;
4500b575de8ed0b628d84d256f5846500b0385979bdTim Murray            out->w = (oA - iA) < 0 ? 0 : oA - iA;
45136889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray        }
45236889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray        break;
45336889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray    case BLEND_STAMP:
45436889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray        ALOGE("Called unimplemented blend intrinsic BLEND_STAMP");
45536889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray        rsAssert(false);
45636889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray        break;
45736889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray    case BLEND_RED:
45836889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray        ALOGE("Called unimplemented blend intrinsic BLEND_RED");
45936889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray        rsAssert(false);
46036889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray        break;
46136889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray    case BLEND_GREEN:
46236889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray        ALOGE("Called unimplemented blend intrinsic BLEND_GREEN");
46336889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray        rsAssert(false);
46436889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray        break;
46536889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray    case BLEND_BLUE:
46636889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray        ALOGE("Called unimplemented blend intrinsic BLEND_BLUE");
46736889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray        rsAssert(false);
46836889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray        break;
46936889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray    case BLEND_HUE:
47036889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray        ALOGE("Called unimplemented blend intrinsic BLEND_HUE");
47136889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray        rsAssert(false);
47236889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray        break;
47336889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray    case BLEND_SATURATION:
47436889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray        ALOGE("Called unimplemented blend intrinsic BLEND_SATURATION");
47536889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray        rsAssert(false);
47636889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray        break;
47736889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray    case BLEND_COLOR:
47836889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray        ALOGE("Called unimplemented blend intrinsic BLEND_COLOR");
47936889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray        rsAssert(false);
48036889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray        break;
48136889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray    case BLEND_LUMINOSITY:
48236889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray        ALOGE("Called unimplemented blend intrinsic BLEND_LUMINOSITY");
48336889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray        rsAssert(false);
48436889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray        break;
485cf9ea9f4145cae663f439b1c2dab956fa37180bbJason Sams
48636889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray    default:
48736889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray        ALOGE("Called unimplemented value %d", p->slot);
48836889a0ecf564e3d47e7f69bb030c6b927061792Tim Murray        rsAssert(false);
489cf9ea9f4145cae663f439b1c2dab956fa37180bbJason Sams
490cf9ea9f4145cae663f439b1c2dab956fa37180bbJason Sams    }
491cf9ea9f4145cae663f439b1c2dab956fa37180bbJason Sams}
492cf9ea9f4145cae663f439b1c2dab956fa37180bbJason Sams
493cf9ea9f4145cae663f439b1c2dab956fa37180bbJason Sams
494c905efd76fdcc1b8846b229bf7d991d185a7b4b7Jason SamsRsdCpuScriptIntrinsicBlend::RsdCpuScriptIntrinsicBlend(RsdCpuReferenceImpl *ctx,
495c905efd76fdcc1b8846b229bf7d991d185a7b4b7Jason Sams                                                       const Script *s, const Element *e)
496c905efd76fdcc1b8846b229bf7d991d185a7b4b7Jason Sams            : RsdCpuScriptIntrinsic(ctx, s, e, RS_SCRIPT_INTRINSIC_ID_BLEND) {
497cf9ea9f4145cae663f439b1c2dab956fa37180bbJason Sams
498709a0978ae141198018ca9769f8d96292a8928e6Jason Sams    mRootPtr = &kernel;
499cf9ea9f4145cae663f439b1c2dab956fa37180bbJason Sams}
500cf9ea9f4145cae663f439b1c2dab956fa37180bbJason Sams
501709a0978ae141198018ca9769f8d96292a8928e6Jason SamsRsdCpuScriptIntrinsicBlend::~RsdCpuScriptIntrinsicBlend() {
502709a0978ae141198018ca9769f8d96292a8928e6Jason Sams}
503709a0978ae141198018ca9769f8d96292a8928e6Jason Sams
504709a0978ae141198018ca9769f8d96292a8928e6Jason Samsvoid RsdCpuScriptIntrinsicBlend::populateScript(Script *s) {
505709a0978ae141198018ca9769f8d96292a8928e6Jason Sams    s->mHal.info.exportedVariableCount = 0;
506709a0978ae141198018ca9769f8d96292a8928e6Jason Sams}
507709a0978ae141198018ca9769f8d96292a8928e6Jason Sams
508c905efd76fdcc1b8846b229bf7d991d185a7b4b7Jason SamsRsdCpuScriptImpl * rsdIntrinsic_Blend(RsdCpuReferenceImpl *ctx,
509c905efd76fdcc1b8846b229bf7d991d185a7b4b7Jason Sams                                      const Script *s, const Element *e) {
510c905efd76fdcc1b8846b229bf7d991d185a7b4b7Jason Sams    return new RsdCpuScriptIntrinsicBlend(ctx, s, e);
511709a0978ae141198018ca9769f8d96292a8928e6Jason Sams}
512709a0978ae141198018ca9769f8d96292a8928e6Jason Sams
513709a0978ae141198018ca9769f8d96292a8928e6Jason Sams
514cf9ea9f4145cae663f439b1c2dab956fa37180bbJason Sams
515