Jason Sams | 170dc84 | 2012-02-23 17:14:39 -0800 | [diff] [blame] | 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 | #ifndef __ANDROID_SCRIPT_H__ |
| 18 | #define __ANDROID_SCRIPT_H__ |
| 19 | |
| 20 | #include <pthread.h> |
| 21 | #include <rs.h> |
| 22 | |
| 23 | #include "RenderScript.h" |
| 24 | #include "Allocation.h" |
| 25 | |
| 26 | class Type; |
| 27 | class Element; |
| 28 | class Allocation; |
| 29 | |
| 30 | class Script : public BaseObj { |
| 31 | protected: |
| 32 | Script(void *id, RenderScript *rs); |
Jason Sams | d1c8c12 | 2012-03-14 15:36:02 -0700 | [diff] [blame] | 33 | void forEach(uint32_t slot, const Allocation *in, const Allocation *out, const void *v, size_t) const; |
| 34 | void bindAllocation(const Allocation *va, uint32_t slot) const; |
| 35 | void setVar(uint32_t index, const void *, size_t len) const; |
| 36 | void setVar(uint32_t index, const BaseObj *o) const; |
| 37 | void invoke(uint32_t slot, const void *v, size_t len) const; |
Jason Sams | 170dc84 | 2012-02-23 17:14:39 -0800 | [diff] [blame] | 38 | |
| 39 | |
Jason Sams | d1c8c12 | 2012-03-14 15:36:02 -0700 | [diff] [blame] | 40 | void invoke(uint32_t slot) const { |
Jason Sams | 170dc84 | 2012-02-23 17:14:39 -0800 | [diff] [blame] | 41 | invoke(slot, NULL, 0); |
| 42 | } |
Jason Sams | d1c8c12 | 2012-03-14 15:36:02 -0700 | [diff] [blame] | 43 | void setVar(uint32_t index, float v) const { |
Jason Sams | 170dc84 | 2012-02-23 17:14:39 -0800 | [diff] [blame] | 44 | setVar(index, &v, sizeof(v)); |
| 45 | } |
Jason Sams | d1c8c12 | 2012-03-14 15:36:02 -0700 | [diff] [blame] | 46 | void setVar(uint32_t index, double v) const { |
Jason Sams | 170dc84 | 2012-02-23 17:14:39 -0800 | [diff] [blame] | 47 | setVar(index, &v, sizeof(v)); |
| 48 | } |
Jason Sams | d1c8c12 | 2012-03-14 15:36:02 -0700 | [diff] [blame] | 49 | void setVar(uint32_t index, int32_t v) const { |
Jason Sams | 170dc84 | 2012-02-23 17:14:39 -0800 | [diff] [blame] | 50 | setVar(index, &v, sizeof(v)); |
| 51 | } |
Jason Sams | d1c8c12 | 2012-03-14 15:36:02 -0700 | [diff] [blame] | 52 | void setVar(uint32_t index, int64_t v) const { |
Jason Sams | 170dc84 | 2012-02-23 17:14:39 -0800 | [diff] [blame] | 53 | setVar(index, &v, sizeof(v)); |
| 54 | } |
Jason Sams | d1c8c12 | 2012-03-14 15:36:02 -0700 | [diff] [blame] | 55 | void setVar(uint32_t index, bool v) const { |
Jason Sams | 170dc84 | 2012-02-23 17:14:39 -0800 | [diff] [blame] | 56 | setVar(index, &v, sizeof(v)); |
| 57 | } |
| 58 | |
| 59 | public: |
| 60 | class FieldBase { |
| 61 | protected: |
| 62 | const Element *mElement; |
| 63 | Allocation *mAllocation; |
| 64 | |
| 65 | void init(RenderScript *rs, uint32_t dimx, uint32_t usages = 0); |
| 66 | |
| 67 | public: |
| 68 | const Element *getElement() { |
| 69 | return mElement; |
| 70 | } |
| 71 | |
| 72 | const Type *getType() { |
| 73 | return mAllocation->getType(); |
| 74 | } |
| 75 | |
| 76 | const Allocation *getAllocation() { |
| 77 | return mAllocation; |
| 78 | } |
| 79 | |
| 80 | //void updateAllocation(); |
| 81 | }; |
| 82 | }; |
| 83 | |
| 84 | #endif |