blob: 0da1f752002d8f301c9e66f1be11fb981edf975d [file] [log] [blame]
Jason Sams709a0972012-11-15 18:18:04 -08001/*
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
18#include "rsCpuIntrinsic.h"
19#include "rsCpuIntrinsicInlines.h"
20
21using namespace android;
22using namespace android::renderscript;
23
24namespace android {
25namespace renderscript {
26
27
28class RsdCpuScriptIntrinsicLUT : public RsdCpuScriptIntrinsic {
29public:
30 virtual void populateScript(Script *);
31 virtual void invokeFreeChildren();
32
33 virtual void setGlobalObj(uint32_t slot, ObjectBase *data);
34
35 virtual ~RsdCpuScriptIntrinsicLUT();
Jason Samsc905efd2012-11-26 15:20:18 -080036 RsdCpuScriptIntrinsicLUT(RsdCpuReferenceImpl *ctx, const Script *s, const Element *e);
Jason Sams709a0972012-11-15 18:18:04 -080037
38protected:
39 ObjectBaseRef<Allocation> lut;
40
41 static void kernel(const RsForEachStubParamStruct *p,
42 uint32_t xstart, uint32_t xend,
43 uint32_t instep, uint32_t outstep);
44};
45
46}
47}
48
49
50void RsdCpuScriptIntrinsicLUT::setGlobalObj(uint32_t slot, ObjectBase *data) {
51 rsAssert(slot == 0);
52 lut.set(static_cast<Allocation *>(data));
53}
54
55
56void RsdCpuScriptIntrinsicLUT::kernel(const RsForEachStubParamStruct *p,
57 uint32_t xstart, uint32_t xend,
58 uint32_t instep, uint32_t outstep) {
59 RsdCpuScriptIntrinsicLUT *cp = (RsdCpuScriptIntrinsicLUT *)p->usr;
60
61 uchar4 *out = (uchar4 *)p->out;
62 uchar4 *in = (uchar4 *)p->in;
63 uint32_t x1 = xstart;
64 uint32_t x2 = xend;
65
66 const uchar *tr = (const uchar *)cp->lut->mHal.drvState.lod[0].mallocPtr;
67 const uchar *tg = &tr[256];
68 const uchar *tb = &tg[256];
69 const uchar *ta = &tb[256];
70
71 while (x1 < x2) {
72 uchar4 p = *in;
73 uchar4 o = {tr[p.x], tg[p.y], tb[p.z], ta[p.w]};
74 *out = o;
75 in++;
76 out++;
77 x1++;
78 }
79}
80
Jason Samsc905efd2012-11-26 15:20:18 -080081RsdCpuScriptIntrinsicLUT::RsdCpuScriptIntrinsicLUT(RsdCpuReferenceImpl *ctx,
82 const Script *s, const Element *e)
83 : RsdCpuScriptIntrinsic(ctx, s, e, RS_SCRIPT_INTRINSIC_ID_LUT) {
Jason Sams709a0972012-11-15 18:18:04 -080084
85 mRootPtr = &kernel;
86}
87
88RsdCpuScriptIntrinsicLUT::~RsdCpuScriptIntrinsicLUT() {
89}
90
91void RsdCpuScriptIntrinsicLUT::populateScript(Script *s) {
92 s->mHal.info.exportedVariableCount = 1;
93}
94
95void RsdCpuScriptIntrinsicLUT::invokeFreeChildren() {
96 lut.clear();
97}
98
99
Jason Samsc905efd2012-11-26 15:20:18 -0800100RsdCpuScriptImpl * rsdIntrinsic_LUT(RsdCpuReferenceImpl *ctx,
101 const Script *s, const Element *e) {
Jason Sams709a0972012-11-15 18:18:04 -0800102
Jason Samsc905efd2012-11-26 15:20:18 -0800103 return new RsdCpuScriptIntrinsicLUT(ctx, s, e);
Jason Sams709a0972012-11-15 18:18:04 -0800104}
105
106