1 /*
2 * Copyright (C) 2008-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 #include <malloc.h>
18
19 #include "RenderScript.h"
20 #include <rs.h>
21 #include "rsDefines.h"
22
23 using namespace android;
24 using namespace RSC;
25
ScriptIntrinsic(sp<RS> rs,int id,sp<const Element> e)26 ScriptIntrinsic::ScriptIntrinsic(sp<RS> rs, int id, sp<const Element> e)
27 : Script(NULL, rs) {
28 mID = rsScriptIntrinsicCreate(rs->getContext(), id, e->getID());
29 }
30
ScriptIntrinsicBlend(sp<RS> rs,sp<const Element> e)31 ScriptIntrinsicBlend::ScriptIntrinsicBlend(sp<RS> rs, sp<const Element> e)
32 : ScriptIntrinsic(rs, RS_SCRIPT_INTRINSIC_ID_BLEND, e) {
33
34 }
35
blendClear(sp<Allocation> in,sp<Allocation> out)36 void ScriptIntrinsicBlend::blendClear(sp<Allocation> in, sp<Allocation> out) {
37 Script::forEach(0, in, out, NULL, 0);
38 }
39
blendSrc(sp<Allocation> in,sp<Allocation> out)40 void ScriptIntrinsicBlend::blendSrc(sp<Allocation> in, sp<Allocation> out) {
41 Script::forEach(1, in, out, NULL, 0);
42 }
43
blendDst(sp<Allocation> in,sp<Allocation> out)44 void ScriptIntrinsicBlend::blendDst(sp<Allocation> in, sp<Allocation> out) {
45 Script::forEach(2, in, out, NULL, 0);
46 }
47
blendSrcOver(sp<Allocation> in,sp<Allocation> out)48 void ScriptIntrinsicBlend::blendSrcOver(sp<Allocation> in, sp<Allocation> out) {
49 Script::forEach(3, in, out, NULL, 0);
50 }
51
blendDstOver(sp<Allocation> in,sp<Allocation> out)52 void ScriptIntrinsicBlend::blendDstOver(sp<Allocation> in, sp<Allocation> out) {
53 Script::forEach(4, in, out, NULL, 0);
54 }
55
blendSrcIn(sp<Allocation> in,sp<Allocation> out)56 void ScriptIntrinsicBlend::blendSrcIn(sp<Allocation> in, sp<Allocation> out) {
57 Script::forEach(5, in, out, NULL, 0);
58 }
59
blendDstIn(sp<Allocation> in,sp<Allocation> out)60 void ScriptIntrinsicBlend::blendDstIn(sp<Allocation> in, sp<Allocation> out) {
61 Script::forEach(6, in, out, NULL, 0);
62 }
63
blendSrcOut(sp<Allocation> in,sp<Allocation> out)64 void ScriptIntrinsicBlend::blendSrcOut(sp<Allocation> in, sp<Allocation> out) {
65 Script::forEach(7, in, out, NULL, 0);
66 }
67
blendDstOut(sp<Allocation> in,sp<Allocation> out)68 void ScriptIntrinsicBlend::blendDstOut(sp<Allocation> in, sp<Allocation> out) {
69 Script::forEach(8, in, out, NULL, 0);
70 }
71
blendSrcAtop(sp<Allocation> in,sp<Allocation> out)72 void ScriptIntrinsicBlend::blendSrcAtop(sp<Allocation> in, sp<Allocation> out) {
73 Script::forEach(9, in, out, NULL, 0);
74 }
75
blendDstAtop(sp<Allocation> in,sp<Allocation> out)76 void ScriptIntrinsicBlend::blendDstAtop(sp<Allocation> in, sp<Allocation> out) {
77 Script::forEach(10, in, out, NULL, 0);
78 }
79
blendXor(sp<Allocation> in,sp<Allocation> out)80 void ScriptIntrinsicBlend::blendXor(sp<Allocation> in, sp<Allocation> out) {
81 Script::forEach(11, in, out, NULL, 0);
82 }
83
84 // Numbering jumps here
blendMultiply(sp<Allocation> in,sp<Allocation> out)85 void ScriptIntrinsicBlend::blendMultiply(sp<Allocation> in, sp<Allocation> out) {
86 Script::forEach(14, in, out, NULL, 0);
87 }
88
89 // Numbering jumps here
blendAdd(sp<Allocation> in,sp<Allocation> out)90 void ScriptIntrinsicBlend::blendAdd(sp<Allocation> in, sp<Allocation> out) {
91 Script::forEach(34, in, out, NULL, 0);
92 }
93
blendSubtract(sp<Allocation> in,sp<Allocation> out)94 void ScriptIntrinsicBlend::blendSubtract(sp<Allocation> in, sp<Allocation> out) {
95 Script::forEach(35, in, out, NULL, 0);
96 }
97
ScriptIntrinsicBlur(sp<RS> rs,sp<const Element> e)98 ScriptIntrinsicBlur::ScriptIntrinsicBlur(sp<RS> rs, sp<const Element> e)
99 : ScriptIntrinsic(rs, RS_SCRIPT_INTRINSIC_ID_BLUR, e) {
100
101 }
102
blur(sp<Allocation> in,sp<Allocation> out)103 void ScriptIntrinsicBlur::blur(sp<Allocation> in, sp<Allocation> out) {
104 Script::setVar(1, in);
105 Script::forEach(0, NULL, out, NULL, 0);
106 }
107
setRadius(float radius)108 void ScriptIntrinsicBlur::setRadius(float radius) {
109 Script::setVar(0, &radius, sizeof(float));
110 }
111