Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [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 | |
| 18 | #include "rsCpuIntrinsic.h" |
| 19 | #include "rsCpuIntrinsicInlines.h" |
| 20 | |
| 21 | using namespace android; |
| 22 | using namespace android::renderscript; |
| 23 | |
| 24 | namespace android { |
| 25 | namespace renderscript { |
| 26 | |
| 27 | |
| 28 | class RsdCpuScriptIntrinsicLUT : public RsdCpuScriptIntrinsic { |
| 29 | public: |
Stephen Hines | c060f14 | 2015-05-13 19:26:09 -0700 | [diff] [blame] | 30 | void populateScript(Script *) override; |
| 31 | void invokeFreeChildren() override; |
Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 32 | |
Stephen Hines | c060f14 | 2015-05-13 19:26:09 -0700 | [diff] [blame] | 33 | void setGlobalObj(uint32_t slot, ObjectBase *data) override; |
Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 34 | |
Stephen Hines | c060f14 | 2015-05-13 19:26:09 -0700 | [diff] [blame] | 35 | ~RsdCpuScriptIntrinsicLUT() override; |
Jason Sams | c905efd | 2012-11-26 15:20:18 -0800 | [diff] [blame] | 36 | RsdCpuScriptIntrinsicLUT(RsdCpuReferenceImpl *ctx, const Script *s, const Element *e); |
Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 37 | |
| 38 | protected: |
| 39 | ObjectBaseRef<Allocation> lut; |
| 40 | |
David Gross | b0abb14 | 2015-03-12 15:23:03 -0700 | [diff] [blame] | 41 | static void kernel(const RsExpandKernelDriverInfo *info, |
Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 42 | uint32_t xstart, uint32_t xend, |
Chris Wailes | 9ed7910 | 2014-07-25 15:53:28 -0700 | [diff] [blame] | 43 | uint32_t outstep); |
Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 44 | }; |
| 45 | |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | |
| 50 | void RsdCpuScriptIntrinsicLUT::setGlobalObj(uint32_t slot, ObjectBase *data) { |
| 51 | rsAssert(slot == 0); |
| 52 | lut.set(static_cast<Allocation *>(data)); |
| 53 | } |
| 54 | |
| 55 | |
David Gross | b0abb14 | 2015-03-12 15:23:03 -0700 | [diff] [blame] | 56 | void RsdCpuScriptIntrinsicLUT::kernel(const RsExpandKernelDriverInfo *info, |
Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 57 | uint32_t xstart, uint32_t xend, |
Chris Wailes | 9ed7910 | 2014-07-25 15:53:28 -0700 | [diff] [blame] | 58 | uint32_t outstep) { |
David Gross | b0abb14 | 2015-03-12 15:23:03 -0700 | [diff] [blame] | 59 | RsdCpuScriptIntrinsicLUT *cp = (RsdCpuScriptIntrinsicLUT *)info->usr; |
Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 60 | |
David Gross | b0abb14 | 2015-03-12 15:23:03 -0700 | [diff] [blame] | 61 | uchar *out = (uchar *)info->outPtr[0]; |
| 62 | const uchar *in = (uchar *)info->inPtr[0]; |
Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 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) { |
Jason Sams | ed157c8 | 2014-06-10 15:30:41 -0700 | [diff] [blame] | 72 | out[0] = tr[in[0]]; |
| 73 | out[1] = tg[in[1]]; |
| 74 | out[2] = tb[in[2]]; |
| 75 | out[3] = ta[in[3]]; |
| 76 | in += 4; |
| 77 | out += 4; |
Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 78 | x1++; |
| 79 | } |
| 80 | } |
| 81 | |
Jason Sams | c905efd | 2012-11-26 15:20:18 -0800 | [diff] [blame] | 82 | RsdCpuScriptIntrinsicLUT::RsdCpuScriptIntrinsicLUT(RsdCpuReferenceImpl *ctx, |
| 83 | const Script *s, const Element *e) |
| 84 | : RsdCpuScriptIntrinsic(ctx, s, e, RS_SCRIPT_INTRINSIC_ID_LUT) { |
Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 85 | |
| 86 | mRootPtr = &kernel; |
| 87 | } |
| 88 | |
| 89 | RsdCpuScriptIntrinsicLUT::~RsdCpuScriptIntrinsicLUT() { |
| 90 | } |
| 91 | |
| 92 | void RsdCpuScriptIntrinsicLUT::populateScript(Script *s) { |
| 93 | s->mHal.info.exportedVariableCount = 1; |
| 94 | } |
| 95 | |
| 96 | void RsdCpuScriptIntrinsicLUT::invokeFreeChildren() { |
| 97 | lut.clear(); |
| 98 | } |
| 99 | |
| 100 | |
Jason Sams | c905efd | 2012-11-26 15:20:18 -0800 | [diff] [blame] | 101 | RsdCpuScriptImpl * rsdIntrinsic_LUT(RsdCpuReferenceImpl *ctx, |
| 102 | const Script *s, const Element *e) { |
Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 103 | |
Jason Sams | c905efd | 2012-11-26 15:20:18 -0800 | [diff] [blame] | 104 | return new RsdCpuScriptIntrinsicLUT(ctx, s, e); |
Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 105 | } |